Admin
2026-01-16 d5fe80c5cb7dc0b209d8fea9faa84c7ca5b20324
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -16,9 +16,14 @@
#endregion << ç‰ˆ æœ¬ æ³¨ é‡Š >>
using AutoMapper;
using Microsoft.Extensions.Logging;
using Org.BouncyCastle.Math.EC;
using SqlSugar;
using System.ComponentModel;
using System.Net;
using System.Reflection;
using System.Reflection.Emit;
using System.Threading.Tasks;
using WIDESEA_Common.LocationEnum;
using WIDESEA_Common.OtherEnum;
using WIDESEA_Common.StockEnum;
@@ -26,6 +31,7 @@
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Task;
@@ -41,13 +47,14 @@
{
    public partial class TaskService : ServiceBase<Dt_Task, IRepository<Dt_Task>>, ITaskService
    {
        private readonly ILogger<TaskService> _logger;
        private readonly IMapper _mapper;
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        private readonly IStockInfoService _stockInfoService;
        private readonly ILocationInfoService _locationInfoService;
        private readonly IWarehouseService _warehouseService;
        private readonly IRoadWayinfoService _roadWayinfoService;
        private Timer _timer;
        public IRepository<Dt_Task> Repository => BaseDal;
        private Dictionary<string, OrderByType> _taskOrderBy = new()
@@ -60,9 +67,10 @@
        public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList();
        public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IStockInfoService stockInfoService, ILocationInfoService locationInfoService,
        public TaskService(ILogger<TaskService> logger, IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IStockInfoService stockInfoService, ILocationInfoService locationInfoService,
            IWarehouseService warehouseService, IRoadWayinfoService roadWayinfoService) : base(BaseDal)
        {
            _logger = logger;
            _mapper = mapper;
            _unitOfWorkManage = unitOfWorkManage;
            _stockInfoService = stockInfoService;
@@ -118,10 +126,14 @@
        private WebResponseContent HandleInboundTask(Dt_Task task, int wcsTaskType)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
            switch (wcsTaskType)
            {
                case 1:
                    task.TaskStatus = (int)InTaskStatusEnum.PLC_InFinish;
                        if(task.TargetAddress == "")
                        {
                    int loctype = 0;
                    if (task.Roadway == "1" || task.Roadway == "2")
                    {
@@ -132,6 +144,7 @@
                    {
                         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);
@@ -142,21 +155,60 @@
                    task.CurrentAddress = task.NextAddress;
                    task.NextAddress= dt_Location.LocationCode;
                    task.TaskStatus = (int)InTaskStatusEnum.PLC_InFinish;
                    dt_Location.LocationStatus = (int)LocationStatusEnum.Lock;
                            Dt_StockInfo dt_StockInfo = new Dt_StockInfo();
                            dt_StockInfo.PalletCode = task.PalletCode;
                            dt_StockInfo.PalletType = task.PalletType;
                            dt_StockInfo.WarehouseId = task.WarehouseId;
                            dt_StockInfo.LocationCode = dt_Location.LocationCode;
                            dt_StockInfo.StockStatus = (int)StockStatusEmun.入库中;
                            dt_StockInfo.Creater = "MWS";
                            dt_StockInfo.CreateDate = DateTime.Now;
                            _unitOfWorkManage.BeginTran();
                            _stockInfoService.AddData(dt_StockInfo);
                    _locationInfoService.UpdateData(dt_Location);
                    BaseDal.UpdateData(task);
                            _unitOfWorkManage.CommitTran();
                    return content.OK($"已接收入库输送线完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                        }
                        else
                        {
                            string Resultplc = MesInTaskStatusEnum.入库完成.GetDescription();
                            MES_parameter mES_PCLParameter = InStoreDocCallback(task.TaskNum, Resultplc, "操作成功", task.PalletCode, task.TargetAddress);
                            if (mES_PCLParameter.Result == "Y")
                            {
                                task.TaskStatus = (int)InTaskStatusEnum.PLC_InFinish;
                                _unitOfWorkManage.BeginTran();
                                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成);
                                _unitOfWorkManage.CommitTran();
                                return content.OK($"输送线任务已反馈至上游,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                            }
                            else
                            {
                                return content.Error("上传MES失败,原因:" + mES_PCLParameter.ResultMsg);
                            }
                        }
                case 2:
                        string Resultsc = MesInTaskStatusEnum.入库完成.GetDescription();
                    //上报MES任务完成
                    MES_parameter mES_Parameter = InStoreDocCallback(task.TaskNum, "Finish", "操作成功", task.PalletCode, task.TargetAddress);
                        MES_parameter mES_Parameter = InStoreDocCallback(task.TaskNum, Resultsc, "操作成功", task.PalletCode, task.TargetAddress);
                    if (mES_Parameter.Result == "Y")
                    {
                            Dt_StockInfo dt_Stockowc = _stockInfoService.Repository.QueryData(x => x.PalletCode == task.PalletCode).FirstOrDefault();
                            Dt_LocationInfo dt_LocationInfo=_locationInfoService.Repository.QueryData(x => x.LocationCode == dt_Stockowc.LocationCode).FirstOrDefault();
                        task.TaskStatus = (int)InTaskStatusEnum.SC_OutFinish;
                        BaseDal.DeleteData(task);
                            dt_Stockowc.StockStatus = (int)StockStatusEmun.已入库;
                            dt_LocationInfo.LocationStatus = (int)LocationStatusEnum.InStock;
                            task.TaskStatus = (int)InTaskStatusEnum.InFinish;
                            _unitOfWorkManage.BeginTran();
                            _stockInfoService.UpdateData(dt_Stockowc);
                            _locationInfoService.UpdateData(dt_LocationInfo);
                            BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成);
                            _unitOfWorkManage.CommitTran();
                        return content.OK($"已接收入库堆垛机完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                    }
                    else
@@ -164,22 +216,31 @@
                        return content.Error("上传MES失败,原因:" + mES_Parameter.ResultMsg);
                    }
                default:
                    return WebResponseContent.Instance.Error($"WCS上报类型错误:{wcsTaskType}");
                        return content.Error($"WCS上报类型错误:{wcsTaskType}");
                }
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return content.Error($"WCS任务完成接口故障,原因:{ex.Message}");
            }
        }
        private WebResponseContent HandleOutboundTask(Dt_Task task, int wcsTaskType)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
            switch (wcsTaskType)
            {
                case 1:
                        string Resultplc = MesOutTaskStatusEnum.到达目的地.GetDescription();
                    //上报MES任务完成
                    MES_parameter mES_Parameter = OutStoreDocCallback(task.TaskNum, "Finish", "操作成功");
                        MES_parameter mES_Parameter = OutStoreDocCallback(task.TaskNum, Resultplc, "操作成功");
                    if (mES_Parameter.Result == "Y")
                    {
                        task.TaskStatus = (int)OutTaskStatusEnum.PLC_OutFinish;
                        BaseDal.DeleteData(task);
                            BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成);
                        return content.OK($"已接收出库输送线完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                    }
                    else
@@ -192,25 +253,54 @@
                    task.CurrentAddress = _Roadwayinfo.OutStationCode;
                    task.NextAddress = task.TargetAddress;
                    task.TaskStatus = (int)OutTaskStatusEnum.SC_OutFinish;
                        Dt_StockInfo dt_Stockowc = _stockInfoService.Repository.QueryData(x => x.PalletCode == task.PalletCode).FirstOrDefault();
                        Dt_LocationInfo dt_LocationInfo = _locationInfoService.Repository.QueryData(x => x.LocationCode == dt_Stockowc.LocationCode).FirstOrDefault();
                        _unitOfWorkManage.BeginTran();
                        _stockInfoService.DeleteData(dt_Stockowc);
                        _locationInfoService.DeleteData(dt_LocationInfo);
                    BaseDal.UpdateData(task);
                        _unitOfWorkManage.CommitTran();
                    return content.OK($"已接收出库堆垛机完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                default:
                    return content.Error($"WCS上报类型错误:{wcsTaskType}");
            }
        }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return content.Error($"WCS任务完成接口故障,原因:{ex.Message}");
            }
        }
        private WebResponseContent HandleRelocationTask(Dt_Task task, int wcsTaskType)
        {
            WebResponseContent responseContent = new WebResponseContent();
            if (wcsTaskType == 2)
            {
                //上报MES堆垛机移库任务
                string Resultplc = MesOutTaskStatusEnum.到达目的地.GetDescription();
                //上报MES任务完成
                MES_parameter mES_Parameter = AbnormalStorageLocation(task.PalletCode, task.SourceAddress, task.TargetAddress);
                if (mES_Parameter.Result == "Y")
                {
                task.TaskStatus = (int)RelocationTaskStatusEnum.RelocationFinish;
                BaseDal.UpdateData(task);
                    BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成);
                return WebResponseContent.Instance.OK($"已接收移库堆垛机完成信息,任务号:{task.TaskId},托盘编号:{task.PalletCode}");
                }
                else
                {
                    return responseContent.Error("上传MES失败,原因:" + mES_Parameter.ResultMsg);
                }
            }
            return WebResponseContent.Instance.Error($"WCS上报类型错误:{wcsTaskType}");
        }
       
    }
}