| | |
| | | package com.ruoyi.appendix.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.appendix.dto.ProcessRouteItemParamInstanceDto; |
| | | import com.ruoyi.appendix.mapper.ProcessRouteItemParamInstanceMapper; |
| | | import com.ruoyi.appendix.pojo.ProcessRouteItemParamInstance; |
| | | import com.ruoyi.appendix.service.ProcessRouteItemParamInstanceService; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <br> |
| | |
| | | @Slf4j |
| | | @Service |
| | | public class ProcessRouteItemParamInstanceServiceImpl extends ServiceImpl<ProcessRouteItemParamInstanceMapper, ProcessRouteItemParamInstance> implements ProcessRouteItemParamInstanceService { |
| | | } |
| | | |
| | | @Override |
| | | public List<ProcessRouteItemParamInstanceDto> routeItemParamList(Long orderId, Long routeItemId) { |
| | | List<ProcessRouteItemParamInstance> list = list(new LambdaQueryWrapper<ProcessRouteItemParamInstance>() |
| | | .eq(ProcessRouteItemParamInstance::getOrderId, orderId) |
| | | .eq(ProcessRouteItemParamInstance::getRouteItemId, routeItemId) |
| | | .orderByAsc(ProcessRouteItemParamInstance::getSort)); |
| | | |
| | | return list.stream().map(item -> { |
| | | ProcessRouteItemParamInstanceDto dto = new ProcessRouteItemParamInstanceDto(); |
| | | BeanUtils.copyProperties(item, dto); |
| | | return dto; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addRouteItemParam(ProcessRouteItemParamInstanceDto dto) { |
| | | if (dto == null) { |
| | | throw new ServiceException("新增数据不能为空"); |
| | | } |
| | | if (dto.getOrderId() == null) { |
| | | throw new ServiceException("生产订单ID不能为空"); |
| | | } |
| | | if (dto.getRouteItemId() == null) { |
| | | throw new ServiceException("工艺路线明细ID不能为空"); |
| | | } |
| | | Long tenantId = SecurityUtils.getLoginUser().getTenantId(); |
| | | |
| | | ProcessRouteItemParamInstance entity = new ProcessRouteItemParamInstance(); |
| | | BeanUtils.copyProperties(dto, entity); |
| | | entity.setId(null); |
| | | entity.setOrderId(dto.getOrderId()); |
| | | entity.setRouteItemId(dto.getRouteItemId()); |
| | | entity.setIsRequired(dto.getIsRequired()); |
| | | // 取当前订单+路线明细下最大 sort + 1 |
| | | ProcessRouteItemParamInstance maxSortItem = getOne(new LambdaQueryWrapper<ProcessRouteItemParamInstance>() |
| | | .select(ProcessRouteItemParamInstance::getSort) |
| | | .eq(ProcessRouteItemParamInstance::getOrderId, dto.getOrderId()) |
| | | .eq(ProcessRouteItemParamInstance::getRouteItemId, dto.getRouteItemId()) |
| | | .orderByDesc(ProcessRouteItemParamInstance::getSort) |
| | | .last("limit 1")); |
| | | entity.setSort(maxSortItem != null && maxSortItem.getSort() != null ? maxSortItem.getSort() + 1 : 1); |
| | | entity.setTenantId(tenantId); |
| | | entity.setCreateTime(LocalDateTime.now()); |
| | | save(entity); |
| | | } |
| | | |
| | | @Override |
| | | public void updateRouteItemParam(ProcessRouteItemParamInstanceDto dto) { |
| | | if (dto == null || dto.getId() == null) { |
| | | throw new ServiceException("更新数据或ID不能为空"); |
| | | } |
| | | if (getById(dto.getId()) == null) { |
| | | throw new ServiceException("数据不存在"); |
| | | } |
| | | ProcessRouteItemParamInstance entity = new ProcessRouteItemParamInstance(); |
| | | BeanUtils.copyProperties(dto, entity); |
| | | entity.setUpdateTime(LocalDateTime.now()); |
| | | updateById(entity); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteRouteItemParam(Long id) { |
| | | if (id == null) { |
| | | throw new ServiceException("ID不能为空"); |
| | | } |
| | | if (getById(id) == null) { |
| | | throw new ServiceException("数据不存在"); |
| | | } |
| | | removeById(id); |
| | | } |
| | | } |