[Employees and department organizations, left tree and right list, click on the tree structure node on the left to query the list of all information associated with the current node and all subordinate nodes]

Employees and department organizations, left tree and right list, click on the tree structure node on the left to query the list of all information associated with the current node and all subordinate nodes.

In the following scenarios - solution

Focus on the last query condition after where.
Focus on the last query condition after where.
Focus on the last query condition after where.

## 格外注意
## 此处{paramEntity.departmentId}为
## 在点击左侧菜单树时,由前端赋值给传给后端的请求参数

## **departmentId:department_table.id**左侧树由department_table表数据组装的tree数据结构
and concat(dc.parentPathId,',',dc.id) like concat('%',{paramEntity.departmentId},'%')
<select id="selectEmployeePage" resultMap="employeeResultMap">
        SELECT
            ri.*
            
        FROM
            employee_table ri
            LEFT JOIN department_table dc ON ri.department_id = dc.id
        WHERE
            ri.is_deleted = 0
            and dc.is_deleted = 0
            <if test="paramEntity.employeeName!=null and paramEntity.employeeName!='' ">
                and ri.employee_name like concat('%',#{paramEntity.employeeName},'%')
            </if>
            <if test="paramEntity.departmentId!= null and paramEntity.departmentId!= ''">
                and concat(dc.parentPathId,',',dc.id) like concat('%',{paramEntity.departmentId},'%')
            </if>
    </select>

1: Scenario conditions-each department under multi-level departments has its own employees

Department table SQL

-- ----------------------------
-- Table structure for department_table 部门表
-- ----------------------------
DROP TABLE IF EXISTS `department_table`;
CREATE TABLE `department_table`  (
  `id` bigint(20) NOT NULL COMMENT '数据id(主键)',
  `department_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '部门名称',
  `pid` bigint(20) NOT NULL COMMENT '父id(一级分类的父id为0)',
  `parentPathId` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '所有祖先id路径',
  `level` int(2) NOT NULL COMMENT '层级(最多到10级)',
  `create_user` bigint(20) NULL DEFAULT NULL COMMENT '创建人',
  `create_dept` bigint(20) NULL DEFAULT NULL COMMENT '创建部门',
  `create_time` timestamp(0) NULL DEFAULT NULL COMMENT '创建时间',
  `update_user` bigint(20) NULL DEFAULT NULL COMMENT '更新人',
  `update_time` timestamp(0) NULL DEFAULT NULL COMMENT '更新时间',
  `status` tinyint(4) NULL DEFAULT NULL COMMENT '业务状态',
  `is_deleted` tinyint(4) NULL DEFAULT NULL COMMENT '是否已删除(0:未删除; 1:已删除)',

  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '部门表' ROW_FORMAT = Dynamic;
SET FOREIGN_KEY_CHECKS = 1;

Employee table SQL
employee

-- ----------------------------
-- Table structure for employee_table 员工表
-- ----------------------------
DROP TABLE IF EXISTS `employee_table`;
CREATE TABLE `employee_table`  (
  `id` bigint(20) NOT NULL COMMENT '主键',
  `employee_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '雇员名称',
  `department_id` bigint(20) NOT NULL COMMENT '部门id',
  `create_user` bigint(20) NULL DEFAULT NULL COMMENT '创建人',
  `create_dept` bigint(20) NULL DEFAULT NULL COMMENT '创建部门',
  `create_time` timestamp(0) NULL DEFAULT NULL COMMENT '创建时间',
  `update_user` bigint(20) NULL DEFAULT NULL COMMENT '更新人',
  `update_time` timestamp(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新时间',
  `status` tinyint(4) NULL DEFAULT NULL COMMENT '业务状态',
  `is_deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否已删除(0:未删除; 1:已删除)',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '雇员表' ROW_FORMAT = Dynamic;

SET FOREIGN_KEY_CHECKS = 1;

Guess you like

Origin blog.csdn.net/weixin_44188105/article/details/131856854