| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using Dm.filter; |
| | | using MailKit.Search; |
| | | using Microsoft.AspNetCore.Http; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | |
| | | private readonly IOutboundOrderDetailService _outboundOrderDetailService; |
| | | private readonly IOutboundOrderService _outboundOrderService; |
| | | private readonly ISplitPackageService _splitPackageService; |
| | | private readonly IRepository<Dt_Task> _taskRepository; |
| | | |
| | | |
| | | public OutboundPickingService(IRepository<Dt_PickingRecord> BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockInfoService stockInfoService, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IStockInfoDetailService stockInfoDetailService, ILocationInfoService locationInfoService, IOutboundOrderDetailService outboundOrderDetailService, ISplitPackageService splitPackageService, IOutboundOrderService outboundOrderService) : base(BaseDal) |
| | | public OutboundPickingService(IRepository<Dt_PickingRecord> BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockInfoService stockInfoService, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IStockInfoDetailService stockInfoDetailService, ILocationInfoService locationInfoService, IOutboundOrderDetailService outboundOrderDetailService, ISplitPackageService splitPackageService, IOutboundOrderService outboundOrderService, IRepository<Dt_Task> taskRepository) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _stockInfoService = stockInfoService; |
| | |
| | | _outboundOrderDetailService = outboundOrderDetailService; |
| | | _splitPackageService = splitPackageService; |
| | | _outboundOrderService = outboundOrderService; |
| | | _taskRepository = taskRepository; |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ«ç æ£é确认 - ç®åçæ¬ |
| | | /// åªå¤çå®é
æ£éçåºåæ£å |
| | | /// æ«ç æ£é确认 |
| | | /// </summary> |
| | | public async Task<WebResponseContent> ConfirmPicking(PickingConfirmRequest request) |
| | | { |
| | |
| | | try |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | // 1. éªè¯æ¡ç æææ§ |
| | | var lockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(it => it.OrderNo == orderNo && |
| | | it.Status == (int)OutLockStockStatusEnum.åºåºä¸ && |
| | | it.PalletCode == palletCode && |
| | | it.CurrentBarcode == barcode) |
| | | .FirstAsync(); |
| | | |
| | | if (lockInfo == null) |
| | | throw new Exception($"æ¡ç {barcode}ä¸å±äºæç{palletCode}æä¸åå¨å¾
åæ£è®°å½"); |
| | | |
| | | |
| | | |
| | | var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>() |
| | | .Where(x => x.Barcode == barcode) |
| | | .Where(x => x.Barcode == barcode && x.StockId == lockInfo.StockId) |
| | | .FirstAsync(); |
| | | |
| | | if (stockDetail == null) |
| | | return WebResponseContent.Instance.Error("æ æçæ¡ç æç©æç¼ç "); |
| | | |
| | | // 2. æ£æ¥åºåå¯ç¨æ°é |
| | | var availableQty = stockDetail.StockQuantity - stockDetail.OutboundQuantity; |
| | | if (availableQty <= 0) |
| | | return WebResponseContent.Instance.Error("åºåæ°éä¸è¶³"); |
| | | |
| | | // 3. æ¥æ¾ç¸å
³çåºåºè¯¦æ
ä¿¡æ¯ |
| | | var outStockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(x => x.OrderNo == orderNo && |
| | | x.PalletCode == palletCode && |
| | | x.CurrentBarcode == barcode && |
| | | x.Status == 0 && |
| | | x.RemainQuantity > 0) |
| | | .FirstAsync(); |
| | | decimal actualQty = lockInfo.AssignQuantity - lockInfo.PickedQty; |
| | | |
| | | if (outStockInfo == null) |
| | | return WebResponseContent.Instance.Error("æªæ¾å°å¯¹åºçæ£éä¿¡æ¯æå·²æ£é宿"); |
| | | // 4. æ´æ°åºå |
| | | stockDetail.StockQuantity -= actualQty; |
| | | stockDetail.OutboundQuantity -= actualQty; |
| | | await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync(); |
| | | |
| | | // 4. æ£æ¥åºåºè¯¦æ
é宿°é |
| | | if (outStockInfo.RemainQuantity <= 0) |
| | | return WebResponseContent.Instance.Error("该æ¡ç å·²æ å©ä½å¯æ£éæ°é"); |
| | | lockInfo.PickedQty += actualQty; |
| | | lockInfo.Status = (int)OutLockStockStatusEnum.æ£é宿; |
| | | await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync(); |
| | | |
| | | // 5. æ´æ°åºåºè¯¦æ
çå·²æ£éæ°é |
| | | outStockInfo.PickedQty = outStockInfo.AssignQuantity; |
| | | outStockInfo.Status = 1; |
| | | await _outStockLockInfoService.Db.Updateable(outStockInfo).ExecuteCommandAsync(); |
| | | |
| | | // 6. æ´æ°åºååºåºæ°é |
| | | await _stockInfoDetailService.Db.Updateable<Dt_StockInfoDetail>() |
| | | .SetColumns(x => x.OutboundQuantity == x.OutboundQuantity + outStockInfo.AssignQuantity) |
| | | .Where(x => x.Id == stockDetail.Id) |
| | | .ExecuteCommandAsync(); |
| | | await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>() |
| | | .SetColumns(it => it.PickedQty == it.PickedQty + actualQty) |
| | | .Where(it => it.Id == lockInfo.OrderDetailId) |
| | | .ExecuteCommandAsync(); |
| | | |
| | | // 7. æ´æ°åºåºåæç» |
| | | var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>() |
| | | .Where(x => x.Id == outStockInfo.OrderDetailId) |
| | | .FirstAsync(); |
| | | |
| | | orderDetail.OverOutQuantity += outStockInfo.AssignQuantity; |
| | | await _outboundOrderDetailService.Db.Updateable(orderDetail).ExecuteCommandAsync(); |
| | | |
| | | // 8. æ£æ¥æ¯å¦å®æåºåº |
| | | |
| | | await CheckAndUpdateOrderStatus(orderNo); |
| | | |
| | | //æ¥è¯¢ä»»å¡è¡¨ |
| | | var task = _taskRepository.QueryData(x => x.OrderNo == orderNo && x.PalletCode == palletCode).FirstOrDefault(); |
| | | // 9. è®°å½æ£éåå² |
| | | var pickingHistory = new Dt_PickingRecord |
| | | { |
| | | |
| | | FactoryArea = lockInfo.FactoryArea, |
| | | TaskNo = task?.TaskNum ?? 0, |
| | | LocationCode = task?.SourceAddress ?? "", |
| | | StockId = stockDetail.Id, |
| | | OrderNo = orderNo, |
| | | OrderDetailId = lockInfo.OrderDetailId, |
| | | PalletCode = palletCode, |
| | | Barcode = barcode, |
| | | MaterielCode = outStockInfo.MaterielCode, |
| | | PickQuantity = outStockInfo.AssignQuantity, |
| | | MaterielCode = lockInfo.MaterielCode, |
| | | PickQuantity = lockInfo.AssignQuantity, |
| | | PickTime = DateTime.Now, |
| | | OutStockLockId = outStockInfo.Id |
| | | Operator = App.User.UserName, |
| | | OutStockLockId = lockInfo.Id |
| | | }; |
| | | await Db.Insertable(pickingHistory).ExecuteCommandAsync(); |
| | | |
| | |
| | | .Where(x => x.OrderNo == orderNo && |
| | | x.PalletCode == palletCode && |
| | | x.CurrentBarcode == barcode && |
| | | x.Status == 1) |
| | | x.Status == 2) |
| | | .FirstAsync(); |
| | | |
| | | if (outStockInfo == null) |
| | |
| | | |
| | | // è¿ååºåºè¯¦æ
ç¶æ |
| | | outStockInfo.PickedQty = 0; |
| | | outStockInfo.Status = 0; |
| | | outStockInfo.Status = 1; |
| | | await _outStockLockInfoService.Db.Updateable(outStockInfo).ExecuteCommandAsync(); |
| | | |
| | | // è¿ååºååºåºæ°é |
| | | await _stockInfoDetailService.Db.Updateable<Dt_StockInfoDetail>() |
| | | .SetColumns(x => x.OutboundQuantity == x.OutboundQuantity - outStockInfo.AssignQuantity) |
| | | .Where(x => x.Barcode == barcode) |
| | | .ExecuteCommandAsync(); |
| | | //// è¿ååºååºåºæ°é |
| | | //await _stockInfoDetailService.Db.Updateable<Dt_StockInfoDetail>() |
| | | // .SetColumns(x => x.OutboundQuantity == x.OutboundQuantity - outStockInfo.AssignQuantity) |
| | | // .Where(x => x.Barcode == barcode) |
| | | // .ExecuteCommandAsync(); |
| | | |
| | | // è¿ååºåºåæç» |
| | | var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>() |
| | |
| | | var list = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(x => x.OrderNo == orderNo && |
| | | x.PalletCode == palletCode && |
| | | x.Status == 0 && |
| | | x.RemainQuantity > 0) |
| | | x.Status == 1) |
| | | .ToListAsync(); |
| | | return list; |
| | | return list.Where(x => x.RemainQuantity > 0).ToList(); |
| | | } |
| | | |
| | | // è·åå·²æ£éå表 |
| | |
| | | var list = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(x => x.OrderNo == orderNo && |
| | | x.PalletCode == palletCode && |
| | | x.Status == 1) |
| | | x.Status == 2) |
| | | .ToListAsync(); |
| | | return list; |
| | | } |
| | | // è·åæ£éæ±æ» |
| | | public async Task<object> GetPickingSummary(string orderNo) |
| | | |
| | | public async Task<object> GetPickingSummary(string orderNo, string palletCode) |
| | | { |
| | | var summary = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(x => x.OrderNo == orderNo && x.Status == 0) |
| | | .Where(x => x.OrderNo == orderNo && |
| | | x.PalletCode == palletCode && x.Status == 1) |
| | | .GroupBy(x => new { x.PalletCode, x.MaterielCode }) |
| | | .Select(x => new |
| | | { |
| | | PalletCode = x.PalletCode, |
| | | MaterielCode = x.MaterielCode, |
| | | UnpickedCount = SqlFunc.AggregateCount(x.Id), |
| | | UnpickedQuantity = SqlFunc.AggregateSum(x.RemainQuantity) |
| | | UnpickedQuantity = SqlFunc.AggregateSum(x.AssignQuantity) - SqlFunc.AggregateSum(x.PickedQty) |
| | | }) |
| | | .ToListAsync(); |
| | | .FirstAsync(); |
| | | |
| | | return summary; |
| | | return summary; |
| | | } |
| | | |
| | | // è·åæ£éæ±æ» |
| | | public async Task<object> GetPickingSummary(ConfirmPickingDto dto) |
| | | { |
| | | var picked = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | | .WhereIF(!string.IsNullOrEmpty(dto.OrderNo), x => x.OrderNo == dto.OrderNo) |
| | | .WhereIF(!string.IsNullOrEmpty(dto.PalletCode), x => x.PalletCode == dto.PalletCode) |
| | | .Where(x => x.Status == 2) |
| | | .GroupBy(x => new { x.PalletCode, x.MaterielCode }) |
| | | .Select(x => new SummaryPickingDto |
| | | { |
| | | PalletCode = x.PalletCode, |
| | | MaterielCode = x.MaterielCode, |
| | | pickedCount = SqlFunc.AggregateCount(x.Id) |
| | | }).FirstAsync(); |
| | | if (picked == null) |
| | | { |
| | | picked = new SummaryPickingDto { pickedCount = 0 }; |
| | | } |
| | | |
| | | var summary = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | | .WhereIF(!string.IsNullOrEmpty(dto.OrderNo), x => x.OrderNo == dto.OrderNo) |
| | | .WhereIF(!string.IsNullOrEmpty(dto.PalletCode), x => x.PalletCode == dto.PalletCode) |
| | | .Where(x => x.Status == 1) |
| | | .GroupBy(x => new { x.PalletCode, x.MaterielCode }) |
| | | .Select(x => new SummaryPickingDto |
| | | { |
| | | PalletCode = x.PalletCode, |
| | | MaterielCode = x.MaterielCode, |
| | | UnpickedCount = SqlFunc.AggregateCount(x.Id), |
| | | UnpickedQuantity = SqlFunc.AggregateSum(x.AssignQuantity) - SqlFunc.AggregateSum(x.PickedQty), |
| | | |
| | | }).FirstAsync(); |
| | | if (summary == null) |
| | | { |
| | | summary = new SummaryPickingDto { pickedCount = 0 }; |
| | | } |
| | | summary.pickedCount = picked.pickedCount; |
| | | |
| | | return summary; |
| | | } |
| | | /// <summary> |
| | | /// è·åæ£éåå² |
| | |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | |
| | | // 1. è·åæçåºåä¿¡æ¯ |
| | | var stockInfo = await _stockInfoService.Db.Queryable<Dt_StockInfo>() |
| | | .Includes(x => x.Details) |
| | | .Where(x => x.PalletCode == request.PalletCode) |
| | | .FirstAsync(); |
| | | .Where(x => x.PalletCode == request.PalletCode).FirstAsync(); |
| | | |
| | | if (stockInfo == null) |
| | | return WebResponseContent.Instance.Error("æªæ¾å°æçåºåä¿¡æ¯"); |
| | | |
| | | // 2. è·åç¸å
³çåºåºéå®ä¿¡æ¯ |
| | | |
| | | var lockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(x => x.PalletCode == request.PalletCode && |
| | | x.Status == (int)OutLockStockStatusEnum.åºåºä¸) |
| | | .Where(x => x.OrderNo == request.OrderNo && x.PalletCode == request.PalletCode) |
| | | .ToListAsync(); |
| | | |
| | | // 3. æ´ä¸ªæçåºåº - 设置åºåºæ°éçäºåºåæ°é |
| | | foreach (var detail in stockInfo.Details) |
| | | { |
| | | decimal outboundQuantity = detail.StockQuantity - detail.OutboundQuantity; |
| | | detail.OutboundQuantity = detail.StockQuantity; // å
¨é¨åºåº |
| | | await _stockInfoDetailService.Db.Updateable(detail).ExecuteCommandAsync(); |
| | | } |
| | | |
| | | // 4. æ´æ°åºåºéå®ä¿¡æ¯ |
| | | foreach (var lockInfo in lockInfos) |
| | | { |
| | | decimal unpicked = lockInfo.AssignQuantity - lockInfo.PickedQty; |
| | | lockInfo.PickedQty += unpicked; // æ 记为å
¨é¨æ£é |
| | | if (lockInfo.Status == (int)OutLockStockStatusEnum.åºåºä¸) |
| | | { |
| | | lockInfo.PickedQty = lockInfo.AssignQuantity; |
| | | } |
| | | lockInfo.Status = (int)OutLockStockStatusEnum.å·²åºåº; |
| | | await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync(); |
| | | |
| | | // æ´æ°åºåºåæç» |
| | | var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>() |
| | | .Where(x => x.Id == lockInfo.OrderDetailId) |
| | | .FirstAsync(); |
| | | orderDetail.OverOutQuantity += unpicked; |
| | | orderDetail.LockQuantity -= unpicked; |
| | | orderDetail.OrderDetailStatus = (int)OrderDetailStatusEnum.Over; |
| | | orderDetail.LockQuantity = 0; |
| | | |
| | | await _outboundOrderDetailService.Db.Updateable(orderDetail).ExecuteCommandAsync(); |
| | | .Where(x => x.Id == lockInfo.OrderDetailId) |
| | | .FirstAsync(); |
| | | if (orderDetail != null) |
| | | { |
| | | orderDetail.OverOutQuantity += lockInfo.PickedQty; |
| | | orderDetail.LockQuantity -= lockInfo.PickedQty; |
| | | orderDetail.OrderDetailStatus = (int)OrderDetailStatusEnum.Over; |
| | | orderDetail.LockQuantity = 0; |
| | | await _outboundOrderDetailService.Db.Updateable(orderDetail).ExecuteCommandAsync(); |
| | | } |
| | | } |
| | | var groupDetails = lockInfos.GroupBy(x => x.OrderDetailId).Select(x => new |
| | | { |
| | | OrderDetailId = x.Key, |
| | | TotalQuantity = x.Sum(o => o.PickedQty) |
| | | }).ToList(); |
| | | foreach (var item in groupDetails) |
| | | { |
| | | var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>().Where(x => x.Id == item.OrderDetailId).FirstAsync(); |
| | | if (orderDetail != null) |
| | | { |
| | | orderDetail.OverOutQuantity = item.TotalQuantity; |
| | | orderDetail.LockQuantity = 0; |
| | | orderDetail.OrderDetailStatus = (int)OrderDetailStatusEnum.Over; |
| | | await _outboundOrderDetailService.Db.Updateable(orderDetail).ExecuteCommandAsync(); |
| | | } |
| | | } |
| | | |
| | | // 5. æ´æ°æå
è®°å½ç¶æ |
| | | await CheckAndUpdateOrderStatus(request.OrderNo); |
| | | |
| | | var lockInfoIds = lockInfos.Select(x => x.Id).ToList(); |
| | | var splitRecords = await _splitPackageService.Db.Queryable<Dt_SplitPackageRecord>() |
| | | .Where(x => lockInfoIds.Contains(x.OutStockLockInfoId) && |
| | |
| | | await _splitPackageService.Db.Updateable(record).ExecuteCommandAsync(); |
| | | } |
| | | |
| | | // 6. æ¸
ç©ºè´§ä½ |
| | | |
| | | var location = await _locationInfoService.Db.Queryable<Dt_LocationInfo>() |
| | | .Where(x => x.LocationCode == stockInfo.LocationCode) |
| | | .FirstAsync(); |
| | |
| | | await _locationInfoService.Db.Updateable(location).ExecuteCommandAsync(); |
| | | } |
| | | |
| | | foreach (var detail in stockInfo.Details) |
| | | { |
| | | await _stockInfoDetailService.Db.Deleteable(detail).ExecuteCommandAsync(); |
| | | } |
| | | await _stockInfoService.Db.Deleteable(stockInfo).ExecuteCommandAsync(); |
| | | |
| | | |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | return WebResponseContent.Instance.OK("ç´æ¥åºåºæå"); |
| | | } |