| | |
| | | using System; |
| | | using Microsoft.AspNetCore.Http; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Common.WareHouseEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_DTO.Outbound; |
| | | using WIDESEA_IRecordService; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.Basic; |
| | | |
| | | namespace WIDESEA_IOutboundService |
| | | { |
| | |
| | | public IRepository<Dt_OutStockLockInfo> Repository => BaseDal; |
| | | public IUnitOfWorkManage _unitOfWorkManage; |
| | | |
| | | public OutStockLockInfoService(IRepository<Dt_OutStockLockInfo> BaseDal, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal) |
| | | private readonly IStockService _stockService; |
| | | private readonly IRecordService _recordService; |
| | | |
| | | public OutStockLockInfoService(IRepository<Dt_OutStockLockInfo> BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockService stockService, IRecordService recordService) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _stockService = stockService; |
| | | _recordService = recordService; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// å建åºåºéå® |
| | | /// </summary> |
| | | public Dt_OutStockLockInfo GetOutStockLockInfo( |
| | | Dt_OutboundOrder outboundOrder, |
| | | Dt_OutboundOrderDetail outboundOrderDetail, |
| | | Dt_StockInfo outStock, |
| | | decimal assignQuantity, |
| | | string barcode = null) |
| | | { |
| | | // è·ååºåæç»ä¿¡æ¯ |
| | | var stockDetails = outStock.Details |
| | | .Where(x => x.MaterielCode == outboundOrderDetail.MaterielCode) |
| | | .ToList(); |
| | | |
| | | if (!stockDetails.Any()) |
| | | { |
| | | throw new Exception($"æªæ¾å°ç©æ[{outboundOrderDetail.MaterielCode}]çåºåæç»"); |
| | | } |
| | | |
| | | // ç¡®å®æ¡ç |
| | | string targetBarcode; |
| | | var firstAvailableDetail=new Dt_StockInfoDetail(); |
| | | if (!string.IsNullOrEmpty(barcode)) |
| | | { |
| | | // éªè¯æå®çæ¡ç æ¯å¦åå¨ |
| | | firstAvailableDetail = stockDetails.FirstOrDefault(x => x.Barcode == barcode); |
| | | if (firstAvailableDetail == null) |
| | | { |
| | | throw new Exception($"æå®çæ¡ç [{barcode}]å¨åºåä¸ä¸åå¨"); |
| | | } |
| | | |
| | | targetBarcode = barcode; |
| | | } |
| | | else |
| | | { |
| | | // 使ç¨ç¬¬ä¸ä¸ªå¯ç¨æ¡ç |
| | | firstAvailableDetail = stockDetails |
| | | .Where(x => x.StockQuantity > x.OutboundQuantity) |
| | | .OrderBy(x => x.CreateDate) |
| | | .FirstOrDefault(); |
| | | |
| | | if (firstAvailableDetail == null) |
| | | { |
| | | throw new Exception($"ç©æ[{outboundOrderDetail.MaterielCode}]没æå¯ç¨åºå"); |
| | | } |
| | | targetBarcode = firstAvailableDetail.Barcode; |
| | | } |
| | | |
| | | return new Dt_OutStockLockInfo() |
| | | { |
| | | PalletCode = outStock.PalletCode, |
| | | AssignQuantity = assignQuantity, |
| | | LocationCode = outStock.LocationCode, |
| | | MaterielName = outboundOrderDetail.MaterielName, |
| | | OrderDetailId = outboundOrderDetail.Id, |
| | | OrderNo = outboundOrder.OrderNo, |
| | | OrderQuantity = outboundOrderDetail.OrderQuantity, |
| | | OriginalQuantity = outStock.Details |
| | | .Where(x => x.MaterielCode == outboundOrderDetail.MaterielCode) |
| | | .Sum(x => x.StockQuantity), |
| | | Status = (int)OutLockStockStatusEnum.å·²åé
, |
| | | StockId = outStock.Id, |
| | | OrderType=outboundOrder.OrderType, |
| | | SupplyCode = firstAvailableDetail.SupplyCode, |
| | | WarehouseCode = firstAvailableDetail.WarehouseCode, |
| | | // æ°å¢å段 |
| | | CurrentBarcode = targetBarcode, |
| | | OriginalLockQuantity = assignQuantity, |
| | | IsSplitted = 0, |
| | | MaterielCode = outboundOrderDetail.MaterielCode, |
| | | BatchNo = firstAvailableDetail.BatchNo, |
| | | Unit = firstAvailableDetail.Unit, |
| | | FactoryArea = firstAvailableDetail.FactoryArea, |
| | | lineNo = outboundOrderDetail.lineNo, |
| | | }; |
| | | } |
| | | |
| | | |
| | | public List<Dt_OutStockLockInfo> GetOutStockLockInfos(Dt_OutboundOrder outboundOrder, Dt_OutboundOrderDetail outboundOrderDetail, List<Dt_StockInfo> outStocks, int? taskNum = null) |
| | | { |
| | | List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>(); |
| | | |
| | | foreach (var item in outStocks) |
| | | { |
| | | Dt_OutStockLockInfo outStockLockInfo = new Dt_OutStockLockInfo() |
| | | { |
| | | PalletCode = item.PalletCode, |
| | | AssignQuantity = item.Details.Where(x => x.MaterielCode == outboundOrderDetail.MaterielCode).Sum(x => x.OutboundQuantity), |
| | | MaterielCode = outboundOrderDetail.MaterielCode, |
| | | BatchNo = outboundOrderDetail.BatchNo, |
| | | LocationCode = item.LocationCode, |
| | | MaterielName = outboundOrderDetail.MaterielName, |
| | | OrderDetailId = outboundOrderDetail.Id, |
| | | OrderNo = outboundOrder.OrderNo, |
| | | OrderType = outboundOrder.OrderType, |
| | | OriginalQuantity = item.Details.Where(x => x.MaterielCode == outboundOrderDetail.MaterielCode).Sum(x => x.StockQuantity), |
| | | Status = taskNum == null ? OutLockStockStatusEnum.å·²åé
.ObjToInt() : OutLockStockStatusEnum.åºåºä¸.ObjToInt(), |
| | | StockId = item.Id, |
| | | TaskNum = taskNum, |
| | | |
| | | |
| | | }; |
| | | outStockLockInfos.Add(outStockLockInfo); |
| | | } |
| | | |
| | | return outStockLockInfos; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è®¢åæç»IDè·ååºåºéå®ä¿¡æ¯ |
| | | /// </summary> |
| | | public async Task<List<Dt_OutStockLockInfo>> GetByOrderDetailId(int orderDetailId) |
| | | { |
| | | return await Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(x => x.OrderDetailId == orderDetailId) |
| | | .OrderBy(x => x.Id) |
| | | .ToListAsync(); |
| | | } |
| | | |
| | | public async Task<LockInfoDetailDto> GetLockInfoDetail(int lockInfoId) |
| | | { |
| | | var lockInfo = await Db.Queryable<Dt_OutStockLockInfo>() |
| | | .LeftJoin<Dt_OutboundOrderDetail>((lockInfo, detail) => lockInfo.OrderDetailId == detail.Id) |
| | | .Where((lockInfo, detail) => lockInfo.Id == lockInfoId) |
| | | .Select((lockInfo, detail) => new LockInfoDetailDto |
| | | { |
| | | Id = lockInfo.Id, |
| | | OrderNo = lockInfo.OrderNo, |
| | | OrderDetailId = lockInfo.OrderDetailId, |
| | | BatchNo = lockInfo.BatchNo, |
| | | MaterielCode = lockInfo.MaterielCode, |
| | | StockId = lockInfo.StockId, |
| | | OrderQuantity = lockInfo.OrderQuantity, |
| | | OriginalQuantity = lockInfo.OriginalQuantity, |
| | | AssignQuantity = lockInfo.AssignQuantity, |
| | | PickedQty = lockInfo.PickedQty, |
| | | LocationCode = lockInfo.LocationCode, |
| | | PalletCode = lockInfo.PalletCode, |
| | | Status = lockInfo.Status, |
| | | IsSplitted = lockInfo.IsSplitted, |
| | | ParentLockId = lockInfo.ParentLockId, |
| | | |
| | | MaterielName = detail.MaterielName, |
| | | Unit = detail.Unit |
| | | }) |
| | | .FirstAsync(); |
| | | |
| | | return lockInfo; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®æçç¼å·è·ååºåºéå®ä¿¡æ¯ |
| | | /// </summary> |
| | | public async Task<List<Dt_OutStockLockInfo>> GetByPalletCode(string palletCode, int? status = null) |
| | | { |
| | | var query = Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(x => x.PalletCode == palletCode); |
| | | |
| | | if (status.HasValue) |
| | | { |
| | | query = query.Where(x => x.Status == status.Value); |
| | | } |
| | | |
| | | return await query.OrderBy(x => x.Id).ToListAsync(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åæççéå®ä¿¡æ¯ |
| | | /// </summary> |
| | | public async Task<List<Dt_OutStockLockInfo>> GetPalletLockInfos(string palletCode) |
| | | { |
| | | return await Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(x => x.PalletCode == palletCode && x.Status == (int)OutLockStockStatusEnum.åºåºä¸) |
| | | .ToListAsync(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ´æ°åºåºéå®ä¿¡æ¯çæ¡ç ï¼ç¨äºæå
æä½ï¼ |
| | | /// </summary> |
| | | public async Task<WebResponseContent> UpdateLockInfoBarcode(int lockInfoId, string newBarcode) |
| | | { |
| | | try |
| | | { |
| | | var lockInfo = await Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(x => x.Id == lockInfoId) |
| | | .FirstAsync(); |
| | | |
| | | if (lockInfo == null) |
| | | return WebResponseContent.Instance.Error("æªæ¾å°åºåºéå®ä¿¡æ¯"); |
| | | |
| | | // éªè¯æ°æ¡ç æ¯å¦åå¨ |
| | | var stockDetail = await Db.Queryable<Dt_StockInfoDetail>() |
| | | .Where(x => x.Barcode == newBarcode && |
| | | x.StockId == lockInfo.StockId && |
| | | x.MaterielCode == lockInfo.MaterielCode) |
| | | .FirstAsync(); |
| | | |
| | | if (stockDetail == null) |
| | | return WebResponseContent.Instance.Error("æ°æ¡ç å¨åºåä¸ä¸åå¨"); |
| | | |
| | | // æ´æ°æ¡ç åæå
ç¶æ |
| | | lockInfo.CurrentBarcode = newBarcode; |
| | | lockInfo.IsSplitted = 1; |
| | | |
| | | await Db.Updateable(lockInfo).ExecuteCommandAsync(); |
| | | |
| | | return WebResponseContent.Instance.OK("æ´æ°æ¡ç æå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æ´æ°æ¡ç 失败: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | public List<Dt_OutStockLockInfo> GetByOrderDetailId(int orderDetailId, OutLockStockStatusEnum? outStockStatus) |
| | | { |
| | | return BaseDal.QueryData(x => x.OrderDetailId == orderDetailId ); |
| | | } |
| | | |
| | | } |