服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-10-25 76e99e160320c9d612feb0861fc9e2b0075172e9
Tiger.Business.MES/Transaction/PackingNode.cs
@@ -48,16 +48,6 @@
            var action = new ApiAction<SubmitOutput>(new SubmitOutput());
            try
            {
                if (input.Qty.ToInt32() <= 0)
                {
                    action.Data.ShortMsg = new("请输入包装数量", ShortMessage.Types.Error);
                    action.Data.OperInfo = new();
                    action.Data.Data = "QtyError";
                    action.IsSuccessed = false;
                    action.LocaleMsg = new($"包装数量[{input.Qty}]不正确,请重新输入数量后继续包装操作");
                    //action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.QtyError", input.Qty);
                    return action;
                }
                //PkgSubmit:手动结束包装,手动保存暂存的包装数据
                if (NodeCmd == "PkgSubmit")
                {
@@ -89,7 +79,7 @@
                                info.InputQty = CurOperInfo(input.Locale).InputQty;
                                action.Data.OperInfo = info;
                            }
                            else if (!IsFinishAllSteps)
                            else if (Steps.Any() && !IsFinishAllSteps)
                            {
                                action.Data.OperInfo = SetOperNodeInfo(CurOperInfo(input.Locale));
                            }
@@ -114,13 +104,14 @@
                                    action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.OnlyMinPackage", input.SN);
                                    return action;
                                }
                                if (Context.ContainsKey("CurPackage") && !Context["CurPackage"].IsNullOrEmpty() && (Context["CurPackage"] as WipPkg).WorkBatch != curSNs.First().Batch.BATCH_NO)
                                var curPkg = Context.ContainsKey("CurPackage") ? Context["CurPackage"] as WipPkg : null;
                                if (!curPkg.IsNullOrEmpty() && !curPkg.IsFinished && curPkg.WorkBatch != curSNs.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, curSNs.First().Batch.BATCH_NO, input.SN);
                                    action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.BatchError", curPkg.WorkBatch, curSNs.First().Batch.BATCH_NO, input.SN);
                                    return action;
                                }
                                if (curSNs.First().Batch.ACT_LINE != CurLine.LINE_CODE)
@@ -165,29 +156,30 @@
                            //查找不到条码已绑定的工单
                            else
                            {
                                //没有当前工单,则先选择工单后再扫描条码
                                if (CurBatch.IsNullOrEmpty())
                                var lastSn = wosns.OrderByDescending(q => q.SN.UPDATE_TIME).FirstOrDefault();
                                if (!lastSn.IsNullOrEmpty())
                                {
                                    action.Data.ShortMsg = new("未选择工单", ShortMessage.Types.Error);
                                    action.Data.ShortMsg = new($"产品{lastSn.SN.STATUS.GetEnumDesc<BIZ_MES_WO_SN.STATUSs>()}", ShortMessage.Types.Error);
                                    action.Data.OperInfo = new();
                                    action.IsSuccessed = false;
                                    //action.LocaleMsg = new($"未选择工单,请先选择要生产的工单");
                                    action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.NotSelectOrderException");
                                    //action.LocaleMsg = new($"进站扫描错误,条码[{0}]{1}", input.SN);
                                    action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.SnStatusError", input.SN, lastSn.SN.STATUS.GetEnumDesc<BIZ_MES_WO_SN.STATUSs>());
                                }
                                //有当前工单且不是投入,则提示条码未投入生产,请先去首站扫描
                                else
                                {
                                    var lastSn = wosns.OrderByDescending(q => q.SN.UPDATE_TIME).FirstOrDefault();
                                    if (!lastSn.IsNullOrEmpty())
                                    //没有当前工单,则先选择工单后再扫描条码
                                    if (CurBatch.IsNullOrEmpty())
                                    {
                                        action.Data.ShortMsg = new($"产品{lastSn.SN.STATUS.GetEnumDesc<BIZ_MES_WO_SN.STATUSs>()}", ShortMessage.Types.Error);
                                        action.Data.ShortMsg = new("未选择工单", ShortMessage.Types.Error);
                                        action.Data.OperInfo = new();
                                        action.IsSuccessed = false;
                                        //action.LocaleMsg = new($"进站扫描错误,条码[{0}]{1}", input.SN);
                                        action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.NotInputException", input.SN);
                                        //action.LocaleMsg = new($"未选择工单,请先选择要生产的工单");
                                        action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.NotSelectOrderException");
                                    }
                                    //有当前工单且不是投入,则提示条码未投入生产,请先去首站扫描
                                    else
                                    {
                                        action.Data.ShortMsg = new("未投入生产", ShortMessage.Types.Error);
                                        action.Data.OperInfo = new();
                                        action.IsSuccessed = false;
@@ -475,7 +467,7 @@
                    CurWipSNHiss.Clear();
                    foreach (var wipSN in wipSNs)
                    {
                        var his = 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}]成功(TransId:{TransID})");
                        wipSN.History.Add(his);
                        CurWipSNHiss.Add(his);
                    }
@@ -621,12 +613,18 @@
        /// <returns></returns>
        public ApiAction<SubmitOutput> DoIfFinishAllSteps(ApiAction<SubmitOutput> action, string locale)
        {
            var curPkg = Context.ContainsKey("CurPackage") ? Context["CurPackage"] as WipPkg : null;
            var operInfo = SetOperNodeInfo(CurOperInfo(locale));
            Action endAction = null;
            //如果当前条码已经走到流程终点则记录条码完工
            if (operInfo.IsReachedEndNode)
            {
                //标记当前包装信息为终点站
                if (!curPkg.IsNullOrEmpty())
                {
                    curPkg.IsReachedEndNode = true;
                }
                //更新工单条码明细信息
                var woSNs = CurBatch.WoSNs.Where(q => CurWipSNs.Any(w => q.WIP_ID == w.ID)).ToList();
                foreach (var woSN in woSNs)
@@ -642,6 +640,7 @@
                    wipSN.NODE_NAME = curNode.NODE_NAME;
                    wipSN.OPER_CODE = curNode.OPER_CODE;
                    wipSN.SEGMENT = curNode.SEGMENT;
                    wipSN.OPERATION_TIME = DateTime.Now;
                }
                var wipHiss = new List<MES_WIP_HIS>();
@@ -656,15 +655,28 @@
                var _woSns = woSNs.Clone();
                var _wipSns = CurWipSNs.Clone();
                var _wipHiss = wipHiss.Clone();
                var _pkgList = curPkg?.IsFinished == true ? GetPackageList(curPkg.Item) : new();
                //保存数据
                endAction = () =>
                {
                    //使用统一的事务DB对象
                    var db = GetCommitDB();
                    //数据保存逻辑
                    db.Storageable(_woSns, UserCode).ExecuteCommand();
                    db.Storageable(_wipSns, UserCode).ExecuteCommand();
                    db.Updateable(_woSns, UserCode).UpdateColumns(q => new { q.UPDATE_TIME, q.UPDATE_USER, q.STATUS }).ExecuteCommand();
                    db.Updateable(_wipSns, UserCode).UpdateColumns(q => new { q.UPDATE_TIME, q.UPDATE_USER, q.STATUS, q.NODE_ID, q.NODE_NAME, q.OPER_CODE, q.SEGMENT, q.OPERATION_TIME }).ExecuteCommand();
                    db.Storageable(_wipHiss, UserCode).ExecuteCommand();
                    if (_pkgList.Any())
                    {
                        var wipIDs = _pkgList.Where(q => !q.WIP_ID.IsNullOrEmpty()).Select(q => q.WIP_ID).ToList();
                        var wo = _pkgList.First().WORK_ORDER;
                        //包装信息保存到生产过程记录
                        db.Updateable<MES_WIP_HIS>()
                            .SetColumns(q => q.TRAY_SN == curPkg.Item.Package.SN)
                            .SetColumns(q => q.INNER_SN == q.CARTON_SN)
                            .SetColumns(q => q.CARTON_SN == curPkg.Item.Package.SN)
                            .Where(q => q.WORK_ORDER == wo && q.OPER_CODE == "EndNode" && wipIDs.Contains(q.WIP_ID))
                            .ExecuteCommand();
                    }
                };
            }
@@ -673,7 +685,7 @@
            //保存成功,返回过站消息
            CurOperInfo(locale).InputQty += CurWipSNs.Count;
            action.Data.Data = new PackingActionOutput() { PkgInfo = Context.ContainsKey("CurPackage") ? Context["CurPackage"] as WipPkg : null };
            action.Data.Data = new PackingActionOutput() { PkgInfo = curPkg };
            action.Data.OperInfo = operInfo;
            action.Data.ShortMsg = new(CurWipSNs.Any(q => q.DFT_FLAG == "Y") ? "不良过站" : "良品过站", ShortMessage.Types.Success);
            //action.LocaleMsg = new($"工单[{CurWipSN.WORK_ORDER}]的条码[{CurWipSN.SN}]在岗位[{CurWipSN.POST_CODE}]工序[{CurWipSN.NODE_NAME}]过站成功,状态[{CurWipSN.STATUS.GetEnumDesc<MES_WIP_DATA.STATUSs>()}]");
@@ -707,19 +719,6 @@
                    {
                        TempPkgAction = new PackingAction();
                        TempPkgAction.Init(this);
                        var CurPkg = Context["CurPackage"] as WipPkg;
                        int shipQty = input.Data.ToInt32();
                        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);
                            return action;
                        }
                        NodeCmd = "PkgSubmit";
                        action = TempPkgAction.Submit(null);