From e21b85869aabac395175aabf8b9e973aabf692df Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期二, 10 三月 2026 17:56:13 +0800
Subject: [PATCH] 优化

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/KLSTaskMethods.cs |   88 ++++++++++++++++++++++++++++++++++---------
 1 files changed, 69 insertions(+), 19 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/KLSTaskMethods.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/KLSTaskMethods.cs"
index 5253d68..0761bf8 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/KLSTaskMethods.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/KLSTaskMethods.cs"
@@ -23,6 +23,7 @@
         /// <returns></returns>
         public WebResponseContent CreateKLSNewInTask(TaskDTO taskDTO, int taskType)
         {
+            WebResponseContent content = new WebResponseContent();
             try
             {
                 int containerType = taskDTO.containerCode.Contains("LLM") ? LocationTypeEnum.LargePallet.ObjToInt() : LocationTypeEnum.SmallPallet.ObjToInt();
@@ -45,16 +46,33 @@
                     Creater = "WMS",
                 };
                 kLSLocationInfo.LocationStatus = LocationStatusEnum.InLock.ObjToInt();
-                Db.Ado.BeginTran();
-                BaseDal.AddData(dt_Task);
-                _kLSLocationInfoService.Repository.UpdateData(kLSLocationInfo);
-                Db.Ado.CommitTran();
-                return WebResponseContent.Instance.OK();
+                try
+                {
+                    Db.Ado.BeginTran();
+                    BaseDal.AddData(dt_Task);
+                    _kLSLocationInfoService.Repository.UpdateData(kLSLocationInfo);
+                    Db.Ado.CommitTran();
+                }
+                catch (Exception ex)
+                {
+                    Db.Ado.RollbackTran();
+                    throw new Exception(ex.Message);
+                }
+                
+                return content.OK(data: new
+                {
+                    taskCode = taskDTO.taskCode,
+                    Message = "鎴愬姛锛�"
+                });
             }
             catch (Exception ex)
             {
-                Db.Ado.RollbackTran();
-                throw new Exception(ex.Message);
+                content.Data = new
+                {
+                    taskCode = taskDTO.taskCode,
+                    Message = $"澶辫触锛亄ex.Message}"
+                };
+                return content.Error(ex.Message);
             }
         }
         /// <summary>
@@ -65,12 +83,12 @@
         /// <returns></returns>
         public WebResponseContent CreateKLSNewOutTask(TaskDTO taskDTO, int taskType)
         {
+            WebResponseContent content = new WebResponseContent();
             try
             {
-                Dt_KLSLocationInfo? kLSLocationInfo = _kLSLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.fromLocationCode);
-                if (kLSLocationInfo == null) throw new Exception($"鏈壘鍒拌捣鐐瑰簱浣嶃�恵taskDTO.fromLocationCode}銆戯紒");
+                Dt_KLSLocationInfo? kLSLocationInfo = _kLSLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.fromLocationCode) ?? throw new Exception($"鏈壘鍒拌捣鐐瑰簱浣嶃�恵taskDTO.fromLocationCode}銆戯紒");
                 if (kLSLocationInfo.LocationStatus != LocationStatusEnum.InStock.ObjToInt()) throw new Exception($"璧风偣搴撲綅銆恵taskDTO.fromLocationCode}銆戝綋鍓嶅簱浣嶇姸鎬佷笉鍙嚭搴擄紒");
-                Dt_Task dt_Task = new Dt_Task()
+                Dt_Task dt_Task = new()
                 {
                     TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                     WMSTaskNum = taskDTO.taskCode,
@@ -87,16 +105,32 @@
                     Creater = "WMS",
                 };
                 kLSLocationInfo.LocationStatus = LocationStatusEnum.OutLock.ObjToInt();
-                Db.Ado.BeginTran();
-                BaseDal.AddData(dt_Task);
-                _kLSLocationInfoService.Repository.UpdateData(kLSLocationInfo);
-                Db.Ado.CommitTran();
-                return WebResponseContent.Instance.OK();
+                try
+                {
+                    Db.Ado.BeginTran();
+                    BaseDal.AddData(dt_Task);
+                    _kLSLocationInfoService.Repository.UpdateData(kLSLocationInfo);
+                    Db.Ado.CommitTran();
+                }
+                catch (Exception ex)
+                {
+                    Db.Ado.RollbackTran();
+                    throw new Exception(ex.Message);
+                }
+                return content.OK(data: new
+                {
+                    taskCode = taskDTO.taskCode,
+                    Message = "鎴愬姛锛�"
+                });
             }
             catch (Exception ex)
             {
-                Db.Ado.RollbackTran();
-                throw new Exception(ex.Message);
+                content.Data = new
+                {
+                    taskCode = taskDTO.taskCode,
+                    Message = $"澶辫触锛亄ex.Message}"
+                };
+                return content.Error(ex.Message);
             }
         }
         #endregion
@@ -104,7 +138,15 @@
         #region 5 璺ㄦゼ灞傝繍杈撲换鍔″垱寤�
         public WebResponseContent CarryTask(TaskDTO taskDTO, int taskType)
         {
-            return WebResponseContent.Instance.OK();
+            try
+            {
+
+                return WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
         }
         #endregion
 
@@ -112,7 +154,15 @@
         #region 6 瑁佸壀閫佽揣
         public WebResponseContent CJCarryTaske(TaskDTO taskDTO, int taskType)
         {
-            return WebResponseContent.Instance.OK();
+            try
+            {
+
+                return WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
         }
         #endregion
     }

--
Gitblit v1.9.3