647556386
2026-01-12 300ca9810420efbf8468c9d6f47bd364c9c72d5f
ÏîÄ¿´úÂë/WMSÎÞ²Ö´¢°æ/WIDESEA_WMSServer/WIDESEA_InboundService/InboundService.cs
@@ -10,6 +10,7 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.AllocateEnum;
@@ -23,6 +24,7 @@
using WIDESEA_Core.Utilities;
using WIDESEA_DTO.Allocate;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Mes;
using WIDESEA_DTO.ReturnMES;
using WIDESEA_IBasicService;
using WIDESEA_IInboundService;
@@ -50,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;
@@ -66,6 +69,7 @@
            _httpClientHelper = httpClientHelper;
            _mesReturnRecord = mesReturnRecord;
            _locationInfoService = locationInfoService;
            _takeStockOrder = takeStockOrder;
        }
        public async Task<WebResponseContent> GroupPallet(GroupPalletDto palletDto)
@@ -88,7 +92,7 @@
                if (details.Count() <= 0)
                {
                    return content.Error("未找到该条码单据信息请确认是否已经组盘完成");
                    return content.Error("请确认是否已经组盘");
                }
                inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Includes(x=>x.Details).Where(x => x.Id == details.First().OrderId).First();
@@ -439,7 +443,7 @@
                    if (allocatefeedmodel.Details.Count <= 0)
                    {
                        throw new Exception("未找到需要回传的数据");
                        return WebResponseContent.Instance.OK($"该单据没有需要回传明细,失败数据回传{returnRecords.Count()}条,回传成功{returnRecords.Count(x => x.ReturnStatus == 1)}条,回传失败{returnRecords.Count(x => x.ReturnStatus == 2)}条");
                    }
                    var response = responseModel(inboundOrder, 3, null, allocatefeedmodel);
@@ -473,7 +477,7 @@
                    if (feedmodel.details.Count<=0)
                    {
                        throw new Exception("未找到需要回传的数据");
                        return WebResponseContent.Instance.OK($"该单据没有需要回传明细,失败数据回传{returnRecords.Count()}条,回传成功{returnRecords.Count(x => x.ReturnStatus == 1)}条,回传失败{returnRecords.Count(x => x.ReturnStatus == 2)}条");
                    }
                    var response = responseModel(inboundOrder, 3, feedmodel);
@@ -592,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);
            }
        }
    }
}