wanshenmean
3 天以前 64a2aa2301946f777659239247233e47ad1e3076
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);
                }
@@ -885,31 +872,31 @@
        {
            try
            {
                // 1. 根据任务类型字符串确定 TaskType 和 TaskStatus
                int taskType;
                int taskStatus;
                switch (dto.TaskType)
                {
                    case "入库":
                        taskType = TaskTypeEnum.Inbound.GetHashCode();
                        taskType = TaskInboundTypeEnum.Inbound.GetHashCode();
                        taskStatus = TaskInStatusEnum.InNew.GetHashCode();
                        break;
                    case "出库":
                        taskType = TaskTypeEnum.Outbound.GetHashCode();
                        taskType = TaskOutboundTypeEnum.Outbound.GetHashCode();
                        taskStatus = TaskOutStatusEnum.OutNew.GetHashCode();
                        break;
                    case "移库":
                        taskType = TaskTypeEnum.Relocation.GetHashCode();
                        taskType = TaskRelocationTypeEnum.Relocation.GetHashCode();
                        taskStatus = TaskRelocationStatusEnum.RelocationNew.GetHashCode();
                        break;
                    default:
                        return WebResponseContent.Instance.Error($"不支持的任务类型: {dto.TaskType}");
                }
                // 2. 生成任务号
                int taskNum = await BaseDal.GetTaskNo();
                // 3. 构建任务实体
                var task = new Dt_Task
                {
                    TaskNum = taskNum,
@@ -919,6 +906,7 @@
                    TaskType = taskType,
                    TaskStatus = taskStatus,
                    Grade = dto.Grade,
                    Roadway = dto.TargetAddress,
                    WarehouseId = dto.WarehouseId,
                    CurrentAddress = dto.SourceAddress,
                    NextAddress = dto.TargetAddress,
@@ -927,31 +915,37 @@
                    ModifyDate = DateTime.Now
                };
                // 4. 保存到数据库
                var result = await BaseDal.AddDataAsync(task) > 0;
                if (!result)
                    return WebResponseContent.Instance.Error("创建任务失败");
                // 5. 发送到 WCS
                var wmsTaskDto = new WMSTaskDTO
                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",
                    wmsTaskDto.ToJson());
                        wmsTaskDtos.ToJson());
                if (!wcsResult.IsSuccess || !wcsResult.Data.Status)
                    return WebResponseContent.Instance.Error($"任务已创建但发送给WCS失败: {wcsResult.Data?.Message}");
                return WebResponseContent.Instance.OK($"手动创建任务成功,任务号: {taskNum}");
                });
            }
            catch (Exception ex)
            {