gongchunyi
7 小时以前 14999b3d001b6eff1220f7a6701c0796eee1089c
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
90
91
package com.ruoyi.production.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.service.BaseParamService;
import com.ruoyi.production.dto.ProductProcessParamDto;
import com.ruoyi.production.dto.ProductProcessParamSortDTO;
import com.ruoyi.production.mapper.ProductProcessParamMapper;
import com.ruoyi.production.pojo.ProductProcessParam;
import com.ruoyi.production.service.ProductProcessParamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * <br>
 * 工序绑定参数接口实现类
 * </br>
 *
 * @author deslrey
 * @version 1.0
 * @since 2026/03/14 13:18
 */
@Slf4j
@Service
public class ProductProcessParamServiceImpl extends ServiceImpl<ProductProcessParamMapper, ProductProcessParam> implements ProductProcessParamService {
 
    @Autowired
    private BaseParamService baseParamService;
 
    @Override
    public List<ProductProcessParamDto> listByProcessId(Long processId) {
        if (processId == null) {
            throw new IllegalArgumentException("工序ID不能为空");
        }
        return baseMapper.selectDtoListByProcessId(processId);
    }
 
    @Override
    public void add(ProductProcessParam productProcessParam) {
        if (productProcessParam.getProcessId() == null) {
            throw new IllegalArgumentException("关联工序ID不能为空");
        }
        if (productProcessParam.getParamId() == null) {
            throw new IllegalArgumentException("关联基础参数ID不能为空");
        }
        productProcessParam.setCreateTime(new Date());
        if (!this.save(productProcessParam)) {
            throw new RuntimeException("新增失败");
        }
    }
 
    @Override
    public void edit(ProductProcessParam productProcessParam) {
        if (productProcessParam.getId() == null) {
            throw new IllegalArgumentException("ID不能为空");
        }
        productProcessParam.setUpdateTime(new Date());
        if (!this.updateById(productProcessParam)) {
            throw new RuntimeException("修改失败");
        }
    }
 
    @Override
    public void deleteByIds(List<Long> ids) {
        if (ids == null || ids.isEmpty()) {
            throw new IllegalArgumentException("ID不能为空");
        }
        if (!this.removeByIds(ids)) {
            throw new RuntimeException("删除失败");
        }
    }
 
    @Override
    public void updateSort(ProductProcessParamSortDTO dto) {
        if (dto == null || dto.getItems() == null || dto.getItems().isEmpty()) {
            throw new IllegalArgumentException("排序数据不能为空");
        }
        List<ProductProcessParam> list = new ArrayList<>();
        for (ProductProcessParamSortDTO.SortItem item : dto.getItems()) {
            ProductProcessParam param = new ProductProcessParam();
            param.setId(item.getId());
            param.setSort(item.getSort());
            list.add(param);
        }
        this.updateBatchById(list);
    }
}