From 189b31f4a6957782d924ee957cbd924399e53982 Mon Sep 17 00:00:00 2001 From: qianjiawei <1184704771@qq.com> Date: Wed, 8 Nov 2023 15:54:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A8=E6=A3=80=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.ProductionMgr/RedisBackGround.cs | 122 ++++++++++-------- QcMgr/Tnb.QcMgr.Entities/Dto/Trigger.cs | 22 ++++ QcMgr/Tnb.QcMgr/QcCheckPlanService.cs | 99 ++++++++++++++ 3 files changed, 190 insertions(+), 53 deletions(-) diff --git a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs index 12879acb..c1278d4b 100644 --- a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs +++ b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs @@ -25,62 +25,74 @@ namespace Tnb.ProductionMgr //获取注塑装箱状态 private void GetZSPackStatus(object state) { - string[] strs = new string[1] { "TY4C-ZHUSU1" }; - string sign = "agvMode"; - foreach (string s in strs) + try { - Dictionary dic = _redisData.HGetAll(s).Result; - foreach (KeyValuePair kv in dic) + string[] strs = new string[1] { "TY4C-ZHUSU1" }; + string sign = "agvMode"; + foreach (string s in strs) { - if (!kv.Key.Contains(sign)) + Dictionary dic = _redisData.HGetAll(s).Result; + foreach (KeyValuePair kv in dic) { - continue; - } - - JObject? res = JsonConvert.DeserializeObject(kv.Value); - if (res != null && res["Value"] != null) - { - if (int.Parse(res["Value"]!.ToString()) is not ((int)Eagvmode.无请求) and not ((int)Eagvmode.收到请求)) + if (!kv.Key.Contains(sign)) { - InstockInput instockInput = new() + continue; + } + JObject? res = JsonConvert.DeserializeObject(kv.Value); + if (res != null && res["Value"] != null) + { + if (int.Parse(res["Value"]!.ToString()) is not ((int)Eagvmode.无请求) and not ((int)Eagvmode.收到请求)) { - equip_code = res["TagName"]!.ToString() - }; - _ = _prdInstockService.InstockTypeOne(instockInput); + InstockInput instockInput = new() + { + equip_code = res["DevName"]!.ToString(), + label_code = res["TagName"]!.ToString() + }; + _prdInstockService.InstockTypeOne(instockInput); + } } } } } + catch (Exception) + { + } } //获取挤出装箱状态 private void GetJCPackStatus(object state) { - string[] strs = new string[1] { "TY4C-SHUSONG-JC" }; - string sign = "AGVFullCall"; - foreach (string s in strs) + try { - Dictionary dic = _redisData.HGetAll(s).Result; - foreach (KeyValuePair kv in dic) + string[] strs = new string[1] { "TY4C-SHUSONG-JC" }; + string sign = "AGVFullCall"; + foreach (string s in strs) { - if (!kv.Key.Contains(sign)) + Dictionary dic = _redisData.HGetAll(s).Result; + foreach (KeyValuePair kv in dic) { - continue; - } - - JObject? res = JsonConvert.DeserializeObject(kv.Value); - if (res != null && res["Value"] != null) - { - if (res.Value("Value")) + if (!kv.Key.Contains(sign)) { - InstockInput instockInput = new() + continue; + } + JObject? res = JsonConvert.DeserializeObject(kv.Value); + if (res != null && res["Value"] != null) + { + if (res.Value("Value")) { - equip_code = res["TagName"]!.ToString() - }; - _ = _prdInstockService.InstockTypeOne(instockInput); + InstockInput instockInput = new() + { + equip_code = res["DevName"]!.ToString(), + label_code = res["TagName"]!.ToString() + }; + _prdInstockService.InstockTypeOne(instockInput); + } } } } } + catch (Exception) + { + } } //获取限位状态 private void GetLimitStatus(object state) @@ -90,29 +102,33 @@ namespace Tnb.ProductionMgr Console.WriteLine($"获取挤出装箱状态"); string data = _redisData.GetHash("TY4C-SHUSONG-JC", "AGVFullCall").Result; Console.WriteLine(data);*/ - /* - string[] strs = new string[1] { "TY4C-WAIBAO" }; - string sign = "AGVCall"; - foreach (string s in strs) + try { - Dictionary dic = _redisData.HGetAll(s).Result; - foreach (KeyValuePair kv in dic) + string[] strs = new string[1] { "TY4C-WAIBAO" }; + string sign = "AGVCall"; + foreach (string s in strs) { - if (!kv.Key.Contains(sign)) + Dictionary dic = _redisData.HGetAll(s).Result; + foreach (KeyValuePair kv in dic) { - continue; - } - - JObject? res = JsonConvert.DeserializeObject(kv.Value); - if (res != null && res["Value"] != null) - { - if (res.Value("Value")) + if (!kv.Key.Contains(sign)) { - // + continue; + } + JObject? res = JsonConvert.DeserializeObject(kv.Value); + if (res != null && res["Value"] != null) + { + if (res.Value("Value")) + { + // + } } } } - }*/ + } + catch (Exception) + { + } } public void Dispose() { @@ -122,9 +138,9 @@ namespace Tnb.ProductionMgr } public Task StartAsync(CancellationToken cancellationToken) { - // ZSpacktimer = new Timer(GetZSPackStatus, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); - // JCpacktimer = new Timer(GetJCPackStatus, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); - // limittimer = new Timer(GetLimitStatus, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); + ZSpacktimer = new Timer(GetZSPackStatus, null, TimeSpan.Zero, TimeSpan.FromSeconds(5)); + JCpacktimer = new Timer(GetJCPackStatus, null, TimeSpan.Zero, TimeSpan.FromSeconds(5)); + limittimer = new Timer(GetLimitStatus, null, TimeSpan.Zero, TimeSpan.FromSeconds(5)); return Task.CompletedTask; } public Task StopAsync(CancellationToken cancellationToken) diff --git a/QcMgr/Tnb.QcMgr.Entities/Dto/Trigger.cs b/QcMgr/Tnb.QcMgr.Entities/Dto/Trigger.cs index ff4126df..1ac31664 100644 --- a/QcMgr/Tnb.QcMgr.Entities/Dto/Trigger.cs +++ b/QcMgr/Tnb.QcMgr.Entities/Dto/Trigger.cs @@ -45,4 +45,26 @@ namespace Tnb.QcMgr.Entities /// public int? pronum { get; set; } } + + + public class CreateTaskEntity + { + /// + /// 物料方案编号 + /// + public List materialids { get; set; } + /// + /// 触发条件 + /// + public EnumTriggerEvent? triggerevent { get; set; } + + public string maintableid { get; set; } + } + public class TaskEntity + { + public List materialids { get; set; } + public QcCheckPlanH qcCheckPlanH { get; set; } + public string maintableid { get; set; } + + } } diff --git a/QcMgr/Tnb.QcMgr/QcCheckPlanService.cs b/QcMgr/Tnb.QcMgr/QcCheckPlanService.cs index 9fafc113..df243bda 100644 --- a/QcMgr/Tnb.QcMgr/QcCheckPlanService.cs +++ b/QcMgr/Tnb.QcMgr/QcCheckPlanService.cs @@ -286,6 +286,105 @@ namespace Tnb.QcMgr } } + + [HttpPost] + public async Task CreateWmsTask(CreateTaskEntity entity) + { + ISugarQueryable Query = _repository.AsSugarClient().Queryable + ((a, b) => new object[] { + JoinType.Inner,a.id== b.mainid, + }); + GetQuery(Query, entity); + List list = await Query.ToListAsync(); + List taskEntities = new List(); + foreach (QcCheckPlanH data in list) + { + if (entity.materialids.Count>0) + { + if (_repository.AsSugarClient().Queryable().Where(p => p.planid == data.id).Any()) + { + var Materials= _repository.AsSugarClient().Queryable().Where(p => p.planid == data.id).Select(p=>p.materialid).ToList(); + var Intersect = entity.materialids.Intersect(Materials).ToList(); + if (Intersect.Count > 0) + { + taskEntities.Add(new TaskEntity { maintableid=entity.maintableid, materialids = Intersect!, qcCheckPlanH = data }); + } + } + } + } + if (taskEntities.Count > 0) + { + await SaveTask(taskEntities); + } + } + + private void GetQuery(ISugarQueryable Query, CreateTaskEntity entity) + { + List DictionaryData = _repository.AsSugarClient().Queryable + ((a, b) => new object[] { JoinType.Left, a.DictionaryTypeId == b.Id, }) + .Where((a, b) => b.FullName == "质检类型选择").ToList(); + QcTriggerEvent TriggerEvent = new(); + EnumTriggerEvent? enumTriggerEvent = entity.triggerevent; + RemarkAttribute remark = RemarkAttribute.GetRemark(enumTriggerEvent); + string type = DictionaryData.Where(p => p.FullName == remark.CheckType).First().Id; + TriggerEvent = _repository.AsSugarClient().Queryable().Where(p => p.type == type && p.name == remark.CheckContent).First(); + Query = Query.Where((a, b) => b.triggertype == "3" && b.content!.Contains(TriggerEvent.id)); + } + + private async Task SaveTask(List taskEntities) + { + DictionaryDataEntity DictionaryData = _repository.AsSugarClient().Queryable + ((a, b) => new object[] { JoinType.Left, a.DictionaryTypeId == b.Id, }) + .Where((a, b) => b.FullName == "质检状态" && a.FullName == "待执行").First(); + foreach (var entity in taskEntities) + { + List plands = await _repository.AsSugarClient().Queryable().Where(p =>p.mainid== entity.qcCheckPlanH.id).ToListAsync(); + + foreach (string s in entity.materialids) + { + DateTime time = DateTime.Now; + QcCheckExecH qcCheckExecH = new() + { + id = SnowflakeIdHelper.NextId(), + checktype = entity.qcCheckPlanH.checktype, + status = DictionaryData.Id, + tasktime = time.ToString("yyyy-MM-dd HH:mm:ss"), + materialid = s, + create_id = _userManager.UserId, + create_time = time, + extras= entity.maintableid + }; + List ExecDs = new(); + foreach (var pland in plands) + { + QcCheckExecD QcCheckExecD = new() + { + mainid = qcCheckExecH.id, + extype = pland.extype, + excontent = pland.excontent, + check = pland.check, + errorcause = pland.errorcause, + errorlevel = pland.errorlevel, + remark = pland.remark, + attachment = pland.attachment, + isexec = pland.isexec, + custom = pland.custom, + typeid = pland.typeid, + itemid = pland.itemid, + create_id = _userManager.UserId, + create_time = time + }; + ExecDs.Add(QcCheckExecD); + } + _ = await _repository.AsSugarClient().Insertable(qcCheckExecH).ExecuteCommandAsync(); + _ = await _repository.AsSugarClient().Insertable(ExecDs).ExecuteCommandAsync(); + } + + } + } + + + /// /// 根据计划生成任务 ///