From c4e968254a4f1c5d538a9fd91284b4843ea08198 Mon Sep 17 00:00:00 2001
From: kazelee <1847801760@qq.com>
Date: 星期五, 23 五月 2025 10:44:58 +0800
Subject: [PATCH] 内部联调,修复问题,添加取消任务功能

---
 api/ApiHelper.cs |  123 +++++++++++++++++++++++++++++++++++-----
 1 files changed, 107 insertions(+), 16 deletions(-)

diff --git a/api/ApiHelper.cs b/api/ApiHelper.cs
index cce68d9..e01d92b 100644
--- a/api/ApiHelper.cs
+++ b/api/ApiHelper.cs
@@ -31,7 +31,7 @@
                     .First();
 
                 if (startLoc == null) {
-                    return BuildSimpleResult(1, $"璧风偣浣嶇疆{model.StartLoc}涓嶅瓨鍦紒");
+                    return BuildSimpleResult(1, $"璧风偣浣嶇疆{model.StartLoc}涓嶅瓨鍦ㄦ垨涓嶆弧瓒宠姹傦細闇�锛�锛夋病鏈夐攣鐘舵�锛�锛夊綋鍓嶆棤瀹瑰櫒锛�锛夊睘浜庡彇鏀捐揣鍖�);
                 }
 
                 // 瀹瑰櫒 ID 鍜�鐗╂枡 ID 鏈寚瀹氾紝鐢辩郴缁熺洿鎺ョ敓鎴�@@ -45,6 +45,7 @@
                     S_LOC_CODE = startLoc.S_CODE,
                     S_CNTR_CODE = cntId,
                 };
+
                 var cgDetail = new TN_CG_Detail() {
                     S_ITEM_CODE = cgId,
                     S_CNTR_CODE = cntId,
@@ -65,7 +66,7 @@
                 }
 
                 var task = WCSHelper.BuildInboundTask(startLoc, endLocCode, cntId);
-                LocationHelper.LockLoc(ref startLoc, 1); // 璧风偣鍑哄簱閿�+                LocationHelper.LockLoc(ref startLoc, 2); // 璧风偣鍑哄簱閿� 
                 // 鏃犺鏄惁閫夋嫨缁堢偣璐ф灦锛岄兘绛夊埌绉伴噸涔嬪悗鍐嶈绠楃粓鐐硅揣浣�                 using (var tran = db.Ado.UseTran()) {
@@ -122,6 +123,7 @@
             try {
                 // 浠诲姟鍙峰瓨鍦細缁堢偣璐ф灦鍜岀粓鐐逛綅缃负绌猴紝涓斾换鍔′负浜у搧鍏ュ簱(PDA)
                 var task = db.Queryable<TN_Task>()
+                    .Where(a => a.S_CODE == model.TaskNo)
                     .Where(a => a.S_B_STATE == "鍙栬揣瀹屾垚" && a.S_TYPE == TaskName.浜у搧鍏ュ簱)
                     .OrderBy(a => a.T_CREATE, SqlSugar.OrderByType.Desc).First();
 
@@ -141,22 +143,27 @@
                 }
 
                 var endLoc = new TN_Location();
-                if (cgDetail.F_QTY > 1500) {
-                    // 閲嶉噺瓒呰繃1.5t锛岄渶瑕侀�鎷�-3灞傝揣鏋�+                if (cgDetail.F_QTY > 2000) {
+                    // 閲嶉噺瓒呰繃2t锛屾姤閿�+                    return BuildSimpleResult(8, $"鐗╂枡閲嶉噺{cgDetail.F_QTY}瓒呰繃2t");
+                }
+                else if (cgDetail.F_QTY > 1500) {
+                    // 閲嶉噺瓒呰繃1.5t锛岄渶瑕侀�鎷�-2灞傝揣鏋�                     endLoc = db.Queryable<TN_Location>()
-                        .Where(a => a.S_CODE == model.endLoc)
+                        .Where(a => a.S_CODE == model.EndLoc)
                         .Where(a => a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "鏃� && a.C_ENABLE == "Y")
                         .Where(a => a.N_CURRENT_NUM == 0)
                         .Where(a => Settings.Areas[1].Contains(a.S_AREA_CODE))
-                        .Where(a => a.N_LAYER <= 3)
+                        .Where(a => a.N_LAYER <= 2)
                         .First();
                 }
                 else if (cgDetail.F_QTY > 0) {
                     endLoc = db.Queryable<TN_Location>()
-                        .Where(a => a.S_CODE == model.endLoc)
+                        .Where(a => a.S_CODE == model.EndLoc)
                         .Where(a => a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "鏃� && a.C_ENABLE == "Y")
                         .Where(a => a.N_CURRENT_NUM == 0)
                         .Where(a => Settings.Areas[1].Contains(a.S_AREA_CODE))
+                        .OrderBy(a => a.N_LAYER > 2 ? 0 : 1) // 浼樺厛鍙栧ぇ浜�鐨�                         //.Where(a => a.N_LAYER <= 3)
                         .First();
                 }
@@ -166,7 +173,7 @@
 
                 // 娌℃湁绗﹀悎鏉′欢鐨勮揣浣�                 if (endLoc == null) {
-                    return BuildSimpleResult(6, $"璐т綅{model.endLoc}涓嶅瓨鍦紝鎴栦笉婊¤冻绉伴噸鏀剧疆瑕佹眰");
+                    return BuildSimpleResult(6, $"璐т綅{model.EndLoc}涓嶅瓨鍦紝鎴栦笉婊¤冻绉伴噸鏀剧疆瑕佹眰");
                 }
 
                 // 淇敼浠诲姟缁堢偣涓篜DA鎸囧畾缁堢偣
@@ -230,8 +237,8 @@
                 var cntId = locCntrRel.S_CNTR_CODE;
                 var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskName);
 
-                LocationHelper.LockLoc(ref startLoc, 1); // 璧风偣鍑哄簱閿�-                LocationHelper.LockLoc(ref endLoc, 2); // 缁堢偣鍏ュ簱閿�+                LocationHelper.LockLoc(ref startLoc, 2); // 璧风偣鍑哄簱閿�+                LocationHelper.LockLoc(ref endLoc, 1); // 缁堢偣鍏ュ簱閿� 
                 using (var tran = db.Ado.UseTran()) {
                     if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new {
@@ -294,8 +301,8 @@
 
                 var cntId = locCntrRel.S_CNTR_CODE;
                 var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskName);
-                LocationHelper.LockLoc(ref startLoc, 1); // 璧风偣鍑哄簱閿�-                LocationHelper.LockLoc(ref endLoc, 2); // 缁堢偣鍏ュ簱閿�+                LocationHelper.LockLoc(ref startLoc, 2); // 璧风偣鍑哄簱閿�+                LocationHelper.LockLoc(ref endLoc, 1); // 缁堢偣鍏ュ簱閿� 
                 using (var tran = db.Ado.UseTran()) {
                     if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new {
@@ -322,6 +329,90 @@
                     return BuildSimpleResult(0,
                         $"鐢熸垚 {taskName} 鎴愬姛锛屽鍣ㄥ彿 {cntId} 锛岃捣鐐�{startLoc.S_CODE} 锛岀粓鐐硅揣鏋�{endLoc.S_CODE}");
                 }
+            }
+            catch (Exception ex) {
+                return BuildSimpleResult(1, $"鍙戠敓浜嗗紓甯革細{ex.Message}");
+            }
+        }
+
+        public static SimpleResult CancelTask(CancelTaskInfo model) {
+            var db = new SqlHelper<object>().GetInstance();
+            var info = "";
+            try {
+                var task = db.Queryable<TN_Task>()
+                    .Where(a => a.S_CODE == model.TaskNo)
+                    .First();
+
+                if (task == null) {
+                    return BuildSimpleResult(2, $"浠诲姟鍙穥model.TaskNo}涓嶅瓨鍦�);
+                }
+
+                if (task.N_B_STATE == 0 && task.S_B_STATE == TN_Task.GetStateStr(0)
+                    || task.N_B_STATE == 1 && task.S_B_STATE == TN_Task.GetStateStr(1)) {
+
+                    task.N_B_STATE = 4;
+                    task.S_B_STATE = "鍙栨秷";
+
+                    var starloc = db.Queryable<TN_Location>().First(a => a.S_CODE == task.S_START_LOC);
+                    var endloc = db.Queryable<TN_Location>().First(a => a.S_CODE == task.S_END_LOC);
+                    //var locCnt = db.Queryable<TN_Loc_Container>().First(a => a.S_CNTR_CODE == task.S_CNTR_CODE);
+                    //var cg = db.Queryable<TN_CG_Detail>().First(a => a.S_CNTR_CODE == task.S_CNTR_CODE);
+
+                    if (starloc != null) {
+                        starloc.N_LOCK_STATE = 0;
+                        starloc.S_LOCK_STATE = "鏃�;
+                        //starloc.N_CURRENT_NUM = 0;
+                        starloc.T_MODIFY = System.DateTime.Now;
+                    }
+
+                    if (endloc != null) {
+                        endloc.N_LOCK_STATE = 0;
+                        endloc.S_LOCK_STATE = "鏃�;
+                        //endloc.N_CURRENT_NUM = 0;
+                        endloc.T_MODIFY = System.DateTime.Now;
+                    }
+
+                    using (var tran = db.Ado.UseTran()) {
+                        if (db.Updateable<TN_Location>(starloc).ExecuteCommand() <= 0) {
+                            tran.RollbackTran();
+
+                            info = $"浠诲姟{task.S_CODE}鍙栨秷澶辫触";
+
+                            return BuildSimpleResult(0, info);
+                        }
+
+                        if (endloc != null) {
+                            if (db.Updateable<TN_Location>(endloc).ExecuteCommand() <= 0) {
+                                tran.RollbackTran();
+
+                                info = $"浠诲姟{task.S_CODE}鍙栨秷澶辫触";
+
+                                return BuildSimpleResult(0, info);
+                            }
+                        }
+
+                        if (db.Updateable<TN_Task>(task).ExecuteCommand() <= 0) {
+                            if (db.Updateable<TN_Location>(endloc).ExecuteCommand() <= 0) {
+                                tran.RollbackTran();
+
+                                info = $"浠诲姟{task.S_CODE}鍙栨秷澶辫触";
+
+                                return BuildSimpleResult(0, info);
+                            }
+                        }
+
+                        tran.CommitTran();
+
+                        info = $"浠诲姟{task.S_CODE}鍙栨秷鎴愬姛";
+
+                        return BuildSimpleResult(0, info);
+                    }
+
+                }
+                else {
+                    return BuildSimpleResult(3, $"鍙湁浠诲姟鍙风姸鎬佷负 绛夊緟 鎴�宸叉帹閫�鐨勪换鍔℃墠鑳藉彇娑�);
+                }
+
             }
             catch (Exception ex) {
                 return BuildSimpleResult(1, $"鍙戠敓浜嗗紓甯革細{ex.Message}");
@@ -496,8 +587,8 @@
 
                 var cntID = locCntrRel.S_CNTR_CODE;
                 var task = WCSHelper.BuildTask(startLoc, endLoc, cntID, taskName);
-                LocationHelper.LockLoc(ref startLoc, 1); // 璧风偣鍑哄簱閿�-                LocationHelper.LockLoc(ref endLoc, 2); // 缁堢偣鍏ュ簱閿�+                LocationHelper.LockLoc(ref startLoc, 2); // 璧风偣鍑哄簱閿�+                LocationHelper.LockLoc(ref endLoc, 1); // 缁堢偣鍏ュ簱閿� 
                 using (var tran = db.Ado.UseTran()) {
                     if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new {
@@ -559,8 +650,8 @@
 
                 var cntID = locCntrRel.S_CNTR_CODE;
                 var task = WCSHelper.BuildTask(startLoc, endLoc, cntID, taskName);
-                LocationHelper.LockLoc(ref startLoc, 1); // 璧风偣鍑哄簱閿�-                LocationHelper.LockLoc(ref endLoc, 2); // 缁堢偣鍏ュ簱閿�+                LocationHelper.LockLoc(ref startLoc, 2); // 璧风偣鍑哄簱閿�+                LocationHelper.LockLoc(ref endLoc, 1); // 缁堢偣鍏ュ簱閿� 
                 using (var tran = db.Ado.UseTran()) {
                     if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new {

--
Gitblit v1.9.1