| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using Tiger.IBusiness; |
| | | using Tiger.IBusiness.MES.WorkAction; |
| | | using Tiger.Model; |
| | | using Tiger.Model.Entitys.MES.Position; |
| | | |
| | |
| | | public BAS_PKG_RULE PkgRule { get; set; } |
| | | public WipPkg CurPkg { get; set; } |
| | | public WipPkgItem CurPkgItem { get; set; } |
| | | public PackingActionOutput CurPrint { get; set; } |
| | | public PackingActionOutput CurCmd { get; set; } |
| | | public int PrintTimes = 0; |
| | | public Dictionary<int, BAS_LABEL_TEMP> LabelDic { get; set; } |
| | | public List<BAS_LABEL_PV> LabelPV { get; set; } |
| | | public Dictionary<int, BAS_LABEL_TEMP> LabelDic { get; set; } = new(); |
| | | public List<BAS_LABEL_PV> LabelPV { get; set; } = new(); |
| | | public int FinishLevel = 0; |
| | | #endregion Propertys & Variables |
| | | |
| | |
| | | NodeAct = nodeAct; |
| | | Setting = setting; |
| | | #endregion |
| | | |
| | | PkgRule = Biz.Db.Queryable<BAS_PKG_RULE>().Where(q => q.RULE_CODE == setting.PKG_CODE).IncludesAllFirstLayer().IncludesAllSecondLayer(q => q.Details).First(); |
| | | //根据行为设置获取多层包装的标签打印模板字典 |
| | | for (int i = 1; i < 10; i++) |
| | | //手动结束包装专用,临时执行行为 |
| | | if (setting.IsNullOrEmpty()) |
| | | { |
| | | var code = Setting.GetType().GetProperty($"OPTION_{i}")?.GetValue(Setting).ToString() ?? ""; |
| | | var label = code.IsNullOrEmpty() ? null : Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(q => q.LABEL_CODE == code).IncludesAllFirstLayer().First(); |
| | | LabelDic.Add(i, label); |
| | | PkgRule = Biz.Db.Queryable<BAS_PKG_RULE>().Where(q => q.RULE_CODE == setting.PKG_CODE).IncludesAllFirstLayer().IncludesAllSecondLayer(q => q.Details).First(); |
| | | } |
| | | //正常条码过站执行包装行为 |
| | | else |
| | | { |
| | | PkgRule = Biz.Db.Queryable<BAS_PKG_RULE>().Where(q => q.RULE_CODE == setting.PKG_CODE).IncludesAllFirstLayer().IncludesAllSecondLayer(q => q.Details).First(); |
| | | } |
| | | //根据行为设置获取多层包装的标签打印模板字典 |
| | | //for (int i = 1; i < 10; i++) |
| | | //{ |
| | | // var code = Setting.GetType().GetProperty($"OPTION_{i}")?.GetValue(Setting)?.ToString() ?? ""; |
| | | // var label = code.IsNullOrEmpty() ? null : Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(q => q.LABEL_CODE == code).IncludesAllFirstLayer().First(); |
| | | // LabelDic.Add(i, label); |
| | | //} |
| | | var codes = (Setting.OPTION_1?? "").JsonToObject<List<WipPkgItem>>(); |
| | | foreach (var code in codes) |
| | | { |
| | | var label = code.LABEL_CODE.IsNullOrEmpty() ? null : Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(q => q.LABEL_CODE == code.LABEL_CODE).IncludesAllFirstLayer().First(); |
| | | LabelDic.Add(code.PKG_LEVEL, label); |
| | | } |
| | | //如果工序上下文中没有包装记录则新建一个,有则获取当前的包装记录 |
| | | if (CurPosition.Context.ContainsKey("CurPackage") && !CurPosition.Context["CurPackage"].IsNullOrEmpty()) |
| | |
| | | IS_MIN_PKG = max.PkgType.IS_MIN_PKG, |
| | | PKG_LEVEL = max.PKG_LEVEL, |
| | | PKG_QTY = max.PKG_QTY, |
| | | LABEL_CODE = LabelDic[max.PKG_LEVEL].LABEL_CODE, |
| | | LABEL_CODE = LabelDic[max.PKG_LEVEL]?.LABEL_CODE, |
| | | } |
| | | }; |
| | | WipPkgItem child = null; |
| | |
| | | IS_MIN_PKG = dtl.PkgType.IS_MIN_PKG, |
| | | PKG_LEVEL = dtl.PKG_LEVEL, |
| | | PKG_QTY = dtl.PKG_QTY, |
| | | LABEL_CODE = LabelDic[dtl.PKG_LEVEL].LABEL_CODE, |
| | | LABEL_CODE = LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE, |
| | | }; |
| | | if (!child.IsNullOrEmpty()) |
| | | { |
| | |
| | | child = item; |
| | | } |
| | | } |
| | | CurPkg.Item.Items.Add(child); |
| | | if (!child.IsNullOrEmpty()) |
| | | { |
| | | CurPkg.Item.Items.Add(child); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | var msg = new Locale("MES.WorkAction.PackingAction.BeginPrint", min.PKG_LEVEL, min.PkgType.PKG_NAME, LabelDic[min.PKG_LEVEL].LABEL_CODE, LabelDic[min.PKG_LEVEL].LABEL_NAME); |
| | | //var msg = new Locale($"开始打印第{min.PKG_LEVEL}层包装[{min.PkgType.PKG_NAME}]的标签[{LabelDic[min.PKG_LEVEL].LABEL_CODE}: {LabelDic[min.PKG_LEVEL].LABEL_NAME}]"); |
| | | var msg = new Locale("MES.WorkAction.PackingAction.BeginPrint", min.PKG_LEVEL, min.PkgType.PKG_NAME, LabelDic[min.PKG_LEVEL]?.LABEL_CODE, LabelDic[min.PKG_LEVEL].LABEL_NAME); |
| | | //var msg = new Locale($"开始打印第{min.PKG_LEVEL}层包装[{min.PkgType.PKG_NAME}]的标签[{LabelDic[min.PKG_LEVEL]?.LABEL_CODE}: {LabelDic[min.PKG_LEVEL].LABEL_NAME}]"); |
| | | return msg; |
| | | } |
| | | } |
| | |
| | | data.ExecCode = "Print"; |
| | | data.PkgLevel = min.PKG_LEVEL; |
| | | data.PrintLable = LabelDic[min.PKG_LEVEL]; |
| | | CurPrint = data; |
| | | CurCmd = data; |
| | | PrintTimes++; |
| | | action.Data.Data = data; |
| | | //action.LocaleMsg = new Locale($"开始第{PrintTimes}次打印第{min.PKG_LEVEL}层包装[{min.PkgType.PKG_NAME}]的标签[{LabelDic[min.PKG_LEVEL].LABEL_CODE}: {LabelDic[min.PKG_LEVEL].LABEL_NAME}]"); |
| | | action.LocaleMsg = new Locale("MES.WorkAction.PackingAction.BeginPrint", PrintTimes, min.PKG_LEVEL, min.PkgType.PKG_NAME, LabelDic[min.PKG_LEVEL].LABEL_CODE, LabelDic[min.PKG_LEVEL].LABEL_NAME); |
| | | //action.LocaleMsg = new Locale($"开始第{PrintTimes}次打印第{min.PKG_LEVEL}层包装[{min.PkgType.PKG_NAME}]的标签[{LabelDic[min.PKG_LEVEL]?.LABEL_CODE}: {LabelDic[min.PKG_LEVEL].LABEL_NAME}]"); |
| | | action.LocaleMsg = new Locale("MES.WorkAction.PackingAction.BeginPrint", PrintTimes, min.PKG_LEVEL, min.PkgType.PKG_NAME, LabelDic[min.PKG_LEVEL]?.LABEL_CODE, LabelDic[min.PKG_LEVEL].LABEL_NAME); |
| | | } |
| | | |
| | | //如果返回成功则认为当前行为可以开始执行,否则返回失败 |
| | |
| | | { |
| | | var action = new ApiAction<SubmitOutput>(new SubmitOutput()); |
| | | |
| | | var pInput = input.Data?.JsonToObject<PackingActionInput>(); |
| | | switch (pInput.ExecCode) |
| | | var pInput = input?.Data?.JsonToObject<PackingActionInput>(); |
| | | switch (pInput?.ExecCode) |
| | | { |
| | | //Scan:扫码,扫描当前包装层级的条码 |
| | | case "Scan": |
| | | if (CurCmd.IsNullOrEmpty() || CurCmd.ExecCode == "Scan" || (CurCmd.ExecCode == "Print" && CurCmd.PkgLevel == pInput.PkgLevel)) |
| | | { |
| | | //客户端扫描成功 |
| | | if (pInput.IsFinish) |
| | | { |
| | | CurCmd = null; |
| | | PrintTimes = 0; |
| | | action = SavePkgData(input, action); |
| | | } |
| | | //客户端扫描失败 |
| | |
| | | break; |
| | | //Print:打印,打印当前包装层级的标签 |
| | | case "Print": |
| | | if (CurCmd.ExecCode == "Print") |
| | | { |
| | | var dtl = PkgRule.Details.First(q => q.PKG_LEVEL == pInput.PkgLevel); |
| | | //客户端完成打印 |
| | | if (pInput.IsFinish) |
| | | { |
| | | CurPrint = null; |
| | | CurCmd = null; |
| | | PrintTimes = 0; |
| | | var data = new PackingActionOutput() { PkgInfo = CurPkg }; |
| | | data.ExecCode = "Scan"; |
| | | data.PkgLevel = dtl.PKG_LEVEL; |
| | | CurCmd = data; |
| | | action.Data.Data = data; |
| | | //action.LocaleMsg = new($"请扫描第{dtl.PKG_LEVEL}层包装[{dtl.PkgType.PKG_NAME}]的标签条码"); |
| | | action.LocaleMsg = new("MES.WorkAction.PackingAction.PleaseScanLabel", dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME); |
| | |
| | | else |
| | | { |
| | | //如果打印失败则尝试三次重新打印,如果都失败则重置工序 |
| | | if (PrintTimes < 3 && !CurPrint.IsNullOrEmpty()) |
| | | if (PrintTimes < 3 && !CurCmd.IsNullOrEmpty()) |
| | | { |
| | | PrintTimes++; |
| | | action.Data.Data = CurPrint; |
| | | //action.LocaleMsg = new Locale($"开始{PrintTimes}次打印第{dtl.PKG_LEVEL}层包装[{dtl.PkgType.PKG_NAME}]的标签[{LabelDic[dtl.PKG_LEVEL].LABEL_CODE}: {LabelDic[dtl.PKG_LEVEL].LABEL_NAME}]"); |
| | | action.LocaleMsg = new Locale("MES.WorkAction.PackingAction.BeginPrint", PrintTimes, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME, LabelDic[dtl.PKG_LEVEL].LABEL_CODE, LabelDic[dtl.PKG_LEVEL].LABEL_NAME); |
| | | action.Data.Data = CurCmd; |
| | | //action.LocaleMsg = new Locale($"开始{PrintTimes}次打印第{dtl.PKG_LEVEL}层包装[{dtl.PkgType.PKG_NAME}]的标签[{LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE}: {LabelDic[dtl.PKG_LEVEL].LABEL_NAME}]"); |
| | | action.LocaleMsg = new Locale("MES.WorkAction.PackingAction.BeginPrint", PrintTimes, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME, LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE, LabelDic[dtl.PKG_LEVEL].LABEL_NAME); |
| | | } |
| | | else |
| | | { |
| | | CurPrint = null; |
| | | CurCmd = null; |
| | | PrintTimes = 0; |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = new($"尝试第{PrintTimes}次打印第{dtl.PKG_LEVEL}层包装[{dtl.PkgType.PKG_NAME}]的标签[{LabelDic[dtl.PKG_LEVEL].LABEL_CODE}: {LabelDic[dtl.PKG_LEVEL].LABEL_NAME}]失败,工序已重置,请重新扫描进站产品条码"); |
| | | action.LocaleMsg = new("MES.WorkAction.PackingAction.PrintFail3Times", PrintTimes, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME, LabelDic[dtl.PKG_LEVEL].LABEL_CODE, LabelDic[dtl.PKG_LEVEL].LABEL_NAME); |
| | | CurPosition.ResetSteps(); |
| | | //action.LocaleMsg = new($"尝试第{PrintTimes}次打印第{dtl.PKG_LEVEL}层包装[{dtl.PkgType.PKG_NAME}]的标签[{LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE}: {LabelDic[dtl.PKG_LEVEL].LABEL_NAME}]失败,工序已重置,请重新扫描进站产品条码"); |
| | | action.LocaleMsg = new("MES.WorkAction.PackingAction.PrintFail3Times", PrintTimes, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME, LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE, LabelDic[dtl.PKG_LEVEL].LABEL_NAME); |
| | | CurPosition.ResetNode(); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | // Complete:完成,完成全部包装后结束行为 |
| | | case "Complete": |
| | | if (CurCmd.ExecCode == "Complete") |
| | | { |
| | | CurCmd = null; |
| | | PrintTimes = 0; |
| | | action = End(); |
| | | } |
| | | break; |
| | | // 手动结束包装,保存暂存的包装数据 |
| | | case null: |
| | | { |
| | | CurCmd = null; |
| | | PrintTimes = 0; |
| | | FinishLevel = 1; |
| | | WipPkgItem curItem = CurPkg.Item; |
| | | while (curItem.PKG_LEVEL > 2) |
| | | { |
| | | var next = curItem.Items.FirstOrDefault(q => !q.IsFinished); |
| | | curItem = next; |
| | | } |
| | | CurPkgItem = curItem; |
| | | |
| | | //手动结束包装默认从第二层包装开始验证 |
| | | var dtl = PkgRule.Details.First(q => q.PKG_LEVEL == 2); |
| | | //行为设定的OPTION_1-9是包装不同层级的标签模板代码,如果为空则不需要打印 |
| | | if (LabelDic[dtl.PKG_LEVEL].IsNullOrEmpty()) |
| | | { |
| | | var data = new PackingActionOutput() { PkgInfo = CurPkg }; |
| | | data.ExecCode = "Scan"; |
| | | data.PkgLevel = dtl.PKG_LEVEL; |
| | | CurCmd = data; |
| | | action.Data.Data = data; |
| | | //action.LocaleMsg = new($"请扫描第{dtl.PKG_LEVEL}层包装[{dtl.PkgType.PKG_NAME}]的标签条码"); |
| | | action.LocaleMsg = new("MES.WorkAction.PackingAction.PleaseScanLabel", dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME); |
| | | } |
| | | else |
| | | { |
| | | //设置打印变量值 |
| | | LabelDic[dtl.PKG_LEVEL] = CurPosition.SetLabelVariables(LabelPV, LabelDic[dtl.PKG_LEVEL]); |
| | | |
| | | var data = new PackingActionOutput() { PkgInfo = CurPkg }; |
| | | data.ExecCode = "Print"; |
| | | data.PkgLevel = dtl.PKG_LEVEL; |
| | | data.PrintLable = LabelDic[dtl.PKG_LEVEL]; |
| | | CurCmd = data; |
| | | PrintTimes++; |
| | | action.Data.Data = data; |
| | | //action.LocaleMsg = new Locale($"开始第{PrintTimes}次打印第{min.PKG_LEVEL}层包装[{min.PkgType.PKG_NAME}]的标签[{LabelDic[min.PKG_LEVEL]?.LABEL_CODE}: {LabelDic[min.PKG_LEVEL].LABEL_NAME}]"); |
| | | action.LocaleMsg = new Locale("MES.WorkAction.PackingAction.BeginPrint", PrintTimes, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME, LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE, LabelDic[dtl.PKG_LEVEL].LABEL_NAME); |
| | | } |
| | | } |
| | | break; |
| | | default: |
| | |
| | | //如果行为设置为出错需要重置工序操作 |
| | | if (!action.IsSuccessed && NodeAct.NEED_RESET == "Y") |
| | | { |
| | | CurPosition.ResetSteps(); |
| | | CurPosition.ResetNode(); |
| | | } |
| | | return action; |
| | | } |
| | |
| | | IS_MIN_PKG = dtl.PkgType.IS_MIN_PKG, |
| | | PKG_LEVEL = dtl.PKG_LEVEL, |
| | | PKG_QTY = dtl.PKG_QTY, |
| | | LABEL_CODE = LabelDic[dtl.PKG_LEVEL].LABEL_CODE, |
| | | LABEL_CODE = LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE, |
| | | IsFinished = true, |
| | | Package = new() |
| | | { |
| | |
| | | IS_MIN_PKG = nextDtl.PkgType.IS_MIN_PKG, |
| | | PKG_LEVEL = nextDtl.PKG_LEVEL, |
| | | PKG_QTY = nextDtl.PKG_QTY, |
| | | LABEL_CODE = LabelDic[nextDtl.PKG_LEVEL].LABEL_CODE, |
| | | LABEL_CODE = LabelDic[nextDtl.PKG_LEVEL]?.LABEL_CODE, |
| | | }; |
| | | curItem.Items.Add(next); |
| | | } |
| | | curItem = next; |
| | | } |
| | | //添加当前的包装明细到上一层包装的明细列表 |
| | | curItem.Items.Add(CurPkgItem); |
| | | if (!curItem.Items.Contains(CurPkgItem)) |
| | | { |
| | | curItem.Items.Add(CurPkgItem); |
| | | } |
| | | CurPkgItem = curItem; |
| | | |
| | | //添加明细后判断当前包装层级的明细数量是否等于包装数量,若相等则标记当前包装层级为完成并尝试打印标签 |
| | | if (CurPkgItem.Items.Count == CurPkgItem.PKG_QTY) |
| | | if (CurPkgItem.Items.Count(q => q.IsFinished) == CurPkgItem.PKG_QTY || CurStep.IsNullOrEmpty()) |
| | | { |
| | | //行为设定的OPTION_1-9是包装不同层级的标签模板代码,如果为空则不需要打印 |
| | | if (LabelDic[dtl.PKG_LEVEL].IsNullOrEmpty()) |
| | |
| | | var data = new PackingActionOutput() { PkgInfo = CurPkg }; |
| | | data.ExecCode = "Scan"; |
| | | data.PkgLevel = dtl.PKG_LEVEL; |
| | | CurCmd = data; |
| | | action.Data.Data = data; |
| | | //action.LocaleMsg = new($"请扫描第{dtl.PKG_LEVEL}层包装[{dtl.PkgType.PKG_NAME}]的标签条码"); |
| | | action.LocaleMsg = new("MES.WorkAction.PackingAction.PleaseScanLabel", dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME); |
| | |
| | | data.ExecCode = "Print"; |
| | | data.PkgLevel = dtl.PKG_LEVEL; |
| | | data.PrintLable = LabelDic[dtl.PKG_LEVEL]; |
| | | CurPrint = data; |
| | | CurCmd = data; |
| | | PrintTimes++; |
| | | action.Data.Data = data; |
| | | //action.LocaleMsg = new Locale($"开始第{PrintTimes}次打印第{dtl.PKG_LEVEL}层包装[{dtl.PkgType.PKG_NAME}]的标签[{LabelDic[dtl.PKG_LEVEL].LABEL_CODE}: {LabelDic[dtl.PKG_LEVEL].LABEL_NAME}]"); |
| | | action.LocaleMsg = new Locale("MES.WorkAction.PackingAction.BeginPrint", PrintTimes, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME, LabelDic[dtl.PKG_LEVEL].LABEL_CODE, LabelDic[dtl.PKG_LEVEL].LABEL_NAME); |
| | | //action.LocaleMsg = new Locale($"开始第{PrintTimes}次打印第{dtl.PKG_LEVEL}层包装[{dtl.PkgType.PKG_NAME}]的标签[{LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE}: {LabelDic[dtl.PKG_LEVEL].LABEL_NAME}]"); |
| | | action.LocaleMsg = new Locale("MES.WorkAction.PackingAction.BeginPrint", PrintTimes, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME, LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE, LabelDic[dtl.PKG_LEVEL].LABEL_NAME); |
| | | } |
| | | } |
| | | //当前包装层级的明细数量未达到包装数量,则完成本次扫描,等待下个产品进站 |
| | |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = new($"客户端提交的包装层级[{pdtl.PKG_LEVEL}]({pdtl.PkgType.PKG_NAME})数据不是正在处理的包装层级[{dtl.PKG_LEVEL}]({dtl.PkgType.PKG_NAME}),工序已重置,请重新扫描进站产品条码"); |
| | | action.LocaleMsg = new("MES.WorkAction.PackingAction.SaveLevelNotMatchException", pdtl.PKG_LEVEL, pdtl.PkgType.PKG_NAME, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME); |
| | | CurPosition.ResetSteps(); |
| | | CurPosition.ResetNode(); |
| | | } |
| | | } |
| | | } |
| | |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = new($"扫描第{dtl.PKG_LEVEL}层包装[{dtl.PkgType.PKG_NAME}]的标签条码[{input.SN}]后保存数据失败,工序已重置,请重新扫描进站产品条码"); |
| | | action.LocaleMsg = new("MES.WorkAction.PackingAction.SavePkgDataException", dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME, input.SN); |
| | | CurPosition.ResetSteps(); |
| | | CurPosition.ResetNode(); |
| | | } |
| | | return action; |
| | | } |
| | |
| | | var data = new PackingActionOutput() { PkgInfo = CurPkg }; |
| | | data.ExecCode = "Complete"; |
| | | data.PkgLevel = CurPkg.Item.PKG_LEVEL; |
| | | CurCmd = data; |
| | | action.Data.Data = data; |
| | | //action.LocaleMsg = new($"第{CurPkg.Item.PKG_LEVEL}层包装[{CurPkg.Item.PKG_NAME}]已经全部完成,保存包装数据"); |
| | | action.LocaleMsg = new("MES.WorkAction.PackingAction.PackageComplete", CurPkg.Item.PKG_LEVEL, CurPkg.Item.PKG_NAME); |
| | | |
| | | //手动结束包装则标记行为完成 |
| | | if (CurStep.IsNullOrEmpty()) |
| | | { |
| | | IsFinished = true; |
| | | } |
| | | |
| | | return action; |
| | | } |
| | | |