| | |
| | | using WIDESEA_IOutboundService; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.Basic; |
| | | |
| | | namespace WIDESEA_OutboundService |
| | | { |
| | |
| | | private readonly IOutStockLockInfoService _outStockLockInfoService; |
| | | private readonly IDailySequenceService _dailySequenceService; |
| | | private readonly IInvokeMESService _invokeMESService; |
| | | |
| | | private readonly IMaterielToMesService _materielToMesService; |
| | | private readonly ILogger<SplitPackageService> _logger; |
| | | public SplitPackageService(IRepository<Dt_SplitPackageRecord> BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockInfoService stockInfoService, IOutStockLockInfoService outStockLockInfoService, IStockInfoDetailService stockInfoDetailService, IDailySequenceService dailySequenceService, IInvokeMESService invokeMESService, ILogger<SplitPackageService> logger) : base(BaseDal) |
| | | public SplitPackageService(IRepository<Dt_SplitPackageRecord> BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockInfoService stockInfoService, IOutStockLockInfoService outStockLockInfoService, IStockInfoDetailService stockInfoDetailService, IDailySequenceService dailySequenceService, IInvokeMESService invokeMESService, ILogger<SplitPackageService> logger, IMaterielToMesService materielToMesService) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _stockInfoService = stockInfoService; |
| | |
| | | _dailySequenceService = dailySequenceService; |
| | | _invokeMESService = invokeMESService; |
| | | _logger = logger; |
| | | _materielToMesService = materielToMesService; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æå
æç®±æä½ |
| | | /// </summary> |
| | | //public async Task<WebResponseContent> SplitPackage(SplitPackageDto request) |
| | | //{ |
| | | // try |
| | | // { |
| | | // _unitOfWorkManage.BeginTran(); |
| | | |
| | | // // 1. éªè¯åºåºéå®ä¿¡æ¯ |
| | | // var lockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | | // .Where(x => x.OrderNo == request.OrderNo && |
| | | // x.PalletCode == request.PalletCode && |
| | | // x.CurrentBarcode == request.OriginalBarcode && |
| | | // x.Status == 1) |
| | | // .FirstAsync(); |
| | | |
| | | // if (lockInfo == null) |
| | | // return WebResponseContent.Instance.Error("æªæ¾å°ææçåºåºéå®ä¿¡æ¯"); |
| | | |
| | | // // 2. æ£æ¥å©ä½é宿°é |
| | | // decimal remainingLockQuantity = lockInfo.OriginalQuantity - lockInfo.PickedQty; |
| | | // if (request.SplitQuantity > remainingLockQuantity) |
| | | // return WebResponseContent.Instance.Error($"æå
æ°éä¸è½å¤§äºå©ä½é宿°éï¼å©ä½ï¼{remainingLockQuantity}"); |
| | | |
| | | // var baseStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>() |
| | | // .Where(x => x.Barcode == request.OriginalBarcode && x.StockId == lockInfo.StockId) |
| | | // .FirstAsync(); |
| | | // if (baseStockDetail == null) |
| | | // throw new Exception($"æªæ¾å°æ¡ç {request.OriginalBarcode}对åºçåºåè®°å½"); |
| | | |
| | | |
| | | // // 4. è®¡ç®æååçæ°é |
| | | // decimal remainingQty = baseStockDetail.StockQuantity - request.SplitQuantity; |
| | | |
| | | // // æ´æ°åºç¡æ¡ç çåºåæ°é为å©ä½æ°é |
| | | // baseStockDetail.StockQuantity = remainingQty; |
| | | // baseStockDetail.OutboundQuantity = remainingQty; |
| | | // await _stockInfoDetailService.Db.Updateable(baseStockDetail).ExecuteCommandAsync(); |
| | | |
| | | |
| | | // var seq = await _dailySequenceService.GetNextSequenceAsync(); |
| | | // // 3. çææ°æ¡ç |
| | | // string newBarcode = "WSLOT" + DateTime.Now.ToString("yyyyMMdd") + seq.ToString()?.PadLeft(5, '0'); |
| | | |
| | | |
| | | // // 为æå
产ççæ°æ¡ç å建åºåè®°å½ |
| | | // var newStockDetail = new Dt_StockInfoDetail |
| | | // { |
| | | // SupplyCode = baseStockDetail.SupplyCode, |
| | | // WarehouseCode = baseStockDetail.WarehouseCode, |
| | | // BarcodeQty = baseStockDetail.BarcodeQty, |
| | | // BarcodeUnit = baseStockDetail.BarcodeUnit, |
| | | // BusinessType = baseStockDetail.BusinessType, |
| | | // Unit = baseStockDetail.Unit, |
| | | // StockId = lockInfo.StockId, |
| | | // MaterielCode = baseStockDetail.MaterielCode, |
| | | // OrderNo = baseStockDetail.OrderNo, |
| | | // BatchNo = baseStockDetail.BatchNo, |
| | | // StockQuantity = request.SplitQuantity, // æ°æ¡ç è·å¾æåæ°é |
| | | // OutboundQuantity = request.SplitQuantity, |
| | | // Barcode = newBarcode, |
| | | // InboundOrderRowNo = baseStockDetail.InboundOrderRowNo, |
| | | |
| | | // }; |
| | | // await _outStockLockInfoService.Db.Insertable(newStockDetail).ExecuteCommandAsync(); |
| | | |
| | | // // 4. å建æ°çåºåºéå®ä¿¡æ¯ï¼æ°æ¡ç ï¼ |
| | | // var newLockInfo = new Dt_OutStockLockInfo |
| | | // { |
| | | |
| | | // OrderNo = lockInfo.OrderNo, |
| | | // OrderDetailId = lockInfo.OrderDetailId, |
| | | // BatchNo = lockInfo.BatchNo, |
| | | // MaterielCode = lockInfo.MaterielCode, |
| | | // MaterielName = lockInfo.MaterielName, |
| | | // StockId = lockInfo.StockId, |
| | | // OrderQuantity = request.SplitQuantity, |
| | | // OriginalQuantity = request.SplitQuantity, |
| | | // AssignQuantity = request.SplitQuantity, // æ°æ¡ç åé
æ°é |
| | | // PickedQty = 0, // æ°æ¡ç æªæ£é |
| | | // LocationCode = lockInfo.LocationCode, |
| | | // PalletCode = lockInfo.PalletCode, |
| | | // TaskNum = lockInfo.TaskNum, |
| | | // Status = (int)OutLockStockStatusEnum.åºåºä¸, |
| | | // Unit = lockInfo.Unit, |
| | | // SupplyCode = lockInfo.SupplyCode, |
| | | // OrderType = lockInfo.OrderType, |
| | | // CurrentBarcode = newBarcode, // æ°æ¡ç |
| | | // OriginalLockQuantity = request.SplitQuantity, |
| | | // IsSplitted = 1, |
| | | // ParentLockId = lockInfo.Id // è®°å½ç¶çº§éå®ID |
| | | // }; |
| | | // await _outStockLockInfoService.Db.Insertable(newLockInfo).ExecuteCommandAsync(); |
| | | |
| | | // lockInfo.AssignQuantity = remainingQty; |
| | | // lockInfo.IsSplitted = 1; // æ 记为已æå
|
| | | // await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync(); |
| | | |
| | | // var previousSplitRecord = await Db.Queryable<Dt_SplitPackageRecord>() |
| | | // .Where(x => x.OriginalBarcode == request.OriginalBarcode && !x.IsReverted) |
| | | // .OrderByDescending(x => x.SplitTime) |
| | | // .FirstAsync(); |
| | | |
| | | // // 6. è®°å½æå
åå²ï¼ç¨äºè¿½è¸ªï¼ |
| | | // var splitHistory = new Dt_SplitPackageRecord |
| | | // { |
| | | // FactoryArea = lockInfo.FactoryArea, |
| | | // TaskNum = lockInfo.TaskNum, |
| | | // OutStockLockInfoId = lockInfo.Id, |
| | | // StockId = baseStockDetail.StockId, |
| | | // Operator = App.User.UserName, |
| | | // IsReverted = false, |
| | | // OriginalBarcode = request.OriginalBarcode, |
| | | // NewBarcode = newBarcode, |
| | | // SplitQty = request.SplitQuantity, |
| | | // RemainQuantity = remainingQty, // è®°å½æååçå©ä½æ°é |
| | | // MaterielCode = lockInfo.MaterielCode, |
| | | // SplitTime = DateTime.Now, |
| | | // OrderNo = request.OrderNo, |
| | | // PalletCode = request.PalletCode, |
| | | // Status = (int)SplitPackageStatusEnum.å·²æå
, |
| | | // PreviousSplitRecordId = previousSplitRecord?.Id??0 // è®°å½å䏿¬¡æå
IDï¼å»ºç«æå
é¾ |
| | | // }; |
| | | // await Db.Insertable(splitHistory).ExecuteCommandAsync(); |
| | | |
| | | // _unitOfWorkManage.CommitTran(); |
| | | |
| | | // try |
| | | // { |
| | | // MaterielToMesDTO dto = new MaterielToMesDTO |
| | | // { |
| | | // batchNo = baseStockDetail.BatchNo, |
| | | // factoryArea = baseStockDetail.FactoryArea, |
| | | // materialCode = baseStockDetail.MaterielCode, |
| | | // newmaterialCode = newBarcode, |
| | | // oldmaterialCode = request.OriginalBarcode, |
| | | // operationType = 1, |
| | | // qty = remainingQty, |
| | | // supplyCode = baseStockDetail.SupplyCode, |
| | | // unit = baseStockDetail.BarcodeUnit, |
| | | // warehouseCode = baseStockDetail.WarehouseCode, |
| | | // reqCode = Guid.NewGuid().ToString(), |
| | | // reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") |
| | | // }; |
| | | // _invokeMESService.NewMaterielToMes(dto); |
| | | // } |
| | | // catch(Exception ex) |
| | | // { |
| | | // _logger.LogError("SplitPackage åä¼ MES: " + ex.Message); |
| | | // } |
| | | // return WebResponseContent.Instance.OK("æå
æå", new |
| | | // { |
| | | // NewBarcode = newBarcode, |
| | | // NewLockInfoId = newLockInfo.Id |
| | | // }); |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // _unitOfWorkManage.RollbackTran(); |
| | | // return WebResponseContent.Instance.Error($"æå
失败: {ex.Message}"); |
| | | // } |
| | | //} |
| | | // è·åæ¡ç çæå
åå²é¾ |
| | | |
| | | public async Task<WebResponseContent> SplitPackage(SplitPackageDto request) |
| | | { |
| | |
| | | CurrentBarcode = newBarcode, |
| | | OriginalLockQuantity = request.SplitQuantity, |
| | | IsSplitted = 1, |
| | | ParentLockId = lockInfo.Id |
| | | ParentLockId = lockInfo.Id, |
| | | Operator = App.User.UserName, |
| | | FactoryArea = lockInfo.FactoryArea, |
| | | lineNo = lockInfo.lineNo, |
| | | WarehouseCode = lockInfo.WarehouseCode, |
| | | }; |
| | | await _outStockLockInfoService.Db.Insertable(newLockInfo).ExecuteCommandAsync(); |
| | | |
| | |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | try |
| | | { |
| | | |
| | | var dt_MaterielToMes = new Dt_MaterielToMes |
| | | { |
| | | OldMaterialBarCode = request.OriginalBarcode, |
| | | NewMaterialBarCode = newBarcode, |
| | | Unit = baseStockDetail.BarcodeUnit, |
| | | factoryArea = baseStockDetail.FactoryArea, |
| | | Qty = remainingQty, |
| | | supplyCode = baseStockDetail.SupplyCode, |
| | | warehouseCode = baseStockDetail.WarehouseCode, |
| | | BatchNo = baseStockDetail.BatchNo, |
| | | MaterielCode = baseStockDetail.MaterielCode, |
| | | |
| | | }; |
| | | _materielToMesService.AddData(dt_MaterielToMes); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogError("SplitPackage åä¼ MES: " + ex.Message); |
| | | } |
| | | |
| | | return WebResponseContent.Instance.OK("æå
æå", new SplitPackageChainDto |
| | | { |
| | | NewBarcode = newBarcode, |