From b593c2d4ada3244f4a256ca18a23c3fef609f234 Mon Sep 17 00:00:00 2001
From: Admin <Admin@ADMIN>
Date: 星期日, 18 一月 2026 17:31:48 +0800
Subject: [PATCH] 最新

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |  291 ++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 214 insertions(+), 77 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
index c48f46f..f4d430c 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
@@ -16,9 +16,15 @@
 #endregion << 鐗� 鏈� 娉� 閲� >>
 
 using AutoMapper;
+using Microsoft.Extensions.Logging;
+using Org.BouncyCastle.Math.EC;
+using SixLabors.ImageSharp;
 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 +32,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 +48,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 +68,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;
@@ -78,8 +87,6 @@
         public string MES_TaskErrorInfoCallback = WIDESEA_Core.Helper.AppSettings.Configuration["MES_TaskErrorInfoCallback"];   //浠诲姟寮傚父涓婃姤
         public string WCS_SendConveyorTask = WIDESEA_Core.Helper.AppSettings.Configuration["WCS_SendConveyorTask"];   //杈撻�佺嚎浠诲姟涓嬪彂
         public string WCS_SendStackerTask = WIDESEA_Core.Helper.AppSettings.Configuration["WCS_SendStackerTask"];   //鍫嗗灈鏈轰换鍔′笅鍙�
-
-
 
 
 
@@ -118,99 +125,229 @@
         private WebResponseContent HandleInboundTask(Dt_Task task, int wcsTaskType)
         {
             WebResponseContent content = new WebResponseContent();
-            switch (wcsTaskType)
+            try
             {
-                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}");
+                switch (wcsTaskType)
+                {
+                    case 1:
 
-                    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;
+                        if (string.IsNullOrEmpty(task.TargetAddress))
+                        {
+                            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;
+                            }
 
-                    _locationInfoService.UpdateData(dt_Location);
-                    BaseDal.UpdateData(task);
-                    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")
-                    {
+                            //鏌ユ壘璐т綅锛屾洿鏂颁换鍔�
+                            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.TaskStatus = (int)InTaskStatusEnum.SC_OutFinish;
-                        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}");
+                            if (task.PalletCode[0] == 1 && (dt_Location.RoadwayNo == "1" || dt_Location.RoadwayNo == "2") && dt_Location.Column < 4)
+                            {
+                                return content.Error($"鏉$爜涓洪珮鎵樼洏锛屼絾鏄煡鎵剧殑璐т綅瑕佸叆鍦ㄤ綆鎵樼洏涓嬶紝鏁呴殰,鎵樼洏鏉$爜锛歿task.PalletCode},璐т綅缂栧彿:{dt_Location.LocationCode}");
+                            }
+
+
+                            Dt_roadwayinfo _Roadwayinfo = _roadWayinfoService.QbtainPlatform(task.Roadway);
+
+                            task.TargetAddress = dt_Location.LocationCode;
+                            task.CurrentAddress = _Roadwayinfo.InSCStationCode;
+                            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, 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();
+
+                            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
+                        {
+                            return content.Error("涓婁紶MES澶辫触锛屽師鍥狅細" + mES_Parameter.ResultMsg);
+                        }
+                    default:
+                        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();
-            switch (wcsTaskType)
+            try
             {
-                case 1:
-                    //涓婃姤MES浠诲姟瀹屾垚
-                    MES_parameter mES_Parameter = OutStoreDocCallback(task.TaskNum, "Finish", "鎿嶄綔鎴愬姛");
-                    if (mES_Parameter.Result == "Y")
-                    {
-                        task.TaskStatus = (int)OutTaskStatusEnum.PLC_OutFinish;
-                        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 content.OK($"宸叉帴鏀跺嚭搴撳爢鍨涙満瀹屾垚淇℃伅锛屼换鍔″彿锛歿task.TaskId},鎵樼洏缂栧彿锛歿task.PalletCode}");
-                default:
-                    return content.Error($"WCS涓婃姤绫诲瀷閿欒锛歿wcsTaskType}");
+                switch (wcsTaskType)
+                {
+                    case 1:
+                        string Resultplc = MesOutTaskStatusEnum.鍒拌揪鐩殑鍦�.GetDescription();
+                        //涓婃姤MES浠诲姟瀹屾垚
+                        MES_parameter mES_Parameter = OutStoreDocCallback(task.TaskNum, Resultplc, "鎿嶄綔鎴愬姛");
+                        if (mES_Parameter.Result != "Y")
+                        {
+                            task.TaskStatus = (int)OutTaskStatusEnum.PLC_OutFinish;
+                            BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
+                            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;
+
+                        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();
+                        dt_LocationInfo.LocationStatus = (int)LocationStatusEnum.Free;
+
+                        string Result = MesOutTaskStatusEnum.鍑哄簱瀹屾垚.GetDescription();
+                        //璋冨彇涓婃父绯荤粺鍙嶉寮�濮嬩换鍔�
+                        MES_parameter mES_SCParameter = OutStoreDocCallback(task.TaskNum, Result, "鎿嶄綔鎴愬姛");
+                        if (mES_SCParameter.Result != "Y")
+                        {
+                            _unitOfWorkManage.BeginTran();
+                            _stockInfoService.DeleteData(dt_Stockowc);
+                            _locationInfoService.UpdateData(dt_LocationInfo);
+                            BaseDal.UpdateData(task);
+                            _unitOfWorkManage.CommitTran();
+                            return content.OK($"宸叉帴鏀跺嚭搴撳爢鍨涙満瀹屾垚淇℃伅锛屼换鍔″彿锛歿task.TaskId},鎵樼洏缂栧彿锛歿task.PalletCode}");
+                        }
+                        else
+                        {
+                            return content.Error("涓婁紶MES澶辫触锛屽師鍥狅細" + mES_SCParameter.ResultMsg);
+                        }
+                    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)
         {
-            if (wcsTaskType == 2)
+            WebResponseContent responseContent = new WebResponseContent();
+            try
             {
-                task.TaskStatus = (int)RelocationTaskStatusEnum.RelocationFinish;
-                BaseDal.UpdateData(task);
-                return WebResponseContent.Instance.OK($"宸叉帴鏀剁Щ搴撳爢鍨涙満瀹屾垚淇℃伅锛屼换鍔″彿锛歿task.TaskId},鎵樼洏缂栧彿锛歿task.PalletCode}");
+                if (wcsTaskType == 2)
+                {
+                    //涓婃姤MES浠诲姟瀹屾垚
+                    MES_parameter mES_Parameter = AbnormalStorageLocation(task.PalletCode, task.SourceAddress, task.TargetAddress);
+                    if (mES_Parameter.Result == "Y")
+                    {
+                        Dt_LocationInfo OriginalLocation = _locationInfoService.Repository.QueryData(x => x.LocationCode == task.SourceAddress).FirstOrDefault();
+                        Dt_LocationInfo NewLocation = _locationInfoService.Repository.QueryData(x => x.LocationCode == task.TargetAddress).FirstOrDefault();
+                        Dt_StockInfo dt_StockInfo = _stockInfoService.Repository.QueryData(x => x.LocationCode == task.TargetAddress).FirstOrDefault();
+
+                        List<Dt_LocationInfo> dt_Locations = new List<Dt_LocationInfo>();
+
+                        OriginalLocation.LocationStatus = (int)LocationStatusEnum.Free;
+                        NewLocation.LocationStatus = (int)LocationStatusEnum.InStock;
+                        dt_StockInfo.LocationCode = NewLocation.LocationCode;
+                        dt_StockInfo.StockStatus = (int)StockStatusEmun.宸插叆搴�;
+                        task.TaskStatus = (int)RelocationTaskStatusEnum.RelocationFinish;
+
+                        dt_Locations.Add(OriginalLocation);
+                        dt_Locations.Add(NewLocation);
+
+                        _unitOfWorkManage.BeginTran();
+                        _locationInfoService.UpdateData(dt_Locations);
+                        _stockInfoService.UpdateData(dt_StockInfo);
+                        BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
+                        _unitOfWorkManage.CommitTran();
+
+                        return WebResponseContent.Instance.OK($"宸叉帴鏀剁Щ搴撳爢鍨涙満瀹屾垚淇℃伅锛屼换鍔″彿锛歿task.TaskId},鎵樼洏缂栧彿锛歿task.PalletCode}");
+                    }
+                    else
+                    {
+                        return responseContent.Error("涓婁紶MES澶辫触锛屽師鍥狅細" + mES_Parameter.ResultMsg);
+                    }
+                }
+                else
+                {
+                    return WebResponseContent.Instance.Error($"WCS涓婃姤绫诲瀷閿欒锛歿wcsTaskType}");
+                }
             }
-            return WebResponseContent.Instance.Error($"WCS涓婃姤绫诲瀷閿欒锛歿wcsTaskType}");
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error($"WMS绯荤粺閿欒锛屽師鍥狅細{ex.Message}");
+            }
+            
         }
 
 
-       
+        
+
     }
 }

--
Gitblit v1.9.3