| | |
| | | package com.ruoyi.technology.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | 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.framework.web.domain.R; |
| | | import com.ruoyi.technology.bean.dto.TechnologyOperationDto; |
| | | import com.ruoyi.technology.bean.vo.TechnologyOperationVo; |
| | | import com.ruoyi.technology.mapper.TechnologyBomStructureMapper; |
| | | import com.ruoyi.technology.mapper.TechnologyOperationMapper; |
| | | import com.ruoyi.technology.mapper.TechnologyOperationParamMapper; |
| | | import com.ruoyi.technology.mapper.TechnologyRoutingOperationMapper; |
| | | import com.ruoyi.technology.pojo.TechnologyBomStructure; |
| | | import com.ruoyi.technology.pojo.TechnologyOperation; |
| | | import com.ruoyi.technology.pojo.TechnologyOperationParam; |
| | | import com.ruoyi.technology.pojo.TechnologyRoutingOperation; |
| | | import com.ruoyi.technology.service.TechnologyOperationService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | /** |
| | | * <p> |
| | | * 服务实现类 |
| | | * </p> |
| | | * |
| | | * @author 芯导软件(江苏)有限公司 |
| | | * @since 2026-04-20 09:49:48 |
| | | */ |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class TechnologyOperationServiceImpl extends ServiceImpl<TechnologyOperationMapper, TechnologyOperation> implements TechnologyOperationService { |
| | | |
| | | private final TechnologyOperationMapper technologyOperationMapper; |
| | | private final TechnologyRoutingOperationMapper technologyRoutingOperationMapper; |
| | | private final TechnologyBomStructureMapper technologyBomStructureMapper; |
| | | private final TechnologyOperationParamMapper technologyOperationParamMapper; |
| | | |
| | | /** |
| | | * 分页查询工序列表。 |
| | | */ |
| | | @Override |
| | | public IPage<TechnologyOperationVo> listPage(Page<TechnologyOperationDto> page, TechnologyOperationDto technologyOperationDto) { |
| | | return technologyOperationMapper.listPage(page, technologyOperationDto); |
| | | } |
| | | |
| | | /** |
| | | * 新增工序并补齐工序编码。 |
| | | */ |
| | | @Override |
| | | public R add(TechnologyOperationDto technologyOperationDto) { |
| | | TechnologyOperation technologyOperation = new TechnologyOperation(); |
| | | BeanUtils.copyProperties(technologyOperationDto, technologyOperation); |
| | | boolean saved = technologyOperationMapper.insert(technologyOperation) > 0; |
| | | if (saved && ObjectUtils.isNull(technologyOperationDto.getNo())) { |
| | | technologyOperation.setNo("GX" + String.format("%08d", technologyOperation.getId())); |
| | | technologyOperationMapper.updateById(technologyOperation); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 删除工序前校验是否已被BOM结构或工艺路线引用。 |
| | | */ |
| | | @Override |
| | | public String batchDelete(List<Long> ids) { |
| | | List<TechnologyRoutingOperation> routingOperations = technologyRoutingOperationMapper.selectList( |
| | | Wrappers.<TechnologyRoutingOperation>lambdaQuery().in(TechnologyRoutingOperation::getTechnologyOperationId, ids)); |
| | | List<TechnologyBomStructure> bomStructures = technologyBomStructureMapper.selectList( |
| | | Wrappers.<TechnologyBomStructure>lambdaQuery().in(TechnologyBomStructure::getOperationId, ids)); |
| | | if (!CollectionUtils.isEmpty(routingOperations) || !CollectionUtils.isEmpty(bomStructures)) { |
| | | throw new RuntimeException("Operation is referenced and cannot be deleted"); |
| | | } |
| | | technologyOperationParamMapper.delete(Wrappers.<TechnologyOperationParam>lambdaQuery() |
| | | .in(TechnologyOperationParam::getTechnologyOperationId, ids)); |
| | | technologyOperationMapper.deleteBatchIds(ids); |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 查询全部工序并转换为返回对象。 |
| | | */ |
| | | @Override |
| | | public List<TechnologyOperationVo> listVo() { |
| | | return this.list().stream().map(item -> { |
| | | TechnologyOperationVo vo = new TechnologyOperationVo(); |
| | | BeanUtils.copyProperties(item, vo); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | } |