From 67e24ac95f23cee0a4a3e9b05975355665cae3c3 Mon Sep 17 00:00:00 2001 From: wenjy Date: Tue, 12 Mar 2024 16:05:28 +0800 Subject: [PATCH] =?UTF-8?q?add=20-=20=E6=B7=BB=E5=8A=A0=E6=8A=95=E6=96=99?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.idea.SlnMesnac/.idea/encodings.xml | 2 +- SlnMesnac.Model/domain/CwssInputRecord.cs | 92 +++++++++++++++++ SlnMesnac.Model/domain/McsInputRecord.cs | 92 +++++++++++++++++ SlnMesnac.Model/dto/ApiRequestParam.cs | 20 ++++ SlnMesnac.Repository/SqlsugarSetup.cs | 1 + .../service/IInputRecordService.cs | 35 +++++++ .../service/Impl/InputRecordServiceImpl.cs | 98 +++++++++++++++++++ .../Controllers/CwssIngCheckController.cs | 89 ++++++++++++++++- .../Controllers/McsIngCheckController.cs | 89 ++++++++++++++++- SlnMesnac/appsettings.Development.json | 5 + 10 files changed, 519 insertions(+), 4 deletions(-) create mode 100644 SlnMesnac.Model/domain/CwssInputRecord.cs create mode 100644 SlnMesnac.Model/domain/McsInputRecord.cs create mode 100644 SlnMesnac.Model/dto/ApiRequestParam.cs create mode 100644 SlnMesnac.Repository/service/IInputRecordService.cs create mode 100644 SlnMesnac.Repository/service/Impl/InputRecordServiceImpl.cs diff --git a/.idea/.idea.SlnMesnac/.idea/encodings.xml b/.idea/.idea.SlnMesnac/.idea/encodings.xml index 40b2185..d899bc1 100644 --- a/.idea/.idea.SlnMesnac/.idea/encodings.xml +++ b/.idea/.idea.SlnMesnac/.idea/encodings.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/SlnMesnac.Model/domain/CwssInputRecord.cs b/SlnMesnac.Model/domain/CwssInputRecord.cs new file mode 100644 index 0000000..7acf5d6 --- /dev/null +++ b/SlnMesnac.Model/domain/CwssInputRecord.cs @@ -0,0 +1,92 @@ +using System; +using System.Runtime.Serialization; +using SqlSugar; + +namespace SlnMesnac.Model.domain +{ + /// + /// CWSS投料记录 + /// + [SugarTable("Record_CwssInput"), TenantAttribute("mesApi")] + [DataContract(Name = "CwssInputRecord CWSS 投料记录")] + public class CwssInputRecord + { + /// + /// 标识 + /// + [SugarColumn(ColumnName="obj_id" ,IsPrimaryKey = true ,IsIdentity = true )] + public int ObjId { get; set; } + + /// + /// 机台编号,预留可传0 + /// + [SugarColumn(ColumnName="equip_id" )] + public int EquipId { get; set; } + + /// + /// 料罐编号 + /// + [SugarColumn(ColumnName="can_number" )] + public string CanNumber { get; set; } + + /// + /// 物料条码 + /// + [SugarColumn(ColumnName="material_barcode" )] + public string MaterialBarcode { get; set; } + + /// + /// 投入数量 + /// + [SugarColumn(ColumnName="input_quantity" )] + public int InputQuantity { get; set; } + + /// + /// 投入重量 + /// + [SugarColumn(ColumnName="input_weight" )] + public double InputWeight { get; set; } + + /// + /// 是否余料 + /// + [SugarColumn(ColumnName="is_remainder" )] + public bool IsRemainder { get; set; } + + /// + /// 余料数量 + /// + [SugarColumn(ColumnName="remainder_quantity" )] + public int RemainderQuantity { get; set; } + + /// + /// 余料重量 + /// + [SugarColumn(ColumnName="remainder_weight" )] + public double RemainderWeight { get; set; } + + /// + /// 是否开仓:1-开仓;2-只保存 + /// + [SugarColumn(ColumnName="is_open" )] + public int IsOpen { get; set; } + + /// + /// 投料结果:1-成功;0-失败 + /// + [SugarColumn(ColumnName="is_flag" )] + public int IsFlag { get; set; } + + /// + /// 备注信息 + /// + [SugarColumn(ColumnName="remark" )] + public string Remark { get; set; } + + /// + /// 记录时间 + /// + [SugarColumn(ColumnName="record_time" )] + public DateTime RecordTime { get; set; } + } +} \ No newline at end of file diff --git a/SlnMesnac.Model/domain/McsInputRecord.cs b/SlnMesnac.Model/domain/McsInputRecord.cs new file mode 100644 index 0000000..7a8d03e --- /dev/null +++ b/SlnMesnac.Model/domain/McsInputRecord.cs @@ -0,0 +1,92 @@ +using System; +using System.Runtime.Serialization; +using SqlSugar; + +namespace SlnMesnac.Model.domain +{ + /// + /// Mcs投料记录 + /// + [SugarTable("Record_McsInput"), TenantAttribute("mesApi")] + [DataContract(Name = "McsInputRecord MCS 投料记录")] + public class McsInputRecord + { + /// + /// 标识 + /// + [SugarColumn(ColumnName="obj_id" ,IsPrimaryKey = true ,IsIdentity = true )] + public int ObjId { get; set; } + + /// + /// 机台编号,预留可传0 + /// + [SugarColumn(ColumnName="equip_id" )] + public int EquipId { get; set; } + + /// + /// 料罐编号 + /// + [SugarColumn(ColumnName="can_number" )] + public string CanNumber { get; set; } + + /// + /// 物料条码 + /// + [SugarColumn(ColumnName="material_barcode" )] + public string MaterialBarcode { get; set; } + + /// + /// 投入数量 + /// + [SugarColumn(ColumnName="input_quantity" )] + public int InputQuantity { get; set; } + + /// + /// 投入重量 + /// + [SugarColumn(ColumnName="input_weight" )] + public double InputWeight { get; set; } + + /// + /// 是否余料 + /// + [SugarColumn(ColumnName="is_remainder" )] + public bool IsRemainder { get; set; } + + /// + /// 余料数量 + /// + [SugarColumn(ColumnName="remainder_quantity" )] + public int RemainderQuantity { get; set; } + + /// + /// 余料重量 + /// + [SugarColumn(ColumnName="remainder_weight" )] + public double RemainderWeight { get; set; } + + /// + /// 是否开仓:1-开仓;2-只保存 + /// + [SugarColumn(ColumnName="is_open" )] + public int IsOpen { get; set; } + + /// + /// 投料结果:1-成功;0-失败 + /// + [SugarColumn(ColumnName="is_flag" )] + public int IsFlag { get; set; } + + /// + /// 备注信息 + /// + [SugarColumn(ColumnName="remark" )] + public string Remark { get; set; } + + /// + /// 记录时间 + /// + [SugarColumn(ColumnName="record_time" )] + public DateTime RecordTime { get; set; } + } +} \ No newline at end of file diff --git a/SlnMesnac.Model/dto/ApiRequestParam.cs b/SlnMesnac.Model/dto/ApiRequestParam.cs new file mode 100644 index 0000000..85a56b2 --- /dev/null +++ b/SlnMesnac.Model/dto/ApiRequestParam.cs @@ -0,0 +1,20 @@ +using System; +using System.Runtime.Serialization; + +namespace SlnMesnac.Model.dto +{ + /// + /// 接口请求参数 + /// + [DataContract(Name = "ApiRequestParam 接口请求参数")] + public class ApiRequestParam + { + public string MaterialBarcode{ get; set; } + + public string CanNumber{ get; set; } + + public string beginTime{ get; set; } + + public string endTime { get; set; } + } +} \ No newline at end of file diff --git a/SlnMesnac.Repository/SqlsugarSetup.cs b/SlnMesnac.Repository/SqlsugarSetup.cs index 4fe0062..1a3a993 100644 --- a/SlnMesnac.Repository/SqlsugarSetup.cs +++ b/SlnMesnac.Repository/SqlsugarSetup.cs @@ -60,6 +60,7 @@ namespace SlnMesnac.Repository services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); } } } diff --git a/SlnMesnac.Repository/service/IInputRecordService.cs b/SlnMesnac.Repository/service/IInputRecordService.cs new file mode 100644 index 0000000..89ddc11 --- /dev/null +++ b/SlnMesnac.Repository/service/IInputRecordService.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using SlnMesnac.Model.domain; + +namespace SlnMesnac.Repository.service +{ + public interface IInputRecordService + { + + /// + /// 获取Mcs投料记录 + /// + /// + List GetMcsInputRecordList(); + + /// + /// 保存Mcs投料记录 + /// + /// + /// + bool SaveMcsInputRecord(McsInputRecord mcsInputRecord); + + /// + /// 获取Cwss投料记录 + /// + /// + List GetCwssInputRecordList(); + + /// + /// 保存Cwss投料记录 + /// + /// + /// + bool SaveCwssInputRecord(CwssInputRecord cwssInputRecord); + } +} \ No newline at end of file diff --git a/SlnMesnac.Repository/service/Impl/InputRecordServiceImpl.cs b/SlnMesnac.Repository/service/Impl/InputRecordServiceImpl.cs new file mode 100644 index 0000000..1fd5327 --- /dev/null +++ b/SlnMesnac.Repository/service/Impl/InputRecordServiceImpl.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using SlnMesnac.Model.domain; + +namespace SlnMesnac.Repository.service.Impl +{ + public class InputRecordServiceImpl:IInputRecordService + { + + private readonly Repository _mcsRep; + + private readonly Repository _cwssRep; + + public InputRecordServiceImpl(Repository mcsRep,Repository cwssRep) + { + _mcsRep = mcsRep; + _cwssRep = cwssRep; + } + + /// + /// 获取Mcs投料记录 + /// + /// + /// + public List GetMcsInputRecordList() + { + List result = null; + try + { + result = _mcsRep.GetList(); + } + catch (Exception e) + { + new InvalidOperationException($"获取Mcs投料记录异常:{e.Message}"); + } + return result; + } + + /// + /// 保存Mcs投料记录 + /// + /// + /// + /// + public bool SaveMcsInputRecord(McsInputRecord mcsInputRecord) + { + bool result = false; + try + { + result = _mcsRep.Insert(mcsInputRecord); + } + catch (Exception e) + { + new InvalidOperationException($"保存Mcs投料记录异常:{e.Message}"); + } + return result; + } + + /// + /// 获取Cwss投料记录 + /// + /// + /// + public List GetCwssInputRecordList() + { + List result = null; + try + { + result = _cwssRep.GetList(); + } + catch (Exception e) + { + new InvalidOperationException($"获取Cwss投料记录异常:{e.Message}"); + } + return result; + } + + /// + /// 保存Cwss投料记录 + /// + /// + /// + /// + public bool SaveCwssInputRecord(CwssInputRecord cwssInputRecord) + { + bool result = false; + try + { + result = _cwssRep.Insert(cwssInputRecord); + } + catch (Exception e) + { + new InvalidOperationException($"保存Mcs投料记录异常:{e.Message}"); + } + return result; + } + } +} \ No newline at end of file diff --git a/SlnMesnac/Controllers/CwssIngCheckController.cs b/SlnMesnac/Controllers/CwssIngCheckController.cs index c777c18..b1ccfdc 100644 --- a/SlnMesnac/Controllers/CwssIngCheckController.cs +++ b/SlnMesnac/Controllers/CwssIngCheckController.cs @@ -21,13 +21,15 @@ public class CwssIngCheckController private IWmsTaskOutService _wmsTaskOutService; private ICwssBinToMaterService _cwssBinToMaterService; private ICwssMaterialInfoService _cwssMaterialInfoService; + private IInputRecordService _inputRecordService; public CwssIngCheckController(ILogger logger, AppConfig appConfig, IWmsTaskOutService wmsTaskOutService, PlcPool plcPool, ICwssBinToMaterService cwssBinToMaterService, - ICwssMaterialInfoService cwssMaterialInfoService) + ICwssMaterialInfoService cwssMaterialInfoService, + IInputRecordService inputRecordService) { _logger = logger; _appConfig = appConfig; @@ -35,6 +37,7 @@ public class CwssIngCheckController _plcPool = plcPool; _cwssBinToMaterService = cwssBinToMaterService; _cwssMaterialInfoService = cwssMaterialInfoService; + _inputRecordService = inputRecordService; } /// @@ -138,8 +141,8 @@ public class CwssIngCheckController break; } } - //保存数据 + SaveInputRecord(ingredientInfo, 1, ""); } while (false); } @@ -152,6 +155,48 @@ public class CwssIngCheckController return result; } + /// + /// 获取Cwss投料记录 + /// + /// + /// + [HttpPost("GetCwssInputRecord")] + public ApiResponse GetCwssInputRecord(ApiRequestParam? apiRequestParam) + { + var result = new ApiResponse(); + try + { + do + { + var cwssInputRecordList = _inputRecordService.GetCwssInputRecordList(); + + if (cwssInputRecordList != null) + { + if (!string.IsNullOrEmpty(apiRequestParam.MaterialBarcode)) + cwssInputRecordList = cwssInputRecordList.Where(x => x.MaterialBarcode == apiRequestParam.MaterialBarcode) + .ToList(); + if (!string.IsNullOrEmpty(apiRequestParam.CanNumber)) + cwssInputRecordList = cwssInputRecordList.Where(x => x.CanNumber == apiRequestParam.CanNumber).ToList(); + if (!string.IsNullOrEmpty(apiRequestParam.beginTime)) + cwssInputRecordList = cwssInputRecordList.Where(x => x.RecordTime >= Convert.ToDateTime(apiRequestParam.beginTime)).ToList(); + if (!string.IsNullOrEmpty(apiRequestParam.endTime)) + cwssInputRecordList = cwssInputRecordList.Where(x => x.RecordTime <= Convert.ToDateTime(apiRequestParam.endTime)).ToList(); + } + + string matStr = JsonSerializer.Serialize(cwssInputRecordList); + result.SetSuccess(matStr); + _logger.LogInformation($"获取Cwss投料记录成功:{matStr},时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + + } while (false); + } + catch(Exception e) + { + result.SetException(e, "获取Cwss投料记录异常"); + _logger.LogError($"获取Cwss投料记录异常:{e.Message}"); + } + return result; + } + /// /// 下发Cwss开仓指令 /// @@ -201,4 +246,44 @@ public class CwssIngCheckController } return result; } + + /// + /// 保存投料记录 + /// + private void SaveInputRecord(IngredientInfo info,int isFlag,string remark) + { + try + { + CwssInputRecord cwssInputRecord = new CwssInputRecord() + { + MaterialBarcode = info.MaterialBarcode, + CanNumber = info.CanNumber, + EquipId = info.EquipId, + InputQuantity = info.InputQuantity, + InputWeight = info.InputWeight, + IsRemainder = info.IsRemainder, + RemainderQuantity = info.RemainderQuantity, + RemainderWeight = info.RemainderWeight, + IsOpen = info.IsOpen, + IsFlag = isFlag, + Remark = remark, + RecordTime = DateTime.Now + }; + + bool result = _inputRecordService.SaveCwssInputRecord(cwssInputRecord); + + if (result) + { + _logger.LogInformation($"投料记录:{JsonSerializer.Serialize(cwssInputRecord)}保存成功"); + } + else + { + _logger.LogInformation($"投料记录:{JsonSerializer.Serialize(cwssInputRecord)}保存失败"); + } + } + catch (Exception ex) + { + _logger.LogError($"投料记录保存异常:{ex.Message}"); + } + } } \ No newline at end of file diff --git a/SlnMesnac/Controllers/McsIngCheckController.cs b/SlnMesnac/Controllers/McsIngCheckController.cs index d127a10..a836e33 100644 --- a/SlnMesnac/Controllers/McsIngCheckController.cs +++ b/SlnMesnac/Controllers/McsIngCheckController.cs @@ -21,6 +21,8 @@ public class McsIngCheckController private IWmsTaskOutService _wmsTaskOutService; private IMcsBinToMaterService _mcsBinToMaterService; private IMcsMaterialInfoService _mcsMaterialInfoService; + private IInputRecordService _inputRecordService; + /// /// @@ -36,7 +38,8 @@ public class McsIngCheckController AppConfig appConfig, IWmsTaskOutService wmsTaskOutService, PlcPool plcPool, - IMcsMaterialInfoService mcsMaterialInfoService) + IMcsMaterialInfoService mcsMaterialInfoService, + IInputRecordService inputRecordService) { _logger = logger; _mcsBinToMaterService = mcsBinToMaterService; @@ -44,6 +47,7 @@ public class McsIngCheckController _wmsTaskOutService = wmsTaskOutService; _plcPool = plcPool; _mcsMaterialInfoService = mcsMaterialInfoService; + _inputRecordService = inputRecordService; } @@ -150,6 +154,7 @@ public class McsIngCheckController } //保存数据 + SaveInputRecord(ingredientInfo, 1, ""); } while (false); } @@ -162,6 +167,48 @@ public class McsIngCheckController return result; } + /// + /// 获取Mcs投料记录 + /// + /// + /// + [HttpPost("GetMcsInputRecord")] + public ApiResponse GetMcsInputRecord(ApiRequestParam? apiRequestParam) + { + var result = new ApiResponse(); + try + { + do + { + var inputRecordList = _inputRecordService.GetMcsInputRecordList(); + + if (inputRecordList != null) + { + if (!string.IsNullOrEmpty(apiRequestParam.MaterialBarcode)) + inputRecordList = inputRecordList.Where(x => x.MaterialBarcode == apiRequestParam.MaterialBarcode) + .ToList(); + if (!string.IsNullOrEmpty(apiRequestParam.CanNumber)) + inputRecordList = inputRecordList.Where(x => x.CanNumber == apiRequestParam.CanNumber).ToList(); + if (!string.IsNullOrEmpty(apiRequestParam.beginTime)) + inputRecordList = inputRecordList.Where(x => x.RecordTime >= Convert.ToDateTime(apiRequestParam.beginTime)).ToList(); + if (!string.IsNullOrEmpty(apiRequestParam.endTime)) + inputRecordList = inputRecordList.Where(x => x.RecordTime <= Convert.ToDateTime(apiRequestParam.endTime)).ToList(); + } + + string matStr = JsonSerializer.Serialize(inputRecordList); + result.SetSuccess(matStr); + _logger.LogInformation($"获取Mcs投料记录成功:{matStr},时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + + } while (false); + } + catch(Exception e) + { + result.SetException(e, "获取Cwss投料记录异常"); + _logger.LogError($"获取Cwss投料记录异常:{e.Message}"); + } + return result; + } + /// /// 下发MCS开仓指令 /// @@ -223,4 +270,44 @@ public class McsIngCheckController } return result; } + + /// + /// 保存投料记录 + /// + private void SaveInputRecord(IngredientInfo info,int isFlag,string remark) + { + try + { + McsInputRecord mcsInputRecord = new McsInputRecord() + { + MaterialBarcode = info.MaterialBarcode, + CanNumber = info.CanNumber, + EquipId = info.EquipId, + InputQuantity = info.InputQuantity, + InputWeight = info.InputWeight, + IsRemainder = info.IsRemainder, + RemainderQuantity = info.RemainderQuantity, + RemainderWeight = info.RemainderWeight, + IsOpen = info.IsOpen, + IsFlag = isFlag, + Remark = remark, + RecordTime = DateTime.Now + }; + + bool result = _inputRecordService.SaveMcsInputRecord(mcsInputRecord); + + if (result) + { + _logger.LogInformation($"投料记录:{JsonSerializer.Serialize(mcsInputRecord)}保存成功"); + } + else + { + _logger.LogInformation($"投料记录:{JsonSerializer.Serialize(mcsInputRecord)}保存失败"); + } + } + catch (Exception ex) + { + _logger.LogError($"投料记录保存异常:{ex.Message}"); + } + } } \ No newline at end of file diff --git a/SlnMesnac/appsettings.Development.json b/SlnMesnac/appsettings.Development.json index b6aaae9..764d921 100644 --- a/SlnMesnac/appsettings.Development.json +++ b/SlnMesnac/appsettings.Development.json @@ -28,6 +28,11 @@ "configId": "cwss", "dbType": 1, "connStr": "server=58.63.214.27,23315;uid=dkmes;pwd=Duken123;database=ShareDB_MES" + }, + { + "configId": "mesApi", + "dbType": 2, + "connStr": "DataSource=E:\\桌面\\杜肯密炼MES项目\\程序设计\\Durk.SlnMesnac\\SlnMesnac\\bin\\Debug\\net6.0\\data\\data.db" } ], "PlcConfig": [