From 531f16f2f15bf792e3e719e00abb57a95356dedd Mon Sep 17 00:00:00 2001 From: Rodney Chen <rodney.chen@hotmail.com> Date: 星期一, 21 四月 2025 12:04:15 +0800 Subject: [PATCH] Merge branch 'master' of http://47.115.28.255:8110/r/TigerClouds-Tech/Server/TigerApi6_2024 --- Tiger.Business.MES/iERP/U9C_MES.cs | 295 +++++++++++++++++++++++----------------------------------- 1 files changed, 118 insertions(+), 177 deletions(-) diff --git a/Tiger.Business.MES/iERP/U9C_MES.cs b/Tiger.Business.MES/iERP/U9C_MES.cs index 7c8579c..c10ace7 100644 --- a/Tiger.Business.MES/iERP/U9C_MES.cs +++ b/Tiger.Business.MES/iERP/U9C_MES.cs @@ -17,6 +17,7 @@ using Apache.NMS.ActiveMQ.Commands; using System.Security.Cryptography; using System.Diagnostics; +using Tiger.Model.MES.Yada; namespace Tiger.Business.MES { @@ -27,14 +28,14 @@ /// </summary> /// <param name="input"></param> /// <returns></returns> - public ApiAction GetBasItem(U9C_MES_Input input) + public ApiAction GetBasItem(U9C_Base_Input input) { var action = new ApiAction(); + var db = Biz.Db; Logger.Scheduler.Info($"鐗╂枡淇℃伅寮�濮嬪悓姝ャ�傘�傘�傛暟鎹鏌ヨ繘琛屼腑銆傘�傘��"); Logger.Scheduler.Info($"{input.triggerDetail}"); - DbClient db = Biz.DataSource["YadaU9C"].Client; - var list = db.Queryable<dynamic>().AS("mes_ItemMaster").Where("ModifiedOn > @startTime And ModifiedOn < @endTime", new { startTime = input.startTime, endTime = input.endTime }).ToList(); - var orgs = Biz.Db.Queryable<SYS_ORGANIZATION>().ToList(); + var list = Biz.DataSource["YadaU9C"].Client.Queryable<dynamic>().AS("mes_ItemMaster").Where("ModifiedOn > @startTime And ModifiedOn < @endTime", new { startTime = input.startTime, endTime = input.endTime }).ToList(); + var orgs = db.Queryable<SYS_ORGANIZATION>().ToList(); List<BAS_ITEM> items = new(); var itemExts = new List<BAS_ITEM_EXT>(); if (list != null && list.Count > 0) @@ -64,7 +65,15 @@ AUTH_ORG = orgs.Where(x => x.ID == orgId).Select(q => q.ORG_CODE).FirstOrDefault(), CUST_PROD_CODE = di["CustomerItem"] == null ? "" : di["CustomerItem"].ToString(), RULE_CODE = di["BarRule"] == null ? "" : di["BarRule"].ToString(), + DEFAULT_LOCATION = di["BinCode"] == null ? "" : di["BinCode"].ToString(), }; + var whUnit = db.Queryable<V_WH_UNIT>().Where(t => t.LOCATION_CODE == basItem.DEFAULT_LOCATION && t.AUTH_ORG == basItem.AUTH_ORG).First(); + if (!whUnit.IsNullOrEmpty()) + { + basItem.DEFAULT_WH = whUnit.WH_CODE; + basItem.DEFAULT_REGION = whUnit.REGION_CODE; + basItem.DEFAULT_SHELF = whUnit.SHELF_CODE; + } items.Add(basItem); var extInfo = new BAS_ITEM_EXT() { @@ -79,64 +88,44 @@ Remark = (di["Remark"] ?? "").ToString(), Packaging = (di["Packaging"] ?? "").ToString(), SapCode = (di["Code1"] ?? "").ToString(), + ReceiptMode = (di["ReceiptMode"] ?? "").ToInt32(), }; itemExts.Add(extInfo); } } } Logger.Scheduler.Info($"鐗╂枡淇℃伅瀛樺叆瀹炰綋涓紝鎬绘暟锛歔{items.Count}]"); - db = Biz.Db; - var dbTran = db.UseTran(() => + + //var dbTran = db.UseTran(() => + //{ + if (items.Any()) { - if (items.Any()) + db.Utilities.PageEach(items, 100, pageList => { - if (items.Count > 100) - { - 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(); - y.AsInsertable.ExecuteCommand(); - y.AsUpdateable.ExecuteCommand(); - } - } - 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); + var y = db.Storageable(pageList, "U9C") + .WhereColumns(t => new { t.ID, t.GHOST_ROW }) + .ToStorage(); + y.AsInsertable.ExecuteCommand(); + y.AsUpdateable.ExecuteCommand(); + }); } + if (itemExts.Any()) + { + 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(); + }); + } + //}); + //if (!dbTran.IsSuccess) + //{ + // action.CatchExceptionWithLog(dbTran.ErrorException, $"鏁版嵁澶勭悊澶辫触"); + // Logger.Scheduler.Error(action.Message); + //} Logger.Scheduler.Info($"鐗╂枡淇℃伅瀛樺叆鏁版嵁搴擄紝鎬绘暟锛歔{items.Count}]"); action.Message = $"鐗╂枡淇℃伅瀛樺叆鏁版嵁搴擄紝鎬绘暟锛歔{items.Count}]"; return action; @@ -208,25 +197,14 @@ db.Storageable(LastRun, "U9C_MES_GetWo").ExecuteCommand(); if (items.Any()) { - 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).ExecuteCommand(); + }); } }); @@ -243,15 +221,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 }) @@ -304,7 +285,7 @@ /// <param name="input"></param> /// <returns></returns> /// <exception cref="NotImplementedException"></exception> - public ApiAction GetCustomer(U9C_MES_Input input) + public ApiAction GetCustomer(U9C_Base_Input input) { var action = new ApiAction(); Logger.Scheduler.Info($"瀹㈡埛淇℃伅寮�濮嬪悓姝ャ�傘�傘�傛暟鎹鏌ヨ繘琛屼腑銆傘�傘��"); @@ -340,37 +321,26 @@ } 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); + 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(); + }); } + + // }); + //if (!dbTran.IsSuccess) + //{ + // action.CatchExceptionWithLog(dbTran.ErrorException, $"鏁版嵁澶勭悊澶辫触"); + // Logger.Scheduler.Error(action.Message); + //} Logger.Scheduler.Info($"瀹㈡埛淇℃伅瀛樺叆鏁版嵁搴擄紝鎬绘暟锛歔{items.Count}]"); action.Message = $"瀹㈡埛淇℃伅瀛樺叆鏁版嵁搴擄紝鎬绘暟锛歔{items.Count}]"; return action; @@ -381,7 +351,7 @@ /// </summary> /// <param name="input"></param> /// <returns></returns> - public ApiAction GetSupplier(U9C_MES_Input input) + public ApiAction GetSupplier(U9C_Base_Input input) { var action = new ApiAction(); Logger.Scheduler.Info($"渚涘簲鍟嗕俊鎭紑濮嬪悓姝ャ�傘�傘�傛暟鎹鏌ヨ繘琛屼腑銆傘�傘��"); @@ -414,37 +384,26 @@ } Logger.Scheduler.Info($"渚涘簲鍟嗕俊鎭瓨鍏ュ疄浣撲腑锛屾�绘暟锛歔{items.Count}]"); db = Biz.Db; - var dbTran = db.UseTran(() => + //var dbTran = db.UseTran(() => + // { + if (items.Any()) { - if (items.Any()) + db.Utilities.PageEach(items, 100, pageList => { - if (items.Count > 100) - { - 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") - .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); + 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(); + }); } + + //}); + //if (!dbTran.IsSuccess) + //{ + // action.CatchExceptionWithLog(dbTran.ErrorException, $"鏁版嵁澶勭悊澶辫触"); + // Logger.Scheduler.Error(action.Message); + //} Logger.Scheduler.Info($"渚涘簲鍟嗕俊鎭瓨鍏ユ暟鎹簱锛屾�绘暟锛歔{items.Count}]"); action.Message = $"渚涘簲鍟嗕俊鎭瓨鍏ユ暟鎹簱锛屾�绘暟锛歔{items.Count}]"; return action; @@ -455,7 +414,7 @@ /// </summary> /// <param name="input"></param> /// <returns></returns> - public ApiAction GetCustBarCode(U9C_MES_Input input) + public ApiAction GetCustBarCode(U9C_Base_Input input) { var action = new ApiAction(); Logger.Scheduler.Info($"瀹㈡埛鏉$爜淇℃伅寮�濮嬪悓姝ャ�傘�傘�傛暟鎹鏌ヨ繘琛屼腑銆傘�傘��"); @@ -465,6 +424,7 @@ List<MES_CUST_SN> items = new(); if (list != null && list.Count > 0) { + Logger.Scheduler.Info($"鑾峰彇瀹㈡埛鏉$爜淇℃伅锛歔{list.ToJson()}]"); foreach (var item in list) { var d = item as System.Dynamic.ExpandoObject; @@ -485,6 +445,7 @@ CREATE_TIME = di["CreatedOn"].ToDateTime(), UPDATE_TIME = di["ModifiedOn"].ToDateTime(), AUTH_ORG = _MES_WO?.AUTH_ORG, + CREATE_USER = "U9C" //鍚屾椂缁機REATE_USER鍜孋REATE_TIME璧嬪�硷紝鍒欎笉浼氳鏇存柊锛屼繚鐣欐墍璧嬬殑鍊� }; items.Add(snItem); } @@ -495,28 +456,17 @@ db = Biz.Db; //var dbTran = db.UseTran(() => //{ - if (items.Any()) + if (items.Any()) + { + db.Utilities.PageEach(items, 100, pageList => { - 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).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(); - }); - } - 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(); - } - } + 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.UPDATE_TIME, q.UPDATE_USER, q.AUTH_ORG }).ExecuteCommand(); + }); + } //}); //if (!dbTran.IsSuccess) @@ -529,7 +479,7 @@ return action; } - public ApiAction GetU9CBasWo(U9C_MES_Input input) + public ApiAction GetU9CBasWo(U9C_Base_Input input) { var action = new ApiAction(); Logger.Scheduler.Info($"宸ュ崟淇℃伅寮�濮嬪悓姝ャ�傘�傘�傛暟鎹鏌ヨ繘琛屼腑銆傘�傘��"); @@ -561,6 +511,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(), @@ -585,28 +536,17 @@ db = Biz.Db; //var dbTran = db.UseTran(() => //{ - if (items.Any()) + if (items.Any()) + { + db.Utilities.PageEach(items, 100, pageList => { - if (items.Count > 100) - { - 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") - .WhereColumns(t => new { t.ORDER_NO, t.GHOST_ROW }) - .ToStorage(); - s.AsInsertable.ExecuteCommand(); - s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); - } - } + 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).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) @@ -632,7 +572,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