开放接口新增获取组数据相关接口
This commit is contained in:
@@ -3,6 +3,7 @@ package com.yunhai.userbase.config;
|
|||||||
import com.yunhai.platform.appauth.AppAuthFilter;
|
import com.yunhai.platform.appauth.AppAuthFilter;
|
||||||
import com.yunhai.platform.appauth.AppAuthProperties;
|
import com.yunhai.platform.appauth.AppAuthProperties;
|
||||||
import com.yunhai.platform.auth.UserDetailsProvider;
|
import com.yunhai.platform.auth.UserDetailsProvider;
|
||||||
|
import com.yunhai.userbase.repository.ApplicationInfoRepository;
|
||||||
import com.yunhai.userbase.service.impl.UserCenterService;
|
import com.yunhai.userbase.service.impl.UserCenterService;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.yunhai.userbase.config;
|
|||||||
import com.yunhai.platform.auth.UserDetailsProvider;
|
import com.yunhai.platform.auth.UserDetailsProvider;
|
||||||
import com.yunhai.platform.utils.model.BoaUser;
|
import com.yunhai.platform.utils.model.BoaUser;
|
||||||
import com.yunhai.userbase.service.impl.UserCenterService;
|
import com.yunhai.userbase.service.impl.UserCenterService;
|
||||||
|
import com.yunhai.userbase.service.impl.UserCenterService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 平台 {@link UserDetailsProvider} 的 UserBase 本地实现:CAS 会话流解析出登录名/手机号后,
|
* 平台 {@link UserDetailsProvider} 的 UserBase 本地实现:CAS 会话流解析出登录名/手机号后,
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ public class SysUserController {
|
|||||||
@PostMapping("Add")
|
@PostMapping("Add")
|
||||||
public void add(@RequestBody @Validated(ValidationGroups.Create.class) SysUserRequest request) {
|
public void add(@RequestBody @Validated(ValidationGroups.Create.class) SysUserRequest request) {
|
||||||
List<String> data=new ArrayList<>();
|
List<String> data=new ArrayList<>();
|
||||||
|
|
||||||
sysUserService.add(request);
|
sysUserService.add(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.yunhai.userbase.model.sysgroup.SysGroupMoveRequest;
|
|||||||
import com.yunhai.userbase.model.sysgroup.SysGroupQuery;
|
import com.yunhai.userbase.model.sysgroup.SysGroupQuery;
|
||||||
import com.yunhai.userbase.model.sysgroup.SysGroupRequest;
|
import com.yunhai.userbase.model.sysgroup.SysGroupRequest;
|
||||||
import com.yunhai.userbase.model.sysgroup.SysGroupSortRequest;
|
import com.yunhai.userbase.model.sysgroup.SysGroupSortRequest;
|
||||||
|
import com.yunhai.platform.utils.model.BoaGroup;
|
||||||
import com.yunhai.userbase.model.sysgroup.SysGroupVo;
|
import com.yunhai.userbase.model.sysgroup.SysGroupVo;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -51,4 +52,30 @@ public interface ISysGroupService {
|
|||||||
* @return 含自身在内的组ID集合;组不存在时返回仅含自身的集合
|
* @return 含自身在内的组ID集合;组不存在时返回仅含自身的集合
|
||||||
*/
|
*/
|
||||||
List<Integer> listSelfAndDescendantIds(Integer groupId);
|
List<Integer> listSelfAndDescendantIds(Integer groupId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取整个平台的组树:从根节点(pid=0)开始,children 递归嵌套全部后代。<br>
|
||||||
|
* 根节点唯一,取最小 id 作为树入口。表为空时返回 null。
|
||||||
|
*/
|
||||||
|
BoaGroup getGroups();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取单个组;withSub=true 时递归挂上全部子孙(整棵子树),false/不传时只返回节点本身(children 为 null)。<br>
|
||||||
|
* 组不存在时返回 null。
|
||||||
|
*
|
||||||
|
* @param groupId 组ID
|
||||||
|
* @param withSub 是否展开子节点,缺省 false
|
||||||
|
* @return 组节点(BoaGroup)
|
||||||
|
*/
|
||||||
|
BoaGroup getGroupById(Integer groupId, Boolean withSub);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量获取组;ids 逗号/空格分隔,按入参顺序返回,不存在的 id 跳过。<br>
|
||||||
|
* withSub 语义同 {@link #getGroupById(Integer, Boolean)}。
|
||||||
|
*
|
||||||
|
* @param ids 组ID列表(逗号/空格分隔)
|
||||||
|
* @param withSub 是否展开子节点,缺省 false
|
||||||
|
* @return 组节点列表(按入参顺序;不存在的跳过)
|
||||||
|
*/
|
||||||
|
List<BoaGroup> getGroupList(String ids, Boolean withSub);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.yunhai.userbase.service.impl;
|
|||||||
|
|
||||||
import com.yunhai.userbase.entity.SysGroup;
|
import com.yunhai.userbase.entity.SysGroup;
|
||||||
import com.yunhai.platform.utils.exception.DException;
|
import com.yunhai.platform.utils.exception.DException;
|
||||||
|
import com.yunhai.platform.utils.model.BoaGroup;
|
||||||
import com.yunhai.userbase.enums.GroupTypeEnum;
|
import com.yunhai.userbase.enums.GroupTypeEnum;
|
||||||
import com.yunhai.userbase.enums.IEnum;
|
import com.yunhai.userbase.enums.IEnum;
|
||||||
import com.yunhai.userbase.model.sysgroup.SysGroupBatchRequest;
|
import com.yunhai.userbase.model.sysgroup.SysGroupBatchRequest;
|
||||||
@@ -223,6 +224,77 @@ public class SysGroupService implements ISysGroupService {
|
|||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===================== 开放接口:组树(BoaGroup) =====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取整个平台的组树:从根节点(pid=0)开始,children 递归嵌套全部后代。<br>
|
||||||
|
* 根节点唯一,取最小 id 作为树入口。表为空或无根时返回 null。
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public BoaGroup getGroups() {
|
||||||
|
List<SysGroup> all = sysGroupRepository.findAll();
|
||||||
|
if (all.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Map<Integer, List<SysGroup>> childrenMap = buildSortedChildrenMap(all);
|
||||||
|
List<SysGroup> roots = childrenMap.getOrDefault(ROOT_PARENT_ID, new ArrayList<>());
|
||||||
|
if (roots.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// 根节点唯一,取最小 id 作为整棵树入口
|
||||||
|
SysGroup root = roots.stream()
|
||||||
|
.min(Comparator.comparingInt(SysGroup::getId))
|
||||||
|
.orElse(roots.get(0));
|
||||||
|
return buildBoaNode(root, childrenMap, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取单个组;withSub=true 时递归挂上全部子孙(整棵子树),false/不传时只返回节点本身(children 为 null)。<br>
|
||||||
|
* 组不存在时返回 null。
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public BoaGroup getGroupById(Integer groupId, Boolean withSub) {
|
||||||
|
if (groupId == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
SysGroup entity = sysGroupRepository.findById(groupId).orElse(null);
|
||||||
|
if (entity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!Boolean.TRUE.equals(withSub)) {
|
||||||
|
return convertToBoaGroup(entity);
|
||||||
|
}
|
||||||
|
List<SysGroup> all = sysGroupRepository.findAll();
|
||||||
|
Map<Integer, List<SysGroup>> childrenMap = buildSortedChildrenMap(all);
|
||||||
|
return buildBoaNode(entity, childrenMap, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量获取组;ids 逗号/空格分隔,按入参顺序返回,不存在的 id 跳过。<br>
|
||||||
|
* withSub 语义同 {@link #getGroupById(Integer, Boolean)}。
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<BoaGroup> getGroupList(String ids, Boolean withSub) {
|
||||||
|
List<Integer> idList = parseIds(ids);
|
||||||
|
if (idList.isEmpty()) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
boolean expand = Boolean.TRUE.equals(withSub);
|
||||||
|
List<SysGroup> all = sysGroupRepository.findAll();
|
||||||
|
Map<Integer, SysGroup> allMap = all.stream()
|
||||||
|
.collect(Collectors.toMap(SysGroup::getId, g -> g, (a, b) -> a));
|
||||||
|
Map<Integer, List<SysGroup>> childrenMap = buildSortedChildrenMap(all);
|
||||||
|
List<BoaGroup> result = new ArrayList<>();
|
||||||
|
for (Integer id : idList) {
|
||||||
|
SysGroup g = allMap.get(id);
|
||||||
|
if (g == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
result.add(expand ? buildBoaNode(g, childrenMap, true) : convertToBoaGroup(g));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// ===================== 批量新增 =====================
|
// ===================== 批量新增 =====================
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -374,6 +446,56 @@ public class SysGroupService implements ISysGroupService {
|
|||||||
|
|
||||||
// ===================== 私有工具 =====================
|
// ===================== 私有工具 =====================
|
||||||
|
|
||||||
|
/** SysGroup -> BoaGroup(id/name/parentId/type/sort);children 默认 null(未展开)。 */
|
||||||
|
private BoaGroup convertToBoaGroup(SysGroup entity) {
|
||||||
|
BoaGroup bg = new BoaGroup();
|
||||||
|
bg.setId(entity.getId());
|
||||||
|
bg.setName(entity.getName());
|
||||||
|
bg.setParentId(entity.getParentId());
|
||||||
|
bg.setType(entity.getType() == null ? null : entity.getType().getKey());
|
||||||
|
bg.setSort(entity.getSort());
|
||||||
|
return bg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归组装 BoaGroup 树节点。withSub=true 时挂上全部子孙(子树),children 为列表(无子则空列表);
|
||||||
|
* withSub=false 时直接返回节点,children 保持 null(表示未展开)。
|
||||||
|
*/
|
||||||
|
private BoaGroup buildBoaNode(SysGroup node, Map<Integer, List<SysGroup>> childrenMap, boolean withSub) {
|
||||||
|
BoaGroup bg = convertToBoaGroup(node);
|
||||||
|
if (!withSub) {
|
||||||
|
return bg;
|
||||||
|
}
|
||||||
|
List<BoaGroup> childBgs = new ArrayList<>();
|
||||||
|
List<SysGroup> children = childrenMap.get(node.getId());
|
||||||
|
if (children != null) {
|
||||||
|
for (SysGroup child : children) {
|
||||||
|
childBgs.add(buildBoaNode(child, childrenMap, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bg.setChildren(childBgs);
|
||||||
|
return bg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 解析逗号/空格分隔的 id 串为 Integer 列表;非数字片段忽略。 */
|
||||||
|
private List<Integer> parseIds(String ids) {
|
||||||
|
List<Integer> result = new ArrayList<>();
|
||||||
|
if (ids == null || ids.trim().isEmpty()) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
for (String s : ids.split("[,\\s]+")) {
|
||||||
|
if (s == null || s.trim().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
result.add(Integer.parseInt(s.trim()));
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
// 跳过非数字片段
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/** pid 下已有子节点的最大 sort +1;无子节点返回 1。 */
|
/** pid 下已有子节点的最大 sort +1;无子节点返回 1。 */
|
||||||
private int nextSort(Integer pid) {
|
private int nextSort(Integer pid) {
|
||||||
Integer max = sysGroupRepository.findMaxSortByParentId(pid);
|
Integer max = sysGroupRepository.findMaxSortByParentId(pid);
|
||||||
|
|||||||
Reference in New Issue
Block a user