diff --git a/sql/ry_20180801.sql b/sql/ry_20180808.sql similarity index 94% rename from sql/ry_20180801.sql rename to sql/ry_20180808.sql index d692d077..66e400dc 100644 --- a/sql/ry_20180801.sql +++ b/sql/ry_20180808.sql @@ -5,6 +5,7 @@ drop table if exists sys_dept; create table sys_dept ( dept_id int(11) not null auto_increment comment '部门id', parent_id int(11) default 0 comment '父部门id', + ancestors varchar(50) default '' comment '祖级列表', dept_name varchar(30) default '' comment '部门名称', order_num int(4) default 0 comment '显示顺序', leader varchar(20) default '' comment '负责人', @@ -21,16 +22,16 @@ create table sys_dept ( -- ---------------------------- -- 初始化-部门表数据 -- ---------------------------- -insert into sys_dept values(100, 0, '若依集团', 0, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); -insert into sys_dept values(101, 100, '研发部门', 1, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); -insert into sys_dept values(102, 100, '市场部门', 2, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); -insert into sys_dept values(103, 100, '测试部门', 3, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); -insert into sys_dept values(104, 100, '财务部门', 4, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); -insert into sys_dept values(105, 100, '运维部门', 5, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); -insert into sys_dept values(106, 101, '研发一部', 1, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); -insert into sys_dept values(107, 101, '研发二部', 2, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); -insert into sys_dept values(108, 102, '市场一部', 1, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); -insert into sys_dept values(109, 102, '市场二部', 2, '若依', '15888888888', 'ry@qq.com', '1', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); +insert into sys_dept values(100, 0, '0', '若依集团', 0, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); +insert into sys_dept values(101, 100, '0,100', '研发部门', 1, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); +insert into sys_dept values(102, 100, '0,100', '市场部门', 2, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); +insert into sys_dept values(103, 100, '0,100', '测试部门', 3, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); +insert into sys_dept values(104, 100, '0,100', '财务部门', 4, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); +insert into sys_dept values(105, 100, '0,100', '运维部门', 5, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); +insert into sys_dept values(106, 101, '0,100,101', '研发一部', 1, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); +insert into sys_dept values(107, 101, '0,100,101', '研发二部', 2, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); +insert into sys_dept values(108, 102, '0,100,102', '市场一部', 1, '若依', '15888888888', 'ry@qq.com', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); +insert into sys_dept values(109, 102, '0,100,102', '市场二部', 2, '若依', '15888888888', 'ry@qq.com', '1', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); -- ---------------------------- diff --git a/src/main/java/com/ruoyi/framework/config/ShiroConfig.java b/src/main/java/com/ruoyi/framework/config/ShiroConfig.java index 58b37c3c..866115bb 100644 --- a/src/main/java/com/ruoyi/framework/config/ShiroConfig.java +++ b/src/main/java/com/ruoyi/framework/config/ShiroConfig.java @@ -263,12 +263,7 @@ public class ShiroConfig shiroFilterFactoryBean.setFilters(filters); // 所有请求需要认证 - filterChainDefinitionMap.put("/**", "user"); - // 系统请求记录当前会话 - filterChainDefinitionMap.put("/main", "onlineSession,syncOnlineSession"); - filterChainDefinitionMap.put("/system/**", "onlineSession,syncOnlineSession"); - filterChainDefinitionMap.put("/monitor/**", "onlineSession,syncOnlineSession"); - filterChainDefinitionMap.put("/tool/**", "onlineSession,syncOnlineSession"); + filterChainDefinitionMap.put("/**", "user,onlineSession,syncOnlineSession"); shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); return shiroFilterFactoryBean; diff --git a/src/main/java/com/ruoyi/project/system/dept/domain/Dept.java b/src/main/java/com/ruoyi/project/system/dept/domain/Dept.java index 8096544a..26e74735 100644 --- a/src/main/java/com/ruoyi/project/system/dept/domain/Dept.java +++ b/src/main/java/com/ruoyi/project/system/dept/domain/Dept.java @@ -14,6 +14,8 @@ public class Dept extends BaseEntity private Long deptId; /** 父部门ID */ private Long parentId; + /** 祖级列表 */ + private String ancestors; /** 部门名称 */ private String deptName; /** 显示顺序 */ @@ -49,6 +51,16 @@ public class Dept extends BaseEntity this.parentId = parentId; } + public String getAncestors() + { + return ancestors; + } + + public void setAncestors(String ancestors) + { + this.ancestors = ancestors; + } + public String getDeptName() { return deptName; @@ -122,9 +134,9 @@ public class Dept extends BaseEntity @Override public String toString() { - return "Dept [deptId=" + deptId + ", parentId=" + parentId + ", deptName=" + deptName + ", orderNum=" + orderNum - + ", leader=" + leader + ", phone=" + phone + ", email=" + email + ", status=" + status - + ", parentName=" + parentName + "]"; + return "Dept [deptId=" + deptId + ", parentId=" + parentId + ", ancestors=" + ancestors + ", deptName=" + + deptName + ", orderNum=" + orderNum + ", leader=" + leader + ", phone=" + phone + ", email=" + email + + ", status=" + status + ", parentName=" + parentName + "]"; } } diff --git a/src/main/java/com/ruoyi/project/system/dept/service/DeptServiceImpl.java b/src/main/java/com/ruoyi/project/system/dept/service/DeptServiceImpl.java index 4cea018c..ffde92e2 100644 --- a/src/main/java/com/ruoyi/project/system/dept/service/DeptServiceImpl.java +++ b/src/main/java/com/ruoyi/project/system/dept/service/DeptServiceImpl.java @@ -119,7 +119,9 @@ public class DeptServiceImpl implements IDeptService @Override public int insertDept(Dept dept) { + Dept info = deptMapper.selectDeptById(dept.getParentId()); dept.setCreateBy(ShiroUtils.getLoginName()); + dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); return deptMapper.insertDept(dept); } @@ -132,7 +134,9 @@ public class DeptServiceImpl implements IDeptService @Override public int updateDept(Dept dept) { + Dept info = deptMapper.selectDeptById(dept.getParentId()); dept.setUpdateBy(ShiroUtils.getLoginName()); + dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); return deptMapper.updateDept(dept); } diff --git a/src/main/resources/mybatis/system/DeptMapper.xml b/src/main/resources/mybatis/system/DeptMapper.xml index c9a90e47..a77dbca6 100644 --- a/src/main/resources/mybatis/system/DeptMapper.xml +++ b/src/main/resources/mybatis/system/DeptMapper.xml @@ -7,6 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <resultMap type="Dept" id="DeptResult"> <id property="deptId" column="dept_id" /> <result property="parentId" column="parent_id" /> + <result property="ancestors" column="ancestors" /> <result property="deptName" column="dept_name" /> <result property="orderNum" column="order_num" /> <result property="leader" column="leader" /> @@ -21,7 +22,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" </resultMap> <sql id="selectDeptVo"> - select t.dept_id, t.parent_id, t.dept_name, t.order_num, t.leader, t.phone, t.email, t.status, t.create_by, t.create_time from sys_dept t + select t.dept_id, t.parent_id, t.ancestors, t.dept_name, t.order_num, t.leader, t.phone, t.email, t.status, t.create_by, t.create_time from sys_dept t </sql> <select id="selectDeptAll" resultMap="DeptResult"> @@ -58,7 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" </select> <select id="selectDeptById" parameterType="Long" resultMap="DeptResult"> - select t.dept_id, t.parent_id, t.dept_name, t.order_num, t.leader, t.phone, t.email, t.status, + select t.dept_id, t.parent_id, t.ancestors, t.dept_name, t.order_num, t.leader, t.phone, t.email, t.status, (select dept_name from sys_dept where dept_id = t.parent_id) parent_name from sys_dept t where dept_id = #{deptId} @@ -69,6 +70,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <if test="deptId != null and deptId != 0">dept_id,</if> <if test="parentId != null and parentId != 0">parent_id,</if> <if test="deptName != null and deptName != ''">dept_name,</if> + <if test="ancestors != null and ancestors != ''">ancestors,</if> <if test="orderNum != null and orderNum != ''">order_num,</if> <if test="leader != null and leader != ''">leader,</if> <if test="phone != null and phone != ''">phone,</if> @@ -80,6 +82,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <if test="deptId != null and deptId != 0">#{deptId},</if> <if test="parentId != null and parentId != 0">#{parentId},</if> <if test="deptName != null and deptName != ''">#{deptName},</if> + <if test="ancestors != null and ancestors != ''">#{ancestors},</if> <if test="orderNum != null and orderNum != ''">#{orderNum},</if> <if test="leader != null and leader != ''">#{leader},</if> <if test="phone != null and phone != ''">#{phone},</if> @@ -95,6 +98,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <set> <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if> <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if> + <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if> <if test="orderNum != null and orderNum != ''">order_num = #{orderNum},</if> <if test="leader != null and leader != ''">leader = #{leader},</if> <if test="phone != null and phone != ''">phone = #{phone},</if> diff --git a/src/main/resources/mybatis/system/UserMapper.xml b/src/main/resources/mybatis/system/UserMapper.xml index 67295c25..9825b5cc 100644 --- a/src/main/resources/mybatis/system/UserMapper.xml +++ b/src/main/resources/mybatis/system/UserMapper.xml @@ -62,8 +62,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <if test="params != null and params.endTime != ''"><!-- 结束时间检索 --> AND date_format(u.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') </if> - <if test="deptId != null and parentId != null and parentId != 0"> - AND u.dept_id IN (SELECT t.dept_id FROM sys_dept t WHERE t.dept_id = #{deptId} OR t.parent_id = #{deptId}) + <if test="deptId != null and deptId != 0"> + AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE FIND_IN_SET (#{deptId},ancestors) )) </if> </select> diff --git a/src/main/resources/templates/system/user/user.html b/src/main/resources/templates/system/user/user.html index 367d04a0..376cb188 100644 --- a/src/main/resources/templates/system/user/user.html +++ b/src/main/resources/templates/system/user/user.html @@ -167,7 +167,6 @@ // 树结构初始化加载 var setting = {view:{selectedMulti:false},data:{key:{title:"title"},simpleData:{enable:true}}, callback:{onClick:function(event, treeId, treeNode){ - tree.expandNode(treeNode); $("#deptId").val(treeNode.id); $("#parentId").val(treeNode.pId); $.table.search();