/// <summary> /// 增加生产计划 /// </summary> /// <param name="inputDtos"></param> /// <returns></returns> public async Task <OperationResult> Add(params PlanProductionScheduleInfoInputDto[] inputDtos) { inputDtos.CheckNotNull("inputDtos"); foreach (var dtoData in inputDtos) { if (string.IsNullOrEmpty(dtoData.ScheduleCode)) { return(new OperationResult(OperationResultType.Error, "请正确填写生产计划编号!")); } if (string.IsNullOrEmpty(dtoData.ScheduleName)) { return(new OperationResult(OperationResultType.Error, "请正确填写生产计划名称!")); } if (PlanProductionScheduleInfoRepository.CheckExists(x => x.ScheduleCode == dtoData.ScheduleCode)) { return(new OperationResult(OperationResultType.Error, "该生产计划编号已存在,无法保存!")); } if (PlanProductionScheduleInfoRepository.CheckExists(x => x.ScheduleName == dtoData.ScheduleName)) { return(new OperationResult(OperationResultType.Error, "该生产计划名称已存在,无法保存!")); } dtoData.OrderItem = PlanOrderItemInfoRepository.TrackEntities.Where(m => m.Id == dtoData.OrderItem_Id).FirstOrDefault(); if (Equals(dtoData.OrderItem, null)) { return(new OperationResult(OperationResultType.Error, "对应的订单明细不存在,无法保存!")); } if (dtoData.OrderItem.RemainQuantity < dtoData.Quantity) { return(new OperationResult(OperationResultType.Error, $"剩余排产数量{dtoData.OrderItem.RemainQuantity}小于计划排产数量{dtoData.Quantity},无法保存!")); } dtoData.OrderItem.RemainQuantity -= dtoData.Quantity; dtoData.OrderItem.OrderState = 2; dtoData.OrderItem.Order.OrderState = 2; dtoData.ProductionRule = ProductionRuleInfoRepository.TrackEntities.Where(m => m.Id == dtoData.ProductionRule_Id).FirstOrDefault(); if (Equals(dtoData.ProductionRule, null)) { return(new OperationResult(OperationResultType.Error, "对应的配方不存在,无法保存!")); } if (Equals(dtoData.StartTime, null) || Equals(dtoData.EndTime)) { return(new OperationResult(OperationResultType.Error, "开始时间或结束时间为空,无法保存!")); } if (dtoData.StartTime < DateTime.Now) { return(new OperationResult(OperationResultType.Error, "开始时间应大于系统当前时间,无法保存!")); } if (dtoData.StartTime >= dtoData.EndTime) { return(new OperationResult(OperationResultType.Error, "开始时间应小于结束时间,无法保存!")); } } PlanProductionScheduleInfoRepository.UnitOfWork.BeginTransaction(); var result = await PlanProductionScheduleInfoRepository.InsertAsync(inputDtos); PlanProductionScheduleInfoRepository.UnitOfWork.Commit(); return(result); }
/// <summary> /// 检查实体是否存在 /// </summary> /// <param name="predicate"></param> /// <param name="id"></param> /// <returns></returns> public bool CheckExists(Expression <Func <PlanProductionScheduleInfo, bool> > predicate, Guid id) { return(PlanProductionScheduleInfoRepository.CheckExists(predicate, id)); }