feat(perf): 查询月度薪资记录时关联员工信息
- 引入 WmsEmployeeInfo 和 WmsEmployeeInfoMapper 依赖 - 在 PerfSalaryVo 中添加 wmsEmployeeInfo 字段 - 实现 attachEmployeeInfo 方法批量填充员工信息 - 避免 N+1 查询问题,通过员工ID批量获取员工信息 - 更新查询方法以返回包含员工信息的完整数据 - 在 pom.xml 中添加 klp-wms 模块依赖
This commit is contained in:
@@ -22,6 +22,10 @@
|
|||||||
<groupId>com.klp</groupId>
|
<groupId>com.klp</groupId>
|
||||||
<artifactId>klp-common</artifactId>
|
<artifactId>klp-common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.klp</groupId>
|
||||||
|
<artifactId>klp-wms</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
|||||||
import com.alibaba.excel.annotation.ExcelProperty;
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
import com.klp.common.annotation.ExcelDictFormat;
|
import com.klp.common.annotation.ExcelDictFormat;
|
||||||
import com.klp.common.convert.ExcelDictConvert;
|
import com.klp.common.convert.ExcelDictConvert;
|
||||||
|
import com.klp.domain.WmsEmployeeInfo;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
@@ -208,5 +209,8 @@ public class PerfSalaryVo {
|
|||||||
@ExcelProperty(value = "备注")
|
@ExcelProperty(value = "备注")
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关联员工简要信息 (联查 wms_employee_info)
|
||||||
|
*/
|
||||||
|
private WmsEmployeeInfo wmsEmployeeInfo;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.klp.common.utils.StringUtils;
|
import com.klp.common.utils.StringUtils;
|
||||||
|
import com.klp.domain.WmsEmployeeInfo;
|
||||||
|
import com.klp.mapper.WmsEmployeeInfoMapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.klp.perf.domain.bo.PerfSalaryBo;
|
import com.klp.perf.domain.bo.PerfSalaryBo;
|
||||||
@@ -18,6 +20,8 @@ import com.klp.perf.service.IPerfSalaryService;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 月度薪资计算记录Service业务层处理
|
* 月度薪资计算记录Service业务层处理
|
||||||
@@ -30,9 +34,10 @@ import java.util.Collection;
|
|||||||
public class PerfSalaryServiceImpl implements IPerfSalaryService {
|
public class PerfSalaryServiceImpl implements IPerfSalaryService {
|
||||||
|
|
||||||
private final PerfSalaryMapper baseMapper;
|
private final PerfSalaryMapper baseMapper;
|
||||||
|
private final WmsEmployeeInfoMapper employeeMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询月度薪资计算记录
|
* 查询月度薪资计算记录(含员工信息)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PerfSalaryVo queryById(Long id){
|
public PerfSalaryVo queryById(Long id){
|
||||||
@@ -40,22 +45,52 @@ public class PerfSalaryServiceImpl implements IPerfSalaryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询月度薪资计算记录列表
|
* 查询月度薪资计算记录列表(含员工信息)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TableDataInfo<PerfSalaryVo> queryPageList(PerfSalaryBo bo, PageQuery pageQuery) {
|
public TableDataInfo<PerfSalaryVo> queryPageList(PerfSalaryBo bo, PageQuery pageQuery) {
|
||||||
LambdaQueryWrapper<PerfSalary> lqw = buildQueryWrapper(bo);
|
LambdaQueryWrapper<PerfSalary> lqw = buildQueryWrapper(bo);
|
||||||
Page<PerfSalaryVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
Page<PerfSalaryVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||||
|
attachEmployeeInfo(result.getRecords());
|
||||||
return TableDataInfo.build(result);
|
return TableDataInfo.build(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询月度薪资计算记录列表
|
* 查询月度薪资计算记录列表(含员工信息)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<PerfSalaryVo> queryList(PerfSalaryBo bo) {
|
public List<PerfSalaryVo> queryList(PerfSalaryBo bo) {
|
||||||
LambdaQueryWrapper<PerfSalary> lqw = buildQueryWrapper(bo);
|
LambdaQueryWrapper<PerfSalary> lqw = buildQueryWrapper(bo);
|
||||||
return baseMapper.selectVoList(lqw);
|
List<PerfSalaryVo> list = baseMapper.selectVoList(lqw);
|
||||||
|
attachEmployeeInfo(list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量填充员工简要信息 (避免 N+1 查询)
|
||||||
|
*/
|
||||||
|
private void attachEmployeeInfo(List<PerfSalaryVo> voList) {
|
||||||
|
if (voList == null || voList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Long> employeeIds = voList.stream()
|
||||||
|
.map(PerfSalaryVo::getEmployeeId)
|
||||||
|
.filter(id -> id != null)
|
||||||
|
.distinct()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (employeeIds.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LambdaQueryWrapper<WmsEmployeeInfo> lqw = Wrappers.lambdaQuery();
|
||||||
|
lqw.in(WmsEmployeeInfo::getInfoId, employeeIds);
|
||||||
|
List<WmsEmployeeInfo> employees = employeeMapper.selectList(lqw);
|
||||||
|
Map<Long, WmsEmployeeInfo> empMap = employees.stream()
|
||||||
|
.collect(Collectors.toMap(WmsEmployeeInfo::getInfoId, Function.identity()));
|
||||||
|
for (PerfSalaryVo vo : voList) {
|
||||||
|
if (vo.getEmployeeId() != null) {
|
||||||
|
vo.setWmsEmployeeInfo(empMap.get(vo.getEmployeeId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private LambdaQueryWrapper<PerfSalary> buildQueryWrapper(PerfSalaryBo bo) {
|
private LambdaQueryWrapper<PerfSalary> buildQueryWrapper(PerfSalaryBo bo) {
|
||||||
|
|||||||
Reference in New Issue
Block a user