wanshenmean
2024-11-06 c9982eb3dd76696b8a3851cc6411a71c402d042f
11.06
已修改13个文件
1141 ■■■■■ 文件已修改
.gitignore 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs 135 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs 54 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/UnitOfWorks/IUnitOfWorkManage.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/UnitOfWorks/UnitOfWorkManage.cs 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_IStorageTaskService/Task/IDt_TaskService.cs 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Model/Models/BasicModel/DtStockInfo.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/AgingInOrOutInput/AgingInOrOutInputService.cs 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/CellState/CellStateService.cs 114 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/ProcessApply/ProcessApplyService.cs 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/Unbind/UnbindService.cs 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs 788 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/TaskController.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.gitignore
@@ -973,3 +973,4 @@
/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_ProcessParameters/obj/Debug/net6.0/WIDESEAWCS_IProcessRepository.csproj.CoreCompileInputs.cache
/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_ProcessRepository/obj/Debug/net6.0/WIDESEAWCS_ProcessRepository.csproj.CoreCompileInputs.cache
/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/obj/Debug/net6.0/WIDESEAWCS_Tasks.csproj.CoreCompileInputs.cache
*.txt
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -20,11 +20,9 @@
using AutoMapper;
using HslCommunication;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using Quartz;
using SqlSugar;
using System.Reflection;
using System.Threading.Tasks;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
@@ -121,7 +119,7 @@
                                    {
                                        command.InteractiveSignal = commandWrite.WriteInteractiveSignal;
                                        int count = string.IsNullOrEmpty(platform.Location) ? 0 + 1 : platform.Location.Split(',').Count() + 1;
                                        method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count });
                                        method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform });
                                    }
                                }
                                else
@@ -140,7 +138,7 @@
                                                {
                                                    command.InteractiveSignal = commandWrite.WriteInteractiveSignal;
                                                    int count = strings.Count - index;
                                                    method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count });
                                                    method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform });
                                                }
                                            }
                                        }
@@ -407,28 +405,42 @@
            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
            if (task != null)
            {
                WebResponseContent content = new WebResponseContent();
                ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(task);
                taskCommand.InteractiveSignal = command.InteractiveSignal;
                if (task.PalletCode != command.Barcode)
                {
                    var NGAddress = _platFormRepository.QueryFirst(x => x.PlatCode == task.TargetAddress).Capacity;
                    taskCommand.TargetAddress = NGAddress;
                    conveyorLine.SendCommand(taskCommand, childDeviceCode);
                }
                else
                {
                    taskCommand.TargetAddress = 0;
                }
                // TODO调用任务完成执行任务完成
                #region 向WMS上报任务完成
                WMSTaskDTO wMSTaskDTO = new WMSTaskDTO();
                var result = HttpHelper.PostAsync("http:127.0.0.1:8098/api/Task/CompleteTaskAsync", (new { taskNum = command.TaskNum }).ToJsonString()).Result;
                content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                // 检查状态并返回
                if (!content.Status)
                    return;
                #endregion 向WMS请求空托盘任务
                conveyorLine.SendCommand(taskCommand, childDeviceCode);
                ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
                content = _taskService.UpdateTaskStatusToNext(task);
            }
        }
        /// <summary>
        /// 创建任务并发送请求
        /// </summary>
        private WebResponseContent CreateAndSendTask(WMSTaskDTO taskDTO)
        public WebResponseContent CreateAndSendTask(WMSTaskDTO taskDTO)
        {
            var content = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
            if (content.Status)
@@ -445,54 +457,91 @@
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        /// <param name="index">线体当前bool读取偏移地址</param>
        public void EmptyTrayReturn(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int index)
        public void EmptyTrayReturn(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int index, Platform platform)
        {
            CheckAndCreateTask((int)TaskOutboundTypeEnum.OutTray, childDeviceCode, index, "CHSC01", "001-001-001");
            TaskOutboundTypeEnum taskOutboundTypeEnum;
            if (platform.PlatformType.Contains("OutTray"))
                taskOutboundTypeEnum = TaskOutboundTypeEnum.OutTray;
            else
                taskOutboundTypeEnum = TaskOutboundTypeEnum.Outbound;
            CheckAndCreateTask(TaskOutboundTypeEnum.OutTray, childDeviceCode, index, platform.Stacker.Split(',')[0], platform.Stacker.Split(',').ToList());
        }
        /// 静置空托盘出库
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        /// <param name="index">线体当前bool读取偏移地址</param>
        public void EmptyTrayOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int index)
        {
            CheckAndCreateTask((int)TaskOutboundTypeEnum.OutTray, childDeviceCode, index, "JZSC01", "002-020-001");
        }
        #region
        ///// <summary>
        ///// 陈化实盘出库)
        ///// </summary>
        ///// <param name="conveyorLine">输送线实例对象</param>
        ///// <param name="command">读取的请求信息</param>
        ///// <param name="childDeviceCode">子设备编号</param>
        ///// <param name="index">线体当前bool读取偏移地址</param>
        //public void ChuanhuaOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
        //{
        //    CheckAndCreateTask(TaskOutboundTypeEnum.Outbound, childDeviceCode, "CHSC01", "001-001-001");
        //}
        /// <summary>
        /// 陈化出库(实盘)
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        /// <param name="index">线体当前bool读取偏移地址</param>
        public void ChuanhuaOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int index)
        {
            CheckAndCreateTask((int)TaskOutboundTypeEnum.Outbound, childDeviceCode, index, "CHSC01", "001-001-001");
        }
        ///// 静置空托盘出库
        ///// </summary>
        ///// <param name="conveyorLine">输送线实例对象</param>
        ///// <param name="command">读取的请求信息</param>
        ///// <param name="childDeviceCode">子设备编号</param>
        ///// <param name="index">线体当前bool读取偏移地址</param>
        //public void EmptyTrayOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int index)
        //{
        //    CheckAndCreateTask(TaskOutboundTypeEnum.OutTray, childDeviceCode, index, "JZSC01", "002-020-001");
        //}
        ///// <summary>
        ///// 静置实盘出库
        ///// </summary>
        ///// <param name="conveyorLine">输送线实例对象</param>
        ///// <param name="command">读取的请求信息</param>
        ///// <param name="childDeviceCode">子设备编号</param>
        ///// <param name="index">线体当前bool读取偏移地址</param>
        //public void JingzhiOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int index)
        //{
        //    CheckAndCreateTask(TaskOutboundTypeEnum.Outbound, childDeviceCode, index, "JZSC01", "002-000-001");
        //}
        #endregion
        /// <summary>
        /// 检查任务并创建新任务
        /// </summary>
        private void CheckAndCreateTask(int taskType, string childDeviceCode, int index, string roadWay, string sourceAddress)
        private void CheckAndCreateTask(TaskOutboundTypeEnum taskType, string childDeviceCode, int index, string roadWay, List<string> roadways = null)
        {
            var tasks = _taskRepository.QueryData(x => x.TaskType == taskType && x.TargetAddress == childDeviceCode);
            var tasks = _taskRepository.QueryData(x => x.TaskType == (int)taskType && x.TargetAddress == childDeviceCode);
            if (tasks.Count < index)
            {
                var taskDTO = new WMSTaskDTO()
                //var taskDTO = new WMSTaskDTO()
                //{
                //    TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")),
                //    Grade = 1,
                //    PalletCode = DateTime.Now.ToString("yyyyMMddHHmmss"),
                //    RoadWay = roadWay,
                //    SourceAddress = sourceAddress,
                //    TargetAddress = childDeviceCode,
                //    TaskState = (int)TaskOutStatusEnum.OutNew,
                //    Id = 0,
                //    TaskType = (int)taskType
                //};
                #region 调用WMS获取出库任务
                WMSTaskDTO taskDTO = new WMSTaskDTO();
                dynamic dynamic = new
                {
                    TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")),
                    Grade = 1,
                    PalletCode = DateTime.Now.ToString("yyyyMMddHHmmss"),
                    RoadWay = roadWay,
                    SourceAddress = sourceAddress,
                    TargetAddress = childDeviceCode,
                    TaskState = (int)TaskOutStatusEnum.OutNew,
                    Id = 0,
                    TaskType = taskType
                    position = childDeviceCode,
                    tag = (int)taskType,
                    areaCdoe = roadWay,
                    roadways = roadways
                };
                var result = HttpHelper.PostAsync("http:127.0.0.1:8098/api/Task/RequestTaskAsync", dynamic.ToJsonString()).Result;
                WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                // 检查状态并返回
                if (!content.Status)
                    return;
                taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
                #endregion
                CreateAndSendTask(taskDTO);
            }
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs
@@ -13,10 +13,11 @@
using WIDESEAWCS_Tasks.ConveyorLineJob;
using HslCommunication;
using OfficeOpenXml.ConditionalFormatting;
using WIDESEAWCS_DTO.WMS;
namespace WIDESEAWCS_Tasks
{
    partial class CommonConveyorLineJob
    public partial class CommonConveyorLineJob
    {
        /// <summary>
        /// 处理出库任务
@@ -34,7 +35,7 @@
            bool isOutboundAndOutFinish = taskOut.TaskType == (int)TaskOutboundTypeEnum.Outbound && taskOut.TaskState == (int)TaskOutStatusEnum.SC_OutFinish;
            bool isOutboundAndLineOutExecuting = taskOut.TaskType == (int)TaskOutboundTypeEnum.Outbound && taskOut.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting;
            if (isOutTray || isOutboundAndOutFinish || isOutboundAndLineOutExecuting)
            if (isOutTray || isOutboundAndOutFinish || !isOutboundAndLineOutExecuting)
            {
                // 发送命令到输送线
                conveyorLine.SendCommand(taskCommand, childDeviceCode);
@@ -56,13 +57,14 @@
        private void HandleNewTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        {
            // 特定条件下创建并发送空托盘入库任务
            if (conveyorLine.DeviceCode == "1003" && childDeviceCode == "1016")
            if ((conveyorLine.DeviceCode == "1003" && childDeviceCode == "1016") || (conveyorLine.DeviceCode == "1005" && childDeviceCode == "1048"))
            {
                // 请求WMS空托盘任务
                CreateAndSendEmptyTrayTask(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
            }
            else if (conveyorLine.DeviceCode == "1001" && childDeviceCode == "1088")
            else if ((conveyorLine.DeviceCode == "1001" && childDeviceCode == "1088")||(conveyorLine.DeviceCode == "1004" && childDeviceCode == "1339"))
            {
                // 请求WMS任务
                // 请求WMS入库任务
                RequestWmsTask(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
            }
            else if ((conveyorLine.DeviceCode == "1001" && childDeviceCode == "1073") || (conveyorLine.DeviceCode == "1003" && childDeviceCode == "1002"))
@@ -109,7 +111,7 @@
        /// <summary>
        /// 创建并发送空托盘任务
        /// </summary>
        private void CreateAndSendEmptyTrayTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        public void CreateAndSendEmptyTrayTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        {
            if (command.Barcode != "NoRead")
            {
@@ -142,18 +144,38 @@
        private WMSTaskDTO CreateEmptyTrayTaskDto(string barcode, string childDeviceCode)
        {
            // 创建并返回空托盘任务DTO
            return new WMSTaskDTO
            //return new WMSTaskDTO
            //{
            //    TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")),
            //    Grade = 1,
            //    PalletCode = barcode,
            //    RoadWay = "JZSC01",
            //    SourceAddress = childDeviceCode,
            //    TargetAddress = "JZSC01",
            //    TaskState = (int)TaskInStatusEnum.InNew,
            //    Id = 0,
            //    TaskType = (int)TaskInboundTypeEnum.InTray,
            //};
            #region 向WMS请求空托盘任务
            WMSTaskDTO wMSTaskDTO = new WMSTaskDTO();
            RequestTaskDto request = new RequestTaskDto()
            {
                TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")),
                Grade = 1,
                Position = childDeviceCode,
                PalletCode = barcode,
                RoadWay = "CHSC01",
                SourceAddress = childDeviceCode,
                TargetAddress = "CHSC01",
                TaskState = (int)TaskInStatusEnum.InNew,
                Id = 0,
                TaskType = (int)TaskInboundTypeEnum.InTray,
            };
            var result = HttpHelper.PostAsync("http:127.0.0.1:8098/api/Task/RequestTaskAsync", request.ToJsonString()).Result;
            WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result);
            // 检查状态并返回
            if (!content.Status)
                return wMSTaskDTO;
            return JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
            #endregion 向WMS请求空托盘任务
        }
        /// <summary>
@@ -180,4 +202,4 @@
            }
        }
    }
}
}
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/UnitOfWorks/IUnitOfWorkManage.cs
@@ -21,5 +21,6 @@
        void CommitTran(MethodInfo method);
        void RollbackTran();
        void RollbackTran(MethodInfo method);
        Task UseTranAsync(Func<Task> action);
    }
}
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseRepository/UnitOfWorks/UnitOfWorkManage.cs
@@ -190,5 +190,26 @@
                }
            }
        }
        public async Task UseTranAsync(Func<Task> action)
        {
            // 开始事务
            _sqlSugarClient.Ado.BeginTran();
            try
            {
                // 执行传入的操作
                await action();
                // 提交事务
                await _sqlSugarClient.Ado.CommitTranAsync();
            }
            catch (Exception ex)
            {
                // 回滚事务
                await _sqlSugarClient.Ado.RollbackTranAsync();
                throw new Exception (ex.Message); // 重新抛出异常,以便调用方可以处理
            }
        }
    }
}
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_IStorageTaskService/Task/IDt_TaskService.cs
@@ -134,9 +134,12 @@
    Task<WebResponseContent> RequestTaskAsync(RequestTaskDto input);
    /// <summary>
    /// 请求空托盘任务
    /// 请求托盘任务
    /// </summary>
    /// <param name="position"></param>
    /// <returns></returns>
    Task<WebResponseContent> RequestTrayTaskAsync(string position);
    /// <param name="position">目标位置</param>
    /// <param name="tag">托盘类型(1:实盘,2:空盘)</param>
    /// <param name="areaCode">区域编码</param>
    /// <param name="roadways">巷道列表</param>
    /// <returns>返回结果集</returns>
    Task<WebResponseContent> RequestTrayTaskAsync(string position, int tag, string areaCode, List<string> roadways);
}
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Model/Models/BasicModel/DtStockInfo.cs
@@ -36,7 +36,7 @@
        public bool IsFull { get; set; }
        /// <summary>
        /// 备注 (静制)
        /// 备注 (静制\陈化时间)
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDescription = "备注")]
        public string Remark { get; set; }
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/AgingInOrOutInput/AgingInOrOutInputService.cs
@@ -23,8 +23,6 @@
        try
        {
            input.SessionId = Guid.NewGuid().ToString();
            input.Software = "陈化机";
            input.EquipmentCode = "P1K10040";
            input.EmployeeNo = "T00001";
            input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
            var inputJson = input.ToDictionary();
@@ -54,12 +52,11 @@
        try
        {
            input.SessionId = Guid.NewGuid().ToString();
            input.Software = "陈化机";
            input.EquipmentCode = "P1K10040";
            input.EmployeeNo = "T00001";
            input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); ;
            var inputJson = input.ToDictionary();
            var x = await HttpsClient.PostAsync("http://ts-momapp01:12020/api/MachineIntegration/AgingOutput", inputJson);
            content.OK(data: x);
            LogFactory.GetLog("静置陈化出库(整托盘)").Info(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("静置陈化出库(整托盘)").Info(true, x);
            content.OK();
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/CellState/CellStateService.cs
@@ -1,13 +1,10 @@
using LogLibrary.Log;
using Masuit.Tools;
using Newtonsoft.Json;
using WIDESEA_Common;
using WIDESEA_Core;
using WIDESEA_DTO;
using WIDESEA_DTO.MOM;
using WIDESEA_IStorageBasicService;
using WIDESEA_IStoragIntegrationServices;
using WIDESEA_Model.Models;
namespace WIDESEA_StoragIntegrationServices;
@@ -33,40 +30,42 @@
        try
        {
            input.SessionId = Guid.NewGuid().ToString();
            input.Software = "陈化机";
            input.EquipmentCode = "P1K10040";
            input.EmployeeNo = "T00001";
            input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
            var inputJson = input.ToDictionary();
            var x = await HttpsClient.PostAsync("http://ts-momapp01:12020/api/MachineIntegration/CellState", inputJson);
            if (x != null)
            {
                ResultCellState result = JsonConvert.DeserializeObject<ResultCellState>(x);
                DtBoxingInfo boxingInfo = new DtBoxingInfo()
                {
                    IsFull = true,
                    PalletCode = "",
                };
                var details = new List<DtBoxingInfoDetail>();
                foreach (var item in result.SerialNos)
                {
                    DtBoxingInfoDetail detail = new DtBoxingInfoDetail()
                    {
                        SerialNumber = item.SerialNo,
                        OrderNo = item.BindCode,
                        Status = item.SerialNoStatus,
                    };
                    details.Add(detail);
                }
                boxingInfo.BoxingInfoDetails = details;
                var abc = await _boxingInfoService.AddBoxingInfoAsync(boxingInfo);
                if (abc.Status)
                    return content.OK("组盘成功");
                else
                    return content.Error("组盘失败");
            }
            #region
            //if (x != null)
            //{
            //    ResultCellState result = JsonConvert.DeserializeObject<ResultCellState>(x);
            //    DtBoxingInfo boxingInfo = new DtBoxingInfo()
            //    {
            //        IsFull = true,
            //        PalletCode = "",
            //    };
            //    var details = new List<DtBoxingInfoDetail>();
            //    foreach (var item in result.SerialNos)
            //    {
            //        DtBoxingInfoDetail detail = new DtBoxingInfoDetail()
            //        {
            //            SerialNumber = item.SerialNo,
            //            OrderNo = item.BindCode,
            //            Status = item.SerialNoStatus,
            //        };
            //        details.Add(detail);
            //    }
            //    boxingInfo.BoxingInfoDetails = details;
            //    var abc = await _boxingInfoService.AddBoxingInfoAsync(boxingInfo);
            //    if (abc.Status)
            //        return content.OK("组盘成功");
            //    else
            //        return content.Error("组盘失败");
            //}
            #endregion
            LogFactory.GetLog("单电芯属性获取").Info(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("单电芯属性获取").Info(true, x);
            return x;
        }
        catch (Exception err)
        {
@@ -88,42 +87,37 @@
        try
        {
            input.SessionId = Guid.NewGuid().ToString();
            input.Software = "陈化机";
            input.EquipmentCode = "P1K10040";
            input.EmployeeNo = "T00001";
            input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
            var inputJson = input.ToDictionary();
            var x = await HttpsClient.PostAsync("http://ts-momapp01:12020/api/MachineIntegration/TrayCellsStatus", inputJson);
            //if (x != null)
            //{
            //    // 反序列化ResultTrayCellsStatus对象
            //    ResultTrayCellsStatus result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(x);
            if (x != null)
            {
                // 反序列化ResultTrayCellsStatus对象
                //ResultTrayCellsStatus result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(x);
            //    // 创建DtBoxingInfo对象
            //    DtBoxingInfo boxingInfo = new DtBoxingInfo
            //    {
            //        IsFull = true,
            //        PalletCode = result.TrayBarcode,
            //    };
                //// 创建DtBoxingInfo对象
                //DtBoxingInfo boxingInfo = new DtBoxingInfo
                //{
                //    IsFull = true,
                //    PalletCode = result.TrayBarcode,
                //};
            //    // 使用LINQ创建DtBoxingInfoDetail对象列表
            //    var details = result.SerialNos.Select(item => new DtBoxingInfoDetail
            //    {
            //        SerialNumber = item.SerialNo,
            //        OrderNo = item.PositionNo.ToString(),
            //        Status = item.SerialNoStatus,
            //        Remark = result.TrayBarcodePropertys.ToJsonString(),
            //        MaterielCode = result.BindCode,
            //    }).ToList();
                //// 使用LINQ创建DtBoxingInfoDetail对象列表
                //var details = result.SerialNos.Select(item => new DtBoxingInfoDetail
                //{
                //    SerialNumber = item.SerialNo,
                //    OrderNo = item.PositionNo.ToString(),
                //    Status = item.SerialNoStatus,
                //    Remark = result.TrayBarcodePropertys.ToJsonString(),
                //    MaterielCode = result.BindCode,
                //}).ToList();
            //    // 赋值DtBoxingInfoDetails
            //    boxingInfo.BoxingInfoDetails = details;
            //    var abc = await _boxingInfoService.AddBoxingInfoAsync(boxingInfo);
            //    if (abc.Status)
            //        content.OK("组盘成功", result);
            //    else
            //        content.Error("组盘失败");
            //}
                //// 赋值DtBoxingInfoDetails
                //boxingInfo.BoxingInfoDetails = details;
                //var abc = await _boxingInfoService.AddBoxingInfoAsync(boxingInfo);
                    content.OK("组盘成功", x);
            }
            LogFactory.GetLog("整盘电芯属性获取").Info(true, $"\r\r--------------------------------------");
            LogFactory.GetLog("整盘电芯属性获取").Info(true, x);
        }
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/ProcessApply/ProcessApplyService.cs
@@ -24,8 +24,6 @@
        try
        {
            input.SessionId = Guid.NewGuid().ToString();
            input.Software = "陈化机";
            input.EquipmentCode = "P1K10040";
            input.EmployeeNo = "T00001";
            input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
            var inputIson = input.ToDictionary();
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/Unbind/UnbindService.cs
@@ -26,12 +26,9 @@
        try
        {
            input.SessionId = Guid.NewGuid().ToString();
            input.Software = "陈化机";
            input.EquipmentCode = "P1K10040";
            input.EmployeeNo = "T00001";
            input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
            var inputJson = input.ToDictionary();
            Console.WriteLine();
            LogFactory.GetLog("托盘单电芯解绑1").Info(true, JsonConvert.SerializeObject(inputJson));
            var x = await HttpsClient.PostAsync("http://ts-momapp01:12020/api/MachineIntegration/TrayCellUnbind", inputJson);
            LogFactory.GetLog("托盘单电芯解绑").Info(true, $"\r\r--------------------------------------");
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
@@ -1,10 +1,13 @@
using Mapster;
using log4net.Core;
using Mapster;
using Masuit.Tools;
using WIDESEA_DTO.MOM;
using WIDESEA_DTO.WMS;
using WIDESEA_IStorageBasicRepository;
using WIDESEA_IStoragIntegrationServices;
using WIDESEA_Model.Models;
using WIDESEA_StorageBasicRepository;
using WIDESEA_StorageTaskRepository;
using WIDESEA_StoragIntegrationServices;
namespace WIDESEA_StorageOutTaskServices;
@@ -83,6 +86,101 @@
    /// </summary>
    /// <param name="saveModel">任务数据合集</param>
    /// <returns>返回结果集</returns>
    //public async Task<WebResponseContent> CompleteStackTaskAsync(Dt_Task task, DtStockInfo stock)
    //{
    //    WebResponseContent content = new WebResponseContent();
    //    try
    //    {
    //        if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
    //        {
    //            var process = await SqlSugarHelper.Db.Queryable<Dt_EquipmentProcess>()
    //                 .FirstAsync(x => x.EquipmentName == task.Roadway);
    //            EquipmentParameterInfo info = JsonConvert.DeserializeObject<EquipmentParameterInfo>(process.ProcessValue);
    //            AgingOutputDto agingOutputDto = new AgingOutputDto()
    //            {
    //                OpFlag = 1,
    //                EquipmentCode = stock.LocationInfo.RoadwayNo,
    //                TrayBarcode = stock.PalletCode,
    //                SerialNos = stock.StockInfoDetails.Select(x => new SerialNoOutDto()
    //                {
    //                    SlotNo = x.OrderNo.ToInt32(),
    //                    SerialNo = x.SerialNumber,
    //                    SerialNoResult = true,
    //                    ParameterInfo = new List<ParameterInfo>()
    //                    {
    //                        new ParameterInfo()
    //                        {
    //                            LowerLomit =info.LowerControlLimit,
    //                            UpperLimit = info.UpperControlLimit,
    //                            ParameterResult = info.EquipmentAvailabilityFlag,
    //                            ParameterCode = info.ParameterCode,
    //                            ParameterDesc = info.Description,
    //                            TargetValue = info.TargetValue,
    //                            Value = info.TargetValue,
    //                            DefectCode = info.UOMCode
    //                        }
    //                    }
    //                }).ToList()
    //            };
    //            content = await _agingInOrOutInputService.GetOCVOutputAsync(agingOutputDto);
    //            var result = JsonConvert.DeserializeObject<BasicResult>(content.ToString());
    //            if (!result.Success)
    //            {
    //                throw new Exception(result.MOMMessage);
    //            }
    //        }
    //        // 更新库存状态
    //        var loation = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress);
    //        var detail = _stockInfoDetailRepository.QueryData(x => x.StockId == stock.Id);
    //        // 设置库位状态为空闲
    //        loation.LocationStatus = LocationEnum.Free.ObjToInt();
    //        // 更新任务状态
    //        task.TaskState = TaskOutStatusEnum.OutFinish.ObjToInt();
    //        task.CurrentAddress = task.NextAddress;
    //        task.NextAddress = task.TargetAddress;
    //        LogFactory.GetLog("任务完成").InfoFormat(true, "堆垛机出库完成", "更新库存状态与任务状态");
    //        // 事务处理
    //        // 开始事务
    //        _unitOfWorkManage.BeginTran();
    //        // 删除库存信息
    //        var isStockUpdated = _stockInfoRepository.DeleteDataById(stock.Id);
    //        // 删除库存信息
    //        var isStockDetailUpdated = _stockInfoDetailRepository.DeleteDataByIds(detail.Select(x => (object)x.Id).ToArray());
    //        // 删除任务信息
    //        var isTaskUpdated = BaseDal.DeleteDataById(task.TaskId);
    //        // 如果库存信息和任务信息都更新成功
    //        if (isStockUpdated && isTaskUpdated && isStockDetailUpdated)
    //        {
    //            // 记录日志
    //            LogFactory.GetLog("任务完成").InfoFormat(true, "堆垛机出库完成", $"事务处理完成,库存状态更新:{isStockUpdated},任务状态更新:{isTaskUpdated}");
    //            // 提交事务
    //            _unitOfWorkManage.CommitTran();
    //            // 返回成功结果
    //            return content.OK("任务完成成功");
    //        }
    //        else
    //        {
    //            // 记录日志
    //            LogFactory.GetLog("任务完成").InfoFormat(true, "堆垛机出库完成", $"事务处理失败,库存状态更新:{isStockUpdated},任务状态更新:{isTaskUpdated}");
    //            // 回滚事务
    //            _unitOfWorkManage.RollbackTran();
    //            // 返回失败结果
    //            return content.Error("任务或库存更新失败");
    //        }
    //    }
    //    catch (Exception err)
    //    {
    //        LogFactory.GetLog("任务完成").InfoFormat(true, $"系统异常,异常信息:{err.Message}", "");
    //        Console.WriteLine(err.Message);
    //        return content.Error(err.Message);
    //    }
    //}
    public async Task<WebResponseContent> CompleteStackTaskAsync(Dt_Task task, DtStockInfo stock)
    {
        WebResponseContent content = new WebResponseContent();
@@ -91,89 +189,126 @@
            if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
            {
                var process = await SqlSugarHelper.Db.Queryable<Dt_EquipmentProcess>()
                     .FirstAsync(x => x.EquipmentName == task.Roadway);
                EquipmentParameterInfo info = JsonConvert.DeserializeObject<EquipmentParameterInfo>(process.ProcessValue);
                AgingOutputDto agingOutputDto = new AgingOutputDto()
                {
                    OpFlag = 1,
                    EquipmentCode = stock.LocationInfo.RoadwayNo,
                    TrayBarcode = stock.PalletCode,
                    SerialNos = stock.StockInfoDetails.Select(x => new SerialNoOutDto()
                    {
                        SlotNo = x.OrderNo.ToInt32(),
                        SerialNo = x.SerialNumber,
                        SerialNoResult = true,
                        ParameterInfo = new List<ParameterInfo>()
                        {
                             new ParameterInfo()
                             {
                                  LowerLomit =info.LowerControlLimit,
                                   UpperLimit = info.UpperControlLimit,
                                   ParameterResult = info.EquipmentAvailabilityFlag,
                                   ParameterCode = info.ParameterCode,
                                    ParameterDesc = info.Description,
                                     TargetValue = info.TargetValue,
                                      Value = info.TargetValue,
                                       DefectCode = info.UOMCode
                             }
                        }
                    }).ToList()
                };
                    .FirstAsync(x => x.EquipmentName == task.Roadway);
                var info = JsonConvert.DeserializeObject<EquipmentParameterInfo>(process.ProcessValue);
                var agingOutputDto = MapToAgingOutputDto(stock, info);
                content = await _agingInOrOutInputService.GetOCVOutputAsync(agingOutputDto);
                ValidateResponse(content);
            }
            // 更新库存状态
            var loation = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress);
            var detail = _stockInfoDetailRepository.QueryData(x => x.StockId == stock.Id);
            // 设置库位状态为空闲
            loation.LocationStatus = LocationEnum.Free.ObjToInt();
            // 更新任务状态
            task.TaskState = TaskOutStatusEnum.OutFinish.ObjToInt();
            task.CurrentAddress = task.NextAddress;
            task.NextAddress = task.TargetAddress;
            LogFactory.GetLog("任务完成").InfoFormat(true, "堆垛机出库完成", "更新库存状态与任务状态");
            // 更新库存状态和任务状态
            (var loc, var tas) = UpdateStockAndTaskStatus(stock, task);
            // 事务处理
            // 开始事务
            _unitOfWorkManage.BeginTran();
            // 删除库存信息
            var isStockUpdated = _stockInfoRepository.DeleteDataById(stock.Id);
            // 删除库存信息
            var isStockDetailUpdated = _stockInfoDetailRepository.DeleteDataByIds(detail.Select(x => (object)x.Id).ToArray());
            // 删除任务信息
            var isTaskUpdated = BaseDal.DeleteDataById(task.TaskId);
            await _unitOfWorkManage.UseTranAsync(async () =>
            {
                await UpdateLocationAsync(loc);
                await DeleteStockInfoAsync(stock.Id);
                await DeleteStockInfoDetailsAsync(stock.StockInfoDetails);
                await DeleteTaskAsync(task.TaskId);
            });
            // 如果库存信息和任务信息都更新成功
            if (isStockUpdated && isTaskUpdated && isStockDetailUpdated)
            {
                // 记录日志
                LogFactory.GetLog("任务完成").InfoFormat(true, "堆垛机出库完成", $"事务处理完成,库存状态更新:{isStockUpdated},任务状态更新:{isTaskUpdated}");
                // 提交事务
                _unitOfWorkManage.CommitTran();
                // 返回成功结果
                return content.OK("任务完成成功");
            }
            else
            {
                // 记录日志
                LogFactory.GetLog("任务完成").InfoFormat(true, "堆垛机出库完成", $"事务处理失败,库存状态更新:{isStockUpdated},任务状态更新:{isTaskUpdated}");
                // 回滚事务
                _unitOfWorkManage.RollbackTran();
                // 返回失败结果
                return content.Error("任务或库存更新失败");
            }
            return content.OK("任务完成成功");
        }
        catch (Exception err)
        {
            LogFactory.GetLog("任务完成").InfoFormat(true, $"系统异常,异常信息:{err.Message}", "");
            Console.WriteLine(err.Message);
            LogFactory.GetLog("任务完成").Error(true, $"系统异常,异常信息:{err.Message}");
            return content.Error(err.Message);
        }
    }
    #endregion 堆垛机出库任务完成
    private AgingOutputDto MapToAgingOutputDto(DtStockInfo stock, EquipmentParameterInfo info)
    {
        return new AgingOutputDto
        {
            OpFlag = 1,
            EquipmentCode = stock.LocationInfo.RoadwayNo,
            TrayBarcode = stock.PalletCode,
            SerialNos = stock.StockInfoDetails.Select(x => new SerialNoOutDto
            {
                SlotNo = x.OrderNo.ToInt32(),
                SerialNo = x.SerialNumber,
                SerialNoResult = true,
                ParameterInfo = new List<ParameterInfo>
            {
                new ParameterInfo
                {
                    LowerLomit = info.LowerControlLimit,
                    UpperLimit = info.UpperControlLimit,
                    ParameterResult = info.EquipmentAvailabilityFlag,
                    ParameterCode = info.ParameterCode,
                    ParameterDesc = info.Description,
                    TargetValue = info.TargetValue,
                    Value = info.TargetValue,
                    DefectCode = info.UOMCode
                }
            }
            }).ToList()
        };
    }
    private void ValidateResponse(WebResponseContent content)
    {
        var result = JsonConvert.DeserializeObject<BasicResult>(content.ToString());
        if (!result.Success)
        {
            throw new Exception(result.MOMMessage);
        }
    }
    private (DtLocationInfo, Dt_Task) UpdateStockAndTaskStatus(DtStockInfo stock, Dt_Task task)
    {
        var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress);
        var details = _stockInfoDetailRepository.QueryData(x => x.StockId == stock.Id);
        location.LocationStatus = LocationEnum.Free.ObjToInt();
        task.TaskState = TaskOutStatusEnum.OutFinish.ObjToInt();
        task.CurrentAddress = task.NextAddress;
        task.NextAddress = task.TargetAddress;
        LogFactory.GetLog("任务完成").Info(true, "更新库存状态与任务状态");
        return (location, task);
    }
    private async Task DeleteStockInfoAsync(int stockId)
    {
        var isStockUpdated = await _stockInfoRepository.DeleteDataByIdAsync(stockId);
        if (!isStockUpdated)
        {
            throw new Exception("库存信息更新失败");
        }
    }
    private async Task UpdateLocationAsync(DtLocationInfo info)
    {
        var isStockUpdated = await _locationRepository.UpdateDataAsync(info);
        if (!isStockUpdated)
        {
            throw new Exception("库存信息更新失败");
        }
    }
    private async Task DeleteStockInfoDetailsAsync(IEnumerable<DtStockInfoDetail> details)
    {
        var ids = details.Select(x => (object)x.Id).ToArray();
        var isStockDetailUpdated = await _stockInfoDetailRepository.DeleteDataByIdsAsync(ids);
        if (!isStockDetailUpdated)
        {
            throw new Exception("库存详情信息更新失败");
        }
    }
    private async Task DeleteTaskAsync(int taskId)
    {
        var isTaskUpdated = await BaseDal.DeleteDataByIdAsync(taskId);
        if (!isTaskUpdated)
        {
            throw new Exception("任务信息更新失败");
        }
    }
    #endregion 出库任务完成
    #region 移库任务完成
@@ -215,85 +350,187 @@
    /// </summary>
    /// <param name="task">任务数据合集</param>
    /// <returns>返回结果集</returns>
    //public async Task<WebResponseContent> CompleteInboundTaskAsync(Dt_Task task)
    //{
    //    WebResponseContent content = new WebResponseContent();
    //    try
    //    {
    //        var boxing = await _boxingInfoRepository.QueryFirstNavAsync(x => x.PalletCode == task.PalletCode);
    //        var locationInf = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.TargetAddress);
    //        locationInf.LocationStatus = (int)LocationEnum.InStock;
    //        // 创建历史任务实例模型
    //        var taskHty = CreateHistoricalTask(task);
    //        // 创建库存实例模型
    //        DtStockInfo stock;
    //        if (boxing == null)
    //        {
    //            // 空托盘
    //            stock = new DtStockInfo()
    //            {
    //                PalletCode = task.PalletCode,
    //                LocationCode = task.TargetAddress,
    //                CreateDate = DateTime.Now,
    //                Creater = "system",
    //                IsFull = boxing.IsFull,
    //                StockInfoDetails = new List<DtStockInfoDetail>()
    //                {
    //                    new DtStockInfoDetail()
    //                    {
    //                         MaterielCode = "空托盘",
    //                         Id = 0,
    //                    }
    //                }
    //            };
    //        }
    //        else
    //        {
    //            // 实盘
    //            var boxDetail = boxing.BoxingInfoDetails.Adapt<List<DtStockInfoDetail>>();
    //            // 创建库存实例模型
    //            stock = new DtStockInfo()
    //            {
    //                PalletCode = task.PalletCode,
    //                LocationCode = task.TargetAddress,
    //                CreateDate = DateTime.Now,
    //                Creater = "system",
    //                IsFull = boxing.IsFull,
    //                StockInfoDetails = boxDetail,
    //            };
    //            AgingInputDto agingInputDto = new AgingInputDto()
    //            {
    //                SerialNos = boxing.BoxingInfoDetails
    //                    .Select(item => new SerialNoInDto { SerialNo = item.SerialNumber, PositionNo = item.OrderNo })
    //                    .ToList(),
    //                TrayBarcode = task.PalletCode,
    //                OpFlag = 1
    //            };
    //            var result = await _agingInOrOutInputService.GetOCVInputAsync(agingInputDto);
    //            stock.Remark = JsonConvert.DeserializeObject<ResponeAgingInputDto>(result.Data.ToString()).LinedProcessFeedbackTime;
    //            LogFactory.GetLog("任务完成").InfoFormat(true, "入库任务完成", $"货位地址:{task.TargetAddress},修改后货位数据:{locationInf}");
    //        }
    //        // 执行数据库事务
    //        bool isResult = await ExecuteTransaction(stock, taskHty, locationInf, task.TaskId);
    //        if (isResult)
    //            content.OK("入库任务完成成功");
    //        else
    //            content.Error("入库任务完成失败");
    //    }
    //    catch (Exception err)
    //    {
    //        Console.WriteLine(err.Message.ToString());
    //    }
    //    return content;
    //}
    /// <summary>
    /// 完成入库任务
    /// </summary>
    /// <param name="task">任务数据合集</param>
    /// <returns>返回结果集</returns>
    public async Task<WebResponseContent> CompleteInboundTaskAsync(Dt_Task task)
    {
        // 初始化响应内容
        WebResponseContent content = new WebResponseContent();
        try
        {
            // 获取装箱信息和目标位置信息
            var boxing = await _boxingInfoRepository.QueryFirstNavAsync(x => x.PalletCode == task.PalletCode);
            var locationInf = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.TargetAddress);
            // 更新目标位置状态为库存中
            locationInf.LocationStatus = (int)LocationEnum.InStock;
            // 创建历史任务实例模型
            var taskHty = CreateHistoricalTask(task);
            // 创建库存实例模型
            DtStockInfo stock;
            if (boxing == null)
            {
                // 空托盘
                stock = new DtStockInfo()
                {
                    PalletCode = task.PalletCode,
                    LocationCode = task.TargetAddress,
                    CreateDate = DateTime.Now,
                    Creater = "system",
                    IsFull = boxing.IsFull,
                    StockInfoDetails = new List<DtStockInfoDetail>()
                    {
                        new DtStockInfoDetail()
                        {
                             MaterielCode = "空托盘",
                             Id = 0,
                        }
                    }
                };
            }
            else
            {
                // 实盘
                var boxDetail = boxing.BoxingInfoDetails.Adapt<List<DtStockInfoDetail>>();
                // 创建库存实例模型
                stock = new DtStockInfo()
                {
                    PalletCode = task.PalletCode,
                    LocationCode = task.TargetAddress,
                    CreateDate = DateTime.Now,
                    Creater = "system",
                    IsFull = boxing.IsFull,
                    StockInfoDetails = boxDetail,
                };
                AgingInputDto agingInputDto = new AgingInputDto()
                {
                    SerialNos = boxing.BoxingInfoDetails
                        .Select(item => new SerialNoInDto { SerialNo = item.SerialNumber, PositionNo = item.OrderNo })
                        .ToList(),
                    TrayBarcode = task.PalletCode,
                    OpFlag = 1
                };
                var result = await _agingInOrOutInputService.GetOCVInputAsync(agingInputDto);
                stock.Remark = JsonConvert.DeserializeObject<ResponeAgingInputDto>(result.Data.ToString()).LinedProcessFeedbackTime;
                LogFactory.GetLog("任务完成").InfoFormat(true, "入库任务完成", $"货位地址:{task.TargetAddress},修改后货位数据:{locationInf}");
            }
            // 根据是否有组盘信息创建库存实例模型
            DtStockInfo stock = boxing == null ? CreateEmptyPalletStock(task, locationInf) : CreateFullPalletStock(task, locationInf, boxing);
            // 执行数据库事务
            bool isResult = await ExecuteTransaction(stock, taskHty, locationInf, task.TaskId);
            if (isResult)
            {
                content.OK("入库任务完成成功");
            }
            else
            {
                content.Error("入库任务完成失败");
            }
        }
        catch (Exception err)
        {
            // 记录异常信息到控制台和日志
            Console.WriteLine(err.Message.ToString());
            LogFactory.GetLog("任务完成").Error(true, err);
        }
        return content;
    }
    /// <summary>
    /// 创建空托盘的库存实例模型
    /// </summary>
    private DtStockInfo CreateEmptyPalletStock(Dt_Task task, DtLocationInfo locationInf)
    {
        return new DtStockInfo()
        {
            PalletCode = task.PalletCode,
            LocationCode = task.TargetAddress,
            CreateDate = DateTime.Now,
            Creater = "system",
            IsFull = false,
            AreaCode = task.Roadway,
            StockInfoDetails = new List<DtStockInfoDetail>()
            {
                new DtStockInfoDetail()
                {
                    MaterielCode = "空托盘",
                    Id = 0,
                }
            }
        };
    }
    /// <summary>
    /// 创建实盘的库存实例模型并调用MOM入库
    /// </summary>
    private DtStockInfo CreateFullPalletStock(Dt_Task task, DtLocationInfo locationInf, DtBoxingInfo boxing)
    {
        var boxDetail = boxing.BoxingInfoDetails.Adapt<List<DtStockInfoDetail>>();
        var stock = new DtStockInfo()
        {
            PalletCode = task.PalletCode,
            LocationCode = task.TargetAddress,
            CreateDate = DateTime.Now,
            Creater = "system",
            IsFull = boxing.IsFull,
            AreaCode = task.Roadway,
            StockInfoDetails = boxDetail,
        };
        // 处理请求参数
        AgingInputDto agingInputDto = new AgingInputDto()
        {
            SerialNos = boxing.BoxingInfoDetails
                .Select(item => new SerialNoInDto { SerialNo = item.SerialNumber, PositionNo = item.OrderNo })
                .ToList(),
            TrayBarcode = task.PalletCode,
            OpFlag = 1
        };
        var result = _agingInOrOutInputService.GetOCVInputAsync(agingInputDto).Result;
        stock.Remark = JsonConvert.DeserializeObject<ResponeAgingInputDto>(result.Data.ToString()).LinedProcessFeedbackTime;
        // 记录日志
        LogFactory.GetLog("任务完成").InfoFormat(true, "入库任务完成", $"货位地址:{task.TargetAddress},修改后货位数据:{locationInf}");
        return stock;
    }
    #endregion 入库任务完成
@@ -301,13 +538,15 @@
    #region 任务完成
    /// <summary>
    /// 任务完成
    /// 完成任务
    /// </summary>
    /// <param name="taskNum">任务号</param>
    /// <returns></returns>
    /// <param name="taskNum">任务编号</param>
    /// <returns>返回结果集</returns>
    public async Task<WebResponseContent> CompleteAsync(int taskNum)
    {
        // 初始化响应内容
        WebResponseContent content = new WebResponseContent();
        // 提取任务数据
        LogFactory.GetLog("任务完成").InfoFormat(true, "提取任务数据", $"任务号:{taskNum}");
@@ -321,61 +560,28 @@
        // 验证库存是否存在
        var stock = await _stockInfoRepository.QueryFirstAsync(x => x.PalletCode == task.PalletCode);
        if (stock == null)
        // 根据任务类型调用相应的完成任务方法
        switch (task.TaskType)
        {
            LogFactory.GetLog("任务完成").InfoFormat(true, "库存不存在存在,判断是否是入库任务", $"{task.TaskType}");
            if (task.TaskType == (int)TaskInboundTypeEnum.Inbound)
            {
            case (int)TaskInboundTypeEnum.Inbound:
            case (int)TaskInboundTypeEnum.InTray:
                LogFactory.GetLog("任务完成").InfoFormat(true, "入库任务", "");
                return await CompleteInboundTaskAsync(task);
            }
            else if (task.TaskType == (int)TaskInboundTypeEnum.InTray)
            {
                LogFactory.GetLog("任务完成").InfoFormat(true, "空托盘入库", "");
                return await CompleteInboundTaskAsync(task);
            }
            else
            {
                LogFactory.GetLog("任务完成").InfoFormat(true, "任务状态异常", "");
                return content.Error("任务状态异常");
            }
        }
        LogFactory.GetLog("任务完成").InfoFormat(true, "验证库存是否存在", JsonConvert.SerializeObject(stock));
        if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
        {
            LogFactory.GetLog("任务完成").InfoFormat(true, "出库任务", "");
            if (task.TaskState == TaskOutStatusEnum.Line_OutFinish.ObjToInt())
            {
                LogFactory.GetLog("任务完成").InfoFormat(true, "堆垛机出库完成", "");
            case (int)TaskOutboundTypeEnum.OutTray:
            case (int)TaskOutboundTypeEnum.Outbound:
                LogFactory.GetLog("任务完成").InfoFormat(true, "出库任务", "");
                return await CompleteStackTaskAsync(task, stock);
            }
            else if (task.TaskState == TaskOutStatusEnum.SC_OutExecuting.ObjToInt())
            {
                LogFactory.GetLog("任务完成").InfoFormat(true, "库存不存在也不是入库任务", "");
                return content.Error("库存不存在");
            }
            else
            {
                LogFactory.GetLog("任务完成").InfoFormat(true, "任务状态异常", "");
                return content.Error("任务状态异常");
            }
        }
        else if (task.TaskType == (int)TaskTypeEnum.RelocationIn)
        {
            LogFactory.GetLog("任务完成").InfoFormat(true, "移库任务完成", "");
            return await CompleteTransferTaskAsync(task, stock);
        }
        else
        {
            LogFactory.GetLog("任务完成").InfoFormat(true, $"任务状态异常", "无参数");
            return content.Error("任务状态异常");
            default:
                return content.Error("任务类型不存在");
        }
    }
    #endregion 任务完成
    #region 请求任务
    #region 请求任务入库
    /// <summary>
    /// 请求任务
@@ -505,64 +711,222 @@
        }
    }
    #endregion 请求任务
    #endregion 请求任务入库
    #region 请求空托盘
    #region 请求出库
    public async Task<WebResponseContent> RequestTrayTaskAsync(string position)
    //public async Task<WebResponseContent> RequestTrayTaskAsync(string position, int tag, string areaCdoe,List<string> roadways)
    //{
    //    WebResponseContent content = new WebResponseContent();
    //    try
    //    {
    //        // 1==实盘 2 ==空盘
    //        if (tag == 1)
    //        {
    //            // 查询库存信息
    //            DtStockInfo? stockInfo = _stockInfoRepository.QueryData(x => x.AreaCode == areaCdoe && Convert.ToDateTime(x.Remark) < DateTime.Now && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && roadways.Contains(x.LocationInfo.RoadwayNo)).OrderBy(x => x.CreateDate).FirstOrDefault();
    //            // 创建新任务实例
    //            var task = new Dt_Task()
    //            {
    //                Grade = 1,
    //                Roadway = stockInfo.LocationInfo.RoadwayNo,
    //                TargetAddress = position,
    //                Dispatchertime = DateTime.Now,
    //                MaterialNo = "",
    //                NextAddress = position,
    //                OrderNo = null,
    //                PalletCode = stockInfo.PalletCode,
    //                SourceAddress = stockInfo.LocationCode,
    //                TaskState = (int)TaskOutStatusEnum.OutNew,
    //                TaskType = (int)TaskOutboundTypeEnum.Outbound,
    //                TaskNum = await BaseDal.GetTaskNo(),
    //                Creater = "Systeam"
    //            };
    //            var taskId = await BaseDal.AddDataAsync(task);
    //            bool isResult = taskId > 0;
    //            if (isResult)
    //            {
    //                WMSTaskDTO taskDTO = new WMSTaskDTO()
    //                {
    //                    TaskNum = task.TaskNum.Value,
    //                    Grade = 1,
    //                    PalletCode = DateTime.Now.ToString("MMddHHmmss"),
    //                    RoadWay = task.Roadway,
    //                    SourceAddress = stockInfo.LocationCode,
    //                    TargetAddress = task.Roadway,
    //                    TaskState = (int)TaskOutStatusEnum.OutNew,
    //                    Id = 0,
    //                    TaskType = (int)TaskOutboundTypeEnum.OutTray
    //                };
    //                stockInfo.LocationInfo.LocationStatus = (int)LocationEnum.InStockDisable;
    //                _locationRepository.UpdateData(stockInfo.LocationInfo);
    //                content.OK(data: taskDTO);
    //            }
    //        }
    //        else
    //        {
    //            var stockInfo = _stockInfoRepository.QueryData(x => x.AreaCode == areaCdoe && x.StockInfoDetails.Any(z => z.MaterielCode == "空托盘") && roadways.Contains(x.LocationInfo.RoadwayNo)).OrderBy(x => x.CreateDate).FirstOrDefault();
    //            // 创建新任务实例
    //            var task = new Dt_Task
    //            {
    //                CurrentAddress = stockInfo.LocationCode,
    //                Grade = 1,
    //                Roadway = stockInfo.LocationInfo.RoadwayNo,
    //                TargetAddress = position,
    //                Dispatchertime = DateTime.Now,
    //                MaterialNo = "",
    //                NextAddress = position,
    //                OrderNo = null,
    //                PalletCode = stockInfo.PalletCode,
    //                SourceAddress = stockInfo.LocationCode,
    //                TaskState = (int)TaskOutStatusEnum.OutNew,
    //                TaskType = (int)TaskOutboundTypeEnum.OutTray,
    //                TaskNum = await BaseDal.GetTaskNo(),
    //                Creater = "Systeam"
    //            };
    //            var taskId = await BaseDal.AddDataAsync(task);
    //            bool isResult = taskId > 0;
    //            if (isResult)
    //            {
    //                WMSTaskDTO taskDTO = new WMSTaskDTO()
    //                {
    //                    TaskNum = task.TaskNum.Value,
    //                    Grade = 1,
    //                    PalletCode = DateTime.Now.ToString("MMddHHmmss"),
    //                    RoadWay = task.Roadway,
    //                    SourceAddress = stockInfo.LocationCode,
    //                    TargetAddress = task.Roadway,
    //                    TaskState = (int)TaskOutStatusEnum.OutNew,
    //                    Id = 0,
    //                    TaskType = (int)TaskOutboundTypeEnum.OutTray
    //                };
    //                content.OK(data: taskDTO);
    //            }
    //        }
    //    }
    //    catch (Exception ex)
    //    {
    //        throw;
    //    }
    //    return content;
    //}
    /// <summary>
    /// 请求托盘任务
    /// </summary>
    /// <param name="position">目标位置</param>
    /// <param name="tag">托盘类型(1:实盘,2:空盘)</param>
    /// <param name="areaCode">区域编码</param>
    /// <param name="roadways">巷道编码集合</param>
    /// <returns>返回结果集</returns>
    public async Task<WebResponseContent> RequestTrayTaskAsync(string position, int tag, string areaCode, List<string> roadways)
    {
        WebResponseContent content = new WebResponseContent();
        try
        {
            var area = _areaInfoRepository.QueryFirst(x => x.AreaCode == "CH");
            // 根据托盘类型查询库存信息
            DtStockInfo stockInfo = tag == 1
                ? QueryStockInfoForRealTray(areaCode, roadways)
                : QueryStockInfoForEmptyTray(areaCode, roadways);
            var stockInfo = _stockInfoRepository.QueryData(x => x.LocationInfo.AreaId == area.AreaID && x.StockInfoDetails.Any(z => z.MaterielCode == "空托盘")).OrderBy(x => x.CreateDate).FirstOrDefault();
            // 创建新任务实例
            var task = new Dt_Task
            if (stockInfo == null)
            {
                CurrentAddress = stockInfo.LocationCode,
                Grade = 1,
                Roadway = stockInfo.LocationInfo.RoadwayNo,
                TargetAddress = position,
                Dispatchertime = DateTime.Now,
                MaterialNo = "",
                NextAddress = position,
                OrderNo = null,
                PalletCode = stockInfo.PalletCode,
                SourceAddress = stockInfo.LocationCode,
                TaskState = (int)TaskOutStatusEnum.OutNew,
                TaskType = (int)TaskOutboundTypeEnum.OutTray,
                TaskNum = await BaseDal.GetTaskNo(),
                Creater = "Systeam"
            };
                return content.Error("库存信息不存在");
            }
            // 创建新任务实例
            var task = CreateTask(stockInfo, position, tag);
            var taskId = await BaseDal.AddDataAsync(task);
            bool isResult = taskId > 0;
            if (isResult)
            if (!isResult)
            {
                WMSTaskDTO taskDTO = new WMSTaskDTO()
                {
                    TaskNum = task.TaskNum.Value,
                    Grade = 1,
                    PalletCode = DateTime.Now.ToString("MMddHHmmss"),
                    RoadWay = task.Roadway,
                    SourceAddress = stockInfo.LocationCode,
                    TargetAddress = task.Roadway,
                    TaskState = (int)TaskOutStatusEnum.OutNew,
                    Id = 0,
                    TaskType = (int)TaskOutboundTypeEnum.OutTray
                };
                content.OK(data: taskDTO);
                return content.Error("任务创建失败");
            }
            // 创建任务DTO
            WMSTaskDTO taskDTO = CreateTaskDTO(task);
            if (tag == 1)
            {
                // 更新库存位置状态为不可用
                stockInfo.LocationInfo.LocationStatus = (int)LocationEnum.InStockDisable;
                await _locationRepository.UpdateDataAsync(stockInfo.LocationInfo);
            }
            // 返回成功响应
            return content.OK(data: taskDTO);
        }
        catch (Exception ex)
        {
            // 记录异常信息并抛出
            LogFactory.GetLog("请求托盘任务").Error(true, ex);
            throw;
        }
        return content;
    }
    #endregion 请求空托盘
    /// <summary>
    /// 查询实盘库存信息
    /// </summary>
    private DtStockInfo QueryStockInfoForRealTray(string areaCode, List<string> roadways)
    {
        return _stockInfoRepository.QueryData(x => x.AreaCode == areaCode && Convert.ToDateTime(x.Remark) < DateTime.Now && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && roadways.Contains(x.LocationInfo.RoadwayNo))
                                   .OrderBy(x => x.CreateDate)
                                   .FirstOrDefault();
    }
    /// <summary>
    /// 查询空盘库存信息
    /// </summary>
    private DtStockInfo QueryStockInfoForEmptyTray(string areaCode, List<string> roadways)
    {
        return _stockInfoRepository.QueryData(x => x.AreaCode == areaCode && x.StockInfoDetails.Any(z => z.MaterielCode == "空托盘") && roadways.Contains(x.LocationInfo.RoadwayNo))
                                   .OrderBy(x => x.CreateDate)
                                   .FirstOrDefault();
    }
    /// <summary>
    /// 创建任务实例
    /// </summary>
    private Dt_Task CreateTask(DtStockInfo stockInfo, string position, int tag)
    {
        return new Dt_Task
        {
            Grade = 1,
            Roadway = stockInfo.LocationInfo.RoadwayNo,
            TargetAddress = position,
            Dispatchertime = DateTime.Now,
            MaterialNo = "",
            NextAddress = position,
            OrderNo = null,
            PalletCode = stockInfo.PalletCode,
            SourceAddress = stockInfo.LocationCode,
            TaskState = (int)TaskOutStatusEnum.OutNew,
            TaskType = tag == 1 ? (int)TaskOutboundTypeEnum.Outbound : (int)TaskOutboundTypeEnum.OutTray,
            TaskNum = BaseDal.GetTaskNo().Result,
            Creater = "System" // 修正拼写错误
        };
    }
    /// <summary>
    /// 创建任务DTO
    /// </summary>
    private WMSTaskDTO CreateTaskDTO(Dt_Task task)
    {
        return new WMSTaskDTO
        {
            TaskNum = task.TaskNum.Value,
            Grade = 1,
            PalletCode = task.PalletCode,
            RoadWay = task.Roadway,
            SourceAddress = task.SourceAddress,
            TargetAddress = task.TargetAddress,
            TaskState = task.TaskState.Value,
            Id = 0,
            TaskType = task.TaskType,
        };
    }
    #endregion 请求出库
    #region 陈化请求出库
@@ -573,8 +937,8 @@
        try
        {
            var area = _areaInfoRepository.QueryFirst(x => x.AreaName == "陈化区");
            // 查询库存信息
            // 查询库存信息
            var stockInfo = _stockInfoRepository.QueryData(x => x.AreaCode == area.AreaCode && Convert.ToDateTime(x.Remark) < DateTime.Now && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock).OrderBy(x => x.CreateDate).FirstOrDefault();
            // 创建新任务实例
            var task = new Dt_Task()
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/TaskController.cs
@@ -61,8 +61,8 @@
    /// <param name="input">请求数据</param>
    /// <returns></returns>
    [HttpPost, AllowAnonymous, Route("RequestTrayTaskAsync")]
    public async Task<WebResponseContent> RequestTrayTaskAsync([FromBody] string position)
    public async Task<WebResponseContent> RequestTrayTaskAsync([FromBody] string position, int tag, string areaCdoe, List<string> roadways)
    {
        return await Service.RequestTrayTaskAsync(position);
        return await Service.RequestTrayTaskAsync(position, tag, areaCdoe, roadways);
    }
}