From caae20fe04fed541f6a14ec96249f476ec6fabe8 Mon Sep 17 00:00:00 2001 From: icewint Date: Thu, 23 May 2024 08:50:46 +0800 Subject: [PATCH] =?UTF-8?q?[important]=E6=B7=BB=E5=8A=A0PLC=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dto/WcsDto/PLC/EditePLCRequest.cs | 16 +++--- .../WcsController/PlcController.cs | 12 +++++ .../ApiServe/Service/WcsService/PlcService.cs | 21 +++++++- WcsMain/DataBase/Dao/AppPLCDao.cs | 49 +++++++++++++++++++ WcsMain/DataBase/TableEntity/AppPLC.cs | 22 ++++++--- 5 files changed, 106 insertions(+), 14 deletions(-) diff --git a/WcsMain/ApiServe/Controllers/Dto/WcsDto/PLC/EditePLCRequest.cs b/WcsMain/ApiServe/Controllers/Dto/WcsDto/PLC/EditePLCRequest.cs index 4b73d89..cee2cb9 100644 --- a/WcsMain/ApiServe/Controllers/Dto/WcsDto/PLC/EditePLCRequest.cs +++ b/WcsMain/ApiServe/Controllers/Dto/WcsDto/PLC/EditePLCRequest.cs @@ -1,4 +1,5 @@ -using System.Text.Json.Serialization; +using DataCheck; +using System.Text.Json.Serialization; namespace WcsMain.ApiServe.Controllers.Dto.WcsDto.PLC; @@ -7,16 +8,11 @@ namespace WcsMain.ApiServe.Controllers.Dto.WcsDto.PLC; /// public class EditePLCRequest { - /// - /// 是否处于编辑模式 - /// - [JsonPropertyName("isEdite")] - public bool IsEdite { get; set; } - /// /// PLC的编号 /// [JsonPropertyName("plcId")] + [DataRules] public int? PlcId { get; set; } /// @@ -25,6 +21,12 @@ public class EditePLCRequest [JsonPropertyName("plcIp")] public string? PlcIp { get; set; } + /// + /// PLC 的名称 + /// + [JsonPropertyName("plcName")] + public string? PlcName { get; set; } + /// /// 机架 /// diff --git a/WcsMain/ApiServe/Controllers/WcsController/PlcController.cs b/WcsMain/ApiServe/Controllers/WcsController/PlcController.cs index c6b6b6c..f9e7c41 100644 --- a/WcsMain/ApiServe/Controllers/WcsController/PlcController.cs +++ b/WcsMain/ApiServe/Controllers/WcsController/PlcController.cs @@ -35,4 +35,16 @@ public class PlcController(PlcService plcService) : ControllerBase { return _plcService.EditePlc(request); } + + + /// + /// 添加或者修改配置项 + /// + /// + /// + [HttpDelete("deletePlc")] + public WcsApiResponse DeletePlc([FromQuery(Name = "plcId")] int? plcId) + { + return _plcService.DeletePlc(plcId); + } } \ No newline at end of file diff --git a/WcsMain/ApiServe/Service/WcsService/PlcService.cs b/WcsMain/ApiServe/Service/WcsService/PlcService.cs index d3b5737..fa6ff29 100644 --- a/WcsMain/ApiServe/Service/WcsService/PlcService.cs +++ b/WcsMain/ApiServe/Service/WcsService/PlcService.cs @@ -1,4 +1,5 @@ using DataCheck; +using System.Collections.Generic; using WcsMain.ApiServe.Controllers.Dto; using WcsMain.ApiServe.Controllers.Dto.WcsDto.PLC; using WcsMain.ApiServe.Factory; @@ -42,13 +43,20 @@ public class PlcService(AppPLCDao pLCDao) { PLCId = Convert.ToInt32(request.PlcId), PLCIp = request.PlcIp, + PLCName = request.PlcName, PLCKind = request.PlcKind, PLCRack = request.Rack, PLCSlot = request.Slot, PLCStatus = request.PlcStatus, Remark = request.Remark }; - if (request.IsEdite) + /* 判断这个编号是否存在 */ + List ? appPLCs = _plcDao.Query(new AppPLC { PLCId = request.PlcId}); + if (appPLCs == default) + { + return WcsApiResponseFactory.DataBaseErr(); + } + if (appPLCs.Count > 0) { // 修改信息 var result = _plcDao.Update(plc); @@ -60,6 +68,17 @@ public class PlcService(AppPLCDao pLCDao) var result = _plcDao.Insert(plc); return result > 0 ? WcsApiResponseFactory.Success() : WcsApiResponseFactory.DataBaseErr(); } + } + /// + /// 删除一条数据 + /// + /// + /// + public WcsApiResponse DeletePlc(int? plcId) + { + if(plcId == default) return WcsApiResponseFactory.RequestErr(); + var result = _plcDao.Delete(new AppPLC { PLCId = plcId }); + return result > 0 ? WcsApiResponseFactory.Success() : WcsApiResponseFactory.DataBaseErr(); } } \ No newline at end of file diff --git a/WcsMain/DataBase/Dao/AppPLCDao.cs b/WcsMain/DataBase/Dao/AppPLCDao.cs index 4b643ab..2fa5884 100644 --- a/WcsMain/DataBase/Dao/AppPLCDao.cs +++ b/WcsMain/DataBase/Dao/AppPLCDao.cs @@ -27,6 +27,35 @@ public class AppPLCDao return default; } + /// + /// 根据条件查询 + /// + /// + /// + public List? Query(AppPLC plc) + { + try + { + var sqlFuc = CommonTool.DbServe.Queryable() + .WhereIF(plc.PLCId != default, w=>w.PLCId == plc.PLCId) + .WhereIF(plc.PLCIp != default, w => w.PLCIp == plc.PLCIp) + .WhereIF(plc.PLCName != default, w => w.PLCName == plc.PLCName) + .WhereIF(plc.PLCStatus != default, w => w.PLCStatus == plc.PLCStatus) + .WhereIF(plc.PLCKind != default, w => w.PLCKind == plc.PLCKind) + .WhereIF(plc.PLCRack != default, w => w.PLCRack == plc.PLCRack) + .WhereIF(plc.PLCSlot != default, w => w.PLCSlot == plc.PLCSlot) + .OrderBy(o => o.PLCId); + var ss = sqlFuc.ToSql(); + return sqlFuc.ToList(); + + } + catch (Exception ex) + { + _ = ex; + } + return default; + } + /// /// 根据主键返回更新条数 @@ -69,6 +98,26 @@ public class AppPLCDao return default; } + /// + /// 删除一行数据,根据主键 + /// + /// + /// + public int Delete(AppPLC plcInfo) + { + try + { + var sqlFuc = CommonTool.DbServe.Deleteable(plcInfo); + return sqlFuc.ExecuteCommand(); + + } + catch (Exception ex) + { + _ = ex; + } + return default; + } + /// /// 根据状态查询PLC数据 diff --git a/WcsMain/DataBase/TableEntity/AppPLC.cs b/WcsMain/DataBase/TableEntity/AppPLC.cs index 1ca7232..acb4839 100644 --- a/WcsMain/DataBase/TableEntity/AppPLC.cs +++ b/WcsMain/DataBase/TableEntity/AppPLC.cs @@ -26,6 +26,21 @@ public class AppPLC [JsonPropertyName("plcIp")] public string? PLCIp { get; set; } + + /// + /// PLC 名称 + /// + [SugarColumn(ColumnName = "plc_name")] + [JsonPropertyName("plcName")] + public string? PLCName { get; set; } + + /// + /// PLC 状态,是否启用 + /// + [SugarColumn(ColumnName = "plc_status")] + [JsonPropertyName("plcStatus")] + public int? PLCStatus { get; set; } + /// /// PLC 系列 /// @@ -50,12 +65,7 @@ public class AppPLC [JsonPropertyName("slot")] public int? PLCSlot { get; set; } - /// - /// PLC 状态,是否启用 - /// - [SugarColumn(ColumnName = "plc_status")] - [JsonPropertyName("plcStatus")] - public int? PLCStatus { get; set; } + /// /// 备注信息