From 51af2794f47d5b68496edbc09d0ccb168347f02b Mon Sep 17 00:00:00 2001
From: HuBingJie <3146306518@qq.com>
Date: 星期六, 22 十一月 2025 10:19:05 +0800
Subject: [PATCH] 1

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |  726 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 706 insertions(+), 20 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
index 610010b..ead1c5c 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
@@ -1,4 +1,4 @@
-锘�#region << 鐗� 鏈� 娉� 閲� >>
+#region << 鐗� 鏈� 娉� 閲� >>
 /*----------------------------------------------------------------
  * 鍛藉悕绌洪棿锛歐IDESEA_TaskInfoService
  * 鍒涘缓鑰咃細鑳$搴�
@@ -21,15 +21,23 @@
 using Microsoft.AspNetCore.Mvc;
 using Newtonsoft.Json;
 using SqlSugar;
+using System.Diagnostics;
+using System.DirectoryServices.Protocols;
+using System.Net;
+using System.Reflection.Emit;
+using System.Threading.Tasks;
 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.Const;
 using WIDESEA_Core.Enums;
 using WIDESEA_Core.Helper;
 using WIDESEA_DTO.Task;
+using WIDESEA_DTO.ToMes;
 using WIDESEA_IBasicService;
 using WIDESEA_IInboundService;
 using WIDESEA_IOutboundService;
@@ -49,6 +57,9 @@
         private readonly IRepository<Dt_LocationInfo> _locationInfoRepository;
         private readonly IRepository<Dt_RoadwayInfo> _roadwayInforepository;
         private readonly IBasicService _basicService;
+        private readonly IDt_ApiInfoService _dt_ApiInfoService;
+        private readonly ILocationStatusChangeRecordService _locationStatusChangeRecordService;
+        private readonly IStationMangerService _stationMangerService;
 
         public IRepository<Dt_Task> Repository => BaseDal;
 
@@ -58,11 +69,7 @@
                 {nameof(Dt_Task.CreateDate),OrderByType.Asc},
             };
 
-        public List<int> TaskTypes => typeof(TaskTypeEnum).GetEnumIndexList();
-
-        public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList();
-
-        public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_StockInfo> stockRepository, IBasicService basicService, IRepository<Dt_Warehouse> warehouseRepository, IRepository<Dt_LocationInfo> locationInfoRepository, IRepository<Dt_RoadwayInfo> roadwayInforepository) : base(BaseDal)
+        public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_StockInfo> stockRepository, IBasicService basicService, IRepository<Dt_Warehouse> warehouseRepository, IRepository<Dt_LocationInfo> locationInfoRepository, IRepository<Dt_RoadwayInfo> roadwayInforepository, IDt_ApiInfoService dt_ApiInfoService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IStationMangerService stationMangerService) : base(BaseDal)
         {
             _mapper = mapper;
             _unitOfWorkManage = unitOfWorkManage;
@@ -71,7 +78,15 @@
             _warehouseRepository = warehouseRepository;
             _locationInfoRepository = locationInfoRepository;
             _roadwayInforepository = roadwayInforepository;
+            _dt_ApiInfoService = dt_ApiInfoService;
+            _locationStatusChangeRecordService = locationStatusChangeRecordService;
+            _stationMangerService=stationMangerService;
         }
+        public int GetTaskNum(string sequenceName)
+        {
+            return Db.Ado.GetScalar($"SELECT NEXT VALUE FOR {sequenceName}").ObjToInt();
+        }
+
         /// <summary>
         /// 浠诲姟淇℃伅鎺ㄩ�佽嚦WCS
         /// </summary>
@@ -85,36 +100,205 @@
                 {
                     x.AGVArea = agvDescription;
                 });
-                string url = AppSettings.Get("WCSApiAddress");
-                if (string.IsNullOrEmpty(url))
-                {
-                    return WebResponseContent.Instance.Error($"鏈壘鍒癢CSApi鍦板潃,璇锋鏌ラ厤缃枃浠�");
-                }
-                string response = HttpHelper.Post($"{url}/api/Task/ReceiveTask", taskDTOs.Serialize());
 
-                return JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("杩斿洖閿欒");
+                var ConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_WCS_IPAddress, SysConfigConst.WCSReceiveTask);      //鑾峰彇鍒皐cs鍏ㄩ儴绫诲瀷鐨勬帴鍙�
+                string WCSReceiveTaskAPI = ConfigsAPIInfo.ApiAddress + ConfigsAPIInfo.ApiName;
+
+                var respon = HttpHelper.Post(WCSReceiveTaskAPI, JsonConvert.SerializeObject(taskDTOs));
+                if (respon != null)
+                {
+                    WebResponseContent respone = JsonConvert.DeserializeObject<WebResponseContent>(respon.ToString());
+                    if (respone.Status)
+                    {
+                        return WebResponseContent.Instance.OK();
+                    }
+                    else
+                    {
+                        return WebResponseContent.Instance.Error($"涓嬪彂鍑哄簱澶辫触锛屽師鍥狅細{respone.Message}锛�");
+                    }
+                }
+                else
+                {
+                    return WebResponseContent.Instance.Error("浠诲姟涓嬪彂澶辫触锛�");
+                }
             }
             catch (Exception ex)
             {
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
+        
+
+
+        /// <summary>
+        /// 鍒ゆ柇宸烽亾鍐呯Щ搴�
+        /// </summary>
+        /// <param name="TaskNum"></param>
+        /// <param name="SourceAddress"></param>
+        /// <returns></returns>
+        public WebResponseContent IsRelocations(int TaskNum)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                List<Dt_LocationInfo> loca = new List<Dt_LocationInfo>();
+
+                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == TaskNum);
+                if (task == null) return content.Error($"鏈壘鍒拌浠诲姟淇℃伅锛屼换鍔″彿锛歿TaskNum}");
+                string Locatask = task.SourceAddress;
+
+                //鑾峰彇鍒版繁搴撲綅缂栧彿
+                Dt_LocationInfo DeepLocation = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == Locatask);
+                if(DeepLocation == null) return content.Error($"鏈壘鍒拌璐т綅淇℃伅,璐т綅缂栧彿:{Locatask}");
+
+                //杩涜鑾峰彇娴呭簱浣嶇紪鍙�
+                int locrow = DeepLocation.Row == 1 ? 2 : 3;
+                Dt_LocationInfo ShallowLocation = _basicService.LocationInfoService.Repository.QueryFirst(x =>x.Row== locrow && x.Layer== DeepLocation.Layer && x.Column== DeepLocation.Column && x.RoadwayNo== DeepLocation.RoadwayNo);
+                if (ShallowLocation == null) return content.Error($"鏈壘鍒拌揣浣嶇紪鍙�:{Locatask}鐨勬祬璐т綅");
+
+                if (ShallowLocation.LocationStatus == (int)LocationStatusEnum.Free)
+                {
+                    return content.OK(data: task);  //鐩存帴杩斿洖褰撳墠鏌ヨ鐨勪换鍔�
+                }
+
+
+                //濡傛灉鏈夎揣锛屽垯鐢熸垚绉诲簱浠诲姟
+                if (ShallowLocation.LocationStatus == (int)LocationStatusEnum.InStock)
+                {
+                    Dt_StockInfo dt_Stock = _stockRepository.QueryFirst(x => x.LocationCode == ShallowLocation.LocationCode);
+                    if (dt_Stock == null) return content.Error($"璐т綅缂栧彿:{Locatask}鐨勬祬璐т綅搴撳瓨寮傚父锛岃妫�鏌ワ紒锛侊紒");
+
+                    //杩涜鑾峰彇鏂扮殑搴撲綅
+                    Dt_LocationInfo? Nextlocation = _basicService.LocationInfoService.GetLocation(DeepLocation.RoadwayNo);//鑾峰彇鍒版柊搴撲綅
+                    if (Nextlocation == null)
+                    {
+                        return content.Error($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅");
+                    }
+                    ShallowLocation.LocationStatus = (int)LocationStatusEnum.Lock;
+                    Nextlocation.LocationStatus = (int)LocationStatusEnum.Lock;
+                    loca.Add(ShallowLocation);
+                    loca.Add(Nextlocation);
+
+                    _unitOfWorkManage.BeginTran();
+                    //鐢熸垚绉诲姩浠诲姟
+                    Dt_Task dt_Task = new()
+                    {
+                        PalletCode = dt_Stock.PalletCode,
+                        TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
+                        Roadway = Nextlocation.RoadwayNo,
+                        TaskType = TaskRelocationTypeEnum.Relocation.ObjToInt(),
+                        TaskStatus = TaskRelocationStatusEnum.RelocationNew.ObjToInt(),
+                        SourceAddress = ShallowLocation.LocationCode,
+                        TargetAddress = Nextlocation.LocationCode,
+                        CurrentAddress = ShallowLocation.LocationCode,
+                        NextAddress = Nextlocation.LocationCode,
+                        Grade = 1,
+                        Creater = "WMS",
+                        Depth = Nextlocation.Depth,
+                        CreateDate = DateTime.Now,
+                    };
+
+                    _locationInfoRepository.UpdateData(loca);
+                    BaseDal.AddData(dt_Task);   //鏂板浠诲姟
+                    _unitOfWorkManage.CommitTran();
+
+                    return content.OK(data: dt_Task);
+                }
+                else
+                {
+                    return content.Error($"璐т綅缂栧彿:{Locatask}鐨勬祬璐т綅鐘舵�佸紓甯革紝娴呰揣浣嶇紪鍙凤細{ShallowLocation.LocationCode}");
+                }
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                throw;
+            }
+        }
+
+        /// <summary>
+        /// 浠诲姟瀹屾垚
+        /// </summary>
+        /// <param name="taskNum">浠诲姟缂栧彿</param>
+        /// <param name="HowWorks">妯″紡锛�1锛氳嚜鍔紝2锛氭墜鍔級</param>
+        /// <returns></returns>
+        public WebResponseContent TaskCompleted(int taskNum)
+        {
+            WebResponseContent content = new WebResponseContent();
+
+            Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+            if (task == null) return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔′俊鎭�");
+            switch (task.TaskType)
+            {
+                case (int)TaskRelocationTypeEnum.Relocation:
+                    return RelocationInTaskCompleted(task);
+                case (int)TaskInboundTypeEnum.Inbound:
+                    return InboundTaskCompleted(task);
+                case (int)TaskOutboundTypeEnum.Outbound:
+                    return OutboundTaskCompleted(task);
+                default: return content.Error($"浠诲姟绫诲瀷閿欒锛屼换鍔″彿锛歿task.TaskNum}");
+            }
+        }
+
+        /// <summary>
+        /// 绉诲簱瀹屾垚鏂规硶
+        /// </summary>
+        /// <param name="task"></param>
+        /// <returns></returns>
+        public WebResponseContent RelocationInTaskCompleted(Dt_Task task)
+        {
+            WebResponseContent webResponse = new WebResponseContent();
+            try
+            {
+                Dt_StockInfo stockInfo = _stockRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
+                Dt_LocationInfo locationpoint = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
+                Dt_LocationInfo locationEnd = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+                List<Dt_LocationInfo> loca = new List<Dt_LocationInfo>();
+                stockInfo.LocationCode = locationEnd.LocationCode;
+                stockInfo.StockStatus = StockStatusEmun.宸插叆搴�.ObjToInt();
+                locationpoint.LocationStatus = LocationStatusEnum.Free.ObjToInt();
+                locationEnd.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+                loca.Add(locationpoint);
+                loca.Add(locationEnd);
+
+                _unitOfWorkManage.BeginTran();
+                _stockRepository.UpdateData(stockInfo);
+                _basicService.LocationInfoService.Repository.UpdateData(loca);
+                BaseDal.DeleteData(task);
+                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
+
+                WebResponseContent content = MES_TransferCompletionFeedback(task);
+                //content.Status = true;
+
+                if (!content.Status)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    return content;
+                }
+
+                _unitOfWorkManage.CommitTran();
+                return webResponse.OK();
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return webResponse.Error($"绉诲簱浠诲姟瀹屾垚澶辫触锛屼换鍔d锛歿task.TaskNum}");
+                throw;
+            }
+            
+        }
+
         /// <summary>
         /// 鍏ュ簱浠诲姟瀹屾垚
         /// </summary>
         /// <param name="tasknum"></param>
         /// <returns></returns>
-        public WebResponseContent InboundTaskCompleted(int taskNum)
+        public WebResponseContent InboundTaskCompleted(Dt_Task task)
         {
             try
             {
-                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
-                if (task == null)
-                {
-                    return WebResponseContent.Instance.Error($"鏈壘鍒拌浠诲姟淇℃伅");
-                }
                 Dt_Warehouse warehouse = _warehouseRepository.QueryFirst(x => x.WarehouseId == task.WarehouseId);
-                Dt_StockInfo stockInfo = _stockRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == task.PalletCode && x.WarehouseId == task.WarehouseId).Includes(x => x.Details).First();
+                Dt_StockInfo stockInfo = _stockRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == task.PalletCode && x.WarehouseId == task.WarehouseId).First();
                 if (stockInfo == null)
                 {
                     return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩樺搴旂殑缁勭洏淇℃伅");
@@ -130,13 +314,27 @@
                 }
                 dt_LocationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                 stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+
                 _unitOfWorkManage.BeginTran();
                 //淇敼璐т綅鐘舵�佷负鏈夎揣
                 _locationInfoRepository.UpdateData(dt_LocationInfo);
                 //淇敼搴撳瓨鐘舵��
                 _stockRepository.UpdateData(stockInfo);
+                task.TaskStatus = (int)TaskInStatusEnum.InFinish;
                 //鍒犻櫎浠诲姟娣诲姞鍘嗗彶
                 BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
+
+
+                WebResponseContent content = TaskCompletionFeedback(task);
+                //content.Status = true;
+                if (!content.Status)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    return content;
+                }
+
+                //Thread.Sleep(5000);
+
                 _unitOfWorkManage.CommitTran();
             }
             catch (Exception)
@@ -146,5 +344,493 @@
             }
             return WebResponseContent.Instance.OK();
         }
+
+        /// <summary>
+        /// 鍑哄簱浠诲姟瀹屾垚
+        /// </summary>
+        /// <param name="task"></param>
+        /// <returns></returns>
+        public WebResponseContent OutboundTaskCompleted(Dt_Task task)
+        {
+            WebResponseContent webResponse = new WebResponseContent();
+            try
+            {
+                Dt_StockInfo stockInfo = _stockRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
+                if (stockInfo == null) return webResponse.Error($"浠诲姟缂栧彿锛歿task.TaskNum},鏈壘鍒版墭鐩橈細{stockInfo.PalletCode}鐨勫簱瀛樹俊鎭�");
+                Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.SourceAddress);
+                if (locationInfo == null) return webResponse.Error($"浠诲姟缂栧彿锛歿task.TaskNum},鏈壘鍒版墭鐩橈細{stockInfo.PalletCode}鐨勮揣浣嶄俊鎭�");
+
+
+                stockInfo.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
+                
+                int beforeStatus = locationInfo.LocationStatus;
+                locationInfo.LocationStatus =(int)LocationStatusEnum.Free;
+                task.TaskStatus = TaskOutStatusEnum.OutFinish.ObjToInt();
+
+                _unitOfWorkManage.BeginTran();
+
+                _stockRepository.DeleteData(stockInfo);
+                _locationInfoRepository.UpdateData(locationInfo);   //淇敼鎴愮┖璐т綅
+
+                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
+                _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt(), "1", task.TaskNum);
+                WebResponseContent content = TaskCompletionFeedback(task);
+                //content.Status = true;
+
+                if (!content.Status)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    return content;
+                }
+                //Thread.Sleep(5000);
+                _unitOfWorkManage.CommitTran();
+                return webResponse.OK();
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return webResponse.Error($"鍑哄簱浠诲姟瀹屾垚澶辫触锛屼换鍔d锛歿task.TaskNum},閿欒鍘熷洜锛歿ex.Message}");
+                throw;
+            }
+            
+        }
+
+
+
+
+
+
+
+        //==============================================绉诲簱瀹屾垚鍙嶉鎺ュ彛====================================================
+        /// <summary>
+        /// 涓婁紶绉诲簱浠诲姟瀹屾垚缁橫ES
+        /// </summary>
+        /// <param name="dt_Task"></param>
+        /// <returns></returns>
+        public WebResponseContent MES_TransferCompletionFeedback(Dt_Task dt_Task)
+        {
+            WebResponseContent webResponse = new WebResponseContent();
+
+            try
+            {
+                string locationCode = null;
+                if (dt_Task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
+                {
+                    locationCode = dt_Task.SourceAddress;
+                }
+                else
+                {
+                    locationCode = dt_Task.TargetAddress;
+                }
+                TransferRequest transferRequest = new TransferRequest()
+                {
+                    //涓氬姟id锛屼换鍔d鍚庣画杩涜鏇存敼
+                    taskId = dt_Task.MEStaskId,   //浠诲姟id
+                    businessId = dt_Task.MESbusinessId,   //涓氬姟id
+                    sourceLocationCode = dt_Task.SourceAddress,
+                    locationCode = locationCode,
+                    palletCode = dt_Task.PalletCode,
+                    status = "FINISH",
+                    errorStatus = "NORMAL",
+                    errorInfo = "",
+                };
+
+                //鑾峰彇鎺ュ彛杩涜璋冨彇
+                var ConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_MES_IPAddress, SysConfigConst.MESTransferCompletionFeedback);      //鑾峰彇鍒皐cs鍏ㄩ儴绫诲瀷鐨勬帴鍙�
+                string WCSReceiveTaskAPI = ConfigsAPIInfo.ApiAddress + ConfigsAPIInfo.ApiName;
+                if (WCSReceiveTaskAPI == null)
+                {
+                   return webResponse.Error($"鍑哄簱澶辫触锛屾湭閰嶇疆MES绉诲簱瀹屾垚鍙嶉鎺ュ彛");
+                }
+                var respon = HttpHelper.Post(WCSReceiveTaskAPI, JsonConvert.SerializeObject(transferRequest));
+                if (respon != null)
+                {
+                   var response = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
+                   if (response.Success)
+                   {
+                       return webResponse.OK();
+                   }
+                   else
+                   {
+                       return webResponse.Error($"璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁板師鍥狅細{response.Message}");
+                   }
+                }
+                else
+                {
+                   return webResponse.Error($"璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁颁负绌�");
+                }
+
+                return webResponse.OK();
+            }
+            catch (Exception ex)
+            {
+                return webResponse.Error($"绉诲簱浠诲姟涓婁紶澶辫触锛佸師鍥狅細{ex.Message}");
+                throw;
+            }
+        }
+
+
+        /// <summary>
+        /// 涓婁紶鍑哄叆搴撲换鍔″畬鎴愮粰MES
+        /// </summary>
+        /// <param name="dt_Task"></param>
+        /// <returns></returns>
+        public WebResponseContent TaskCompletionFeedback(Dt_Task dt_Task)
+        {
+            WebResponseContent webResponse = new WebResponseContent();
+
+            try
+            {
+                string locationCode = null;
+                if (dt_Task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
+                {
+                    locationCode = dt_Task.SourceAddress;
+                }
+                else
+                {
+                    locationCode = dt_Task.TargetAddress;
+                }
+                TaskNotification transferRequest = new TaskNotification()
+                    {
+                        //涓氬姟id锛屼换鍔d鍚庣画杩涜鏇存敼
+                        taskId = dt_Task.MEStaskId,   //浠诲姟id
+                        businessId = dt_Task.MESbusinessId,   //涓氬姟id
+                        palletCode = dt_Task.PalletCode,
+                        subPalletCode = dt_Task.MESsubPalletCode,//瀛愭墭鐩樼紪鐮�
+                        locationCode = locationCode,
+                        errorStatus = "NORMAL",
+                        errorInfo = "",
+                    };
+
+                //鑾峰彇鎺ュ彛杩涜璋冨彇
+                var ConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_MES_IPAddress, SysConfigConst.MESTaskFeedback);      //鑾峰彇鍒皐cs鍏ㄩ儴绫诲瀷鐨勬帴鍙�
+                string WCSReceiveTaskAPI = ConfigsAPIInfo.ApiAddress + ConfigsAPIInfo.ApiName;
+                if (WCSReceiveTaskAPI == null)
+                {
+                    return webResponse.Error($"浠诲姟鍙嶉MES澶辫触锛屾湭閰嶇疆MES浠诲姟瀹屾垚鍙嶉鎺ュ彛");
+                }
+                
+                // 娣诲姞璋冭瘯淇℃伅
+                string requestJson = JsonConvert.SerializeObject(transferRequest);
+                //Console.WriteLine($"MES鍙嶉鎺ュ彛URL: {WCSReceiveTaskAPI}");
+                //Console.WriteLine($"MES鍙嶉璇锋眰鏁版嵁: {requestJson}");
+                
+                // 浣跨敤淇鍚庣殑PostSync鏂规硶锛堝凡鍦≒ostSync涓缃粯璁よ姹傚ご锛�
+                var respon = HttpHelper.Post(WCSReceiveTaskAPI, requestJson);
+                if (respon != null)
+                {
+                    var response = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
+                    if (response.Success)
+                    {
+                        return webResponse.OK();
+                    }
+                    else
+                    {
+                        return webResponse.Error($"璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁板師鍥狅細{response.Message}");
+                    }
+                }
+                else
+                {
+                    return webResponse.Error($"璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁颁负绌�");
+                }
+            }
+            catch (Exception ex)
+            {
+                return webResponse.Error($"浠诲姟浠诲姟涓婁紶澶辫触锛佸師鍥狅細{ex.Message}");
+                throw;
+            }
+        }
+
+        public ApiResponse<object> MESresponse(string Message, bool Success,int  Code)
+        {
+            ApiResponse<object> apiResponse = new ApiResponse<object>();
+            apiResponse.Message = Message;
+            apiResponse.Success = Success;
+            apiResponse.Code = 1;
+            return apiResponse;
+        }
+
+        /// <summary>
+        /// 鍙栨秷浠诲姟鎺ュ彛
+        /// </summary>
+        /// <param name="taskNum">浠诲姟鍙�</param>
+        /// <returns></returns>
+        public WebResponseContent Cancelinventory(int taskNum)
+        {
+            WebResponseContent webResponse = new WebResponseContent();
+            try
+            {
+                // 鏌ユ壘浠诲姟
+                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.TaskStatus == TaskOutStatusEnum.OutFinish.ObjToInt());
+                if (task == null)
+                {
+                    return webResponse.Error($"鏈壘鍒颁换鍔″彿涓恒�恵taskNum}銆戠殑浠诲姟淇℃伅");
+                }
+
+                bool res;
+                switch (task.TaskType)
+                {
+                    case (int)TaskInboundTypeEnum.Inbound:
+                        res = task.TaskStatus == TaskInStatusEnum.Line_InExecuting.ObjToInt();
+                        break;
+                    case (int)TaskOutboundTypeEnum.Outbound:
+                        res = task.TaskStatus == TaskOutStatusEnum.OutNew.ObjToInt();
+                        break;
+                    case (int)TaskRelocationTypeEnum.Relocation:
+                        res = task.TaskStatus == TaskRelocationStatusEnum.RelocationNew.ObjToInt();
+                        break;
+                    default:
+                        res = false;
+                        break;
+                }
+                if (!res) return WebResponseContent.Instance.Error("浠诲姟鐘舵�佸紓甯�");
+
+                Dt_StockInfo stockInfo = _stockRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
+
+                _unitOfWorkManage.BeginTran();
+
+                int stockmsseg;
+                int locationmsseg;
+                bool taskmsseg;
+                if (task.TaskType == TaskOutboundTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskRelocationTypeEnum.Relocation.ObjToInt())
+                {
+                    stockmsseg = _stockRepository.Db.Updateable<Dt_StockInfo>()
+                  .SetColumns(x => x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt())
+                  .Where(x => x.PalletCode == task.PalletCode)
+                  .ExecuteCommand();
+                    locationmsseg = _locationInfoRepository.Db.Updateable<Dt_LocationInfo>()
+          .SetColumns(x => x.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
+          .Where(x => x.LocationCode == stockInfo.LocationCode)
+          .ExecuteCommand();
+                    taskmsseg = BaseDal.DeleteData(task);
+                }
+                else
+                {
+                    locationmsseg = _locationInfoRepository.Db.Updateable<Dt_LocationInfo>()
+                    .SetColumns(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt())
+                    .Where(x => x.LocationCode == stockInfo.LocationCode)
+                    .ExecuteCommand();
+                    stockmsseg = _stockRepository.DeleteData(stockInfo).ObjToInt();
+                    taskmsseg = BaseDal.DeleteData(task);
+                }
+                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
+                //鑾峰彇鎺ュ彛杩涜璋冨彇
+                var ConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_MES_IPAddress, SysConfigConst.WCSCancelinventory);      //鑾峰彇鍒皐cs鍏ㄩ儴绫诲瀷鐨勬帴鍙�
+                string WCSReceiveTaskAPI = ConfigsAPIInfo.ApiAddress + ConfigsAPIInfo.ApiName;
+                if (WCSReceiveTaskAPI == null)
+                {
+                    return webResponse.Error($"浠诲姟鍙嶉MES澶辫触锛屾湭閰嶇疆MES浠诲姟瀹屾垚鍙嶉鎺ュ彛");
+                }
+                var respon = HttpHelper.Get(WCSReceiveTaskAPI, JsonConvert.SerializeObject(task.TaskNum));
+                if (respon != null)
+                {
+                    var response = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
+                    //    if (response.Success)
+                    //    {
+                    //        return webResponse.OK();
+                    //    }
+                    //    else
+                    //    {
+                    //        return webResponse.Error($"璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁板師鍥狅細{response.Message}");
+                    //    }
+                    //}
+                    //else
+                    //{
+                    //    return webResponse.Error($"璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁颁负绌�");
+                    //}
+                    if (stockmsseg > 0 && locationmsseg > 0 && taskmsseg)
+                    {
+                        _unitOfWorkManage.CommitTran();
+                        return webResponse.OK("浠诲姟鍙栨秷鎴愬姛");
+
+                    }
+
+                }
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return webResponse.Error($"鍙栨秷浠诲姟澶辫触锛屽師鍥狅細{ex.Message}");
+            }
+            _unitOfWorkManage.RollbackTran();
+            return webResponse.Error("浠诲姟鍙栨秷澶辫触");
+        }
+
+        /// <summary>
+        /// 鍒涘缓璐т綅
+        /// </summary>
+        /// <param name="locationInfo"></param>
+        /// <returns></returns>
+        /// <exception cref="NotImplementedException"></exception>
+        public ApiResponse<object> createLocation(List<LocationInfoDto> locationInfo)
+        {
+            List<Dt_LocationInfo> dt_LocationInfoList = new List<Dt_LocationInfo>();
+            foreach (var item in locationInfo)
+            {
+                Dt_LocationInfo dt_LocationInfo = new Dt_LocationInfo()
+                {
+                    LocationCode = item.locationCode,
+                    LocationName = item.locationName,
+                    RoadwayNo = item.roadwayNo,
+                    Row = item.row,
+                    Column = item.column,
+                    Layer = item.layer,
+                    Depth = (int)item.depth,
+                    LocationType = item.locationType,
+                    LocationStatus = item.locationStatus,
+                    EnableStatus = item.enableStatus == true ? 1 : 0,
+                    Remark = item.remark,
+                    CreateDate = DateTime.Now,
+                    Creater = App.User.UserName,
+                };
+                dt_LocationInfoList.Add(dt_LocationInfo);
+            }
+            int res = _locationInfoRepository.AddData(dt_LocationInfoList);
+            if (res <= 0)
+            {
+                return MESresponse($"鍒涘缓璐т綅澶辫触",false);
+            }
+            return MESresponse($"", true);
+        }
+
+        /// <summary>
+        /// 淇敼璐т綅
+        /// </summary>
+        /// <param name="locationInfo"></param>
+        /// <returns></returns>
+        /// <exception cref="NotImplementedException"></exception>
+        public ApiResponse<object> updateLocation(LocationInfoDto locationInfo)
+        {
+            Dt_LocationInfo dt_LocationInfo = new Dt_LocationInfo()
+            {
+                LocationCode = locationInfo.locationCode,
+                LocationName = locationInfo.locationName,
+                RoadwayNo = locationInfo.roadwayNo,
+                Row = locationInfo.row,
+                Column = locationInfo.column,
+                Layer = locationInfo.layer,
+                Depth = (int)locationInfo.depth,
+                LocationType = locationInfo.locationType,
+                LocationStatus = locationInfo.locationStatus,
+                EnableStatus = locationInfo.enableStatus == true ? 1 : 0,
+                Remark = locationInfo.remark,
+                CreateDate = DateTime.Now,
+            };
+            bool res = _locationInfoRepository.Db.Updateable(dt_LocationInfo)
+    .Where(x => x.LocationCode == dt_LocationInfo.LocationCode)
+    .ExecuteCommand() > 0;
+            if (!res)
+            {
+                return MESresponse($"淇敼璐т綅澶辫触",false);
+            }
+            return MESresponse($"", true);
+        }
+
+        /// <summary>
+        /// 鍒犻櫎璐т綅
+        /// </summary>
+        /// <param name="locationCode"></param>
+        /// <returns></returns>
+        /// <exception cref="NotImplementedException"></exception>
+        public ApiResponse<object> deleteLocation(List<string> locationCode)
+        {
+            WebResponseContent webResponseContent = new WebResponseContent();
+            int res = _locationInfoRepository.Db.Deleteable<Dt_LocationInfo>().Where(x => locationCode.Contains(x.LocationCode)).ExecuteCommand();
+            if (res <= 0)
+            {
+                return MESresponse($"鍒犻櫎璐т綅澶辫触",false);
+            }
+            return MESresponse($"", true);
+        }
+
+
+        public static string GetLastPart(string locationCode)
+        {
+            string[] parts = locationCode.Split('-');
+            return parts[parts.Length - 1];
+        }
+
+
+        /// <summary>
+        /// 鍑哄簱
+        /// </summary>
+        /// <param name="locationCode"></param>
+        /// <returns></returns>
+        /// <exception cref="NotImplementedException"></exception>
+        public WebResponseContent chuku(string locationCode)
+        {
+
+            try
+            {
+                Dt_StockInfo dt_StockInfo =  _stockRepository.QueryFirst(x => x.LocationCode.StartsWith("SC01") && x.StockStatus == 6);
+                int result = GetLastPart(dt_StockInfo.LocationCode).ObjToInt(); // 杩斿洖 "C03"
+
+                List<Dt_Task> dt_s = new List<Dt_Task>();
+                //鐢熸垚绉诲姩浠诲姟
+                Dt_Task dt_Task = new()
+                {
+                    PalletCode = dt_StockInfo.PalletCode,
+                    TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
+                    Roadway = "SC01",
+                    TaskType = TaskOutboundTypeEnum.Outbound.ObjToInt(),
+                    TaskStatus = TaskOutStatusEnum.OutNew.ObjToInt(),
+                    SourceAddress = dt_StockInfo.LocationCode,
+                    TargetAddress = "1006",
+                    CurrentAddress = dt_StockInfo.LocationCode,
+                    NextAddress = "1006",
+                    Grade = 1,
+                    Creater = "MES",
+                    Depth = result,
+                    CreateDate = DateTime.Now,
+                    MEStaskId = "EXTASK20251020002",
+                    MESbusinessId = "EXBUS20251020002",
+                    MESsubPalletCode = dt_StockInfo.MESsubPalletCode,
+                    OutboundPlatform = "1005"
+                };
+
+                ////鍒涘缓缁勭洏淇℃伅
+                //var dt_Stock = new Dt_StockInfo
+                //{
+                //    PalletCode = dt_Task.PalletCode,
+                //    PalletType = 1,
+                //    LocationCode = locationCode,
+                //    StockStatus = 6,
+                //    Creater = "WMS",
+                //    CreateDate = DateTime.Now,
+                //    MESsubPalletCode = dt_Task.MESsubPalletCode,
+                //};
+
+                Dt_LocationInfo dt_LocationInfo = _locationInfoRepository.QueryFirst(x => x.LocationCode == dt_StockInfo.LocationCode);
+                dt_LocationInfo.LocationStatus = (int)LocationStatusEnum.InStockLock;
+                dt_StockInfo.StockStatus = 7;
+
+                bool l = _locationInfoRepository.UpdateData(dt_LocationInfo);
+                bool s = _stockRepository.UpdateData(dt_StockInfo);
+                int t = BaseDal.AddData(dt_Task);
+                bool ss = s.ObjToBool();
+                bool tt = t.ObjToBool();
+
+
+                if (!l && !ss && tt)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                }
+
+                dt_s.Add(dt_Task);
+                var respon = PushTasksToWCS(dt_s, "");
+                if (respon.Status)
+                {
+                    _unitOfWorkManage.CommitTran();  //鎻愪氦浜嬪姟
+                    return WebResponseContent.Instance.OK();
+                }
+                return WebResponseContent.Instance.Error();
+            }
+            catch
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error();
+
+            }
+        }
     }
 }

--
Gitblit v1.9.3