From ff79aa687518fed4b7ec46c5065611859f002982 Mon Sep 17 00:00:00 2001 From: yanko <747575620@qq.com> Date: Fri, 17 Nov 2023 09:38:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=83=96=E5=AD=90=E5=A4=A9=E9=AA=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BPA.MES.Base.Application.xml | 736 +++++++++++++++--- .../Const/ClaimConst.cs | 4 + .../Entitys/App/Pztj_MaterialsInfoEntity.cs | 7 +- .../Entitys/App/Pztj_WorkInfoEntity.cs | 7 +- .../Entitys/App/Pztj_WorkInfoStatusEntity.cs | 4 + .../Entitys/Base/DevicesInfoEntity.cs | 23 - .../Entitys/Base/MaterialsInfoEntity.cs | 31 - .../Entitys/Logs/AlarmLogEntity.cs | 26 +- .../Entitys/Logs/ProgramLogEntity.cs | 18 +- .../Entitys/Logs/RunLogEntity.cs | 18 +- .../Entitys/Logs/UserLogEntity.cs | 6 + .../Filters/AGVAttribute.cs | 39 + ...erLogAttribute .cs => OperLogAttribute.cs} | 0 .../MQTT/MQTTService.cs | 85 +- .../AGVService/Dtos/AGVThirdPartyDto.cs | 199 ++++- .../Services/AGVThirdPartyService.cs | 152 ++-- .../Services/IAGVThirdPartyService.cs | 28 +- .../Services/CraftsInfoService.cs | 16 +- .../Services/DeviceProductFunctionService.cs | 10 +- .../Services/DeviceProductService.cs | 16 +- .../Services/LogService/Dtos/AlarmLogDto.cs | 28 +- .../Services/LogService/Dtos/ProgramLogDto.cs | 20 + .../Services/LogService/Dtos/RunLogDto.cs | 22 +- .../Services/LogService/Dtos/UserLogDto.cs | 4 + .../LogService/Services/AlarmLogService.cs | 3 + .../LogService/Services/ProgramLogService.cs | 3 + .../LogService/Services/RunLogService.cs | 3 + .../MaterialService/Dtos/MaterialsInfoDto.cs | 11 +- .../Services/MaterialsInfoService.cs | 34 +- .../OrderService/Service/OrderService.cs | 4 +- .../Dtos/ProductLineDeviceDto.cs | 14 + .../Dtos/ProductLineStockDto.cs | 30 + .../Services/IProductLineService.cs | 4 +- .../Services/ProductLineService.cs | 49 +- .../SysCacheService/ISysCacheService.cs | 15 + .../SysCacheService/SysCacheService.cs | 163 ++++ .../WorkInfoService/Dtos/WorkInfoDto.cs | 17 +- .../Dtos/WorkInfoMaterialsRecordDto.cs | 48 ++ .../WorkInfoService/Dtos/WorkInfoStatusDto.cs | 51 +- .../Services/IWorkInfoService.cs | 4 +- .../Services/WorkInfoService.cs | 124 ++- backend/BPA.MES.Base.Core/SqlsugarSetup.cs | 4 + backend/BPA.MES.Base.Web.Core/Startup.cs | 29 - .../.config/dotnet-tools.json | 5 + .../BPA.MES.Base.Web.Entry.csproj.user | 1 + .../PublishProfiles/FolderProfile.pubxml | 21 + .../PublishProfiles/FolderProfile.pubxml.user | 10 + .../Properties/launchSettings.json | 2 +- .../BPA.MES.Base.Web.Entry/appsettings.json | 6 +- 49 files changed, 1775 insertions(+), 379 deletions(-) delete mode 100644 backend/BPA.MES.Base.Application/Entitys/Base/DevicesInfoEntity.cs delete mode 100644 backend/BPA.MES.Base.Application/Entitys/Base/MaterialsInfoEntity.cs create mode 100644 backend/BPA.MES.Base.Application/Filters/AGVAttribute.cs rename backend/BPA.MES.Base.Application/Filters/{OperLogAttribute .cs => OperLogAttribute.cs} (100%) create mode 100644 backend/BPA.MES.Base.Application/Services/SysCacheService/ISysCacheService.cs create mode 100644 backend/BPA.MES.Base.Application/Services/SysCacheService/SysCacheService.cs create mode 100644 backend/BPA.MES.Base.Web.Entry/.config/dotnet-tools.json create mode 100644 backend/BPA.MES.Base.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml create mode 100644 backend/BPA.MES.Base.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml.user diff --git a/backend/BPA.MES.Base.Application/BPA.MES.Base.Application.xml b/backend/BPA.MES.Base.Application/BPA.MES.Base.Application.xml index 37ed6ec..0279dd0 100644 --- a/backend/BPA.MES.Base.Application/BPA.MES.Base.Application.xml +++ b/backend/BPA.MES.Base.Application/BPA.MES.Base.Application.xml @@ -82,6 +82,11 @@ 是否是管理员 + + + 所有缓存关键字集合 + + 地址 @@ -461,11 +466,16 @@ 原料单位 - + 原料分组 + + + 每升重量 + + 名 称 :胖子天骄料仓管理 @@ -517,6 +527,11 @@ 成品Id + + + 指定设备Id + + 产量 @@ -568,6 +583,11 @@ 创建时间 + + + 备注 + + 名 称 : @@ -791,24 +811,6 @@ 配方Id - - - 名 称 :设备 - 创 建 人 :yangxiao - 创建时间 :2023/3/2 13:51:45 - 描 述 : - - - - - 名称 - - - - - 编码 - - 名 称 :码表数据 @@ -883,34 +885,6 @@ 介绍 - - - 名 称 :物料 - 创 建 人 :yangxiao - 创建时间 :2023/3/2 13:52:00 - 描 述 : - - - - - 名称 - - - - - 编码 - - - - - 单位 - - - - - 每秒出水量(g) - - 名 称 : @@ -1113,6 +1087,26 @@ 设备名称 + + + 日期 + + + + + 时间 + + + + + 创建时间 + + + + + 类型 + + 名 称 :程序日志 @@ -1131,6 +1125,21 @@ 日志消息 + + + 日期 + + + + + 时间 + + + + + 日志消息 + + 名 称 :运行日志 @@ -1149,6 +1158,21 @@ 日志消息 + + + 日期 + + + + + 时间 + + + + + 日志消息 + + 名 称 :用户日志 @@ -1172,6 +1196,11 @@ 日志消息 + + + 日志时间 + + 状态 @@ -1347,6 +1376,14 @@ 父级模块 + + + 执行操作前后 + + + + + 名 称 :接口AOP @@ -1389,7 +1426,7 @@ 描 述 : - + Mqtt通用服务 @@ -1399,6 +1436,16 @@ code + + + reason_code + + + + + + + 消息内容 @@ -1640,7 +1687,7 @@ - + 任务状态 @@ -1808,128 +1855,175 @@ 1) 辊筒货位到货位搬运 - + - 名 称 :AGV线路管理 - 创 建 人 :yangxiao - 创建时间 : 2023/8/7 10:03:21 - 描 述 : + 是否成功 - + - 增加 + 状态码 - - - + - 删除 + 消息 - - - - + - 详情 + 返回数据数组 - - - - + - 列表 + 状态码 - - - + - 分页 + 消息体 - - - + - 下拉 + 任务编号 - - - + - 更新 + AGV请求 - - - - + - 下发任务 + 快仓api地址 - - - + - 取消任务 + 任务编码 - - - + - + 仓库编码 默认值1 - - - + - 任务回调 + 优先级 0-99 越高越先执行 + + + + + 任务下发起止点信息 + + + + + 用户自定义信息编号 + + + + + 起点点位 + + + + + 终点点位 + + + + + 上料方式 自动/人工 + + + + + 上料交互方式 //接口对接 false + + + + + 下料方式 true自动/false人工 + + + + + 接口对接 false + + + + + 起点设备ID + + + + + 目标设备ID + + + + + 名 称 :AGV线路管理 + 创 建 人 :yangxiao + 创建时间 : 2023/8/7 10:03:21 + 描 述 : + + + + + 增加 - + - AGV上下料交互请求 + 删除 + - + - 下发任务 + 详情 - + + - + - 取消任务 + 列表 - + - + - 任务回调 + 分页 - + - AGV上下料交互请求 + 下拉 + + + + + + + 更新 + @@ -1991,6 +2085,46 @@ + + + AGV第三方api + + + + + 下发任务 + + + + + + + 取消任务 + + + + + + + 上下料反馈给AGV接口 + + + + + + + 任务反馈(暴露给AGV厂商) + + + + + + + AGV上下料交互请求 (暴露给AGV厂商) + + + + 名 称 : @@ -2081,6 +2215,41 @@ + + + 下发任务 + + + + + + + 取消任务 + + + + + + + 任务回调 + + + + + + + AGV上下料交互请求 + + + + + + + 上下料反馈给AGV接口 + + + + 名 称 : @@ -4560,11 +4729,31 @@ 报警等级 + + + 类型 + + 设备名称 + + + 日期 + + + + + 时间 + + + + + 日志消息 + + 增加 @@ -4620,6 +4809,16 @@ 设备名称 + + + 开始时间 + + + + + 结束时间 + + 输出 @@ -4648,6 +4847,21 @@ 日志消息 + + + 日期 + + + + + 时间 + + + + + 日志消息 + + 增加 @@ -4693,6 +4907,16 @@ 日志消息 + + + 开始时间 + + + + + 结束时间 + + 输出 @@ -4721,6 +4945,21 @@ 日志消息 + + + 日期 + + + + + 时间 + + + + + 日志消息 + + 增加 @@ -4766,6 +5005,16 @@ 日志消息 + + + 开始时间 + + + + + 结束时间 + + 输出 @@ -4799,6 +5048,11 @@ 日志消息 + + + 日志时间 + + 增加 @@ -5272,12 +5526,17 @@ - + 原料分组 + + + 每升重量 + + 增加 @@ -5333,6 +5592,11 @@ + + + 类型名称 + + 名 称 :物料服务 @@ -5711,6 +5975,21 @@ 产线设备 + + + 产线设备不分页 + + + + + 名称 + + + + + 产线Id + + 产线设备分页 @@ -5859,6 +6138,26 @@ 产线设备 + + + 产线设备不分页 + + + + + 名称 + + + + + 产线Id + + + + + 物料Id + + 产线设备分页 @@ -5894,6 +6193,11 @@ 主键 + + + 产线名称 + + 名称 @@ -5905,6 +6209,16 @@ 编码 + + + 物料信息 + + + + + 物料名称 + + 名 称 :分组信息 @@ -6078,7 +6392,7 @@ - + 产线设备不分页 @@ -6102,7 +6416,7 @@ - + 产线料仓不分页 @@ -6186,7 +6500,7 @@ - + 产线设备不分页 @@ -6210,7 +6524,7 @@ - + 产线料仓不分页 @@ -6968,6 +7282,11 @@ 产量 + + + 设备id + + 创建时间 @@ -7083,6 +7402,16 @@ 线名称 + + + 设备编码 + + + + + 设备名称 + + 工单状态 @@ -7189,6 +7518,51 @@ 描 述 : + + + 物料名称 + + + + + 物料id + + + + + 工单id + + + + + 重量 + + + + + 第几锅 + + + + + 配方Id + + + + + 配方名称 + + + + + 物料状态 + + + + + 更新时间 + + 增加 @@ -7234,6 +7608,21 @@ 主键 + + + 物料类型 + + + + + 物料类型名称 + + + + + 每升重量 + + 名 称 :工单状态 @@ -7257,6 +7646,11 @@ 创建时间 + + + 备注 + + 增加 @@ -7277,6 +7671,11 @@ 状态 + + + 备注 + + 删除 @@ -7292,6 +7691,21 @@ 分页 + + + 下发 + + + + + 工单ID + + + + + 设备ID + + 输出 @@ -7302,6 +7716,11 @@ 主键 + + + 状态名称 + + 名 称 :工单服务 @@ -7359,11 +7778,11 @@ - + 工单下发 - 工单Id + 工单Id @@ -7447,11 +7866,11 @@ - + 工单下发 - 工单id + 工单id @@ -7514,6 +7933,83 @@ 描 述 : + + + 系统缓存服务 + + + + + 获取所有缓存关键字 + + + + + + 删除指定关键字缓存 + + + + + + + 删除某特征关键字缓存 + + + + + + + 设置缓存 + + + + + + + + 设置缓存 + + + + + + + + 获取缓存 + + + + + + + 获取缓存 + + + + + + + + 检查给定 key 是否存在 + + 键 + + + + + 增加缓存Key + + + + + + + + + + + [账号信息]入参基础 diff --git a/backend/BPA.MES.Base.Application/Const/ClaimConst.cs b/backend/BPA.MES.Base.Application/Const/ClaimConst.cs index e3a9f13..67d1454 100644 --- a/backend/BPA.MES.Base.Application/Const/ClaimConst.cs +++ b/backend/BPA.MES.Base.Application/Const/ClaimConst.cs @@ -64,6 +64,10 @@ /// 是否是管理员 /// public const bool ISADMIN = false; + /// + /// 所有缓存关键字集合 + /// + public const string CACHE_KEY_ALL = "allkey"; } public class MQTTConfig diff --git a/backend/BPA.MES.Base.Application/Entitys/App/Pztj_MaterialsInfoEntity.cs b/backend/BPA.MES.Base.Application/Entitys/App/Pztj_MaterialsInfoEntity.cs index 2acd5d6..c80edb4 100644 --- a/backend/BPA.MES.Base.Application/Entitys/App/Pztj_MaterialsInfoEntity.cs +++ b/backend/BPA.MES.Base.Application/Entitys/App/Pztj_MaterialsInfoEntity.cs @@ -24,6 +24,11 @@ /// /// 原料分组 /// - public string Gourp { get; set; } + public string Type { get; set; } + /// + /// 每升重量 + /// + [SugarColumn(IsNullable = true)] + public string WeightPerLiter { get; set; } } } diff --git a/backend/BPA.MES.Base.Application/Entitys/App/Pztj_WorkInfoEntity.cs b/backend/BPA.MES.Base.Application/Entitys/App/Pztj_WorkInfoEntity.cs index c59fc46..b7c9372 100644 --- a/backend/BPA.MES.Base.Application/Entitys/App/Pztj_WorkInfoEntity.cs +++ b/backend/BPA.MES.Base.Application/Entitys/App/Pztj_WorkInfoEntity.cs @@ -23,12 +23,17 @@ /// public string FinalId { get; set; } /// + /// 指定设备Id + /// + [SugarColumn(IsNullable = true)] + public string DeviceId { get; set; } + /// /// 产量 /// public string Number { get;set; } /// /// 创建时间 /// - public string CreateTime { get; set; } + public DateTime CreateTime { get; set; } } } diff --git a/backend/BPA.MES.Base.Application/Entitys/App/Pztj_WorkInfoStatusEntity.cs b/backend/BPA.MES.Base.Application/Entitys/App/Pztj_WorkInfoStatusEntity.cs index 59a680b..bbad5c8 100644 --- a/backend/BPA.MES.Base.Application/Entitys/App/Pztj_WorkInfoStatusEntity.cs +++ b/backend/BPA.MES.Base.Application/Entitys/App/Pztj_WorkInfoStatusEntity.cs @@ -21,5 +21,9 @@ /// 创建时间 /// public DateTime CreateTime { get; set; } + /// + /// 备注 + /// + public string Remark { get; set; } } } diff --git a/backend/BPA.MES.Base.Application/Entitys/Base/DevicesInfoEntity.cs b/backend/BPA.MES.Base.Application/Entitys/Base/DevicesInfoEntity.cs deleted file mode 100644 index a233b87..0000000 --- a/backend/BPA.MES.Base.Application/Entitys/Base/DevicesInfoEntity.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace BPA.MES.Base.Application.Entitys -{ - /// - /// 名 称 :设备 - /// 创 建 人 :yangxiao - /// 创建时间 :2023/3/2 13:51:45 - /// 描 述 : - /// - [SugarTable("devices_info")] - public class DevicesInfoEntity: DEntityBase - { - /// - /// 名称 - /// - [Required(ErrorMessage = "名称不能为空")] - public string Name { get; set; } - /// - /// 编码 - /// - [Required(ErrorMessage = "编码不能为空")] - public string Code { get; set; } - } -} diff --git a/backend/BPA.MES.Base.Application/Entitys/Base/MaterialsInfoEntity.cs b/backend/BPA.MES.Base.Application/Entitys/Base/MaterialsInfoEntity.cs deleted file mode 100644 index 3f8ec05..0000000 --- a/backend/BPA.MES.Base.Application/Entitys/Base/MaterialsInfoEntity.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace BPA.MES.Base.Application.Entitys -{ - /// - /// 名 称 :物料 - /// 创 建 人 :yangxiao - /// 创建时间 :2023/3/2 13:52:00 - /// 描 述 : - /// - [SugarTable("materials_info")] - public class MaterialsInfoEntity: DEntityBase - { - /// - /// 名称 - /// - [Required(ErrorMessage = "名称不能为空")] - public string Name { get; set; } - /// - /// 编码 - /// - [Required(ErrorMessage = "编码不能为空")] - public string Code { get; set; } - /// - /// 单位 - /// - public string Unit { get; set; } - /// - /// 每秒出水量(g) - /// - public string Wos { get; set; } - } -} diff --git a/backend/BPA.MES.Base.Application/Entitys/Logs/AlarmLogEntity.cs b/backend/BPA.MES.Base.Application/Entitys/Logs/AlarmLogEntity.cs index b9b9746..eb9a200 100644 --- a/backend/BPA.MES.Base.Application/Entitys/Logs/AlarmLogEntity.cs +++ b/backend/BPA.MES.Base.Application/Entitys/Logs/AlarmLogEntity.cs @@ -6,7 +6,7 @@ /// 创建时间 : 2023/8/21 10:17:57 /// 描 述 : /// - [SugarTable("alarm_log")] + [SugarTable("alarm")] public class AlarmLogEntity : DEntityBase { /// @@ -14,23 +14,41 @@ /// [SugarColumn(IsNullable = true)] public string MsgInfo { get; set; } - /// /// 报警值 /// [SugarColumn(IsNullable = true)] public string Value { get; set; } - /// /// 报警等级 /// [SugarColumn(IsNullable = true)] public string Grade { get; set; } - /// /// 设备名称 /// [SugarColumn(IsNullable = true)] public string DeviceName { get; set; } + /// + /// 日期 + /// + [SugarColumn(IsNullable = true)] + public string Date { get; set; } + /// + /// 时间 + /// + [SugarColumn(IsNullable = true)] + public string Time { get; set; } + /// + /// 创建时间 + /// + [SugarColumn(IsNullable = true)] + public DateTime CreateDate { get; set; } + /// + /// 类型 + /// + [SugarColumn(IsNullable = true)] + public string LogType { get; set; } + } } diff --git a/backend/BPA.MES.Base.Application/Entitys/Logs/ProgramLogEntity.cs b/backend/BPA.MES.Base.Application/Entitys/Logs/ProgramLogEntity.cs index a996686..8167b9b 100644 --- a/backend/BPA.MES.Base.Application/Entitys/Logs/ProgramLogEntity.cs +++ b/backend/BPA.MES.Base.Application/Entitys/Logs/ProgramLogEntity.cs @@ -6,7 +6,7 @@ /// 创建时间 : 2023/8/21 10:18:13 /// 描 述 : /// - [SugarTable("program_log")] + [SugarTable("programlog")] public class ProgramLogEntity : DEntityBase { /// @@ -20,5 +20,21 @@ /// [SugarColumn(IsNullable = true)] public string MsgInfo { get; set; } + /// + /// 日期 + /// + [SugarColumn(IsNullable = true)] + public string Date { get; set; } + /// + /// 时间 + /// + [SugarColumn(IsNullable = true)] + public string Time { get; set; } + /// + /// 日志消息 + /// + [SugarColumn(IsNullable = true)] + public DateTime CreateDate { get; set; } + } } diff --git a/backend/BPA.MES.Base.Application/Entitys/Logs/RunLogEntity.cs b/backend/BPA.MES.Base.Application/Entitys/Logs/RunLogEntity.cs index 57af863..6c66919 100644 --- a/backend/BPA.MES.Base.Application/Entitys/Logs/RunLogEntity.cs +++ b/backend/BPA.MES.Base.Application/Entitys/Logs/RunLogEntity.cs @@ -6,7 +6,7 @@ /// 创建时间 : 2023/8/21 10:18:34 /// 描 述 : /// - [SugarTable("run_log")] + [SugarTable("runlog")] public class RunLogEntity : DEntityBase { /// @@ -14,11 +14,25 @@ /// [SugarColumn(IsNullable = true)] public string LogType { get; set; } - /// /// 日志消息 /// [SugarColumn(IsNullable = true)] public string MsgInfo { get; set; } + /// + /// 日期 + /// + [SugarColumn(IsNullable = true)] + public string Date { get; set; } + /// + /// 时间 + /// + [SugarColumn(IsNullable = true)] + public string Time { get; set; } + /// + /// 日志消息 + /// + [SugarColumn(IsNullable = true)] + public DateTime CreateDate { get; set; } } } diff --git a/backend/BPA.MES.Base.Application/Entitys/Logs/UserLogEntity.cs b/backend/BPA.MES.Base.Application/Entitys/Logs/UserLogEntity.cs index ff26ef6..06f9db3 100644 --- a/backend/BPA.MES.Base.Application/Entitys/Logs/UserLogEntity.cs +++ b/backend/BPA.MES.Base.Application/Entitys/Logs/UserLogEntity.cs @@ -26,5 +26,11 @@ /// [SugarColumn(IsNullable = true)] public string MsgInfo { get; set; } + + /// + /// 日志时间 + /// + [SugarColumn(IsNullable = true)] + public DateTime CreateDate { get; set; } } } diff --git a/backend/BPA.MES.Base.Application/Filters/AGVAttribute.cs b/backend/BPA.MES.Base.Application/Filters/AGVAttribute.cs new file mode 100644 index 0000000..dfdff3e --- /dev/null +++ b/backend/BPA.MES.Base.Application/Filters/AGVAttribute.cs @@ -0,0 +1,39 @@ +using BPA.MES.Base.Application.Services; +using BPA.MES.Base.Application.Services.AGVService.Dtos; +using Furion.JsonSerialization; +using Microsoft.AspNetCore.Mvc.Filters; +using System.Diagnostics; + +namespace BPA.MES.Base.Application +{ + public class AGVAttribute : ActionFilterAttribute + { + /// + /// 执行操作前后 + /// + /// + /// + /// + public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) + { + // 获取 HttpContext 和 HttpRequest 对象 + var httpContext = context.HttpContext; + var httpRequest = httpContext.Request; + var sw = new Stopwatch(); + sw.Start(); + var actionContext = await next(); + sw.Stop(); + var server = App.GetService(); + var contentstring = JSON.Serialize(context.ActionArguments["input"]); + AGVLoadAndUnloadRequest input = JSON.Deserialize(contentstring); + Roller_JobRequest roller_Job = new() + { + AgvCode = input.Body.Event.agvCode, + Complete = true, + JobId = input.Body.Event.jobId, + MsgId = input.Body.Event.msgId + }; + await server.RollerJobExecute(roller_Job); + } + } +} diff --git a/backend/BPA.MES.Base.Application/Filters/OperLogAttribute .cs b/backend/BPA.MES.Base.Application/Filters/OperLogAttribute.cs similarity index 100% rename from backend/BPA.MES.Base.Application/Filters/OperLogAttribute .cs rename to backend/BPA.MES.Base.Application/Filters/OperLogAttribute.cs diff --git a/backend/BPA.MES.Base.Application/MQTT/MQTTService.cs b/backend/BPA.MES.Base.Application/MQTT/MQTTService.cs index cd61c89..9bd2368 100644 --- a/backend/BPA.MES.Base.Application/MQTT/MQTTService.cs +++ b/backend/BPA.MES.Base.Application/MQTT/MQTTService.cs @@ -11,12 +11,14 @@ namespace BPA.MES.Base.Application /// 创建时间 : 2022/11/18 15:38:40 /// 描 述 : /// - public class MQTTService : IMQTTService, ITransient + public class MQTTService : IMQTTService, ITransient, IDynamicApiController { private readonly ISqlSugarClient _dbContext; - public MQTTService(ISqlSugarClient db) + ISysCacheService _sysCacheService; + public MQTTService(ISqlSugarClient db, ISysCacheService sysCacheService) { _dbContext = db; + _sysCacheService = sysCacheService; } public async Task GetMQTTConfig() { @@ -26,49 +28,90 @@ namespace BPA.MES.Base.Application MQTTConfig.Address = entity.Address; MQTTConfig.Account = entity.Account; MQTTConfig.Pwd = entity.Pwd; + await _sysCacheService.SetAsync("mqtt", entity); } } /// /// Mqtt通用服务 /// - public async Task MqttPublish(IMessage payload, string topic,int messageId) + public async Task MqttPublish(MqttPublishDto input) + { + bool result = false; + MQTTInfoEntity mqttentity = new(); + mqttentity = await _sysCacheService.GetAsync("mqtt"); + if (mqttentity==null) + { + mqttentity = await _dbContext.Queryable().FirstAsync(); + await _sysCacheService.SetAsync("mqtt", mqttentity); + } + try + { + input.Payload.MessageId = input.MessageId; + input.Payload.MsgVersion = new Version(1, 0, 0, 0); + MsgPackage mp = new() + { + Message = input.Payload, + MessageLen = JSON.Serialize(input.Payload).Length + }; + //组装MQTT消息 + var tem = await $"http://{mqttentity.Address}/api/v5/publish".SetHeaders(new + { + Authorization = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes($"{mqttentity.Account}:{mqttentity.Pwd}")) + }).SetBody(new + { + input.Topic, + payload = JsonConvert.SerializeObject(mp), + qos = 2, + retain = false, + clientid = "pztj_service" + }).PostAsStringAsync(); + var res = JSON.Deserialize(tem); + if (res.Code == 0 || res.Reason_code<100 || !string.IsNullOrEmpty(res.Id)) + { + result = true; + } + Console.WriteLine($"_____________________MQTT发消息:{JsonConvert.SerializeObject(mp)}"); + } + catch + { + + } + + return result; + } + [AllowAnonymous] + public async Task MqttTestPublish(string topic, string msg) { bool result = false; var mqttentity = await _dbContext.Queryable().FirstAsync(); string mqttAddress = mqttentity.Address; try { - payload.MessageId = messageId; - payload.MsgVersion = new Version(1, 0, 0, 0); - MsgPackage mp = new MsgPackage(); - mp.Message = payload; - mp.MessageLen = JSON.Serialize(payload).Length; //组装MQTT消息 - var tem = await $"http://{mqttAddress}/api/v4/mqtt/publish".SetHeaders(new + var tem = await $"http://{mqttAddress}/api/v5/publish".SetHeaders(new { Authorization = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes($"{mqttentity.Account}:{mqttentity.Pwd}")) }).SetBody(new { topic, - payload = JsonConvert.SerializeObject(mp), + payload = msg, qos = 2, retain = false, clientid = "pztj_service" }).PostAsStringAsync(); var res = JSON.Deserialize(tem); - if (res.Code == 0) + if (res.Code == 0 || res.Reason_code < 100 || !string.IsNullOrEmpty(res.Id)) { result = true; } } catch { - + } return result; } - } public class MqttResult @@ -77,11 +120,25 @@ namespace BPA.MES.Base.Application /// code /// public int Code { get; set; } + /// + /// reason_code + /// + public int Reason_code { get; set; } + /// + /// + /// + public string Id { get; set; } } + public class MqttPublishDto + { + public IMessage Payload { get; set; } + public string Topic { get; set; } + public int MessageId { get; set; } + } public interface IMQTTService { - Task MqttPublish(IMessage payload, string topic, int messageId); + Task MqttPublish(MqttPublishDto input); Task GetMQTTConfig(); } diff --git a/backend/BPA.MES.Base.Application/Services/AGVService/Dtos/AGVThirdPartyDto.cs b/backend/BPA.MES.Base.Application/Services/AGVService/Dtos/AGVThirdPartyDto.cs index 4f6f0ec..3ed7710 100644 --- a/backend/BPA.MES.Base.Application/Services/AGVService/Dtos/AGVThirdPartyDto.cs +++ b/backend/BPA.MES.Base.Application/Services/AGVService/Dtos/AGVThirdPartyDto.cs @@ -1,4 +1,5 @@ -using System; +using BPA.AGV; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -7,10 +8,37 @@ using System.Threading.Tasks; namespace BPA.MES.Base.Application.Services.AGVService.Dtos { + public class Roller_JobRequest + { + public string Url { get; set; } + + [Required(ErrorMessage = "[{0}]不能为空")] + [MaxLength(64, ErrorMessage = "[{0}]不能超过64字符")] + public string AgvCode { get; set; } + + [Required(ErrorMessage = "[{0}]不能为空")] + [MaxLength(64, ErrorMessage = "[{0}]不能超过64字符")] + public string JobId { get; set; } + + [Required(ErrorMessage = "[{0}]不能为空")] + [MaxLength(64, ErrorMessage = "[{0}]不能超过64字符")] + public string MsgId { get; set; } + + public bool? Complete { get; set; } + } + public class AGVExecuteReplyRequest + { + public AgvHeader Header { get; set; } + public AgvReplyBody Body { get; set; } + } + + public class AgvReplyBody { public AGVExecuteReplyDto Event { get; set; } } + + public class AGVExecuteReplyMQTT: IMessage { public AGVExecuteReplyDto Event { get; set; } @@ -19,6 +47,12 @@ namespace BPA.MES.Base.Application.Services.AGVService.Dtos } public class AGVLoadAndUnloadRequest + { + public AgvHeader Header { get; set; } + public AGVLoadAndUnloadBody Body { get; set; } + } + + public class AGVLoadAndUnloadBody { public AGVLoadAndUnloadDto Event { get; set; } } @@ -30,6 +64,28 @@ namespace BPA.MES.Base.Application.Services.AGVService.Dtos public Version MsgVersion { get; set; } } + public class AgvBody + { + public AgvHeader Header { get; set; } + public AgvRetrun Body { get; set; } + } + public class AgvHeader + { + public string RequestId { get; set; } + public string Timestamp { get; set; } + public string Version { get; set; } + } + public class AgvRetrun + { + public string Code { get; set; } + + public bool Success { get; set; } + + public string Message { get; set; } + + public object? Data { get; set; } + } + /// /// 任务完成回报Dto /// @@ -51,7 +107,7 @@ namespace BPA.MES.Base.Application.Services.AGVService.Dtos public string jobId { get; set; } /// - /// + /// 任务状态 /// public string state { get; set; } @@ -275,4 +331,143 @@ namespace BPA.MES.Base.Application.Services.AGVService.Dtos POINT_ROLLER_MOVE=2 } + public class KC_Response + { + public KC_Response() + { + Data = new(); + } + /// + /// 是否成功 + /// + public bool Success { get; set; } + /// + /// 状态码 + /// + public string Code { get; set; } + /// + /// 消息 + /// + public string Message { get; set; } + /// + /// 返回数据数组 + /// + public List Data { get; set; } + } + public class KC_Response_Data + { + /// + /// 状态码 + /// + public string Code { get; set; } + /// + /// 消息体 + /// + public string Message { get; set; } + /// + /// 任务编号 + /// + public string RobotJobId { get; set; } + } + /// + /// AGV请求 + /// + public class KC_ExecuteRequest + { + /// + /// 快仓api地址 + /// + public string Url { get; set; } + /// + /// 任务编码 + /// + public string RobotJobId { get; set; } + /// + /// 仓库编码 默认值1 + /// + public long WarehouseId { get; set; } = 1; + + public string RobotJobGroupId { get; set; } + + public int? Sequence { get; set; } + + public string RobotJobGroupNum { get; set; } + /// + /// 优先级 0-99 越高越先执行 + /// + public int? JobPriority { get; set; } + + public int? JobPriorityType { get; set; } + + public string Deadline { get; set; } + + public string AgvType { get; set; } + + public string AgvEndPoint { get; set; } + + public bool NeedOperation { get; set; } + + public string AgvCode { get; set; } + + public int? TaskCountDown { get; set; } = 0; + public string BusinessType { get; set; } + [Required(ErrorMessage = "[{0}]不能为空")] + [MaxLength(64, ErrorMessage = "[{0}]不能超过64字符")] + //任务类型 用来滚筒点对点 POINT_ROLLER_MOVE n8H7jX + public string JobType { get; set; } = "POINT_ROLLER_MOVE"; + [Required(ErrorMessage = "[{0}]不能为空")] + public KC_JobDataRequest? JobData { get; set; } + } + /// + /// 任务下发起止点信息 + /// + public class KC_JobDataRequest + { + /// + /// 用户自定义信息编号 + /// + public string ContainerCode { get; set; } + /// + /// 起点点位 + /// + [Required(ErrorMessage = "[{0}]不能为空")] + [MaxLength(64, ErrorMessage = "[{0}]不能超过64字符")] + public string StartPoint { get; set; } + /// + /// 终点点位 + /// + [Required(ErrorMessage = "[{0}]不能为空")] + [MaxLength(64, ErrorMessage = "[{0}]不能超过64字符")] + public string EndPoint { get; set; } + /// + /// 上料方式 自动/人工 + /// + public bool? AutoLoad { get; set; } + /// + /// 上料交互方式 //接口对接 false + /// + public bool? EnableIOLoad { get; set; } = false; + /// + /// 下料方式 true自动/false人工 + /// + public bool? AutoUnload { get; set; } + /// + /// 接口对接 false + /// + public bool? EnableIOUnload { get; set; } = false; + /// + /// 起点设备ID + /// + public long LoadEquipmentId { get; set; } + /// + /// 目标设备ID + /// + public long UnloadEquipmentId { get; set; } + + public long LoadInteractive { get; set; } + + public long LoadHeight { get; set; } + + public long UnloadHeight { get; set; } + } } diff --git a/backend/BPA.MES.Base.Application/Services/AGVService/Services/AGVThirdPartyService.cs b/backend/BPA.MES.Base.Application/Services/AGVService/Services/AGVThirdPartyService.cs index 6662673..7777e04 100644 --- a/backend/BPA.MES.Base.Application/Services/AGVService/Services/AGVThirdPartyService.cs +++ b/backend/BPA.MES.Base.Application/Services/AGVService/Services/AGVThirdPartyService.cs @@ -1,24 +1,21 @@ using BPA.AGV; using BPA.MES.Base.Application.Services.AGVService.Dtos; -using MQTTnet.Client; -using MQTTnet.Client.Publishing; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Furion.EventBus; +using Furion.JsonSerialization; +using Furion.RemoteRequest.Extensions; -namespace BPA.MES.Base.Application.Services.AGVService.Services +namespace BPA.MES.Base.Application.Services { - + /// + /// AGV第三方api + /// [AllowAnonymous, NonUnify] [ApiDescriptionSettings("AGV管理", Name = "AgvThirdParty", Tag = "AGV第三方api", KeepName = true, SplitCamelCase = true, KeepVerb = true)] - public class AGVThirdPartyService:IAGVThirdPartyService, ITransient, IDynamicApiController + public class AGVThirdPartyService : IAGVThirdPartyService, ITransient, IDynamicApiController { private readonly AGVHandler _aGVHandler; private readonly IMQTTService _MQTTService; - public AGVThirdPartyService(AGVHandler aGVHandler, IMQTTService MQTTService) + public AGVThirdPartyService(AGVHandler aGVHandler, IMQTTService MQTTService) { _aGVHandler = aGVHandler; _MQTTService = MQTTService; @@ -27,98 +24,147 @@ namespace BPA.MES.Base.Application.Services.AGVService.Services /// /// 下发任务 /// - /// + /// /// [HttpPost] - public async Task ExecuteAsync(KCExecuteRequest cExecuteRequest) + public async Task Execute(KC_ExecuteRequest input) { - - if (cExecuteRequest.JobData != null) - cExecuteRequest = new KCExecuteRequest + List cExecuteRequests = new(); + if (string.IsNullOrEmpty(input.RobotJobId)) + { + throw Oops.Bah("任务编号不能为空"); + } + if (input.JobData != null) + input = new KC_ExecuteRequest { - Url = cExecuteRequest.Url,//http://[IP:Port]/api/quicktron/wcs/standardized.robot.job.submit - RobotJobId = Guid.NewGuid().ToString(), - WarehouseId = cExecuteRequest.WarehouseId, - JobPriority = cExecuteRequest.JobPriority, - JobPriorityType = cExecuteRequest.JobPriorityType, - JobData = new KCJobDataRequest + Url = string.IsNullOrEmpty(input.Url) ? App.GetConfig("AGVUrl")+"/api/quicktron/wcs/standardized.robot.job.submit": input.Url + "/api/quicktron/wcs/standardized.robot.job.submit", + RobotJobId = input.RobotJobId,//任务号 + WarehouseId = input.WarehouseId,//仓库编码 默认值1 + JobPriority = input.JobPriority, //优先级 0-99 越高越先执行 + JobPriorityType = input.JobPriorityType, //优先级类型 0 普通和1 强制. + JobType = input.JobType,//任务类型 用来滚筒点对点 POINT_ROLLER_MOVE n8H7jX + JobData = new KC_JobDataRequest { - StartPoint = cExecuteRequest.JobData.StartPoint, - - EndPoint = cExecuteRequest.JobData.EndPoint, + StartPoint = input.JobData.StartPoint, //起点 + EndPoint = input.JobData.EndPoint,//终点 + ContainerCode = input.JobData.ContainerCode,//桶号 + AutoLoad = input.JobData.AutoLoad,//上料方式 自动/人工 + EnableIOLoad = input.JobData.EnableIOLoad,//上料交互方式 //接口对接 false + AutoUnload = input.JobData.AutoUnload,//下料方式 true自动/false人工 + EnableIOUnload = input.JobData.EnableIOUnload,//接口对接 false + LoadEquipmentId = input.JobData.LoadEquipmentId,//起点设备ID + UnloadEquipmentId = input.JobData.UnloadEquipmentId,//目标设备ID } }; - return await _aGVHandler.ExecuteAsync(cExecuteRequest); + cExecuteRequests.Add(input); + try + { + Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:{input.RobotJobId}接收到下发任务!"); + var res = await input.Url.SetBody(cExecuteRequests).PostAsStringAsync(); + return JSON.Deserialize(res); + } + catch (Exception ex) + { + throw Oops.Bah(ex.Message); + } } - /// /// 取消任务 /// /// /// [HttpPost] - public async Task CancelAsync(KCCancelRequest kCCancelRequest) + public async Task Cancel(KCCancelRequest kCCancelRequest) { - //http://[IP:Port]/api/quicktron/wcs/standardized.robot.job.cancel + kCCancelRequest.Url = string.IsNullOrEmpty(kCCancelRequest.Url) ? App.GetConfig("AGVUrl") + "/api/quicktron/wcs/standardized.robot.job.cancel" : kCCancelRequest.Url + "/api/quicktron/wcs/standardized.robot.job.cancel"; return await _aGVHandler.CancelAsync(kCCancelRequest); } - /// - /// + /// 上下料反馈给AGV接口 /// - /// + /// /// - public async Task RollerJobExecuteAsync(RollerJobRequest rollerJobRequest) + public async Task RollerJobExecute(Roller_JobRequest input) { //http://[IP:Port]/api/quicktron/wcs/standardized.roller.job.upstream.response - return await _aGVHandler.RollerJobExecuteAsync(rollerJobRequest); + input.Url = string.IsNullOrEmpty(input.Url) ? App.GetConfig("AGVUrl") + "/api/quicktron/wcs/standardized.roller.job.upstream.response": input.Url+ "/api/quicktron/wcs/standardized.roller.job.upstream.response"; + try + { + var res = await input.Url.SetBody(input).PostAsStringAsync(); + Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:{input.JobId}上下料反馈给AGV接口!{res}"); + return JSON.Deserialize(res); + } + catch (Exception ex) + { + return new RollerJobResponse() { Success = false }; + } } - /// - /// 任务回调 + /// 任务反馈(暴露给AGV厂商) /// /// /// [HttpPost] - public async Task ExecuteReplyAsync(AGVExecuteReplyRequest input) + public async Task ExecuteReply(AGVExecuteReplyRequest input) { try { - var data = new AGVExecuteReplyMQTT() { - Event = input.Event, + Event = input.Body.Event, }; - return await _MQTTService.MqttPublish(data, Topics.ExecuteReplyTopic, MessageID.TaskState); + bool res = await _MQTTService.MqttPublish(new MqttPublishDto(){ Payload= data, Topic = Topics.ExecuteReplyTopic, MessageId = MessageID.TaskState }); + Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:接收到AGV反馈请求!", res.ToString()); + AgvBody agvBody = new() + { + Header = input.Header, + Body = new AgvRetrun { Code = "SUCCESS", Success = res, Message = "SUCCESS", Data = null } + }; + Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:AGV反馈消息!{JSON.Serialize(agvBody)}"); + return agvBody; } - catch (Exception e) + catch (Exception ex) { - return false; + AgvBody agvBody = new() + { + Header = input.Header, + Body = new AgvRetrun { Code = "SUCCESS", Success = false, Message = ex.Message, Data = null } + }; + return agvBody; } } - - /// - /// AGV上下料交互请求 + /// AGV上下料交互请求 (暴露给AGV厂商) /// /// /// - [HttpPost] - public async Task LoadAndUnloadAsync(AGVLoadAndUnloadRequest input) + [HttpPost, AGV] + public async Task LoadAndUnload(AGVLoadAndUnloadRequest input) { try { var data = new AGVLoadAndUnloadMQTT() { - Event = input.Event, + Event = input.Body.Event, + }; + bool res = await _MQTTService.MqttPublish(new MqttPublishDto() { Payload= data, Topic = Topics.LoadAndUnloadTopic, MessageId = MessageID.LoadAndUnload }); + Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:接收到AGV上下料交互请求!{res.ToString()}"); + AgvBody agvBody = new() + { + Header = input.Header, + Body = new AgvRetrun { Code = "SUCCESS", Success = res, Message = "SUCCESS", Data = null } }; - return await _MQTTService.MqttPublish(data, Topics.LoadAndUnloadTopic, MessageID.LoadAndUnload); + return agvBody; } - catch (Exception e) + catch (Exception ex) { - return false; + AgvBody agvBody = new() + { + Header = input.Header, + Body = new AgvRetrun { Code = "SUCCESS", Success = false, Message = ex.Message, Data = null } + }; + return agvBody; } } - } } diff --git a/backend/BPA.MES.Base.Application/Services/AGVService/Services/IAGVThirdPartyService.cs b/backend/BPA.MES.Base.Application/Services/AGVService/Services/IAGVThirdPartyService.cs index 7f07cd8..4849af8 100644 --- a/backend/BPA.MES.Base.Application/Services/AGVService/Services/IAGVThirdPartyService.cs +++ b/backend/BPA.MES.Base.Application/Services/AGVService/Services/IAGVThirdPartyService.cs @@ -1,12 +1,7 @@ using BPA.AGV; using BPA.MES.Base.Application.Services.AGVService.Dtos; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace BPA.MES.Base.Application.Services.AGVService.Services +namespace BPA.MES.Base.Application.Services { public interface IAGVThirdPartyService { @@ -14,31 +9,32 @@ namespace BPA.MES.Base.Application.Services.AGVService.Services /// /// 下发任务 /// - /// + /// /// - Task ExecuteAsync(KCExecuteRequest cExecuteRequest); - + Task Execute(KC_ExecuteRequest input); /// /// 取消任务 /// /// /// - Task CancelAsync(KCCancelRequest kCCancelRequest); - - + Task Cancel(KCCancelRequest kCCancelRequest); /// /// 任务回调 /// /// /// - Task ExecuteReplyAsync(AGVExecuteReplyRequest input); - - + Task ExecuteReply(AGVExecuteReplyRequest input); /// /// AGV上下料交互请求 /// /// /// - Task LoadAndUnloadAsync(AGVLoadAndUnloadRequest input); + Task LoadAndUnload(AGVLoadAndUnloadRequest input); + /// + /// 上下料反馈给AGV接口 + /// + /// + /// + Task RollerJobExecute(Roller_JobRequest input); } } diff --git a/backend/BPA.MES.Base.Application/Services/CraftsInfoService/Services/CraftsInfoService.cs b/backend/BPA.MES.Base.Application/Services/CraftsInfoService/Services/CraftsInfoService.cs index 99dd664..1e8301f 100644 --- a/backend/BPA.MES.Base.Application/Services/CraftsInfoService/Services/CraftsInfoService.cs +++ b/backend/BPA.MES.Base.Application/Services/CraftsInfoService/Services/CraftsInfoService.cs @@ -39,8 +39,20 @@ [HttpPost] public async Task Del(CraftsInfoDelInput input) { - var res = await _dbContext.Deleteable().Where(x=>x.Id==input.Id).ExecuteCommandHasChangeAsync(); - return res; + //事务,删除所有子表 + try + { + _dbContext.Ado.BeginTran(); + await _dbContext.Deleteable().Where(x => x.Id == input.Id).ExecuteCommandAsync(); + await _dbContext.Deleteable().Where(x => x.CraftId == input.Id).ExecuteCommandAsync(); + _dbContext.Ado.CommitTran(); + } + catch (Exception ex) + { + _dbContext.Ado.RollbackTran(); + throw Oops.Bah("删除失败!"); + } + return true; } /// /// 详情 diff --git a/backend/BPA.MES.Base.Application/Services/DeviceProductService/Services/DeviceProductFunctionService.cs b/backend/BPA.MES.Base.Application/Services/DeviceProductService/Services/DeviceProductFunctionService.cs index daab822..a95ba3e 100644 --- a/backend/BPA.MES.Base.Application/Services/DeviceProductService/Services/DeviceProductFunctionService.cs +++ b/backend/BPA.MES.Base.Application/Services/DeviceProductService/Services/DeviceProductFunctionService.cs @@ -22,7 +22,7 @@ [HttpPost] public async Task Add(DeviceProductFunctionAddInput input) { - var r_entity = await _dbContext.Queryable().FirstAsync(x => x.Name == input.Name); + var r_entity = await _dbContext.Queryable().Where(x=>x.DeviceProductId==input.DeviceProductId && x.Name == input.Name).FirstAsync(); if (r_entity != null) { throw Oops.Bah("名称已存在!"); @@ -111,8 +111,16 @@ [HttpPost] public async Task Update(DeviceProductFunctionUpdateInput input) { + + var isEntity = await _dbContext.Queryable() + .Where(x =>x.Id != input.Id && x.DeviceProductId == input.DeviceProductId && x.Name == input.Name).FirstAsync(); + if (isEntity != null) + { + throw Oops.Bah("名称已存在!"); + } var entity = await _dbContext.Queryable().Where(x => x.Id == input.Id).FirstAsync(); entity = input.Adapt(); + var res = await _dbContext.Updateable(entity).IgnoreColumns(true).ExecuteCommandHasChangeAsync(); return res; } diff --git a/backend/BPA.MES.Base.Application/Services/DeviceProductService/Services/DeviceProductService.cs b/backend/BPA.MES.Base.Application/Services/DeviceProductService/Services/DeviceProductService.cs index 2e33825..fcbc849 100644 --- a/backend/BPA.MES.Base.Application/Services/DeviceProductService/Services/DeviceProductService.cs +++ b/backend/BPA.MES.Base.Application/Services/DeviceProductService/Services/DeviceProductService.cs @@ -39,8 +39,20 @@ [HttpPost] public async Task Del(DeviceProductDelInput input) { - var res = await _dbContext.Deleteable().Where(x => x.Id == input.Id).ExecuteCommandHasChangeAsync(); - return res; + //事务,删除所有子表 + try + { + _dbContext.Ado.BeginTran(); + await _dbContext.Deleteable().Where(x => x.Id == input.Id).ExecuteCommandAsync(); + await _dbContext.Deleteable().Where(x => x.DeviceProductId == input.Id).ExecuteCommandAsync(); + _dbContext.Ado.CommitTran(); + } + catch (Exception ex) + { + _dbContext.Ado.RollbackTran(); + throw Oops.Bah("删除失败!"); + } + return true; } /// /// 详情 diff --git a/backend/BPA.MES.Base.Application/Services/LogService/Dtos/AlarmLogDto.cs b/backend/BPA.MES.Base.Application/Services/LogService/Dtos/AlarmLogDto.cs index f270043..66420fd 100644 --- a/backend/BPA.MES.Base.Application/Services/LogService/Dtos/AlarmLogDto.cs +++ b/backend/BPA.MES.Base.Application/Services/LogService/Dtos/AlarmLogDto.cs @@ -12,21 +12,35 @@ /// 报警信息 /// public string MsgInfo { get; set; } - /// /// 报警值 /// public string Value { get; set; } - /// /// 报警等级 /// public string Grade { get; set; } - + /// + /// 类型 + /// + public string LogType { get; set; } /// /// 设备名称 /// public string DeviceName { get; set; } + /// + /// 日期 + /// + public string Date { get; set; } + /// + /// 时间 + /// + public string Time { get; set; } + /// + /// 日志消息 + /// + public DateTime CreateDate { get; set; } + } /// /// 增加 @@ -86,6 +100,14 @@ /// 设备名称 /// public string DeviceName { get; set; } + /// + /// 开始时间 + /// + public DateTime? StartTime { get; set; } + /// + /// 结束时间 + /// + public DateTime? EndTime { get; set; } } /// /// 输出 diff --git a/backend/BPA.MES.Base.Application/Services/LogService/Dtos/ProgramLogDto.cs b/backend/BPA.MES.Base.Application/Services/LogService/Dtos/ProgramLogDto.cs index 94a85dc..51a9b75 100644 --- a/backend/BPA.MES.Base.Application/Services/LogService/Dtos/ProgramLogDto.cs +++ b/backend/BPA.MES.Base.Application/Services/LogService/Dtos/ProgramLogDto.cs @@ -17,6 +17,18 @@ /// 日志消息 /// public string MsgInfo { get; set; } + /// + /// 日期 + /// + public string Date { get; set; } + /// + /// 时间 + /// + public string Time { get; set; } + /// + /// 日志消息 + /// + public DateTime CreateDate { get; set; } } /// /// 增加 @@ -66,6 +78,14 @@ /// 日志消息 /// public string MsgInfo { get; set; } + /// + /// 开始时间 + /// + public DateTime? StartTime { get; set; } + /// + /// 结束时间 + /// + public DateTime? EndTime { get; set; } } /// /// 输出 diff --git a/backend/BPA.MES.Base.Application/Services/LogService/Dtos/RunLogDto.cs b/backend/BPA.MES.Base.Application/Services/LogService/Dtos/RunLogDto.cs index 4d21248..da4598b 100644 --- a/backend/BPA.MES.Base.Application/Services/LogService/Dtos/RunLogDto.cs +++ b/backend/BPA.MES.Base.Application/Services/LogService/Dtos/RunLogDto.cs @@ -12,11 +12,22 @@ /// 日志类别 /// public string LogType { get; set; } - /// /// 日志消息 /// public string MsgInfo { get; set; } + /// + /// 日期 + /// + public string Date { get; set; } + /// + /// 时间 + /// + public string Time { get; set; } + /// + /// 日志消息 + /// + public DateTime CreateDate { get; set; } } /// /// 增加 @@ -61,11 +72,18 @@ /// 日志类别 /// public string LogType { get; set; } - /// /// 日志消息 /// public string MsgInfo { get; set; } + /// + /// 开始时间 + /// + public DateTime? StartTime { get; set; } + /// + /// 结束时间 + /// + public DateTime? EndTime { get; set; } } /// /// 输出 diff --git a/backend/BPA.MES.Base.Application/Services/LogService/Dtos/UserLogDto.cs b/backend/BPA.MES.Base.Application/Services/LogService/Dtos/UserLogDto.cs index 8ef79ce..7216d5b 100644 --- a/backend/BPA.MES.Base.Application/Services/LogService/Dtos/UserLogDto.cs +++ b/backend/BPA.MES.Base.Application/Services/LogService/Dtos/UserLogDto.cs @@ -22,6 +22,10 @@ /// 日志消息 /// public string MsgInfo { get; set; } + /// + /// 日志时间 + /// + public DateTime CreateDate { get; set; } } /// /// 增加 diff --git a/backend/BPA.MES.Base.Application/Services/LogService/Services/AlarmLogService.cs b/backend/BPA.MES.Base.Application/Services/LogService/Services/AlarmLogService.cs index b6f5eaa..4b27e13 100644 --- a/backend/BPA.MES.Base.Application/Services/LogService/Services/AlarmLogService.cs +++ b/backend/BPA.MES.Base.Application/Services/LogService/Services/AlarmLogService.cs @@ -75,6 +75,9 @@ .WhereIF(!string.IsNullOrEmpty(input.Grade), x => x.Grade.Contains(input.Grade)) .WhereIF(!string.IsNullOrEmpty(input.MsgInfo), x => x.MsgInfo.Contains(input.MsgInfo)) .WhereIF(!string.IsNullOrEmpty(input.Value), x => x.Value.Contains(input.Value)) + .WhereIF(input.StartTime.HasVal(), x => x.CreateDate >= input.StartTime.Value) + .WhereIF(input.EndTime.HasVal(), x => x.CreateDate <= input.EndTime.Value) + .OrderByDescending(x=>x.CreateDate) .ToPagedListAsync(input.PageIndex, input.PageSize); SqlSugarPagedList output = entity.Adapt>(); return output; diff --git a/backend/BPA.MES.Base.Application/Services/LogService/Services/ProgramLogService.cs b/backend/BPA.MES.Base.Application/Services/LogService/Services/ProgramLogService.cs index 27d40a0..c169424 100644 --- a/backend/BPA.MES.Base.Application/Services/LogService/Services/ProgramLogService.cs +++ b/backend/BPA.MES.Base.Application/Services/LogService/Services/ProgramLogService.cs @@ -73,6 +73,9 @@ var entity = await _dbContext.Queryable() .WhereIF(input.LogType != null, x => x.LogType == input.LogType) .WhereIF(!string.IsNullOrEmpty(input.MsgInfo), x => x.MsgInfo.Contains(input.MsgInfo)) + .WhereIF(input.StartTime.HasVal(), x => x.CreateDate >= input.StartTime.Value) + .WhereIF(input.EndTime.HasVal(), x => x.CreateDate <= input.EndTime.Value) + .OrderByDescending(x => x.CreateDate) .ToPagedListAsync(input.PageIndex, input.PageSize); SqlSugarPagedList output = entity.Adapt>(); return output; diff --git a/backend/BPA.MES.Base.Application/Services/LogService/Services/RunLogService.cs b/backend/BPA.MES.Base.Application/Services/LogService/Services/RunLogService.cs index 3f239f9..a85d548 100644 --- a/backend/BPA.MES.Base.Application/Services/LogService/Services/RunLogService.cs +++ b/backend/BPA.MES.Base.Application/Services/LogService/Services/RunLogService.cs @@ -73,6 +73,9 @@ var entity = await _dbContext.Queryable() .WhereIF(!string.IsNullOrEmpty(input.LogType), x => x.LogType.Contains(input.LogType)) .WhereIF(!string.IsNullOrEmpty(input.MsgInfo), x => x.MsgInfo.Contains(input.MsgInfo)) + .WhereIF(input.StartTime.HasVal(), x => x.CreateDate >= input.StartTime.Value) + .WhereIF(input.EndTime.HasVal(), x => x.CreateDate <= input.EndTime.Value) + .OrderByDescending(x => x.CreateDate) .ToPagedListAsync(input.PageIndex, input.PageSize); SqlSugarPagedList output = entity.Adapt>(); return output; diff --git a/backend/BPA.MES.Base.Application/Services/MaterialService/Dtos/MaterialsInfoDto.cs b/backend/BPA.MES.Base.Application/Services/MaterialService/Dtos/MaterialsInfoDto.cs index c960780..1404191 100644 --- a/backend/BPA.MES.Base.Application/Services/MaterialService/Dtos/MaterialsInfoDto.cs +++ b/backend/BPA.MES.Base.Application/Services/MaterialService/Dtos/MaterialsInfoDto.cs @@ -27,7 +27,12 @@ /// 原料分组 /// /// - public string Gourp { get; set; } + public string Type { get; set; } + /// + /// 每升重量 + /// + + public string WeightPerLiter { get; set; } } /// /// 增加 @@ -84,5 +89,9 @@ /// /// public string Id { get; set; } + /// + /// 类型名称 + /// + public string TypeName { get; set; } } } diff --git a/backend/BPA.MES.Base.Application/Services/MaterialService/Services/MaterialsInfoService.cs b/backend/BPA.MES.Base.Application/Services/MaterialService/Services/MaterialsInfoService.cs index c43d00a..269dfae 100644 --- a/backend/BPA.MES.Base.Application/Services/MaterialService/Services/MaterialsInfoService.cs +++ b/backend/BPA.MES.Base.Application/Services/MaterialService/Services/MaterialsInfoService.cs @@ -51,8 +51,15 @@ [HttpGet] public async Task Detail(string Id) { - var entity = await _dbContext.Queryable().FirstAsync(x => x.Id == Id); - MaterialsInfoOutput output = entity.Adapt(); + var output = await _dbContext.Queryable() + .LeftJoin((a,b)=>a.Type==b.Id) + .Where((a,b)=> a.Id == Id) + .Select((a,b)=>new MaterialsInfoOutput + { + Id=a.Id.SelectAll(), + TypeName = b.Value + }) + .FirstAsync(); return output; } /// @@ -63,8 +70,14 @@ [HttpGet] public async Task> List() { - var entity = await _dbContext.Queryable().ToListAsync(); - List output = entity.Adapt>(); + var output = await _dbContext.Queryable() + .LeftJoin((a, b) => a.Type == b.Id) + .Select((a, b) => new MaterialsInfoOutput + { + Id = a.Id.SelectAll(), + TypeName = b.Value + }) + .ToListAsync(); return output; } /// @@ -75,11 +88,16 @@ [HttpPost] public async Task> PagedList(MaterialsInfoQueryPageInput input) { - var entity = await _dbContext.Queryable() - .WhereIF(!string.IsNullOrEmpty(input.Name),x=>x.Name.Contains(input.Name)) - .WhereIF(!string.IsNullOrEmpty(input.Code), x => x.Code.Contains(input.Code)) + var output = await _dbContext.Queryable() + .LeftJoin((a, b) => a.Type == b.Id) + .WhereIF(!string.IsNullOrEmpty(input.Name), (a, b) => a.Name.Contains(input.Name)) + .WhereIF(!string.IsNullOrEmpty(input.Code), (a, b) => a.Code.Contains(input.Code)) + .Select((a, b) => new MaterialsInfoOutput + { + Id = a.Id.SelectAll(), + TypeName = b.Value + }) .ToPagedListAsync(input.PageIndex, input.PageSize); - SqlSugarPagedList output = entity.Adapt>(); return output; } /// diff --git a/backend/BPA.MES.Base.Application/Services/OrderService/Service/OrderService.cs b/backend/BPA.MES.Base.Application/Services/OrderService/Service/OrderService.cs index 44486a3..a3c725d 100644 --- a/backend/BPA.MES.Base.Application/Services/OrderService/Service/OrderService.cs +++ b/backend/BPA.MES.Base.Application/Services/OrderService/Service/OrderService.cs @@ -58,7 +58,7 @@ namespace BPA.MES.Base.Application.Services.OrderService.Service ProductionLineId=a.LineId, ProductionLineName=c.Name, Id = a.Id, - CreateTime=a.CreateTime, + CreateTime=a.CreateTime.ToString(), Status = d.Status == null ? WorkOrderStatusEnum.Draft : d.Status }).ToListAsync(); @@ -230,7 +230,7 @@ namespace BPA.MES.Base.Application.Services.OrderService.Service { Pztj_WorkInfoEntity entity = new Pztj_WorkInfoEntity() { - CreateTime = DateTime.Now.ToString(), + CreateTime = DateTime.Now, FinalId = item.FinalslId, LineId = item.ProductionLineId, Name = "", diff --git a/backend/BPA.MES.Base.Application/Services/ProductLineService/Dtos/ProductLineDeviceDto.cs b/backend/BPA.MES.Base.Application/Services/ProductLineService/Dtos/ProductLineDeviceDto.cs index b8c1425..e8e6c26 100644 --- a/backend/BPA.MES.Base.Application/Services/ProductLineService/Dtos/ProductLineDeviceDto.cs +++ b/backend/BPA.MES.Base.Application/Services/ProductLineService/Dtos/ProductLineDeviceDto.cs @@ -20,6 +20,20 @@ public class ProductLineDeviceAddInput: ProductLineDeviceDto { + } + /// + /// 产线设备不分页 + /// + public class ProductLineDeviceQueryInput + { + /// + /// 名称 + /// + public string Name { get; set; } + /// + /// 产线Id + /// + public string LineId { get; set; } } /// /// 产线设备分页 diff --git a/backend/BPA.MES.Base.Application/Services/ProductLineService/Dtos/ProductLineStockDto.cs b/backend/BPA.MES.Base.Application/Services/ProductLineService/Dtos/ProductLineStockDto.cs index 89e2c76..6876119 100644 --- a/backend/BPA.MES.Base.Application/Services/ProductLineService/Dtos/ProductLineStockDto.cs +++ b/backend/BPA.MES.Base.Application/Services/ProductLineService/Dtos/ProductLineStockDto.cs @@ -21,6 +21,24 @@ { + } + /// + /// 产线设备不分页 + /// + public class ProductLineStockQueryInput + { + /// + /// 名称 + /// + public string Name { get; set; } + /// + /// 产线Id + /// + public string LineId { get; set; } + /// + /// 物料Id + /// + public string MaterialId { get; set; } } /// /// 产线设备分页 @@ -56,6 +74,10 @@ /// public string Id { get; set; } /// + /// 产线名称 + /// + public string LineName { get; set; } + /// /// 名称 /// /// 设备名称 @@ -64,6 +86,14 @@ /// 编码 /// public string StockCode { get; set; } + /// + /// 物料信息 + /// + public string MaterialId { get; set; } + /// + /// 物料名称 + /// + public string MateriaName { get; set; } } } diff --git a/backend/BPA.MES.Base.Application/Services/ProductLineService/Services/IProductLineService.cs b/backend/BPA.MES.Base.Application/Services/ProductLineService/Services/IProductLineService.cs index bc92523..e352cc8 100644 --- a/backend/BPA.MES.Base.Application/Services/ProductLineService/Services/IProductLineService.cs +++ b/backend/BPA.MES.Base.Application/Services/ProductLineService/Services/IProductLineService.cs @@ -63,7 +63,7 @@ /// 产线设备不分页 /// /// - Task> DeviceList(); + Task> DeviceList(ProductLineDeviceQueryInput input); /// /// 产线设备分页 /// @@ -90,7 +90,7 @@ /// 产线料仓不分页 /// /// - Task> StockList(); + Task> StockList(ProductLineStockQueryInput input); /// /// 产线料仓分页 /// diff --git a/backend/BPA.MES.Base.Application/Services/ProductLineService/Services/ProductLineService.cs b/backend/BPA.MES.Base.Application/Services/ProductLineService/Services/ProductLineService.cs index d5261d6..2a64b93 100644 --- a/backend/BPA.MES.Base.Application/Services/ProductLineService/Services/ProductLineService.cs +++ b/backend/BPA.MES.Base.Application/Services/ProductLineService/Services/ProductLineService.cs @@ -145,11 +145,24 @@ /// 产线设备不分页 /// /// - [HttpGet] - public async Task> DeviceList() + [HttpPost] + public async Task> DeviceList(ProductLineDeviceQueryInput input) { - var entity = await _dbContext.Queryable().ToListAsync(); - List output = entity.Adapt>(); + var output = await _dbContext.Queryable() + .LeftJoin((a, b) => a.DeviceId == b.Id) + .WhereIF(!string.IsNullOrEmpty(input.Name), (a, b) => b.Name.Contains(input.Name)) + .WhereIF(!string.IsNullOrEmpty(input.LineId), (a, b) => a.LineId == input.LineId) + .Select((a, b) => new ProductLineDeviceOutput + { + DeviceId = a.DeviceId, + DeviceCode = b.Code, + DeviceName = b.Name, + Describe = b.Describe, + DeviceType = b.DeviceType, + Id = a.Id, + LineId = a.LineId + }). + ToListAsync(); return output; } /// @@ -162,7 +175,7 @@ var entity = await _dbContext.Queryable() .LeftJoin((a,b)=>a.DeviceId==b.Id) .WhereIF(!string.IsNullOrEmpty(input.Name), (a, b) => b.Name.Contains(input.Name)) - .Where((a, b) => a.LineId == input.LineId) + .WhereIF(!string.IsNullOrEmpty(input.LineId), (a, b) => a.LineId == input.LineId) .Select((a,b)=>new ProductLineDeviceOutput { DeviceId = a.DeviceId, @@ -207,12 +220,26 @@ /// 产线料仓不分页 /// /// - [HttpGet] - public async Task> StockList() + [HttpPost] + public async Task> StockList(ProductLineStockQueryInput input) { - var entity = await _dbContext.Queryable().ToListAsync(); - List output = entity.Adapt>(); - return output; + var entity = await _dbContext.Queryable() + .LeftJoin((a, b) => a.StockId == b.Id) + .LeftJoin((a, b,c) => b.MaterialId == c.Id) + .WhereIF(!string.IsNullOrEmpty(input.MaterialId), (a, b) => b.MaterialId == input.MaterialId) + .WhereIF(!string.IsNullOrEmpty(input.LineId), (a, b) => a.LineId == input.LineId) + .Select((a, b,c) => new ProductLineStockOutput + { + Id = a.Id, + LineId = a.LineId, + StockCode = b.Code, + StockId = b.Id, + StockName = b.Name, + MaterialId = b.MaterialId, + MateriaName = c.Name + }) + .ToListAsync(); + return entity; } /// /// 产线料仓分页 @@ -224,7 +251,7 @@ var entity = await _dbContext.Queryable() .LeftJoin((a, b) => a.StockId == b.Id) .WhereIF(!string.IsNullOrEmpty(input.Name), (a, b) => b.Name.Contains(input.Name)) - .Where((a, b) => a.LineId == input.LineId) + .WhereIF(!string.IsNullOrEmpty(input.LineId), (a, b) => a.LineId == input.LineId) .Select((a, b) => new ProductLineStockOutput { StockId = a.StockId, diff --git a/backend/BPA.MES.Base.Application/Services/SysCacheService/ISysCacheService.cs b/backend/BPA.MES.Base.Application/Services/SysCacheService/ISysCacheService.cs new file mode 100644 index 0000000..f070ad9 --- /dev/null +++ b/backend/BPA.MES.Base.Application/Services/SysCacheService/ISysCacheService.cs @@ -0,0 +1,15 @@ +namespace BPA.MES.Base.Application +{ + public interface ISysCacheService + { + Task AddCacheKey(string cacheKey); + Task DelCacheKey(string cacheKey); + bool Exists(string cacheKey); + Task> GetAllCacheKeys(); + Task GetAsync(string cacheKey); + Task GetStringAsync(string cacheKey); + Task RemoveAsync(string key); + Task SetAsync(string cacheKey, object value); + Task SetStringAsync(string cacheKey, string value); + } +} diff --git a/backend/BPA.MES.Base.Application/Services/SysCacheService/SysCacheService.cs b/backend/BPA.MES.Base.Application/Services/SysCacheService/SysCacheService.cs new file mode 100644 index 0000000..bc6de78 --- /dev/null +++ b/backend/BPA.MES.Base.Application/Services/SysCacheService/SysCacheService.cs @@ -0,0 +1,163 @@ +using Furion.JsonSerialization; +using Microsoft.Extensions.Caching.Distributed; +using System.Text; + +namespace BPA.MES.Base.Application +{ + /// + /// 系统缓存服务 + /// + [ApiDescriptionSettings(Name = "Cache", Order = 100)] + public class SysCacheService : ISysCacheService, IDynamicApiController, ISingleton + { + private readonly IDistributedCache _cache; + + public SysCacheService(IDistributedCache cache) + { + _cache = cache; + } + + /// + /// 获取所有缓存关键字 + /// + /// + [HttpGet("sysCache/keyList")] + public async Task> GetAllCacheKeys() + { + var res = await _cache.GetStringAsync(ClaimConst.CACHE_KEY_ALL); + return string.IsNullOrWhiteSpace(res) ? null : JSON.Deserialize>(res); + } + + /// + /// 删除指定关键字缓存 + /// + /// + /// + [HttpGet("sysCache/remove")] + public async Task RemoveAsync(string key) + { + await _cache.RemoveAsync(key); + + await DelCacheKey(key); + } + + /// + /// 删除某特征关键字缓存 + /// + /// + /// + [NonAction] + public async Task DelByPatternAsync(string key) + { + var allkeys = await GetAllCacheKeys(); + var delAllkeys = allkeys.Where(u => u.Contains(key)).ToList(); + + // 删除相应的缓存 + delAllkeys.ForEach(u => + { + _cache.Remove(u); + }); + + // 更新所有缓存键 + allkeys = allkeys.Where(u => !u.Contains(key)).ToList(); + await _cache.SetStringAsync(ClaimConst.CACHE_KEY_ALL, JSON.Serialize(allkeys)); + } + + /// + /// 设置缓存 + /// + /// + /// + /// + [NonAction] + public async Task SetAsync(string cacheKey, object value) + { + await _cache.SetAsync(cacheKey, Encoding.UTF8.GetBytes(JSON.Serialize(value))); + + await AddCacheKey(cacheKey); + } + + /// + /// 设置缓存 + /// + /// + /// + /// + [NonAction] + public async Task SetStringAsync(string cacheKey, string value) + { + await _cache.SetStringAsync(cacheKey, value); + + await AddCacheKey(cacheKey); + } + + /// + /// 获取缓存 + /// + /// + /// + [HttpGet("sysCache/detail")] + public async Task GetStringAsync(string cacheKey) + { + return await _cache.GetStringAsync(cacheKey); + } + + /// + /// 获取缓存 + /// + /// + /// + /// + [NonAction] + public async Task GetAsync(string cacheKey) + { + var res = await _cache.GetAsync(cacheKey); + return res == null ? default : JSON.Deserialize(Encoding.UTF8.GetString(res)); + } + + /// + /// 检查给定 key 是否存在 + /// + /// 键 + /// + [NonAction] + public bool Exists(string cacheKey) + { + return _cache.Equals(cacheKey); + } + + /// + /// 增加缓存Key + /// + /// + /// + [NonAction] + public async Task AddCacheKey(string cacheKey) + { + var res = await _cache.GetStringAsync(ClaimConst.CACHE_KEY_ALL); + var allkeys = string.IsNullOrWhiteSpace(res) ? new List() : JSON.Deserialize>(res); + if (!allkeys.Any(m => m == cacheKey)) + { + allkeys.Add(cacheKey); + await _cache.SetStringAsync(ClaimConst.CACHE_KEY_ALL, JSON.Serialize(allkeys)); + } + } + + /// + /// + /// + /// + /// + [NonAction] + public async Task DelCacheKey(string cacheKey) + { + var res = await _cache.GetStringAsync(ClaimConst.CACHE_KEY_ALL); + var allkeys = string.IsNullOrWhiteSpace(res) ? new List() : JSON.Deserialize>(res); + if (allkeys.Any(m => m == cacheKey)) + { + allkeys.Remove(cacheKey); + await _cache.SetStringAsync(ClaimConst.CACHE_KEY_ALL, JSON.Serialize(allkeys)); + } + } + } +} diff --git a/backend/BPA.MES.Base.Application/Services/WorkInfoService/Dtos/WorkInfoDto.cs b/backend/BPA.MES.Base.Application/Services/WorkInfoService/Dtos/WorkInfoDto.cs index 73947d0..9a1dd23 100644 --- a/backend/BPA.MES.Base.Application/Services/WorkInfoService/Dtos/WorkInfoDto.cs +++ b/backend/BPA.MES.Base.Application/Services/WorkInfoService/Dtos/WorkInfoDto.cs @@ -25,6 +25,10 @@ /// public string Number { get; set; } /// + /// 设备id + /// + public string DeviceId { get; set; } + /// /// 创建时间 /// public string CreateTime { get; set; } @@ -137,6 +141,14 @@ /// public string LineName { get; set; } /// + /// 设备编码 + /// + public string DeviceCode { get; set; } + /// + /// 设备名称 + /// + public string DeviceName { get; set; } + /// /// 工单状态 /// public WorkOrderStatusEnum? Status { get; set; } @@ -170,6 +182,9 @@ /// /// 物料信息 /// - public List MaterialList { get; set; } + public List MaterialList { get; set; } } + + + } diff --git a/backend/BPA.MES.Base.Application/Services/WorkInfoService/Dtos/WorkInfoMaterialsRecordDto.cs b/backend/BPA.MES.Base.Application/Services/WorkInfoService/Dtos/WorkInfoMaterialsRecordDto.cs index 94ea370..bb40e1a 100644 --- a/backend/BPA.MES.Base.Application/Services/WorkInfoService/Dtos/WorkInfoMaterialsRecordDto.cs +++ b/backend/BPA.MES.Base.Application/Services/WorkInfoService/Dtos/WorkInfoMaterialsRecordDto.cs @@ -8,6 +8,42 @@ /// public class WorkInfoMaterialsRecordDto { + /// + /// 物料名称 + /// + public string MaterialName { get; set; } + /// + /// 物料id + /// + public string MaterialId { get; set; } + /// + /// 工单id + /// + public string WorkId { get; set; } + /// + /// 重量 + /// + public string Weight { get; set; } + /// + /// 第几锅 + /// + public string PotNum { get; set; } + /// + /// 配方Id + /// + public string RecipeId { get; set; } + /// + /// 配方名称 + /// + public string RecipeName { get; set; } + /// + /// 物料状态 + /// + public EBatchingStatus MaterialStatus { get; set; } + /// + /// 更新时间 + /// + public DateTime? UpdateTime { get; set; } } /// /// 增加 @@ -56,5 +92,17 @@ /// 主键 /// public string Id { get; set; } + /// + /// 物料类型 + /// + public string MaterialType { get; set; } + /// + /// 物料类型名称 + /// + public string MaterialTypeName { get; set; } + /// + /// 每升重量 + /// + public string WeightPerLiter { get; set; } } } diff --git a/backend/BPA.MES.Base.Application/Services/WorkInfoService/Dtos/WorkInfoStatusDto.cs b/backend/BPA.MES.Base.Application/Services/WorkInfoService/Dtos/WorkInfoStatusDto.cs index 8cd5bf7..b34fdb4 100644 --- a/backend/BPA.MES.Base.Application/Services/WorkInfoService/Dtos/WorkInfoStatusDto.cs +++ b/backend/BPA.MES.Base.Application/Services/WorkInfoService/Dtos/WorkInfoStatusDto.cs @@ -15,11 +15,16 @@ /// /// 工单状态 /// - public string Status { get; set; } + public WorkOrderStatusEnum Status { get; set; } /// /// 创建时间 /// public DateTime CreateTime { get; set; } + /// + /// 备注 + /// + + public string Remark { get; set; } } /// /// 增加 @@ -41,6 +46,11 @@ /// 状态 /// public WorkOrderStatusEnum Status { get; set; } + /// + /// 备注 + /// + + public string Remark { get; set; } } /// /// 删除 @@ -58,6 +68,20 @@ public class WorkInfoStatusQueryPageInput : RequestPage { + } + /// + /// 下发 + /// + public class PublishInput + { + /// + /// 工单ID + /// + public string WorkId { get; set; } + /// + /// 设备ID + /// + public string? DeviceId { get; set; } } /// /// 输出 @@ -68,5 +92,30 @@ /// 主键 /// public string Id { get; set; } + /// + /// 状态名称 + /// + public string StatusName { get { + + switch (Status) + { + case WorkOrderStatusEnum.Unkown: + return "未知"; + case WorkOrderStatusEnum.Draft: + return "草稿"; + case WorkOrderStatusEnum.Issued: + return "已下发"; + case WorkOrderStatusEnum.Receive: + return "已接受"; + case WorkOrderStatusEnum.Started: + return "已启动"; + case WorkOrderStatusEnum.Completed: + return "已完成"; + case WorkOrderStatusEnum.Obsolete: + return "废弃"; + default: + return "错误"; + } + } } } } diff --git a/backend/BPA.MES.Base.Application/Services/WorkInfoService/Services/IWorkInfoService.cs b/backend/BPA.MES.Base.Application/Services/WorkInfoService/Services/IWorkInfoService.cs index bb290de..985ae45 100644 --- a/backend/BPA.MES.Base.Application/Services/WorkInfoService/Services/IWorkInfoService.cs +++ b/backend/BPA.MES.Base.Application/Services/WorkInfoService/Services/IWorkInfoService.cs @@ -53,9 +53,9 @@ /// /// 工单下发 /// - /// 工单Id + /// 工单Id /// - Task Publish(string workId); + Task Publish(PublishInput input); /// /// 强制结束 /// diff --git a/backend/BPA.MES.Base.Application/Services/WorkInfoService/Services/WorkInfoService.cs b/backend/BPA.MES.Base.Application/Services/WorkInfoService/Services/WorkInfoService.cs index 16ada5e..1647e59 100644 --- a/backend/BPA.MES.Base.Application/Services/WorkInfoService/Services/WorkInfoService.cs +++ b/backend/BPA.MES.Base.Application/Services/WorkInfoService/Services/WorkInfoService.cs @@ -74,34 +74,51 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services .LeftJoin((a, b) => a.FinalId == b.Id) .LeftJoin((a, b, c) => a.LineId == c.Id) .LeftJoin((a, b, c, d) => d.Id == SqlFunc.Subqueryable().Where(s => s.WorkId == a.Id).OrderByDesc(s => s.CreateTime).Select(s => s.Id)) + .LeftJoin((a,b,c,d,e)=>a.DeviceId==e.Id) .Where((a, b, c, d) => a.Id == Id) - .Select((a, b, c, d) => new WorkInfoDetailOutput + .Select((a, b, c, d, e) => new WorkInfoDetailOutput { Id = a.Id.SelectAll(), + DeviceCode = e.Code, + DeviceName=e.Name, + DeviceId = e.Id, FinalName = b.Name, LineName = c.Name, Status = d.Status == null ? WorkOrderStatusEnum.Draft : d.Status }).FirstAsync(); - if (entity==null) + if (entity == null) { throw Oops.Bah("没有找到工单信息!"); } //获取成品信息 var finainfo = await _dbContext.Queryable().FirstAsync(x => x.Id == entity.FinalId); - if (finainfo==null) + if (finainfo == null) { throw Oops.Bah("没有找到成品信息!"); } //获取工艺步骤 var craftlist = await _dbContext.Queryable().Where(x => x.WorkId == Id).ToListAsync(); //获取物料信息 - var materiallist = await _dbContext.Queryable().Where(x => x.WorkId == Id).ToListAsync(); + var materiallist = await _dbContext.Queryable() + .LeftJoin((a,b)=>a.MaterialId==b.Id) + .LeftJoin((a,b,c) => b.Type == c.Id) + .Where((a, b) => a.WorkId == Id) + .Select((a, b,c) => + new WorkInfoMaterialsRecordOutput + { + Id = a.Id.SelectAll(), + MaterialType = c.Id, + MaterialTypeName = c.Value, + WeightPerLiter = b.WeightPerLiter + }) + .ToListAsync(); entity.CraftList = craftlist; entity.MaterialList = materiallist; - if(craftlist.Max(x=>x.Status) == RecipeStatus.执行完成 && craftlist.Max(x => x.Status) == craftlist.Min(x => x.Status)) + if (craftlist.Max(x => x.Status) == RecipeStatus.执行完成 && craftlist.Max(x => x.Status) == craftlist.Min(x => x.Status)) { entity.CraftStatus = RecipeStatus.执行完成; - }else + } + else if (craftlist.Max(x => x.Status) == RecipeStatus.等待执行 && craftlist.Max(x => x.Status) == craftlist.Min(x => x.Status)) { entity.CraftStatus = RecipeStatus.等待执行; @@ -141,8 +158,8 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services .WhereIF(!string.IsNullOrEmpty(input.Name), (a, b, c, d) => b.Name.Contains(input.Name)) .WhereIF(!string.IsNullOrEmpty(input.Id), (a, b, c, d) => a.Id.Contains(input.Id)) .WhereIF(input.Status != null, (a, b, c, d) => input.Status.Contains(d.Status)) - .WhereIF(input.StartTime!=null,(a, b, c, d) => input.StartTime<= Convert.ToDateTime(a.CreateTime)) - .WhereIF(input.EndTime != null, (a, b, c, d) => input.EndTime.Value.AddHours(23).AddMinutes(59).AddSeconds(59) >= Convert.ToDateTime(a.CreateTime)) + .WhereIF(input.StartTime != null, (a, b, c, d) => input.StartTime <= a.CreateTime) + .WhereIF(input.EndTime != null, (a, b, c, d) => input.EndTime.Value.AddHours(23).AddMinutes(59).AddSeconds(59) >= a.CreateTime) .Select((a, b, c, d) => new WorkInfoOutput { Id = a.Id.SelectAll(), @@ -169,6 +186,7 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services .WhereIF(input.Status != null, (a, b, c, d) => input.Status.Contains(d.Status)) .WhereIF(input.StartTime != null, (a, b, c, d) => input.StartTime <= Convert.ToDateTime(a.CreateTime)) .WhereIF(input.EndTime != null, (a, b, c, d) => input.EndTime.Value.AddHours(23).AddMinutes(59).AddSeconds(59) >= Convert.ToDateTime(a.CreateTime)) + .OrderByDescending((a, b, c, d) => a.CreateTime) .Select((a, b, c, d) => new WorkInfoOutput { Id = a.Id.SelectAll(), @@ -182,56 +200,71 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services /// /// 工单下发 /// - /// 工单id + /// 工单id /// /// [HttpPost] - public async Task Publish(string workId) + public async Task Publish(PublishInput input) { - + string userId = App.User?.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + string userName = App.User?.FindFirst(ClaimConst.CLAINM_NAME)?.Value; + if (!string.IsNullOrEmpty(input.DeviceId)) + { + await _dbContext.Updateable().SetColumns(x => x.DeviceId == input.DeviceId).Where(x => x.Id == input.WorkId).ExecuteCommandAsync(); + } var res = await UpdateStatus( new WorkInfoStatusUpdateInput { - WorkId = workId, - Status = WorkOrderStatusEnum.Issued + WorkId = input.WorkId, + Status = WorkOrderStatusEnum.Issued, + Remark = $"[{userId}]{userName}" }); - var entity = await _dbContext.Queryable().FirstAsync(x => x.Id == workId); - WorkInfoOutput workInfo = entity.Adapt(); + var workentity = await _dbContext.Queryable() + .LeftJoin((a,b)=>a.DeviceId==b.Id) + .Where((a, b) => a.Id == input.WorkId) + .Select((a,b)=>new WorkInfoOutput + { + Id=a.Id.SelectAll(), + DeviceCode = b.Code, + DeviceName = b.Name + }) + .FirstAsync(); if (res) { - WorkInfoMaterialsRecordEntity workInfoMaterialsRecordEntity = new() + WorkInfoMaterialsRecordEntity workInfoMaterialsRecordEntity = new() { - MaterialId = workId, + MaterialId = input.WorkId, }; //获取成品信息 - var finainfo = await _dbContext.Queryable().FirstAsync(x => x.Id == entity.FinalId); + var finainfo = await _dbContext.Queryable().FirstAsync(x => x.Id == workentity.FinalId); if (finainfo == null) { throw Oops.Bah("没有找到成品信息!"); } - + var materiallist = await _dbContext.Queryable() - .LeftJoin((a,b)=>a.MaterialId==b.Id) - .Where((a, b) => a.RecipesId == finainfo.RecipeId) - .Select((a, b) => new WorkInfoMaterialsRecordEntity + .LeftJoin((a, b) => a.MaterialId == b.Id) + .LeftJoin((a,b,c)=>a.RecipesId==c.Id) + .Where((a, b, c) => a.RecipesId == finainfo.RecipeId) + .Select((a, b, c) => new WorkInfoMaterialsRecordEntity { MaterialId = a.MaterialId, MaterialName = b.Name, MaterialStatus = EBatchingStatus.等待配料, - WorkId = workId, + WorkId = input.WorkId, Weight = a.Weight, RecipeId = a.RecipesId, - RecipeName = b.Name + RecipeName = c.Name }) .ToListAsync(); - + //获取物料信息 - + var craftsteplist = await _dbContext.Queryable() - .LeftJoin((a,b)=>a.CraftId==b.Id) - .LeftJoin((a,b,c)=>a.DeviceProductFunctionId==c.Id) - .Where((a,b)=>a.CraftId== finainfo.CraftId) - .Select((a,b,c)=>new WorkInfoCraftstepRecordEntity + .LeftJoin((a, b) => a.CraftId == b.Id) + .LeftJoin((a, b, c) => a.DeviceProductFunctionId == c.Id) + .Where((a, b) => a.CraftId == finainfo.CraftId) + .Select((a, b, c) => new WorkInfoCraftstepRecordEntity { CraftId = a.CraftId, CraftName = b.Name, @@ -241,12 +274,12 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services CraftstepParms = a.Params, Status = RecipeStatus.等待执行, Step = a.Step, - WorkId = workId + WorkId = input.WorkId }) .ToListAsync(); List newmateriallist = new(); List newcraftslist = new(); - for (int i = 1; i <= Convert.ToInt32(entity.Number); i++) + for (int i = 1; i <= Convert.ToInt32(workentity.Number); i++) { foreach (var item in materiallist) { @@ -276,7 +309,7 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services Status = item.Status, Step = item.Step, WorkId = item.WorkId, - PotNum=i.ToString(), + PotNum = i.ToString(), }; newcraftslist.Add(itementity); } @@ -284,8 +317,9 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services try { _dbContext.Ado.BeginTran(); - await _dbContext.Deleteable().Where(x => x.WorkId == workId).ExecuteCommandAsync(); - await _dbContext.Deleteable().Where(x => x.WorkId == workId).ExecuteCommandAsync(); + await _dbContext.Deleteable().Where(x => x.WorkId == input.WorkId).ExecuteCommandAsync(); + await _dbContext.Deleteable().Where(x => x.WorkId == input.WorkId).ExecuteCommandAsync(); + await _dbContext.Insertable(newcraftslist).ExecuteCommandAsync(); await _dbContext.Insertable(newmateriallist).ExecuteCommandAsync(); _dbContext.Ado.CommitTran(); @@ -295,7 +329,7 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services _dbContext.Ado.RollbackTran(); throw Oops.Oh("下发失败!"); } - await _MQTTService.MqttPublish(workInfo, Topics.WorkOrderPush, MessageID.WorkOrderIssued); + await _MQTTService.MqttPublish(new MqttPublishDto() { Payload = workentity, Topic = Topics.WorkOrderPush, MessageId = MessageID.WorkOrderIssued }); } return true; } @@ -367,12 +401,16 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services { - var entityFrist = await _dbContext.Queryable().Where(x => x.Id == input.WorkCraftstepId).FirstAsync(); + var entityFrist = await _dbContext.Queryable().Where(x => x.Id == input.WorkCraftstepId).FirstAsync(); + if (entityFrist==null) + { + throw Oops.Bah("未查询到工单信息!"); + } if (!string.IsNullOrEmpty(input.WorkId)) { bool res = await _dbContext.Updateable() - .SetColumns(x=>x.Status==input.Status) - .SetColumns(x=>x.UpdateTime==DateTime.Now).IgnoreColumns(true).Where(x=>x.WorkId==input.WorkId && x.PotNum==input.PotNum).ExecuteCommandHasChangeAsync(); + .SetColumns(x => x.Status == input.Status) + .SetColumns(x => x.UpdateTime == DateTime.Now).IgnoreColumns(true).Where(x => x.WorkId == input.WorkId && x.PotNum == input.PotNum).ExecuteCommandHasChangeAsync(); return res; } else @@ -397,10 +435,13 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services [HttpPost] public async Task ForcedEnd(string workId) { + string userId = App.User?.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + string userName = App.User?.FindFirst(ClaimConst.CLAINM_NAME)?.Value; Pztj_WorkInfoStatusEntity entity = new() { WorkId = workId, - Status = WorkOrderStatusEnum.Completed + Status = WorkOrderStatusEnum.Completed, + Remark = $"{userName}[{userId}]点击你强制结束" }; var res = await _dbContext.Insertable(entity).IgnoreColumns(true).ExecuteCommandIdentityIntoEntityAsync(); return res; @@ -413,8 +454,9 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services [HttpGet] public async Task> StatusList(string workId) { - var entitys = await _dbContext.Queryable().Where(x => x.WorkId == workId).ToListAsync(); + var entitys = await _dbContext.Queryable().Where(x => x.WorkId == workId).OrderByDescending(x=>x.CreateTime).ToListAsync(); List list = entitys.Adapt>(); + return list; } } diff --git a/backend/BPA.MES.Base.Core/SqlsugarSetup.cs b/backend/BPA.MES.Base.Core/SqlsugarSetup.cs index 4c60df1..35195bd 100644 --- a/backend/BPA.MES.Base.Core/SqlsugarSetup.cs +++ b/backend/BPA.MES.Base.Core/SqlsugarSetup.cs @@ -39,6 +39,10 @@ namespace BPA.MES.Base.Core { entityInfo.SetValue(DateTime.Now); }; + if (entityInfo.PropertyName == "CreateDate" && entityInfo.OperationType == DataFilterType.InsertByObject) + { + entityInfo.SetValue(DateTime.Now); + }; }; } ); diff --git a/backend/BPA.MES.Base.Web.Core/Startup.cs b/backend/BPA.MES.Base.Web.Core/Startup.cs index 8cc2834..d0ee2cc 100644 --- a/backend/BPA.MES.Base.Web.Core/Startup.cs +++ b/backend/BPA.MES.Base.Web.Core/Startup.cs @@ -56,35 +56,6 @@ public class Startup : AppStartup op.Sign = "123456"; }); - //services.AddMqttClientHostedService(op => - //{ - // op.Port = 1883; - // op.Server = "10.2.1.21"; - // op.UserName = "emqx_u_block"; - // op.Password = "emqx_p_admin8765490789"; - // op.mqttClientConnectedHandlerDelegate = new MqttClientConnectedHandlerDelegate(async e => - // { - // Console.WriteLine("MQTT连接成功"); - // }); - // op.mqttClientDisconnectedHandlerDelegate = new MqttClientDisconnectedHandlerDelegate(async e => - // { - // Console.WriteLine("MQTT断开连接"); - // await Task.Delay(TimeSpan.FromSeconds(5)); - // try - // { - // //var options = builder.Build().Services.GetService(); - // //await builder.Build().Services.GetService().ConnectAsync(options); - // } - // catch (global::System.Exception) - // { - // } - // }); - // op.MqttApplicationMessageReceivedHandler = new MQTTnet.Client.Receiving.MqttApplicationMessageReceivedHandlerDelegate(async e => - // { - - // }); - //}); - services.AddControllers() .AddInjectWithUnifyResult(); } diff --git a/backend/BPA.MES.Base.Web.Entry/.config/dotnet-tools.json b/backend/BPA.MES.Base.Web.Entry/.config/dotnet-tools.json new file mode 100644 index 0000000..b0e38ab --- /dev/null +++ b/backend/BPA.MES.Base.Web.Entry/.config/dotnet-tools.json @@ -0,0 +1,5 @@ +{ + "version": 1, + "isRoot": true, + "tools": {} +} \ No newline at end of file diff --git a/backend/BPA.MES.Base.Web.Entry/BPA.MES.Base.Web.Entry.csproj.user b/backend/BPA.MES.Base.Web.Entry/BPA.MES.Base.Web.Entry.csproj.user index 4ba691b..ea3d269 100644 --- a/backend/BPA.MES.Base.Web.Entry/BPA.MES.Base.Web.Entry.csproj.user +++ b/backend/BPA.MES.Base.Web.Entry/BPA.MES.Base.Web.Entry.csproj.user @@ -5,5 +5,6 @@ BPA.MES.Base.Web.Entry + D:\胖子天骄\PZTJ.MES\backend\BPA.MES.Base.Web.Entry\Properties\PublishProfiles\FolderProfile.pubxml \ No newline at end of file diff --git a/backend/BPA.MES.Base.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml b/backend/BPA.MES.Base.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml new file mode 100644 index 0000000..ee4a573 --- /dev/null +++ b/backend/BPA.MES.Base.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Release + Any CPU + FileSystem + bin\Release\net6.0\publish\ + FileSystem + + net6.0 + win-x64 + c8d99f52-edc7-411f-8300-6db14bf59e8c + true + + \ No newline at end of file diff --git a/backend/BPA.MES.Base.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml.user b/backend/BPA.MES.Base.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml.user new file mode 100644 index 0000000..a5d23b1 --- /dev/null +++ b/backend/BPA.MES.Base.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml.user @@ -0,0 +1,10 @@ + + + + + <_PublishTargetUrl>D:\胖子天骄\PZTJ.MES\backend\BPA.MES.Base.Web.Entry\bin\Release\net6.0\publish\ + True|2023-11-03T01:49:49.8809253Z;True|2023-10-19T18:26:28.9736059+08:00;True|2023-10-19T12:20:00.3256982+08:00;True|2023-10-18T11:41:41.7977602+08:00;True|2023-10-17T18:56:25.1421613+08:00;True|2023-10-16T15:43:05.7944751+08:00;True|2023-10-15T17:28:41.6387899+08:00;True|2023-10-14T18:02:29.7904729+08:00;True|2023-10-14T10:58:09.1850768+08:00;False|2023-10-14T10:57:38.1803146+08:00;True|2023-10-10T15:43:25.4511019+08:00;False|2023-10-10T15:34:09.4564943+08:00;False|2023-10-09T14:10:16.8583415+08:00;True|2023-10-09T14:07:07.0884367+08:00;True|2023-10-09T13:50:15.6186644+08:00;True|2023-10-09T12:23:40.9180586+08:00; + + \ No newline at end of file diff --git a/backend/BPA.MES.Base.Web.Entry/Properties/launchSettings.json b/backend/BPA.MES.Base.Web.Entry/Properties/launchSettings.json index 38d1625..600107a 100644 --- a/backend/BPA.MES.Base.Web.Entry/Properties/launchSettings.json +++ b/backend/BPA.MES.Base.Web.Entry/Properties/launchSettings.json @@ -22,7 +22,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "applicationUrl": "http://localhost:5002", + "applicationUrl": "http://172.16.12.102:5002", "dotnetRunMessages": true }, "Docker": { diff --git a/backend/BPA.MES.Base.Web.Entry/appsettings.json b/backend/BPA.MES.Base.Web.Entry/appsettings.json index d565364..e6469bc 100644 --- a/backend/BPA.MES.Base.Web.Entry/appsettings.json +++ b/backend/BPA.MES.Base.Web.Entry/appsettings.json @@ -10,9 +10,11 @@ "AllowedHosts": "*", "ConnectionConfigs": [ { - "ConnectionString": "server=10.2.1.254;Port=3306;Database=bpa_pztj_mes;Uid=root;Pwd=BapAdmin123456.;", + //"ConnectionString": "server=10.2.1.254;Port=3306;Database=bpa_pztj_mes;Uid=root;Pwd=BapAdmin123456.;", + "ConnectionString": "server=192.168.1.231;Port=3306;Database=bpa_pztj_mes;Uid=root;Pwd=pztj8127;", "DbType": "MySql", "IsAutoCloseConnection": true } - ] + ], + "AGVUrl": "http://172.16.12.206:10080" } \ No newline at end of file