修改树机构查询
This commit is contained in:
parent
e90aa05c43
commit
6a17d1d210
|
|
@ -17,6 +17,8 @@ import io.swagger.annotations.Api;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
|
@ -44,7 +46,7 @@ public class TokenController {
|
|||
|
||||
|
||||
@PostMapping("login")
|
||||
public Result<?> login(LoginBody form) {
|
||||
public Result<?> login(@RequestBody LoginBody form) {
|
||||
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword(),null);
|
||||
// 获取登录token
|
||||
return Result.ok(tokenService.createToken(userInfo),"登录成功");
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package com.securitycontrol.common.core.utils.aes;
|
||||
|
||||
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -15,10 +17,8 @@ public class ListHelper {
|
|||
return false;
|
||||
}
|
||||
public static <T> boolean isEmpty(List<T> list){
|
||||
|
||||
return !isNotEmpty(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 集合转字符串
|
||||
* @param list
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
package com.securitycontrol.entity.system;
|
||||
|
||||
import com.securitycontrol.entity.system.vo.OrgVo;
|
||||
import com.securitycontrol.entity.system.vo.TreeNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author:cwchen
|
||||
|
|
@ -13,69 +15,35 @@ import java.util.Objects;
|
|||
* @description:下拉树-工具类
|
||||
*/
|
||||
public class TreeBuild {
|
||||
public List<TreeNode> nodeList = new ArrayList<>();
|
||||
|
||||
private final static String P_ID="0";
|
||||
/**
|
||||
* 构造方法
|
||||
* @param nodeList 将数据集合赋值给nodeList,即所有数据作为所有节点。
|
||||
* 遍历获取
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
public TreeBuild(List<TreeNode> nodeList){
|
||||
this.nodeList = nodeList;
|
||||
public static List<TreeNode> transTreeList(List<TreeNode> list){
|
||||
//map
|
||||
list.stream().map(node -> {
|
||||
node.setChildren(fromTree(node, list));
|
||||
return node;
|
||||
}).collect(Collectors.toList());
|
||||
//过滤出最上级的菜单
|
||||
return list.stream()
|
||||
.filter(ele -> P_ID.equals(ele.getParentId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
/**
|
||||
* 找寻指定菜单的下级菜单
|
||||
* @param node 当前菜单
|
||||
* @param list 所有的菜单list
|
||||
* @return 下级菜单
|
||||
*/
|
||||
public static List<TreeNode> fromTree(TreeNode node, List<TreeNode> list) {
|
||||
return list.stream()
|
||||
.filter(ele -> node.getId().equals(ele.getParentId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取需构建的所有根节点(顶级节点) "0"
|
||||
* @return 所有根节点List集合
|
||||
*/
|
||||
public List<TreeNode> getRootNode(){
|
||||
// 保存所有根节点(所有根节点的数据)
|
||||
List<TreeNode> rootNodeList = new ArrayList<>();
|
||||
// treeNode:查询出的每一条数据(节点)
|
||||
for (TreeNode treeNode : nodeList){
|
||||
// 判断当前节点是否为根节点,此处注意:若parentId类型是String,则要采用equals()方法判断。
|
||||
if (0 == treeNode.getParentId()) {
|
||||
// 是,添加
|
||||
rootNodeList.add(treeNode);
|
||||
}
|
||||
}
|
||||
return rootNodeList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据每一个顶级节点(根节点)进行构建树形结构
|
||||
* @return 构建整棵树
|
||||
*/
|
||||
public List<TreeNode> buildTree(){
|
||||
// treeNodes:保存一个顶级节点所构建出来的完整树形
|
||||
List<TreeNode> treeNodes = new ArrayList<TreeNode>();
|
||||
// getRootNode():获取所有的根节点
|
||||
for (TreeNode treeRootNode : getRootNode()) {
|
||||
// 将顶级节点进行构建子树
|
||||
treeRootNode = buildChildTree(treeRootNode);
|
||||
// 完成一个顶级节点所构建的树形,增加进来
|
||||
treeNodes.add(treeRootNode);
|
||||
}
|
||||
return treeNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归-----构建子树形结构
|
||||
* @param pNode 根节点(顶级节点)
|
||||
* @return 整棵树
|
||||
*/
|
||||
public TreeNode buildChildTree(TreeNode pNode){
|
||||
List<TreeNode> childTree = new ArrayList<TreeNode>();
|
||||
// nodeList:所有节点集合(所有数据)
|
||||
for (TreeNode treeNode : nodeList) {
|
||||
// 判断当前节点的父节点ID是否等于根节点的ID,即当前节点为其下的子节点
|
||||
if (Objects.equals(treeNode.getParentId(),pNode.getId())) {
|
||||
// 再递归进行判断当前节点的情况,调用自身方法
|
||||
childTree.add(buildChildTree(treeNode));
|
||||
}
|
||||
}
|
||||
// for循环结束,即节点下没有任何节点,树形构建结束,设置树结果
|
||||
pNode.setChildren(childTree);
|
||||
return pNode;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
package com.securitycontrol.entity.system.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* 组织机构查询
|
||||
* @author HeiZi
|
||||
*/
|
||||
@Data
|
||||
public class OrgDto {
|
||||
/**关键字*/
|
||||
@Pattern(regexp = "^[a-zA-Z0-9_\\s]+$",message = "查询条件不能包含特殊字符")
|
||||
private String keyWord;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.securitycontrol.entity.system.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import org.omg.CORBA.PRIVATE_MEMBER;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 组织机构实体类
|
||||
* @author HeiZi
|
||||
*/
|
||||
@Data
|
||||
public class OrgVo {
|
||||
/**组织机构id*/
|
||||
private String orgId;
|
||||
/**组织机构名称*/
|
||||
private String orgName;
|
||||
/**组织机构编码*/
|
||||
private String abbName;
|
||||
/**组织机构简称*/
|
||||
@JsonProperty("bName")
|
||||
private String bName;
|
||||
/**上级节点id*/
|
||||
@JsonProperty("pId")
|
||||
private String pId;
|
||||
/**删除状态*/
|
||||
private String delFlag;
|
||||
/**子数据*/
|
||||
private List<OrgVo> children;
|
||||
|
||||
}
|
||||
|
|
@ -17,13 +17,13 @@ import java.util.List;
|
|||
public class TreeNode {
|
||||
|
||||
@ApiModelProperty(value = "id")
|
||||
private Integer id;
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "名称")
|
||||
private String label;
|
||||
|
||||
@ApiModelProperty(value = "父ID")
|
||||
private Integer parentId;
|
||||
private String parentId;
|
||||
|
||||
@ApiModelProperty(value = "层级")
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
|
|
|
|||
|
|
@ -93,6 +93,24 @@
|
|||
<groupId>com.securitycontrol</groupId>
|
||||
<artifactId>securitycontrol-commons-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.9.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -30,14 +30,11 @@ public class ISelectServiceImpl implements ISelectService {
|
|||
@Override
|
||||
public AjaxResult getOrgTree() {
|
||||
List<TreeNode> groupList = new ArrayList<>();
|
||||
List<TreeNode> list = new ArrayList<>();
|
||||
try {
|
||||
list = mapper.getOrgTree();
|
||||
List<TreeNode> list = mapper.getOrgTree();
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
// 创建树形结构(数据集合作为参数)
|
||||
TreeBuild treeBuild = new TreeBuild(list);
|
||||
// 原查询结果转换树形结构
|
||||
groupList = treeBuild.buildTree();
|
||||
groupList= TreeBuild.transTreeList(list);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("组织机构树-查询失败", e);
|
||||
|
|
@ -51,4 +48,6 @@ public class ISelectServiceImpl implements ISelectService {
|
|||
list = mapper.getRoleLists();
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
package com.securitycontrol.system.controller;
|
||||
|
||||
import com.securitycontrol.common.core.domain.Result;
|
||||
import com.securitycontrol.common.core.web.controller.BaseController;
|
||||
import com.securitycontrol.common.core.web.page.TableDataInfo;
|
||||
import com.securitycontrol.entity.system.dto.OrgDto;
|
||||
import com.securitycontrol.entity.system.vo.OrgVo;
|
||||
import com.securitycontrol.system.service.OrgService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 组织机构控制层
|
||||
* @author HeiZi
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/org/")
|
||||
public class OrgController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private OrgService service;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("getOrgList")
|
||||
public Result<List<OrgVo>> getOrgList(OrgDto dto) {
|
||||
return service.getOrgList(dto);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 新增組織機構
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("addOrg")
|
||||
public Result<String> addOrg(@RequestBody OrgVo dto) {
|
||||
return service.addOrg(dto);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*修改组织机构
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("updateOrg")
|
||||
public Result<String> updateOrg(@RequestBody OrgVo dto) {
|
||||
return service.updateOrg(dto);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增組織機構
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("delOrg")
|
||||
public Result<String> delOrg(OrgVo dto) {
|
||||
return service.delOrg(dto);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package com.securitycontrol.system.mapper;
|
||||
|
||||
import com.securitycontrol.entity.system.dto.OrgDto;
|
||||
import com.securitycontrol.entity.system.vo.OrgVo;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 组织机构处理层
|
||||
* @author HeiZi
|
||||
*/
|
||||
@Repository
|
||||
public interface OrgMapper {
|
||||
/**
|
||||
*查询 组织机构集合
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
List<OrgVo> getOrgList(OrgDto dto);
|
||||
|
||||
/**
|
||||
* 新增组织机构
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
int addOrg(OrgVo dto);
|
||||
|
||||
/**
|
||||
* 修改组织机构
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
int updateOrg(OrgVo dto);
|
||||
|
||||
/**
|
||||
*删除组织机构
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
int delOrg(OrgVo dto);
|
||||
}
|
||||
|
|
@ -33,5 +33,10 @@ public interface LoginService {
|
|||
*/
|
||||
List<SysMenu> getAllMenuList(String userId);
|
||||
|
||||
/**
|
||||
* 更新用户登录信息
|
||||
* @param userId
|
||||
* @param ip
|
||||
*/
|
||||
void updateUserLogin(String userId, String ip);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
package com.securitycontrol.system.service;
|
||||
|
||||
import com.securitycontrol.common.core.domain.Result;
|
||||
import com.securitycontrol.entity.system.dto.OrgDto;
|
||||
import com.securitycontrol.entity.system.vo.OrgVo;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 租户机构接口层
|
||||
* @author HeiZi
|
||||
*/
|
||||
public interface OrgService {
|
||||
/**
|
||||
* 查询组织机构结婚
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
Result<List<OrgVo>> getOrgList(OrgDto dto);
|
||||
|
||||
/**
|
||||
* 新增组织机构
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
Result<String> addOrg(OrgVo dto);
|
||||
|
||||
/**
|
||||
* 修改组织机构
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
Result<String> updateOrg(OrgVo dto);
|
||||
|
||||
/**
|
||||
* 删除组织机构
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
Result<String> delOrg(OrgVo dto);
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
package com.securitycontrol.system.service;
|
||||
|
||||
import com.alibaba.nacos.common.utils.UuidUtils;
|
||||
import com.securitycontrol.common.core.domain.Result;
|
||||
import com.securitycontrol.common.core.utils.aes.ListHelper;
|
||||
import com.securitycontrol.common.core.utils.aes.StringHelper;
|
||||
import com.securitycontrol.entity.system.dto.OrgDto;
|
||||
import com.securitycontrol.entity.system.vo.OrgVo;
|
||||
import com.securitycontrol.system.mapper.OrgMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.stereotype.Service;
|
||||
import sun.plugin.util.UIUtil;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author HeiZi
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class OrgServiceImpl implements OrgService{
|
||||
|
||||
|
||||
@Resource
|
||||
private OrgMapper mapper;
|
||||
|
||||
private final static String P_ID="0";
|
||||
|
||||
private final static int SUCCESS=0;
|
||||
|
||||
@Override
|
||||
public Result<List<OrgVo>> getOrgList(OrgDto dto) {
|
||||
List<OrgVo> list=mapper.getOrgList(dto);
|
||||
if(ListHelper.isEmpty(list)){
|
||||
return Result.ok(new ArrayList<>());
|
||||
}
|
||||
return Result.ok(getChildList(list));
|
||||
}
|
||||
@Override
|
||||
public Result<String> addOrg(OrgVo dto) {
|
||||
try {
|
||||
if (StringHelper.isEmpty(dto.getOrgId())) {
|
||||
dto.setOrgId(UuidUtils.generateUuid().toUpperCase());
|
||||
}
|
||||
if (StringHelper.isEmpty(dto.getPId())) {
|
||||
dto.setPId("0");
|
||||
}
|
||||
int num = mapper.addOrg(dto);
|
||||
if (num > SUCCESS) {
|
||||
return Result.ok("新增成功");
|
||||
}
|
||||
return Result.fail("新增失败");
|
||||
} catch (Exception e) {
|
||||
log.error(e.toString(), e);
|
||||
return Result.fail("服务异常");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Result<String> updateOrg(OrgVo dto) {
|
||||
try{
|
||||
if(StringHelper.isEmpty(dto.getOrgId())){
|
||||
return Result.ok("主键不能为空");
|
||||
}
|
||||
if(StringHelper.isEmpty(dto.getPId())){
|
||||
dto.setPId("0");
|
||||
}
|
||||
int num=mapper.updateOrg(dto);
|
||||
if(num>SUCCESS){
|
||||
return Result.ok("修改成功");
|
||||
}
|
||||
return Result.fail("修改失败");
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
return Result.fail("服务异常");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> delOrg(OrgVo dto) {
|
||||
try{
|
||||
if(StringHelper.isEmpty(dto.getOrgId())){
|
||||
return Result.ok("主键不能为空");
|
||||
}
|
||||
int num=mapper.delOrg(dto);
|
||||
if(num>SUCCESS){
|
||||
return Result.ok("删除成功");
|
||||
}
|
||||
return Result.fail("删除失败");
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
return Result.fail("服务异常");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 遍历获取
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
public List<OrgVo> getChildList( List<OrgVo> list){
|
||||
//map
|
||||
list.stream().map(orgVo -> {
|
||||
orgVo.setChildren(this.fromTree(orgVo, list));
|
||||
return orgVo;
|
||||
}).collect(Collectors.toList());
|
||||
//过滤出最上级的菜单
|
||||
return list.stream()
|
||||
.filter(ele -> P_ID.equals(ele.getPId()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
}
|
||||
/**
|
||||
* 找寻指定菜单的下级菜单
|
||||
* @param orgVo 当前菜单
|
||||
* @param list 所有的菜单list
|
||||
* @return 下级菜单
|
||||
*/
|
||||
private List<OrgVo> fromTree(OrgVo orgVo, List<OrgVo> list) {
|
||||
return list.stream()
|
||||
.filter(ele -> orgVo.getOrgId().equals(ele.getPId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.securitycontrol.system.mapper.OrgMapper">
|
||||
<insert id="addOrg">
|
||||
insert into sys_org(org_id, org_name, abb_name, b_name, p_id, del_flag)
|
||||
values (#{orgId},#{orgId},#{abbName},#{bName},#{pId},'0')
|
||||
</insert>
|
||||
<update id="updateOrg">
|
||||
update sys_org set
|
||||
org_name=#{orgName},abb_name=#{abbName},b_name=#{bName},p_id=#{pId}
|
||||
where org_id=#{orgId}
|
||||
</update>
|
||||
<delete id="delOrg">
|
||||
update sys_org set del_flag=1 where org_id=#{orgId}
|
||||
</delete>
|
||||
<select id="getOrgList" resultType="com.securitycontrol.entity.system.vo.OrgVo" parameterType="com.securitycontrol.entity.system.dto.OrgDto">
|
||||
select org_id orgId,org_name orgName,abb_name abbName,b_name bName,p_id pId
|
||||
FROM sys_org
|
||||
where del_flag=0
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.securitycontrol.system.service;
|
||||
|
||||
|
||||
import com.securitycontrol.common.core.domain.Result;
|
||||
import com.securitycontrol.entity.system.vo.OrgVo;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import javax.xml.ws.soap.Addressing;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class OrgServiceImplTest {
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
OrgService service;
|
||||
|
||||
|
||||
@Test
|
||||
public void getOrgList() {
|
||||
Result<List<OrgVo>> list=service.getOrgList(null);
|
||||
System.err.println("测试");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue