wanshenmean
2025-04-16 29f20b28392d212c04c0c40a512894f8622cfa53
CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Partial/TaskService.cs
@@ -2,12 +2,14 @@
using Mapster;
using Newtonsoft.Json;
using System.Diagnostics.CodeAnalysis;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob.Models;
namespace WIDESEAWCS_TaskInfoService
{
@@ -221,28 +223,28 @@
                    return content.Error("当前托盘存在任务");
                }
                // 检查是否已存在直接出库任务
                if (await HasDirectOutboundTask(stationManager))
                {
                    return content.Error($"【{stationManager.stationChildCode}】已存在直接出库任务任务");
                }
                //// 检查是否已存在直接出库任务
                //if (await HasDirectOutboundTask(stationManager))
                //{
                //    return content.Error($"【{stationManager.stationChildCode}】已存在直接出库任务任务");
                //}
                if (stationManager.stationType == 7)
                {
                    var result = await HandleStationType7(palletCode, stationManager);
                    if (result != null)
                    {
                        return result;
                    }
                }
                else if (stationManager.stationType == 6)
                {
                    var result = await HandleStationType6(palletCode, stationManager);
                    if (result != null)
                    {
                        return result;
                    }
                }
                //if (stationManager.stationType == 7)
                //{
                //    var result = await HandleStationType7(palletCode, stationManager);
                //    if (result != null)
                //    {
                //        return result;
                //    }
                //}
                //else if (stationManager.stationType == 6)
                //{
                //    var result = await HandleStationType6(palletCode, stationManager);
                //    if (result != null)
                //    {
                //        return result;
                //    }
                //}
                // 发起请求获取入库任务
                content = await RequestInTask(palletCode, stationManager);
@@ -279,38 +281,9 @@
        }
        // 处理 stationType 为 7 的情况
        private async Task<WebResponseContent> HandleStationType7(string palletCode, Dt_StationManager stationManager)
        private async Task<WebResponseContent> HandleStationType7(Dt_StationManager stationManager)
        {
            var station = await _stationManagerRepository.QueryFirstAsync(x => x.stationType == 6 && x.productLine == stationManager.productLine && x.stationArea == stationManager.stationArea);
            var runTask = await BaseDal.QueryFirstAsync(x => x.CurrentAddress == station.stationChildCode && x.TaskState == (int)TaskInStatusEnum.Line_InFinish && x.TaskType == (int)TaskInboundTypeEnum.InTray);
            if (runTask != null)
            {
                runTask.TargetAddress = stationManager.stationLocation;
                runTask.NextAddress = stationManager.stationChildCode;
                runTask.Grade = 3;
                runTask.TaskType = (int)TaskOutboundTypeEnum.InToOut;
                runTask.TaskState = (int)TaskOutStatusEnum.OutNew;
                var wmsIpAddrss = GetWmsIpAddress(SysConfigKeyConst.SetEmptyOutbyInToOutAsync);
                var result = await HttpHelper.PostAsync(wmsIpAddrss, new { palletCode = runTask.PalletCode, EquiCodeMOM = stationManager.stationEquipMOM, Roadways = stationManager.Roadway, area = stationManager.stationArea, Position = station.stationChildCode }.ToJsonString());
                var content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                if (content.Status)
                {
                    await BaseDal.UpdateDataAsync(runTask);
                    ConsoleHelper.WriteSuccessLine($"【{runTask.PalletCode}直接出库至二封】");
                    return content.OK("成功");
                }
                else
                {
                    ConsoleHelper.WriteErrorLine(content.Message);
                }
            }
            else
            {
                ConsoleHelper.WriteErrorLine($"【{station.stationChildCode}】未找到空托盘入库任务");
            }
            var station = await _taskNeedBarcodeRepository.QueryFirstAsync(x => x.toArea == stationManager.stationChildCode && x.productLine == stationManager.productLine);
            return null;
        }
@@ -368,7 +341,7 @@
        private async Task<WebResponseContent> RequestInTask(string palletCode, Dt_StationManager stationManager)
        {
            var wmsIpAddrss = GetWmsIpAddress(SysConfigKeyConst.RequestInTask);
            var result = await HttpHelper.PostAsync(wmsIpAddrss, new { palletCode = palletCode, EquiCodeMOM = stationManager.stationEquipMOM, Roadways = stationManager.Roadway, area = stationManager.stationArea, Position = stationManager.stationChildCode }.ToJsonString());
            var result = await HttpHelper.PostAsync(wmsIpAddrss, new { palletCode = palletCode, EquiCodeMOM = stationManager.stationEquipMOM, Roadways = stationManager.Roadway, area = stationManager.stationArea, Position = stationManager.stationChildCode, ProductionLine = stationManager.productLine}.ToJsonString());
            return JsonConvert.DeserializeObject<WebResponseContent>(result);
        }
@@ -417,6 +390,7 @@
        public WebResponseContent ReceiveByWMSTask([NotNull] WMSTaskDTO taskDTO)
        {
            WebResponseContent content = new WebResponseContent();
            ConsoleHelper.WriteSuccessLine($"接收到任务,任务数据:{JsonConvert.SerializeObject(taskDTO, Formatting.Indented)}");
            try
            {
                if (BaseDal.QueryFirst(x => x.TaskNum == taskDTO.TaskNum || x.PalletCode == taskDTO.PalletCode) != null)
@@ -428,12 +402,47 @@
                if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                {
                    var stationinfo = _stationManagerRepository.QueryFirst(x => x.stationLocation == taskDTO.TargetAddress && x.Roadway == taskDTO.RoadWay);
                    task.TaskState = (int)TaskOutStatusEnum.OutNew;
                    task.CurrentAddress = taskDTO.RoadWay;
                    task.NextAddress = stationinfo.stationChildCode;
                    task.SourceAddress = taskDTO.SourceAddress;
                    task.TargetAddress = taskDTO.TargetAddress;
                    if (task.TaskType == (int)TaskOutboundTypeEnum.OutTray)
                    {
                        // 查询下一个路由
                        List<Dt_Router> routers = _routerService.QueryNextRoutes(taskDTO.RoadWay, taskDTO.TargetAddress);
                        if (routers.Count > 0)
                        {
                            // 设置任务状态为出库新建
                            task.TaskState = (int)TaskOutStatusEnum.OutNew;
                            // 设置当前地址为源地址
                            task.CurrentAddress = taskDTO.SourceAddress;
                            // 设置下一个地址为第一个子位置
                            task.NextAddress = routers.FirstOrDefault().ChildPosi;
                        }
                        else
                        {
                            // 查询从源地址到目标地址的路由
                            routers = _routerService.QueryNextRoutes(taskDTO.SourceAddress, taskDTO.TargetAddress);
                            if (routers.Count > 0)
                            {
                                // 设置任务状态为出库完成
                                task.TaskState = (int)TaskOutStatusEnum.SC_OutFinish;
                                // 设置当前地址为源地址
                                task.CurrentAddress = taskDTO.SourceAddress;
                                // 设置下一个地址为第一个子位置
                                task.NextAddress = routers.FirstOrDefault().ChildPosi;
                            }
                        }
                    }
                    else
                    {
                        var stationinfo = _stationManagerRepository.QueryFirst(x => x.stationLocation == taskDTO.TargetAddress && x.Roadway == taskDTO.RoadWay);
                        task.TaskState = (int)TaskOutStatusEnum.OutNew;
                        task.CurrentAddress = taskDTO.RoadWay;
                        task.NextAddress = stationinfo.stationChildCode;
                        task.SourceAddress = taskDTO.SourceAddress;
                        task.TargetAddress = taskDTO.TargetAddress;
                        //if (taskDTO.TaskType == (int)TaskOutboundTypeEnum.InToOut)
                        //{
                        //    task.TaskState = (int)TaskInStatusEnum.Line_InFinish;
                        //}
                    }
                }
                else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
                {
@@ -613,30 +622,6 @@
                var task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
                if (task == null) return WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】");
                //if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup && task.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting)
                //{
                //    //todo
                //}
                //else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup && task.TaskState == (int)TaskInStatusEnum.SC_InExecuting)
                //{
                //    //todo 同步到WMS
                //    BaseDal.DeleteData(task);
                //}
                //else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
                //{
                //    //todo 调用WMS移库完成
                //}
                //else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OtherGroup)
                //{
                //}
                //else
                //{
                //    throw new Exception($"任务类型错误,未找到该任务类型,任务号:【{taskNum}】,任务类型:【{task.TaskType}】");
                //}
                #region WMS同步任务完成
                var keys = new Dictionary<string, object>()
@@ -666,21 +651,7 @@
                    BaseDal.DeleteData(task);
                }
                #region 更新任务状态
                //var updateTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.UpdateTask)?.ConfigValue;
                //if (wmsBase == null || updateTask == null)
                //{
                //    throw new InvalidOperationException("WMS IP 未配置");
                //}
                //wmsIpAddress = wmsBase + updateTask;
                //result = HttpHelper.PostAsync(wmsIpAddress, new { TaskNum = task.TaskNum, TaskState = task.TaskState }.ToJsonString()).Result;
                //content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                #endregion 更新任务状态
                //content = WebResponseContent.Instance.OK();
                content.OK(data: task);
            }
            catch (Exception ex)
            {
@@ -688,5 +659,9 @@
            }
            return content;
        }
        //public override WebResponseContent DeleteData(Dt_Task entity)
        //{
        //    return base.DeleteData(entity);
        //}
    }
}