Admin
2026-01-15 7d6194cf002b8f54d41cdc50b7f1b1843c1da636
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -17,12 +17,17 @@
using AutoMapper;
using SqlSugar;
using System.Net;
using System.Reflection;
using WIDESEA_Common.LocationEnum;
using WIDESEA_Common.OtherEnum;
using WIDESEA_Common.StockEnum;
using WIDESEA_Common.TaskEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Task;
using WIDESEA_IBasicService;
using WIDESEA_IInboundService;
@@ -55,10 +60,16 @@
        public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList();
        public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal)
        public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IStockInfoService stockInfoService, ILocationInfoService locationInfoService,
            IWarehouseService warehouseService, IRoadWayinfoService roadWayinfoService) : base(BaseDal)
        {
            _mapper = mapper;
            _unitOfWorkManage = unitOfWorkManage;
            _stockInfoService = stockInfoService;
            _locationInfoService = locationInfoService;
            _warehouseService = warehouseService;
            _roadWayinfoService=roadWayinfoService;
        }
        public string MES_InReporttask = WIDESEA_Core.Helper.AppSettings.Configuration["MES_InReporttask"]; //入库反馈信息
        public string MES_OutReporttask = WIDESEA_Core.Helper.AppSettings.Configuration["MES_OutReporttask"];   //出库反馈信息
@@ -79,11 +90,12 @@
        /// <returns></returns>
        public WebResponseContent TaskCompleted(WCSTaskDTO wCSTask)
        {
            WebResponseContent webResponse= new WebResponseContent();
            try
            {
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskId == wCSTask.TaskNum && x.PalletCode == wCSTask.PalletCode);
                if (task == null)
                    return WebResponseContent.Instance.Error("未找到任务信息");
                    return webResponse.Error("未找到任务信息");
                switch ((TaskTypeEnum)task.TaskType)
                {
@@ -94,27 +106,63 @@
                    case TaskTypeEnum.Relocation:
                        return HandleRelocationTask(task, wCSTask.TaskType);
                    default:
                        return WebResponseContent.Instance.Error($"任务类型错误,任务号:{task.TaskId},托盘编号:{task.PalletCode},类型:{task.TaskType}");
                        return webResponse.Error($"任务类型错误,任务号:{task.TaskId},托盘编号:{task.PalletCode},类型:{task.TaskType}");
                }
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error($"WMS任务完成错误:{ex.Message}");
                return webResponse.Error($"WMS任务完成错误:{ex.Message}");
            }
        }
        private WebResponseContent HandleInboundTask(Dt_Task task, int wcsTaskType)
        {
            WebResponseContent content = new WebResponseContent();
            switch (wcsTaskType)
            {
                case 1:
                    task.TaskStatus = (int)InTaskStatusEnum.PLC_InFinish;
                    int loctype = 0;
                    if (task.Roadway == "1" || task.Roadway == "2")
                    {
                        if(task.PalletType=="1") loctype = (int)LocationTypeEnum.SmallPallet;
                        else if(task.PalletType=="2") loctype = (int)LocationTypeEnum.MediumPallet;
                    }
                    else
                    {
                         loctype = (int)LocationTypeEnum.LargePallet;
                    }
                    //查找货位,更新任务
                    Dt_LocationInfo dt_Location=_locationInfoService.GetLocation(task.Roadway, loctype);
                    Dt_LocationInfo ShallowCargoHold = _locationInfoService.ShallowGetLocation(dt_Location.RoadwayNo, dt_Location.LocationType, dt_Location.Row, dt_Location.Layer, dt_Location.Column);
                    if(ShallowCargoHold==null) return content.Error($"未找到该货位信息,货位编号:{dt_Location.LocationCode}的浅货位");
                    if(ShallowCargoHold.LocationStatus != (int)LocationStatusEnum.Free) return content.Error($"任务号:{task.TaskId},托盘编号:{task.PalletCode},查找的货位浅货位有货,货位编号:{ShallowCargoHold.LocationCode}");
                    task.TargetAddress = dt_Location.LocationCode;
                    task.CurrentAddress = task.NextAddress;
                    task.NextAddress= dt_Location.LocationCode;
                    task.TaskStatus = (int)InTaskStatusEnum.PLC_InFinish;
                    dt_Location.LocationStatus = (int)LocationStatusEnum.Lock;
                    _locationInfoService.UpdateData(dt_Location);
                    BaseDal.UpdateData(task);
                    return WebResponseContent.Instance.OK($"已接收入库输送线完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                    return content.OK($"已接收入库输送线完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                case 2:
                    //上报MES任务完成
                    MES_parameter mES_Parameter = InStoreDocCallback(task.TaskNum, "Finish", "操作成功", task.PalletCode, task.TargetAddress);
                    if (mES_Parameter.Result == "Y")
                    {
                    task.TaskStatus = (int)InTaskStatusEnum.SC_OutFinish;
                    BaseDal.UpdateData(task);
                    return WebResponseContent.Instance.OK($"已接收入库堆垛机完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                        BaseDal.DeleteData(task);
                        return content.OK($"已接收入库堆垛机完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                    }
                    else
                    {
                        return content.Error("上传MES失败,原因:" + mES_Parameter.ResultMsg);
                    }
                default:
                    return WebResponseContent.Instance.Error($"WCS上报类型错误:{wcsTaskType}");
            }
@@ -122,18 +170,32 @@
        private WebResponseContent HandleOutboundTask(Dt_Task task, int wcsTaskType)
        {
            WebResponseContent content = new WebResponseContent();
            switch (wcsTaskType)
            {
                case 1:
                    //上报MES任务完成
                    MES_parameter mES_Parameter = OutStoreDocCallback(task.TaskNum, "Finish", "操作成功");
                    if (mES_Parameter.Result == "Y")
                    {
                    task.TaskStatus = (int)OutTaskStatusEnum.PLC_OutFinish;
                    BaseDal.UpdateData(task);
                    return WebResponseContent.Instance.OK($"已接收出库输送线完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                        BaseDal.DeleteData(task);
                        return content.OK($"已接收出库输送线完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                    }
                    else
                    {
                        return content.Error("上传MES失败,原因:" + mES_Parameter.ResultMsg);
                    }
                case 2:
                    //获取对应PLC站台信息
                    Dt_roadwayinfo _Roadwayinfo = _roadWayinfoService.QbtainPlatform(task.Roadway);
                    task.CurrentAddress = _Roadwayinfo.OutStationCode;
                    task.NextAddress = task.TargetAddress;
                    task.TaskStatus = (int)OutTaskStatusEnum.SC_OutFinish;
                    BaseDal.UpdateData(task);
                    return WebResponseContent.Instance.OK($"已接收出库堆垛机完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                    return content.OK($"已接收出库堆垛机完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                default:
                    return WebResponseContent.Instance.Error($"WCS上报类型错误:{wcsTaskType}");
                    return content.Error($"WCS上报类型错误:{wcsTaskType}");
            }
        }
@@ -147,5 +209,8 @@
            }
            return WebResponseContent.Instance.Error($"WCS上报类型错误:{wcsTaskType}");
        }
    }
}