服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2024-11-21 a55e502c37bdc2831fc904c08961e9bca7778ae7
Tiger.Business.MES/Transaction/YadaPacking.cs
@@ -36,6 +36,7 @@
        public string NodeCmd { get; set; }
        public PackingAction TempPkgAction { get; set; }
        public bool IsPrintCustomerLabel { get; set; }
        public string ShippingOrder { get; set; }
        #endregion Propertys & Variables
        #region Functions
@@ -49,19 +50,23 @@
            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;
                }
                //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;
                //}
                if (input.Options.ContainsKey("IsPrintCustomerLabel"))
                {
                    IsPrintCustomerLabel = input.Options["IsPrintCustomerLabel"].ToBoolean();
                }
                if (input.Options.ContainsKey("ShippingOrder"))
                {
                    ShippingOrder = IsPrintCustomerLabel ? input.Options["ShippingOrder"].ToString() : "";
                }
                //PkgSubmit:手动结束包装,手动保存暂存的包装数据
                if (NodeCmd == "PkgSubmit")
@@ -418,6 +423,8 @@
                        wipSN.OPER_CODE = curNode.OPER_CODE;
                        wipSN.SEGMENT = curNode.SEGMENT;
                        wipSN.OPERATION_TIME = DateTime.Now;
                        wipSN.SHIPPING_ORDER = ShippingOrder;
                        wipSN.UNBIND_FLAG = "N";
                        var curShiftPeriod = GetShiftPeriodForNow();
                        if (!curShiftPeriod.IsNullOrEmpty())
                        {
@@ -692,7 +699,8 @@
                var _woSns = woSNs.Clone();
                var _wipSns = CurWipSNs.Clone();
                var _wipHiss = wipHiss.Clone();
                var _pkgList = curPkg?.IsFinished == true ? GetPackageList(curPkg.Item) : new();
                var _pkgList = curPkg?.IsFinished == true ? GetPackageList(curPkg.Item).Clone() : new();
                var _wipIDs = curPkg?.IsFinished == true ? curPkg.Item.GetWipSnList().Select(q => q.Key).ToList().Clone() : new();
                //保存数据
                endAction = () =>
                {
@@ -704,14 +712,14 @@
                    db.Storageable(_wipHiss, UserCode).ExecuteCommand();
                    if (_pkgList.Any())
                    {
                        var wipIDs = _pkgList.Where(q => !q.WIP_ID.IsNullOrEmpty()).Select(q => q.WIP_ID).ToList();
                        //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>(UserCode)
                            .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))
                            .Where(q => q.WORK_ORDER == wo && q.OPER_CODE == "EndNode" && _wipIDs.Contains(q.WIP_ID))
                            .ExecuteCommand();
                    }
                };
@@ -828,7 +836,7 @@
                        TempPkgAction.Init(this);
                        int shipQty = input.Data.ToInt32();
                        int curQty = CurPkg.Item.TotalQty;
                        double curQty = CurPkg.Item.TotalQty;
                        int ruleQty = TempPkgAction.PkgRule.GetTotalQty();
                        //有填出货数量则验证当前包装数量必须等于(出货数量/包装规则数量)的余数
                        if (shipQty > 0 && curQty != shipQty % ruleQty)
@@ -872,6 +880,34 @@
            return action;
        }
        /// <summary>
        /// 打印测试标签
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction<PackingActionOutput>> TestPrint()
        {
            var action = new ApiAction<PackingActionOutput>();
            try
            {
                var CurPkg = Context.ContainsKey("CurPackage") ? Context["CurPackage"] as WipPkg : null;
                var LabelPV = Biz.Db.Queryable<BAS_LABEL_PV>().ToList();
                var label = CurPkg.Item.LABEL_CODE.IsNullOrEmpty() ? null : Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(q => q.LABEL_CODE == CurPkg.Item.LABEL_CODE).IncludesAllFirstLayer().First();
                var printLb =  SetLabelVariables(LabelPV, label, new PackingAction(), CurPkg);
                action.Data = new PackingActionOutput()
                {
                    ExecCode = "PrintTest",
                    PkgInfo = CurPkg,
                    PrintLable = printLb,
                };
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"包装工序:打印测试标签异常");
            }
            return action;
        }
        #endregion Functions
        /// <summary>