系统管理之组织机构树形化结构优化篇
Posted 在奋斗的大道
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了系统管理之组织机构树形化结构优化篇相关的知识,希望对你有一定的参考价值。
本文基于:系统管理之组织机构树形化结构 一文,采用Java8 filter 和group by 实现树形结构分组。
Controller层代码片段:
Map<String, List<UcasAuthOrganizationInfo >> sub = list.stream().filter(node -> node.getPsid() != "0").collect(Collectors.groupingBy(node -> node.getPsid()));
list.forEach(node -> node.setChild(sub.get(node.getSid())));
List<UcasAuthOrganizationInfo > filter = list.stream().filter(node -> node.getPsid() == "0").collect(Collectors.toList());
表结构及其初始化数据
/*
Navicat mysql Data Transfer
Source Server : 192.168.1.73
Source Server Type : MySQL
Source Server Version : 80015
Source Host : 192.168.1.73:3306
Source Schema : ucas_zh_08
Target Server Type : MySQL
Target Server Version : 80015
File Encoding : 65001
Date: 15/10/2021 15:50:59
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for auth_organization
-- ----------------------------
DROP TABLE IF EXISTS `auth_organization`;
CREATE TABLE `auth_organization` (
`sid` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '主键',
`psid` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '父Id',
`organization_code` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '机构编码',
`organization_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '机构名称',
`created_by` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '创建人',
`created_dt` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`version` int(9) NULL DEFAULT 1 COMMENT '版本号',
`updated_by` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '更新人',
`updated_dt` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
`zone_org_code` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '区域机构',
`state` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '2' COMMENT '状态(1:禁用,2:启用)',
`value1` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备用字段1',
`value2` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备用字段2',
`value3` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备用字段3',
`depth` int(10) NULL DEFAULT NULL COMMENT '组织深度',
`sort_field` int(9) NULL DEFAULT NULL COMMENT '排序字段',
`organization_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '机构路径',
`is_business` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '是否绑定业务: 1绑定、2:未绑定',
`unique_sid` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '操作日志记录uuid',
PRIMARY KEY (`sid`) USING BTREE,
UNIQUE INDEX `organization_code`(`organization_code`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '机构表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of auth_organization
-- ----------------------------
INSERT INTO `auth_organization` VALUES ('1', '0', 'office', '珠海市局', NULL, '2019-08-13 00:00:00', 9, NULL, '2019-10-16 12:03:15', NULL, '2', NULL, NULL, NULL, 1, 1, '/office', '2', NULL);
INSERT INTO `auth_organization` VALUES ('10', '1', '202', '住房保障科', NULL, '2019-10-16 10:44:09', 5, NULL, '2019-10-29 19:22:47', NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('11', '1', '203', '规委秘书处', NULL, '2019-10-16 10:44:45', 2, NULL, '2019-10-16 10:46:01', NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('12', '1', '201', '住房发展改革科', NULL, '2019-09-19 10:34:21', 5, NULL, '2019-10-16 10:46:20', NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('13', '1', '205', '建筑工程规划管理科', NULL, '2019-10-16 10:45:38', 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('14', '1', '204', '城市更新项目统筹科、城市更新项目监管科', NULL, NULL, 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('15', '1', '206', '验收备案科', NULL, NULL, 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('16', '1', '207', '住房发展与房地产市场监管科', NULL, NULL, 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('17', '1', '208', '规划编制管理科', NULL, NULL, 2, NULL, '2019-10-22 09:54:32', NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('18', '1', '209', '建设用地规划管理科', NULL, NULL, 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('19', '1', '210', '环境艺术与城市设计管理科', NULL, NULL, 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('20', '1', '211', '交通与市政工程规划管理科', NULL, NULL, 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('21', '1', '212', '建筑市场监管科', NULL, NULL, 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('22', '1', '213', '建设工程质量安全监管科', NULL, NULL, 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('23', '1', '214', '建设工程招标投标管理科', NULL, NULL, 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('24', '1', '215', '村镇规划建设科', NULL, NULL, 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('25', '1', '216', '行政审批服务科', NULL, NULL, 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('26', '1', '217', '执法监察支队', NULL, NULL, 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('27', '3', '218', '香洲区规划分局', NULL, NULL, 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('28', '3', '219', '保税区规划分局', NULL, NULL, 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, 2, NULL, NULL, '1', NULL);
INSERT INTO `auth_organization` VALUES ('3', '0', 'record-office', '珠海市档案分局', NULL, '2019-08-29 16:53:46', 2, NULL, '2019-10-16 12:03:40', NULL, '2', NULL, NULL, NULL, 1, 2, '/record-office', '2', NULL);
INSERT INTO `auth_organization` VALUES ('636140421965283328', '11', 'ceshi001', '测试', NULL, '2019-10-22 09:54:55', 2, NULL, '2019-10-22 09:56:50', NULL, '2', NULL, NULL, NULL, 3, NULL, NULL, NULL, NULL);
INSERT INTO `auth_organization` VALUES ('638820190129356800', '10', 'test-001', '测试部', NULL, '2019-10-29 19:23:22', 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, 3, NULL, NULL, NULL, NULL);
INSERT INTO `auth_organization` VALUES ('709440331082498048', '0', 'sz_20201', '深圳市城建档案局1', NULL, '2020-05-11 16:22:37', 3, NULL, '2020-05-11 17:18:06', NULL, '2', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'd6d1c0f7362b45818f1996acd8834cde');
INSERT INTO `auth_organization` VALUES ('815959806274830336', '0', 'gz_0001', '广州市城建档案局', NULL, '2021-03-01 14:51:47', 1, NULL, NULL, NULL, '2', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
SET FOREIGN_KEY_CHECKS = 1;
实体对象
import java.util.Date;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import com.***.common.model.BaseModel;
public class UcasAuthOrganizationInfo extends BaseModel
/**
*
*/
private static final long serialVersionUID = 1L;
private String sid;
private String psid;
@NotBlank(message="统一社会信用代码不能为空")
private String organizationCode;
@NotBlank(message="机构名称不能为空")
@Length(min = 1, max = 32, message="机构名称超长")
private String organizationName;
private String createdBy;
private Date createdDt;
private Integer version;
private String updatedBy;
private Date updatedDt;
private String zoneOrgCode;
private String state;
private String value1;
private String value2;
private String value3;
private Integer depth;
private Integer sortField;
private String organizationPath;
// 补充字段:是否涉及业务
private String isBusiness;
private String uniqueSid;
// 子类
private List<UcasAuthOrganizationInfo> child
public List<UcasAuthOrganizationInfo> getChild()
return child;
public void setChild(List<UcasAuthOrganizationInfo> child)
this.child= child;
public String getUniqueSid()
return uniqueSid;
public void setUniqueSid(String uniqueSid)
this.uniqueSid = uniqueSid;
public String getOrganizationPath()
return organizationPath;
public void setOrganizationPath(String organizationPath)
this.organizationPath = organizationPath;
public Integer getSortField()
return sortField;
public void setSortField(Integer sortField)
this.sortField = sortField;
public String getSid()
return sid;
public void setSid(String sid)
this.sid = sid;
public String getPsid()
return psid;
public void setPsid(String psid)
this.psid = psid;
public String getOrganizationCode()
return organizationCode;
public void setOrganizationCode(String organizationCode)
this.organizationCode = organizationCode == null ? null : organizationCode.trim();
public String getOrganizationName()
return organizationName;
public void setOrganizationName(String organizationName)
this.organizationName = organizationName == null ? null : organizationName.trim();
public String getCreatedBy()
return createdBy;
public void setCreatedBy(String createdBy)
this.createdBy = createdBy == null ? null : createdBy.trim();
public Date getCreatedDt()
return createdDt;
public void setCreatedDt(Date createdDt)
this.createdDt = createdDt;
public Integer getVersion()
return version;
public void setVersion(Integer version)
this.version = version;
public String getUpdatedBy()
return updatedBy;
public void setUpdatedBy(String updatedBy)
this.updatedBy = updatedBy == null ? null : updatedBy.trim();
public Date getUpdatedDt()
return updatedDt;
public void setUpdatedDt(Date updatedDt)
this.updatedDt = updatedDt;
public String getZoneOrgCode()
return zoneOrgCode;
public void setZoneOrgCode(String zoneOrgCode)
this.zoneOrgCode = zoneOrgCode == null ? null : zoneOrgCode.trim();
public String getState()
return state;
public void setState(String state)
this.state = state == null ? null : state.trim();
public String getValue1()
return value1;
public void setValue1(String value1)
this.value1 = value1 == null ? null : value1.trim();
public String getValue2()
return value2;
public void setValue2(String value2)
this.value2 = value2 == null ? null : value2.trim();
public String getValue3()
return value3;
public void setValue3(String value3)
this.value3 = value3 == null ? null : value3.trim();
public Integer getDepth()
return depth;
public void setDepth(Integer depth)
this.depth = depth;
public String getIsBusiness()
return isBusiness;
public void setIsBusiness(String isBusiness)
this.isBusiness = isBusiness;
@Override
public String toString()
return "UcasAuthOrganizationInfo [sid=" + sid + ", psid=" + psid + ", organizationCode=" + organizationCode
+ ", organizationName=" + organizationName + ", createdBy=" + createdBy + ", createdDt=" + createdDt
+ ", version=" + version + ", updatedBy=" + updatedBy + ", updatedDt=" + updatedDt + ", zoneOrgCode="
+ zoneOrgCode + ", state=" + state + ", value1=" + value1 + ", value2=" + value2 + ", value3=" + value3
+ ", depth=" + depth + ", sortField=" + sortField + ", organizationPath=" + organizationPath
+ ", isBusiness=" + isBusiness + "]";
效果截图和mapper 就不截图展示了。
以上是关于系统管理之组织机构树形化结构优化篇的主要内容,如果未能解决你的问题,请参考以下文章