heshaofeng
2026-01-13 d741e7a7ad7de5045e5c6b6145d9da1783cadecd
ÏîÄ¿´úÂë/WMSÎÞ²Ö´¢°æ/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);
            }
        }
    }
}