| | |
| | | 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.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.common.utils.StringUtils; |
| | | 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.pojo.ProcessRoute; |
| | | import com.ruoyi.production.pojo.ProcessRouteItem; |
| | | import com.ruoyi.production.pojo.ProductOrder; |
| | | import com.ruoyi.production.pojo.ProductProcessRoute; |
| | | import com.ruoyi.production.service.ProcessRouteService; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProcessRoute; |
| | | import com.ruoyi.sales.service.ISalesLedgerProcessRouteService; |
| | | import com.ruoyi.sales.service.ISalesLedgerProductProcessService; |
| | | 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.Arrays; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | @AllArgsConstructor |
| | |
| | | public class ProcessRouteServiceImpl extends ServiceImpl<ProcessRouteMapper, ProcessRoute> implements ProcessRouteService { |
| | | |
| | | @Autowired |
| | | private ISalesLedgerProcessRouteService salesLedgerProcessRouteService; |
| | | |
| | | @Autowired |
| | | private ProcessRouteMapper processRouteMapper; |
| | | |
| | | @Autowired |
| | | private ProcessRouteItemMapper processRouteItemMapper; |
| | | |
| | | @Autowired |
| | | private ProductOrderMapper productOrderMapper; |
| | | |
| | | @Override |
| | | public IPage<ProcessRouteDto> pageProcessRouteDto(Page<ProcessRouteDto> page, ProcessRouteDto processRouteDto) { |
| | | |
| | | return processRouteMapper.pageProcessRouteDto(page, processRouteDto); |
| | | } |
| | | |
| | | @Override |
| | | public Integer saveProcessRoute(ProcessRoute processRoute) { |
| | | if (processRoute == null) { |
| | | throw new ServiceException("工艺路线新增失败,数据不能为空"); |
| | | } |
| | | if (StringUtils.isEmpty(processRoute.getProcessRouteName())) { |
| | | throw new ServiceException("工艺路线新增失败,名称不能为空"); |
| | | } |
| | | this.save(processRoute); |
| | | 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); |
| | | } |
| | | |
| | | @Override |
| | | public int batchDelete(List<Long> ids) { |
| | | //先判断是否已经引用了 |
| | | List<SalesLedgerProcessRoute> list = salesLedgerProcessRouteService.list(new LambdaQueryWrapper<SalesLedgerProcessRoute>().in(SalesLedgerProcessRoute::getProcessRouteId, ids)); |
| | | if (list != null && list.size() > 0) { |
| | | throw new ServiceException("该工艺路线已被引用不能删除"); |
| | | } |
| | | //删除工艺路线详情 |
| | | processRouteItemMapper.delete(Wrappers.<ProcessRouteItem>lambdaQuery().in(ProcessRouteItem::getRouteId, ids)); |
| | | return processRouteMapper.deleteBatchIds(ids); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateDefault(Long id) { |
| | | ProcessRoute currentRoute = this.getById(id); |
| | | if (currentRoute == null) { |
| | | throw new ServiceException("工艺路线不存在"); |
| | | } |
| | | if (Integer.valueOf(1).equals(currentRoute.getIsDefault())) { |
| | | return; |
| | | } |
| | | this.update(Wrappers.<ProcessRoute>lambdaUpdate() |
| | | .set(ProcessRoute::getIsDefault, 0) |
| | | .eq(ProcessRoute::getIsDefault, 1)); |
| | | this.update(Wrappers.<ProcessRoute>lambdaUpdate() |
| | | .set(ProcessRoute::getIsDefault, 1) |
| | | .eq(ProcessRoute::getId, id)); |
| | | } |
| | | } |