From b13d3d2c634df625dcaa74371f1d36a8376851b4 Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期二, 06 一月 2026 14:54:16 +0800
Subject: [PATCH] 优化撤销组盘功能

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_InboundService/InboundService.cs |   74 ++++++++++++++++++++++++++++++++----
 1 files changed, 65 insertions(+), 9 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_InboundService/InboundService.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_InboundService/InboundService.cs"
index b66eda7..38f2aa6 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_InboundService/InboundService.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_InboundService/InboundService.cs"
@@ -1,12 +1,18 @@
 锘縰sing LogLibrary.Log;
 using MailKit;
 using MailKit.Search;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
+using Org.BouncyCastle.Asn1.X509;
+using SixLabors.ImageSharp;
 using SqlSugar;
 using System;
+using System.Collections;
 using System.Collections.Generic;
+using System.Data;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Common.AllocateEnum;
 using WIDESEA_Common.CommonEnum;
 using WIDESEA_Common.OrderEnum;
 using WIDESEA_Common.StockEnum;
@@ -18,6 +24,7 @@
 using WIDESEA_DTO.Allocate;
 using WIDESEA_DTO.Inbound;
 using WIDESEA_DTO.ReturnMES;
+using WIDESEA_IBasicService;
 using WIDESEA_IInboundService;
 using WIDESEA_IStockService;
 using WIDESEA_Model.Models;
@@ -41,7 +48,9 @@
         private IStockService _stockService;
         private readonly IRepository<Dt_AllocateMaterialInfo> _allocateMaterialInfo;
         private readonly HttpClientHelper _httpClientHelper;
-        public InboundService(IUnitOfWorkManage unitOfWorkManage, IInboundOrderDetailService inboundOrderDetailService, IInboundOrderService inbounOrderService, IRepository<Dt_InboundOrder> inboundOrderRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IRepository<Dt_LocationType> locationTypeRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IStockService stockService, IRepository<Dt_Task> taskRepository,IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfo, HttpClientHelper httpClientHelper)
+        private readonly IRepository<Dt_MesReturnRecord> _mesReturnRecord;
+        private readonly ILocationInfoService _locationInfoService;
+        public InboundService(IUnitOfWorkManage unitOfWorkManage, IInboundOrderDetailService inboundOrderDetailService, IInboundOrderService inbounOrderService, IRepository<Dt_InboundOrder> inboundOrderRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IRepository<Dt_LocationType> locationTypeRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IStockService stockService, IRepository<Dt_Task> taskRepository,IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfo, HttpClientHelper httpClientHelper, IRepository<Dt_MesReturnRecord> mesReturnRecord,ILocationInfoService locationInfoService)
         {
             _unitOfWorkManage = unitOfWorkManage;
             InboundOrderDetailService = inboundOrderDetailService;
@@ -55,6 +64,8 @@
             _taskRepository = taskRepository;
             _allocateMaterialInfo = allocateMaterialInfo;
             _httpClientHelper = httpClientHelper;
+            _mesReturnRecord = mesReturnRecord;
+            _locationInfoService = locationInfoService;
         }
 
         public async Task<WebResponseContent> GroupPallet(GroupPalletDto palletDto)
@@ -84,6 +95,17 @@
                 {
                     return content.Error("鏈壘鍒拌鏉$爜涓诲崟淇℃伅");
                 }
+                var warehouse =_warehouseAreaRepository.QueryFirst(x => x.Code == palletDto.WarehouseType);
+                if(inboundOrder.BusinessType=="11" && inboundOrder.FactoryArea != warehouse.FactoryArea)
+                {
+                    return content.Error($"褰撳墠鍘傚尯涓嶄竴鑷�");
+                }
+
+                if(inboundOrder.BusinessType != "11"&& inboundOrder.Details.FirstOrDefault().WarehouseCode != palletDto.WarehouseType)
+                {
+                    return content.Error($"璇ユ潯鐮佹墍灞炰粨搴撲负{inboundOrder.Details.FirstOrDefault().WarehouseCode}涓庡綋鍓嶄粨搴搟palletDto.WarehouseType}涓嶄竴鑷达紝涓嶅厑璁哥粍鐩�");
+                }
+
                 Dt_StockInfo? stockInfo = await _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == palletDto.PalletCode).FirstAsync();
 
                 List<string?> materielCodes = details.GroupBy(x => x.Barcode).Select(x => x.Key).ToList();
@@ -98,18 +120,26 @@
                     stockInfo.Details = new List<Dt_StockInfoDetail>();
                 }
 
-                if (stockInfo != null && stockInfo.Details.Count>0 && stockInfo.Details.FirstOrDefault()?.WarehouseCode != palletDto.WarehouseType)
+                if (inboundOrder.BusinessType != MESDocumentType.PurchaseInbound.ToString() && stockInfo != null && stockInfo.Details.Count > 0 && stockInfo.Details.FirstOrDefault()?.WarehouseCode != palletDto.WarehouseType)
                 {
                     return content.Error($"璇ユ墭鐩樼粍鐩樹粨搴撲负{stockInfo.Details.FirstOrDefault()?.WarehouseCode}涓庡綋鍓嶄粨搴搟palletDto.WarehouseType}涓嶄竴鑷达紝涓嶅厑璁哥粍鐩�");
                 }
 
+                if (!_locationInfoService.QueryLocationCount(Convert.ToInt32(palletDto.locationType)))
+                {
+                    return content.Error($"璇ュ簱鍖簕palletDto.locationType}涓嶅瓨鍦ㄧ┖闂插簱浣�");
+                }
+
                 foreach (var item in details)
                 {
+                    var datevaliDate = _inboundOrderRepository.Db.Queryable<Dt_MaterialExpirationDate>().Where(x=>x.MaterialCode.Contains(item.MaterielCode.Substring(0,6))).First();
+
                     stockInfo.Details.Add(new Dt_StockInfoDetail
                     {
                         StockId = stockInfo == null ? 0 : stockInfo.Id,
                         Barcode = item.Barcode,
                         MaterielCode = item.MaterielCode,
+                        MaterielName = item.MaterielName,
                         BatchNo = item.BatchNo,
                         Unit = item.Unit,
                         InboundOrderRowNo = item.lineNo,
@@ -122,7 +152,7 @@
                         Status = 0,
                         OrderNo = inboundOrder.InboundOrderNo,
                         BusinessType = inboundOrder.BusinessType,
-
+                        ValidDate = inboundOrder.BusinessType == BusinessTypeEnum.澶栭儴浠撳簱璋冩櫤浠�.ToString() ? item.ValidDate : datevaliDate == null ? null : Convert.ToDateTime(DateTime.Now).AddDays(Convert.ToDouble(datevaliDate.ValidityDays)),
                     });
 
                     item.ReceiptQuantity = item.BarcodeQty;
@@ -326,21 +356,41 @@
             }
         }
 
-        public WebResponseContent BatchInOrderFeedbackToMes(string OrderNo)
+        public WebResponseContent BatchInOrderFeedbackToMes(int id)
         {
             WebResponseContent content = new WebResponseContent();
             try
             {
                 var inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>()
-                                    .Where(x => x.InboundOrderNo == OrderNo)
+                                    .Where(x => x.Id == id)
                                     .First();
+
+                List<Dt_MesReturnRecord> returnRecords = _mesReturnRecord.QueryData(x => x.OrderNo == inboundOrder.InboundOrderNo && x.OrderId == inboundOrder.Id && x.ReturnStatus == 2);
+                foreach (var item in returnRecords)
+                {
+                    HttpResponseResult<MesResponseDTO> httpResponse = _httpClientHelper.Post<MesResponseDTO>(item.ApiUrl, item.RequestData);
+                    item.ReturnCount += 1;
+                    bool success = httpResponse.IsSuccess && httpResponse.Data.Code == "200";
+                    item.ReturnStatus = success ? 1 : 2;
+                    item.HttpStatusCode = httpResponse.StatusCode.ObjToInt();
+                    item.LastReturnTime = DateTime.Now;
+                    item.ResponseData = httpResponse.Content;
+                    item.SuccessTime = httpResponse.IsSuccess ? DateTime.Now : null;
+
+                    //List<Dt_InboundOrderDetail> details=new List<Dt_InboundOrderDetail>();
+                    //foreach (var y in item.DetailsId.Split(','))
+                    //{
+                    //    details.Add( _inboundOrderDetailRepository.QueryFirst(x => x.Id == Convert.ToInt32(y)));
+                    //}
+                }
+                _mesReturnRecord.UpdateData(returnRecords);
 
                 var inboundOrderDetail = _inboundOrderRepository.Db.Queryable<Dt_InboundOrderDetail>()
                                         .Where(x => x.OrderId == inboundOrder.Id && x.OrderDetailStatus==(int)OrderDetailStatusEnum.Over && x.ReturnToMESStatus == 0)
                                         .ToList();
 
-                var stocks = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.StockStatus == 6)
-                                            .Where(it => SqlFunc.Subqueryable<Dt_StockInfoDetail>().Where(s => s.StockId == it.Id && s.OrderNo == OrderNo).Any())
+                var stocks = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.StockStatus == (int)StockStatusEmun.鍏ュ簱瀹屾垚)
+                                            .Where(it => SqlFunc.Subqueryable<Dt_StockInfoDetail>().Where(s => s.StockId == it.Id && s.OrderNo == inboundOrder.InboundOrderNo).Any())
                                             .ToList();
 
                 var stockIds = stocks.Select(s => s.Id).ToList();
@@ -387,12 +437,18 @@
                         throw new Exception("鏈壘鍒伴渶瑕佸洖浼犵殑鏁版嵁");
                     }
 
-                    var response = responseModel(inboundOrder, 3,null, allocatefeedmodel);
+                    var response = responseModel(inboundOrder, 3, null, allocatefeedmodel);
 
                     if (response != null && response.IsSuccess)
                     {
                         _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 })
-                        .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand();
+                        .Where(it => it.OrderId == inboundOrder.Id && inbounddetailID.Contains(it.Id)).ExecuteCommand();
+                    }
+                    else
+                    {
+                        _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 2 })
+                         .Where(it => inbounddetailID.Contains(it.Id)).ExecuteCommand();
+                        return content.Error("鍥炰紶MES澶辫触");
                     }
                 }
                 else

--
Gitblit v1.9.3