diff --git a/WcsMain/ApiServe/Controllers/Dto/WcsDto/DB/EditeDBRequest.cs b/WcsMain/ApiServe/Controllers/Dto/WcsDto/DB/EditeDBRequest.cs index f24e436..791e749 100644 --- a/WcsMain/ApiServe/Controllers/Dto/WcsDto/DB/EditeDBRequest.cs +++ b/WcsMain/ApiServe/Controllers/Dto/WcsDto/DB/EditeDBRequest.cs @@ -33,10 +33,4 @@ public class EditeDBRequest /// [JsonPropertyName("remark")] public string? Remark { get; set; } - - /// - /// 是否是编辑状态 - /// - [JsonPropertyName("isEdite")] - public bool IsEdite { get; set; } } \ No newline at end of file diff --git a/WcsMain/ApiServe/Controllers/Dto/WcsDto/DB/GetDBWithPlcNameRequest.cs b/WcsMain/ApiServe/Controllers/Dto/WcsDto/DB/GetDBWithPlcNameRequest.cs new file mode 100644 index 0000000..131cd9f --- /dev/null +++ b/WcsMain/ApiServe/Controllers/Dto/WcsDto/DB/GetDBWithPlcNameRequest.cs @@ -0,0 +1,26 @@ +using System.Text.Json.Serialization; + +namespace WcsMain.ApiServe.Controllers.Dto.WcsDto.DB; + + +/// +/// 返回PLCDB块同时返回 PLC名称的请求实体 +/// +public class GetDBWithPlcNameRequest +{ + /// + /// DB 名称 + /// + [JsonPropertyName("dbName")] + public string? DBName { get; set; } + + /// + /// plc编号 + /// + [JsonPropertyName("plcId")] + public int? PlcId { get; set; } + + + + +} diff --git a/WcsMain/ApiServe/Controllers/Dto/WcsDto/DB/GetDBWithPlcNameResponse.cs b/WcsMain/ApiServe/Controllers/Dto/WcsDto/DB/GetDBWithPlcNameResponse.cs new file mode 100644 index 0000000..482e137 --- /dev/null +++ b/WcsMain/ApiServe/Controllers/Dto/WcsDto/DB/GetDBWithPlcNameResponse.cs @@ -0,0 +1,49 @@ +using System.Text.Json.Serialization; + +namespace WcsMain.ApiServe.Controllers.Dto.WcsDto.DB; + +/// +/// 返回PLCDB块同时返回 PLC名称的响应实体 +/// +public class GetDBWithPlcNameResponse +{ + /// + /// plc ID + /// + [JsonPropertyName("plcId")] + public int? PlcId { get; set; } + + /// + /// plc 名称 + /// + [JsonPropertyName("plcName")] + public string? PlcName { get; set;} + + /// + /// db的名称 + /// + [JsonPropertyName("dbName")] + public string? DBName { get; set; } + + /// + /// db 地址 + /// + [JsonPropertyName("dbAddress")] + public string? DBAddress { get; set; } + + /// + /// 是否系统级别 + /// + [JsonPropertyName("isSystem")] + public int? IsSystem { get; set;} + + /// + /// 备注 + /// + [JsonPropertyName("remark")] + public string? Remark { get; set; } + + + + +} diff --git a/WcsMain/ApiServe/Controllers/WcsController/PlcDbController.cs b/WcsMain/ApiServe/Controllers/WcsController/PlcDbController.cs index 7b0aafb..9638317 100644 --- a/WcsMain/ApiServe/Controllers/WcsController/PlcDbController.cs +++ b/WcsMain/ApiServe/Controllers/WcsController/PlcDbController.cs @@ -31,7 +31,7 @@ public class PlcDbController(PlcDbService plcDbService) : ControllerBase /// /// /// - [HttpPost("editeDB")] + [HttpPost("addOrUpdate")] public WcsApiResponse EditeDB([FromBody] EditeDBRequest request) { return _plcDbService.EditePlc(request); @@ -48,4 +48,15 @@ public class PlcDbController(PlcDbService plcDbService) : ControllerBase return _plcDbService.DeleteDB(dbName); } + /// + /// 查询 db 同时返回 PLC名称 + /// + /// + /// + [HttpPost("getDBWithPlcName")] + public WcsApiResponse> GetDBWithPlcName(GetDBWithPlcNameRequest request) + { + return _plcDbService.GetDBWithPlcName(request); + } + } \ No newline at end of file diff --git a/WcsMain/ApiServe/Service/WcsService/PlcDbService.cs b/WcsMain/ApiServe/Service/WcsService/PlcDbService.cs index b883eee..b923db1 100644 --- a/WcsMain/ApiServe/Service/WcsService/PlcDbService.cs +++ b/WcsMain/ApiServe/Service/WcsService/PlcDbService.cs @@ -49,7 +49,12 @@ public class PlcDbService(AppDBDao dBDao) IsSystem = request.IsSystem, Remark = request.Remark }; - if (request.IsEdite) + List? dBs = _dBDao.Select(new AppDB { DBName = request.DbName}); + if(dBs == default) + { + return WcsApiResponseFactory.DataBaseErr(); + } + if (dBs.Count > 0) { // 修改信息 var result = _dBDao.Update(db); @@ -78,4 +83,19 @@ public class PlcDbService(AppDBDao dBDao) var result = _dBDao.Delete(new AppDB() { DBName = dbName }); return result > 0 ? WcsApiResponseFactory.Success() : WcsApiResponseFactory.DataBaseErr(); } + + /// + /// 查询 PLCDB地址,同时返回PLC名称 + /// + /// + /// + public WcsApiResponse> GetDBWithPlcName(GetDBWithPlcNameRequest request) + { + List? dbs = _dBDao.QueryWithPlcName(new AppDB { PlcId = request.PlcId, DBName = request.DBName }); + if (dbs == default) + { + return WcsApiResponseFactory.DataBaseErr>(); + } + return WcsApiResponseFactory.Success(dbs, "查询成功"); + } } \ No newline at end of file diff --git a/WcsMain/DataBase/Dao/AppDBDao.cs b/WcsMain/DataBase/Dao/AppDBDao.cs index 16ef481..d813b28 100644 --- a/WcsMain/DataBase/Dao/AppDBDao.cs +++ b/WcsMain/DataBase/Dao/AppDBDao.cs @@ -1,4 +1,5 @@ -using WcsMain.Common; +using WcsMain.ApiServe.Controllers.Dto.WcsDto.DB; +using WcsMain.Common; using WcsMain.DataBase.TableEntity; using WcsMain.WcsAttribute.AutoFacAttribute; @@ -109,4 +110,37 @@ public class AppDBDao /// public List? Select() => Select(new AppDB()); + + /// + /// 查询所有DB地址,同时返回PLC名称 + /// + /// + /// + public List? QueryWithPlcName(AppDB appDB) + { + try + { + var sqlFuc = CommonTool.DbServe.Queryable() + .LeftJoin((db, plc) => db.PlcId == plc.PLCId) + .WhereIF(!string.IsNullOrEmpty(appDB.DBName), db => db.DBName!.Contains(appDB.DBName!)) + .WhereIF(appDB.PlcId != default, db => db.PlcId == appDB.PlcId) + .OrderBy(db => new { db.PlcId, db.DBName }) + .Select((db, plc) => new GetDBWithPlcNameResponse + { + PlcId = db.PlcId, + PlcName = plc.PLCName, + DBName = db.DBName, + DBAddress = db.DBAddress, + IsSystem = db.IsSystem, + Remark = db.Remark, + }); + return sqlFuc.ToList(); + } + catch (Exception ex) + { + _ = ex; + return default; + } + } + } \ No newline at end of file