liyong
4 小时以前 1ca5584d7e3200a9af65a099bd26d3593e2ba702
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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;
 
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());
    }
}