refactor(qc): 重构质检检查任务查询逻辑

- 将原有的聚合字段拆分方式改为关联表查询方式
- 新增检查任务与检查项关联关系的独立查询
- 使用批量查询替代字符串拆分提高性能
- 优化检查项数据组装逻辑
- 移除原有的字符串分割处理方法
- 改进钢卷信息查询条件判断逻辑
This commit is contained in:
2026-02-03 10:18:03 +08:00
parent 3e55354f04
commit 44933221fe

View File

@@ -51,71 +51,69 @@ public class WmsCheckTaskServiceImpl implements IWmsCheckTaskService {
*/
@Override
public WmsCheckTaskVo queryById(Long taskId) {
WmsCheckTaskVo vo = baseMapper.selectVoByIdPlus(taskId);
if (vo != null && vo.getItemIds() != null) {
// 1. 拆分所有聚合字段(新增 checkTaskItemIds 的处理)
String[] ids = vo.getItemIds().split(","); // 检查项表的 item_id
String[] checkTaskItemIds = vo.getCheckTaskItemIds() != null ? vo.getCheckTaskItemIds().split(",") : new String[ids.length]; // 关联表的 item_id新增
String[] names = vo.getItemNames() != null ? vo.getItemNames().split(",") : new String[ids.length];
String[] statusArr = vo.getItemStatus() != null ? vo.getItemStatus().split(",") : new String[ids.length];
String[] targetUppers = vo.getTargetUppers() != null ? vo.getTargetUppers().split(",") : new String[ids.length];
String[] targetLowers = vo.getTargetLowers() != null ? vo.getTargetLowers().split(",") : new String[ids.length];
String[] standardTargets = vo.getStandardTargets() != null ? vo.getStandardTargets().split(",") : new String[ids.length];
String[] units = vo.getUnits() != null ? vo.getUnits().split(",") : new String[ids.length];
String[] qualitativeQuantitatives = vo.getQualitativeQuantitatives() != null ? vo.getQualitativeQuantitatives().split(",") : new String[ids.length];
String[] actualMeasures = vo.getActualMeasures() != null ? vo.getActualMeasures().split(",") : new String[ids.length];
WmsCheckTaskVo vo = baseMapper.selectVoById(taskId);
if (vo == null) {
return null;
}
// 查询检查任务与检查项关联关系
List<WmsCheckTaskItem> taskItems = wmsCheckTaskItemMapper.selectList(
Wrappers.<WmsCheckTaskItem>lambdaQuery()
.eq(WmsCheckTaskItem::getCheckTaskId, taskId)
.eq(WmsCheckTaskItem::getDelFlag, 0)
);
if (!taskItems.isEmpty()) {
Set<Long> itemIds = new HashSet<>();
for (WmsCheckTaskItem taskItem : taskItems) {
itemIds.add(taskItem.getCheckItemId());
}
// 查询检查项基础信息
List<WmsCheckItem> checkItems = wmsCheckItemMapper.selectBatchIds(itemIds);
Map<Long, WmsCheckItem> itemMap = new HashMap<>();
for (WmsCheckItem item : checkItems) {
itemMap.put(item.getItemId(), item);
}
// 组装检查项列表
List<WmsCheckItemVo> itemList = new ArrayList<>();
for (int i = 0; i < ids.length; i++) {
if (!ids[i].isEmpty()) { // 跳过空字符串(避免拆分后出现空元素)
WmsCheckItemVo item = new WmsCheckItemVo();
// 2. 赋值检查项 ID原逻辑保留
item.setItemId(Long.valueOf(ids[i]));
// 3. 新增:赋值关联表的 item_id
if (checkTaskItemIds.length > i && !checkTaskItemIds[i].isEmpty()) {
item.setCheckTaskItemId(Long.valueOf(checkTaskItemIds[i])); // 假设 WmsCheckItemVo 有这个字段
}
// 4. 其他字段赋值(保持原逻辑,补充判空)
if (names.length > i) item.setItemName(names[i]);
if (statusArr.length > i) item.setStatus(statusArr[i]);
// 处理数值类型时,先判空再转换,避免 NumberFormatException
if (targetUppers.length > i && StringUtils.isNotBlank(targetUppers[i])) {
item.setTargetUpper(new BigDecimal(targetUppers[i])); // 推荐用 new BigDecimal避免 Double 精度问题
}
if (targetLowers.length > i && StringUtils.isNotBlank(targetLowers[i])) {
item.setTargetLower(new BigDecimal(targetLowers[i]));
}
if (standardTargets.length > i && StringUtils.isNotBlank(standardTargets[i])) {
item.setStandardTarget(new BigDecimal(standardTargets[i]));
}
if (units.length > i) item.setUnit(units[i]);
if (qualitativeQuantitatives.length > i && StringUtils.isNotBlank(qualitativeQuantitatives[i])) {
item.setQualitativeQuantitative(Integer.parseInt(qualitativeQuantitatives[i]));
}
if (actualMeasures.length > i) item.setActualMeasure(actualMeasures[i]);
itemList.add(item);
for (WmsCheckTaskItem taskItem : taskItems) {
WmsCheckItemVo itemVo = new WmsCheckItemVo();
WmsCheckItem checkItem = itemMap.get(taskItem.getCheckItemId());
if (checkItem != null) {
itemVo.setItemId(checkItem.getItemId());
itemVo.setItemName(checkItem.getItemName());
}
itemVo.setCheckTaskItemId(taskItem.getItemId());
itemVo.setStatus(taskItem.getStatus().toString());
itemVo.setTargetUpper(taskItem.getTargetUpper());
itemVo.setTargetLower(taskItem.getTargetLower());
itemVo.setStandardTarget(taskItem.getStandardTarget());
itemVo.setUnit(taskItem.getUnit());
itemVo.setQualitativeQuantitative(taskItem.getQualitativeQuantitative());
itemVo.setActualMeasure(taskItem.getActualMeasure() != null ? taskItem.getActualMeasure().toString() : null);
itemList.add(itemVo);
}
vo.setItemList(itemList);
}
// 查询关联的钢卷信息
List<WmsCheckTaskCoilRelation> coilRelations = null;
if (vo != null) {
coilRelations = wmsCheckTaskCoilRelationMapper.selectList(
Wrappers.<WmsCheckTaskCoilRelation>lambdaQuery()
.eq(WmsCheckTaskCoilRelation::getTaskId, vo.getTaskId())
.eq(WmsCheckTaskCoilRelation::getDelFlag, 0)
);
}
List<WmsCheckTaskCoilRelation> coilRelations = wmsCheckTaskCoilRelationMapper.selectList(
Wrappers.<WmsCheckTaskCoilRelation>lambdaQuery()
.eq(WmsCheckTaskCoilRelation::getTaskId, taskId)
.eq(WmsCheckTaskCoilRelation::getDelFlag, 0)
);
if (coilRelations != null && !coilRelations.isEmpty()) {
if (!coilRelations.isEmpty()) {
Set<String> coilIdSet = new HashSet<>();
for (WmsCheckTaskCoilRelation relation : coilRelations) {
coilIdSet.add(relation.getCoilId());
}
// 查询钢卷基础信息
List<WmsMaterialCoilVo> coilList = queryCoilsByIds(coilIdSet);
vo.setCoilList(coilList);
}