feat(schProdSchedule): 实现排产单主表与明细表的关联查询功能

- 在SchProdScheduleDetailVo中添加schedule字段用于关联主表信息
- 在SchProdScheduleVo中添加detailList字段用于关联明细列表
- 实现fillSchedule方法批量填充排产单明细中的主表信息
- 实现fillDetailList方法批量填充排产单主表中的明细列表
- 修改queryById、queryPageList、queryList方法以支持关联数据查询
- 添加必要的依赖注入和工具类导入
This commit is contained in:
2026-06-25 13:23:30 +08:00
parent 3277610ff7
commit 86200d189d
4 changed files with 95 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ package com.klp.flow.domain.vo;
import java.math.BigDecimal;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.TableField;
import com.klp.common.annotation.ExcelDictFormat;
import com.klp.common.convert.ExcelDictConvert;
import lombok.Data;
@@ -69,5 +70,10 @@ public class SchProdScheduleDetailVo {
@ExcelProperty(value = "单行排产备注")
private String remark;
/**
* 关联的排产单主表信息
*/
@TableField(exist = false)
private SchProdScheduleVo schedule;
}

View File

@@ -5,10 +5,13 @@ import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.TableField;
import com.klp.common.annotation.ExcelDictFormat;
import com.klp.common.convert.ExcelDictConvert;
import lombok.Data;
import java.util.List;
/**
* 排产单主视图对象 sch_prod_schedule
@@ -186,5 +189,10 @@ public class SchProdScheduleVo {
@ExcelProperty(value = "备注")
private String remark;
/**
* 关联的排产明细列表
*/
@TableField(exist = false)
private List<SchProdScheduleDetailVo> detailList;
}

View File

@@ -12,12 +12,17 @@ import org.springframework.stereotype.Service;
import com.klp.flow.domain.bo.SchProdScheduleDetailBo;
import com.klp.flow.domain.vo.SchProdScheduleDetailVo;
import com.klp.flow.domain.SchProdScheduleDetail;
import com.klp.flow.domain.vo.SchProdScheduleVo;
import com.klp.flow.mapper.SchProdScheduleDetailMapper;
import com.klp.flow.mapper.SchProdScheduleMapper;
import com.klp.flow.service.ISchProdScheduleDetailService;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 排产单明细Service业务层处理
@@ -30,13 +35,18 @@ import java.util.Collection;
public class SchProdScheduleDetailServiceImpl implements ISchProdScheduleDetailService {
private final SchProdScheduleDetailMapper baseMapper;
private final SchProdScheduleMapper scheduleMapper;
/**
* 查询排产单明细
*/
@Override
public SchProdScheduleDetailVo queryById(Long scheduleDetailId){
return baseMapper.selectVoById(scheduleDetailId);
SchProdScheduleDetailVo vo = baseMapper.selectVoById(scheduleDetailId);
if (vo != null) {
fillSchedule(Collections.singletonList(vo));
}
return vo;
}
/**
@@ -46,6 +56,7 @@ public class SchProdScheduleDetailServiceImpl implements ISchProdScheduleDetailS
public TableDataInfo<SchProdScheduleDetailVo> queryPageList(SchProdScheduleDetailBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<SchProdScheduleDetail> lqw = buildQueryWrapper(bo);
Page<SchProdScheduleDetailVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
fillSchedule(result.getRecords());
return TableDataInfo.build(result);
}
@@ -55,7 +66,32 @@ public class SchProdScheduleDetailServiceImpl implements ISchProdScheduleDetailS
@Override
public List<SchProdScheduleDetailVo> queryList(SchProdScheduleDetailBo bo) {
LambdaQueryWrapper<SchProdScheduleDetail> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
List<SchProdScheduleDetailVo> list = baseMapper.selectVoList(lqw);
fillSchedule(list);
return list;
}
/**
* 批量填充主表信息
*/
private void fillSchedule(List<SchProdScheduleDetailVo> voList) {
if (voList == null || voList.isEmpty()) {
return;
}
Set<Long> scheduleIds = voList.stream()
.map(SchProdScheduleDetailVo::getScheduleId)
.filter(id -> id != null)
.collect(Collectors.toSet());
if (scheduleIds.isEmpty()) {
return;
}
List<SchProdScheduleVo> schedules = scheduleMapper.selectVoBatchIds(scheduleIds);
Map<Long, SchProdScheduleVo> scheduleMap = schedules != null
? schedules.stream().collect(Collectors.toMap(SchProdScheduleVo::getScheduleId, s -> s, (a, b) -> a))
: Collections.emptyMap();
for (SchProdScheduleDetailVo vo : voList) {
vo.setSchedule(scheduleMap.get(vo.getScheduleId()));
}
}
private LambdaQueryWrapper<SchProdScheduleDetail> buildQueryWrapper(SchProdScheduleDetailBo bo) {

View File

@@ -12,12 +12,17 @@ import org.springframework.stereotype.Service;
import com.klp.flow.domain.bo.SchProdScheduleBo;
import com.klp.flow.domain.vo.SchProdScheduleVo;
import com.klp.flow.domain.SchProdSchedule;
import com.klp.flow.domain.SchProdScheduleDetail;
import com.klp.flow.domain.vo.SchProdScheduleDetailVo;
import com.klp.flow.mapper.SchProdScheduleMapper;
import com.klp.flow.mapper.SchProdScheduleDetailMapper;
import com.klp.flow.service.ISchProdScheduleService;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collectors;
/**
* 排产单主Service业务层处理
@@ -30,13 +35,18 @@ import java.util.Collection;
public class SchProdScheduleServiceImpl implements ISchProdScheduleService {
private final SchProdScheduleMapper baseMapper;
private final SchProdScheduleDetailMapper detailMapper;
/**
* 查询排产单主
*/
@Override
public SchProdScheduleVo queryById(Long scheduleId){
return baseMapper.selectVoById(scheduleId);
SchProdScheduleVo vo = baseMapper.selectVoById(scheduleId);
if (vo != null) {
fillDetailList(Collections.singletonList(vo));
}
return vo;
}
/**
@@ -46,6 +56,7 @@ public class SchProdScheduleServiceImpl implements ISchProdScheduleService {
public TableDataInfo<SchProdScheduleVo> queryPageList(SchProdScheduleBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<SchProdSchedule> lqw = buildQueryWrapper(bo);
Page<SchProdScheduleVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
fillDetailList(result.getRecords());
return TableDataInfo.build(result);
}
@@ -55,7 +66,37 @@ public class SchProdScheduleServiceImpl implements ISchProdScheduleService {
@Override
public List<SchProdScheduleVo> queryList(SchProdScheduleBo bo) {
LambdaQueryWrapper<SchProdSchedule> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
List<SchProdScheduleVo> list = baseMapper.selectVoList(lqw);
fillDetailList(list);
return list;
}
/**
* 批量填充明细列表
*/
private void fillDetailList(List<SchProdScheduleVo> voList) {
if (voList == null || voList.isEmpty()) {
return;
}
List<Long> scheduleIds = voList.stream()
.map(SchProdScheduleVo::getScheduleId)
.filter(id -> id != null)
.distinct()
.collect(Collectors.toList());
if (scheduleIds.isEmpty()) {
return;
}
LambdaQueryWrapper<SchProdScheduleDetail> detailQw = Wrappers.lambdaQuery();
detailQw.in(SchProdScheduleDetail::getScheduleId, scheduleIds);
List<SchProdScheduleDetailVo> allDetails = detailMapper.selectVoList(detailQw);
if (allDetails == null || allDetails.isEmpty()) {
return;
}
Map<Long, List<SchProdScheduleDetailVo>> detailMap = allDetails.stream()
.collect(Collectors.groupingBy(SchProdScheduleDetailVo::getScheduleId));
for (SchProdScheduleVo vo : voList) {
vo.setDetailList(detailMap.getOrDefault(vo.getScheduleId(), Collections.emptyList()));
}
}
private LambdaQueryWrapper<SchProdSchedule> buildQueryWrapper(SchProdScheduleBo bo) {