public async override Task <StorageAreaDto> Create(StorageAreaDto input) { var StorageArea = await base.Create(input); CurrentUnitOfWork.SaveChanges(); // 更新库位区域 var StorageLocations = _repositorySL.GetAll().Where(r => input.ShelfNames.Contains(r.Name)).ToArray(); foreach (var StorageLocation in StorageLocations) { StorageLocation.StorageAreaId = StorageArea.Id; } // 更新料号区域 var MPNS = _repositoryMPN.GetAll().Where(r => input.MPNIds.Contains(r.Id)).ToArray(); foreach (var mpn in MPNS) { _repositoryMPNSM.Insert(new MPNStorageAreaMap() { MPNId = mpn.Id, StorageAreaId = StorageArea.Id }); } return(StorageArea); }
public async Task AllBright() { var lightType = SettingManager.GetSettingValueForTenant <int>("lightIsRGB", AbpSession.TenantId.Value); var lightColor = LightColor.Default; if (lightType == 1) { lightColor = LightColor.Green; } var lights = await _repository.GetAll().GroupBy(r => r.MainBoardId).Select(r => new AllLight { LightOrder = 1, LightColor = lightColor, MainBoardId = r.Key }).Distinct().ToListAsync(); // 小灯,灯塔 LightService.AllLightOrder(lights); LightService.HouseOrder(lights.Select(r => new HouseLight() { LightOrder = 1, MainBoardId = r.MainBoardId, LightColor = lightColor, HouseLightSide = 0 }).ToList()); LightService.HouseOrder(lights.Select(r => new HouseLight() { LightOrder = 1, LightColor = lightColor, MainBoardId = r.MainBoardId, HouseLightSide = 1 }).ToList()); }
public async Task BrightByPartNoIds(LightOrderDto[] input) { var settinglightType = await _repositoryT.FirstOrDefaultAsync(c => c.TenantId == AbpSession.TenantId && c.Name == "lightIsRGB"); var lightType = settinglightType == null ? 0 : int.Parse(settinglightType.Value); var lightColor = LightColor.Default; if (lightType == 1) { lightColor = LightColor.Green; } // 查询料号库存 List <string> reelIds = new List <string>(); foreach (var item in input) { var reelsOne = _repository.GetAll().Where(r => r.PartNoId == item.ReelOrPns && r.StorageId == item.StorageId).Select(r => r.Id).ToList(); reelIds.AddRange(reelsOne); } var lights = await _repositorysl.GetAll().Where(r => reelIds.Contains(r.ReelId)).GroupBy(r => new StorageLight { RackPositionId = r.PositionId, ContinuedTime = 10, LightColor = lightColor, LightOrder = 1, MainBoardId = r.MainBoardId }).Select(r => r.Key).ToListAsync(); // 小灯 LightService.LightOrder(lights); // 灯塔 var mains = lights.GroupBy(r => new AllLight { LightOrder = 0, LightColor = lightColor, MainBoardId = r.MainBoardId }).Select(r => r.Key).ToList(); LightService.HouseOrder(lights.Select(r => new HouseLight() { LightOrder = 1, LightColor = lightColor, MainBoardId = r.MainBoardId, HouseLightSide = 0 }).ToList()); LightService.HouseOrder(lights.Select(r => new HouseLight() { LightOrder = 1, LightColor = lightColor, MainBoardId = r.MainBoardId, HouseLightSide = 1 }).ToList()); }
public async Task <ICollection <StorageDto> > GetStorageByKeyName(string keyName) { if (keyName == null) { keyName = ""; } var res = await _repository.GetAll().Where(c => c.Id.Contains(keyName)).Take(10).ToListAsync(); return(ObjectMapper.Map <List <StorageDto> >(res)); }
public async Task <ICollection <CustomerDto> > GetCustomerById(string Id) { if (Id == null) { Id = ""; } var res = await _repository.GetAll().Where(c => c.Id.Contains(Id)).Take(10).ToListAsync(); return(ObjectMapper.Map <List <CustomerDto> >(res)); }
public async Task <ICollection <I18NDto> > GetByDtoName(string dtoName) { var thisAssembly = typeof(WMSCloudApplicationModule).GetAssembly().ExportedTypes.Where(t => t.Name.ToLower() == dtoName.ToLower()).FirstOrDefault(); var lang = await SettingManager.GetSettingValueForUserAsync(LocalizationSettingNames.DefaultLanguage, AbpSession.ToUserIdentifier()); var dbI18N = await _repository.GetAll().Where(i => i.Key.StartsWith(dtoName) && i.LanguageName == lang).ToListAsync(); var p = thisAssembly.GetProperties(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <System.Reflection.PropertyInfo, ApplicationLanguageText>() .ForMember(m => m.Key, opt => opt.MapFrom(s => dtoName + s.Name)) .ForMember(m => m.Value, opt => opt.MapFrom(s => dbI18N.FirstOrDefault(i => i.Key == dtoName + s.Name) == null ? s.Name : dbI18N.FirstOrDefault(i => i.Key == dtoName + s.Name).Value)) .ForMember(m => m.LanguageName, opt => opt.MapFrom(s => lang)); } ); var languageText = config.CreateMapper().Map <List <System.Reflection.PropertyInfo>, List <ApplicationLanguageText> >(p.ToList()); var nDtos = ObjectMapper.Map <List <I18NDto> >(languageText); var more = dbI18N.Where(r => !(nDtos.Select(o => o.Key).Contains(r.Key))); languageText.AddRange(more); return(ObjectMapper.Map <List <I18NDto> >(languageText)); }
public async Task <PrintReelDto> GetNewPrintReel(PrintReelDto printReelDto) { var printStartStr = SettingManager.GetSettingValueForTenant("printStartStr", AbpSession.TenantId.Value); // await _repositoryT.FirstOrDefaultAsync(r => r.TenantId == AbpSession.TenantId && r.Name == "printStartStr"); var partStr = DateTime.Now.ToString("yyyyMMdd"); if (printStartStr != null) { partStr = printStartStr + partStr; } printReelDto.PrintStr = partStr; var printReelOld = _repository.GetAll().Where(r => r.PrintStr == partStr).OrderByDescending(r => r.PrintIndex).FirstOrDefault(); if (printReelOld == null) { printReelDto.PrintIndex = 1; } else { printReelDto.PrintIndex = printReelOld.PrintIndex + 1; } printReelDto.Id = partStr + printReelDto.PrintIndex.ToString().PadLeft(5, '0'); var res = await this.Create(printReelDto); return(res); }
public async Task <GetReceivedsResult> GetReceiveds(ReelMoveDto inputDto) { var res = new GetReceivedsResult() { Msg = "OK", ReceivedReelBills = null }; // 条码解析 var reelDtoObj = await _barCodeAnalysisAppService.Analysis(new BaseData.BarCodeAnalysiss.Dto.AnalysisDto() { BarCode = inputDto.BarCode, DtoName = "ReelDto" }); if (!reelDtoObj.Success) { res.Msg = reelDtoObj.Msg; throw new LYException(res.Msg); } ReelDto reel = reelDtoObj.Result as ReelDto; //所有当前料号未收完成的单据号 var receiveIdNow = await _repositoryrrb.GetAll().Where(r => r.PartNoId == reel.PartNoId && r.Qty > r.ReceivedQty).ToListAsync(); if (receiveIdNow == null || receiveIdNow.Count == 0) { res.Msg = "当前没有足够的收料单,请确认"; throw new LYException(res.Msg); } res.ReceivedReelBills = ObjectMapper.Map <List <ReceivedReelBillDto> >(receiveIdNow); return(res); }
public async override Task <StorageAreaDto> Update(StorageAreaDto input) { // 删除区域现有货架 var OldStorageLocations = _repositorySL.GetAll().Where(r => r.StorageAreaId == input.Id).ToArray(); foreach (var StorageLocation in OldStorageLocations) { StorageLocation.StorageAreaId = null; } // 清空区域现有物料 var MPNStorageAreaMaps = _repositoryMPNSM.GetAll().Where(r => r.StorageAreaId == input.Id).ToArray(); foreach (var MPNStorageAreaMap in MPNStorageAreaMaps) { _repositoryMPNSM.Delete(MPNStorageAreaMap); } CurrentUnitOfWork.SaveChanges(); var StorageArea = await base.Update(input); CurrentUnitOfWork.SaveChanges(); // 更新库位区域 var StorageLocations = _repositorySL.GetAll().Where(r => input.ShelfNames.Contains(r.Name)).ToArray(); foreach (var StorageLocation in StorageLocations) { StorageLocation.StorageAreaId = StorageArea.Id; } // 更新料号区域 var MPNS = _repositoryMPN.GetAll().Where(r => input.MPNIds.Contains(r.Name)).ToArray(); foreach (var mpn in MPNS) { _repositoryMPNSM.Insert(new MPNStorageAreaMap() { MPNId = mpn.Id, StorageAreaId = StorageArea.Id }); } return(StorageArea); }
public override Task <ReelMoveMethodDto> Update(ReelMoveMethodDto input) { foreach (var item in _repositoryRMMStorageMap.GetAll().Where(r => r.ReelMoveMethodId == input.Id).ToList()) { _repositoryRMMStorageMap.Delete(item.Id); } CurrentUnitOfWork.SaveChanges(); return(base.Update(input)); }
public async Task <ICollection <ReelMoveMethodDto> > GetReelMoveMethodByKeyName(string keyName) { if (keyName == null) { keyName = ""; } var res = await _repository.GetAll().Where(c => c.Id.Contains(keyName) && c.AllocationTypesStr.ToLower().Contains("send")).Take(10).ToListAsync(); // && c.AllocationType.ToString().ToLower().Contains("send") return(ObjectMapper.Map <List <ReelMoveMethodDto> >(res)); }
public async Task <ICollection <WorkBillDto> > GetWorkBillByKeyName(string keyName) { if (keyName == null) { keyName = ""; } var res = await _repository.GetAll().Where(w => w.Id.Contains(keyName) && w.IsActive && w.Qty > w.ReadyMQty).Take(10).ToListAsync(); return(ObjectMapper.Map <List <WorkBillDto> >(res)); }
public PagedResultDto <BOMDto> GetItemsById(string Id, PagedResultRequestInput input) { // 查询 // var query = _repository.GetAll().Where(m => m.ProductId == Id); var query = config.CreateMapper().Map <List <BOM>, List <BOMDto> >( _repository.GetAll().Where(m => m.ProductId == Id).ToList()); var res = query.AsQueryable().DynamicQuery(input); var tasksCount = res.Count(); //默认的分页方式 //var taskList = query.Skip(input.SkipCount).Take(input.MaxResultCount).ToList(); //ABP提供了扩展方法PageBy分页方式 var taskList = res.PageBy(input).ToList(); return(new PagedResultDto <BOMDto>(tasksCount, taskList)); }
public async Task AllBright() { var settinglightType = await _repositoryST.FirstOrDefaultAsync(c => c.TenantId == AbpSession.TenantId && c.Name == "lightIsRGB"); var lightType = settinglightType == null ? 0 : int.Parse(settinglightType.Value); var lightColor = LightColor.Default; if (lightType == 1) { lightColor = LightColor.Green; } var lights = await _repository.GetAll().GroupBy(r => r.MainBoardId).Select(r => new AllLight { LightOrder = 1, LightColor = lightColor, MainBoardId = r.Key }).Distinct().ToListAsync(); // 小灯,灯塔 LightService.AllLightOrder(lights); LightService.HouseOrder(lights.Select(r => new HouseLight() { LightOrder = 1, MainBoardId = r.MainBoardId, LightColor = lightColor, HouseLightSide = 0 }).ToList()); LightService.HouseOrder(lights.Select(r => new HouseLight() { LightOrder = 1, LightColor = lightColor, MainBoardId = r.MainBoardId, HouseLightSide = 1 }).ToList()); }
public async Task <ICollection <MenuCDto> > GetMenu() { // 查询角色拥有菜单,及其公共菜单,菜单最多三级 var menus = await _repository.GetAll() .Include(m => m.Children) .ThenInclude(m => m.Children) .ThenInclude(m => m.Children) .OrderBy(m => m.Index) .Where(m => m.Group) .ToListAsync(); menus = OrderByIndex(menus); return(ObjectMapper.Map <List <MenuCDto> >(menus)); }
public Task <AnalysisResDto> Analysis(AnalysisDto analysisDto) { return(Task.Factory.StartNew(() => { AnalysisResDto res = new AnalysisResDto() { Success = true, Msg = "条码解析成功" }; var thisAssembly = typeof(WMSCloudApplicationModule).GetAssembly().ExportedTypes.Where(t => t.Name.ToLower() == analysisDto.DtoName.ToLower()).FirstOrDefault(); if (thisAssembly == null) { throw new LYException("未找到要解析的数据传输对象"); } // 查询该对象的解析规则 var analysiss = _repository.GetAll().Where(a => a.ClassName == analysisDto.DtoName).ToList(); if (analysiss == null || analysiss.Count < 1) { throw new LYException("未设置条码解析规则"); } // 条码解析 try { //获取指定名称的类型 object resObj = Activator.CreateInstance(thisAssembly, null); //创建指定类型实例 PropertyInfo[] fields = resObj.GetType().GetProperties(); //获取指定对象的所有公共属性 foreach (var pInfo in fields) { // 判断是否存在解析规则 var analysis = analysiss.Where(a => a.PropertyName.ToLower() == pInfo.Name.ToLower()).FirstOrDefault(); if (analysis == null) { continue; } var oneStr = ""; // 进行正则解析 if (analysis.IsReplace) { oneStr = Regex.Replace(analysisDto.BarCode, analysis.RegEX, ""); } else { oneStr = Regex.Match(analysisDto.BarCode, analysis.RegEX).Value; } if (pInfo.PropertyType.BaseType.Name == "Enum") { pInfo.SetValue(resObj, System.Enum.Parse(pInfo.PropertyType, oneStr, true), null); } else { if (pInfo.PropertyType == typeof(DateTime)) { oneStr = GetDateCode(oneStr); } pInfo.SetValue(resObj, Convert.ChangeType(oneStr, pInfo.PropertyType), null); } } res.Result = resObj; } catch (Exception ex) { throw new LYException("条码解析失败" + ex.Message); } return res; })); }
public async Task <ICollection <LineDto> > GetLineByKeyName(string keyName) { var res = await _repository.GetAll().Where(l => l.Id.Contains(keyName)).Take(10).ToListAsync(); return(ObjectMapper.Map <List <LineDto> >(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 = 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 <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 <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); }