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;
|
}
|
}
|