| | |
| | | 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.common.exception.ServiceException; |
| | | import com.ruoyi.production.dto.ProcessRouteDto; |
| | | import com.ruoyi.production.mapper.ProcessRouteItemMapper; |
| | | import com.ruoyi.production.mapper.ProcessRouteMapper; |
| | | import com.ruoyi.production.mapper.ProductOrderMapper; |
| | | import com.ruoyi.production.mapper.ProductProcessRouteMapper; |
| | | import com.ruoyi.production.mapper.ProductStructureMapper; |
| | | import com.ruoyi.production.pojo.ProcessRoute; |
| | | import com.ruoyi.production.pojo.ProcessRouteItem; |
| | | import com.ruoyi.production.pojo.ProductOrder; |
| | | import com.ruoyi.production.pojo.ProductProcessRoute; |
| | | import com.ruoyi.production.pojo.ProductStructure; |
| | | import com.ruoyi.production.service.ProcessRouteService; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | @Autowired |
| | | private ProductOrderMapper productOrderMapper; |
| | | |
| | | @Autowired |
| | | private ProductStructureMapper productStructureMapper; |
| | | |
| | | @Override |
| | | public IPage<ProcessRouteDto> pageProcessRouteDto(Page<ProcessRouteDto> page, ProcessRouteDto processRouteDto) { |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Integer saveProcessRoute(ProcessRoute processRoute) { |
| | | this.save(processRoute); |
| | | if (processRoute.getBomId() == null) { |
| | | throw new ServiceException("请选择BOM"); |
| | | } |
| | | if (!this.save(processRoute)) { |
| | | throw new ServiceException("工艺路线保存失败"); |
| | | } |
| | | |
| | | String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); |
| | | String idStr = String.format("%06d", processRoute.getId()); |
| | | String newProductCode = "GYLX" + dateStr + idStr; |
| | | // 更新数据库中的productCode |
| | | processRoute.setProcessRouteCode(newProductCode); |
| | | return processRouteMapper.updateById(processRoute); |
| | | if (processRouteMapper.updateById(processRoute) != 1) { |
| | | throw new ServiceException("工艺路线编号生成失败"); |
| | | } |
| | | |
| | | List<ProductStructure> structures = productStructureMapper.selectList( |
| | | Wrappers.<ProductStructure>lambdaQuery() |
| | | .eq(ProductStructure::getBomId, processRoute.getBomId()) |
| | | .isNotNull(ProductStructure::getParentId) |
| | | .orderByAsc(ProductStructure::getId)); |
| | | if (structures.isEmpty()) { |
| | | throw new ServiceException("当前BOM没有可生成的子项"); |
| | | } |
| | | |
| | | int dragSort = 1; |
| | | for (ProductStructure structure : structures) { |
| | | if (structure.getProductModelId() == null) { |
| | | throw new ServiceException("BOM中存在未绑定产品的子项"); |
| | | } |
| | | if (structure.getProcessId() == null) { |
| | | throw new ServiceException("BOM中存在未配置工序的子项"); |
| | | } |
| | | |
| | | ProcessRouteItem item = new ProcessRouteItem(); |
| | | item.setRouteId(processRoute.getId()); |
| | | item.setProductModelId(structure.getProductModelId()); |
| | | item.setProcessId(structure.getProcessId()); |
| | | item.setDragSort(dragSort++); |
| | | item.setIsQuality(false); |
| | | if (processRouteItemMapper.insert(item) != 1) { |
| | | throw new ServiceException("工艺路线明细生成失败"); |
| | | } |
| | | } |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | @Override |