| | |
| | | package com.ruoyi.production.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | 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.dto.ProductStructureDto; |
| | | import com.ruoyi.production.mapper.ProcessRouteItemMapper; |
| | | import com.ruoyi.production.mapper.ProcessRouteMapper; |
| | | import com.ruoyi.production.mapper.ProductOrderMapper; |
| | | import com.ruoyi.production.pojo.ProcessRoute; |
| | | import com.ruoyi.production.pojo.ProcessRouteItem; |
| | | import com.ruoyi.production.pojo.ProductOrder; |
| | | import com.ruoyi.production.service.ProcessRouteService; |
| | | import com.ruoyi.production.service.ProductStructureService; |
| | | import com.ruoyi.project.system.domain.SysDictData; |
| | | import com.ruoyi.project.system.mapper.SysDictDataMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | @AllArgsConstructor |
| | |
| | | @Autowired |
| | | private ProcessRouteMapper processRouteMapper; |
| | | |
| | | @Autowired |
| | | private ProcessRouteItemMapper processRouteItemMapper; |
| | | |
| | | @Autowired |
| | | private ProductOrderMapper productOrderMapper; |
| | | |
| | | @Autowired |
| | | private ProductStructureService productStructureService; |
| | | |
| | | @Autowired |
| | | private SysDictDataMapper sysDictDataMapper; |
| | | |
| | | |
| | | @Override |
| | | public IPage<ProcessRouteDto> pageProcessRouteDto(Page<ProcessRouteDto> page, ProcessRouteDto processRouteDto) { |
| | | |
| | | return processRouteMapper.pageProcessRouteDto(page, processRouteDto); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Integer saveProcessRoute(ProcessRoute processRoute) { |
| | | if (processRoute == null || processRoute.getDictCode() == null) { |
| | | throw new ServiceException("新增工艺路线失败,产品类型不能为空"); |
| | | } |
| | | SysDictData sysDictData = sysDictDataMapper.selectDictDataById(processRoute.getDictCode()); |
| | | if (sysDictData == null) { |
| | | throw new ServiceException("新增工艺路线失败,产品类型不存在"); |
| | | } |
| | | |
| | | save(processRoute); |
| | | if (processRoute.getProcessRouteCode() == null || processRoute.getProcessRouteCode().trim().isEmpty()) { |
| | | String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); |
| | | String idStr = String.format("%06d", processRoute.getId()); |
| | | String newProductCode = "GYLX" + dateStr + idStr; |
| | | processRoute.setProcessRouteCode(newProductCode); |
| | | return processRouteMapper.updateById(processRoute); |
| | | } |
| | | return 1; |
| | | } |
| | | |
| | | @Override |
| | | public int batchDelete(List<Long> ids) { |
| | | //先判断是否已经引用了 |
| | | List<ProductOrder> productOrders = productOrderMapper.selectList(Wrappers.<ProductOrder>lambdaQuery().in(ProductOrder::getRouteId, ids)); |
| | | if (productOrders.size() > 0) { |
| | | throw new RuntimeException("该工艺路线生产已引用,不能删除"); |
| | | } |
| | | //删除工艺路线详情 |
| | | processRouteItemMapper.delete(Wrappers.<ProcessRouteItem>lambdaQuery().in(ProcessRouteItem::getRouteId, ids)); |
| | | return processRouteMapper.deleteBatchIds(ids); |
| | | } |
| | | |
| | | @Override |
| | | public List<ProductStructureDto> getRouteBom(Long id) { |
| | | if (id == null) { |
| | | return new ArrayList<>(0); |
| | | } |
| | | |
| | | ProcessRoute processRoute = getById(id); |
| | | if (processRoute == null) { |
| | | throw new ServiceException("工艺路线不存在"); |
| | | } |
| | | |
| | | List<ProductStructureDto> list = productStructureService.listByBomId(processRoute.getBomId()); |
| | | if (list == null) { |
| | | list = new ArrayList<>(0); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public ProcessRoute latestTypeDate(String productName, String strength) { |
| | | return baseMapper.latestTypeDate(productName, strength); |
| | | } |
| | | } |