思路就是,获取所有的name,code字典集合,按code进行map分组,然后遍历需要展示的list,同时将code传入map中,获取对应的对象name,再赋值。
List<GhaChkSysDeptExpand> ghaChkSysDeptExpandList = ghaChkSysDeptExpandMapper.selectByCondition(param);
//根据deptCode转换deptName
List<SysDept> deptAll = chkCommonService.getDeptAll();
if (deptAll != null) {
Map<Long, SysDept> sysDeptMap = deptAll.stream().collect(Collectors.toMap(SysDept::getDeptId, Function.identity(),
(key1, key2) -> key2));
ghaChkSysDeptExpandList.stream().forEach(one -> {
SysDept sysDept = sysDeptMap.get(Long.parseLong(one.getDeptCode()));
if (sysDept != null) {
one.setDeptName(sysDept.getDeptName());
}
});
}