Browse Source

添加最低部组织名称字段

master
luogw 1 month ago
parent
commit
b308eb6f58
  1. 3
      src/main/java/com/project/ding/domain/entity/UserEntity.java
  2. 26
      src/main/java/com/project/ding/domain/service/impl/SearchUserDomainServiceImpl.java
  3. 6
      src/main/java/com/project/ding/utils/DingUserSyncUtil.java

3
src/main/java/com/project/ding/domain/entity/UserEntity.java

@ -54,6 +54,9 @@ public class UserEntity extends BaseEntity {
@Column(name = "dept_id_str" , columnDefinition="varchar(2000) comment '部门id集合'")
private String deptIdStr;
@Column(name = "dept_name_str" , columnDefinition="varchar(2000) comment '部门id集合'")
private String deptNameStr;
/**
* 存储为 JSON 数组: [1, 10, 101]
*/

26
src/main/java/com/project/ding/domain/service/impl/SearchUserDomainServiceImpl.java

@ -50,7 +50,7 @@ public class SearchUserDomainServiceImpl implements SearchUserDomainService {
}
if (StrUtil.isNotBlank(param.getSearchDeptName())) {
queryWrapper.like(UserEntity::getDeptPathNameStr , param.getSearchDeptName());
queryWrapper.like(UserEntity::getDeptNameStr , param.getSearchDeptName());
}
queryWrapper.orderByDesc(UserEntity::getDeptIdStr);
@ -95,18 +95,18 @@ public class SearchUserDomainServiceImpl implements SearchUserDomainService {
deptNameList.add(String.join("-" , departmentDTOPathList.stream().filter(DepartmentDTO::getLeaf)
.findAny().orElse(new DepartmentDTO()).getDeptNamePath()));
}
dto.setDeptNameStr(String.join("," , deptNameList));
// 改为最底部门
if (StrUtil.isNotBlank(dto.getDeptNameStr())) {
dto.setDeptNameStr(Arrays.stream(dto.getDeptNameStr().split(",")) // 1. 按逗号拆分成数组并转为流
.map(s -> {
// 2. 对每一项找到最后一个横杠的位置
int lastIndex = s.lastIndexOf("-");
// 3. 如果有横杠则截取,没有则保留原样
return (lastIndex != -1) ? s.substring(lastIndex + 1) : s;
})
.collect(Collectors.joining(",")));
}
// dto.setDeptNameStr(String.join("," , deptNameList));
// // 改为最底部门
// if (StrUtil.isNotBlank(dto.getDeptNameStr())) {
// dto.setDeptNameStr(Arrays.stream(dto.getDeptNameStr().split(",")) // 1. 按逗号拆分成数组并转为流
// .map(s -> {
// // 2. 对每一项找到最后一个横杠的位置
// int lastIndex = s.lastIndexOf("-");
// // 3. 如果有横杠则截取,没有则保留原样
// return (lastIndex != -1) ? s.substring(lastIndex + 1) : s;
// })
// .collect(Collectors.joining(",")));
// }
return dto;
}

6
src/main/java/com/project/ding/utils/DingUserSyncUtil.java

@ -108,10 +108,11 @@ public class DingUserSyncUtil {
List<DepartmentDTO> departmentDTOList = TreeUtils.tree2List(departmentDTOtreeList, DepartmentDTO::getChildrenList);
Map<String , List<Long>> depIdPathMap = new HashMap<>();
Map<String , List<String>> depNamePathMap = new HashMap<>();
Map<String, String> allDepartmentNameMap = new HashMap<>();
departmentDTOList.forEach(dto -> depIdPathMap.put(dto.getId().toString() , dto.getDeptIdPath()));
departmentDTOList.forEach(dto -> depNamePathMap.put(dto.getId().toString() , dto.getDeptNamePath()));
allDepartment.forEach(dto -> allDepartmentNameMap.put(dto.getId().toString(), dto.getName()));
List<List<DepartmentDTO>> departmentPartitions = ListUtil.partition(departmentDTOList, 300);
for (List<DepartmentDTO> batch : departmentPartitions) {
@ -124,14 +125,17 @@ public class DingUserSyncUtil {
allUserDTOList.forEach(user -> {
Set<Long> depIdPathSet = new HashSet<>();
Set<String> depNamePathSet = new HashSet<>();
Set<String> depNameSet = new HashSet<>();
if (StrUtil.isNotBlank(user.getDeptIdStr())) {
for (String idStr : user.getDeptIdStr().split(",")) {
depIdPathSet.addAll(depIdPathMap.get(idStr));
depNamePathSet.addAll(depNamePathMap.get(idStr));
depNameSet.add(allDepartmentNameMap.get(idStr));
}
}
user.setDeptIdList(depIdPathSet.stream().toList());
user.setDeptPathNameStr(String.join("," , depNamePathSet));
user.setDeptNameStr(String.join("," , depNameSet));
});
List<List<UserDTO>> userPartitions = ListUtil.partition(allUserDTOList, 300);
for (List<UserDTO> batch : userPartitions) {

Loading…
Cancel
Save