| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean add(ProductionPlanDto productionPlanDto) { |
| | | if (StringUtils.isEmpty(productionPlanDto.getApplyNo())) { |
| | | throw new ServiceException("新增失败,申请单编号不能为空"); |
| | | } |
| | | Long count = productionPlanMapper.selectCount(Wrappers.<ProductionPlan>lambdaQuery() |
| | | .eq(ProductionPlan::getApplyNo, productionPlanDto.getApplyNo())); |
| | | if (count > 0) { |
| | | throw new ServiceException("新增失败,申请单编号 " + productionPlanDto.getApplyNo() + " 已存在"); |
| | | } |
| | | productionPlanDto.setDataSourceType(DataSourceTypeEnum.MANUAL.getCode()); |
| | | productionPlanDto.setStatus(0); |
| | | productionPlanMapper.insert(productionPlanDto); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean update(ProductionPlanDto productionPlanDto) { |
| | | if (productionPlanDto == null) { |
| | | if (productionPlanDto == null || productionPlanDto.getId() == null) { |
| | | throw new ServiceException("编辑失败,数据不能为空"); |
| | | } |
| | | ProductionPlan productionPlan = getById(productionPlanDto.getId()); |
| | |
| | | throw new ServiceException("编辑失败,主生产计划不存在"); |
| | | } |
| | | |
| | | if (StringUtils.isNotEmpty(productionPlanDto.getApplyNo()) |
| | | && !productionPlanDto.getApplyNo().equals(productionPlan.getApplyNo())) { |
| | | |
| | | Long count = productionPlanMapper.selectCount(Wrappers.<ProductionPlan>lambdaQuery() |
| | | .eq(ProductionPlan::getApplyNo, productionPlanDto.getApplyNo()) |
| | | .ne(ProductionPlan::getId, productionPlanDto.getId())); // 排除自身 |
| | | |
| | | if (count > 0) { |
| | | throw new ServiceException("编辑失败,申请单编号 " + productionPlanDto.getApplyNo() + " 已被占用"); |
| | | } |
| | | } |
| | | // 已下发状态,不能编辑 |
| | | if (productionPlan.getStatus() != 0) { |
| | | throw new BaseException("编辑失败,该生产计划已下发或部分下发状态,禁止编辑"); |
| | | } |
| | | |
| | | // 查询是否有关联订单 |
| | | boolean hasProductOrderPlan = productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery().eq(ProductOrderPlan::getProductionPlanId, productionPlanDto.getId())).stream().anyMatch(p -> p.getProductOrderId() != null); |
| | | boolean hasProductOrderPlan = productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery() |
| | | .eq(ProductOrderPlan::getProductionPlanId, productionPlanDto.getId())) |
| | | .stream().anyMatch(p -> p.getProductOrderId() != null); |
| | | |
| | | if (hasProductOrderPlan) { |
| | | // 如果关联,方数只能递增 |
| | | ProductionPlan currentPlan = productionPlanMapper.selectById(productionPlanDto.getId()); |
| | | if (productionPlanDto.getVolume().compareTo(currentPlan.getVolume()) < 0) { |
| | | if (productionPlanDto.getVolume().compareTo(productionPlan.getVolume()) < 0) { |
| | | throw new BaseException("方数不能递减"); |
| | | } |
| | | } |