处理财务导出显示指定名称问题

This commit is contained in:
andy 2026-06-02 16:50:54 +08:00
parent 8e7d331c65
commit f07b0b7e16
3 changed files with 38 additions and 9 deletions

View File

@ -57,6 +57,9 @@ public class SysDept extends BaseEntity
/** 是否加班 */
private String isOverTime;
/** 是否加班 */
private String isShowFinancial;
/** 子部门 */
@TableField(exist = false)
private List<SysDept> children = new ArrayList<SysDept>();

View File

@ -283,7 +283,7 @@ public class RzSalaryDetailServiceImpl extends ServiceImpl<RzSalaryDetailMapper,
deptLists.add(depts);
}
SalaryVo result = sumSalaryVo(allList);
result.setDeptName(sheetCompanyName+"");
result.setDeptName(sheetCompanyName+"");
result.setPeopleNum(dataList.size());
allList.add(result);
@ -303,7 +303,7 @@ public class RzSalaryDetailServiceImpl extends ServiceImpl<RzSalaryDetailMapper,
companyLists.add(ewSalaryVoList);
}else{
SalaryVo result = sumSalaryVo(dataList);
result.setDeptName(sheetCompanyName+"");
result.setDeptName(sheetCompanyName+"");
result.setPeopleNum(dataList.size());
allList.add(result);
@ -348,24 +348,28 @@ public class RzSalaryDetailServiceImpl extends ServiceImpl<RzSalaryDetailMapper,
private List<SalaryVo> buildExportData(RzSalaryDetail rzSalaryDetail) {
// 获取所有部门列表
List<SysDept> deptList = deptMapper.selectList(new LambdaQueryWrapper<SysDept>());
Map<Long, String> deptNameMap = Collections.emptyMap(); //deptList.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName));
for (SysDept dept : deptList) {
deptNameMap.put(dept.getDeptId(), buildDept(dept.getDeptId(), deptList, deptNameMap));
}
//部门列表转换为部门ID到部门名称的映射
Map<Long, String> deptNameMap = deptList.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName));
// Map<Long, String> deptNameMap = deptList.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName));
//键为部门ID值为部门名称用于快速查找父部门为根部门ID为0的部门名称
Map<String, String> nameAndDeptIdMap = deptList.stream().filter(d -> d.getParentId().equals(0l)).collect(Collectors.toMap(d->String.valueOf(d.getDeptId()), SysDept::getDeptName));
Map<String, String> topDeptNameAndDeptIdMap = deptList.stream().filter(d -> d.getParentId().equals(0l)).collect(Collectors.toMap(d->String.valueOf(d.getDeptId()), SysDept::getDeptName));
Map<Long, String> companyNameMap = Collections.emptyMap();
// 过滤出所有非根部门即parentId不等于0的部门并为每个部门执行以下操作
deptList.stream().filter(d -> !d.getParentId().equals(0l)).forEach(d ->{
// 将当前部门的祖ID字符串拆分成List以便后续处理
List<String> parentIdList = Collections.asList(d.getAncestors().split(","));
Iterator<String> it = nameAndDeptIdMap.keySet().iterator();
Iterator<String> it = topDeptNameAndDeptIdMap.keySet().iterator();
while (it.hasNext()){
String pid = it.next();
if(parentIdList.contains(pid)){
companyNameMap.put(d.getDeptId(), nameAndDeptIdMap.get(pid));
companyNameMap.put(d.getDeptId(), topDeptNameAndDeptIdMap.get(pid));
}
}
});
nameAndDeptIdMap.entrySet().stream().forEach(d->{
topDeptNameAndDeptIdMap.entrySet().stream().forEach(d->{
companyNameMap.put(Long.valueOf(d.getKey()), d.getValue());
});
@ -390,6 +394,21 @@ public class RzSalaryDetailServiceImpl extends ServiceImpl<RzSalaryDetailMapper,
return voResult;
}
public String buildDept(Long deptId, List<SysDept> deptList, Map<Long,String> showDeptNameMap){
if(showDeptNameMap.containsKey(deptList)){
return showDeptNameMap.get(deptId);
}
SysDept sysDept = deptList.stream().filter(d -> d.getDeptId().equals(deptId)).findFirst().orElse(null);
if(sysDept != null){
if("1".equals(sysDept.getIsShowFinancial())){
return sysDept.getDeptName();
}else{
return buildDept(sysDept.getParentId(), deptList, showDeptNameMap);
}
}
return null;
}
private List<RzSalaryDetail> selectRzSalaryDetaiList(RzSalaryDetail rzSalaryDetail) {
return getBaseMapper().selectRzSalaryDetailList(rzSalaryDetail);
}

View File

@ -19,10 +19,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="isOverTime" column="is_over_time" />
<result property="isShowFinancial" column="is_show_financial" />
</resultMap>
<sql id="selectDeptVo">
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.leader, d.phone,d.status, d.del_flag,d.is_over_time, d.create_by, d.create_time
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.leader, d.phone,d.status, d.del_flag,d.is_over_time, d.is_show_financial, d.create_by, d.create_time
from sys_dept d
</sql>
@ -41,9 +42,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="status != null and status != ''">
AND status = #{status}
</if>
<if test="isOverTime != null and status != ''">
<if test="isOverTime != null and isOverTime != ''">
AND is_over_time = #{isOverTime}
</if>
<if test="isShowFinancial != null and isShowFinancial != ''">
AND is_show_financial = #{isShowFinancial}
</if>
<!-- 数据范围过滤 -->
${params.dataScope}
order by d.parent_id
@ -99,6 +103,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="phone != null and phone != ''">phone,</if>
<if test="status != null">status,</if>
<if test="isOverTime != null">is_over_time,</if>
<if test="isShowFinancial != null">is_show_financial,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
@ -110,6 +115,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="phone != null and phone != ''">#{phone},</if>
<if test="status != null">#{status},</if>
<if test="isOverTime != null">#{isOverTime},</if>
<if test="isShowFinancial != null">#{isShowFinancial},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
@ -125,6 +131,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="phone != null">phone = #{phone},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="isOverTime != null">is_over_time = #{isOverTime},</if>
<if test="isShowFinancial != null">is_show_financial = #{isShowFinancial},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>