From b079910e5de15863c26e479ffab15cc45d706f1a Mon Sep 17 00:00:00 2001
From: kazelee <1847801760@qq.com>
Date: 星期一, 19 五月 2025 16:25:22 +0800
Subject: [PATCH] 测试修复轮询出库、抽检流程的问题

---
 Services/DebugService.cs |  117 ++++++++++++++++++++++++----------------------------------
 1 files changed, 48 insertions(+), 69 deletions(-)

diff --git a/Services/DebugService.cs b/Services/DebugService.cs
index 71d3d88..8537315 100644
--- a/Services/DebugService.cs
+++ b/Services/DebugService.cs
@@ -7,6 +7,7 @@
 using CsvHelper;
 using CsvHelper.Configuration;
 
+using HH.WCS.Mobox3.DSZSH.Helper;
 using HH.WCS.Mobox3.DSZSH.Helpers;
 using HH.WCS.Mobox3.DSZSH.Models;
 
@@ -53,50 +54,75 @@
             }
 
             var agvTaskState = new AgvTaskState() {
-                TaskNo = model.TaskID,
-                ForkliftNo = model.ForkliftNo,
+                task_no = model.TaskID,
+                forklift_no = model.ForkliftNo,
             };
 
             var result = new ReturnResult();
 
             // 褰撳墠鐘舵�娌℃湁杈惧埌鏈�粓鐘舵�鏃讹紝寰幆鍔犲叆杩斿洖鍒楄〃
             while (agvCurrentState != model.NextState) {
-                agvTaskState.State = agvCurrentState;
+                agvTaskState.state = agvCurrentState;
                 result = AgvService.OperateAgvTaskStatus(agvTaskState);
                 returnResults.ResultList.Add(result);
                 agvCurrentState = AgvHelper.GetNextState(agvCurrentState);
             }
 
             // 灏嗗惊鐜病鏈夊埌杈剧殑鏈�粓鐘舵�锛屼篃鍔犲叆杩斿洖鍒楄〃
-            agvTaskState.State = model.NextState;
+            agvTaskState.state = model.NextState;
             result = AgvService.OperateAgvTaskStatus(agvTaskState);
             returnResults.ResultList.Add(result);
 
             return returnResults;
         }
 
-
         /// <summary>
         /// 鍒濆鏁版嵁搴撳缓绔�         /// </summary>
         /// <returns></returns>
-        public static string CreateDatabase() {
+        public static string CreateDatabase(bool cover = false) {
             try {
                 var db = DbHelper.GetDbClient();
 
-                //db.CodeFirst.InitTables<TN_CG_Detail>();
-                //db.CodeFirst.InitTables<TN_WorkOrder>();
-                //db.CodeFirst.InitTables<TN_CAR_IN>();
-                ////db.CodeFirst.InitTables<SYSHelper.OI_SYS_MAXID>();
-                //db.CodeFirst.InitTables<TN_Task_Action>();
-                //db.CodeFirst.InitTables<TN_Task>();
-                //db.CodeFirst.InitTables<TN_Location>();
-                //db.CodeFirst.InitTables<TN_Loc_Container>();
+                var entityTypes = new Type[] { 
+                    //typeof(TN_CAR_IN),
+                    //typeof(TN_CG_Detail),
+                    //typeof(TN_Container),
+                    //typeof(TN_Loc_Container),
+                    //typeof(TN_Location),
+                    //typeof(TN_Task),
+                    //typeof(TN_Task_Action),
+                    //typeof(SysHelper.OI_SYS_MAXID),
 
-                //db.CodeFirst.InitTables<TN_Outbound_Order>();
-                //db.CodeFirst.InitTables<TN_Outbound_Detail>();
-                //db.CodeFirst.InitTables<TN_Check_Order>();
-                db.CodeFirst.InitTables<TN_Check_Detail>();
+                    //typeof(TN_Inbound_Order),
+                    typeof(TN_Check_Detail),
+                    //typeof(TN_Check_Order),
+                    //typeof(TN_CNTR_ITEM),
+                    //typeof(TN_Outbound_Detail),
+                    //typeof(TN_Outbound_Order),
+                    //typeof(TN_Shift_Order),
+                    //typeof(TN_Shift_Detail)
+                };
+
+                using (var tran = db.Ado.UseTran()) {
+                    if (cover) {
+                        // 鍒犻櫎鎵�湁琛紙鎸変緷璧栧叧绯诲�搴忥級
+                        //var tables = db.DbMaintenance.GetTableInfoList();
+                        //foreach (var table in tables.OrderByDescending(t => t.Name)) {
+                        //    db.DbMaintenance.DropTable(table.Name);
+                        //}
+
+                        // 鍒涘缓鏂拌〃
+                        db.CodeFirst.InitTables(entityTypes);
+
+                        //db.CodeFirst.BackupTable().InitTables(entityTypes);
+                    }
+                    else {
+                        db.CodeFirst.InitTables(entityTypes);
+                    }
+
+                    tran.CommitTran();
+                }
 
             }
             catch (Exception ex) {
@@ -150,16 +176,6 @@
                             loc = newLoc;
                         }
 
-                        //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)) {
                             LogHelper.Info("瀹瑰櫒鍙蜂负绌猴紝涓嶅啀璇诲彇鍚庨潰鐨勬暟鎹�);
                             continue;
@@ -185,23 +201,23 @@
                             }
                         }
 
-                        if (string.IsNullOrEmpty(locCntrCg.CgId)) {
+                        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_CG_ID == locCntrCg.CgId);
+                            && 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_CG_ID = locCntrCg.CgId, S_BATCH_NO = locCntrCg.BatchNo ?? "" });
+                            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();
                 }
 
@@ -215,42 +231,5 @@
                 return $"Error reading CSV file: {ex.Message}";
             }
         }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <returns></returns>
-        //public string InsertOutboundOrder() {
-        //    string filePath = PathHelper.GetProjDir("./debug/outbound_order.csv");
-        //    var db = DbHelper.GetDbClient();
-
-        //    try {
-        //        var configuration = new CsvConfiguration(CultureInfo.InvariantCulture) {
-        //            // 閰嶇疆閫夐」
-        //            Delimiter = ",",               // 鍒嗛殧绗�-        //            HasHeaderRecord = true,        // 鏈夋爣棰樿
-        //            MissingFieldFound = null,      // 蹇界暐缂哄け瀛楁
-        //            HeaderValidated = null,        // 璺宠繃鏍囬楠岃瘉
-        //            BadDataFound = context => { }  // 澶勭悊閿欒鏁版嵁
-        //        };
-
-        //        var locCntrCgList = new List<DebugModel.OutboundOrder>();
-
-        //        using (var reader = new StreamReader(filePath))
-        //        using (var csv = new CsvReader(reader, configuration)) {
-        //            // 璇诲彇璁板綍
-        //            locCntrCgList = csv.GetRecords<DebugModel.OutboundOrder>().ToList();
-        //        }
-
-        //        using (var tran = db.Ado.UseTran()) {
-                    
-        //        }
-
-        //    }
-        //    catch (Exception) {
-
-        //        throw;
-        //    }
-        //}
     }
 }

--
Gitblit v1.9.1