Browse Source

用户筛选

master
niohe·erbao 1 year ago
parent
commit
c564253693
5 changed files with 143 additions and 73 deletions
  1. +13
    -2
      pmapi/src/main/java/com/ningdatech/pmapi/organization/service/IDingEmployeeInfoService.java
  2. +9
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/organization/service/IDingOrganizationService.java
  3. +28
    -3
      pmapi/src/main/java/com/ningdatech/pmapi/organization/service/impl/DingEmployeeInfoServiceImpl.java
  4. +23
    -4
      pmapi/src/main/java/com/ningdatech/pmapi/organization/service/impl/DingOrganizationServiceImpl.java
  5. +70
    -64
      pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java

+ 13
- 2
pmapi/src/main/java/com/ningdatech/pmapi/organization/service/IDingEmployeeInfoService.java View File

@@ -1,11 +1,13 @@
package com.ningdatech.pmapi.organization.service;

import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo;

import java.util.List;

/**
* <p>
* 服务类
* 服务类
* </p>
*
* @author Lierbao
@@ -13,4 +15,13 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface IDingEmployeeInfoService extends IService<DingEmployeeInfo> {

/**
* 根据专家 专有钉codeList 获取专家组织codeList
*
* @param employeeCodeList
* @return
*/
List<String> getEmployeesOrgCodeList(List<String> employeeCodeList);

List<DingEmployeeInfo> getEmployeeList(List<String> employeeCodeList);
}

+ 9
- 0
pmapi/src/main/java/com/ningdatech/pmapi/organization/service/IDingOrganizationService.java View File

@@ -1,6 +1,7 @@
package com.ningdatech.pmapi.organization.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo;
import com.ningdatech.pmapi.organization.model.entity.DingOrganization;

import java.util.Collection;
@@ -54,10 +55,18 @@ public interface IDingOrganizationService extends IService<DingOrganization> {

/**
* 根据orgCodeList 获取 code 和 名称 Map
*
* @param orgCodeList
* @return
*/
Map<String, String> getOrgCodeAndNameMap(List<String> orgCodeList);

Map<String, DingOrganization> getOrgMap(List<String> orgCodeList);

/**
* 获取 key:专家code value:组织信息
* @param employeeInfoList
* @return
*/
Map<String, DingOrganization> getEmpCodeOrgMap(List<DingEmployeeInfo> employeeInfoList);
}

+ 28
- 3
pmapi/src/main/java/com/ningdatech/pmapi/organization/service/impl/DingEmployeeInfoServiceImpl.java View File

@@ -1,14 +1,20 @@
package com.ningdatech.pmapi.organization.service.impl;

import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ningdatech.pmapi.organization.mapper.DingEmployeeInfoMapper;
import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo;
import com.ningdatech.pmapi.organization.service.IDingEmployeeInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
* <p>
* 服务实现类
* 服务实现类
* </p>
*
* @author Lierbao
@@ -17,4 +23,23 @@ import org.springframework.stereotype.Service;
@Service
public class DingEmployeeInfoServiceImpl extends ServiceImpl<DingEmployeeInfoMapper, DingEmployeeInfo> implements IDingEmployeeInfoService {

@Override
public List<String> getEmployeesOrgCodeList(List<String> employeeCodeList) {
if (CollUtil.isEmpty(employeeCodeList)) {
return new ArrayList<>();
}
List<DingEmployeeInfo> dingEmployeeInfoList = this.list(Wrappers.lambdaQuery(DingEmployeeInfo.class).in(DingEmployeeInfo::getEmployeeCode, employeeCodeList));
List<String> orgCodeList = dingEmployeeInfoList.stream().map(DingEmployeeInfo::getOrganizationCode).distinct().collect(Collectors.toList());
return orgCodeList;
}

@Override
public List<DingEmployeeInfo> getEmployeeList(List<String> employeeCodeList) {
if (CollUtil.isEmpty(employeeCodeList)) {
return new ArrayList<>();
}
List<DingEmployeeInfo> dingEmployeeInfoList = this.list(Wrappers.lambdaQuery(DingEmployeeInfo.class)
.in(DingEmployeeInfo::getEmployeeCode, employeeCodeList));
return dingEmployeeInfoList;
}
}

+ 23
- 4
pmapi/src/main/java/com/ningdatech/pmapi/organization/service/impl/DingOrganizationServiceImpl.java View File

@@ -7,14 +7,12 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ningdatech.basic.util.CollUtils;
import com.ningdatech.pmapi.organization.mapper.DingOrganizationMapper;
import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo;
import com.ningdatech.pmapi.organization.model.entity.DingOrganization;
import com.ningdatech.pmapi.organization.service.IDingOrganizationService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

/**
@@ -77,9 +75,30 @@ public class DingOrganizationServiceImpl extends ServiceImpl<DingOrganizationMap
@Override
public Map<String, DingOrganization> getOrgMap(List<String> orgCodeList) {
orgCodeList = orgCodeList.stream().distinct().collect(Collectors.toList());
if (CollectionUtil.isEmpty(orgCodeList)) {
return new HashMap<>();
}
List<DingOrganization> dingOrganizationList = listByCodes(orgCodeList);
return dingOrganizationList.stream()
.filter(r -> StringUtils.isNotBlank(r.getOrganizationCode()))
.collect(Collectors.toMap(DingOrganization::getOrganizationCode, r -> r));
}

@Override
public Map<String, DingOrganization> getEmpCodeOrgMap(List<DingEmployeeInfo> employeeInfoList) {
List<String> orgCodeList = employeeInfoList.stream()
.map(DingEmployeeInfo::getOrganizationCode)
.distinct().collect(Collectors.toList());

Map<String, DingOrganization> orgMap = this.getOrgMap(orgCodeList);

Map<String, DingOrganization> empCodeOrgMap = new HashMap<String, DingOrganization>();
for(DingEmployeeInfo dingEmployeeInfo:employeeInfoList){
DingOrganization dingOrganization = orgMap.get(dingEmployeeInfo.getOrganizationCode());
if (Objects.nonNull(dingOrganization)){
empCodeOrgMap.put(dingEmployeeInfo.getEmployeeCode(),dingOrganization);
}
}
return empCodeOrgMap;
}
}

+ 70
- 64
pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java View File

@@ -35,8 +35,10 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
@@ -63,70 +65,51 @@ public class UserInfoManage {
String orgCode = req.getOrgCode();
String name = req.getName();

List<String> roleCompliantEmployeeCodeList = getRoleCompliantEmployeeCodeList(req.getUserRoleList());
if (roleCompliantEmployeeCodeList != null && roleCompliantEmployeeCodeList.size() == 0) {
List<Long> userIdList = getRoleCompliantUserIdList(req.getUserRoleList());
if (userIdList != null && userIdList.size() == 0) {
return pageVo;
}
List<String> orgNameCompliantOrgCodeList = getOrgNameCompliantOrgCodeList(req.getOrgName());
if (orgNameCompliantOrgCodeList != null && orgNameCompliantOrgCodeList.size() == 0) {
List<String> compliantOrgEmpCodeList = getCompliantOrgEmpCodeList(req.getOrgName(), req.getOrgCode());
if (compliantOrgEmpCodeList != null && compliantOrgEmpCodeList.size() == 0) {
return pageVo;
}

LambdaQueryWrapper<DingEmployeeInfo> wrapper = Wrappers.lambdaQuery(DingEmployeeInfo.class)
.eq(DingEmployeeInfo::getMainJob, "true")
.eq(DingEmployeeInfo::getStatus, "A")
.eq(StringUtils.isNotBlank(orgCode), DingEmployeeInfo::getOrganizationCode, orgCode)
.like(StringUtils.isNotBlank(phoneNo), DingEmployeeInfo::getBindUserMobile, phoneNo)
.like(StringUtils.isNotBlank(name), DingEmployeeInfo::getEmployeeName, name)
.in(Objects.nonNull(roleCompliantEmployeeCodeList), DingEmployeeInfo::getEmployeeCode, roleCompliantEmployeeCodeList)
.in(Objects.nonNull(orgNameCompliantOrgCodeList), DingEmployeeInfo::getOrganizationCode, orgNameCompliantOrgCodeList);

Page<DingEmployeeInfo> page = iDingEmployeeInfoService.page(new Page<>(req.getPageNumber(), req.getPageSize()), wrapper);
List<DingEmployeeInfo> records = page.getRecords();
LambdaQueryWrapper<UserInfo> wrapper = Wrappers.lambdaQuery(UserInfo.class)
.like(StringUtils.isNotBlank(phoneNo), UserInfo::getMobile, phoneNo)
.like(StringUtils.isNotBlank(name), UserInfo::getRealName, name)
.in(Objects.nonNull(userIdList), UserInfo::getId, userIdList)
.in(Objects.nonNull(compliantOrgEmpCodeList), UserInfo::getEmployeeCode, compliantOrgEmpCodeList);

Page<UserInfo> page = iUserInfoService.page(new Page<>(req.getPageNumber(), req.getPageSize()), wrapper);
List<UserInfo> records = page.getRecords();
long total = page.getTotal();
List<ResUserInfoListVO> result = new ArrayList<>();
if (records != null && records.size() > 0) {
List<String> employeeCodeList = records.stream().map(DingEmployeeInfo::getEmployeeCode)
List<String> employeeCodeList = records.stream().map(UserInfo::getEmployeeCode)
.distinct().collect(Collectors.toList());

Map<String, UserInfo> employeeCodeAvailableMap = new HashMap<>(16);
if (CollUtil.isNotEmpty(employeeCodeList)) {
employeeCodeAvailableMap = iUserInfoService.list(Wrappers.lambdaQuery(UserInfo.class)
.in(UserInfo::getEmployeeCode, employeeCodeList))
.stream().collect(Collectors.toMap(UserInfo::getEmployeeCode, Function.identity()));
}
List<String> orgCodeList = records.stream()
.map(DingEmployeeInfo::getOrganizationCode)
.filter(StringUtils::isNotBlank).distinct()
.collect(Collectors.toList());
Map<String, DingOrganization> orgMap = iDingOrganizationService.getOrgMap(orgCodeList);
List<DingEmployeeInfo> employeeInfoList = iDingEmployeeInfoService.getEmployeeList(employeeCodeList);
Map<String, DingOrganization> empCodeOrgMap = iDingOrganizationService.getEmpCodeOrgMap(employeeInfoList);

Map<String, UserInfo> finalEmployeeCodeAvailableMap = employeeCodeAvailableMap;
records.forEach(r -> {
ResUserInfoListVO item = new ResUserInfoListVO();
item.setName(r.getEmployeeName());
String organizationCode = r.getOrganizationCode();
if (StringUtils.isNotBlank(organizationCode) && orgMap.containsKey(organizationCode)) {
item.setOrgName(orgMap.get(organizationCode).getOrganizationName());
item.setOrgCode(organizationCode);
String regionCode = orgMap.get(organizationCode).getDivisionCode();
item.setRegionCode(regionCode);
if (Objects.nonNull(regionCode)) {
item.setRegionName(regionCacheHelper.getDisplayName(regionCode, RegionConst.RL_COUNTY));
item.setName(r.getRealName());
String employeeCode = r.getEmployeeCode();
if (StringUtils.isNotBlank(employeeCode)) {
DingOrganization dingOrganization = empCodeOrgMap.get(employeeCode);
if (Objects.nonNull(dingOrganization)) {
item.setOrgName(dingOrganization.getOrganizationName());
item.setOrgCode(dingOrganization.getOrganizationCode());
String regionCode = dingOrganization.getDivisionCode();
item.setRegionCode(regionCode);
if (Objects.nonNull(regionCode)) {
item.setRegionName(regionCacheHelper.getDisplayName(regionCode, RegionConst.RL_COUNTY));
}
}

}
// TODO 从用户信息中获取
// 从所属组织中获取
// resListVO.setRegionId();
UserInfo userInfo = finalEmployeeCodeAvailableMap.get(r.getEmployeeCode());
// 装配用户状态 及 userId
userStatusAssembler(item, userInfo);

if (Objects.isNull(userInfo)) {
item.setUpdateTime(r.getUpdateOn());
} else {
item.setUpdateTime(userInfo.getUpdateOn());
}
userStatusAssembler(item, r);
item.setUpdateTime(r.getUpdateOn());
item.setEmployeeCode(r.getEmployeeCode());
item.setUserRoleList(getUserRoleVOList(item.getUserId()));
result.add(item);
@@ -137,24 +120,50 @@ public class UserInfoManage {
return pageVo;
}

private List<String> getOrgNameCompliantOrgCodeList(String orgName) {
if (StringUtils.isBlank(orgName)) {
private List<String> getCompliantOrgEmpCodeList(String orgName, String orgCode) {
if (StringUtils.isBlank(orgName) && StringUtils.isBlank(orgCode)) {
return null;
}
List<DingOrganization> dingOrganizationList = iDingOrganizationService.list(Wrappers.lambdaQuery(DingOrganization.class)
.like(DingOrganization::getOrganizationName, orgName));
List<String> compliantOrgCodeList = new ArrayList<>();

// 查重符合筛选条件的组织列表
if (StringUtils.isNotBlank(orgName)) {
List<DingOrganization> dingOrganizationList = iDingOrganizationService.list(Wrappers.lambdaQuery(DingOrganization.class)
.like(DingOrganization::getOrganizationName, orgName));
List<String> compliantOrgNameList = dingOrganizationList.stream()
.map(DingOrganization::getOrganizationCode)
.collect(Collectors.toList());
if (CollUtil.isEmpty(compliantOrgNameList)) {
return new ArrayList<>();
}
compliantOrgCodeList.addAll(compliantOrgNameList);
}

return dingOrganizationList.stream()
.map(DingOrganization::getOrganizationCode)
.collect(Collectors.toList());
if (StringUtils.isNotBlank(orgCode)) {
compliantOrgCodeList.add(orgCode);
}
if (CollUtil.isEmpty(compliantOrgCodeList)) {
return new ArrayList<>();
}

// 查重符合筛选条件的用户code列表
List<DingEmployeeInfo> dingEmployeeInfoList = iDingEmployeeInfoService.list(Wrappers.lambdaQuery(DingEmployeeInfo.class)
.in(DingEmployeeInfo::getOrganizationCode, compliantOrgCodeList));

List<String> compliantOrgEmpCodeList = dingEmployeeInfoList.stream()
.map(DingEmployeeInfo::getEmployeeCode).distinct().collect(Collectors.toList());
if (compliantOrgEmpCodeList.size() > 500) {
throw new BizException("搜索结果过多请缩小搜索范围");
}
return compliantOrgEmpCodeList;
}

/**
* 获取符合查询条件的 用户 employeeCode
* 获取符合查询条件的 用户 userId
*
* @param userRoleList
*/
private List<String> getRoleCompliantEmployeeCodeList(List<UserRoleVO> userRoleList) {
private List<Long> getRoleCompliantUserIdList(List<UserRoleVO> userRoleList) {
userRoleList = userRoleList.stream().filter(r -> Objects.nonNull(r.getId())).collect(Collectors.toList());
if (CollUtil.isEmpty(userRoleList)) {
return null;
@@ -166,12 +175,9 @@ public class UserInfoManage {
if (CollUtil.isEmpty(compliantUserIdList)) {
return new ArrayList<>();
}

// TODO 这里过滤的非浙政钉用户的专家 后续需要增加补充逻辑
return iUserInfoService.list(Wrappers.lambdaQuery(UserInfo.class)
.in(UserInfo::getId, compliantUserIdList))
.stream().map(UserInfo::getEmployeeCode)
.filter(StringUtils::isNotBlank).collect(Collectors.toList());
.stream().map(UserInfo::getId).collect(Collectors.toList());

}



Loading…
Cancel
Save