From 6b859e3a66611841adbabd4bf01ae6575be96bca Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期三, 20 十一月 2024 21:40:21 +0800
Subject: [PATCH] 一些优化

---
 Tiger.Business.MES/Common/WorkBatch.cs |   22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/Tiger.Business.MES/Common/WorkBatch.cs b/Tiger.Business.MES/Common/WorkBatch.cs
index d230d1c..d431e97 100644
--- a/Tiger.Business.MES/Common/WorkBatch.cs
+++ b/Tiger.Business.MES/Common/WorkBatch.cs
@@ -601,14 +601,14 @@
             var batchs = wipList.Where(q => !q.BATCH_NO.IsNullOrEmpty()).GroupBy(q => new { q.BATCH_NO }).Select(g => new { 
                 g.Key.BATCH_NO, 
                 Qty = g.Count(),
-                FinishQty = g.Count(q => q.STATUS == MES_WIP_DATA.STATUSs.Finished.GetValue()),
+                OutQty = g.Count(q => MES_WIP_DATA.STATUSs.Output.GetValue() <= q.STATUS && q.STATUS < MES_WIP_DATA.STATUSs.InStorage.GetValue()),
             });
             var db = Biz.Db;
             var dbTran = db.UseTran(() =>
             {
                 //BIZ_MES_WO
                 wo.INPUT_QTY -= wipList.Count;
-                wo.OUTPUT_QTY -= wipList.Count(q => q.STATUS == MES_WIP_DATA.STATUSs.Finished.GetValue());
+                wo.OUTPUT_QTY -= wipList.Count(q => MES_WIP_DATA.STATUSs.Output.GetValue() <= q.STATUS && q.STATUS < MES_WIP_DATA.STATUSs.InStorage.GetValue());
                 wo.SCRAP_QTY += wipList.Count;
                 wo.STATUS = wo.STATUS.GetEnum<BIZ_MES_WO.STATUSs>() == BIZ_MES_WO.STATUSs.Closed ? BIZ_MES_WO.STATUSs.Working.GetValue() : wo.STATUS;
                 db.Updateable(wo, user).UpdateColumns(q => new { q.INPUT_QTY, q.OUTPUT_QTY, q.SCRAP_QTY, q.UPDATE_USER, q.UPDATE_TIME, q.STATUS }).ExecuteCommand();
@@ -617,7 +617,7 @@
                 foreach (var batch in wobatchs)
                 {
                     batch.INPUT_QTY -= batchs.Where(q=>q.BATCH_NO == batch.BATCH_NO).First().Qty;
-                    batch.OUTPUT_QTY -= batchs.Where(q => q.BATCH_NO == batch.BATCH_NO).First().FinishQty;
+                    batch.OUTPUT_QTY -= batchs.Where(q => q.BATCH_NO == batch.BATCH_NO).First().OutQty;
                     batch.SCRAP_QTY += batchs.Where(q => q.BATCH_NO == batch.BATCH_NO).First().Qty;
                     batch.STATUS = batch.STATUS.GetEnum<BIZ_MES_WO_BATCH.STATUSs>() == BIZ_MES_WO_BATCH.STATUSs.Closed ? BIZ_MES_WO_BATCH.STATUSs.Working.GetValue() : batch.STATUS;
                 }
@@ -625,6 +625,7 @@
                 //BIZ_MES_WO_SN
                 db.Updateable<BIZ_MES_WO_SN>(user)
                             .SetColumns(q => q.STATUS == BIZ_MES_WO_SN.STATUSs.Offline.GetValue())
+                            .SetColumns(q => q.TRAY_SN == null).SetColumns(q => q.OUTER_SN == null)
                             .Where(q => q.WORK_ORDER == wo.ORDER_NO && wipIDs.Contains(q.WIP_ID))
                             .ExecuteCommand();
                 //MES_WIP_DATA & MES_WIP_HIS
@@ -632,6 +633,8 @@
                 foreach (var wipSN in wipList.Where(q => q.STATUS != MES_WIP_DATA.STATUSs.Offline.GetValue()))
                 {
                     wipSN.STATUS = MES_WIP_DATA.STATUSs.Offline.GetValue();
+                    wipSN.TRAY_SN = wipSN.INNER_SN = wipSN.CARTON_SN = wipSN.PALLET_SN = wipSN.SHIPPING_ORDER = null;
+                    wipSN.FINISHED_FLAG = wipSN.HOLD_FLAG = "N";
                     wipSN.UNBIND_FLAG = "Y";
                     wipSN.NODE_ID = "";
                     wipSN.NODE_NAME = "涓嬬嚎閫�搴�";
@@ -672,7 +675,18 @@
                 //鎶涘嚭寮傚父
                 throw dbTran.ErrorException;
             }
-
+            //鏇存柊宸ュ崟姹犱腑鐨勫伐鍗曟潯鐮佽〃鏁版嵁鐨勭姸鎬�
+            foreach (var item in WoContext.WoBatchDic)
+            {
+                if (item.Value.WO.ORDER_NO == wo.ORDER_NO)
+                {
+                    foreach (var woSn in item.Value.WoSNs.Where(q => wipIDs.Contains(q.WIP_ID)))
+                    {
+                        woSn.STATUS = BIZ_MES_WO_SN.STATUSs.Offline.GetValue();
+                    }
+                    item.Value.Update();
+                }
+            }
             return action;
         }
         #endregion

--
Gitblit v1.9.3