服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-08-16 eec9f268552af1d0ce8c95312930770669f1cc18
Tiger.Business.MES/Transaction/PackingNode.cs
@@ -55,9 +55,9 @@
                    //如果行为被标记成已完成,则重置工序
                    if (TempPkgAction.IsFinished)
                    {
                        action.Data.OperInfo = OperInfoDic.ContainsKey(CurBatch?.Batch?.BATCH_NO ?? "") ? OperInfoDic[CurBatch.Batch.BATCH_NO] : new();
                        ResetNode();
                    }
                    return action;
                }
                //NodeSubmit:产品过站,正常产品过站逻辑
                else
@@ -70,7 +70,10 @@
                        if (!CurBatch.IsNullOrEmpty() && CurBatch.IsFirstNode(PostCode))
                        {
                            action = NodeSubmit(action, input);
                            return action;
                            //更新工序信息
                            var info = WoContext.GetSnOperInfo(input.SN).Data;
                            info.InputQty = OperInfoDic[CurBatch.Batch.BATCH_NO].InputQty;
                            action.Data.OperInfo = info;
                        }
                        //当前岗位在当前工单不是首站,则查找条码已绑定的工单当作当前工单
                        else
@@ -83,6 +86,8 @@
                            {
                                if (wosns.Count > 1 && wosns.Any(q => q.SN.TRAY_SN != q.SN.OUTER_SN))
                                {
                                    action.Data.ShortMsg = new("请扫描产品", ShortMessage.Types.Error);
                                    action.Data.OperInfo = new();
                                    action.IsSuccessed = false;
                                    action.LocaleMsg = new($"条码[{0}]是载具条码,请扫描载具中的产品条码继续包装操作");
                                    action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.OnlyMinPackage", input.SN);
@@ -90,10 +95,11 @@
                                }
                                if (wosns.First().Batch.ACT_LINE != CurLine.LINE_CODE)
                                {
                                    action.Data.ShortMsg = new("产线错误", ShortMessage.Types.Error);
                                    action.Data.OperInfo = new();
                                    action.IsSuccessed = false;
                                    //action.LocaleMsg = new($"条码[{0}]已在产线[{1}]投入生产,请在正确岗位扫描");
                                    action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.NotCorrectLine", input.SN, wosns.First().Batch.ACT_LINE);
                                    return action;
                                } 
                                else
                                {
@@ -103,14 +109,16 @@
                                       var result = await SelectOrder(new() { AuthOption = input.AuthOption, OrderNo = wosns.First().Batch.ORDER_NO });
                                       if (!result.IsSuccessed)
                                       {
                                           action.IsSuccessed = result.IsSuccessed;
                                            action.Data.ShortMsg = new("工单异常", ShortMessage.Types.Error);
                                            action.Data.OperInfo = new();
                                            action.IsSuccessed = result.IsSuccessed;
                                           action.LocaleMsg = result.LocaleMsg;
                                           return action;
                                       }
                                   }
                                   //条码过站
                                   action = NodeSubmit(action, input);
                                   return action;
                                    action.Data.OperInfo = SetOperNodeInfo(OperInfoDic[CurBatch.Batch.BATCH_NO]);
                                }
                            }
                            //查找不到条码已绑定的工单
@@ -119,18 +127,20 @@
                                //没有当前工单,则先选择工单后再扫描条码
                                if (CurBatch.IsNullOrEmpty())
                                {
                                    action.Data.ShortMsg = new("未选择工单", ShortMessage.Types.Error);
                                    action.Data.OperInfo = new();
                                    action.IsSuccessed = false;
                                    //action.LocaleMsg = new($"未选择工单,请先选择要生产的工单");
                                    action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.NotSelectOrderException");
                                    return action;
                                }
                                //有当前工单且不是投入,则提示条码未投入生产,请先去首站扫描
                                else
                                {
                                    action.Data.ShortMsg = new("未投入生产", ShortMessage.Types.Error);
                                    action.Data.OperInfo = new();
                                    action.IsSuccessed = false;
                                    //action.LocaleMsg = new($"条码[{input.SN}]尚未投入生产,请先去首站扫描", input.SN);
                                    action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.NotInputException", input.SN);
                                    return action;
                                }
                            }
                        }
@@ -142,7 +152,7 @@
                        if (submitStep.IsNullOrEmpty())
                        {
                            action = BeginNextActionStep(input);
                            return action;
                            action.Data.OperInfo = OperInfoDic[CurBatch.Batch.BATCH_NO];
                        }
                        else
                        {
@@ -168,20 +178,28 @@
                            //如果所有工步都完成
                            if (IsFinishAllSteps)
                            {
                                return DoIfFinishAllSteps(result);
                                result = DoIfFinishAllSteps(result);
                            }
                            result.Data.OperInfo = OperInfoDic[CurBatch.Batch.BATCH_NO];
                            return result;
                        }
                    }
                    //没有可执行的工步
                    ResetNode();
                    action.IsSuccessed = false;
                    //action.LocaleMsg = new($"岗位[{CurPosition.POST_CODE}]工步执行异常,请重新扫描产品条码", CurPosition.POST_CODE);
                    action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.WorkStepException", CurPosition.POST_CODE);
                    else
                    {
                        action.Data.ShortMsg = new("重置扫描", ShortMessage.Types.Error);
                        action.Data.OperInfo = OperInfoDic.ContainsKey(CurBatch?.Batch?.BATCH_NO ?? "") ? OperInfoDic[CurBatch.Batch.BATCH_NO] : new();
                        ResetNode();
                       action.IsSuccessed = false;
                       //action.LocaleMsg = new($"岗位[{CurPosition.POST_CODE}]工步执行异常,请重新扫描产品条码", CurPosition.POST_CODE);
                       action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.WorkStepException", CurPosition.POST_CODE);
                    }
                }
            }
            catch (Exception ex)
            {
                action.Data.ShortMsg = new("工序异常", ShortMessage.Types.Error);
                action.Data.OperInfo = OperInfoDic.ContainsKey(CurBatch?.Batch?.BATCH_NO ?? "") ? OperInfoDic[CurBatch.Batch.BATCH_NO] : new();
                //action.CatchExceptionWithLog(ex, $"包装工序:提交操作数据异常");
                action.CatchExceptionWithLog(ex, Biz.L("MES.Transaction.PackingNode.SubmitException"));
            }
@@ -203,16 +221,18 @@
                var woStatus = CurBatch.CheckCanProduce(curNode);
                if (!woStatus.IsSuccessed)
                {
                    woStatus.Data.ShortMsg = new("工单异常", ShortMessage.Types.Error);
                    return woStatus;
                }
                //非法过站防呆:进入工序时要增加判断条码是否按流程过站
                var wipSNs = Biz.Db.Queryable<MES_WIP_DATA>().IncludesAllFirstLayer().Where(q => (q.SN == input.SN || q.TRAY_SN == input.SN) && q.WORK_ORDER == CurBatch.WO.ORDER_NO).ToList();
                if (wipSNs.IsNullOrEmpty())
                {
                   var wipSN = new MES_WIP_DATA()
                   {
                       SN = input.SN,
                       STATUS = MES_WIP_DATA.STATUSs.Init.GetValue(),
                        FLOW_SN = input.SN,
                        STATUS = MES_WIP_DATA.STATUSs.Init.GetValue(),
                       ITEM_CODE = CurBatch.WO.ITEM_CODE,
                       WORK_ORDER = CurBatch.Batch.ORDER_NO,
                       BATCH_NO = CurBatch.Batch.BATCH_NO,
@@ -225,9 +245,33 @@
                   };
                    wipSNs.Add(wipSN);
                }
                //如果条码不是当前工单或者产线的则报错
                if (wipSNs.Any(q => q.WORK_ORDER != CurBatch.WO.ORDER_NO || q.LINE_CODE != CurLine.LINE_CODE))
                {
                    if (wipSNs.First().LINE_CODE == CurLine.LINE_CODE)
                    {
                        action.Data.ShortMsg = new("工单错误", ShortMessage.Types.Error);
                        action.IsSuccessed = false;
                        //action.LocaleMsg = new($"产品[{CurSN}]不属于当前工单,请切换到工单[{wipSNs.First().WORK_ORDER}]后再扫描");
                        action.LocaleMsg = new("MES.Transaction.PackingNode.NodeSubmit.WoError", CurSN, wipSNs.First().WORK_ORDER);
                        return action;
                    }
                    else
                    {
                        action.Data.ShortMsg = new("产线错误", ShortMessage.Types.Error);
                        action.IsSuccessed = false;
                        //action.LocaleMsg = new($"产品[{CurSN}]已在产线[{wipSNs.First().LINE_CODE}]投产,请到产线[{wipSNs.First().LINE_CODE}]扫描");
                        action.LocaleMsg = new("MES.Transaction.PackingNode.NodeSubmit.LineError", CurSN, wipSNs.First().LINE_CODE);
                        return action;
                    }
                }
                //非法过站防呆:进入工序时要增加判断条码是否按流程过站
                var canGotoNext = CurBatch.CanGotoNext(input, wipSNs.First(), curNode);
                if (!canGotoNext.IsSuccessed)
                {
                    woStatus.Data.ShortMsg = new("进站错误", ShortMessage.Types.Error);
                    return canGotoNext;
                }
@@ -242,6 +286,7 @@
                            CurBatch.WoSNs.Add(new()
                            {
                                WORK_ORDER = CurBatch.Batch.ORDER_NO,
                                WIP_ID = wipSN.ID,
                                SN = wipSN.SN,
                                TRAY_SN = wipSN.TRAY_SN,
                                STATUS = BIZ_MES_WO_SN.STATUSs.NotInput.GetValue(),
@@ -309,6 +354,7 @@
                            {
                                AUTH_ORG = wipSN.AUTH_ORG,
                                AUTH_PROD = wipSN.LINE_CODE,
                                WIP_ID = wipSN.ID,
                                SN = wipSN.SN,
                                STATUS = MES_WIP_DFT.STATUSs.WaitHandle.GetValue(),
                                ITEM_CODE = wipSN.ITEM_CODE,
@@ -326,8 +372,10 @@
                                DFT_CODE = dft.DFT_CODE,
                                DFT_NAME = dft.DFT_NAME,
                                DFT_LEVEL = dft.DFT_LEVEL,
                                FLOW_SN = wipSN.FLOW_SN,
                                TRAY_SN = wipSN.TRAY_SN,
                                CONTAINER_SN = wipSN.CONTAINER_SN,
                                INNER_SN = wipSN.INNER_SN,
                                CARTON_SN = wipSN.CARTON_SN,
                                PALLET_SN = wipSN.PALLET_SN,
                                INV_FLAG = wipSN.INV_FLAG,
                                OPERATION_TIME = DateTime.Now,
@@ -352,6 +400,14 @@
                        CurWipSNHiss.Add(new MES_WIP_HIS(wipSN, $"工单[{wipSN.WORK_ORDER}]条码[{wipSN.SN}]在岗位[{wipSN.POST_CODE}]过站工序[{wipSN.NODE_NAME}]成功"));
                    }
                    //创建变量克隆对象用于传入DBSubmitAction中保存当前需要暂存的数据值
                    var _woSns = woSNs.Clone();
                    var _wipSns = wipSNs.Clone();
                    var _wipHiss = CurWipSNHiss.Clone();
                    var _defect = CurDefects.Clone();
                    var _curNode = curNode.Clone();
                    var _Batch = CurBatch.Batch.Clone();
                    //初始化工步列表
                    Steps.Clear();
                   var curStep = new Biz.WorkStep(IWorkStep.Types.Node, this) 
@@ -360,26 +416,28 @@
                       Node = curNode,
                       DBSubmitAction = () =>
                       {
                           var db = GetCommitDB();
                           db.Storageable(woSNs, UserCode).ExecuteCommand();
                           db.Storageable(wipSNs, UserCode).ExecuteCommand();
                           db.Storageable(CurWipSNHiss, UserCode).ExecuteCommand();
                            //使用统一的事务DB对象
                            var db = GetCommitDB();
                            //数据保存逻辑
                           db.Storageable(_woSns, UserCode).ExecuteCommand();
                           db.Storageable(_wipSns, UserCode).ExecuteCommand();
                           db.Storageable(_wipHiss, UserCode).ExecuteCommand();
                            //如果有不良则保存
                            if (CurDefects.Any())
                            if (_defect.Any())
                            {
                                db.Storageable(CurDefects, UserCode).ExecuteCommand();
                                db.Storageable(_defect, UserCode).ExecuteCommand();
                            }
                            //如果是投入站
                            if (curNode.IS_INPUT == "Y")
                            if (_curNode.IS_INPUT == "Y")
                            {
                                db.Updateable<BIZ_MES_WO>().SetColumns(q => q.INPUT_QTY == q.INPUT_QTY + wipSNs.Count).Where(q => q.ORDER_NO == CurBatch.WO.ORDER_NO).ExecuteCommand();
                                db.Updateable<BIZ_MES_WO_BATCH>().SetColumns(q => q.INPUT_QTY == q.INPUT_QTY + wipSNs.Count).Where(q => q.BATCH_NO == CurBatch.Batch.BATCH_NO).ExecuteCommand();
                                db.Updateable<BIZ_MES_WO>().SetColumns(q => q.INPUT_QTY == q.INPUT_QTY + _woSns.Count).Where(q => q.ORDER_NO == _Batch.ORDER_NO).ExecuteCommand();
                                db.Updateable<BIZ_MES_WO_BATCH>().SetColumns(q => q.INPUT_QTY == q.INPUT_QTY + _woSns.Count).Where(q => q.BATCH_NO == _Batch.BATCH_NO).ExecuteCommand();
                            }
                            //如果是产出站
                            if (curNode.IS_OUTPUT == "Y")
                            if (_curNode.IS_OUTPUT == "Y")
                            {
                                db.Updateable<BIZ_MES_WO>().SetColumns(q => q.OUTPUT_QTY == q.OUTPUT_QTY + wipSNs.Count).Where(q => q.ORDER_NO == CurBatch.WO.ORDER_NO).ExecuteCommand();
                                db.Updateable<BIZ_MES_WO_BATCH>().SetColumns(q => q.OUTPUT_QTY == q.OUTPUT_QTY + wipSNs.Count).Where(q => q.BATCH_NO == CurBatch.Batch.BATCH_NO).ExecuteCommand();
                                db.Updateable<BIZ_MES_WO>().SetColumns(q => q.OUTPUT_QTY == q.OUTPUT_QTY + _woSns.Count).Where(q => q.ORDER_NO == _Batch.ORDER_NO).ExecuteCommand();
                                db.Updateable<BIZ_MES_WO_BATCH>().SetColumns(q => q.OUTPUT_QTY == q.OUTPUT_QTY + _woSns.Count).Where(q => q.BATCH_NO == _Batch.BATCH_NO).ExecuteCommand();
                            }
                        }
                   };
@@ -451,6 +509,7 @@
            }
            catch (Exception ex)
            {
                action.Data.ShortMsg = new("工步异常", ShortMessage.Types.Error);
                ResetNode();
                //action.CatchExceptionWithLog(ex, $"{curNode.NODE_NAME}:工序节点工步提交数据异常,请检查工序节点设置");
                action.CatchExceptionWithLog(ex, Biz.L("MES.Transaction.PackingNode.NodeSubmitException", curNode.NODE_NAME));
@@ -469,10 +528,13 @@
            SaveStepsCommitActionToDB();
            //保存成功,返回过站消息
            OperInfoDic[CurBatch.Batch.BATCH_NO].InputQty += CurWipSNs.Count;
            action.Data.ShortMsg = new("过站成功", ShortMessage.Types.Success);
            //action.LocaleMsg = new($"工单[{CurWipSN.WORK_ORDER}]的条码[{CurWipSN.SN}]在岗位[{CurWipSN.POST_CODE}]工序[{CurWipSN.NODE_NAME}]过站成功,状态[{CurWipSN.STATUS.GetEnumDesc<MES_WIP_DATA.STATUSs>()}]");
            action.LocaleMsg = new("MES.Transaction.CollectNode.ScanSn.PassSuccess", CurWipSNs.First().WORK_ORDER, CurSN, CurWipSNs.First().POST_CODE, CurWipSNs.First().NODE_NAME,CurWipSNs.First().STATUS.GetEnumDesc<MES_WIP_DATA.STATUSs>());
            //重置工序
            ResetNode();
            return action;
        }