public async Task <ReelSupplyResultDto> Supply(ReelSupplyInputDto[] input) { ReelSupplyResultDto res = new ReelSupplyResultDto() { ErrorMsgs = new List <string>(), IsSuccess = true }; List <ReelSupplyTemp> reelSupplyTemps = new List <ReelSupplyTemp>(); await _repository.DeleteAsync(r => true); var la = await _repositorySL.GetAllListAsync(s => s.LightState != LightState.Off); foreach (var sl in la) { sl.LightState = LightState.Off; // await _repositorySL.UpdateAsync(sl); } CurrentUnitOfWork.SaveChanges(); // 查询备损数量 var readyLossQty = SettingManager.GetSettingValueForTenant <int>("readyLossQty", AbpSession.TenantId.Value);// int.Parse(_repositoryT.FirstOrDefault(c => c.TenantId == AbpSession.TenantId && c.Name == "readyLossQty").Value); // 查询提前预警天数 var overdueDay = SettingManager.GetSettingValueForTenant <int>("overdueDay", AbpSession.TenantId.Value); //int.Parse(_repositoryT.FirstOrDefault(c => c.TenantId == AbpSession.TenantId && c.Name == "overdueDay").Value); // 查询强制先进先出天数 var mustFifoDay = SettingManager.GetSettingValueForTenant <int>("mustFifoDay", AbpSession.TenantId.Value); //int.Parse(_repositoryT.FirstOrDefault(c => c.TenantId == AbpSession.TenantId && c.Name == "mustFifoDay").Value); // 补料调拨策略 var reelSupplyMethodId = SettingManager.GetSettingValueForTenant("reelSupplyMethodId", AbpSession.TenantId.Value);// _repositoryT.FirstOrDefault(c => c.TenantId == AbpSession.TenantId && c.Name == "reelSupplyMethodId").Value; // 获取补料调拨策略 var reelSupplyMethod = await _repositoryRMM.GetAllIncluding(r => r.OutStorages).FirstOrDefaultAsync(r => r.Id == reelSupplyMethodId); if (reelSupplyMethod == null) { res.ErrorMsgs.Add("未配置补料调拨策略"); throw new LYException(res); } // 按备料单分组 foreach (var item in input.GroupBy(r => r.ReadyMBillId)) { // 查询当前备料单详细 var readyNow = await _repositoryrb.FirstOrDefaultAsync(item.Key); if (readyNow == null) { res.ErrorMsgs.Add("备料单[" + item.Key + "]不存在"); continue; } // 先假设没有关联的备料单信息 var allReadys = new List <ReadyMBill>() { readyNow }; if (readyNow.ReReadyMBillId != null) { // 查询备料单关联的所有备料单是否包含当前物料 allReadys = await _repositoryrb.GetAll().Where(r => r.ReReadyMBillId == readyNow.ReReadyMBillId).ToListAsync(); } foreach (var pn in item) { // 查询所有备料详细是否包含该物料 var pnInfo = await _repositoryrbd.GetAll().Where(r => allReadys.Select(rm => rm.Id).Contains(r.ReadyMBillId) && r.PartNoId == pn.PartNoId).FirstOrDefaultAsync(); if (pnInfo == null) { res.ErrorMsgs.Add("备料单[" + item.Key + "]及其合并的备料单不包含物料[" + pn + "]的备料信息"); continue; } // 查询物料基础信息 var mpn = await _repositorympn.FirstOrDefaultAsync(pn.PartNoId); // 查询库存中该料号所有物料 在库存中挑料,分为两部分.一部分强制先进先出。一部分按数量挑选 var reels = _repositoryReel.GetAll().Where(r => r.StorageLocationId.Length > 0 && // 有库位 r.IsActive && // 有效 r.PartNoId == pn.PartNoId && // 料号正确 reelSupplyMethod.OutStorages.Select(s => s.StorageId).Contains(r.StorageId) // 仓库正确 ).ToList() .Where(r => r.MakeDate.AddDays(mpn.ShelfLife + r.ExtendShelfLife - overdueDay) > DateTime.Now && reelSupplyTemps.FirstOrDefault(s => s.Id == r.Id) == null) // 未过期 且未被挑料 .ToList(); // 按d/c 进行先进先出排序 // && r.MakeDate.AddDays(mpn.ShelfLife + r.ExtendShelfLife - mustFifoDay) > DateTime.Now // 必须先进先出 var nowDemandSendQty = pn.Qtys; // 死循环挑料,库存料盘还有。且没挑够,且站位未发够 while (reels.Count > 0 && nowDemandSendQty > 0) { // 先挑选强制发料物料 var reel = reels.Where(r => r.MakeDate.AddDays(mpn.ShelfLife + r.ExtendShelfLife - mustFifoDay) > DateTime.Now).OrderBy(r => r.MakeDate).FirstOrDefault(); if (reel == null) // 没有强制先进先出 { // 获取库存最大料盘数量 var maxQtyReel = reels.OrderBy(r => r.Qty).FirstOrDefault().Qty; if (nowDemandSendQty > maxQtyReel) { // 当需求数大于库存最大料盘数量,按FIFO取同数量中物料 reel = reels.Where(r => r.Qty == maxQtyReel).OrderBy(r => r.MakeDate).FirstOrDefault(); } else { // 当需求数小于库存最大料盘数量 // 1、先查询库存数量大于需求数且差距最小物料 reel = reels.Where(r => r.Qty > nowDemandSendQty).OrderBy(r => reel.Qty).FirstOrDefault(); if (reel == null) { // 2、如果没有数量大于需求数物料,直接从最大包装开始拿料 reel = reels.OrderByDescending(r => r.Qty).FirstOrDefault(); } } } // 模拟添加发料临时表,且标记为已发 reelSupplyTemps.Add(new ReelSupplyTemp() { Id = reel.Id, IsActive = true, PartNoId = pn.PartNoId, DemandQty = pn.Qtys, DemandSendQty = pn.Qtys, IsSend = false, Qty = reel.Qty, SendQty = reel.Qty, StorageLocationId = reel.StorageLocationId, ReelMoveMethodId = reelSupplyMethodId, ReReadyMBillId = readyNow.ReReadyMBillId == null ? readyNow.Id : readyNow.ReReadyMBillId, ReadyMBillDetailedId = pnInfo.Id, // SlotId = slot.Id }); // 标记亮灯,真正的亮灯操作。移到专门的亮灯客户端 var sl = _repositorySL.Get(reel.StorageLocationId); sl.LightState = LightState.On; _repositorySL.Update(sl); // 已发数量 // readySlotD.SendQty += reel.Qty; // reel.SlotId = slot.Id; // 更新站位数量 // slotQty -= reel.Qty; // 移除当前料盘,让其不进入下一次挑料 reels.Remove(reel); // 重新计算当前需求数 nowDemandSendQty = nowDemandSendQty - reel.Qty; } } } // 最后进行亮灯 foreach (var reelSupplyTemp in reelSupplyTemps) { await _repository.InsertAsync(reelSupplyTemp); } CurrentUnitOfWork.SaveChanges(); // 亮灯 var lights = _repositorySL.GetAllList(s => s.LightState == LightState.On); //小灯 var simlights = lights.Select(l => new StorageLight() { ContinuedTime = 10, LightOrder = 1, MainBoardId = l.MainBoardId, RackPositionId = l.PositionId }).ToList(); LightService.LightOrder(simlights); // 灯塔 var houselights = simlights.Select(l => new HouseLight() { HouseLightSide = 1, LightOrder = 1, MainBoardId = l.MainBoardId }).Distinct().ToList(); // await _notificationService.SendNotification("HouseOrder", houselights); LightService.HouseOrder(houselights); res.ErrorMsgs.Add("补料挑料成功" + (res.ErrorMsgs.Count > 0 ? "部分条目补料失败" : "")); res.IsSuccess = true; return(res); }
public async Task <ReelMoveResDto> ReelMove(ReelMoveDto inputDto) { // Logger.Info("tm1" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss ffff")); // 获取调拨策略信息 ReelMoveMethod reelMoveMethod = await _repositoryRMM.GetAll().Where(m => m.Id == inputDto.ReelMoveMethodId).Include(m => m.OutStorages).FirstOrDefaultAsync(); // 条码解析信息 ReelDto reelDto = null; // 料盘信息 Reel reel = null; // 料盘物料信息 MPN reelMpn = null; // 日志信息 ReelMoveLog reelMoveLog = new ReelMoveLog() { ReelMoveMethodId = reelMoveMethod.Id }; // 返回信息 ReelMoveResDto resDto = new ReelMoveResDto() { IsContinuity = inputDto.IsContinuity, Msg = "操作成功", NextShlefLab = inputDto.ShlefLab }; // 下架货架信息 StorageLocation shelfUp = null; // 上架货架信息 StorageLocation shelfOn = null; // 条码解析 Func <Task> BarCodeAnalysis = new Func <Task>(async() => { if (reelDto == null) { var analysisRes = await _barCodeAnalysisAppService.Analysis(new BaseData.BarCodeAnalysiss.Dto.AnalysisDto() { BarCode = inputDto.BarCode, DtoName = "ReelDto" }); if (!analysisRes.Success) { resDto.Msg = analysisRes.Msg; throw new LYException(resDto.Msg); } else { reelDto = analysisRes.Result as ReelDto; } } }); // 检查料盘 Func <Task> CheckReel = new Func <Task>(async() => { if (reelDto == null) { await BarCodeAnalysis(); } if (reel == null) { reel = await _repository.FirstOrDefaultAsync(reelDto.Id); if (reel == null) { throw new LYException(reelDto.Id + "不存在,请先进行料卷注册"); } reelMoveLog.ReelId = reel.Id; reelMoveLog.PartNoId = reel.PartNoId; reelMoveLog.Qty = reel.Qty; } }); // 检查库位信息 Func <Task> CheckShelfOn = new Func <Task>(async() => { if (shelfOn == null) { shelfOn = await _repositorysl.FirstOrDefaultAsync(inputDto.ShlefLab); if (shelfOn == null) { resDto.Msg = "库位[" + inputDto.ShlefLab + "]不存在"; throw new LYException(resDto.Msg); } reelMoveLog.StorageLocationId = shelfOn.Id; } }); // 获取物料信息 Func <Task> CheckMPN = new Func <Task>(async() => { if (reelMpn == null) { reelMpn = await _repositorympn.FirstOrDefaultAsync(reelDto.PartNoId); if (reelMpn == null) { resDto.Msg = "料号[" + reel.PartNoId + "]未维护"; throw new LYException(resDto.Msg); } } }); // 获取物料库位信息 Func <Task> GetShelfUp = new Func <Task>(async() => { shelfUp = await _repositorysl.FirstOrDefaultAsync(reel.StorageLocationId); if (shelfUp == null) { resDto.Msg = "料盘[" + reel.Id + "]未上架"; throw new LYException(resDto.Msg); } reelMoveLog.StorageLocationId = shelfUp.Id; }); foreach (var allocationType in reelMoveMethod.AllocationTypes) { switch (allocationType) { case AllocationType.Move: case AllocationType.OnSL: case AllocationType.UpSl: case AllocationType.Send: case AllocationType.Return: case AllocationType.Received: case AllocationType.SendFirstReel: case AllocationType.SupplyReel: if (reel == null) // 进行料卷检查 { await CheckReel(); } switch (allocationType) { case AllocationType.Move: // 转仓 #region 转仓 // 检查料卷调出仓是否合法 if (!reelMoveMethod.OutStorages.Select(s => s.StorageId).Contains(reel.StorageId)) { resDto.Msg = "料卷不属于该调拨策略的调出仓[" + string.Join('|', reelMoveMethod.OutStorages.Select(s => s.StorageId)) + "]"; throw new LYException(resDto.Msg); } // 进行转仓 reel.StorageId = reelMoveMethod.InStorageId; #endregion break; case AllocationType.OnSL: // 上架 #region 架 if (shelfOn == null) { await CheckShelfOn(); // 检查库位信息 } // 库位是否有料 if (shelfOn.ReelId != null) { resDto.Msg = "库位[" + inputDto.ShlefLab + "]已绑定料卷[" + shelfOn.ReelId + "]"; throw new LYException(1, resDto.Msg); } // 库位是否在转入仓 if (shelfOn.StorageId != reelMoveMethod.InStorageId) { resDto.Msg = "库位[" + inputDto.ShlefLab + "]不不属于[" + reelMoveMethod.InStorageId + "]仓"; throw new LYException(1, resDto.Msg); } // 料卷是否上架 if (reel.StorageLocationId != null) { resDto.Msg = "料卷[" + reel.Id + "]已经上架[" + reel.StorageLocationId + "]"; throw new LYException(resDto.Msg); } // 查询物料可用区域 var mpnA = _repositorysMPNA.GetAll().Where(r => r.MPNId == reel.PartNoId).ToArray(); if (mpnA.Length > 0 && !mpnA.Select(r => r.StorageAreaId).Contains(shelfOn.StorageAreaId)) { resDto.Msg = "物料[" + reel.PartNoId + "]允许上架分区为[" + string.Join('|', mpnA.Select(r => r.StorageAreaId)) + "]"; throw new LYException(resDto.Msg); } else { if (shelfOn.StorageAreaId != null && !mpnA.Select(r => r.StorageAreaId).Contains(shelfOn.StorageAreaId)) { resDto.Msg = "分区[" + shelfOn.StorageAreaId + "]不允许物料[" + reel.PartNoId + "]上架"; throw new LYException(resDto.Msg); } } // Logger.Info("tm91" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss ffff")); // 寻找下一个空库位 var nextShelf = await _repositorysl.GetAll() .Where(s => s.MainBoardId == shelfOn.MainBoardId && s.PositionId > shelfOn.PositionId && (s.ReelId == null || s.ReelId.Length == 0)) .OrderBy(s => s.PositionId) .FirstOrDefaultAsync(); // Logger.Info("tm92" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss ffff")); if (nextShelf != null) { resDto.NextShlefLab = nextShelf.Id; } else { resDto.IsContinuity = false; } // 进行上架双向绑定 reel.StorageLocationId = shelfOn.Id; shelfOn.ReelId = reel.Id; // 保存上架信息 // _repositorysl.Update(shelfOn); #endregion break; case AllocationType.UpSl: // 下架 #region 架 await GetShelfUp(); // 清除双向绑定 shelfUp.ReelId = null; reel.StorageLocationId = null; LightService.LightOrder(new List <StorageLight>() { new StorageLight() { ContinuedTime = 10, LightOrder = 0, MainBoardId = shelfUp.MainBoardId, LightColor = shelfUp.LightColor, RackPositionId = shelfUp.PositionId } }); #endregion break; case AllocationType.Send: // 发料 #region 发料 // 检测发料临时表里面有没有该数据 var sendtemp = await _repositoryRST.FirstOrDefaultAsync(reel.Id); if (sendtemp == null) { resDto.Msg = "料卷未被挑料"; throw new LYException(resDto.Msg); } // 查询挑料料站表行数据 var readySlot = await _repositorySlot.FirstOrDefaultAsync(sendtemp.SlotId); if (sendtemp.IsSend) { if (readySlot != null) { resDto.Msg = @"料卷已经发料 " + sendtemp.FisrtStorageLocationId + "" + "\r\n站位信息: \r\n" + "面别: [" + (readySlot.BoardSide == SideType.B ? "S" : "C") + "]\r\n机器: [" + readySlot.Machine + "]\r\nTable: [" + readySlot.Table + "]\r\n站位: [" + readySlot.SlotName + "]\r\n边别: [" + (readySlot.Side == SideType.L ? "L" : "R") + "]"; } else { resDto.Msg = "料卷已经发料"; } throw new LYException(resDto.Msg); } // 查询挑料明细行数据 var readyBillD = await _repositoryReadyMBilld.FirstOrDefaultAsync(sendtemp.ReadyMBillDetailedId); // 改变发料状态 sendtemp.IsSend = true; // 添加发料数量 readyBillD.SendQty += reel.Qty; // 改变料盘备料关联 reel.ReadyMBillDetailedId = readyBillD.Id; reel.ReadyMBillId = readyBillD.ReadyMBillId; // 改变物料料站表绑定 reel.SlotId = sendtemp.SlotId; // 改变日志备料关联 reelMoveLog.ReadyMBillDetailedId = readyBillD.Id; reelMoveLog.ReadyMBillId = readyBillD.ReadyMBillId; reelMoveLog.SlotId = sendtemp.SlotId; // 灭灯 await GetShelfUp(); shelfUp.LightState = LightState.Off; // 如果发料完成,删除临时表 if (_repositoryRST.GetAll().Where(r => r.ReReadyMBillId == sendtemp.ReReadyMBillId && r.IsSend == false).Count() == 1) { await _repositoryRST.DeleteAsync(r => r.ReReadyMBillId == sendtemp.ReReadyMBillId); } // 查询当前物料的站位信息 if (readySlot != null) { resDto.Msg = "站位信息: \r\n" + "面别: [" + (readySlot.BoardSide == SideType.B ? "S" : "C") + "]\r\n机器: [" + readySlot.Machine + "]\r\nTable: [" + readySlot.Table + "]\r\n站位: [" + readySlot.SlotName + "]\r\n边别: [" + (readySlot.Side == SideType.L ? "L" : "R") + "]"; } else { resDto.Msg = "发料成功"; } var readyMs = await _repositoryReadyMBill.GetAll().Where(r => r.ReReadyMBillId == sendtemp.ReReadyMBillId).ToListAsync(); var readyMss = readyMs.Select(r => r.Id); var readyMBs = await _repositoryReadyMBilld.GetAll().Where(r => readyMss.Contains(r.ReadyMBillId)) .Select(r => new { r.PartNoId, r.Qty, r.SendQty, r.ReturnQty }) .ToListAsync(); if (readyMBs.GroupBy(r => r.PartNoId).Select(r => new { r.Key, Qty = r.Sum(s => s.SendQty) - r.Sum(s => s.Qty) }).Where(r => r.Qty < 0).Count() == 1) { foreach (var item in readyMs) { item.ReadyMStatus = ReadyMStatus.Finish; } } // 如果为首料进行小车闪灯 if (sendtemp.FisrtStorageLocationId != null && sendtemp.FisrtStorageLocationId.Length > 0) { var shelfF = await _repositorysl.FirstOrDefaultAsync(sendtemp.FisrtStorageLocationId); StorageLight storage = new StorageLight() { ContinuedTime = 10, LightOrder = 2, MainBoardId = shelfF.MainBoardId, RackPositionId = shelfF.PositionId, LightColor = shelfF.LightColor }; LightService.LightOrder(new List <StorageLight>() { storage }); } // 灭小灯和塔灯 LightService.LightOrder(new List <StorageLight>() { new StorageLight() { ContinuedTime = 10, LightOrder = 0, MainBoardId = shelfUp.MainBoardId, LightColor = shelfUp.LightColor, RackPositionId = shelfUp.PositionId } }); CurrentUnitOfWork.SaveChanges(); // 大灯 可能需要修改 var lights = _repositorysl.GetAll().Where(s => s.MainBoardId == shelfUp.MainBoardId && s.LightState != LightState.Off && s.LightColor == shelfUp.LightColor); if (lights.Count() == 0) { LightService.HouseOrder(new List <HouseLight>() { new HouseLight() { HouseLightSide = 1, LightOrder = 0, LightColor = shelfUp.LightColor, MainBoardId = shelfUp.MainBoardId } }); } #endregion break; case AllocationType.Return: // 退料 // 查询最近的发料日志 var sendLog = await _repositoryReelMoveLog.GetAll().Where(r => r.IsActive && r.ReelId == reel.Id && r.ReadyMBillDetailedId != null).OrderByDescending(r => r.CreationTime).FirstOrDefaultAsync(); if (sendLog != null) { var readyBillDreturn = await _repositoryReadyMBilld.FirstOrDefaultAsync(sendLog.ReadyMBillDetailedId); if (sendLog != null) { readyBillDreturn.ReturnQty += inputDto.ReturnReelQty; sendLog.IsActive = false; } } break; case AllocationType.Received: // 收料 #region 收料 var receiveId = await _repositoryrrb.FirstOrDefaultAsync(r => r.PartNoId == reel.PartNoId && r.Qty > r.ReceivedQty && r.IQCCheckId == inputDto.IQCCheckId); if (receiveId == null) { resDto.Msg = "当前ERP没有足够的IQC检验单,请确认"; throw new LYException(resDto.Msg); } receiveId.ReceivedQty += reel.Qty; if (receiveId.ReceivedQty == receiveId.Qty) { receiveId.IsActive = true; } reel.ReceivedReelBillId = receiveId.Id; reelMoveLog.ReceivedReelBillId = receiveId.Id; #endregion break; case AllocationType.Register: // 注册 break; case AllocationType.SendFirstReel: // 发首料 break; case AllocationType.SupplyReel: // 补料 #region 补料 // 检测补料料临时表里面有没有该数据 var supplytemp = await _repositoryReelSupplyTemp.FirstOrDefaultAsync(reel.Id); if (supplytemp == null) { resDto.Msg = "料卷未被挑料"; throw new LYException(resDto.Msg); } if (supplytemp.IsSend) { resDto.Msg = @"料卷已经发料 " + supplytemp.FisrtStorageLocationId; throw new LYException(resDto.Msg); } // 查询挑料明细行数据 var readyBillDSupply = await _repositoryReadyMBilld.FirstOrDefaultAsync(supplytemp.ReadyMBillDetailedId); // 改变发料状态 supplytemp.IsSend = true; // 添加发料数量 readyBillDSupply.SendQty += reel.Qty; // 查询挑料料站表行数据 var readySlotSupply = await _repositorySlot.FirstOrDefaultAsync(readyBillDSupply.SlotId); // 改变料盘备料关联 reel.ReadyMBillDetailedId = readyBillDSupply.Id; reel.ReadyMBillId = readyBillDSupply.ReadyMBillId; // 改变物料料站表绑定 reel.SlotId = supplytemp.SlotId; // 改变日志备料关联 reelMoveLog.ReadyMBillDetailedId = readyBillDSupply.Id; reelMoveLog.ReadyMBillId = readyBillDSupply.ReadyMBillId; reelMoveLog.SlotId = supplytemp.SlotId; await GetShelfUp(); // 灭灯 shelfUp.LightState = LightState.Off; if (readySlotSupply != null) { resDto.Msg = "站位信息: \r\n" + "面别: [" + (readySlotSupply.BoardSide == SideType.B ? "S" : "C") + "]\r\n机器: [" + readySlotSupply.Machine + "]\r\nTable: [" + readySlotSupply.Table + "]\r\n站位: [" + readySlotSupply.SlotName + "]\r\n边别: [" + (readySlotSupply.Side == SideType.L ? "L" : "R") + "]"; } else { resDto.Msg = "发料成功"; } // 灭小灯和塔灯 LightService.LightOrder(new List <StorageLight>() { new StorageLight() { ContinuedTime = 10, LightColor = shelfUp.LightColor, LightOrder = 0, MainBoardId = shelfUp.MainBoardId, RackPositionId = shelfUp.PositionId } }); CurrentUnitOfWork.SaveChanges(); // 大灯 可能需要修改 var lightssupply = _repositorysl.GetAll().Where(s => s.MainBoardId == shelfUp.MainBoardId && s.LightState != LightState.Off && s.LightColor == shelfUp.LightColor); if (lightssupply.Count() == 0) { LightService.HouseOrder(new List <HouseLight>() { new HouseLight() { HouseLightSide = 1, LightOrder = 0, MainBoardId = shelfUp.MainBoardId, LightColor = shelfUp.LightColor } }); } #endregion break; case AllocationType.UpByShelf: // 按库位下架 break; default: break; } break; case AllocationType.UpByShelf: #region 库位下架 if (inputDto.ShlefLab == null || inputDto.ShlefLab.Length == 0) { inputDto.ShlefLab = inputDto.BarCode; } // 找到库位物料 var shelfL = _repositorysl.FirstOrDefault(inputDto.ShlefLab); if (shelfL == null) { throw new LYException(1, "库位[" + inputDto.ShlefLab + "]不存在"); } if (shelfL.ReelId == null) { throw new LYException(1, "库位[" + inputDto.ShlefLab + "]上无料"); } // 查询库位上 reel reel = _repository.FirstOrDefault(shelfL.ReelId); shelfL.ReelId = null; reel.StorageLocationId = null; reelMoveLog.ReelId = reel.Id; reelMoveLog.PartNoId = reel.PartNoId; reelMoveLog.Qty = reel.Qty; LightService.LightOrder(new List <StorageLight>() { new StorageLight() { ContinuedTime = 10, LightOrder = 0, MainBoardId = shelfL.MainBoardId, LightColor = shelfL.LightColor, RackPositionId = shelfL.PositionId } }); #endregion break; case AllocationType.Register: #region 料卷注册 // 查询料号是否已经维护 await BarCodeAnalysis(); reel = _repository.FirstOrDefault(reelDto.Id); if (reel == null) { await CheckMPN(); // 刚注册物料不能被禁用 reelDto.IsActive = true; reel = ObjectMapper.Map <Reel>(reelDto); // 直接进入注册仓库 reel.StorageId = reelMpn.RegisterStorageId; reel = await _repository.InsertAsync(reel); // 进行注册,注册后立马保存料盘信息 await CurrentUnitOfWork.SaveChangesAsync(); } reelMoveLog.ReelId = reel.Id; reelMoveLog.PartNoId = reel.PartNoId; reelMoveLog.Qty = reel.Qty; #endregion break; case AllocationType.Out: #region 出库 if (reel == null) // 进行料卷检查 { await CheckReel(); } if (reel.StorageLocationId != null) { await GetShelfUp(); shelfUp.ReelId = null; } await _repository.DeleteAsync(reel); #endregion break; default: break; } } reelMoveLog.ReelInfo = Newtonsoft.Json.JsonConvert.SerializeObject(reel); // 最后插入调拨日志 await _repositoryReelMoveLog.InsertAsync(reelMoveLog); resDto.Reel = ObjectMapper.Map <ReelDto>(reel); if (inputDto.ReturnReelQty > 0) { reel.Qty = inputDto.ReturnReelQty; resDto.Reel.Qty = inputDto.ReturnReelQty; } return(resDto); }