From 70541192ff0c11dec68959fcf6ba6b4c90a81f9c Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期四, 15 八月 2024 17:20:49 +0800
Subject: [PATCH] 增加称重行为

---
 Tiger.Business.MES/WorkAction/PackingAction.cs |  115 +++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 70 insertions(+), 45 deletions(-)

diff --git a/Tiger.Business.MES/WorkAction/PackingAction.cs b/Tiger.Business.MES/WorkAction/PackingAction.cs
index d5b882d..683dc42 100644
--- a/Tiger.Business.MES/WorkAction/PackingAction.cs
+++ b/Tiger.Business.MES/WorkAction/PackingAction.cs
@@ -9,6 +9,8 @@
 using Tiger.IBusiness.MES.WorkAction;
 using Tiger.Model;
 using Tiger.Model.Entitys.MES.Position;
+using static Tiger.Model.WMS_ITEM_PKG;
+using Tiger.Model.Minsun;
 
 namespace Tiger.Business.MES.WorkAction
 {
@@ -194,15 +196,8 @@
                 case "Scan":
                     if (CurCmd.IsNullOrEmpty() || CurCmd.ExecCode == "Scan" || (CurCmd.ExecCode == "Print" && CurCmd.PkgLevel == pInput.PkgLevel))
                     {
-                        //瀹㈡埛绔壂鎻忔垚鍔�
-                        if (pInput.IsFinish)
-                        {
-                            CurCmd = null;
-                            PrintTimes = 0;
-                            action = SavePkgData(input, action);
-                        }
                         //瀹㈡埛绔壂鎻忓け璐�
-                        else
+                        if (!pInput.IsFinish || pInput.PkgSN.IsNullOrEmpty())
                         {
                             var dtl = PkgRule.Details.First(q => q.PKG_LEVEL == pInput.PkgLevel);
                             action.IsSuccessed = false;
@@ -210,6 +205,19 @@
                             action.LocaleMsg = new("MES.WorkAction.PackingAction.ScanFail", dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME);
                             return action;
                         }
+                        //楠岃瘉褰撳墠鍖呰鏉$爜鏄惁宸茬粡琚壂鎻忚繃
+                        if (GetPackageList(CurPkg.Item).Any(q => q.SN == pInput.PkgSN))
+                        {
+                            var dtl = PkgRule.Details.First(q => q.PKG_LEVEL == pInput.PkgLevel);
+                            action.IsSuccessed = false;
+                            //action.LocaleMsg = new($"鏉$爜[{pInput.PkgSN}]鏃犻渶閲嶅鎵弿锛岃鎵弿绗瑊dtl.PKG_LEVEL}灞傚寘瑁匸{dtl.PkgType.PKG_NAME}]鐨勬爣绛炬潯鐮�");
+                            action.LocaleMsg = new("MES.WorkAction.PackingAction.ScanRepeat", pInput.PkgSN, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME);
+                            return action;
+                        }
+                        //瀹㈡埛绔壂鎻忔垚鍔�
+                        CurCmd = null;
+                        PrintTimes = 0;
+                        action = SavePkgData(input, action);
                     }
                     break;
                 //Print锛氭墦鍗帮紝鎵撳嵃褰撳墠鍖呰灞傜骇鐨勬爣绛�
@@ -339,28 +347,30 @@
                         PKG_QTY = dtl.PKG_QTY,
                         LABEL_CODE = LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE,
                         IsFinished = true,
-                        Package = new()
-                        {
-                            AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG,
-                            AUTH_PROD = CurPosition.CurLine.LINE_CODE,
-                            SN = pInput.PkgSN,
-                            PKG_TYPE = dtl.PkgType.PKG_NAME,
-                            ITEM_CODE = CurPosition.CurWipSNs.First().ITEM_CODE,
-                            QTY = CurPosition.CurWipSNs.First().QTY,
-                            UNIT = dtl.PkgType.PKG_NAME,
-                            WORK_ORDER = CurPosition.CurWipSNs.First().WORK_ORDER,
-                            BATCH_NO = CurPosition.CurWipSNs.First().BATCH_NO,
-                            ROT_CODE = CurPosition.CurWipSNs.First().ROT_CODE,
-                            NODE_ID = CurPosition.CurWipSNs.First().NODE_ID,
-                            NODE_NAME = CurPosition.CurWipSNs.First().NODE_NAME,
-                            FTY_CODE = CurPosition.CurWipSNs.First().FTY_CODE,
-                            WS_CODE = CurPosition.CurWipSNs.First().WS_CODE,
-                            LINE_CODE = CurPosition.CurWipSNs.First().LINE_CODE,
-                            POST_CODE = CurPosition.CurWipSNs.First().POST_CODE,
-                            OPER_CODE = CurPosition.CurWipSNs.First().OPER_CODE,
-                            SEGMENT = CurPosition.CurWipSNs.First().SEGMENT,
-                        }
                     };
+
+                    CurPkgItem.Package = Biz.Db.Queryable<MES_WIP_PKG>().Where(q => q.SN == pInput.PkgSN && q.AUTH_ORG == CurPosition.WorkBatch.WO.AUTH_ORG).First() ?? new()
+                    {
+                        AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG,
+                        AUTH_PROD = CurPosition.CurLine.LINE_CODE,
+                        SN = pInput.PkgSN,
+                    };
+                    CurPkgItem.Package.WIP_ID = CurPosition.CurWipSNs.Count == 1 ? CurPosition.CurWipSNs.First().ID : null;
+                    CurPkgItem.Package.PKG_TYPE = dtl.PkgType.PKG_NAME;
+                    CurPkgItem.Package.ITEM_CODE = CurPosition.CurWipSNs.First().ITEM_CODE;
+                    CurPkgItem.Package.QTY = CurPosition.CurWipSNs.First().QTY;
+                    CurPkgItem.Package.UNIT = dtl.PkgType.PKG_NAME;
+                    CurPkgItem.Package.WORK_ORDER = CurPosition.CurWipSNs.First().WORK_ORDER;
+                    CurPkgItem.Package.BATCH_NO = CurPosition.CurWipSNs.First().BATCH_NO;
+                    CurPkgItem.Package.ROT_CODE = CurPosition.CurWipSNs.First().ROT_CODE;
+                    CurPkgItem.Package.NODE_ID = CurPosition.CurWipSNs.First().NODE_ID;
+                    CurPkgItem.Package.NODE_NAME = CurPosition.CurWipSNs.First().NODE_NAME;
+                    CurPkgItem.Package.FTY_CODE = CurPosition.CurWipSNs.First().FTY_CODE;
+                    CurPkgItem.Package.WS_CODE = CurPosition.CurWipSNs.First().WS_CODE;
+                    CurPkgItem.Package.LINE_CODE = CurPosition.CurWipSNs.First().LINE_CODE;
+                    CurPkgItem.Package.POST_CODE = CurPosition.CurWipSNs.First().POST_CODE;
+                    CurPkgItem.Package.OPER_CODE = CurPosition.CurWipSNs.First().OPER_CODE;
+                    CurPkgItem.Package.SEGMENT = CurPosition.CurWipSNs.First().SEGMENT;
                     FinishLevel++;
                     action = SavePkgData(input, action);
                 }
@@ -402,7 +412,7 @@
                         //鏈�澶栧眰鍖呰宸茬粡瀹屾垚鍖呰锛屼繚瀛樺寘瑁呮暟鎹埌鏁版嵁搴�
                         else
                         {
-                            action = SaveToDB();
+                            action = CompletePkg();
                         }
                     }
                     //褰撳墠澶勭悊鐨勫寘瑁呭眰绾у凡缁忓鐞嗗畬锛岀户缁線涓婁繚瀛�
@@ -506,22 +516,9 @@
             return list;
         }
 
-        public ApiAction<SubmitOutput> SaveToDB()
+        public ApiAction<SubmitOutput> CompletePkg()
         {
             var action = new ApiAction<SubmitOutput>(new SubmitOutput());
-
-            var pkgList = GetPackageList(CurPkg.Item);
-
-            //淇濆瓨鏁版嵁搴�
-            var db = Biz.Db;
-            var dbTran = db.UseTran(() =>
-            {
-                db.Insertable(pkgList, CurPosition.UserCode).ExecuteCommand();
-            });
-            if (!dbTran.IsSuccess)
-            {
-                throw dbTran.ErrorException;
-            }
 
             var data = new PackingActionOutput() { PkgInfo = CurPkg };
             data.ExecCode = "Complete";
@@ -556,6 +553,7 @@
                 {
                     AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG,
                     AUTH_PROD = CurPosition.CurLine.LINE_CODE,
+                    WIP_ID = wipSn.ID,
                     HIS_ID = CurPosition.CurWipSNHiss.First(q => q.SN == wipSn.SN).ID,
                     SN = wipSn.SN,
                     STATUS = wipSn.STATUS,
@@ -573,7 +571,11 @@
                     POST_CODE = wipSn.POST_CODE,
                     OPER_CODE = wipSn.OPER_CODE,
                     SEGMENT = wipSn.SEGMENT,
+                    FLOW_SN = wipSn.FLOW_SN,
                     TRAY_SN = wipSn.TRAY_SN,
+                    INNER_SN = wipSn.INNER_SN,
+                    CARTON_SN = wipSn.CARTON_SN,
+                    PALLET_SN = wipSn.PALLET_SN,
                     OPERATION_TIME = DateTime.Now,
                     SFTS_CODE = wipSn.SFTS_CODE,
                     SFT_CODE = wipSn.SFT_CODE,
@@ -586,11 +588,34 @@
                 wipActs.Add(wipAct);
             }
 
+            //鍒涘缓鍙橀噺鍏嬮殕瀵硅薄鐢ㄤ簬浼犲叆DBSubmitAction涓繚瀛樺綋鍓嶉渶瑕佹殏瀛樼殑鏁版嵁鍊�
+            var _wipActs = wipActs.Clone();
+            var _pkgList = CurPkg.IsFinished ? GetPackageList(CurPkg.Item) : new();
             //淇濆瓨鏁版嵁
             CurStep.DBSubmitAction = () =>
             {
                 var db = CurPosition.GetCommitDB();
-                db.Storageable(wipActs, CurPosition.UserCode).ExecuteCommand();
+                db.Storageable(_wipActs, CurPosition.UserCode).ExecuteCommand();
+                if (_pkgList.Any())
+                {
+                    db.Insertable(_pkgList, CurPosition.UserCode).ExecuteCommand();
+                    foreach (var pkg in _pkgList)
+                    {
+                        //鍖呰淇℃伅淇濆瓨鍒板湪鍒跺搧淇℃伅琛�
+                        db.Updateable<MES_WIP_DATA>()
+                            .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 == pkg.WORK_ORDER && q.SN == pkg.SN)
+                            .ExecuteCommand();
+                        //鍖呰淇℃伅淇濆瓨鍒板伐鍗曟潯鐮佹槑缁嗚〃
+                        db.Updateable<BIZ_MES_WO_SN>()
+                            .SetColumns(q => q.TRAY_SN == CurPkg.Item.Package.SN)
+                            .SetColumns(q => q.OUTER_SN == CurPkg.Item.Package.SN)
+                            .Where(q => q.WORK_ORDER == pkg.WORK_ORDER && q.SN == pkg.SN)
+                            .ExecuteCommand();
+                    }
+                }
             };
 
             if (CurPkg.IsFinished)

--
Gitblit v1.9.3