public async Task <bool> BatchInsOrUpdate(ICollection <MPNDto> input) { // 查询备损数量 string registerStorageId = null; // 此处后面可能会进行改动 var readyLossQty = _repositoryT.FirstOrDefault(c => c.TenantId == AbpSession.TenantId && c.Name == "registerStorageId"); if (readyLossQty != null) { registerStorageId = readyLossQty.Value; } try { foreach (var item in input) { try { var nowMPN = _repository.FirstOrDefault(item.Id); if (nowMPN != null && (( nowMPN.Name != item.Name) || (nowMPN.Info != item.Info) || (nowMPN.MPNHierarchy != item.MPNHierarchy) || (nowMPN.MPNLevel != item.MPNLevel) || (nowMPN.MPQs != item.MPQs) || (nowMPN.MPNType != item.MPNType) )) { nowMPN.Name = item.Name; nowMPN.Info = item.Info; nowMPN.MPNHierarchy = item.MPNHierarchy; nowMPN.MPNLevel = item.MPNLevel; nowMPN.MPQs = item.MPQs; nowMPN.MPNType = item.MPNType; // await _repository.UpdateAsync(nowMPN); } else if (nowMPN == null) { nowMPN = ObjectMapper.Map <MPN>(item); nowMPN.RegisterStorageId = registerStorageId; await _repository.InsertAsync(nowMPN); } } catch (Exception ex) { item.Remark += ex.Message; } CurrentUnitOfWork.SaveChanges(); } return(true); } catch (Exception ex) { throw new LYException(ex.Message); } }
public async Task AddByLY(LYDto lYDto) { List <StorageLocationDto> list = new List <StorageLocationDto>(); for (int i = 0; i < lYDto.ShelfCode.Length; i++) { for (int j = 1; j <= lYDto.Count; j++) { list.Add(new StorageLocationDto() { Code = lYDto.ShelfCode[i], Name = lYDto.ShelfCode[i], Id = lYDto.ShelfId[i] + j.ToString().PadLeft(4, '0'), MainBoardId = j > 700 ? lYDto.mainId[i][1] : lYDto.mainId[i][0], PositionId = j, IsActive = true, StorageId = lYDto.StorageId, StorageLocationTypeId = lYDto.StorageLocationTypeId }); } } foreach (var item in list) { if (_repository.FirstOrDefault(s => s.Id == item.Id) == null) { await Create(item); } else { await Update(item); } } }
public async Task ReturnReel(ReturnReelDto returnReel) { // 查询备料单是否存在 var readyMBill = _repositoryReadyMBill.FirstOrDefault(returnReel.ReadyMBillId); if (readyMBill == null) { throw new LYException(string.Format("备料单{0}不存在", returnReel.ReadyMBillId)); } if (readyMBill.ReReadyMBillId == null) { throw new LYException(string.Format("备料单{0}未进行备料", returnReel.ReadyMBillId)); } // 查询记账备料单下面是否有该料号 var readyMBillDetaileds = await _repositoryReadyMBilld.GetAll().Where(r => _repositoryReadyMBill.GetAll() .Where(r1 => r1.ReReadyMBillId == readyMBill.ReReadyMBillId) .Select(r1 => r1.Id).Contains(r.ReadyMBillId) && r.PartNoId == returnReel.PartNoId).ToListAsync(); if (readyMBillDetaileds == null || readyMBillDetaileds.Count == 0) { throw new LYException(string.Format("备料单{0}及其合并的备料单不需要物料{1}", returnReel.ReadyMBillId, returnReel.PartNoId)); } // 查询是否发料 if (readyMBillDetaileds.Sum(r => r.SendQty) == 0) { throw new LYException(string.Format("备料单{0}及其合并的备料单物料{1}还未发料", returnReel.ReadyMBillId, returnReel.PartNoId)); } // 进行退料 var readyMBillDetailed = readyMBillDetaileds.FirstOrDefault(); readyMBillDetailed.ReturnQty += returnReel.Qty; }
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); }
public async Task <PagedResultDto <ReadyMBillDetailedReportDto> > GetAllAsync(string readyBillId, PagedResultRequestInput input) { var resS = await Task.Factory.StartNew(() => { // 获取输入备料单的记账备料单 var readyBill = _repositoryReadyMBill.FirstOrDefault(readyBillId); if (readyBill == null) { return(new PagedResultDto <ReadyMBillDetailedReportDto>(0, new List <ReadyMBillDetailedReportDto>())); } // 获取筛选条件中的 备料单 合集 var readyBills = _repositoryReadyMBill.GetAll().Where(s => s.ReReadyMBillId == readyBill.ReReadyMBillId).Include(r => r.WorkBills).ThenInclude(s => s.WorkBill).ToList(); // 查询记账备料单的相信信息 var ReadyMBillds = _repositoryReadyMBilld.GetAll().Where(s => readyBills.Select(r => r.Id).Contains(s.ReadyMBillId)).ToList(); var toList = new Func <IEnumerable <IEnumerable <string> >, string>(i => { var list = new List <string>(); foreach (var item in i) { foreach (var str in item) { list.Add(str); } } return(string.Join('|', list.Distinct())); }); // 分组 var res = ReadyMBillds.GroupBy(r => r.PartNoId).Select(s => new ReadyMBillDetailedReportDto() { ReReadyMBillId = readyBill.ReReadyMBillId, WorkBillIds = toList(readyBills.Select(r => r.WorkBills).Select(w => w.Select(wo => wo.WorkBillId + ":" + wo.Qty)).Distinct()), Products = toList(readyBills.Select(r => r.WorkBills).Select(w => w.Select(wo => wo.WorkBill.ProductId)).Distinct()), Lines = toList(readyBills.Select(r => r.WorkBills).Select(w => w.Select(wo => wo.WorkBill.LineId)).Distinct()), DemandQty = s.Sum(r => r.Qty), SendQty = s.Sum(r => r.SendQty), PartNoId = s.Key, FollowQty = s.Sum(r => r.FollowQty), ReadyMBillIds = string.Join('|', readyBills.Select(r => r.Id)), ReelMoveMethodId = s.FirstOrDefault().ReelMoveMethodId, ReturnQty = s.Sum(r => r.ReturnQty), MoreSendQty = s.Sum(r => r.SendQty) - s.Sum(r => r.Qty) - s.Sum(r => r.ReturnQty), NoFollowQty = s.Sum(r => r.SendQty) - s.Sum(r => r.FollowQty), RealSendQty = s.Sum(r => r.SendQty) - s.Sum(r => r.ReturnQty) }); var query = res.AsQueryable().DynamicQuery(input); var tasksCount = query.Count(); //默认的分页方式 //var taskList = query.Skip(input.SkipCount).Take(input.MaxResultCount).ToList(); //ABP提供了扩展方法PageBy分页方式 var taskList = query.PageBy(input).ToList(); return(new PagedResultDto <ReadyMBillDetailedReportDto>(tasksCount, taskList)); }); return(resS); }
public async Task <ICollection <BatchSlotListDto> > BatchEdit(BatchSlotDto batchSlot) { var res = new List <BatchSlotListDto>(); // 查询机种 var product = _repositoryMPN.FirstOrDefault(batchSlot.ProductId); if (product == null) { throw new LYException(1, "半成品料号" + batchSlot.ProductId + "不存在"); } // 查询所有 线别 var lines = _repositoryLine.GetAll().Where(l => l.Id.StartsWith(batchSlot.LineId)); if (lines == null || lines.Count() < 1) { throw new LYException(2, "线别" + batchSlot.LineId + "不存在"); } try { List <Slot> listSlot = new List <Slot>(); // 将所有线别插入料表和Pin信息 foreach (var line in lines) { // 检查是否有Pin信息 var uph = _repositoryUPH.FirstOrDefault(u => u.ProductId == batchSlot.ProductId && u.LineId == line.Id); if (uph == null) { _repositoryUPH.Insert(new UPH() { ProductId = batchSlot.ProductId, LineId = line.Id, IsActive = true, Pin = batchSlot.Pin, Remark = "料站表导入自动添加的UPH信息", Meter = 1, Qty = 999999 }); } else { uph.Pin = batchSlot.Pin; } foreach (var slot in batchSlot.Slots) { // 判断物料是否存在 var mpn = _repositoryMPN.FirstOrDefault(slot.PartNoId); if (mpn == null) { if (res.FirstOrDefault(s => s.Index == slot.Index) == null) { res.Add(slot); } continue; } // 查询是否有料站表 var dtSlot = _repositorySlot.FirstOrDefault(s => s.BoardSide == batchSlot.BoardSide && s.Machine == slot.Machine && s.ProductId == batchSlot.ProductId && s.LineId == line.Id && s.Table == slot.Table && s.PartNoId == slot.PartNoId && s.SlotName == slot.SlotName); if (dtSlot == null) { // 没有 listSlot.Add(new Slot() { BoardSide = batchSlot.BoardSide, Feeder = slot.Feeder, IsActive = true, LineId = line.Id, Machine = slot.Machine, PartNoId = slot.PartNoId, Version = batchSlot.Version, Table = slot.Table, SlotName = slot.SlotName, Side = slot.Side, Qty = slot.Qty, ProductId = batchSlot.ProductId, MachineType = slot.MachineType, Location = string.Join(",", slot.Location.Trim().Replace("\"", "").Replace("-", "").Split(' ', StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Trim().Split(':', StringSplitOptions.RemoveEmptyEntries).Length > 1 ? s.Trim().Split(':', StringSplitOptions.RemoveEmptyEntries)[1] : s.Trim().Split(':', StringSplitOptions.RemoveEmptyEntries)[0]).OrderBy(s => s)), LineSide = slot.LineSide, Index = slot.Index }); } else { // 有 dtSlot.BoardSide = batchSlot.BoardSide; dtSlot.Feeder = slot.Feeder; dtSlot.IsActive = true; dtSlot.LineId = line.Id; dtSlot.Machine = slot.Machine; dtSlot.PartNoId = slot.PartNoId; dtSlot.Version = batchSlot.Version; dtSlot.Table = slot.Table; dtSlot.SlotName = slot.SlotName; dtSlot.Side = slot.Side; dtSlot.Qty = slot.Qty; dtSlot.ProductId = batchSlot.ProductId; dtSlot.MachineType = slot.MachineType; dtSlot.Location = string.Join(",", slot.Location.Trim().Replace("\"", "").Replace("-", "").Split(',', StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).OrderBy(s => s)); dtSlot.LineSide = slot.LineSide; dtSlot.Index = slot.Index; listSlot.Add(dtSlot); } } } foreach (var item in listSlot) { _repositorySlot.InsertOrUpdate(item); } await CurrentUnitOfWork.SaveChangesAsync(); // 将不在本次料表中的站位更新为无效 // 查询该机种该线别该版本 var NoActives = _repositorySlot.GetAll().Where(r => r.BoardSide == listSlot.FirstOrDefault().BoardSide&& r.ProductId == listSlot.FirstOrDefault().ProductId&& r.LineId == listSlot.FirstOrDefault().LineId&& !listSlot.Select(s => s.Id).Contains(r.Id)).ToArray(); foreach (var item in NoActives) { item.IsActive = false; _repositorySlot.Update(item); } } catch (Exception ex) { throw new LYException(ex.Message, ex); } return(res); }
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 = int.Parse(_repositoryT.FirstOrDefault(c => c.TenantId == AbpSession.TenantId && c.Name == "readyLossQty").Value); // 查询提前预警天数 var overdueDay = int.Parse(_repositoryT.FirstOrDefault(c => c.TenantId == AbpSession.TenantId && c.Name == "overdueDay").Value); // 查询强制先进先出天数 var mustFifoDay = int.Parse(_repositoryT.FirstOrDefault(c => c.TenantId == AbpSession.TenantId && c.Name == "mustFifoDay").Value); // 补料调拨策略 var reelSupplyMethodId = _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); }