服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-08-16 eec9f268552af1d0ce8c95312930770669f1cc18
Tiger.Business.MES/WorkAction/PackingAction.cs
@@ -32,6 +32,7 @@
        public Dictionary<int, BAS_LABEL_TEMP> LabelDic { get; set; }    = new();
        public List<BAS_LABEL_PV> LabelPV { get; set; } = new();
        public int FinishLevel = 0;
        public bool NeedWeighing { get; set; } = false;
        #endregion Propertys & Variables
        #region Functions
@@ -65,6 +66,8 @@
                LabelDic.Add(code.PKG_LEVEL, label);
            }
            LabelPV = Biz.Db.Queryable<BAS_LABEL_PV>().ToList();
            //获取是否包装完后需要称重
            NeedWeighing = Setting.OPTION_2 == "Y";
            //如果工序上下文中没有包装记录则新建一个,有则获取当前的包装记录
            if (CurPosition.Context.ContainsKey("CurPackage") && !CurPosition.Context["CurPackage"].IsNullOrEmpty())
            {
@@ -172,6 +175,7 @@
                CurCmd = data;
                PrintTimes++;
                action.Data.Data = data;
                action.Data.ShortMsg = new("打印标签", ShortMessage.Types.Normal);
                //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);
            }
@@ -200,6 +204,7 @@
                        if (!pInput.IsFinish || pInput.PkgSN.IsNullOrEmpty())
                        {
                            var dtl = PkgRule.Details.First(q => q.PKG_LEVEL == pInput.PkgLevel);
                            action.Data.ShortMsg = new("扫描错误", ShortMessage.Types.Error);
                            action.IsSuccessed = false;
                            //action.LocaleMsg = new($"条码扫描失败,请重新扫描第{dtl.PKG_LEVEL}层包装[{dtl.PkgType.PKG_NAME}]的标签条码");
                            action.LocaleMsg = new("MES.WorkAction.PackingAction.ScanFail", dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME);
@@ -209,6 +214,7 @@
                        if (GetPackageList(CurPkg.Item).Any(q => q.SN == pInput.PkgSN))
                        {
                            var dtl = PkgRule.Details.First(q => q.PKG_LEVEL == pInput.PkgLevel);
                            action.Data.ShortMsg = new("扫描错误", ShortMessage.Types.Error);
                            action.IsSuccessed = false;
                            //action.LocaleMsg = new($"条码[{pInput.PkgSN}]无需重复扫描,请扫描第{dtl.PKG_LEVEL}层包装[{dtl.PkgType.PKG_NAME}]的标签条码");
                            action.LocaleMsg = new("MES.WorkAction.PackingAction.ScanRepeat", pInput.PkgSN, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME);
@@ -218,6 +224,10 @@
                        CurCmd = null;
                        PrintTimes = 0;
                        action = SavePkgData(input, action);
                        if (action.IsSuccessed)
                        {
                            action.Data.ShortMsg = new("扫描成功", ShortMessage.Types.Success);
                        }
                    }
                    break;
                //Print:打印,打印当前包装层级的标签
@@ -235,6 +245,7 @@
                            data.PkgLevel = dtl.PKG_LEVEL;
                            CurCmd = data;
                            action.Data.Data = data;
                            action.Data.ShortMsg = new("扫描标签", ShortMessage.Types.Normal);
                            //action.LocaleMsg = new($"请扫描第{dtl.PKG_LEVEL}层包装[{dtl.PkgType.PKG_NAME}]的标签条码");
                            action.LocaleMsg = new("MES.WorkAction.PackingAction.PleaseScanLabel", dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME);
                        } 
@@ -246,6 +257,7 @@
                            {
                                PrintTimes++;
                                action.Data.Data = CurCmd;
                                action.Data.ShortMsg = new("重新打印", ShortMessage.Types.Normal);
                                //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);
                            }
@@ -253,6 +265,7 @@
                            {
                                CurCmd = null;
                                PrintTimes = 0;
                                action.Data.ShortMsg = new("打印失败", ShortMessage.Types.Failed);
                                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);
@@ -267,7 +280,43 @@
                    {
                        CurCmd = null;
                        PrintTimes = 0;
                        action = End();
                        if (NeedWeighing)
                        {
                            var data = new PackingActionOutput() { PkgInfo = CurPkg };
                            data.ExecCode = "Weighing";
                            data.PkgLevel = CurPkgItem.PKG_LEVEL;
                            CurCmd = data;
                            action.Data.Data = data;
                            action.Data.ShortMsg = new("包装成功", ShortMessage.Types.Success);
                            //action.LocaleMsg = new($"请把包装[{CurPkgItem.Package.SN}]上称称重");
                            action.LocaleMsg = new("MES.WorkAction.PackingAction.PleaseWeighing", CurPkgItem.Package.SN);
                        }
                        else
                        {
                            action = End();
                        }
                    }
                    break;
                // Complete:完成,完成全部包装后结束行为
                case "Weighing":
                    if (CurCmd.ExecCode == "Weighing")
                    {
                        if (!pInput.WeightInfo.IsNullOrEmpty() && pInput.WeightInfo.Weight > 0)
                        {
                            CurCmd = null;
                            PrintTimes = 0;
                            CurPkgItem.Package.WEIGHT = pInput.WeightInfo.Weight;
                            CurPkgItem.Package.WEIGHT_UNIT = pInput.WeightInfo.Unit;
                            action = End();
                        }
                        else
                        {
                            action.IsSuccessed = false;
                            action.Data.ShortMsg = new("称重失败", ShortMessage.Types.Failed);
                            //action.LocaleMsg = new($"包装[{CurPkgItem.Package.SN}]称重数据异常,请重新上称称重");
                            action.LocaleMsg = new("MES.WorkAction.PackingAction.PleaseWeighingAgain", CurPkgItem.Package.SN);
                            return action;
                        }
                    }
                    break;
                // 手动结束包装,保存暂存的包装数据
@@ -294,6 +343,7 @@
                            data.PkgLevel = dtl.PKG_LEVEL;
                            CurCmd = data;
                            action.Data.Data = data;
                            action.Data.ShortMsg = new("扫描标签", ShortMessage.Types.Normal);
                            //action.LocaleMsg = new($"请扫描第{dtl.PKG_LEVEL}层包装[{dtl.PkgType.PKG_NAME}]的标签条码");
                            action.LocaleMsg = new("MES.WorkAction.PackingAction.PleaseScanLabel", dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME);
                        }
@@ -309,6 +359,7 @@
                            CurCmd = data;
                            PrintTimes++;
                            action.Data.Data = data;
                            action.Data.ShortMsg = new("打印标签", ShortMessage.Types.Normal);
                            //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);
                        }
@@ -485,6 +536,7 @@
                    //数据异常
                    else
                    {
                        action.Data.ShortMsg = new("包装错误", ShortMessage.Types.Error);
                        var pdtl = PkgRule.Details.First(q => q.PKG_LEVEL == pInput.PkgLevel);
                        action.IsSuccessed = false;
                        //action.LocaleMsg = new($"客户端提交的包装层级[{pdtl.PKG_LEVEL}]({pdtl.PkgType.PKG_NAME})数据不是正在处理的包装层级[{dtl.PKG_LEVEL}]({dtl.PkgType.PKG_NAME}),工序已重置,请重新扫描进站产品条码");
@@ -495,6 +547,7 @@
            }
            catch (System.Exception ex)
            {
                action.Data.ShortMsg = new("包装异常", ShortMessage.Types.Exception);
                var dtl = PkgRule.Details.First(q => q.PKG_LEVEL == pInput.PkgLevel);
                action.CatchExceptionWithLog(ex, $"包装行为:扫描第{dtl.PKG_LEVEL}层包装[{dtl.PkgType.PKG_NAME}]的标签条码[{input.SN}]后保存数据失败");
                action.IsSuccessed = false;
@@ -525,14 +578,15 @@
            data.PkgLevel = CurPkg.Item.PKG_LEVEL;
            CurCmd = data;
            action.Data.Data = data;
            action.Data.ShortMsg = new("保存包装数据", ShortMessage.Types.Normal);
            //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;
            }
            //if (CurStep.IsNullOrEmpty())
            //{
            //    IsFinished = true;
            //}
            return action;
        }
@@ -547,45 +601,49 @@
            //记录行为操作记录
            var wipActs = new List<MES_WIP_ACT>();
            foreach (var wipSn in CurPosition.CurWipSNs)
            //不是手动结束包装则保存行为操作记录
            if (!CurStep.IsNullOrEmpty())
            {
                var wipAct = new MES_WIP_ACT()
                {
                    AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG,
                    AUTH_PROD = CurPosition.CurLine.LINE_CODE,
                    WIP_ID = wipSn.ID,
                    HIS_ID = CurPosition.CurWipSNHiss.First(q => q.SN == wipSn.SN).ID,
                    SN = wipSn.SN,
                    STATUS = wipSn.STATUS,
                    ITEM_CODE = wipSn.ITEM_CODE,
                    WORK_ORDER = wipSn.WORK_ORDER,
                    BATCH_NO = wipSn.BATCH_NO,
                    ROT_CODE = wipSn.ROT_CODE,
                    NODE_ID = wipSn.NODE_ID,
                    NODE_NAME = wipSn.NODE_NAME,
                    ACT_ID = NodeAct.ID,
                    ACT_NAME = NodeAct.ACT_NAME,
                    FTY_CODE = wipSn.FTY_CODE,
                    WS_CODE = wipSn.WS_CODE,
                    LINE_CODE = wipSn.LINE_CODE,
                    POST_CODE = wipSn.POST_CODE,
                    OPER_CODE = wipSn.OPER_CODE,
                    SEGMENT = wipSn.SEGMENT,
                    FLOW_SN = wipSn.FLOW_SN,
                    TRAY_SN = wipSn.TRAY_SN,
                    INNER_SN = wipSn.INNER_SN,
                    CARTON_SN = wipSn.CARTON_SN,
                    PALLET_SN = wipSn.PALLET_SN,
                    OPERATION_TIME = DateTime.Now,
                    SFTS_CODE = wipSn.SFTS_CODE,
                    SFT_CODE = wipSn.SFT_CODE,
                    PRD_CODE = wipSn.PRD_CODE,
                    ACT_TYPE = NodeAct.ACT_TYPE,
                    ACT_SN = wipSn.SN,
                    ACT_RESULT = "Y",
                    TRACE_INFO = $"产品条码[{string.Join(",", CurPosition.CurSN)}]包装完成",
                };
                wipActs.Add(wipAct);
               foreach (var wipSn in CurPosition.CurWipSNs)
               {
                   var wipAct = new MES_WIP_ACT()
                   {
                       AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG,
                       AUTH_PROD = CurPosition.CurLine.LINE_CODE,
                       WIP_ID = wipSn.ID,
                       HIS_ID = CurPosition.CurWipSNHiss.First(q => q.SN == wipSn.SN).ID,
                       SN = wipSn.SN,
                       STATUS = wipSn.STATUS,
                       ITEM_CODE = wipSn.ITEM_CODE,
                       WORK_ORDER = wipSn.WORK_ORDER,
                       BATCH_NO = wipSn.BATCH_NO,
                       ROT_CODE = wipSn.ROT_CODE,
                       NODE_ID = wipSn.NODE_ID,
                       NODE_NAME = wipSn.NODE_NAME,
                       ACT_ID = NodeAct.ID,
                       ACT_NAME = NodeAct.ACT_NAME,
                       FTY_CODE = wipSn.FTY_CODE,
                       WS_CODE = wipSn.WS_CODE,
                       LINE_CODE = wipSn.LINE_CODE,
                       POST_CODE = wipSn.POST_CODE,
                       OPER_CODE = wipSn.OPER_CODE,
                       SEGMENT = wipSn.SEGMENT,
                       FLOW_SN = wipSn.FLOW_SN,
                       TRAY_SN = wipSn.TRAY_SN,
                       INNER_SN = wipSn.INNER_SN,
                       CARTON_SN = wipSn.CARTON_SN,
                       PALLET_SN = wipSn.PALLET_SN,
                       OPERATION_TIME = DateTime.Now,
                       SFTS_CODE = wipSn.SFTS_CODE,
                       SFT_CODE = wipSn.SFT_CODE,
                       PRD_CODE = wipSn.PRD_CODE,
                       ACT_TYPE = NodeAct.ACT_TYPE,
                       ACT_SN = wipSn.SN,
                       ACT_RESULT = "Y",
                       TRACE_INFO = $"产品条码[{string.Join(",", CurPosition.CurSN)}]包装完成",
                   };
                   wipActs.Add(wipAct);
               }
            }
            //创建变量克隆对象用于传入DBSubmitAction中保存当前需要暂存的数据值
@@ -595,7 +653,10 @@
            CurStep.DBSubmitAction = () =>
            {
                var db = CurPosition.GetCommitDB();
                db.Storageable(_wipActs, CurPosition.UserCode).ExecuteCommand();
                if (_wipActs.Any())
                {
                   db.Storageable(_wipActs, CurPosition.UserCode).ExecuteCommand();
                }
                if (_pkgList.Any())
                {
                    db.Insertable(_pkgList, CurPosition.UserCode).ExecuteCommand();
@@ -641,8 +702,9 @@
            }
            IsFinished = true;
            action.LocaleMsg = new($"产品条码[{CurPosition.CurSN}]包装完成");
            action.LocaleMsg = new("MES.WorkAction.PackingAction.PackingSuccess", CurPosition.CurSN);
            action.Data.ShortMsg = new("包装完成", ShortMessage.Types.Success);
            action.LocaleMsg = new($"条码[{CurPkg.Item.Package.SN}]包装完成");
            action.LocaleMsg = new("MES.WorkAction.PackingAction.PackingSuccess", CurPkg.Item.Package.SN);
            return action;
        }