public async Task <List <EquipmentShiftDto> > GetShiftByEquipmentID(int Id) { var query = EsRepository.GetAll().Where(p => p.FEqiupmentID == Id).Include(p => p.Employee) .Include(p => p.Equipment); var list = await query.ToListAsync(); return(list.MapTo <List <EquipmentShiftDto> >()); }
public async Task <int> Create(ICMODailyCreatDto input) { var icmo = MRepository.GetAll().SingleOrDefault(p => p.任务单号 == input.FMOBillNo); if (icmo == null) { this.EX(-1, $"{input.FMOBillNo} 任务单不存在,请检查"); } var oplist = await SUbRepository.GetAll().ToListAsync(); var equipmentList = await ERepository.GetAll().Where(p => p.FType == PublicEnum.EquipmentType.设备).ToListAsync(); var orgs = await ORepository.GetAll().Where(p => p.FWorkshopType).ToListAsync(); var eqShifts = await EsRepository.GetAll().ToListAsync(); if (icmo != null) { var schedule = GetOrCreateSchedule(icmo); var org = orgs.SingleOrDefault(o => o.DisplayName == icmo.车间); if (org == null) { this.EX(-1, $"找不到此车间:{icmo.车间},请检查组织架构信息"); } foreach (var dailyItem in input.Dailies) { var equipments = equipmentList.Where(e => e.FName == dailyItem.FMachineName && e.FWorkCenterID == org.Id); if (equipments.Count() > 1) { this.EX(-1, $"【{org.DisplayName}】车间存在多个【{dailyItem.FMachineName}】设备"); } var equipment = equipments.SingleOrDefault(); if (equipment == null) { this.EX(-1, $"在【{icmo.车间}】车间找不到设备:{dailyItem.FMachineName} ,请检查设备档案"); } var shift = eqShifts.SingleOrDefault(p => p.FEqiupmentID == equipment.FInterID && p.FShift == dailyItem.FShift); if (shift == null) { this.EX(-1, $"设备:{dailyItem.FMachineName} 的班次信息中不存在 【{dailyItem.FShift}】,请检查设备的班次信息"); } var entity = schedule.Dailies.SingleOrDefault(p => p.FDate == dailyItem.FDate && p.FMachineID == equipment.FInterID && p.FShift == shift.Id); var op = oplist.SingleOrDefault(p => p.FName == dailyItem.FOperID); var index = (schedule.Dailies.Count + 1).ToString("000"); if (entity == null && dailyItem.FPlanAuxQty > 0) { entity = new Entities.ICMODaily { FMachineID = equipment.FInterID, FWorkCenterID = org.Id, FShift = shift.Id, FID = Guid.NewGuid().ToString(), FBillNo = "DA" + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + index, //任务计划单号 FMOInterID = icmo.FMOInterID, //任务单ID FMOBillNo = icmo.任务单号, //任务单号 FBiller = AbpSession.UserId.ToString(), //当前登录用户 FSrcID = schedule.FID, FPlanAuxQty = dailyItem.FPlanAuxQty, FBillTime = DateTime.Now, FDate = dailyItem.FDate.Date, FOperID = op != null?op.FInterID:0, FWorkCenterName = icmo.车间, FWorker = shift.FEmployeeID, FPackQty = dailyItem.PackQty }; //插入新的日计划单 schedule.Dailies.Add(entity); } else if (dailyItem.FPlanAuxQty > 0) { schedule.FPlanAuxQty -= entity.FPlanAuxQty; entity.FPlanAuxQty = dailyItem.FPlanAuxQty; schedule.FPlanAuxQty += entity.FPlanAuxQty; } } //更新计划单 SRepository.Update(schedule); return(schedule.Dailies.Count); } else { throw new UserFriendlyException(string.Format("任务单:{0}不存在", input.FMOBillNo)); } }