From 2d3ee03961d6cfbde70342e8a97bc7b05d0b0dc3 Mon Sep 17 00:00:00 2001 From: kazelee <1847801760@qq.com> Date: 星期一, 21 七月 2025 17:27:34 +0800 Subject: [PATCH] 优化代码, 封装货位锁和创建任务流程, 数据库事务等 --- api/ApiHelper.cs | 39 ++++++++++++--------------------------- 1 files changed, 12 insertions(+), 27 deletions(-) diff --git a/api/ApiHelper.cs b/api/ApiHelper.cs index f1adf15..8708fea 100644 --- a/api/ApiHelper.cs +++ b/api/ApiHelper.cs @@ -1,6 +1,7 @@ 锘縰sing System; using System.Collections.Generic; using System.Linq; +using System.Security.Cryptography; using HH.WCS.Mobox3.DSZSH.core; using HH.WCS.Mobox3.DSZSH.models; @@ -8,6 +9,7 @@ using HH.WCS.Mobox3.DSZSH.wms; using Newtonsoft.Json; + using SqlSugar; using Swashbuckle.Swagger; @@ -61,10 +63,8 @@ } // 鏇存柊[璧风偣/缁堢偣]閿佺姸鎬�鍒涘缓浠诲姟 - WCSHelper.LockStartLoc(ref startLoc); - WCSHelper.LockEndLoc(ref endLoc); - var task = WCSHelper.BuildTask(startLoc, endLoc, locCntrRel.S_CNTR_CODE, taskInfo.TaskName); - + var task = WCSHelper.BuildTaskWithLocLock(startLoc, endLoc, locCntrRel.S_CNTR_CODE, taskInfo.TaskName); + using (var tran = db.Ado.UseTran()) { // 鍒犻櫎/鏇存柊鏃璐т綅/瀹瑰櫒/鐗╂枡]淇℃伅 if (old.LocCntrRel != null && db.Deleteable(old.LocCntrRel).ExecuteCommand() <= 0) { @@ -148,9 +148,7 @@ } // 璧风偣缁堢偣涓婇攣,鍒涘缓浠诲姟 - WCSHelper.LockStartLoc(ref startLoc); - WCSHelper.LockEndLoc(ref endLoc); - var task = WCSHelper.BuildTask(startLoc, endLoc, locCntrRel.S_CNTR_CODE, taskInfo.TaskName); + var task = WCSHelper.BuildTaskWithLocLock(startLoc, endLoc, locCntrRel.S_CNTR_CODE, taskInfo.TaskName); using (var tran = db.Ado.UseTran()) { if (old.CgDetail != null && db.Deleteable(old.CgDetail).ExecuteCommand() <= 0) { @@ -237,9 +235,7 @@ return NewSimpleResult(3, preLog + $"娌℃湁鎵惧埌鍚堥�鐨勭粓鐐硅揣浣�瑕佹眰:閿佺姸鎬�'鏃�;褰撳墠瀹瑰櫒鏁伴噺=0;鎵�湪搴撳尯={LogObject(taskInfo.EndAreas)}"); } - WCSHelper.LockStartLoc(ref startLoc); - WCSHelper.LockEndLoc(ref endLoc); - var task = WCSHelper.BuildTask(startLoc, endLoc, locCntrRel.S_CNTR_CODE, taskInfo.TaskName); + var task = WCSHelper.BuildTaskWithLocLock(startLoc, endLoc, locCntrRel.S_CNTR_CODE, taskInfo.TaskName); using (var tran = db.Ado.UseTran()) { if (old.CgDetail != null && db.Deleteable(old.CgDetail).ExecuteCommand() <= 0) { @@ -329,9 +325,7 @@ return NewSimpleResult(5, preLog + $"娌℃湁鎵惧埌鍚堥�鐨勭粓鐐硅揣浣�瑕佹眰:閿佺姸鎬�'鏃�;褰撳墠瀹瑰櫒鏁伴噺=0;鎵�湪搴撳尯={LogObject(taskInfo.EndAreas)}"); } - WCSHelper.LockStartLoc(ref startLoc); - WCSHelper.LockEndLoc(ref endLoc); - var task = WCSHelper.BuildTask(startLoc, endLoc, model.CntId, taskInfo.TaskName); + var task = WCSHelper.BuildTaskWithLocLock(startLoc, endLoc, model.CntId, taskInfo.TaskName); cntr.S_SOURCE = task.S_CODE; // 鐢ㄤ换鍔″彿浣滀负瀹瑰櫒鏇存柊鐨勪緷鎹� cntr.T_MODIFY = DateTime.Now; @@ -396,10 +390,8 @@ return NewSimpleResult(3, preLog + $"娌℃湁鎵惧埌鍚堥�鐨勭粓鐐硅揣浣�瑕佹眰:閿佺姸鎬�'鏃�,褰撳墠瀹瑰櫒鏁伴噺=0,鎵�湪搴撳尯={LogObject(taskInfo.EndAreas)}"); } - WCSHelper.LockStartLoc(ref startLoc); - WCSHelper.LockEndLoc(ref endLoc); - var task = WCSHelper.BuildTask(startLoc, endLoc, model.CntId, taskInfo.TaskName); - + var task = WCSHelper.BuildTaskWithLocLock(startLoc, endLoc, model.CntId, taskInfo.TaskName); + using (var tran = db.Ado.UseTran()) { // 鏇存柊[璧风偣/缁堢偣]閿佺姸鎬�鍒涘缓浠诲姟 if (db.Updateable(startLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, it.N_CURRENT_NUM, }).ExecuteCommand() <= 0) { @@ -463,10 +455,7 @@ cgDetail.T_MODIFY = DateTime.Now; var cntId = locCntrRel.S_CNTR_CODE; - var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskInfo.TaskName); - - WCSHelper.LockStartLoc(ref startLoc); - WCSHelper.LockEndLoc(ref endLoc); + var task = WCSHelper.BuildTaskWithLocLock(startLoc, endLoc, cntId, taskInfo.TaskName); using (var tran = db.Ado.UseTran()) { if (db.Updateable(cgDetail).UpdateColumns(it => new { it.N_ITEM_STATE, it.S_ITEM_STATE, it.T_MODIFY }).ExecuteCommand() <= 0) { @@ -538,9 +527,7 @@ cgDetail.N_ITEM_STATE = 2; cgDetail.S_ITEM_STATE = "涓嶅悎鏍�; - WCSHelper.LockStartLoc(ref startLoc); - WCSHelper.LockEndLoc(ref endLoc); - var task = WCSHelper.BuildTask(startLoc, endLoc, locCntrRel.S_CNTR_CODE, taskInfo.TaskName); + var task = WCSHelper.BuildTaskWithLocLock(startLoc, endLoc, locCntrRel.S_CNTR_CODE, taskInfo.TaskName); using (var tran = db.Ado.UseTran()) { if (db.Updateable(cgDetail).UpdateColumns(it => new { it.N_ITEM_STATE, it.S_ITEM_STATE }).ExecuteCommand() <= 0) { @@ -601,9 +588,7 @@ var cntId = locCntrRel.S_CNTR_CODE; - WCSHelper.LockStartLoc(ref startLoc); - WCSHelper.LockEndLoc(ref endLoc); - var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskInfo.TaskName); + var task = WCSHelper.BuildTaskWithLocLock(startLoc, endLoc, cntId, taskInfo.TaskName); using (var tran = db.Ado.UseTran()) { //if (db.Insertable(locCntrRel).ExecuteCommand() <= 0) { -- Gitblit v1.9.1