| | |
| | | package com.ruoyi.production.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.pojo.Product; |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.basic.service.IProductModelService; |
| | | import com.ruoyi.basic.service.IProductService; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.production.dto.ProductProcessDto; |
| | | import com.ruoyi.production.dto.ProductProcessImportDto; |
| | | import com.ruoyi.production.enums.ProductProcessEnum; |
| | | import com.ruoyi.production.mapper.ProcessRouteItemMapper; |
| | | import com.ruoyi.production.mapper.ProductProcessMapper; |
| | |
| | | import com.ruoyi.production.pojo.ProductProcess; |
| | | import com.ruoyi.production.pojo.ProductProcessRouteItem; |
| | | 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 org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class ProductProcessServiceImpl extends ServiceImpl<ProductProcessMapper, ProductProcess> implements ProductProcessService { |
| | | public class ProductProcessServiceImpl extends ServiceImpl<ProductProcessMapper, ProductProcess> |
| | | implements ProductProcessService { |
| | | |
| | | @Autowired |
| | | private ProductProcessMapper productProcessMapper; |
| | |
| | | |
| | | @Autowired |
| | | private ProductProcessRouteItemMapper productProcessRouteItemMapper; |
| | | |
| | | @Autowired |
| | | private IProductModelService productModelService; |
| | | |
| | | @Autowired |
| | | private IProductService productService; |
| | | |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Override |
| | | public IPage<ProductProcessDto> listPage(Page page, ProductProcessDto productProcessDto) { |
| | |
| | | if (ObjectUtils.isEmpty(productProcessDto.getName())) { |
| | | throw new ServiceException("é¨ä»¶åç§°ä¸è½ä¸ºç©º"); |
| | | } |
| | | long count = this.count(Wrappers.<ProductProcess>lambdaQuery().eq(ProductProcess::getName, productProcessDto.getName())); |
| | | if (count > 0) { |
| | | throw new ServiceException("é¨ä»¶åç§°å·²åå¨ï¼ä¸è½éå¤"); |
| | | } |
| | | |
| | | if (ObjectUtils.isNotEmpty(productProcessDto.getNo())) { |
| | | long noCount = this.count(Wrappers.<ProductProcess>lambdaQuery().eq(ProductProcess::getNo, productProcessDto.getNo())); |
| | |
| | | throw new ServiceException("å·¥åºç¼å·å·²åå¨ï¼ä¸è½éå¤"); |
| | | } |
| | | } |
| | | // å¤æè®¡åå·¥æ¶æ¯å¦ä¸ºç©º |
| | | if (ObjectUtils.isEmpty(productProcessDto.getSalaryQuota())) { |
| | | throw new ServiceException("æ°å¢å¤±è´¥,计åå·¥æ¶ä¸è½ä¸ºç©º"); |
| | | } |
| | | // å¤æäº§åæ¯å¦åå¨ |
| | | if (ObjectUtils.isEmpty(productProcessDto.getProductModelId())) { |
| | | throw new ServiceException("æ°å¢å¤±è´¥,é¨ä»¶ä¸è½ä¸ºç©º"); |
| | | } |
| | | ProductModel productModel = productModelService.getById(productProcessDto.getProductModelId()); |
| | | if (productModel == null) { |
| | | throw new ServiceException("æ°å¢å¤±è´¥,该é¨ä»¶ä¸åå¨"); |
| | | } |
| | | |
| | | ProductProcess productProcess = new ProductProcess(); |
| | | BeanUtils.copyProperties(productProcessDto, productProcess); |
| | | productProcess.setProductModelId(productModel.getId()); |
| | | |
| | | validatePlanner(productProcessDto.getPlannerId(), productProcessDto.getPlannerName(), null); |
| | | |
| | | boolean save = productProcessMapper.insert(productProcess) > 0; |
| | | if (save && ObjectUtils.isEmpty(productProcess.getNo())) { |
| | | String no = "GX" + String.format("%08d", productProcess.getId()); |
| | | // 注æï¼è¿éç±äºæ¯èªå¨çæç ID è¡¥å
¨ï¼é常ä¸ä¼éå¤ï¼ä½å»ºè®® set ä¹åæ´æ° |
| | | productProcess.setNo(no); |
| | | productProcessMapper.updateById(productProcess); |
| | | } |
| | |
| | | if (ObjectUtils.isEmpty(productProcessDto.getName())) { |
| | | throw new ServiceException("é¨ä»¶åç§°ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | long nameCount = this.count(Wrappers.<ProductProcess>lambdaQuery() |
| | | .eq(ProductProcess::getName, productProcessDto.getName()) |
| | | .ne(ProductProcess::getId, productProcessDto.getId())); |
| | | if (nameCount > 0) { |
| | | throw new ServiceException("é¨ä»¶åç§°å·²åå¨ï¼ä¸è½éå¤"); |
| | | } |
| | | if (ObjectUtils.isNotEmpty(productProcessDto.getNo())) { |
| | | long noCount = this.count(Wrappers.<ProductProcess>lambdaQuery() |
| | | .eq(ProductProcess::getNo, productProcessDto.getNo()) |
| | |
| | | throw new ServiceException("å·¥åºç¼å·å·²åå¨ï¼ä¸è½éå¤"); |
| | | } |
| | | } |
| | | |
| | | // 夿å
³èäº§åæ¯å¦åå¨ |
| | | if (ObjectUtils.isNotEmpty(productProcessDto.getProductModelId())) { |
| | | ProductModel productModel = productModelService.getById(productProcessDto.getProductModelId()); |
| | | if (productModel == null) { |
| | | throw new ServiceException("ä¿®æ¹å¤±è´¥ï¼å
³èé¨ä»¶ä¸åå¨"); |
| | | } |
| | | } |
| | | |
| | | // æ ¡éªè®¡å人å |
| | | validatePlanner(productProcessDto.getPlannerId(), productProcessDto.getPlannerName(), null); |
| | | |
| | | ProductProcess productProcess = new ProductProcess(); |
| | | BeanUtils.copyProperties(productProcessDto, productProcess); |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void importData(MultipartFile file) { |
| | | try { |
| | | ExcelUtil<ProductProcess> util = new ExcelUtil<>(ProductProcess.class); |
| | | List<ProductProcess> productProcessList = util.importExcel(file.getInputStream()); |
| | | if (CollectionUtils.isEmpty(productProcessList)) { |
| | | ExcelUtil<ProductProcessImportDto> util = new ExcelUtil<>(ProductProcessImportDto.class); |
| | | List<ProductProcessImportDto> importList = util.importExcel(file.getInputStream()); |
| | | if (CollectionUtils.isEmpty(importList)) { |
| | | throw new ServiceException("模æ¿é误æå¯¼å
¥æ°æ®ä¸ºç©º"); |
| | | } |
| | | |
| | | for (int i = 0; i < productProcessList.size(); i++) { |
| | | ProductProcess productProcess = productProcessList.get(i); |
| | | List<ProductProcess> productProcessList = new ArrayList<>(); |
| | | for (int i = 0; i < importList.size(); i++) { |
| | | ProductProcessImportDto importDto = importList.get(i); |
| | | int rowNum = i + 2; |
| | | SysUser sysUser = null; |
| | | |
| | | if (ObjectUtils.isEmpty(productProcess)) { |
| | | if (ObjectUtils.isEmpty(importDto)) { |
| | | throw new ServiceException("第" + rowNum + "è¡æ°æ®ä¸ºç©ºï¼è¯·ä½¿ç¨æ£ç¡®ç模æ¿è¿è¡å¯¼å
¥"); |
| | | } |
| | | if (ObjectUtils.isEmpty(productProcess.getName())) { |
| | | if (ObjectUtils.isEmpty(importDto.getName())) { |
| | | throw new ServiceException("第" + rowNum + "è¡ï¼é¨ä»¶åç§°ä¸è½ä¸ºç©º"); |
| | | } |
| | | if (ObjectUtils.isEmpty(productProcess.getProductProcessType())) { |
| | | throw new ServiceException("第" + rowNum + "è¡ï¼é¨ä»¶ã" + productProcess.getName() + "ãçç±»åä¸è½ä¸ºç©º"); |
| | | if (ObjectUtils.isEmpty(importDto.getProductModel())) { |
| | | throw new ServiceException("第" + rowNum + "è¡ï¼é¨ä»¶è§æ ¼ä¸è½ä¸ºç©º"); |
| | | } |
| | | ProductProcessEnum enumByInfo = ProductProcessEnum.getEnumByInfo(productProcess.getProductProcessType()); |
| | | // æ£éªäº§åä¸ç±»åæ¯å¦åå¨ |
| | | Product product = productService.getOne(new LambdaQueryWrapper<Product>().eq(Product::getProductName, importDto.getName())); |
| | | if (product == null) { |
| | | throw new ServiceException("第" + rowNum + "è¡: é¨ä»¶ã" + importDto.getName() + "ãä¸åå¨"); |
| | | } |
| | | ProductModel productModel = productModelService.getOne(new LambdaQueryWrapper<ProductModel>().eq(ProductModel::getProductId, product.getId()).eq(ProductModel::getModel, importDto.getProductModel())); |
| | | if (ObjectUtils.isEmpty(productModel)) { |
| | | throw new ServiceException("第" + rowNum + "è¡ï¼é¨ä»¶è§æ ¼ã" + importDto.getProductModel() + "ãä¸åå¨"); |
| | | } |
| | | |
| | | if (ObjectUtils.isEmpty(importDto.getProductProcessType())) { |
| | | throw new ServiceException("第" + rowNum + "è¡ï¼é¨ä»¶ã" + importDto.getName() + "ãçç±»åä¸è½ä¸ºç©º"); |
| | | } |
| | | ProductProcessEnum enumByInfo = ProductProcessEnum.getEnumByInfo(importDto.getProductProcessType()); |
| | | if (ObjectUtils.isEmpty(enumByInfo)) { |
| | | throw new ServiceException("第" + rowNum + "è¡ï¼é¨ä»¶ã" + productProcess.getName() + "ãçç±»åã" + productProcess.getProductProcessType() + "ãä¸åå¨ï¼è¯·å¡«åæ£ç¡®çç±»åï¼å å·¥ã宿¿å·è¯å¶ä½ã管路ç»å¯¹ãç½ä½è¿æ¥åè°è¯ãæµè¯æåãå
¶ä»"); |
| | | }else { |
| | | productProcess.setType(enumByInfo.getCode()); |
| | | throw new ServiceException("第" + rowNum + "è¡ï¼é¨ä»¶ã" + importDto.getName() + "ãçç±»åã" |
| | | + importDto.getProductProcessType() + "ãä¸åå¨ï¼è¯·å¡«åæ£ç¡®çç±»åï¼å å·¥ã宿¿å·è¯å¶ä½ã管路ç»å¯¹ãç½ä½è¿æ¥åè°è¯ãæµè¯æåãå
¶ä»"); |
| | | } |
| | | // æ£éªè®¡åå·¥æ¶ |
| | | if (importDto.getSalaryQuota() == null || importDto.getSalaryQuota().compareTo(BigDecimal.ZERO) < 0) { |
| | | throw new ServiceException("第" + rowNum + "è¡ï¼è®¡åå·¥æ¶ä¸è½ä¸ºç©ºä¸è´æ°"); |
| | | } |
| | | // æ£éªè®¡å人å |
| | | if (StringUtils.isNotEmpty(importDto.getPlannerName())) { |
| | | sysUser = sysUserMapper.selectUserByNickName(importDto.getPlannerName()); |
| | | if (ObjectUtils.isEmpty(sysUser)) { |
| | | throw new ServiceException("第" + rowNum + "è¡ï¼è®¡å人åã" + importDto.getPlannerName() + "ãä¸åå¨"); |
| | | } |
| | | } |
| | | |
| | | ProductProcess productProcess = new ProductProcess(); |
| | | BeanUtils.copyProperties(importDto, productProcess); |
| | | productProcess.setProductModelId(productModel.getId()); |
| | | productProcess.setType(enumByInfo.getCode()); |
| | | if (sysUser != null) { |
| | | productProcess.setPlannerId(sysUser.getUserId()); |
| | | productProcess.setPlannerName(sysUser.getUserName()); |
| | | } |
| | | productProcessList.add(productProcess); |
| | | } |
| | | |
| | | saveOrUpdateBatch(productProcessList); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªè®¡åäººåæ¯å¦åå¨ |
| | | * |
| | | * @param plannerId 计å人åID |
| | | * @param plannerName 计å人åå§å |
| | | * @param rowNum è¡å· |
| | | */ |
| | | private void validatePlanner(Long plannerId, String plannerName, Integer rowNum) { |
| | | String prefix = rowNum != null ? "第" + rowNum + "è¡ï¼" : ""; |
| | | if (plannerId != null) { |
| | | if (sysUserMapper.selectUserById(plannerId) == null) { |
| | | throw new ServiceException(prefix + "计å人åIDã" + plannerId + "ãä¸åå¨"); |
| | | } |
| | | } else if (ObjectUtils.isNotEmpty(plannerName)) { |
| | | if (sysUserMapper.selectUserByNickName(plannerName) == null) { |
| | | throw new ServiceException(prefix + "计å人åå§åã" + plannerName + "ãä¸åå¨"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void batchDelete(List<Integer> ids) { |
| | | // æ¥è¯¢æ¯å¦ç产ä¸å·²ç»å¼ç¨äºè¿äºå·¥åº |
| | | List<ProcessRouteItem> processRouteItems = processRouteItemMapper.selectList(Wrappers.<ProcessRouteItem>lambdaQuery().in(ProcessRouteItem::getProcessId, ids)); |
| | | List<ProductProcessRouteItem> productProcessRouteItems = productProcessRouteItemMapper.selectList(Wrappers.<ProductProcessRouteItem>lambdaQuery().in(ProductProcessRouteItem::getProcessId, ids)); |
| | | List<ProcessRouteItem> processRouteItems = processRouteItemMapper |
| | | .selectList(Wrappers.<ProcessRouteItem>lambdaQuery().in(ProcessRouteItem::getProcessId, ids)); |
| | | List<ProductProcessRouteItem> productProcessRouteItems = productProcessRouteItemMapper.selectList( |
| | | Wrappers.<ProductProcessRouteItem>lambdaQuery().in(ProductProcessRouteItem::getProcessId, ids)); |
| | | if (!CollectionUtils.isEmpty(processRouteItems) || !CollectionUtils.isEmpty(productProcessRouteItems)) { |
| | | throw new ServiceException("该工åºå·²ç»è¢«ä½¿ç¨ï¼æ æ³å é¤"); |
| | | } |