123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- using PlcSiemens.Core.Extension;
- using ServiceCenter.Extensions;
- using ServiceCenter.Logs;
- using ServiceCenter.SqlSugars;
- using SqlSugar;
- using System.ComponentModel;
- using WCS.Core;
- using WCS.Entity;
- using WCS.Entity.Protocol.Station;
- using WCS.WorkEngineering.Extensions;
- using WCS.WorkEngineering.WebApi.Controllers;
- using WCS.WorkEngineering.Worlds;
- using TaskStatus = WCS.Entity.TaskStatus;
- namespace WCS.WorkEngineering.Systems
- {
- /// <summary>
- /// 分流点
- /// </summary>
- [BelongTo(typeof(SortingBranchWorld))]
- [Description("环形库分流点")]
- public class 环形库分流点 : DeviceSystem<Device<IStation520, IStation521, IStation523, IStation91>>
- {
- protected override bool ParallelDo => true;
- public override void Do(Device<IStation520, IStation521, IStation523, IStation91> obj)
- {
- if (obj.Data.VoucherNo != obj.Data2.VoucherNo)
- {
- if (obj.Data2.TaskNumber != 0 && obj.Data2.TaskNumber != 2)
- {
- obj.Data.TaskNumber = obj.Data2.TaskNumber;
- World.Log($"复写:{obj.Data.TaskNumber}");
- }
- World.Log($"凭证号不一致,DB520:{obj.Data.VoucherNo}-DB521:{obj.Data2.VoucherNo}", LogLevelEnum.Mid);
- return;
- }
- if (obj.Data3.Status.HasFlag(StationStatus.Run))
- {
- World.Log("设备运行中");
- return;
- }
- ;
- if (!obj.Data3.Status.HasFlag(StationStatus.OT_Status))
- {
- World.Log("站台货物信息与实际占用不一致", LogLevelEnum.Mid);
- return;
- }
- if (!obj.Data3.Status.HasFlag(StationStatus.PH_Status))
- {
- World.Log("站台无光电信息", LogLevelEnum.Mid);
- return;
- }
- ;
- if (obj.Data2.Request != 1)
- {
- World.Log("无请求", LogLevelEnum.Mid);
- return;
- }
- var isPut = false;
- var nextAdd = GetNext(obj);
- if (nextAdd == 9999) return;
- var goodsType = obj.Data4.Length.ToInt();
- int taskId = 0;
- SqlSugarHelper.Do(_db =>
- {
- var db = _db.Default;
- WCS_TaskInfo? taskInfo;
- if (obj.Data2.TaskNumber == 1 || obj.Data2.TaskNumber == 3 || obj.Data2.TaskNumber == 2)
- {
- var type = goodsType.ToString();
- //找到一条起点是当前位置且状态小于2的任务
- taskInfo = db.Queryable<WCS_TaskInfo>().NoLock().OrderBy(x => x.AddTime).First(x => x.Status < TaskStatus.FinishOfShunt && x.AddrFrom == obj.Entity.Code && x.BarCode.Contains("Error") && x.AddrNext == null && x.GoodsType == goodsType);
- if (taskInfo == null)
- {
- switch (obj.Data2.TaskNumber)
- {
- case 1:
- WmsApi.PalletizingCreateseErrorTasks(obj.Entity.Code, type);
- break;
- case 3: //bc质量
- WmsApi.PalletizingCreateseErrorTasks(obj.Entity.Code, type, 3);
- break;
- case 2: //南北流错
- WmsApi.PalletizingCreateseErrorTasks(obj.Entity.Code, type, 2);
- break;
- }
- return;
- }
- if (taskInfo.Status == TaskStatus.NewBuild)
- {
- //更新任务状态
- taskInfo.Status = TaskStatus.WaitingToExecute;
- taskInfo.EditTime =DateTime.Now;
- taskInfo.EditWho = "WCS";
- db.UpdateableRowLock(taskInfo).ExecuteCommand();
- taskInfo.AddWCS_TASK_DTL(db, obj.Entity.Code, $"初始化异常轮入库任务信息");
- return;
- }
- }
- taskInfo = db.Queryable<WCS_TaskInfo>().NoLock().First(v => v.ID == obj.Data2.TaskNumber && v.Status < TaskStatus.FinishOfShunt );
- if (taskInfo == null)
- {
- taskInfo = db.Queryable<WCS_TaskInfo>().NoLock().First(x => x.AddrFrom == obj.Entity.Code && x.BarCode.Contains("Error") && x.Status== TaskStatus.WaitingToExecute && x.AddrNext == null && x.GoodsType == goodsType);
- if (taskInfo==null)
- {
- World.Log($"未找到对应的WCS任务{obj.Data2.TaskNumber},1", LogLevelEnum.High);
- return;
- }
- }
- if (taskInfo.AddTime < DateTime.Now.AddHours(-12) && obj.Data2.TaskNumber == taskInfo.ID)
- {
- obj.Data.TaskNumber = 1;
- obj.Data.GoodsEnd = obj.Entity.Code.ToShort();
- obj.Data.VoucherNo++;
- World.Log($"超时执行记录:任务号[{taskInfo.ID}]-[{obj.Data.TaskNumber}]-[{obj.Data.VoucherNo}]");
- return;
- }
- if (taskInfo.Grade != null && (taskInfo.Grade.ToUpper() != "A") && obj.Data2.TaskNumber == taskInfo.ID)
- {
- obj.Data.TaskNumber = 3;
- obj.Data.GoodsEnd = obj.Entity.Code.ToShort();
- obj.Data.VoucherNo++;
- World.Log($"BC执行记录:任务号[{taskInfo.ID}]-[{obj.Data.TaskNumber}]-[{obj.Data.VoucherNo}]");
- return;
- }
- if (!taskInfo.BarCode.Contains("Error"))
- {
- switch (goodsType)
- {
- case 9 when !taskInfo.BarCode.Contains("HAWS09"):
- World.Log($"外检结果与任务条码不匹配--外检结果:[{goodsType}]-条码[{taskInfo.BarCode}]", LogLevelEnum.High);
- return;
- case 18 when !taskInfo.BarCode.Contains("HAWS18"):
- World.Log($"外检结果与任务条码不匹配--外检结果:[{goodsType}]-条码[{taskInfo.BarCode}]", LogLevelEnum.High);
- return;
- case 34 when !taskInfo.BarCode.Contains("HAWS34"):
- World.Log($"外检结果与任务条码不匹配--外检结果:[{goodsType}]-条码[{taskInfo.BarCode}]", LogLevelEnum.High);
- return;
- case 50 when !taskInfo.BarCode.Contains("HAWS50"):
- World.Log($"外检结果与任务条码不匹配--外检结果:[{goodsType}]-条码[{taskInfo.BarCode}]", LogLevelEnum.High);
- return;
- }
- }
- switch (obj.Entity.Code)
- {
- case "418":
- if (taskInfo.WarehouseCode != "1N")
- {
- //throw new KnownException($"当前任务应该当前往{taskInfo.WarehouseCode}库", LogLevelEnum.Mid);
- if (taskInfo.WarehouseCode.Contains("N"))
- {
- EditFlow(taskInfo, "1N", db, obj.Entity.Code);
- return;
- }
- WriteInfo(obj, taskInfo);
- return;
- }
- break;
- case "618":
- if (taskInfo.WarehouseCode != "1S")
- {
- //throw new KnownException($"当前任务应该当前往{taskInfo.WarehouseCode}库", LogLevelEnum.Mid);
- if (taskInfo.WarehouseCode.Contains("S"))
- {
- EditFlow(taskInfo, "1S", db, obj.Entity.Code);
- return;
- }
-
- WriteInfo(obj, taskInfo);
- return;
- }
- break;
- case "818":
- if (taskInfo.WarehouseCode != "2N")
- {
- //throw new KnownException($"当前任务应该当前往{taskInfo.WarehouseCode}库", LogLevelEnum.Mid);
- if (taskInfo.WarehouseCode.Contains("N"))
- {
- EditFlow(taskInfo, "2N", db, obj.Entity.Code);
- return;
- }
- WriteInfo(obj, taskInfo);
- return;
- }
- break;
- case "1018":
- if (taskInfo.WarehouseCode != "2S")
- {
- //throw new KnownException($"当前任务应该当前往{taskInfo.WarehouseCode}库", LogLevelEnum.Mid);
- if (taskInfo.WarehouseCode.Contains("S"))
- {
- EditFlow(taskInfo, "2S", db, obj.Entity.Code);
- return;
- }
- WriteInfo(obj, taskInfo);
- return;
- }
- break;
- case "1218":
- if (taskInfo.WarehouseCode != "3N")
- {
- //throw new KnownException($"当前任务应该当前往{taskInfo.WarehouseCode}库", LogLevelEnum.Mid);
- if (taskInfo.WarehouseCode.Contains("N"))
- {
- EditFlow(taskInfo, "3N", db, obj.Entity.Code);
- return;
- }
-
- WriteInfo(obj, taskInfo);
- return;
- }
- break;
- case "1418":
- if (taskInfo.WarehouseCode != "3S")
- {
- //throw new KnownException($"当前任务应该当前往{taskInfo.WarehouseCode}库", LogLevelEnum.Mid);
- if (taskInfo.WarehouseCode.Contains("S"))
- {
- EditFlow(taskInfo, "3S", db, obj.Entity.Code);
- return;
- }
- WriteInfo(obj, taskInfo);
- return;
- }
- break;
- }
- var isTruss = false; //表示这个工字轮是要去桁架区域码垛的,默认不作处理
- if (goodsType == 18)
- {
- //判断这个垛型是否是到桁架区域进行码垛
- var toTruss = db.Queryable<BillBomsetgrp>().NoLock().First(x => x.BomCode.Contains(taskInfo.MatCode) && x.IsStop == 0);
- if (toTruss == null)
- {
- World.Log($"未找到任务{taskInfo.ID}对应垛型信息,请确认垛型是否停用", LogLevelEnum.Mid);
- return;
- }
-
- if (toTruss.IsTruss)
- {
- nextAdd = obj.Entity.Code switch
- {
- "418" => 455,
- "618" => 655,
- "818" => 855,
- "1018" => 1055,
- "1218" => 1255,
- "1418" => 1455,
- _ => 9999
- };
- isTruss = true;
- }
- }
- taskInfo = db.Queryable<WCS_TaskInfo>().ReadPastUpdLock().First(v => v.ID == obj.Data2.TaskNumber && v.Status < TaskStatus.FinishOfShunt && !v.BarCode.Contains("Error"));
- if (taskInfo == null)
- {
- taskInfo = db.Queryable<WCS_TaskInfo>().ReadPastUpdLock().First(x => x.AddrFrom == obj.Entity.Code && x.BarCode.Contains("Error") && x.Status== TaskStatus.WaitingToExecute && x.AddrNext == null && x.GoodsType == goodsType);
- if (taskInfo==null)
- {
- World.Log($"未找到对应的WCS任务{obj.Data2.TaskNumber},2", LogLevelEnum.Mid);
- return;
- };
- }
- taskId = taskInfo.ID;
- if (goodsType != 9 && !isTruss) //09工字轮在环形库分流点只分配下一个地址,不作任何变更
- {
- taskInfo.AddrNext = nextAdd.ToString();
- taskInfo.Status = TaskStatus.FinishOfShunt;
- taskInfo.EditTime = DateTime.Now;
- taskInfo.WarehouseCode = taskInfo.WarehouseCode.Contains("R") ? taskInfo.WarehouseCode : taskInfo.WarehouseCode + "R";
- taskInfo.AddrTo = "Robot";
- taskInfo.GoodsType = goodsType;
- db.UpdateableRowLock(taskInfo).UpdateColumns(x => new { x.AddrNext, x.Status, x.EditTime, x.WarehouseCode, x.AddrTo, x.GoodsType }).ExecuteCommand();
- taskInfo.AddWCS_TASK_DTL(db, obj.Entity.Code, nextAdd.ToString(), "工字轮完成环形库分流");
- }
- else
- {
- taskInfo.AddrNext = nextAdd.ToString();
- taskInfo.EditTime = DateTime.Now;
- taskInfo.GoodsType = goodsType;
- db.UpdateableRowLock(taskInfo).UpdateColumns(x => new { x.AddrNext, x.EditTime, x.GoodsType }).ExecuteCommand();
- taskInfo.AddWCS_TASK_DTL(db, obj.Entity.Code, nextAdd.ToString(), "工字轮途径环形库分流点");
- }
- isPut = true;
- });
- if (!isPut) return;
- obj.Data.TaskNumber = taskId;
- obj.Data.TaskNumber = taskId;
- obj.Data.GoodsStart = obj.Entity.Code.ToShort();
- obj.Data.GoodsStart = obj.Entity.Code.ToShort();
- obj.Data.GoodsEnd = nextAdd;
- obj.Data.GoodsEnd = nextAdd;
- obj.Data.SetVoucherNo();
- World.Log($"执行记录:任务号[{taskId}]-[{obj.Data.VoucherNo}]");
- }
- private void WriteInfo(Device<IStation520, IStation521, IStation523, IStation91> device, WCS_TaskInfo task)
- {
- device.Data.TaskNumber = 2;
- device.Data.GoodsEnd = device.Entity.Code.ToShort();
- device.Data.VoucherNo++;
- World.Log($"南北流错执行记录:任务号[{task.ID}]-[{device.Data.TaskNumber}]-[{device.Data.VoucherNo}]");
- }
- /// <summary>
- /// 编辑流向
- /// </summary>
- public void EditFlow(WCS_TaskInfo task, string warehouseCode, SqlSugarScopeProvider db, string locCode)
- {
- WmsApi.EditorialFlow(new FjEditorialFlowRequest() { TaskId = task.ID, LocCode = locCode, WareCode = warehouseCode });
- task.WarehouseCode = warehouseCode;
- db.UpdateableRowLock(task).UpdateColumns(x=> new {x.WarehouseCode}).ExecuteCommand();
- task.AddWCS_TASK_DTL(db, locCode, $"变更流向至{warehouseCode}");
- }
- public override bool Select(Device dev)
- {
- return dev.Code is "418" or "618" or "818" or "1018" or "1218" or "1418";
- }
- /// <summary>
- /// 计算非零九的去向
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- public short GetNext(Device<IStation520, IStation521, IStation523, IStation91> obj)
- {
- return obj.Data4.Length switch
- {
- 9 => obj.Entity.Code switch
- {
- "418" => 455,
- "618" => 655,
- "818" => 855,
- "1018" => 1055,
- "1218" => 1255,
- "1418" => 1455,
- _ => 9999
- },
- 18 => obj.Entity.Code switch
- {
- "418" => 444,
- "618" => 644,
- "818" => 844,
- "1018" => 1044,
- "1218" => 1244,
- "1418" => 1444,
- _ => 9999
- },
- 50 => obj.Entity.Code switch
- {
- "418" => 426,
- "618" => 626,
- "818" => 826,
- "1018" => 1026,
- "1218" => 1226,
- "1418" => 1426,
- _ => 9999
- },
- 34 => obj.Entity.Code switch
- {
- "418" => 435,
- "618" => 635,
- "818" => 835,
- "1018" => 1035,
- "1218" => 1235,
- "1418" => 1435,
- _ => 9999
- },
- _ => 9999
- };
- }
- }
- }
|