From 454bd635d7e37aec7c48bb627129b519b4853ce6 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期四, 09 一月 2025 16:20:36 +0800
Subject: [PATCH] U9C条码实体更新

---
 Tiger.Business.MES/iERP/U9C_MES.cs |  325 +++++++++++++++++++++++++++--------------------------
 1 files changed, 164 insertions(+), 161 deletions(-)

diff --git a/Tiger.Business.MES/iERP/U9C_MES.cs b/Tiger.Business.MES/iERP/U9C_MES.cs
index 7f56288..dfe8d48 100644
--- a/Tiger.Business.MES/iERP/U9C_MES.cs
+++ b/Tiger.Business.MES/iERP/U9C_MES.cs
@@ -78,6 +78,7 @@
                             Accuracy = (di["Accuracy"] ?? "").ToString(),
                             Remark = (di["Remark"] ?? "").ToString(),
                             Packaging = (di["Packaging"] ?? "").ToString(),
+                            SapCode = (di["Code1"] ?? "").ToString(),
                         };
                         itemExts.Add(extInfo);
                     }
@@ -85,57 +86,58 @@
             }
             Logger.Scheduler.Info($"鐗╂枡淇℃伅瀛樺叆瀹炰綋涓紝鎬绘暟锛歔{items.Count}]");
             db = Biz.Db;
-            var dbTran = db.UseTran(() =>
+            //var dbTran = db.UseTran(() =>
+            //{
+            if (items.Any())
             {
-                if (items.Any())
+                if (items.Count > 100)
                 {
-                    if (items.Count > 100)
+                    db.Utilities.PageEach(items, 100, pageList =>
                     {
-                        db.Utilities.PageEach(items, 100, pageList =>
-                        {
-                            var y = db.Storageable(pageList, "U9C")
-                                   .WhereColumns(t => new { t.ID, t.GHOST_ROW })
-                                   .ToStorage();
-                            y.AsInsertable.ExecuteCommand();
-                            y.AsUpdateable.ExecuteCommand();
-                        });
-                    }
-                    else {
-                        var y = db.Storageable(items, "U9C")
-                                       .WhereColumns(t => new { t.ID, t.GHOST_ROW })
-                                       .ToStorage();
+                        var y = db.Storageable(pageList, "U9C")
+                               .WhereColumns(t => new { t.ID, t.GHOST_ROW })
+                               .ToStorage();
                         y.AsInsertable.ExecuteCommand();
                         y.AsUpdateable.ExecuteCommand();
-                    }
+                    });
                 }
-                if (itemExts.Any())
+                else
                 {
-                    if (itemExts.Count > 100)
-                    {
-                        db.Utilities.PageEach(itemExts, 100, pageList =>
-                         {
-                             var y = db.Storageable(pageList, "U9C")
-                                    .WhereColumns(t => new { t.ITEM_ID, t.GHOST_ROW })
-                                    .ToStorage();
-                             y.AsInsertable.ExecuteCommand();
-                             y.AsUpdateable.ExecuteCommand();
-                         });
-                    }
-                    else
-                    {
-                        var s = db.Storageable(itemExts, "U9C")
-                               .WhereColumns(t => new { t.ITEM_ID, t.GHOST_ROW })
-                               .ToStorage();
-                        s.AsInsertable.ExecuteCommand();
-                        s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
-                    }
+                    var y = db.Storageable(items, "U9C")
+                                   .WhereColumns(t => new { t.ID, t.GHOST_ROW })
+                                   .ToStorage();
+                    y.AsInsertable.ExecuteCommand();
+                    y.AsUpdateable.ExecuteCommand();
                 }
-            });
-            if (!dbTran.IsSuccess)
-            {
-                action.CatchExceptionWithLog(dbTran.ErrorException, $"鏁版嵁澶勭悊澶辫触");
-                Logger.Scheduler.Error(action.Message);
             }
+            if (itemExts.Any())
+            {
+                if (itemExts.Count > 100)
+                {
+                    db.Utilities.PageEach(itemExts, 100, pageList =>
+                     {
+                         var y = db.Storageable(pageList, "U9C")
+                                .WhereColumns(t => new { t.ITEM_ID, t.GHOST_ROW })
+                                .ToStorage();
+                         y.AsInsertable.ExecuteCommand();
+                         y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                     });
+                }
+                else
+                {
+                    var s = db.Storageable(itemExts, "U9C")
+                           .WhereColumns(t => new { t.ITEM_ID, t.GHOST_ROW })
+                           .ToStorage();
+                    s.AsInsertable.ExecuteCommand();
+                    s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                }
+            }
+            //});
+            //if (!dbTran.IsSuccess)
+            //{
+            //    action.CatchExceptionWithLog(dbTran.ErrorException, $"鏁版嵁澶勭悊澶辫触");
+            //    Logger.Scheduler.Error(action.Message);
+            //}
             Logger.Scheduler.Info($"鐗╂枡淇℃伅瀛樺叆鏁版嵁搴擄紝鎬绘暟锛歔{items.Count}]");
             action.Message = $"鐗╂枡淇℃伅瀛樺叆鏁版嵁搴擄紝鎬绘暟锛歔{items.Count}]";
             return action;
@@ -207,15 +209,15 @@
                 db.Storageable(LastRun, "U9C_MES_GetWo").ExecuteCommand();
                 if (items.Any())
                 {
-                    if (items.Count > 150)
+                    if (items.Count > 100)
                     {
-                        db.Utilities.PageEach(items, 1000, pageList =>
+                        db.Utilities.PageEach(items, 100, pageList =>
                         {
                             var y = db.Storageable(pageList, "U9C")
                                    .WhereColumns(t => new { t.ORDER_NO, t.GHOST_ROW })
                                    .ToStorage();
-                            y.BulkCopy();
-                            y.BulkUpdate();
+                            y.AsInsertable.ExecuteCommand();
+                            y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
                         });
                     }
                     else
@@ -242,15 +244,18 @@
                 Work.DoAsync(() =>
                 {
                     List<BIZ_MES_WO> woList = new();
-                    foreach (var wo in items) {
+                    foreach (var wo in items)
+                    {
                         //鍙湁宸ュ崟鐘舵�佷负鍒濆鍖栧拰宸ヨ壓鐘舵�佷负寰呴厤缃墠鑷姩缁戝畾宸ヨ壓璺嚎
-                        if (wo.STATUS == BIZ_MES_WO.STATUSs.Init.GetValue() && wo.ROUTE_STATUS == BIZ_MES_WO.ROUTE_STATUSs.WaitSet.GetValue()) {
+                        if (wo.STATUS == BIZ_MES_WO.STATUSs.Init.GetValue() && wo.ROUTE_STATUS == BIZ_MES_WO.ROUTE_STATUSs.WaitSet.GetValue())
+                        {
                             try
                             {
                                 var rot = Biz.Db.Queryable<MES_PROD_OPER>()
-                                .GroupBy(x => new { x.PROD_CODE, x.ROT_ID})
+                                .GroupBy(x => new { x.PROD_CODE, x.ROT_ID })
                                 .Where(q => q.PROD_CODE == wo.ITEM_CODE)
-                                .Select(it => new {
+                                .Select(it => new
+                                {
                                     PROD_CODE = it.PROD_CODE,
                                     ROT_ID = it.ROT_ID
                                 })
@@ -284,11 +289,7 @@
                     {
                         if (woList.Any())
                         {
-                            var s = _db.Storageable(woList, "U9C")
-                                   .WhereColumns(t => new { t.ORDER_NO, t.GHOST_ROW })
-                                   .ToStorage();
-                            s.AsInsertable.ExecuteCommand();
-                            s.AsUpdateable.IgnoreColumns(x => x.ID).UpdateColumns(x => new { x.ROUTE_STATUS}).ExecuteCommand();
+                            _db.Updateable(woList, "U9C").UpdateColumns(x => new { x.ROUTE_STATUS }).ExecuteCommand();
                         }
 
                     });
@@ -343,37 +344,37 @@
             }
             Logger.Scheduler.Info($"瀹㈡埛淇℃伅瀛樺叆瀹炰綋涓紝鎬绘暟锛歔{items.Count}]");
             db = Biz.Db;
-            var dbTran = db.UseTran(() =>
-                {
-                    if (items.Any())
-                    {
-                        if (items.Count > 100)
-                        {
-                           db.Utilities.PageEach(items, 100, pageList =>
-                            {
-                                var y = db.Storageable(pageList, "U9C")
-                                       .WhereColumns(t => new { t.CUST_CODE, t.GHOST_ROW })
-                                       .ToStorage();
-                                y.AsInsertable.ExecuteCommand();
-                                y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
-                            });
-                        }
-                        else
-                        {
-                            var s = db.Storageable(items, "U9C")
-                                   .WhereColumns(t => new { t.CUST_CODE, t.GHOST_ROW })
-                                   .ToStorage();
-                            s.AsInsertable.ExecuteCommand();
-                            s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
-                        }
-                    }
-
-                });
-            if (!dbTran.IsSuccess)
+            //var dbTran = db.UseTran(() =>
+            //    {
+            if (items.Any())
             {
-                action.CatchExceptionWithLog(dbTran.ErrorException, $"鏁版嵁澶勭悊澶辫触");
-                Logger.Scheduler.Error(action.Message);
+                if (items.Count > 100)
+                {
+                    db.Utilities.PageEach(items, 100, pageList =>
+                     {
+                         var y = db.Storageable(pageList, "U9C")
+                                .WhereColumns(t => new { t.CUST_CODE, t.GHOST_ROW })
+                                .ToStorage();
+                         y.AsInsertable.ExecuteCommand();
+                         y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                     });
+                }
+                else
+                {
+                    var s = db.Storageable(items, "U9C")
+                           .WhereColumns(t => new { t.CUST_CODE, t.GHOST_ROW })
+                           .ToStorage();
+                    s.AsInsertable.ExecuteCommand();
+                    s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                }
             }
+
+            //    });
+            //if (!dbTran.IsSuccess)
+            //{
+            //    action.CatchExceptionWithLog(dbTran.ErrorException, $"鏁版嵁澶勭悊澶辫触");
+            //    Logger.Scheduler.Error(action.Message);
+            //}
             Logger.Scheduler.Info($"瀹㈡埛淇℃伅瀛樺叆鏁版嵁搴擄紝鎬绘暟锛歔{items.Count}]");
             action.Message = $"瀹㈡埛淇℃伅瀛樺叆鏁版嵁搴擄紝鎬绘暟锛歔{items.Count}]";
             return action;
@@ -417,37 +418,37 @@
             }
             Logger.Scheduler.Info($"渚涘簲鍟嗕俊鎭瓨鍏ュ疄浣撲腑锛屾�绘暟锛歔{items.Count}]");
             db = Biz.Db;
-            var dbTran = db.UseTran(() =>
+            //var dbTran = db.UseTran(() =>
+            // {
+            if (items.Any())
             {
-                if (items.Any())
+                if (items.Count > 100)
                 {
-                    if (items.Count > 100)
+                    db.Utilities.PageEach(items, 100, pageList =>
                     {
-                        db.Utilities.PageEach(items, 100, pageList =>
-                        {
-                            var y = db.Storageable(pageList, "U9C")
-                                   .WhereColumns(t => new { t.SUPP_CODE, t.GHOST_ROW })
-                                   .ToStorage();
-                            y.AsInsertable.ExecuteCommand();
-                            y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
-                        });
-                    }
-                    else
-                    {
-                        var s = db.Storageable(items, "U9C")
+                        var y = db.Storageable(pageList, "U9C")
                                .WhereColumns(t => new { t.SUPP_CODE, t.GHOST_ROW })
                                .ToStorage();
-                        s.AsInsertable.ExecuteCommand();
-                        s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
-                    }
+                        y.AsInsertable.ExecuteCommand();
+                        y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                    });
                 }
-
-            });
-            if (!dbTran.IsSuccess)
-            {
-                action.CatchExceptionWithLog(dbTran.ErrorException, $"鏁版嵁澶勭悊澶辫触");
-                Logger.Scheduler.Error(action.Message);
+                else
+                {
+                    var s = db.Storageable(items, "U9C")
+                           .WhereColumns(t => new { t.SUPP_CODE, t.GHOST_ROW })
+                           .ToStorage();
+                    s.AsInsertable.ExecuteCommand();
+                    s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                }
             }
+
+            //});
+            //if (!dbTran.IsSuccess)
+            //{
+            //    action.CatchExceptionWithLog(dbTran.ErrorException, $"鏁版嵁澶勭悊澶辫触");
+            //    Logger.Scheduler.Error(action.Message);
+            //}
             Logger.Scheduler.Info($"渚涘簲鍟嗕俊鎭瓨鍏ユ暟鎹簱锛屾�绘暟锛歔{items.Count}]");
             action.Message = $"渚涘簲鍟嗕俊鎭瓨鍏ユ暟鎹簱锛屾�绘暟锛歔{items.Count}]";
             return action;
@@ -496,37 +497,37 @@
             }
             Logger.Scheduler.Info($"瀹㈡埛鏉$爜淇℃伅瀛樺叆瀹炰綋涓紝鎬绘暟锛歔{items.Count}]");
             db = Biz.Db;
-            var dbTran = db.UseTran(() =>
+            //var dbTran = db.UseTran(() =>
+            //{
+            if (items.Any())
             {
-                if (items.Any())
+                if (items.Count > 100)
                 {
-                    if (items.Count > 100)
-                    {
-                      db.Utilities.PageEach(items, 100, pageList =>
-                        {
-                            var y = db.Storageable(pageList, "U9C")
-                                   .WhereColumns(t => new { t.CUST_SN, t.GHOST_ROW })
-                                   .ToStorage();
-                            y.AsInsertable.ExecuteCommand();
-                            y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
-                        });
-                    }
-                    else
-                    {
-                        var s = db.Storageable(items, "U9C")
-                               .WhereColumns(t => new { t.CUST_SN, t.GHOST_ROW })
-                               .ToStorage();
-                        s.AsInsertable.ExecuteCommand();
-                        s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
-                    }
+                    db.Utilities.PageEach(items, 100, pageList =>
+                      {
+                          var y = db.Storageable(pageList, "U9C")
+                                 .WhereColumns(t => new { t.CUST_SN, t.GHOST_ROW })
+                                 .ToStorage();
+                          y.AsInsertable.ExecuteCommand();
+                          y.AsUpdateable.IgnoreColumns(x => x.ID).UpdateColumns(q => new { q.CUST_CODE, q.WORK_ORDER, q.CUST_SN, q.FLOW_SN, q.ITEM_CODE, q.CREATE_TIME, q.UPDATE_TIME, q.UPDATE_USER, q.AUTH_ORG }).ExecuteCommand();
+                      });
                 }
-
-            });
-            if (!dbTran.IsSuccess)
-            {
-                action.CatchExceptionWithLog(dbTran.ErrorException, $"鏁版嵁澶勭悊澶辫触");
-                Logger.Scheduler.Error(action.Message);
+                else
+                {
+                    var s = db.Storageable(items, "U9C")
+                           .WhereColumns(t => new { t.CUST_SN, t.GHOST_ROW })
+                           .ToStorage();
+                    s.AsInsertable.ExecuteCommand();
+                    s.AsUpdateable.IgnoreColumns(x => x.ID).UpdateColumns(q => new { q.CUST_CODE, q.WORK_ORDER, q.CUST_SN, q.FLOW_SN, q.ITEM_CODE, q.CREATE_TIME, q.UPDATE_TIME, q.UPDATE_USER, q.AUTH_ORG }).ExecuteCommand();
+                }
             }
+
+            //});
+            //if (!dbTran.IsSuccess)
+            //{
+            //    action.CatchExceptionWithLog(dbTran.ErrorException, $"鏁版嵁澶勭悊澶辫触");
+            //    Logger.Scheduler.Error(action.Message);
+            //}
             Logger.Scheduler.Info($"瀹㈡埛鏉$爜淇℃伅瀛樺叆鏁版嵁搴擄紝鎬绘暟锛歔{items.Count}]");
             action.Message = $"瀹㈡埛鏉$爜淇℃伅瀛樺叆鏁版嵁搴擄紝鎬绘暟锛歔{items.Count}]";
             return action;
@@ -564,6 +565,7 @@
                             UPDATE_TIME = di["ModifiedOn"].ToDateTime(),
                             PLAN_START_TIME = di["CreatedOn"].ToDateTime(),
                             STATUS = 0,
+                            WS_CODE = di["Department"] == null ? "" : di["Department"].ToString(),
                             AUTH_ORG = orgs.Where(x => x.ID == orgId).Select(q => q.ORG_CODE).FirstOrDefault(),
                             SALES_ORDER = di["SrcDoc_SrcDocNo"] == null ? "" : di["SrcDoc_SrcDocNo"].ToString(),
                             SALES_REMARK = di["SoLineMemo"] == null ? "" : di["SoLineMemo"].ToString(),
@@ -572,7 +574,7 @@
                             CUST_PREFIX = di["OutBarHead"] == null ? "" : di["OutBarHead"].ToString(),
                             SALES_CONTRACT = di["Contracts"] == null ? "" : di["Contracts"].ToString(),
                         };
-                        if (!Biz.Db.Queryable<BIZ_MES_WO>().Any(x => x.ORDER_NO == woItem.ORDER_NO && (x.STATUS > BIZ_MES_WO.STATUSs.Init.GetValue() || x.ROUTE_STATUS > BIZ_MES_WO.ROUTE_STATUSs.WaitSet.GetValue())))
+                        if (!Biz.Db.Queryable<BIZ_MES_WO>().Any(x => x.ORDER_NO == woItem.ORDER_NO && x.STATUS > BIZ_MES_WO.STATUSs.Imported.GetValue()))
                         {
                             items.Add(woItem);
                         }
@@ -586,37 +588,37 @@
             }
             Logger.Scheduler.Info($"宸ュ崟淇℃伅瀛樺叆瀹炰綋涓紝鎬绘暟锛歔{items.Count}]");
             db = Biz.Db;
-            var dbTran = db.UseTran(() =>
+            //var dbTran = db.UseTran(() =>
+            //{
+            if (items.Any())
             {
-                if (items.Any())
+                if (items.Count > 100)
                 {
-                    if (items.Count > 100)
+                    db.Utilities.PageEach(items, 100, pageList =>
                     {
-                        db.Utilities.PageEach(items, 100, pageList =>
-                        {
-                            var y = db.Storageable(pageList, "U9C")
-                                   .WhereColumns(t => new { t.ORDER_NO, t.GHOST_ROW })
-                                   .ToStorage();
-                            y.AsInsertable.ExecuteCommand();
-                            y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
-                        });
-                    }
-                    else
-                    {
-                        var s = db.Storageable(items, "U9C")
+                        var y = db.Storageable(pageList, "U9C")
                                .WhereColumns(t => new { t.ORDER_NO, t.GHOST_ROW })
                                .ToStorage();
-                        s.AsInsertable.ExecuteCommand();
-                        s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
-                    }
+                        y.AsInsertable.ExecuteCommand();
+                        y.AsUpdateable.IgnoreColumns(x => x.ID).UpdateColumns(q => new { q.ORDER_NO, q.ORDER_TYPE, q.PLAN_QTY, q.CUST_CODE, q.ITEM_CODE, q.CREATE_TIME, q.UPDATE_TIME, q.PLAN_START_TIME, q.STATUS, q.WS_CODE, q.AUTH_ORG, q.SALES_ORDER, q.SALES_REMARK, q.SERIAL_NO, q.SN_PREFIX, q.CUST_PREFIX, q.SALES_CONTRACT }).ExecuteCommand();
+                    });
                 }
-
-            });
-            if (!dbTran.IsSuccess)
-            {
-                action.CatchExceptionWithLog(dbTran.ErrorException, $"鏁版嵁澶勭悊澶辫触");
-                Logger.Scheduler.Error(action.Message);
+                else
+                {
+                    var s = db.Storageable(items, "U9C")
+                           .WhereColumns(t => new { t.ORDER_NO, t.GHOST_ROW })
+                           .ToStorage();
+                    s.AsInsertable.ExecuteCommand();
+                    s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                }
             }
+
+            //});
+            //if (!dbTran.IsSuccess)
+            //{
+            //    action.CatchExceptionWithLog(dbTran.ErrorException, $"鏁版嵁澶勭悊澶辫触");
+            //    Logger.Scheduler.Error(action.Message);
+            //}
             action.Message = $"宸ュ崟淇℃伅瀛樺叆鏁版嵁搴擄紝鎬绘暟锛歔{items.Count}]";
             Logger.Scheduler.Info($"{action.Message}");
             if (action.IsSuccessed && items.Count > 0)
@@ -635,7 +637,8 @@
                                 var rot = Biz.Db.Queryable<MES_PROD_OPER>()
                                 .GroupBy(x => new { x.PROD_CODE, x.ROT_ID })
                                 .Where(q => q.PROD_CODE == wo.ITEM_CODE)
-                                .Select(it => new {
+                                .Select(it => new
+                                {
                                     PROD_CODE = it.PROD_CODE,
                                     ROT_ID = it.ROT_ID
                                 })

--
Gitblit v1.9.3