From 77bc3a65b83a58c9fc30fb80679a93bc45a2cb84 Mon Sep 17 00:00:00 2001
From: z8018 <1282578289@qq.com>
Date: 星期四, 18 十二月 2025 19:11:22 +0800
Subject: [PATCH] 修复前端拣选页面问题

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |  170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 163 insertions(+), 7 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
index b8f8669..922cf88 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
@@ -41,10 +41,12 @@
 using WIDESEA_Core.BaseServices;
 using WIDESEA_Core.Enums;
 using WIDESEA_Core.Helper;
+using WIDESEA_Core.Util;
 using WIDESEA_DTO.Allocate;
 using WIDESEA_DTO.Basic;
 using WIDESEA_DTO.Inbound;
 using WIDESEA_DTO.Outbound;
+using WIDESEA_DTO.ReturnMES;
 using WIDESEA_DTO.Task;
 using WIDESEA_IAllocateService;
 using WIDESEA_IBasicService;
@@ -56,6 +58,7 @@
 using WIDESEA_Model.Models;
 using WIDESEA_Model.Models.Check;
 using WIDESEA_Model.Models.Outbound;
+using static HslCommunication.Profinet.Knx.KnxCode;
 
 namespace WIDESEA_TaskInfoService
 {
@@ -85,6 +88,9 @@
         private readonly IAllocateService _allocateService;
         private readonly IInvokeMESService _invokeMESService;
         private readonly ITask_HtyService _task_HtyService;
+        private readonly IRepository<Dt_AllocateMaterialInfo> _allocateMaterialInfo;
+        private readonly IRepository<Dt_AllocateMaterialInfo_Hty> _allocateMaterialInfo_Hty;
+        private readonly HttpClientHelper _httpClientHelper;
         public IRepository<Dt_Task> Repository => BaseDal;
 
         private Dictionary<string, SqlSugar.OrderByType> _taskOrderBy = new()
@@ -104,7 +110,7 @@
 
         public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList();
 
-        public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_StockInfo> stockRepository, ILocationInfoService locationInfoService, IInboundOrderService inboundOrderService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IESSApiService eSSApiService, ILogger<TaskService> logger, IStockService stockService, IRecordService recordService, IInboundOrderDetailService inboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IInvokeMESService invokeMESService, IOutStockLockInfoService outStockLockInfoService, IAllocateService allocateService, IRepository<Dt_OutboundBatch> outboundBatchRepository, IRepository<Dt_ReCheckOrder> reCheckOrderRepository, IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository, IMaterialUnitService materialUnitService, ITask_HtyService task_HtyService) : base(BaseDal)
+        public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_StockInfo> stockRepository, ILocationInfoService locationInfoService, IInboundOrderService inboundOrderService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IESSApiService eSSApiService, ILogger<TaskService> logger, IStockService stockService, IRecordService recordService, IInboundOrderDetailService inboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IInvokeMESService invokeMESService, IOutStockLockInfoService outStockLockInfoService, IAllocateService allocateService, IRepository<Dt_OutboundBatch> outboundBatchRepository, IRepository<Dt_ReCheckOrder> reCheckOrderRepository, IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository, IMaterialUnitService materialUnitService, ITask_HtyService task_HtyService, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfo, IRepository<Dt_AllocateMaterialInfo_Hty> allocateMaterialInfo_Hty, HttpClientHelper httpClientHelper) : base(BaseDal)
         {
             _mapper = mapper;
             _unitOfWorkManage = unitOfWorkManage;
@@ -128,6 +134,9 @@
             _allocateOrderRepository = allocateOrderRepository;
             _materialUnitService = materialUnitService;
             _task_HtyService = task_HtyService;
+            _allocateMaterialInfo = allocateMaterialInfo;
+            _allocateMaterialInfo_Hty = allocateMaterialInfo_Hty;
+            _httpClientHelper = httpClientHelper;
         }
 
         public async Task TaskStatusChange(string taskNum, TaskStatusEnum taskStatusEnum)
@@ -292,7 +301,7 @@
             task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
 
             //  BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
-            var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.浜哄伐鍒犻櫎);
+            var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
             if (!result)
             {
                 await Db.Deleteable(task).ExecuteCommandAsync();
@@ -351,8 +360,10 @@
                                }).ToList();
                             allocatefeedmodel.Details = groupedData;
 
-                            var feedbackresult = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
-                            if (feedbackresult != null && feedbackresult.code == 200)
+                            //var feedbackresult = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
+
+                            var response = responseModel(inboundOrder, 3, null, allocatefeedmodel);
+                            if (response != null && response.IsSuccess)
                             {
                                 _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
                                 .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
@@ -455,8 +466,11 @@
                                }).ToList();
                             feedmodel.details = groupedData;
 
-                            var feedbackresult = await _invokeMESService.FeedbackInbound(feedmodel);
-                            if (feedbackresult != null && feedbackresult.code == 200)
+                            //var feedbackresult = await _invokeMESService.FeedbackInbound(feedmodel);
+
+                            var response= responseModel(inboundOrder,2, feedmodel);
+
+                            if (response != null && response.IsSuccess)
                             {
                                 _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1, Remark = "" })
                                 .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
@@ -465,7 +479,7 @@
                             }
                             else
                             {
-                                _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 2, Remark = feedbackresult.message })
+                                _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 2, Remark = response.ErrorMessage })
                                 .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
                                 _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 2 })
                                .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand();
@@ -481,6 +495,61 @@
             }
 
             return WebResponseContent.Instance.OK();
+        }
+
+        public HttpResponseResult<MesResponseDTO> responseModel(Dt_InboundOrder order, int InterfaceType, FeedbackInboundRequestModel model = null, AllocateDto allocateDto = null)
+        {
+            HttpResponseResult<MesResponseDTO> httpResponseResult = new HttpResponseResult<MesResponseDTO>();
+            string reqCode = Guid.NewGuid().ToString();
+            string reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+            string requestData = string.Empty;
+            string apiUrl = string.Empty;            
+            if (model != null)
+            {
+                apiUrl = AppSettings.GetValue("AldMaterialWarehousing");
+                httpResponseResult = _httpClientHelper.Post<MesResponseDTO>(apiUrl, model.Serialize());
+                requestData = model.Serialize();
+            }
+            else
+            {
+                apiUrl = AppSettings.GetValue("AldAllocationOperation");
+                httpResponseResult = _httpClientHelper.Post<MesResponseDTO>(apiUrl, allocateDto.Serialize());
+                requestData = allocateDto.Serialize(); 
+            }
+            httpResponseResult.ApiUrl = apiUrl;
+            bool isSuccess = httpResponseResult.IsSuccess && httpResponseResult.Data.Code == "200";
+            string message = "鎴愬姛";
+            if (!isSuccess)
+            {
+                if (!httpResponseResult.IsSuccess)
+                {
+                    message = $"MES鎺ュ彛杩斿洖閿欒锛孒TTP浠g爜锛歿httpResponseResult.StatusCode}锛屼俊鎭細{httpResponseResult.ErrorMessage}";
+                }
+                else if (httpResponseResult?.Data?.Code != "200")
+                {
+                    message = $"璋冪敤MES鎺ュ彛澶辫触锛屼唬鐮侊細{httpResponseResult?.Data?.Code}锛屼俊鎭細{httpResponseResult?.Data?.Message}";
+                }
+            }
+            Dt_MesReturnRecord mesReturnRecord = new Dt_MesReturnRecord()
+            {
+                ApiUrl = httpResponseResult.ApiUrl,
+                InterfaceType = InterfaceType,
+                OrderId = order.Id,
+                OrderNo = order.InboundOrderNo,
+                RequestCode = reqCode,
+                RequestData = requestData,
+                FailureReason = message,
+                LastReturnTime = DateTime.Now,
+                HttpStatusCode = httpResponseResult.StatusCode.ObjToInt(),
+                ResponseData = httpResponseResult.Content,
+                ReturnType = 0,
+                ReturnCount = 1,
+                ReturnStatus = httpResponseResult.IsSuccess ? 1 : 2,
+                SuccessTime = httpResponseResult.IsSuccess ? DateTime.Now : null
+            };
+            _unitOfWorkManage.Db.Insertable(mesReturnRecord).ExecuteCommand();
+
+            return httpResponseResult;
         }
 
 
@@ -509,6 +578,7 @@
 
 
             stock.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
+            stock.LocationCode = "";
 
             stock.Details.ForEach(x =>
             {
@@ -598,6 +668,92 @@
                 return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message));
             }
         }
+        /// <summary>
+        /// 鏅轰粨璋冨叆鏅轰粨瀹屾垚
+        /// </summary>
+        /// <param name="task"></param>
+        /// <returns></returns>
+        public async Task<WebResponseContent> AllocateInWarehouseTaskCompleted(Dt_Task task)
+        {
+
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+
+                Dt_StockInfo stockInfo = await _stockRepository.Db.Queryable<Dt_StockInfo>()
+                    .Includes(x => x.Details)
+                    .Where(x => x.PalletCode == task.PalletCode)
+                    .FirstAsync();
+
+                if (stockInfo == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩樺搴旂殑缁勭洏淇℃伅");
+                }
+
+                if (stockInfo.Details.Count == 0 && stockInfo.PalletType != PalletTypeEnum.Empty.ObjToInt())
+                {
+                    _logger.LogInformation($"TaskService InPickTaskCompleted: 鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅.{task.TaskNum}");
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅");
+                }
+                Dt_LocationInfo locationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+                if (locationInfo == null)
+                {
+                    return content.Error($"鏈壘鍒板搴旂殑缁堢偣璐т綅淇℃伅");
+                }
+                
+                if (!string.IsNullOrEmpty(stockInfo.LocationCode))
+                {
+                    return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡缁戝畾璐т綅");
+                }
+                if (locationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
+                {
+                    return WebResponseContent.Instance.Error($"璐т綅鐘舵�佷笉姝g‘");
+                }
+                List<Dt_AllocateMaterialInfo> allocateMaterialInfos = _allocateMaterialInfo.QueryData(x => x.OrderNo == stockInfo.Details.FirstOrDefault().OrderNo);
+                if(allocateMaterialInfos == null)
+                {
+                    return content.Error("鏈壘鍒板叆鏅轰粨鐨勭墿鏂欎俊鎭�");
+                }
+                _unitOfWorkManage.BeginTran();
+                var alldelete = _allocateMaterialInfo.DeleteAndMoveIntoHty(allocateMaterialInfos ,OperateTypeEnum.鑷姩鍒犻櫎);
+                if (!alldelete)
+                {
+                    await Db.Deleteable(task).ExecuteCommandAsync();
+                }
+
+                var beforelocationStatus = locationInfo.LocationStatus;
+                locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+                _locationInfoService.Repository.UpdateData(locationInfo);
+
+                stockInfo.LocationCode = locationInfo.LocationCode;
+                stockInfo.PalletCode = task.PalletCode;
+                stockInfo.LocationCode = task.TargetAddress;
+                stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                _stockRepository.UpdateData(stockInfo);
+
+                task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
+                var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
+                _unitOfWorkManage.CommitTran();
+                if (!result)
+                {
+                    await Db.Deleteable(task).ExecuteCommandAsync();
+                }
+                try
+                {
+                    _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforelocationStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
+                }
+                catch (Exception ex)
+                {
+                    _logger.LogInformation($"InEmptyTaskCompleted AddLocationStatusChangeRecord : {ex.Message} ");
+                }
+                return content;
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message));
+            }
+        }
 
 
         public async Task<WebResponseContent> InPickTaskCompleted(Dt_Task task)

--
Gitblit v1.9.3