From d741e7a7ad7de5045e5c6b6145d9da1783cadecd Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期二, 13 一月 2026 09:55:03 +0800
Subject: [PATCH] Merge branch 'htq20251215' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu into htq20251215

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_InboundService/InboundService.cs |  124 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 123 insertions(+), 1 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 3c2b957..4a3c19c 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"
@@ -52,7 +52,8 @@
         private readonly 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)
+        private readonly IRepository<Dt_TakeStockOrder> _takeStockOrder;
+        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,IRepository<Dt_TakeStockOrder> takeStockOrder)
         {
             _unitOfWorkManage = unitOfWorkManage;
             InboundOrderDetailService = inboundOrderDetailService;
@@ -68,6 +69,7 @@
             _httpClientHelper = httpClientHelper;
             _mesReturnRecord = mesReturnRecord;
             _locationInfoService = locationInfoService;
+            _takeStockOrder = takeStockOrder;
         }
 
         public async Task<WebResponseContent> GroupPallet(GroupPalletDto palletDto)
@@ -594,5 +596,125 @@
 
             return httpResponseResult;
         }
+
+        public async Task<WebResponseContent> StockTakeGroupPallet(GroupPalletDto palletDto)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                (bool, string, object?) result2 = ModelValidate.ValidateModelData(palletDto);
+                if (!result2.Item1) return content.Error(result2.Item2);
+
+                // 楠岃瘉浠撳簱缂栧彿鏄惁瀛樺湪
+                var code = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>()
+                    .Where(x => x.Code == palletDto.WarehouseType)
+                    .Select(x => x.Code)
+                    .First();
+                if (string.IsNullOrEmpty(code))
+                {
+                    return content.Error($"浠撳簱涓病鏈夎{palletDto.WarehouseType}缂栧彿銆�");
+                }
+
+                // 鏌ヨ褰撳墠鎵樼洏鐨勫簱瀛樹俊鎭�
+                Dt_StockInfo? stockInfo = await _stockInfoRepository.Db.Queryable<Dt_StockInfo>()
+                    .Includes(x => x.Details)
+                    .Where(x => x.PalletCode == palletDto.PalletCode)
+                    .FirstAsync();
+
+                // 楠岃瘉鎵樼洏鏄惁宸茬敓鎴愪换鍔�
+                if (_taskRepository.QueryFirst(x => x.PalletCode == palletDto.PalletCode) != null)
+                {
+                    return content.Error($"璇ユ墭鐩樺凡鐢熸垚浠诲姟");
+                }
+
+                // 楠岃瘉鎵樼洏鏄惁宸蹭笂鏋讹紙宸蹭笂鏋朵笉鑳界粍鐩橈級
+                if (stockInfo != null && !string.IsNullOrEmpty(stockInfo.LocationCode) && stockInfo.StockStatus != (int)StockStatusEmun.缁勭洏鏆傚瓨)
+                {
+                    return content.Error("宸蹭笂鏋剁殑鎵樼洏涓嶈兘鍐嶆缁勭洏");
+                }
+
+                Dt_StockInfoDetail stockInfoDetail = _stockService.StockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+                    .Where(x => x.Barcode == palletDto.Barcode && x.StockId == 0)
+                    .First();
+                if (stockInfoDetail == null)
+                {
+                    return content.Error($"{palletDto.Barcode} 鏉$爜宸插叧鑱斿叾浠栨墭鐩橈紝鏃犳硶缁勭洏");
+                }
+
+                Dt_TakeStockOrder takeStockOrder = _takeStockOrder.Db.Queryable<Dt_TakeStockOrder>()
+                    .Where(x => x.OrderNo == stockInfoDetail.OrderNo)
+                    .First();
+                if (takeStockOrder == null)
+                {
+                    return content.Error($"{palletDto.Barcode} 涓嶅睘浜庣洏鐐瑰崟鎹腑鐨勬潯鐮侊紝涓嶅厑璁哥洏浜忕粍鐩�");
+                }
+                if (stockInfo == null)
+                {
+                    stockInfo = new Dt_StockInfo()
+                    {
+                        PalletType = (int)PalletTypeEnum.None,
+                        LocationType = Convert.ToInt32(palletDto.locationType),
+                        PalletCode = palletDto.PalletCode,
+                        StockStatus = (int)StockStatusEmun.缁勭洏鏆傚瓨,
+                        Details = new List<Dt_StockInfoDetail>()
+                    };
+                }
+
+                if (stockInfo.Details.Count > 0 && stockInfo.Details.FirstOrDefault()?.WarehouseCode != palletDto.WarehouseType)
+                {
+                    return content.Error($"璇ユ墭鐩樼粍鐩樹粨搴撲负{stockInfo.Details.FirstOrDefault()?.WarehouseCode}涓庡綋鍓嶄粨搴搟palletDto.WarehouseType}涓嶄竴鑷达紝涓嶅厑璁哥粍鐩�");
+                }
+
+                _unitOfWorkManage.BeginTran();
+
+                try
+                {
+                    if (stockInfo.Id == 0)
+                    {
+                        int newStockId = await _stockInfoRepository.Db.Insertable(stockInfo).ExecuteReturnIdentityAsync();
+                        stockInfo.Id = newStockId;
+                    }
+
+                    stockInfoDetail.StockId = stockInfo.Id;
+
+                    await _stockService.StockInfoDetailService.Db.Updateable(stockInfoDetail)
+                        .Where(x => x.Id == stockInfoDetail.Id)
+                        .ExecuteCommandAsync();
+
+                    if (stockInfo.Id != 0 && stockInfo.Details != null && !stockInfo.Details.Contains(stockInfoDetail))
+                    {
+                        stockInfo.Details.Add(stockInfoDetail);
+
+                        await _stockInfoRepository.Db.Updateable(stockInfo)
+                            .IgnoreColumns(x => x.Details)
+                            .ExecuteCommandAsync();
+                    }
+
+                    // 鎻愪氦浜嬪姟
+                    _unitOfWorkManage.CommitTran();
+                }
+                catch (Exception)
+                {
+                    // 浜嬪姟鍥炴粴
+                    _unitOfWorkManage.RollbackTran();
+                    throw; // 鎶涚粰澶栧眰catch澶勭悊鏃ュ織
+                }
+
+                // 鏌ヨ鏈�鏂扮殑搴撳瓨淇℃伅锛堝寘鍚叧鑱旂殑鏄庣粏锛�
+                Dt_StockInfo? NewstockInfo = await _stockInfoRepository.Db.Queryable<Dt_StockInfo>()
+                    .Includes(x => x.Details)
+                    .Where(x => x.PalletCode == palletDto.PalletCode)
+                    .FirstAsync();
+
+                return WebResponseContent.Instance.OK(data: NewstockInfo.Details.OrderByDescending(x => x.Id));
+
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                LogFactory.GetLog($"缁勭洏淇℃伅").Info(true, $"銆愬紓甯搞�戯細銆恵ex.Message}銆憑Environment.NewLine}銆恵ex.StackTrace}銆憑Environment.NewLine}{Environment.NewLine}");
+                return content.Error(ex.Message);
+            }
+        }
     }
 }

--
Gitblit v1.9.3