服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-09-18 e4ccb1dbd2af10d3322cba90722baf059e5bc853
Tiger.Business.MES/Transaction/PackingNode.cs
@@ -55,9 +55,9 @@
                    //如果行为被标记成已完成,则重置工序
                    if (TempPkgAction.IsFinished)
                    {
                        action.Data.OperInfo = CurOperInfo(input.Locale);
                        ResetNode();
                    }
                    return action;
                }
                //NodeSubmit:产品过站,正常产品过站逻辑
                else
@@ -69,31 +69,56 @@
                        //先判断当前工单不为空且当前岗位在当前工单是不是首站,如果是则不允许变更当前工单,尝试把条码绑定到当前工单
                        if (!CurBatch.IsNullOrEmpty() && CurBatch.IsFirstNode(PostCode))
                        {
                            //更新CurBatch
                            CurBatch?.Update();
                            //提交数据
                            action = NodeSubmit(action, input);
                            return action;
                            //更新工序信息
                            if (!action.IsSuccessed)
                            {
                                var info = WoContext.GetSnOperInfo(input.SN).Data;
                                info.InputQty = CurOperInfo(input.Locale).InputQty;
                                action.Data.OperInfo = info;
                            }
                            else if (!IsFinishAllSteps)
                            {
                                action.Data.OperInfo = SetOperNodeInfo(CurOperInfo(input.Locale));
                            }
                        }
                        //当前岗位在当前工单不是首站,则查找条码已绑定的工单当作当前工单
                        else
                        {
                            var wosns = Biz.Db.Queryable<BIZ_MES_WO_BATCH, BIZ_MES_WO_SN>((q, s) => new JoinQueryInfos(JoinType.Inner, q.ORDER_NO == s.WORK_ORDER))
                                                        .ByAuth(input.AuthOption).Where((q, s) => s.SN == input.SN || s.TRAY_SN == input.SN).Select((q, s) => new { Batch = q, SN = s }).ToList();
                                                        .ByAuth(input.AuthOption).Where((q, s) => s.SN == input.SN || s.FLOW_SN == input.SN || s.TRAY_SN == input.SN).Select((q, s) => new { Batch = q, SN = s }).ToList();
                                                        
                            //查找到条码已绑定的工单
                            if (!wosns.IsNullOrEmpty())
                            {
                                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($"条码[{0}]是载具条码,请扫描载具中的产品条码继续包装操作");
                                    action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.OnlyMinPackage", input.SN);
                                    return action;
                                }
                                if (Context.ContainsKey("CurPackage") && !Context["CurPackage"].IsNullOrEmpty() && (Context["CurPackage"] as WipPkg).WorkBatch != wosns.First().Batch.BATCH_NO)
                                {
                                    action.Data.ShortMsg = new("工单批次错误", ShortMessage.Types.Error);
                                    action.Data.OperInfo = new();
                                    action.IsSuccessed = false;
                                    //action.LocaleMsg = new($"正在包装工单批次[{0}]的产品,请先完成当前包装后再扫描其他批次[{1}]的产品[{2}]");
                                    action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.BatchError", (Context["CurPackage"] as WipPkg).WorkBatch, wosns.First().Batch.BATCH_NO, CurSN);
                                    return action;
                                }
                                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 +128,27 @@
                                       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;
                                    //更新CurBatch
                                    CurBatch?.Update();
                                    //条码过站
                                    action = NodeSubmit(action, input);
                                    if (!action.IsSuccessed && !CurWipSNs.Any())
                                    {
                                        var info = WoContext.GetSnOperInfo(input.SN).Data;
                                        info.InputQty = CurOperInfo(input.Locale).InputQty;
                                        action.Data.OperInfo = info;
                                    }
                                    else if (!IsFinishAllSteps)
                                    {
                                        action.Data.OperInfo = SetOperNodeInfo(CurOperInfo(input.Locale));
                                    }
                                }
                            }
                            //查找不到条码已绑定的工单
@@ -119,18 +157,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;
                                }
                            }
                        }
@@ -138,11 +178,14 @@
                    //完成工序节点工步后,后开始执行当前工序的行为工步
                    else if (IsFinishNodeSteps && !IsFinishAllSteps)
                    {
                        //更新CurBatch
                        CurBatch?.Update();
                        var submitStep = Steps.Where(q => q.ID == input.CurStepID && !q.IsFinished).FirstOrDefault();
                        if (submitStep.IsNullOrEmpty())
                        {
                            action = BeginNextActionStep(input);
                            return action;
                            action.Data.OperInfo = CurOperInfo(input.Locale);
                        }
                        else
                        {
@@ -168,20 +211,31 @@
                            //如果所有工步都完成
                            if (IsFinishAllSteps)
                            {
                                return DoIfFinishAllSteps(result);
                                result = DoIfFinishAllSteps(result, input.Locale);
                            }
                            else
                            {
                                result.Data.OperInfo = CurOperInfo(input.Locale);
                            }
                            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 = CurOperInfo(input.Locale);
                        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 = CurOperInfo(input.Locale);
                //action.CatchExceptionWithLog(ex, $"包装工序:提交操作数据异常");
                action.CatchExceptionWithLog(ex, Biz.L("MES.Transaction.PackingNode.SubmitException"));
            }
@@ -203,10 +257,11 @@
                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();
                var wipSNs = Biz.Db.Queryable<MES_WIP_DATA>().IncludesAllFirstLayer().Where(q => q.SN == input.SN || q.FLOW_SN == input.SN || q.TRAY_SN == input.SN).ToList();
                if (wipSNs.IsNullOrEmpty())
                {
                   var wipSN = new MES_WIP_DATA()
@@ -217,7 +272,11 @@
                       ITEM_CODE = CurBatch.WO.ITEM_CODE,
                       WORK_ORDER = CurBatch.Batch.ORDER_NO,
                       BATCH_NO = CurBatch.Batch.BATCH_NO,
                       HOLD_FLAG = "N",
                        FTY_CODE = CurFactory.FTY_CODE,
                        WS_CODE = CurWorkshop.WS_CODE,
                        LINE_CODE = CurLine.LINE_CODE,
                        POST_CODE = CurPosition.POST_CODE,
                        HOLD_FLAG = "N",
                       REWORK_FLAG = CurBatch.WO.ORDER_TYPE == BIZ_MES_WO.ORDER_TYPEs.Rework.GetValue() ? "Y" : "N",
                       FINISHED_FLAG = "N",
                       INV_FLAG = "N",
@@ -226,9 +285,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", input.SN, 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", input.SN, 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;
                }
@@ -245,6 +328,7 @@
                                WORK_ORDER = CurBatch.Batch.ORDER_NO,
                                WIP_ID = wipSN.ID,
                                SN = wipSN.SN,
                                FLOW_SN = wipSN.SN,
                                TRAY_SN = wipSN.TRAY_SN,
                                STATUS = BIZ_MES_WO_SN.STATUSs.NotInput.GetValue(),
                            });
@@ -354,7 +438,9 @@
                    CurWipSNHiss.Clear();
                    foreach (var wipSN in wipSNs)
                    {
                        CurWipSNHiss.Add(new MES_WIP_HIS(wipSN, $"工单[{wipSN.WORK_ORDER}]条码[{wipSN.SN}]在岗位[{wipSN.POST_CODE}]过站工序[{wipSN.NODE_NAME}]成功"));
                        var his = new MES_WIP_HIS(wipSN, $"工单[{wipSN.WORK_ORDER}]条码[{wipSN.SN}]在岗位[{wipSN.POST_CODE}]过站工序[{wipSN.NODE_NAME}]成功");
                        wipSN.History.Add(his);
                        CurWipSNHiss.Add(his);
                    }
                    //创建变量克隆对象用于传入DBSubmitAction中保存当前需要暂存的数据值
@@ -367,11 +453,13 @@
                    //初始化工步列表
                    Steps.Clear();
                   var curStep = new Biz.WorkStep(IWorkStep.Types.Node, this)
                   var curStep = new Biz.WorkStep(IWorkStep.NodeTypes.Node, this)
                    {
                       Sequence = Steps.Count + 1,
                        Name = "扫描产品",
                        Sequence = Steps.Count + 1,
                       Node = curNode,
                       DBSubmitAction = () =>
                        OperSetting = CurBatch.NodeSets.FirstOrDefault(q => q.NODE_ID == curNode.ID),
                        DBSubmitAction = () =>
                       {
                            //使用统一的事务DB对象
                            var db = GetCommitDB();
@@ -415,15 +503,15 @@
                    }
                    //完成第一个工序节点工步
                    curStep.IsFinished = true;
               CurStep = curStep;
                    curStep.Status = StepStatus.Finished;
                    CurStep = curStep;
                } 
                else if (!IsFinishNodeSteps)
                {
                    var curStep = Steps.Where(q => q.Type == IWorkStep.Types.Node && !q.IsFinished).OrderBy(q => q.Sequence).First();
                    var curStep = Steps.Where(q => q.NodeType == IWorkStep.NodeTypes.Node && !q.IsFinished).OrderBy(q => q.Sequence).First();
                    //完成当前工序节点工步
                    curStep.IsFinished = true;
                    curStep.Status = StepStatus.Finished;
                    CurStep = curStep;
                }
@@ -433,7 +521,7 @@
                    //未完成所有工序节点工步
                    if (!IsFinishNodeSteps)
                    {
                        var next = Steps.Where(q => q.Type == IWorkStep.Types.Node && !q.IsFinished).OrderBy(q => q.Sequence).First();
                        var next = Steps.Where(q => q.NodeType == IWorkStep.NodeTypes.Node && !q.IsFinished).OrderBy(q => q.Sequence).First();
                        //设置后续可执行的工步列表
                        NextSteps.Clear();
                        NextSteps.Add(next);
@@ -461,11 +549,12 @@
                if (IsFinishAllSteps)
                {
                    action.Data.SetValue(CurBatch, CurStep, "", IsFinishAllSteps);
                    action = DoIfFinishAllSteps(action);
                    action = DoIfFinishAllSteps(action, input.Locale);
                }
            }
            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));
@@ -478,19 +567,20 @@
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public ApiAction<SubmitOutput> DoIfFinishAllSteps(ApiAction<SubmitOutput> action)
        public ApiAction<SubmitOutput> DoIfFinishAllSteps(ApiAction<SubmitOutput> action, string locale)
        {
            //保存数据库
            SaveStepsCommitActionToDB();
            //保存成功,返回过站消息
            CurOperInfo(locale).InputQty += CurWipSNs.Count;
            action.Data.OperInfo = SetOperNodeInfo(CurOperInfo(locale));
            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>());
            //重置工序
            //if (!isClone)
            {
                ResetNode();
            }
            ResetNode();
            
            return action;
        }
@@ -499,7 +589,7 @@
        /// 包装工序:手动结束包装
        /// </summary>
        /// <returns></returns>
        public async Task<ApiAction<SubmitOutput>> CompletePkg()
        public async Task<ApiAction<SubmitOutput>> CompletePkg(ApiAction input)
        {
            var action = new ApiAction<SubmitOutput>(new SubmitOutput());
            try
@@ -509,10 +599,24 @@
                {
                    if (Context.ContainsKey("CurPackage"))
                    {
                        var CurPkg = Context["CurPackage"] as WipPkg;
                        int shipQty = input.Data.ToInt32();
                        NodeCmd = "PkgSubmit";
                        TempPkgAction = new PackingAction();
                        TempPkgAction.Init(null, this, null, null);
                        TempPkgAction.Init(this);
                        int curQty = CurPkg.Item.TotalQty;
                        int ruleQty = TempPkgAction.PkgRule.GetTotalQty();
                        //有填出货数量则验证当前包装数量必须等于(出货数量/包装规则数量)的余数
                        if (shipQty > 0 &&  curQty != shipQty % ruleQty)
                        {
                            action.IsSuccessed = false;
                            //action.LocaleMsg = new($"出货数量设定为[{0}],目前包装了[{1}],包装尾数的数量必需是[{2}],请装够数量后再结束包装");
                            action.LocaleMsg = new("MES.Transaction.PackingNode.NotMatchShipQty", shipQty, curQty, shipQty % ruleQty);
                        }
                        action = TempPkgAction.Submit(null);
                    }
                    else