| | |
| | | import com.ruoyi.production.service.ProductProcessService; |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import com.ruoyi.project.system.service.ISysUserService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | | @Service |
| | |
| | | if (productModel == null) { |
| | | throw new ServiceException("新增失败,该部件不存在"); |
| | | } |
| | | validateDuplicateTypeForSameProduct(productModel.getId(), productProcessDto.getType(), null); |
| | | |
| | | ProductProcess productProcess = new ProductProcess(); |
| | | BeanUtils.copyProperties(productProcessDto, productProcess); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(ProductProcessDto productProcessDto) { |
| | | if (ObjectUtils.isEmpty(productProcessDto.getId())) { |
| | | throw new ServiceException("修改失败,工序ID不能为空"); |
| | | } |
| | | if (ObjectUtils.isEmpty(productProcessDto.getName())) { |
| | | throw new ServiceException("部件名称不能为空"); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | // 判断关联产品是否存在 |
| | | if (ObjectUtils.isNotEmpty(productProcessDto.getProductModelId())) { |
| | | ProductModel productModel = productModelService.getById(productProcessDto.getProductModelId()); |
| | | if (productModel == null) { |
| | | throw new ServiceException("修改失败,关联部件不存在"); |
| | | } |
| | | ProductProcess oldProductProcess = this.getById(productProcessDto.getId()); |
| | | if (oldProductProcess == null) { |
| | | throw new ServiceException("修改失败,工序不存在"); |
| | | } |
| | | Long finalProductModelId = ObjectUtils.isNotEmpty(productProcessDto.getProductModelId()) |
| | | ? productProcessDto.getProductModelId() : oldProductProcess.getProductModelId(); |
| | | Integer finalType = ObjectUtils.isNotEmpty(productProcessDto.getType()) |
| | | ? productProcessDto.getType() : oldProductProcess.getType(); |
| | | |
| | | // 判断关联产品是否存在 |
| | | ProductModel productModel = productModelService.getById(finalProductModelId); |
| | | if (productModel == null) { |
| | | throw new ServiceException("修改失败,关联部件不存在"); |
| | | } |
| | | validateDuplicateTypeForSameProduct(productModel.getId(), finalType, productProcessDto.getId()); |
| | | |
| | | // 校验计划人员 |
| | | validatePlanner(productProcessDto.getPlannerId(), productProcessDto.getPlannerName(), null); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 校验同一产品下工序类型不能重复 |
| | | */ |
| | | private void validateDuplicateTypeForSameProduct(Long productModelId, Integer type, Long excludeId) { |
| | | if (productModelId == null || type == null) { |
| | | return; |
| | | } |
| | | ProductModel currentModel = productModelService.getById(productModelId); |
| | | if (currentModel == null || currentModel.getProductId() == null) { |
| | | return; |
| | | } |
| | | List<ProductModel> productModels = productModelService.list( |
| | | Wrappers.<ProductModel>lambdaQuery().eq(ProductModel::getProductId, currentModel.getProductId())); |
| | | if (CollectionUtils.isEmpty(productModels)) { |
| | | return; |
| | | } |
| | | List<Long> productModelIds = productModels.stream().map(ProductModel::getId).collect(Collectors.toList()); |
| | | LambdaQueryWrapper<ProductProcess> queryWrapper = Wrappers.<ProductProcess>lambdaQuery() |
| | | .in(ProductProcess::getProductModelId, productModelIds) |
| | | .eq(ProductProcess::getType, type); |
| | | if (excludeId != null) { |
| | | queryWrapper.ne(ProductProcess::getId, excludeId); |
| | | } |
| | | if (this.count(queryWrapper) > 0) { |
| | | throw new ServiceException("操作失败,同一产品不能存在重复的部件类型"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void batchDelete(List<Integer> ids) { |