package com.ruoyi.production.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.basic.pojo.BaseParam; import com.ruoyi.basic.service.BaseParamService; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.production.dto.ProductionOrderRouteItemParamDto; import com.ruoyi.production.mapper.ProductionOrderRouteItemParamMapper; import com.ruoyi.production.pojo.ProductionOrderRouteItemParam; import com.ruoyi.production.service.IProductionOrderRouteItemParamService; 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 java.time.LocalDateTime; import java.util.List; import java.util.stream.Collectors; /** *

* 生产订单绑定的工艺路线工序--参数表 服务实现类 *

* * @author deslrey * @since 2026-03-20 */ @Slf4j @Service public class ProductionOrderRouteItemParamServiceImpl extends ServiceImpl implements IProductionOrderRouteItemParamService { @Autowired private BaseParamService baseParamService; @Override public List routeItemParamList(Long orderId, Long routeItemId) { List list = list(new LambdaQueryWrapper() .eq(ProductionOrderRouteItemParam::getOrderId, orderId) .eq(ProductionOrderRouteItemParam::getRouteItemId, routeItemId) .orderByAsc(ProductionOrderRouteItemParam::getSort)); return list.stream().map(item -> { ProductionOrderRouteItemParamDto dto = new ProductionOrderRouteItemParamDto(); BeanUtils.copyProperties(item, dto); return dto; }).collect(Collectors.toList()); } @Override @Transactional(rollbackFor = Exception.class) public void addRouteItemParam(ProductionOrderRouteItemParamDto 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(); BaseParam baseParam = baseParamService.getById(dto.getParamId()); if (baseParam == null) { throw new ServiceException("新增参数不存在"); } ProductionOrderRouteItemParam entity = new ProductionOrderRouteItemParam(); BeanUtils.copyProperties(dto, entity); entity.setId(null); entity.setOrderId(dto.getOrderId()); entity.setRouteItemId(dto.getRouteItemId()); entity.setIsRequired(dto.getIsRequired()); // 取当前订单+路线明细下最大 sort + 1 ProductionOrderRouteItemParam maxSortItem = getOne(new LambdaQueryWrapper() .select(ProductionOrderRouteItemParam::getSort) .eq(ProductionOrderRouteItemParam::getOrderId, dto.getOrderId()) .eq(ProductionOrderRouteItemParam::getRouteItemId, dto.getRouteItemId()) .orderByDesc(ProductionOrderRouteItemParam::getSort) .last("limit 1")); entity.setSort(maxSortItem != null && maxSortItem.getSort() != null ? maxSortItem.getSort() + 1 : 1); entity.setParamKey(baseParam.getParamKey()); entity.setParamName(baseParam.getParamName()); entity.setParamFormat(baseParam.getParamFormat()); entity.setParamType(baseParam.getParamType()); entity.setValueMode(baseParam.getValueMode()); entity.setUnit(baseParam.getUnit()); entity.setRemark(baseParam.getRemark()); entity.setTenantId(tenantId); entity.setCreateTime(LocalDateTime.now()); save(entity); } @Override public void updateRouteItemParam(ProductionOrderRouteItemParamDto dto) { if (dto == null || dto.getId() == null) { throw new ServiceException("更新数据或ID不能为空"); } if (getById(dto.getId()) == null) { throw new ServiceException("数据不存在"); } ProductionOrderRouteItemParam entity = new ProductionOrderRouteItemParam(); 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); } }