From e127d46553234fbd6d29b9f4ab2ad0b319b9b27a Mon Sep 17 00:00:00 2001 From: zhou keda <1315948824@qq.com> Date: Mon, 5 Aug 2024 17:24:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=BA=E5=8F=B0=E5=8E=9F=E6=96=99=E8=AE=BE?= =?UTF-8?q?=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entity/EqpEquipment.cs | 5 + .../Entity/PrdRawMaterialBarcode.cs | 16 +- .../Entity/PrdRawMaterialBarcodeRecord.cs | 12 +- .../PrdRawMaterialBarcodeService.cs | 198 ++++++++++++++++++ 4 files changed, 227 insertions(+), 4 deletions(-) diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpEquipment.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpEquipment.cs index ccbfef31..3d60f4fa 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpEquipment.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpEquipment.cs @@ -228,4 +228,9 @@ public partial class EqpEquipment : BaseEntity /// 入库仓库id /// public string? instock_warehouse_id { get; set; } + + /// + /// 截料阀 + /// + public string stop_valve { get; set; } } diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdRawMaterialBarcode.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdRawMaterialBarcode.cs index 42a61f33..d18baa73 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdRawMaterialBarcode.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdRawMaterialBarcode.cs @@ -20,9 +20,19 @@ public partial class PrdRawMaterialBarcode : BaseEntity public string bill_code { get; set; } = string.Empty; /// - /// 料仓id/机台id + /// 料仓id /// public string equip_id { get; set; } = string.Empty; + + /// + /// 机台id + /// + public string equip_ids { get; set; } = string.Empty; + + /// + /// 截料阀 + /// + public string stop_valve { get; set; } /// /// 物料id @@ -52,12 +62,12 @@ public partial class PrdRawMaterialBarcode : BaseEntity /// /// 开始时间 /// - public DateTime start_time { get; set; } = DateTime.Now; + public DateTime? start_time { get; set; } /// /// 结束时间 /// - public DateTime end_time { get; set; } = DateTime.Now; + public DateTime? end_time { get; set; } /// /// 备注 diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdRawMaterialBarcodeRecord.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdRawMaterialBarcodeRecord.cs index 07e37510..b6310261 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdRawMaterialBarcodeRecord.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdRawMaterialBarcodeRecord.cs @@ -20,9 +20,19 @@ public partial class PrdRawMaterialBarcodeRecord : BaseEntity public string bill_code { get; set; } = string.Empty; /// - /// 料仓id/机台id + /// 料仓id /// public string equip_id { get; set; } = string.Empty; + + /// + /// 机台id + /// + public string equip_ids { get; set; } = string.Empty; + + /// + /// 截料阀 + /// + public string stop_valve { get; set; } /// /// 物料id diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdRawMaterialBarcodeService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdRawMaterialBarcodeService.cs index 3aebee3d..31349b68 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdRawMaterialBarcodeService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdRawMaterialBarcodeService.cs @@ -25,6 +25,7 @@ using Tnb.WarehouseMgr.Entities.Configs; using Tnb.Common.Utils; using Tnb.WarehouseMgr.Entities.Consts; using HttpClientHelper = Tnb.Common.Utils.HttpClientHelper; +using Tnb.Common.Redis; namespace Tnb.ProductionMgr { @@ -46,11 +47,13 @@ namespace Tnb.ProductionMgr public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); private readonly IVisualDevService _visualDevService; private readonly IRunService _runService; + private readonly RedisData _redisData; public PrdRawMaterialBarcodeService(ISqlSugarRepository repository, IUserManager userManager, IBillRullService billRuleService, IVisualDevService visualDevService, + RedisData redisData, IRunService runService, IDictionaryDataService dictionaryDataService) { @@ -60,6 +63,7 @@ namespace Tnb.ProductionMgr _dictionaryDataService = dictionaryDataService; _visualDevService = visualDevService; _runService = runService; + _redisData = redisData; OverideFuncs.UpdateAsync = Update; } @@ -290,6 +294,7 @@ namespace Tnb.ProductionMgr .SetColumns(x => x.end_time == null) .SetColumns(x => x.is_update == 0) .SetColumns(x => x.material_id == "") + .SetColumns(x=>x.absorb_material_finish==0) .Where(x => x.id == item.id) .ExecuteCommandAsync(); @@ -331,5 +336,198 @@ namespace Tnb.ProductionMgr } return "成功"; } + + /// + /// 更新截料阀 + /// + /// + [HttpPost] + public async Task UpdateStopValve(List ids) + { + try + { + await _db.Ado.BeginTranAsync(); + + List prdRawMaterialBarcodeList = await _db.Queryable() + .Where(x => ids.Contains(x.id)).ToListAsync(); + foreach (var item in prdRawMaterialBarcodeList) + { + if (string.IsNullOrEmpty(item.stop_valve)) + { + throw Oops.Bah($"{item.bill_code}未设置截料阀"); + } + + if (string.IsNullOrEmpty(item.equip_ids)) + { + throw Oops.Bah($"{item.bill_code}未设置机台"); + } + + List equipIdList = JsonConvert.DeserializeObject>(item.equip_ids); + List eqpEquipments = await _db.Queryable().Where(x => equipIdList.Contains(x.id)).ToListAsync(); + foreach (var equipment in eqpEquipments) + { + EqpDaq eqpDaq = await _db.Queryable().Where(x => x.equip_id == equipment.id && x.label_name.Contains("原料选择")).FirstAsync(); + + if (eqpDaq == null) + { + throw Oops.Bah($"{equipment.name}未设置原料选择数据采集项"); + } + + Dictionary dicCommand3 = new(StringComparer.OrdinalIgnoreCase) + { + ["DevName"] = eqpDaq.equip_code, + ["token"] = _eleCtlCfg.token, + ["TagName"] = eqpDaq.label_name, + ["Value"] = item.stop_valve, + }; + Log.Information($"{eqpDaq.equip_code}{eqpDaq.label_name}更新参数:{JsonConvert.SerializeObject(dicCommand3)}"); + string responseresult3 = await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand3, false); + Log.Information($"{eqpDaq.equip_code}{eqpDaq.label_name}更新返回结果:{responseresult3}"); + + await _db.Updateable() + .SetColumns(x => x.start_time == DateTime.Now) + .SetColumns(x => x.is_update == 1) + .Where(x => x.id == item.id) + .ExecuteCommandAsync(); + } + + } + + await _db.Ado.CommitTranAsync(); + } + catch (Exception e) + { + await _db.Ado.RollbackTranAsync(); + throw Oops.Bah(e.Message); + } + + return "成功"; + } + + /// + /// 管道状态 + /// + /// + [HttpPost] + public async Task GetPipingStatus(List ids) + { + try + { + await _db.Ado.BeginTranAsync(); + + List prdRawMaterialBarcodeList = await _db.Queryable() + .Where(x => ids.Contains(x.id)).ToListAsync(); + foreach (var item in prdRawMaterialBarcodeList) + { + + if (string.IsNullOrEmpty(item.equip_ids)) + { + throw Oops.Bah($"{item.bill_code}未设置机台"); + } + + List equipIdList = JsonConvert.DeserializeObject>(item.equip_ids); + List eqpEquipments = await _db.Queryable().Where(x => equipIdList.Contains(x.id)).ToListAsync(); + foreach (var equipment in eqpEquipments) + { + EqpDaq eqpDaq = await _db.Queryable().Where(x => x.equip_id == equipment.id && x.label_name.Contains("配管状态")).FirstAsync(); + + if (eqpDaq == null) + { + throw Oops.Bah($"{equipment.name}未设置配管状态数据采集项"); + } + + bool data = await _redisData.TryGetValueByKeyField(eqpDaq.equip_code, eqpDaq.label_name); + + int pipingStatus = data ? 1 : 0; + await _db.Updateable() + .SetColumns(x => x.piping_status == pipingStatus) + .Where(x => x.id == item.id) + .ExecuteCommandAsync(); + } + + } + + await _db.Ado.CommitTranAsync(); + } + catch (Exception e) + { + await _db.Ado.RollbackTranAsync(); + throw Oops.Bah(e.Message); + } + + return "成功"; + } + + /// + /// 机台原料设定吸料完成 + /// + /// + [HttpPost] + public async Task MaterialSuctionCompleted2(List ids) + { + try + { + await _db.Ado.BeginTranAsync(); + + List prdRawMaterialBarcodeList = await _db.Queryable() + .Where(x => ids.Contains(x.id)).ToListAsync(); + List insertList = new List(); + foreach (var item in prdRawMaterialBarcodeList) + { + List equipIdList = JsonConvert.DeserializeObject>(item.equip_ids); + List eqpEquipments = await _db.Queryable().Where(x => equipIdList.Contains(x.id)).ToListAsync(); + foreach (var equipment in eqpEquipments) + { + EqpDaq eqpDaq = await _db.Queryable().Where(x => x.equip_id == equipment.id && x.label_name.Contains("原料选择")).FirstAsync(); + + if (eqpDaq == null) + { + throw Oops.Bah($"{equipment.name}未设置原料选择数据采集项"); + } + + Dictionary dicCommand3 = new(StringComparer.OrdinalIgnoreCase) + { + ["DevName"] = eqpDaq.equip_code, + ["token"] = _eleCtlCfg.token, + ["TagName"] = eqpDaq.label_name, + ["Value"] = "", + }; + Log.Information($"{eqpDaq.equip_code}{eqpDaq.label_name}吸料完成参数:{JsonConvert.SerializeObject(dicCommand3)}"); + string responseresult3 = await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand3, false); + Log.Information($"{eqpDaq.equip_code}{eqpDaq.label_name}吸料完成返回结果:{responseresult3}"); + + } + + PrdRawMaterialBarcodeRecord prdRawMaterialBarcodeRecord = item.Adapt(); + prdRawMaterialBarcodeRecord.id = SnowflakeIdHelper.NextId(); + prdRawMaterialBarcodeRecord.end_time = DateTime.Now; + insertList.Add(prdRawMaterialBarcodeRecord); + + await _db.Updateable() + .SetColumns(x => x.bill_code == "") + .SetColumns(x => x.start_time == null) + .SetColumns(x => x.end_time == null) + .SetColumns(x => x.is_update == 0) + .SetColumns(x=>x.piping_status == 0) + .SetColumns(x=>x.absorb_material_finish==0) + .Where(x => x.id == item.id) + .ExecuteCommandAsync(); + + } + + if (!insertList.IsEmpty()) + { + await _db.Insertable(insertList).ExecuteCommandAsync(); + } + + await _db.Ado.CommitTranAsync(); + } + catch (Exception e) + { + await _db.Ado.RollbackTranAsync(); + throw Oops.Bah(e.Message); + } + return "成功"; + } } } \ No newline at end of file