From ef839d119eec2c28fac5f5ba175d71f926afae44 Mon Sep 17 00:00:00 2001 From: kazelee <1847801760@qq.com> Date: 星期二, 20 五月 2025 11:49:22 +0800 Subject: [PATCH] 修复数据库表字段不匹配、读取重量错误处理等逻辑 --- Services/DebugService.cs | 159 ++++++++++++++++++++++++---------------------------- 1 files changed, 74 insertions(+), 85 deletions(-) diff --git a/Services/DebugService.cs b/Services/DebugService.cs index 4684196..63be575 100644 --- a/Services/DebugService.cs +++ b/Services/DebugService.cs @@ -125,98 +125,82 @@ return "鎴愬姛"; } - public static string InsertLocCntrCg() { - string filePath = PathHelper.GetProjDir("./debug/loc_cntr_cg.csv"); + public static string InsertLocCntrCg(LocCntrCg locCntrCg) { var db = DbHelper.GetDbClient(); try { - var configuration = new CsvConfiguration(CultureInfo.InvariantCulture) { - // 閰嶇疆閫夐」 - Delimiter = ",", // 鍒嗛殧绗�- HasHeaderRecord = true, // 鏈夋爣棰樿 - MissingFieldFound = null, // 蹇界暐缂哄け瀛楁 - HeaderValidated = null, // 璺宠繃鏍囬楠岃瘉 - BadDataFound = context => { } // 澶勭悊閿欒鏁版嵁 - }; - - var locCntrCgList = new List<LocCntrCg>(); - - using (var reader = new StreamReader(filePath)) - using (var csv = new CsvReader(reader, configuration)) { - // 璇诲彇璁板綍 - locCntrCgList = csv.GetRecords<LocCntrCg>().ToList(); - } - using (var tran = db.UseTran()) { - foreach (var locCntrCg in locCntrCgList) { - LogHelper.Info("LogCntrCg锛� + JsonConvert.SerializeObject(locCntrCg)); - if (string.IsNullOrEmpty(locCntrCg.LocCode)) break; + LogHelper.Info("LogCntrCg锛� + JsonConvert.SerializeObject(locCntrCg)); + if (string.IsNullOrEmpty(locCntrCg.LocCode)) { + return "鍙傛暟闈炴硶"; + } - var loc = db.Queryable<TN_Location>().First(a => a.S_CODE == locCntrCg.LocCode); - if (loc == null) { - var newLoc = new TN_Location { - S_CODE = locCntrCg.LocCode, - S_AREA_CODE = locCntrCg.LocArea ?? "" - }; + var loc = db.Queryable<TN_Location>().First(a => a.S_CODE == locCntrCg.LocCode); + if (loc == null) { + var newLoc = new TN_Location { + S_CODE = locCntrCg.LocCode, + S_AREA_CODE = locCntrCg.LocArea ?? "" + }; - if (db.Insertable<TN_Location>(newLoc).ExecuteCommand() <= 0) { - tran.RollbackTran(); - LogHelper.Info($"鎻掑叆浣嶇疆{locCntrCg.LocCode}澶辫触"); - return "鎻掑叆澶辫触"; - } - - loc = newLoc; + if (db.Insertable<TN_Location>(newLoc).ExecuteCommand() <= 0) { + tran.RollbackTran(); + LogHelper.Info($"鎻掑叆浣嶇疆{locCntrCg.LocCode}澶辫触"); + return "鎻掑叆澶辫触"; } - //if (loc.N_CURRENT_NUM == 0) { - // loc.N_CURRENT_NUM = 1; - // if (db.Updateable<TN_Location>(loc).UpdateColumns( - // it => new { it.N_CURRENT_NUM, it.T_MODIFY }).ExecuteCommand() <= 0) { - // tran.RollbackTran(); - // LogHelper.Info($"淇敼浣嶇疆{locCntrCg.LocCode}澶辫触"); - // continue; - // } - //} + loc = newLoc; + } - if (string.IsNullOrEmpty(locCntrCg.CntrCode)) { - LogHelper.Info("瀹瑰櫒鍙蜂负绌猴紝涓嶅啀璇诲彇鍚庨潰鐨勬暟鎹�); - continue; + //if (loc.N_CURRENT_NUM == 0) { + // loc.N_CURRENT_NUM = 1; + // if (db.Updateable<TN_Location>(loc).UpdateColumns( + // it => new { it.N_CURRENT_NUM, it.T_MODIFY }).ExecuteCommand() <= 0) { + // tran.RollbackTran(); + // LogHelper.Info($"淇敼浣嶇疆{locCntrCg.LocCode}澶辫触"); + // continue; + // } + //} + + if (string.IsNullOrEmpty(locCntrCg.CntrCode)) { + tran.CommitTran(); + LogHelper.Info("瀹瑰櫒鍙蜂负绌猴紝涓嶅啀璇诲彇鍚庨潰鐨勬暟鎹�); + return "瀹瑰櫒鍙蜂负绌猴紝涓嶅啀璇诲彇鍚庨潰鐨勬暟鎹�; + } + + var locCntrRel = db.Queryable<TN_Loc_Container>().First(a => a.S_LOC_CODE == locCntrCg.LocCode + && a.S_CNTR_CODE == locCntrCg.CntrCode); + + if (locCntrRel == null) { + var newLocCntrRel = new TN_Loc_Container { + S_LOC_CODE = locCntrCg.LocCode, + S_CNTR_CODE = locCntrCg.CntrCode + }; + + loc.N_CURRENT_NUM = 1; + + if (db.Insertable<TN_Loc_Container>(newLocCntrRel).ExecuteCommand() <= 0 + && db.Updateable<TN_Location>(loc).UpdateColumns(c => c.N_CURRENT_NUM).ExecuteCommand() <= 0) { + tran.RollbackTran(); + LogHelper.Info($"鎻掑叆浣嶇疆鎵樼洏鍏崇郴{locCntrCg.LocCode}-{locCntrCg.CntrCode}澶辫触"); + return "鎻掑叆澶辫触"; } + } - var locCntrRel = db.Queryable<TN_Loc_Container>().First(a => a.S_LOC_CODE == locCntrCg.LocCode - && a.S_CNTR_CODE == locCntrCg.CntrCode); + if (string.IsNullOrEmpty(locCntrCg.ItemCode)) { + tran.CommitTran(); + LogHelper.Info("鐗╂枡鍙蜂负绌猴紝涓嶅啀璇诲彇鍚庨潰鐨勬暟鎹�); + return "鐗╂枡鍙蜂负绌猴紝涓嶅啀璇诲彇鍚庨潰鐨勬暟鎹�; + } - if (locCntrRel == null) { - var newLocCntrRel = new TN_Loc_Container { - S_LOC_CODE = locCntrCg.LocCode, - S_CNTR_CODE = locCntrCg.CntrCode - }; - - loc.N_CURRENT_NUM = 1; - - if (db.Insertable<TN_Loc_Container>(newLocCntrRel).ExecuteCommand() <= 0 - && db.Updateable<TN_Location>(loc).UpdateColumns(c => c.N_CURRENT_NUM).ExecuteCommand() <= 0) { - tran.RollbackTran(); - LogHelper.Info($"鎻掑叆浣嶇疆鎵樼洏鍏崇郴{locCntrCg.LocCode}-{locCntrCg.CntrCode}澶辫触"); - return "鎻掑叆澶辫触"; - } - } - - if (string.IsNullOrEmpty(locCntrCg.ItemCode)) { - LogHelper.Info("鐗╂枡鍙蜂负绌猴紝涓嶅啀璇诲彇鍚庨潰鐨勬暟鎹�); - continue; - } - - var cgDetail = db.Queryable<TN_CG_Detail>().First(a => a.S_CNTR_CODE == locCntrCg.CntrCode - && a.S_ITEM_CODE == locCntrCg.ItemCode); - if (cgDetail == null) { - var locList = new List<TN_CG_Detail>(); - locList.Add(new TN_CG_Detail { S_CNTR_CODE = locCntrCg.CntrCode, S_ITEM_CODE = locCntrCg.ItemCode, S_BATCH_NO = locCntrCg.BatchNo ?? "" }); - if (db.Insertable<TN_CG_Detail>(locList).ExecuteCommand() <= 0) { - tran.RollbackTran(); - LogHelper.Info($"鎻掑叆鎵樼洏鐗╂枡鍏崇郴{locCntrCg.CntrCode}-{locCntrCg}澶辫触"); - return "鎻掑叆澶辫触"; - } + var cgDetail = db.Queryable<TN_CG_Detail>().First(a => a.S_CNTR_CODE == locCntrCg.CntrCode + && a.S_ITEM_CODE == locCntrCg.ItemCode); + if (cgDetail == null) { + var locList = new List<TN_CG_Detail>(); + locList.Add(new TN_CG_Detail { S_CNTR_CODE = locCntrCg.CntrCode, S_ITEM_CODE = locCntrCg.ItemCode, S_BATCH_NO = locCntrCg.BatchNo ?? "" }); + if (db.Insertable<TN_CG_Detail>(locList).ExecuteCommand() <= 0) { + tran.RollbackTran(); + LogHelper.Info($"鎻掑叆鎵樼洏鐗╂枡鍏崇郴{locCntrCg.CntrCode}-{locCntrCg}澶辫触"); + return "鎻掑叆澶辫触"; } } tran.CommitTran(); @@ -225,19 +209,24 @@ return "鎻掑叆鏁版嵁鎴愬姛"; } - catch (FileNotFoundException) { - return $"Error: File not found - {filePath}"; - } catch (Exception ex) { - return $"Error reading CSV file: {ex.Message}"; + return $"{ex.Message}"; } } public static string SetTaskWeight(SetTaskWeightInfo model) { var db = DbHelper.GetDbClient(); + var cgDetail = db.Queryable<TN_CG_Detail, TN_Task>((d, t) => d.S_CNTR_CODE == t.S_CNTR_CODE) + .Where((d, t) => t.S_CODE == model.TaskNo).First(); + + if (cgDetail == null) { + return "鎵句笉鍒板搴旂殑鐗╂枡淇℃伅"; + } + + cgDetail.F_QTY = model.Weight; try { - if (db.Updateable<TN_Task>().SetColumns(it => it.F_WEIGHT == model.Weight).Where(it => it.S_CODE == model.TaskNo) + if (db.Updateable<TN_CG_Detail>(cgDetail).UpdateColumns(it => it.F_QTY) .ExecuteCommand() <= 0 ) { return "淇敼澶辫触"; } -- Gitblit v1.9.1