public ICMODailyDto Create(ICMODailyCreatDto input) { var tran = context.Database.BeginTransaction(); try { // 检查是否已存在任务计划单 var schedule = context.ICMOSchedule.SingleOrDefault(p => p.FMOBillNo == input.FMOBillNo && p.FMOInterID == input.FMOInterID); //不存在则新建 if (schedule == null) { schedule = new ICMOSchedule() { FID = Guid.NewGuid().ToString(), FBillNo = "SC" + DateTime.Now.ToString("yyyyMMddHHmmss"), //计划单号 FMOInterID = input.FMOInterID, //任务单ID FMOBillNo = input.FMOBillNo }; //任务单号 context.ICMOSchedule.Add(schedule); //插入任务计划单 } else { context.ICMOSchedule.Attach(schedule); context.Entry(schedule).State = EntityState.Modified; } //已存在的排程日计划单 var dailyEntityList = context.ICMODaily.Where(p => p.FSrcID == schedule.FID).ToList(); foreach (var daily in input.Dailies) { //比较传入数据是否已存在,如果存在则更新数据,否则插入新记录 var dailyEntity = dailyEntityList.SingleOrDefault(p => p.FMachineID == daily.FMachineID && p.FWorkCenterID == daily.FWorkCenterID && p.FShift == daily.FShift); JITEF.DIME2Barcode.ICMODaily item = null; if (dailyEntity != null) { item = dailyEntity; context.ICMODaily.Attach(item); context.Entry(item).State = EntityState.Modified; } else { var index = (Array.IndexOf(input.Dailies, daily) + dailyEntityList.Count + 1).ToString("000"); item = new JITEF.DIME2Barcode.ICMODaily(); item.FMachineID = daily.FMachineID; item.FWorkCenterID = daily.FWorkCenterID; item.FShift = daily.FShift; item.FID = Guid.NewGuid().ToString(); item.FBillNo = "DA" + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + index; //任务计划单号 item.FMOInterID = input.FMOInterID; //任务单号 item.FMOBillNo = input.FMOBillNo; //任务单号 item.FBiller = this.AbpSession.UserId.ToString(); //当前登录用户 item.FSrcID = schedule.FID; context.ICMODaily.Attach(item); context.Entry(item).State = EntityState.Added; } item.FPlanAuxQty = daily.FPlanAuxQty; item.FDate = daily.FDate; } //更新任务计划单派工数 //schedule.FPlanAuxQty = planTotalQty; context.SaveChanges(); tran.Commit(); } catch (Exception e) { Console.WriteLine(e); tran.Rollback(); throw; } return(new ICMODailyDto()); }
/// <summary> /// 生成日计划单接口 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <VW_ICMODailyDto> Create(ICMODailyCreatDto input) { var dailyList = await Repository.GetAll().Where(p => p.FMOBillNo == input.FMOBillNo && p.FMOInterID == input.FMOInterID).ToListAsync(); var fsrcId = ""; //任务计划单FID decimal?totoalPlan = 0; //计划单排产数 if (dailyList == null || dailyList.Count == 0) { fsrcId = Guid.NewGuid().ToString(); } else { fsrcId = dailyList.First().FSrcID; totoalPlan += dailyList.Sum(p => p.FPlanAuxQty); } //插入日计划单 foreach (var item in input.Dailies) { var daily = dailyList.SingleOrDefault(p => p.FShift == item.FShift && p.FMachineID == item.FMachineID && item.FWorkCenterID == p.FWorkCenterID && item.FDate == p.FDate); Entities.ICMODaily insertUpdateObj = null; if (daily != null) { totoalPlan -= daily.FPlanAuxQty; totoalPlan += item.FPlanAuxQty; insertUpdateObj = daily; insertUpdateObj.FPlanAuxQty = item.FPlanAuxQty; Repository.Update(insertUpdateObj); } else { totoalPlan += item.FPlanAuxQty; var index = (input.Dailies.IndexOf(item) + dailyList.Count + 1).ToString("000"); insertUpdateObj = new Entities.ICMODaily() { FMachineID = item.FMachineID, FWorkCenterID = item.FWorkCenterID, FShift = item.FShift, FID = Guid.NewGuid().ToString(), FBillNo = "DA" + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + index, //任务计划单号 FMOInterID = input.FMOInterID, //任务单号 FMOBillNo = input.FMOBillNo, //任务单号 FBiller = this.AbpSession.UserId.ToString(), //当前登录用户 FSrcID = fsrcId, FPlanAuxQty = item.FPlanAuxQty, FBillTime = DateTime.Parse(DateTime.Now.ToString("yyyy-M-d HH:mm:ss")), FDate = item.FDate.Date }; var entity = Repository.Insert(insertUpdateObj); } } //更新任务计划单的总排产数 await InsertOrUpdateICMOSchedul(new ICMODailyCreatedtEventData { FSrcID = fsrcId, FMOBillNo = input.FMOBillNo, FMOInterID = input.FMOInterID, FBiller = AbpSession.UserId.ToString(), FPlanAuxQty = totoalPlan }); return(null); }
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)); } }