Просмотр исходного кода

修改组织树查询接口

tags/24080901
WendyYang 10 месяцев назад
Родитель
Сommit
85fe74bfba
6 измененных файлов: 87 добавлений и 85 удалений
  1. +1
    -1
      hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/IProjectRenewalFundDeclarationService.java
  2. +2
    -2
      hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/impl/ProjectRenewalFundDeclarationServiceImpl.java
  3. +4
    -4
      hz-pm-api/src/main/java/com/hz/pm/api/user/controller/MhUnitController.java
  4. +3
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/user/helper/MhUnitCache.java
  5. +9
    -4
      hz-pm-api/src/main/java/com/hz/pm/api/user/helper/impl/MhUnitCacheImpl.java
  6. +68
    -74
      hz-pm-api/src/main/java/com/hz/pm/api/user/manage/MhUnitManage.java

+ 1
- 1
hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/IProjectRenewalFundDeclarationService.java Просмотреть файл

@@ -16,5 +16,5 @@ import com.hz.pm.api.projectlib.model.req.ProjectRenewalListReq;
*/
public interface IProjectRenewalFundDeclarationService extends IService<ProjectRenewalFundDeclaration> {

Page<ProjectRenewalFundDeclarationPO> pageSql(Page<ProjectRenewalFundDeclarationPO> page, ProjectRenewalListReq req);
void pageSql(Page<ProjectRenewalFundDeclarationPO> page, ProjectRenewalListReq req);
}

+ 2
- 2
hz-pm-api/src/main/java/com/hz/pm/api/projectlib/service/impl/ProjectRenewalFundDeclarationServiceImpl.java Просмотреть файл

@@ -25,8 +25,8 @@ public class ProjectRenewalFundDeclarationServiceImpl
implements IProjectRenewalFundDeclarationService {

@Override
public Page<ProjectRenewalFundDeclarationPO> pageSql(Page<ProjectRenewalFundDeclarationPO> page, ProjectRenewalListReq req) {
return baseMapper.pageSql(page, req);
public void pageSql(Page<ProjectRenewalFundDeclarationPO> page, ProjectRenewalListReq req) {
baseMapper.pageSql(page, req);
}

}

+ 4
- 4
hz-pm-api/src/main/java/com/hz/pm/api/user/controller/MhUnitController.java Просмотреть файл

@@ -3,7 +3,6 @@ package com.hz.pm.api.user.controller;
import com.hz.pm.api.user.manage.MhUnitManage;
import com.hz.pm.api.user.model.dto.MhUnitTreeDTO;
import com.hz.pm.api.user.model.dto.MhUnitUserTreeDTO;
import com.hz.pm.api.user.model.dto.UnitDTO;
import com.hz.pm.api.user.model.po.MhUnitListReq;
import com.hz.pm.api.user.model.po.UserTreeReq;
import com.hz.pm.api.user.model.vo.MhUnitListVO;
@@ -13,6 +12,7 @@ import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@@ -35,8 +35,8 @@ public class MhUnitController {

@GetMapping("/tree")
@ApiOperation("单位树")
public List<MhUnitTreeDTO> getMhUnitTree() {
return mhUnitManage.getMhUnitTree();
public List<MhUnitTreeDTO> getMhUnitTree(@RequestParam(required = false) String name) {
return mhUnitManage.getMhUnitTree(name);
}

@GetMapping("/wflowModelConfig/tree")
@@ -54,7 +54,7 @@ public class MhUnitController {
@GetMapping("/user/tree")
@ApiOperation("用户组织树")
public List<MhUnitUserTreeDTO> getUserTree(UserTreeReq req) {
return mhUnitManage.getUserTree(req);
return mhUnitManage.getUnitUserTree(req);
}




+ 3
- 0
hz-pm-api/src/main/java/com/hz/pm/api/user/helper/MhUnitCache.java Просмотреть файл

@@ -2,6 +2,7 @@ package com.hz.pm.api.user.helper;

import com.hz.pm.api.user.model.dto.UnitDTO;

import java.util.Collection;
import java.util.List;

/**
@@ -20,6 +21,8 @@ public interface MhUnitCache {

UnitDTO getById(Long id);

List<UnitDTO> listByIds(Collection<Long> unitIds);

List<UnitDTO> getChildren(Long id);

List<Long> getChildrenIds(Long id);


+ 9
- 4
hz-pm-api/src/main/java/com/hz/pm/api/user/helper/impl/MhUnitCacheImpl.java Просмотреть файл

@@ -20,10 +20,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

@@ -113,6 +110,11 @@ public class MhUnitCacheImpl implements MhUnitCache, InitializingBean {
}

@Override
public List<UnitDTO> listByIds(Collection<Long> unitIds) {
return new ArrayList<>(cache.getAll(unitIds).values());
}

@Override
public List<UnitDTO> getChildren(Long id) {
return CollUtils.convert(childIdMap.get(id), cache::get);
}
@@ -140,6 +142,9 @@ public class MhUnitCacheImpl implements MhUnitCache, InitializingBean {
List<Long> nodeIdPaths = new ArrayList<>();
Long currUnitId = unitId, parentId;
while ((parentId = parentIdMap.get(currUnitId)) != null) {
if (parentId.equals(currUnitId)) {
break;
}
nodeIdPaths.add(0, currUnitId);
currUnitId = parentId;
}


+ 68
- 74
hz-pm-api/src/main/java/com/hz/pm/api/user/manage/MhUnitManage.java Просмотреть файл

@@ -1,7 +1,7 @@
package com.hz.pm.api.user.manage;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import cn.hutool.core.text.CharSequenceUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -23,12 +23,10 @@ import com.ningdatech.basic.model.PageVo;
import com.ningdatech.basic.util.CollUtils;
import com.ningdatech.basic.util.TreeUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

@@ -44,18 +42,37 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public class MhUnitManage {

@Value("${mh.unit.root-parent-id:0}")
private Long unitRootParentId;

private final IMhUnitService mhUnitService;
private final MhUnitCache mhUnitCache;
private final IUserInfoService userInfoService;

public List<MhUnitTreeDTO> getMhUnitTree() {
public List<MhUnitTreeDTO> getMhUnitTree(String name) {
List<UnitDTO> retUnits;
List<UnitDTO> allUnits = mhUnitCache.all();
List<MhUnitTreeDTO> nodes = allUnits.stream().map(w -> {
if (StrUtils.isNotBlank(name)) {
allUnits.removeIf(w -> !w.getName().contains(name));
retUnits = allUnits.stream()
.map(w -> mhUnitCache.getUnitIdPaths(w.getId()))
.flatMap(Collection::stream)
.distinct()
.map(mhUnitCache::getById)
.filter(Objects::nonNull)
.collect(Collectors.toList());
} else {
retUnits = allUnits;
}
if (allUnits.isEmpty()) {
return Collections.emptyList();
}
List<MhUnitTreeDTO> nodes = retUnits.stream().map(w -> {
MhUnitTreeDTO node = BeanUtil.copyProperties(w, MhUnitTreeDTO.class);
node.setStrip(node.getType().getStrip());
return node;
}).collect(Collectors.toList());
return TreeUtil.convertToTree(nodes, 0L);
return TreeUtil.convertToTree(nodes, unitRootParentId);
}

public List<MhUnitTreeDTO> getMhUnitStripTree() {
@@ -73,8 +90,12 @@ public class MhUnitManage {
}

public PageVo<MhUnitListVO> page(MhUnitListReq req) {
LambdaQueryWrapper<MhUnit> query = Wrappers.lambdaQuery(MhUnit.class)
.like(StrUtils.isNotBlank(req.getName()), MhUnit::getName, req.getName());
LambdaQueryWrapper<MhUnit> query = Wrappers.lambdaQuery(MhUnit.class);
if (StrUtils.isNotBlank(req.getName())) {
query.and(q1 -> q1.like(MhUnit::getName, req.getName())
.or(q2 -> q2.like(MhUnit::getShortName, req.getName())));
}

Page<MhUnit> page = mhUnitService.page(req.page(), query);
if (page.getTotal() == 0) {
return PageVo.empty();
@@ -92,51 +113,47 @@ public class MhUnitManage {
return PageVo.of(records, page.getTotal());
}

public List<MhUnitUserTreeDTO> getUserTree(UserTreeReq req) {
List<Long> selectedUnitIds = new ArrayList<>();
List<MhUnitUserTreeDTO> selectedUsers = new ArrayList<>();
public List<MhUnitUserTreeDTO> getUnitUserTree(UserTreeReq req) {
List<MhUnitUserTreeDTO> selectedUnits = new ArrayList<>();
if (req.getId() != null) {
// 查询单位
Wrapper<MhUnit> unitQuery = Wrappers.lambdaQuery(MhUnit.class)
.select(MhUnit::getId)
.like(StrUtils.isNotBlank(req.getName()), MhUnit::getName, req.getName())
.eq(MhUnit::getParentId, req.getId());
List<MhUnit> units = mhUnitService.list(unitQuery);
selectedUnitIds.addAll(CollUtils.fieldList(units, MhUnit::getId));
// 查询用户
LambdaQueryWrapper<UserInfo> userQuery = Wrappers.lambdaQuery(UserInfo.class)
.select(UserInfo::getMhUnitId, UserInfo::getId, UserInfo::getRealName)
.like(StrUtils.isNotBlank(req.getName()), UserInfo::getRealName, req.getName())
.eq(UserInfo::getMhUnitId, req.getId())
.last("limit 100");
List<UserInfo> userInfos = userInfoService.list(userQuery);
selectedUnitIds.addAll(CollUtils.fieldList(userInfos, UserInfo::getMhUnitId));
userInfos.forEach(w -> selectedUsers.add(getMhUnitUserTree(w)));
if (selectedUnitIds.isEmpty()) {
return Collections.emptyList();
}
String rootId = UnitUserNodeType.UNIT + "#" + req.getId();
selectedUnitIds.forEach(w -> {
UnitDTO unit = mhUnitCache.getById(w);
if (unit != null) {
selectedUnits.add(getMhUnitUserTree(unit));
}
});
selectedUnits.addAll(selectedUsers);
return TreeUtil.convertToTree(selectedUnits, rootId);
Set<Long> viewUnitIds = new HashSet<>();
boolean hasId = req.getId() != null;
if (hasId) {
List<Long> childIds = mhUnitCache.getChildrenIdsRecursion(req.getId());
viewUnitIds.addAll(childIds);
viewUnitIds.add(req.getId());
}
boolean hasName = CharSequenceUtil.isNotBlank(req.getName());
LambdaQueryWrapper<UserInfo> userQuery = Wrappers.lambdaQuery(UserInfo.class)
.select(UserInfo::getMhUnitId, UserInfo::getId, UserInfo::getRealName)
.in(!viewUnitIds.isEmpty(), UserInfo::getMhUnitId, viewUnitIds)
.gt(UserInfo::getMhUnitId, 0);
if (hasName) {
// 查询满足名字的
userQuery.like(UserInfo::getRealName, req.getName())
.last("limit 500");
} else if (hasId) {
List<UnitDTO> units = mhUnitCache.listByIds(viewUnitIds);
selectedUnits.addAll(CollUtils.convert(units, this::getMhUnitUserTree));
} else {
// 如果没有查询指定组织,那么直接查询第一级组织
List<UnitDTO> childrenUnits = mhUnitCache.getChildren(0L);
if (childrenUnits.isEmpty()) {
return Collections.emptyList();
}
for (UnitDTO unit : childrenUnits) {
selectedUnits.add(getMhUnitUserTree(unit));
List<UnitDTO> all = mhUnitCache.all();
selectedUnits.addAll(CollUtils.convert(all, this::getMhUnitUserTree));
}
List<UserInfo> userInfos = userInfoService.list(userQuery);
if (userInfos.isEmpty()) {
return Collections.emptyList();
}
if (hasName) {
Set<Long> tmpUnitIds = CollUtils.fieldSet(userInfos, UserInfo::getMhUnitId);
Set<Long> allUnitIds = new HashSet<>();
for (Long unitId : tmpUnitIds) {
allUnitIds.addAll(mhUnitCache.getUnitIdPaths(unitId));
}
selectedUnits.sort(selectedUnits.get(0).comparator());
return selectedUnits;
List<UnitDTO> allUnits = mhUnitCache.listByIds(allUnitIds);
selectedUnits.addAll(CollUtils.convert(allUnits, this::getMhUnitUserTree));
}
selectedUnits.addAll(CollUtils.convert(userInfos, this::getMhUnitUserTree));
String rootId = UnitUserNodeType.UNIT.name() + "#" + (hasId ? req.getId() : unitRootParentId);
return TreeUtil.convertToTree(selectedUnits, rootId);
}

private MhUnitUserTreeDTO getMhUnitUserTree(UnitDTO unit) {
@@ -161,27 +178,4 @@ public class MhUnitManage {
return node;
}

public static List<MhUnitTreeDTO> convertToTree(List<MhUnitTreeDTO> units) {
List<Long> ids = CollUtils.fieldList(units, MhUnitTreeDTO::getId);
List<MhUnitTreeDTO> roots = new ArrayList<>();
for (MhUnitTreeDTO node : units) {
if (!ids.contains(node.getParentId())) {
roots.add(node);
} else {
for (MhUnitTreeDTO parent : units) {
if (parent.getId().equals(node.getParentId())) {
List<MhUnitTreeDTO> children = parent.getChildren();
if (children == null) {
children = new ArrayList<>();
parent.setChildren(children);
}
children.add(node);
break;
}
}
}
}
return roots;
}

}

Загрузка…
Отмена
Сохранить