gongchunyi
6 天以前 352a6420c3241955abd26aaaad997fdc65ffdb3a
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
package com.ruoyi.sales.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.sales.pojo.SalesLedgerProductProcess;
import com.ruoyi.sales.mapper.SalesLedgerProductProcessMapper;
import com.ruoyi.sales.service.ISalesLedgerProductProcessService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
 
/**
 * <p>
 * 销售产品加工明细 服务实现类
 * </p>
 *
 * @author deslrey
 * @since 2026-03-25
 */
@Service
public class SalesLedgerProductProcessServiceImpl extends ServiceImpl<SalesLedgerProductProcessMapper, SalesLedgerProductProcess> implements ISalesLedgerProductProcessService {
 
    @Override
    public Page<SalesLedgerProductProcess> salesLedgerProductProcessList(Page<SalesLedgerProductProcess> page, String name) {
        LambdaQueryWrapper<SalesLedgerProductProcess> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(name)) {
            wrapper.like(SalesLedgerProductProcess::getProcessName, name);
        }
        return this.page(page, wrapper);
    }
 
    @Override
    public void addProcess(SalesLedgerProductProcess process) {
        checkDuplicate(process.getProcessName(), null, process.getProcessName());
        this.save(process);
    }
 
    @Override
    public void updateProcess(SalesLedgerProductProcess process) {
        checkDuplicate(process.getProcessName(), process.getId(), process.getProcessName());
        this.updateById(process);
    }
 
    @Override
    public void deleteProcess(Integer id) {
        this.removeById(id);
    }
 
    private void checkDuplicate(String processName, Integer excludeId, String code) {
        LambdaQueryWrapper<SalesLedgerProductProcess> wrapper = new LambdaQueryWrapper<>();
 
        wrapper.and(w -> w
                .eq(SalesLedgerProductProcess::getProcessName, processName)
                .or()
                .eq(SalesLedgerProductProcess::getCode, code));
 
        if (excludeId != null) {
            wrapper.ne(SalesLedgerProductProcess::getId, excludeId);
        }
 
        if (this.count(wrapper) > 0) {
            throw new RuntimeException("工序名称或编码已存在");
        }
    }
}