From fcee1ab17f2cca5c1b058304a987cce43d0e7672 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期三, 01 一月 2025 21:34:20 +0800
Subject: [PATCH] 新增工单备料信息获取功能及相关接口

---
 Tiger.Business.MES/BIZ/BIZ_MES_WO.cs |  427 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 396 insertions(+), 31 deletions(-)

diff --git a/Tiger.Business.MES/BIZ/BIZ_MES_WO.cs b/Tiger.Business.MES/BIZ/BIZ_MES_WO.cs
index f135d86..4d9aab6 100644
--- a/Tiger.Business.MES/BIZ/BIZ_MES_WO.cs
+++ b/Tiger.Business.MES/BIZ/BIZ_MES_WO.cs
@@ -18,6 +18,9 @@
 using System.Drawing.Printing;
 using System.Net.NetworkInformation;
 using Tiger.Model.MES.Yada;
+using static Microsoft.CodeAnalysis.CSharp.SyntaxTokenParser;
+using Tiger.Model.Minsun;
+using Tiger.Model.Entitys.MES.U9C;
 
 namespace Tiger.Business.MES
 {
@@ -129,20 +132,30 @@
                     return result;
                 }
                 var batchs = await Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Where(x => x.ORDER_NO == input.Wo.ORDER_NO).ToListAsync();
-                if ((batchs.Count > 0 && batchs.Sum(x => x.PLAN_QTY) + input.WoBatch.PLAN_QTY > _wo.PLAN_QTY) || input.WoBatch.PLAN_QTY > _wo.PLAN_QTY)
+                if (batchs.Count > 0)
                 {
-                    result.IsSuccessed = false;
-                    result.LocaleMsg = new($"宸ュ崟涓嬪彂鐨勬暟閲忚秴杩囧伐鍗曡鍒掓暟閲忥紝涓嶈兘涓嬪彂锛�");
-                    return result;
-                }
-                var _batch = Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Where(x => x.ORDER_NO == input.Wo.ORDER_NO && x.ACT_LINE == input.WoBatch.ACT_LINE && x.STATUS < BIZ_MES_WO.STATUSs.Closed.GetValue()).First();
-                if (_batch != null)
-                {
-                    result.IsSuccessed = false;
-                    result.LocaleMsg = new($"宸ュ崟[{input.Wo.ORDER_NO}]宸茬粡瀛樺湪宸ュ崟鎵规[{_batch.BATCH_NO}]鍦ㄧ嚎浣揫{input.WoBatch.ACT_LINE}]涓姸鎬佷负[{_batch.STATUS.GetEnumDesc<BIZ_MES_WO.STATUSs>()}]锛屼笉鑳戒笅鍙戯紒");
-                    return result;
+                    if ((batchs.Sum(x => x.PLAN_QTY) + input.WoBatch.PLAN_QTY > _wo.PLAN_QTY) || input.WoBatch.PLAN_QTY > _wo.PLAN_QTY)
+                    {
+                        result.IsSuccessed = false;
+                        result.LocaleMsg = new($"宸ュ崟涓嬪彂鐨勬暟閲忚秴杩囧伐鍗曡鍒掓暟閲忥紝涓嶈兘涓嬪彂锛�");
+                        return result;
+                    }
+                    if (batchs.Any(x => x.ORDER_NO == input.Wo.ORDER_NO && x.ACT_LINE == input.WoBatch.ACT_LINE && x.STATUS < BIZ_MES_WO.STATUSs.Closed.GetValue()))
+                    {
+                        result.IsSuccessed = false;
+                        result.LocaleMsg = new($"宸ュ崟[{input.Wo.ORDER_NO}]宸茬粡鏈夋壒娆″瓨鍦ㄧ嚎浣揫{input.WoBatch.ACT_LINE}]涓紝鑰屼笖鐘舵�佷笉涓哄叧闂紝涓嶈兘涓嬪彂锛�");
+                        return result;
+                    }
+                    if (batchs.Any(x => x.ORDER_NO == input.Wo.ORDER_NO && x.STATUS == BIZ_MES_WO.STATUSs.Init.GetValue() && SqlFunc.DateIsSame(x.PLAN_DATE, DateTime.Now)))
+                    {
+                        result.IsSuccessed = false;
+                        result.LocaleMsg = new($"宸ュ崟[{input.Wo.ORDER_NO}]宸茬粡鏈夋壒娆″瓨鍦ㄨ鍒掓棩鏈熺浉鍚岋紝鑰屼笖鐘舵�佷负[鍒濆鍖朷锛岃杞埌宸ュ崟鎵规涓笅鍙戯紒");
+                        return result;
+                    }
                 }
                 //WoContext.RemoveBatch(input.WoBatch.BATCH_NO);
+                input.WoBatch.PLAN_DATE = DateTime.Now;
+                input.Wo.PLAN_DATE = (input.Wo.PLAN_DATE ?? "") + ((input.Wo.PLAN_DATE ?? "").Contains(input.WoBatch.PLAN_DATE.ToString("yyyy-MM-dd")) ? "" : $",{input.WoBatch.PLAN_DATE.ToString("yyyy-MM-dd")}");
                 input.Wo.ACT_LINE = input.WoBatch.ACT_LINE;
                 input.Wo.RELEASE_TIME = DateTime.Now;
                 input.Wo.RELEASE_USER = input.WoBatch.UPDATE_USER;
@@ -164,7 +177,7 @@
                        .WhereColumns(t => new { t.ORDER_NO, t.GHOST_ROW })
                        .ToStorage();
                     y.AsInsertable.ExecuteCommand();
-                    y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                    y.AsUpdateable.IgnoreColumns(x => x.ID).UpdateColumns(q => new { q.STATUS, q.PLAN_DATE, q.ACT_LINE, q.RELEASE_TIME, q.RELEASE_USER, q.UPDATE_TIME, q.UPDATE_USER }).ExecuteCommand();
 
                     db.Insertable(input.WoBatch).ExecuteCommand();
                 });
@@ -184,7 +197,6 @@
                             pars[1].Direction = System.Data.ParameterDirection.Output;
                             pars[2].Direction = System.Data.ParameterDirection.Output;
                             Biz.Db.Ado.UseStoredProcedure().ExecuteCommand("SP_MES_WO2CUST", pars);
-                            //response.LocaleMsg = new(pars[2].Value.ToString());
                             if (pars[1].Value.ToInt32() == 0)
                             {
                                 Logger.Default.Info($"宸ュ崟[{input.Wo.ORDER_NO}]涓嬪彂瀹屾垚鍚庝繚瀛樺伐鑹鸿矾绾挎暟鎹埌浜у搧[{input.Wo.ITEM_CODE}]鐨勫鎴穂{input.Wo.CUST_CODE ?? ""}]鐨勫伐鑹鸿矾绾夸腑锛寋pars[2].Value.ToString()}");
@@ -223,6 +235,8 @@
                 var _wo = await Biz.Db.Queryable<BIZ_MES_WO>().Where(x => x.ORDER_NO == input.WorkOrder).FirstAsync();
                 if (_wo != null)
                 {
+                    _wo.CHANGE_TIME = _wo.STATUS == BIZ_MES_WO.STATUSs.Paused.GetValue() && input.Status == BIZ_MES_WO.STATUSs.Working.GetValue() ? DateTime.Now : _wo.CHANGE_TIME;
+                    _wo.CHANGE_USER = _wo.STATUS == BIZ_MES_WO.STATUSs.Paused.GetValue() && input.Status == BIZ_MES_WO.STATUSs.Working.GetValue() ? input.UserId : _wo.CHANGE_USER;
                     _wo.STATUS = input.Status < 0 ? _wo.STATUS : input.Status;
                     _wo.ROUTE_STATUS = input.RouteStatus;
                 }
@@ -267,6 +281,8 @@
                 var _woBatch = await Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Where(x => x.BATCH_NO == input.WoBatch).FirstAsync();
                 if (_woBatch != null)
                 {
+                    _woBatch.CHANGE_TIME = _woBatch.STATUS == BIZ_MES_WO_BATCH.STATUSs.Paused.GetValue() && input.Status == BIZ_MES_WO_BATCH.STATUSs.Working.GetValue() ? DateTime.Now : _woBatch.CHANGE_TIME;
+                    _woBatch.CHANGE_USER = _woBatch.STATUS == BIZ_MES_WO_BATCH.STATUSs.Paused.GetValue() && input.Status == BIZ_MES_WO_BATCH.STATUSs.Working.GetValue() ? input.UserId : _woBatch.CHANGE_USER;
                     _woBatch.STATUS = input.Status < 0 ? _woBatch.STATUS : input.Status;
                     if (input.Status == BIZ_MES_WO_BATCH.STATUSs.Paused.GetValue())
                     {
@@ -284,6 +300,16 @@
                         _woBatch.RELEASE_TIME = DateTime.Now;
                         _woBatch.RELEASE_USER = input.UserId;
                         _woBatch.ACT_LINE = input.ActLine;
+                        _woBatch.CHANGE_USER = input.UserId;
+                        _woBatch.CHANGE_TIME = DateTime.Now;
+                        _wo.STATUS = BIZ_MES_WO.STATUSs.Release.GetValue();
+                    }
+                    else
+                    {
+                        if (input.Status == BIZ_MES_WO_BATCH.STATUSs.Init.GetValue() && !Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Where(x => x.ORDER_NO == input.WorkOrder && x.BATCH_NO != input.WoBatch && x.STATUS > BIZ_MES_WO_BATCH.STATUSs.Init.GetValue()).Any())
+                        {
+                            _wo.STATUS = BIZ_MES_WO.STATUSs.Init.GetValue();
+                        }
                     }
                 }
                 else
@@ -299,11 +325,15 @@
                     //濡傛灉鏄笅鍙�
                     if (input.Status == BIZ_MES_WO_BATCH.STATUSs.Release.GetValue())
                     {
-                        db.Updateable(_woBatch, input.UserId).UpdateColumns(x => new { x.STATUS, x.RELEASE_USER, x.RELEASE_TIME, x.ACT_LINE, x.UPDATE_USER, x.UPDATE_TIME }).ExecuteCommand();
+                        db.Updateable(_woBatch, input.UserId).UpdateColumns(x => new { x.STATUS, x.RELEASE_USER, x.RELEASE_TIME, x.ACT_LINE, x.UPDATE_USER, x.UPDATE_TIME, x.CHANGE_USER, x.CHANGE_TIME }).ExecuteCommand();
                     }
                     else
                     {
-                        db.Updateable(_woBatch, input.UserId).UpdateColumns(x => new { x.STATUS, x.UPDATE_USER, x.UPDATE_TIME }).ExecuteCommand();
+                        db.Updateable(_woBatch, input.UserId).UpdateColumns(x => new { x.STATUS, x.UPDATE_USER, x.UPDATE_TIME, x.CHANGE_USER, x.CHANGE_TIME }).ExecuteCommand();
+                    }
+                    if (!_wo.IsNullOrEmpty())
+                    {
+                        db.Updateable(_wo, input.UserId).UpdateColumns(x => new { x.STATUS, x.UPDATE_USER, x.UPDATE_TIME }).ExecuteCommand();
                     }
                 });
                 if (!dbTran.IsSuccess)
@@ -354,7 +384,7 @@
                 var db = Biz.Db;
                 var dbTran = db.UseTran(() =>
                 {
-                    Expression<Func<BAS_LABEL_VAR_WO, object>> predicate = !input.WORK_ORDER.IsNullOrEmpty() ? t => new { t.LABEL_ID, t.WORK_ORDER, t.VAR_NAME, t.GHOST_ROW } : 
+                    Expression<Func<BAS_LABEL_VAR_WO, object>> predicate = !input.WORK_ORDER.IsNullOrEmpty() ? t => new { t.LABEL_ID, t.WORK_ORDER, t.VAR_NAME, t.GHOST_ROW } :
                     !input.PROD_CODE.IsNullOrEmpty() ? t => new { t.LABEL_ID, t.PROD_CODE, t.VAR_NAME, t.GHOST_ROW } : t => new { t.LABEL_ID, t.VAR_NAME, t.GHOST_ROW };
                     var y = db.Storageable(input)
                        .WhereColumns(predicate)
@@ -453,28 +483,143 @@
         }
 
         /// <summary>
-        /// 鑾峰彇閲嶆墦鏍囩淇℃伅
+        /// 鏇存柊琛屼负涓殑绠卞彿
         /// </summary>
-        /// <param name="input"></param>
+        /// <param name="code"></param>
         /// <returns></returns>
-        public async Task<ApiAction<LOG_LABEL_PRINT>> GetRePrintInfo(RePrintInput input)
+        public async Task<ApiAction> SavePrintLabelInAct(string code)
         {
-            var result = new ApiAction<LOG_LABEL_PRINT>();
+            var result = new ApiAction();
             try
             {
-                //鍏堟煡鍑哄伐鍗曟潯鐮佷腑鏄惁瀛樺湪
-                var woSn = await Biz.Db.Queryable<BIZ_MES_WO_SN>().Where(q => q.SN.Equals(input.Code) || q.FLOW_SN.Equals(input.Code)).FirstAsync();
+                var woSn = await Biz.Db.Queryable<BIZ_MES_WO_SN>().Where(q => q.SN == code || q.FLOW_SN == code || q.OUTER_SN == code).FirstAsync();
                 if (woSn == null)
                 {
                     result.IsSuccessed = false;
                     result.LocaleMsg = new($"鏉$爜涓嶅瓨鍦紒");
                     return result;
                 }
+                //鍙栧緱鍖呰鍒楄〃
+                var pkgList = Biz.Db.Queryable<MES_WIP_PKG>().Where(q => q.PARENT_SN == woSn.OUTER_SN && q.OPER_CODE == "SpecPackingNode").ToList();
+                if (pkgList.Count == 0)
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"鏉$爜涓嶅瓨鍦紒");
+                    return result;
+                }
+                List<MES_WIP_ACT> actlist = new List<MES_WIP_ACT>();
+                //瀹㈡埛鏍囩
+                var wipAct = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.CARTON_SN == woSn.OUTER_SN && q.NODE_ID == pkgList[0].NODE_ID && !SqlFunc.IsNullOrEmpty(q.ACT_VALUE_3)).First();
+                if (!wipAct.IsNullOrEmpty())
+                {
+                    var label = JsonConvert.DeserializeObject<BAS_LABEL_TEMP>(wipAct.ACT_VALUE_3);
+                    var cardNo = label.Variables.Where(q => q.VAR_NAME == "CardQR").FirstOrDefault();
+                    if (!woSn.OUTER_SN.IsNullOrEmpty() && !cardNo.IsNullOrEmpty() && !cardNo.Value.StartsWith(woSn.OUTER_SN))
+                    {
+                        cardNo.Value = $"{woSn.OUTER_SN}{cardNo.Value}";
+                    }
+                    string ACT_VALUE_3 = JsonConvert.SerializeObject(label);
+                    foreach (var pkg in pkgList)
+                    {
+                        var actSn = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.WIP_ID == pkg.WIP_ID && q.NODE_ID == pkg.NODE_ID && q.ACT_VALUE_4 == "Customer").First();
+                        if (!actSn.IsNullOrEmpty())
+                        {
+                            actSn.ACT_VALUE_3 = ACT_VALUE_3;
+                            actlist.Add(actSn);
+                        }
+                    }
+                }
+                //鍏ュ簱鏍囩
+                var wipActInStore = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.SN == woSn.SN && q.NODE_ID == pkgList[0].NODE_ID && !SqlFunc.IsNullOrEmpty(q.ACT_VALUE_3) && q.ACT_VALUE_4 == "InStore").First();
+                if (!wipActInStore.IsNullOrEmpty())
+                {
+                    var label = JsonConvert.DeserializeObject<BAS_LABEL_TEMP>(wipActInStore.ACT_VALUE_3);
+                    var cardNo = label.Variables.Where(q => q.VAR_NAME == "CardQR").FirstOrDefault();
+                    if (!woSn.OUTER_SN.IsNullOrEmpty() && !cardNo.IsNullOrEmpty() && !cardNo.Value.StartsWith(woSn.OUTER_SN))
+                    {
+                        cardNo.Value = $"{woSn.OUTER_SN}{cardNo.Value}";
+                    }
+                    var xh = label.Variables.Where(q => q.VAR_NAME == "XH").FirstOrDefault();
+                    if (!woSn.OUTER_SN.IsNullOrEmpty() && !xh.IsNullOrEmpty())
+                    {
+                        xh.Value = $"{woSn.OUTER_SN}";
+                    }
+                    string ACT_VALUE_3 = JsonConvert.SerializeObject(label);
+                    foreach (var pkg in pkgList)
+                    {
+                        var actSn = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.WIP_ID == pkg.WIP_ID && q.NODE_ID == pkg.NODE_ID && q.ACT_VALUE_4 == "InStore").First();
+                        if (!actSn.IsNullOrEmpty())
+                        {
+                            actSn.ACT_VALUE_3 = ACT_VALUE_3;
+                            actlist.Add(actSn);
+                        }
+                    }
+                }
+                var db = Biz.Db;
+                var dbTran = db.UseTran(() =>
+                {
+                    db.Updateable(actlist).UpdateColumns(q => new { q.ACT_VALUE_3 }).ExecuteCommand();
+                });
+                if (!dbTran.IsSuccess)
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"鏇存柊琛屼负鏃ュ織涓殑绠卞彿寮傚父");
+                }
+            }
+            catch (Exception ex)
+            {
+                result.CatchExceptionWithLog(ex, "鏇存柊琛屼负鏃ュ織涓殑绠卞彿寮傚父");
+            }
+            return result;
+        }
 
-                result.Data = await Biz.Db.Queryable<LOG_LABEL_PRINT>()
+        /// <summary>
+        /// 鑾峰彇閲嶆墦鏍囩淇℃伅
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        public async Task<ApiAction> GetRePrintInfo(RePrintInput input)
+        {
+            var result = new ApiAction();
+            try
+            {
+                //鍏堟煡鍑哄伐鍗曟潯鐮佷腑鏄惁瀛樺湪
+                var outerSn = input.Code.Split('|')[0];
+                var woSn = await Biz.Db.Queryable<BIZ_MES_WO_SN>().Where(q => q.SN.Equals(input.Code) || q.FLOW_SN.Equals(input.Code) || q.OUTER_SN == outerSn).FirstAsync();
+                if (woSn == null)
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"鏉$爜涓嶅瓨鍦紒");
+                    return result;
+                }
+                var woNode = await Biz.Db.Queryable<MES_WO_NODE>().Where(q => q.WORK_ORDER.Equals(woSn.WORK_ORDER) && q.OPER_CODE == "SpecPackingNode").FirstAsync();
+                if (woNode == null)
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"宸ヨ壓璺嚎鑺傜偣[SpecPackingNode-瑁呯]涓嶅瓨鍦�");
+                    return result;
+                }
+                string printParam = "";
+                var labelPrint = await Biz.Db.Queryable<LOG_LABEL_PRINT>()
                     .WhereIF(input.ReqType == 0, q => q.SN.Equals(woSn.SN) || q.SN.Equals(woSn.FLOW_SN)) //鐧界洅鏍囩
-                    .WhereIF(input.ReqType == 1, q => q.SN.Equals(woSn.OUTER_SN)) //绠辨爣绛�
+                    .WhereIF(input.ReqType == 1, q => q.SN.Equals(woSn.OUTER_SN) && q.PRINT_LABEL != "InStoreLabel") //绠辨爣绛�-瀹㈡埛
+                    .WhereIF(input.ReqType == 2, q => q.SN.Equals(woSn.OUTER_SN) && q.PRINT_LABEL == "InStoreLabel") //绠辨爣绛�-鍏ュ簱
                     .FirstAsync();
+                //濡傛灉鏌ヤ笉鍒板氨鍘昏涓烘棩蹇楁煡
+                if (labelPrint.IsNullOrEmpty() && input.ReqType == 1)
+                {
+                    printParam = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.CARTON_SN.Equals(woSn.OUTER_SN) && q.ACT_VALUE_4 == "Customer" && !SqlFunc.IsNullOrEmpty(q.ACT_VALUE_3)).First()?.ACT_VALUE_3 ?? "";
+                }
+                else if (labelPrint.IsNullOrEmpty() && input.ReqType == 2)
+                {
+                    printParam = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.SN.Equals(woSn.SN) && q.ACT_VALUE_4 == "InStore").First()?.ACT_VALUE_3 ?? "";
+                }
+                else
+                {
+                    printParam = labelPrint?.PRINT_PARAM ?? "";
+                }
+                result.Data = printParam;
+                result.LocaleMsg = new($"閲嶆墦鏉$爜[{input.Code}]鐨勬爣绛炬垚鍔�");
             }
             catch (Exception ex)
             {
@@ -488,21 +633,46 @@
         /// </summary>
         /// <param name="wo"></param>
         /// <returns></returns>
-        public async Task<ApiAction> GetShipList(string wo, string orgCode)
+        public async Task<ApiAction<ShippingOutput>> GetShipList(ShippingInput input)
         {
-            var result = new ApiAction();
+            var result = new ApiAction<ShippingOutput>();
             try
             {
                 DbClient db = Biz.DataSource["YadaU9C"].Client;
-                var org = await Biz.Db.Queryable<SYS_ORGANIZATION>().Where(q=>q.ORG_CODE == orgCode).FirstAsync();
-                if (db.Queryable<mes_ShipList>().Any(q => q.MoDoc.Equals(wo) && SqlFunc.DateIsSame(q.BusinessDate, DateTime.Now) && q.Status == 2 && q.Org == org.ID.ToInt64()))
+                var org = await Biz.Db.Queryable<SYS_ORGANIZATION>().Where(q => q.ORG_CODE == input.orgCode).FirstAsync();
+                string wo = input.wo;
+                if (!input.SN.IsNullOrEmpty() && input.wo.IsNullOrEmpty())
                 {
-                    result.Data = "Customer";
+                    var woSn = Biz.Db.Queryable<BIZ_MES_WO_SN>().Where(q => q.SN == input.SN || q.FLOW_SN == input.SN).First();
+                    if (!woSn.IsNullOrEmpty())
+                    {
+                        wo = woSn.WORK_ORDER;
+                    }
+                }
+                var ship = db.Queryable<mes_ShipList>().Where(q => q.MoDoc.Equals(wo) && q.Org == org.ID.ToInt64() && q.Status == 2).First();
+                if (!ship.IsNullOrEmpty())
+                {
+                    result.Data = ship.BusinessDate.Date == DateTime.Now.Date ? new()
+                    {
+                        ShipDoc = ship.ShipDoc,
+                        ShippingQty = ship.ShipQty.ToDouble(),
+                        Tag = "Customer"
+                    } : new()
+                    {
+                        ShipDoc = ship.ShipDoc,
+                        ShippingQty = ship.ShipQty.ToDouble(),
+                        Tag = "InStoreLabel"
+                    };
+                    result.LocaleMsg = new($"鍑鸿揣淇℃伅瀛樺湪锛�");
                 }
                 else
                 {
-                    result.LocaleMsg = new($"鍑鸿揣淇℃伅瀛樺湪锛�");
-                    result.Data = "InStore";
+                    result.Data = new()
+                    {
+                        ShipDoc = "",
+                        ShippingQty = 0,
+                        Tag = "InStoreLabel"
+                    };
                 }
             }
             catch (Exception ex)
@@ -511,5 +681,200 @@
             }
             return result;
         }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="SN"></param>
+        /// <param name="user"></param>
+        /// <returns></returns>
+        public async Task<ApiAction> UnbindWipSnFromWO(UnbindWipSnInput input)
+        {
+            var result = new ApiAction();
+            try
+            {
+                var cartonSn = input.SN.Split('|')[0];
+                var wipList = await Biz.Db.Queryable<MES_WIP_DATA>().Where(q => q.SN.Equals(input.SN) || q.FLOW_SN.Equals(input.SN) || q.CARTON_SN == cartonSn).ToListAsync();
+                if (wipList.Count == 0)
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"瑙g粦鐨勬潯鐮佷笉瀛樺湪褰撳墠鎿嶄綔琛ㄤ腑锛�");
+                    return result;
+                }
+                var wo = await Biz.Db.Queryable<BIZ_MES_WO>().Where(q => q.ORDER_NO == wipList[0].WORK_ORDER).FirstAsync();
+                result = WorkBatch.UnbindWipSnFromWO(wo, wipList, input.user);
+                if (result.IsSuccessed)
+                {
+                    var newList = await Biz.Db.Queryable<MES_WIP_PKG>().Where(q => q.WORK_ORDER == wo.ORDER_NO && q.BATCH_NO == wipList[0].BATCH_NO && SqlFunc.IsNullOrEmpty(q.PARENT_SN) && q.QTY > 0).ToListAsync();
+                    result.Data = newList;
+                }
+            }
+            catch (Exception ex)
+            {
+                result.CatchExceptionWithLog(ex, "瑙g粦鏉$爜寮傚父");
+            }
+            return result;
+        }
+
+        /// <summary>
+        /// 鐢熸垚鍏ュ簱鑾峰彇鏉$爜宸ュ崟淇℃伅鍙婂寘瑁呬俊鎭�
+        /// </summary>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public async Task<ApiAction<InStoreInfo>> GetErpProdInBth(string code)
+        {
+            var result = new ApiAction<InStoreInfo>();
+            try
+            {
+                //寰楀埌宸ュ崟鏉$爜璁板綍
+                var cartonSn = code.Split('|')[0];
+                var woSns = await Biz.Db.Queryable<BIZ_MES_WO_SN>().Where(q => q.OUTER_SN == cartonSn).ToListAsync();
+                if (woSns.Count == 0)
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"鏉$爜涓嶅瓨鍦紒");
+                    return result;
+                }
+                var wo = await Biz.Db.Queryable<BIZ_MES_WO>().Where(q => q.ORDER_NO == woSns[0].WORK_ORDER).IncludesAllFirstLayer().IncludesAllSecondLayer(q => q._ItemInfos).FirstAsync();
+                if (wo == null)
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"鏉$爜瀵瑰簲鐨勫伐鍗曚笉瀛樺湪");
+                    return result;
+                }
+                //鍒ゆ柇宸ュ崟鏄惁宸茬粡鍏ㄩ儴鍏ュ簱
+
+
+                InStoreInfo inStoreInfo = new()
+                {
+                    ErpProdInBth = new()
+                    {
+                        WORK_ORDER = wo.ORDER_NO,
+                        BATCH_NO = woSns[0].BATCH_NO,
+                        SALES_ORDER = wo.SALES_ORDER,
+                        ITEM_CODE = wo.ITEM_CODE,
+                        ITEM_NAME = wo.ItemInfo?.ITEM_DESC,
+                        SapCode = wo.ItemInfo?.ExtInfo?.SapCode,
+                        SCAN_QTY = woSns.Count,
+                        IS_HANDLED = "N" //Y-宸茬敓鎴愶紝N-鏈敓鎴愶紝F-澶辫触
+                    },
+                    InStoreScanInfo = new()
+                    {
+                        SN = cartonSn,
+                        SALES_ORDER = wo.SALES_ORDER,
+                        WORK_ORDER = wo.ORDER_NO,
+                        BATCH_NO = woSns[0].BATCH_NO,
+                        SCAN_QTY = woSns.Count
+                    }
+                };
+                result.Data = inStoreInfo;
+                result.LocaleMsg = new($"鑾峰彇鏉$爜[{code}]宸ュ崟淇℃伅鍙婂寘瑁呬俊鎭垚鍔�");
+            }
+            catch (Exception ex)
+            {
+                result.CatchExceptionWithLog(ex, $"鑾峰彇鏉$爜[{code}]宸ュ崟淇℃伅鍙婂寘瑁呬俊鎭紓甯�");
+            }
+            return result;
+        }
+
+        /// <summary>
+        /// 鑾峰彇宸ュ崟澶囨枡淇℃伅
+        /// </summary>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public async Task<ApiAction<List<WoFlowCardPrintJson>>> GetWoPickList(string code)
+        {
+            var action = new ApiAction<List<WoFlowCardPrintJson>>($"鎴愬姛", new List<WoFlowCardPrintJson>());
+            try
+            {
+                DbClient db = Biz.DataSource["YadaU9C"].Client;
+                var moPickLists = db.Queryable<mes_MOPickList>().Where(q => q.MoDocNo == code).ToList();
+                var ids = moPickLists.Select(x => SqlFunc.ToString(x.ItemMaster)).ToList();
+                var items = Biz.Db.Queryable<BAS_ITEM>().Where(q => ids.Contains(q.ID)).IncludesAllFirstLayer().ToList();
+                var wo = await Biz.Db.Queryable<BIZ_MES_WO>().Where(q => q.ORDER_NO == code).IncludesAllFirstLayer().FirstAsync();
+                SugarParameter[] pars = Biz.Db.Ado.GetParameters(new { WO = code });
+                var routeList = Biz.Db.Ado.UseStoredProcedure().SqlQuery<V_MES_WO_PTREE>("SP_MES_GET_WO_PTREE", pars);//杩斿洖List
+                var routeStr = string.Join("->", routeList.Where(q => q.type == "Node" && q.name != "瀹屽伐").OrderBy(x=>x.seq).Select(q=>q.name).ToList());
+                List<WoFlowCardPrintJson> woFlowCardPrintJson = new();
+                //鐢熸垚鎵撳嵃瀹炰綋
+                int i = 1;
+                WoFlowCardPrintJson printJson = new()
+                {
+                    ID = Guid.NewGuid().ToString("N"),
+                    OrderNo = code,
+                    ItemCode = wo.ITEM_CODE,
+                    ItemDesc = wo.ItemInfo?.ITEM_DESC,
+                    SapCode = wo.ItemInfo?.ExtInfo?.SapCode,
+                    Qty = wo.PLAN_QTY,
+                    Model = "",
+                    Remark = wo.SALES_REMARK,
+                    RouteStr = routeStr,
+                    Items = new() { }
+                };
+                foreach (var item in moPickLists)
+                {
+                    PrintWoPickList list = new()
+                    {
+                        LineNo = item.DocLineNO,
+                        SapCode = items.Where(q=> q.ID == SqlFunc.ToString(item.ItemMaster)).FirstOrDefault()?.ExtInfo?.SapCode,
+                        ItemCode = item.Code,
+                        ItemDesc = items.Where(q => q.ID == SqlFunc.ToString(item.ItemMaster)).FirstOrDefault()?.ITEM_DESC,
+                        PickQty = item.ActualReqQty,
+                        LineRemark = "",
+                        WhCode = item.BinCode,
+                        WhCode07 = item.WhCode == "10107" ? item.BinCode : "",
+                        Method = item.IssueStyleName,
+                    };
+                    printJson.Items.Add(list);
+                    if (i % 6 == 0)
+                    {
+                        woFlowCardPrintJson.Add(printJson);
+                        printJson = new()
+                        {
+                            ID = Guid.NewGuid().ToString("N"),
+                            OrderNo = code,
+                            ItemCode = wo.ITEM_CODE,
+                            ItemDesc = wo.ItemInfo?.ITEM_DESC,
+                            SapCode = wo.ItemInfo?.ExtInfo?.SapCode,
+                            Qty = wo.PLAN_QTY,
+                            Model = "",
+                            Remark = wo.SALES_REMARK,
+                            RouteStr = routeStr,
+                            Items = new() { }
+                        };
+                    }
+                    i++;
+                }
+                action.Data = woFlowCardPrintJson;
+            }
+            catch (Exception ex)
+            {
+                action.CatchExceptionWithLog(ex, $"鑾峰彇宸ュ崟{code}澶囨枡淇℃伅寮傚父");
+            }
+            return action;
+        }
+
+        #region 鎻愪氦鍓嶉�氱敤鏂规硶
+        /// <summary>
+        /// 鎻愪氦鍓嶆鏌ユ槸鍚﹀矖浣嶃�佸伐鍗曞拰涓嶈壇浠g爜
+        /// </summary>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public async Task<ApiAction<CheckCodeOutput>> CheckCode(string code)
+        {
+            var action = new ApiAction<CheckCodeOutput>($"妫�鏌ユ潯鐮亄code}鎴愬姛", new CheckCodeOutput());
+            try
+            {
+                action.Data.Position = DbCache.Cache.Position[code];
+                action.Data.WorkOrder = await Biz.Db.Queryable<BIZ_MES_WO>().Where(q => q.ORDER_NO == code).FirstAsync();
+                action.Data.Defect = DbCache.Cache.Defect[code];
+            }
+            catch (Exception ex)
+            {
+                action.CatchExceptionWithLog(ex, $"妫�鏌ユ潯鐮亄code}寮傚父");
+            }
+            return action;
+        }
+        #endregion
     }
 }

--
Gitblit v1.9.3