广丰卷烟厂数采质量分析系统
zhuguifei
2026-03-20 3471290659516cf21db3211a9053daff5f283e03
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package org.dromara.qa.qm.service.impl;
 
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.qa.qm.domain.QmStd;
import org.springframework.stereotype.Service;
import org.dromara.qa.qm.domain.bo.QmJudgeBo;
import org.dromara.qa.qm.domain.vo.QmJudgeVo;
import org.dromara.qa.qm.domain.QmJudge;
import org.dromara.qa.qm.mapper.QmJudgeMapper;
import org.dromara.qa.qm.service.IQmJudgeService;
import org.dromara.qa.qm.service.IQmStdService;
import org.dromara.qa.qm.mapper.QmStdMapper;
 
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.HashMap;
 
/**
 * 判定依据Service业务层处理
 *
 * @author zhuguifei
 * @date 2026-03-18
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class QmJudgeServiceImpl implements IQmJudgeService {
 
    private final QmJudgeMapper baseMapper;
    private final QmStdMapper qmStdMapper;
 
    /**
     * 查询判定依据
     *
     * @param id 主键
     * @return 判定依据
     */
    @Override
    public QmJudgeVo queryById(String id){
        return baseMapper.selectVoById(id);
    }
 
    /**
     * 分页查询判定依据列表
     *
     * @param bo        查询条件
     * @param pageQuery 分页参数
     * @return 判定依据分页列表
     */
    @Override
    public TableDataInfo<QmJudgeVo> queryPageList(QmJudgeBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<QmJudge> lqw = buildQueryWrapper(bo);
        Page<QmJudgeVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        queryQmStd(result);
        return TableDataInfo.build(result);
    }
 
    private void queryQmStd(Page<QmJudgeVo> result) {
        if (result == null || result.getRecords() == null || result.getRecords().isEmpty()) {
            return;
        }
        List<QmJudgeVo> records = result.getRecords();
 
        // 1. Collect all unique stdCode values
        Set<String> stdCodes = records.stream()
            .map(QmJudgeVo::getStdCod)
            .filter(StringUtils::isNotBlank)
            .collect(Collectors.toSet());
 
        if (stdCodes.isEmpty()) {
            return;
        }
 
        // 2. Query QmStd entities based on the collected stdCode values
        LambdaQueryWrapper<QmStd> stdLqw = Wrappers.lambdaQuery();
        stdLqw.in(QmStd::getId, stdCodes);
        List<QmStd> qmStds = qmStdMapper.selectList(stdLqw);
 
        // 3. Create a map from stdCode to stdName for easy lookup
        Map<String, String> stdCodeToNameMap = qmStds.stream()
            .collect(Collectors.toMap(QmStd::getId, QmStd::getStdName, (oldValue, newValue) -> oldValue));
 
        // 4. Populate stdName for each QmJudgeVo
        records.forEach(judgeVo ->
            judgeVo.setStdName(stdCodeToNameMap.getOrDefault(judgeVo.getStdCod(), null))
        );
    }
 
    /**
     * 查询符合条件的判定依据列表
     *
     * @param bo 查询条件
     * @return 判定依据列表
     */
    @Override
    public List<QmJudgeVo> queryList(QmJudgeBo bo) {
        LambdaQueryWrapper<QmJudge> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }
 
    private LambdaQueryWrapper<QmJudge> buildQueryWrapper(QmJudgeBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<QmJudge> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(bo.getMatCode()), QmJudge::getMatCode, bo.getMatCode());
        lqw.like(StringUtils.isNotBlank(bo.getMatName()), QmJudge::getMatName, bo.getMatName());
        lqw.like(StringUtils.isNotBlank(bo.getJudgeName()), QmJudge::getJudgeName, bo.getJudgeName());
        lqw.eq(bo.getStatus()!=null,QmJudge::getStatus, bo.getStatus());
        lqw.eq(bo.getCategory()!=null,QmJudge::getCategory, bo.getCategory());
        return lqw;
    }
 
    /**
     * 新增判定依据
     *
     * @param bo 判定依据
     * @return 是否新增成功
     */
    @Override
    public Boolean insertByBo(QmJudgeBo bo) {
        QmJudge add = MapstructUtils.convert(bo, QmJudge.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
        }
        return flag;
    }
 
    /**
     * 修改判定依据
     *
     * @param bo 判定依据
     * @return 是否修改成功
     */
    @Override
    public Boolean updateByBo(QmJudgeBo bo) {
        QmJudge update = MapstructUtils.convert(bo, QmJudge.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }
 
    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(QmJudge entity){
        //TODO 做一些数据校验,如唯一约束
    }
 
    /**
     * 校验并批量删除判定依据信息
     *
     * @param ids     待删除的主键集合
     * @param isValid 是否进行有效性校验
     * @return 是否删除成功
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<String> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteByIds(ids) > 0;
    }
}