| | |
| | | |
| | | 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.Customer; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.production.dto.ProductProcessDto; |
| | | import com.ruoyi.production.enums.ProductProcessEnum; |
| | | import com.ruoyi.production.mapper.ProcessRouteItemMapper; |
| | | import com.ruoyi.production.mapper.ProductProcessMapper; |
| | | import com.ruoyi.production.mapper.ProductProcessRouteItemMapper; |
| | | import com.ruoyi.production.pojo.ProcessRouteItem; |
| | | import com.ruoyi.production.pojo.ProductProcess; |
| | | import com.ruoyi.production.pojo.ProductProcessRouteItem; |
| | | import com.ruoyi.production.service.ProductProcessService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class ProductProcessServiceImpl extends ServiceImpl<ProductProcessMapper, ProductProcess> implements ProductProcessService { |
| | | |
| | | @Autowired |
| | | private ProductProcessMapper productProcessMapper; |
| | | |
| | | @Autowired |
| | | private ProcessRouteItemMapper processRouteItemMapper; |
| | | |
| | | @Autowired |
| | | private ProductProcessRouteItemMapper productProcessRouteItemMapper; |
| | | |
| | | @Override |
| | | public IPage<ProductProcessDto> listPage(Page page, ProductProcessDto productProcessDto) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult add(ProductProcessDto productProcessDto) { |
| | | ProductProcess productProcess = new ProductProcess(); |
| | | BeanUtils.copyProperties(productProcessDto,productProcess); |
| | | boolean save = productProcessMapper.insert(productProcess) > 0; |
| | | if (save && ObjectUtils.isNotNull(productProcessDto.getNo())) { |
| | | // 根据id生成no字段:GX + 8位数字(不足8位前面补0) |
| | | String no = "GX" + String.format("%08d", productProcess.getId()); |
| | | productProcess.setNo(no); |
| | | |
| | | productProcessMapper.updateById(productProcess); |
| | | return AjaxResult.success(); |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void add(ProductProcessDto productProcessDto) { |
| | | if (ObjectUtils.isEmpty(productProcessDto.getName())) { |
| | | throw new ServiceException("部件名称不能为空"); |
| | | } |
| | | return AjaxResult.error(); |
| | | 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())); |
| | | if (noCount > 0) { |
| | | throw new ServiceException("工序编号已存在,不能重复"); |
| | | } |
| | | } |
| | | |
| | | ProductProcess productProcess = new ProductProcess(); |
| | | BeanUtils.copyProperties(productProcessDto, productProcess); |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult importData(MultipartFile file) { |
| | | try { |
| | | ExcelUtil<ProductProcess> util = new ExcelUtil<ProductProcess>(ProductProcess.class); |
| | | List<ProductProcess> productProcessList = util.importExcel(file.getInputStream()); |
| | | if(CollectionUtils.isEmpty(productProcessList)){ |
| | | return AjaxResult.warn("模板错误或导入数据为空"); |
| | | } |
| | | this.saveOrUpdateBatch(productProcessList); |
| | | return AjaxResult.success(true); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return AjaxResult.error("导入失败"); |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(ProductProcessDto productProcessDto) { |
| | | 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()) |
| | | .ne(ProductProcess::getId, productProcessDto.getId())); |
| | | if (noCount > 0) { |
| | | throw new ServiceException("工序编号已存在,不能重复"); |
| | | } |
| | | } |
| | | |
| | | ProductProcess productProcess = new ProductProcess(); |
| | | BeanUtils.copyProperties(productProcessDto, productProcess); |
| | | this.updateById(productProcess); |
| | | } |
| | | |
| | | @Override |
| | | @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)) { |
| | | throw new ServiceException("模板错误或导入数据为空"); |
| | | } |
| | | |
| | | for (int i = 0; i < productProcessList.size(); i++) { |
| | | ProductProcess productProcess = productProcessList.get(i); |
| | | int rowNum = i + 2; |
| | | |
| | | if (ObjectUtils.isEmpty(productProcess)) { |
| | | throw new ServiceException("第" + rowNum + "行数据为空,请使用正确的模板进行导入"); |
| | | } |
| | | if (ObjectUtils.isEmpty(productProcess.getName())) { |
| | | throw new ServiceException("第" + rowNum + "行:部件名称不能为空"); |
| | | } |
| | | if (ObjectUtils.isEmpty(productProcess.getProductProcessType())) { |
| | | throw new ServiceException("第" + rowNum + "行:部件【" + productProcess.getName() + "】的类型不能为空"); |
| | | } |
| | | ProductProcessEnum enumByInfo = ProductProcessEnum.getEnumByInfo(productProcess.getProductProcessType()); |
| | | if (ObjectUtils.isEmpty(enumByInfo)) { |
| | | throw new ServiceException("第" + rowNum + "行:部件【" + productProcess.getName() + "】的类型【" + productProcess.getProductProcessType() + "】不存在,请填写正确的类型:加工、刮板冷芯制作、管路组对、罐体连接及调试、测试打压、其他"); |
| | | }else { |
| | | productProcess.setType(enumByInfo.getCode()); |
| | | } |
| | | } |
| | | |
| | | saveOrUpdateBatch(productProcessList); |
| | | } catch (ServiceException e) { |
| | | throw e; |
| | | } catch (Exception e) { |
| | | log.error("部件导入异常:{}", e.getMessage(), e); |
| | | throw new ServiceException("部件导入异常:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @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)); |
| | | if (!CollectionUtils.isEmpty(processRouteItems) || !CollectionUtils.isEmpty(productProcessRouteItems)) { |
| | | throw new ServiceException("该工序已经被使用,无法删除"); |
| | | } |
| | | productProcessMapper.deleteBatchIds(ids); |
| | | } |
| | | } |