From 64a2aa2301946f777659239247233e47ad1e3076 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期日, 12 四月 2026 11:54:15 +0800
Subject: [PATCH] feat(事务管理): 添加异步事务处理方法

---
 Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_WCS.cs |  103 +++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 90 insertions(+), 13 deletions(-)

diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_WCS.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_WCS.cs
index 9aa52de..ed7108a 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_WCS.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_WCS.cs
@@ -1,27 +1,15 @@
 using Mapster;
-using MapsterMapper;
 using Microsoft.Extensions.Configuration;
 using SqlSugar;
-using System.DirectoryServices.Protocols;
-using System.Text.Json;
 using WIDESEA_Common.Constants;
 using WIDESEA_Common.LocationEnum;
 using WIDESEA_Common.StockEnum;
 using WIDESEA_Common.TaskEnum;
 using WIDESEA_Common.WareHouseEnum;
 using WIDESEA_Core;
-using WIDESEA_Core.BaseRepository;
-using WIDESEA_Core.BaseServices;
-using WIDESEA_Core.Core;
-using WIDESEA_Core.Enums;
 using WIDESEA_Core.Helper;
-using WIDESEA_DTO.GradingMachine;
-using WIDESEA_DTO.MES;
 using WIDESEA_DTO.Stock;
 using WIDESEA_DTO.Task;
-using WIDESEA_IBasicService;
-using WIDESEA_IStockService;
-using WIDESEA_ITaskInfoService;
 using WIDESEA_Model.Models;
 
 namespace WIDESEA_TaskInfoService
@@ -185,7 +173,6 @@
                 // 鍒ゆ柇鏄笉鏄瀬鍗峰簱浠诲姟
                 if (taskDto.WarehouseId == (int)WarehouseEnum.FJ1 || taskDto.WarehouseId == (int)WarehouseEnum.ZJ1)
                 {
-
                     return await CompleteAgvInboundTaskAsync(taskDto);
                 }
 
@@ -876,6 +863,96 @@
             }
         }
 
+        /// <summary>
+        /// 鎵嬪姩鍒涘缓浠诲姟
+        /// </summary>
+        /// <param name="dto">鎵嬪姩鍒涘缓浠诲姟鍙傛暟</param>
+        /// <returns></returns>
+        public async Task<WebResponseContent> CreateManualTaskAsync(CreateManualTaskDto dto)
+        {
+            try
+            {
+                int taskType;
+                int taskStatus;
+                switch (dto.TaskType)
+                {
+                    case "鍏ュ簱":
+                        taskType = TaskInboundTypeEnum.Inbound.GetHashCode();
+                        taskStatus = TaskInStatusEnum.InNew.GetHashCode();
+                        break;
+
+                    case "鍑哄簱":
+                        taskType = TaskOutboundTypeEnum.Outbound.GetHashCode();
+                        taskStatus = TaskOutStatusEnum.OutNew.GetHashCode();
+                        break;
+
+                    case "绉诲簱":
+                        taskType = TaskRelocationTypeEnum.Relocation.GetHashCode();
+                        taskStatus = TaskRelocationStatusEnum.RelocationNew.GetHashCode();
+                        break;
+
+                    default:
+                        return WebResponseContent.Instance.Error($"涓嶆敮鎸佺殑浠诲姟绫诲瀷: {dto.TaskType}");
+                }
+
+                int taskNum = await BaseDal.GetTaskNo();
+
+                var task = new Dt_Task
+                {
+                    TaskNum = taskNum,
+                    PalletCode = dto.Barcode,
+                    SourceAddress = dto.SourceAddress,
+                    TargetAddress = dto.TargetAddress,
+                    TaskType = taskType,
+                    TaskStatus = taskStatus,
+                    Grade = dto.Grade,
+                    Roadway = dto.TargetAddress,
+                    WarehouseId = dto.WarehouseId,
+                    CurrentAddress = dto.SourceAddress,
+                    NextAddress = dto.TargetAddress,
+                    Creater = "manual",
+                    CreateDate = DateTime.Now,
+                    ModifyDate = DateTime.Now
+                };
+
+                var wmsTaskDtos = new List<WMSTaskDTO>()
+                {
+                    new()
+                    {
+                        TaskNum = task.TaskNum,
+                        PalletCode = task.PalletCode,
+                        SourceAddress = task.SourceAddress,
+                        TargetAddress = task.TargetAddress,
+                        TaskType = task.TaskType,
+                        Roadway = task.Roadway,
+                        TaskStatus = task.TaskStatus,
+                        WarehouseId = task.WarehouseId
+                    }
+                };
+
+                await _unitOfWorkManage.BeginTranAsync(async () =>
+                {
+                    // 4. 淇濆瓨鍒版暟鎹簱
+                    var result = await BaseDal.AddDataAsync(task) > 0;
+                    if (!result)
+                        return WebResponseContent.Instance.Error("鍒涘缓浠诲姟澶辫触");
+
+                    var wcsResult = _httpClientHelper.Post<WebResponseContent>(
+                        "http://localhost:9292/api/Task/ReceiveManualTask",
+                        wmsTaskDtos.ToJson());
+
+                    if (!wcsResult.IsSuccess || !wcsResult.Data.Status)
+                        return WebResponseContent.Instance.Error($"浠诲姟宸插垱寤轰絾鍙戦�佺粰WCS澶辫触: {wcsResult.Data?.Message}");
+
+                    return WebResponseContent.Instance.OK($"鎵嬪姩鍒涘缓浠诲姟鎴愬姛锛屼换鍔″彿: {taskNum}");
+                });
+            }
+            catch (Exception ex)
+            {
+                return WebResponseContent.Instance.Error($"鎵嬪姩鍒涘缓浠诲姟寮傚父: {ex.Message}");
+            }
+        }
+
         #endregion WCS閫昏緫澶勭悊
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3