From 6d2faa6e299bdfe545ee339269e64f2900229147 Mon Sep 17 00:00:00 2001
From: kazelee <1847801760@qq.com>
Date: 星期三, 16 七月 2025 17:29:26 +0800
Subject: [PATCH] 添加AGV实时状态反馈接口、看板获取AGV状态接口

---
 api/DebugController.cs |  169 +++++++++-----------------------------------------------
 1 files changed, 27 insertions(+), 142 deletions(-)

diff --git a/api/DebugController.cs b/api/DebugController.cs
index b59eb96..e2c950a 100644
--- a/api/DebugController.cs
+++ b/api/DebugController.cs
@@ -106,147 +106,26 @@
         /// <returns></returns>
         [HttpPost]
         [Route("CreateDatabase")]
-        public string CreateDatabase(CoverInfo model) {
+        public string CreateDatabase() {
             try {
                 var db = new SqlHelper<object>().GetInstance();
-                var cover = model.IsCover;
 
-                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),
+                var entityTypes = new Type[] { };
 
-                };
-
-                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();
-                }
-
+                //db.CodeFirst.InitTables(entityTypes);
             }
             catch (Exception ex) {
                 LogHelper.Info($"鍙戠敓浜嗗紓甯�);
                 return "鍒濆鍖栨暟鎹簱閿欒" + ex.Message;
             }
-
             return "鎴愬姛";
         }
 
         /// <summary>
-        /// DEBUG锛氭彃鍏ヨ揣浣嶃�瀹瑰櫒銆佽揣鍝佷俊鎭�+        /// DEBUG锛氭牴鎹换鍔″彿璁剧疆鐗╂枡閲嶉噺
         /// </summary>
+        /// <param name="model"></param>
         /// <returns></returns>
-        [HttpPost]
-        [Route("InsertLocCntrCg")]
-        public string InsertLocCntrCg(LocCntrCg locCntrCg) {
-            var db = new SqlHelper<object>().GetInstance();
-
-            try {
-                using (var tran = db.UseTran()) {
-                    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 ?? ""
-                        };
-
-                        if (db.Insertable<TN_Location>(newLoc).ExecuteCommand() <= 0) {
-                            tran.RollbackTran();
-                            LogHelper.Info($"鎻掑叆浣嶇疆{locCntrCg.LocCode}澶辫触");
-                            return "鎻掑叆澶辫触";
-                        }
-
-                        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)) {
-                        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 "鎻掑叆澶辫触";
-                        }
-                    }
-
-                    if (string.IsNullOrEmpty(locCntrCg.ItemCode)) {
-                        tran.CommitTran();
-                        LogHelper.Info("鐗╂枡鍙蜂负绌猴紝涓嶅啀璇诲彇鍚庨潰鐨勬暟鎹�);
-                        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();
-                }
-
-                return "鎻掑叆鏁版嵁鎴愬姛";
-
-            }
-            catch (Exception ex) {
-                return $"{ex.Message}";
-            }
-        }
-
         [HttpPost]
         [Route("SetTaskWeight")]
         public string SetTaskWeight(SetTaskWeightInfo model) {
@@ -258,16 +137,34 @@
                 return "鎵句笉鍒板搴旂殑鐗╂枡淇℃伅";
             }
 
+            var task = db.Queryable<TN_Task>()
+                .Where(t => t.S_CODE == model.TaskNo).First();
+
+            if (cgDetail == null) {
+                return "鎵句笉鍒板搴旂殑浠诲姟鍙�;
+            }
+
             cgDetail.F_QTY = model.Weight;
+            task.F_WEIGHT = model.Weight;
 
             try {
-                if (db.Updateable<TN_CG_Detail>(cgDetail).UpdateColumns(it => it.F_QTY)
+                using (var tran = db.Ado.UseTran()) {
+                    if (db.Updateable<TN_CG_Detail>(cgDetail).UpdateColumns(it => it.F_QTY)
                     .ExecuteCommand() <= 0) {
-                    return "淇敼澶辫触";
-                }
-                return "淇敼鎴愬姛";
+                        tran.RollbackTran();
+                        return "淇敼澶辫触";
+                    }
 
+                    if (db.Updateable<TN_Task>(task).UpdateColumns(it => it.F_WEIGHT).ExecuteCommand() <= 0) {
+                        tran.RollbackTran();
+                        return "淇敼澶辫触";
+                    }
+                    tran.CommitTran();
+                }
+                LogHelper.Info($"妯℃嫙AGV浼犻�鐗╂枡閲嶉噺锛氫慨鏀逛换鍔″彿{task.S_CODE}閲嶉噺涓簕model.Weight}", "HosttoagvTask");
+                return "淇敼鎴愬姛";
             }
+
             catch (Exception ex) {
 
                 return ex.Message;
@@ -281,14 +178,6 @@
 
     public class GzResults {
         public List<GzResult> GzResultList { set; get; }
-    }
-
-    public class LocCntrCg {
-        public string LocCode { get; set; }
-        public string LocArea { get; set; }
-        public string CntrCode { get; set; }
-        public string ItemCode { get; set; }
-        public string BatchNo { get; set; }
     }
 
     /// <summary>
@@ -307,10 +196,6 @@
         /// AGV 涓嬩竴涓姸鎬�         /// </summary>
         public int NextState { set; get; }
-    }
-
-    public class CoverInfo {
-        public bool IsCover { set; get; } = true;
     }
 
     public class SetTaskWeightInfo {

--
Gitblit v1.9.1