Browse Source

角色管理添加角色类型 模块添加时自动给管理员角色添上对应模块

tags/正式版本
雍文秀 2 years ago
parent
commit
08908e64e1

+ 1
- 0
sapi/src/main/java/com/xhkjedu/sapi/controller/system/ModuleController.java View File

84
                 module.getModulename(),"应用名称",2,
84
                 module.getModulename(),"应用名称",2,
85
                 module.getMinout(),"应用分类",1,
85
                 module.getMinout(),"应用分类",1,
86
                 module.getMclass(),"应用分组",1,
86
                 module.getMclass(),"应用分组",1,
87
+                module.getSchoolid(),"学校id",1,
87
                 module.getModuletype(),"模块归属",1
88
                 module.getModuletype(),"模块归属",1
88
         });
89
         });
89
         int result = moduleService.add(module);
90
         int result = moduleService.add(module);

+ 3
- 0
sapi/src/main/java/com/xhkjedu/sapi/mapper/system/ModuleMapper.java View File

61
 
61
 
62
     //修改模块状态
62
     //修改模块状态
63
     void updateModuleDisplay(@Param("moduleid") String moduleid, @Param("display") Integer display);
63
     void updateModuleDisplay(@Param("moduleid") String moduleid, @Param("display") Integer display);
64
+
65
+    //根据学校id获取管理员角色id
66
+    Integer getRoleIdBySchoolId(@Param("schoolid") Integer schoolid);
64
 }
67
 }

+ 3
- 0
sapi/src/main/java/com/xhkjedu/sapi/model/system/TRole.java View File

20
     //角色名称
20
     //角色名称
21
     private String rolename;
21
     private String rolename;
22
 
22
 
23
+    //角色类型0管理员1其他角色
24
+    private Integer roletype;
25
+
23
     //角色备注
26
     //角色备注
24
     private String comm;
27
     private String comm;
25
 
28
 

+ 21
- 2
sapi/src/main/java/com/xhkjedu/sapi/service/system/ModuleService.java View File

1
 package com.xhkjedu.sapi.service.system;
1
 package com.xhkjedu.sapi.service.system;
2
 
2
 
3
 import com.xhkjedu.sapi.mapper.system.ModuleMapper;
3
 import com.xhkjedu.sapi.mapper.system.ModuleMapper;
4
+import com.xhkjedu.sapi.mapper.system.RoleModuleMapper;
4
 import com.xhkjedu.sapi.model.system.TModule;
5
 import com.xhkjedu.sapi.model.system.TModule;
6
+import com.xhkjedu.sapi.model.system.TRoleModule;
5
 import com.xhkjedu.sapi.utils.ApiUtil;
7
 import com.xhkjedu.sapi.utils.ApiUtil;
6
 import com.xhkjedu.sapi.vo.system.ModuleSelVo;
8
 import com.xhkjedu.sapi.vo.system.ModuleSelVo;
7
 import com.xhkjedu.utils.N_Utils;
9
 import com.xhkjedu.utils.N_Utils;
8
 import org.springframework.beans.factory.annotation.Autowired;
10
 import org.springframework.beans.factory.annotation.Autowired;
9
 import org.springframework.stereotype.Service;
11
 import org.springframework.stereotype.Service;
12
+import org.springframework.transaction.annotation.Transactional;
10
 
13
 
11
 import java.util.ArrayList;
14
 import java.util.ArrayList;
12
 import java.util.List;
15
 import java.util.List;
22
 public class ModuleService {
25
 public class ModuleService {
23
     @Autowired
26
     @Autowired
24
     private ModuleMapper moduleMapper;
27
     private ModuleMapper moduleMapper;
28
+    @Autowired
29
+    private RoleModuleMapper roleModuleMapper;
25
 
30
 
26
     /**
31
     /**
27
      *功能描述 添加
32
      *功能描述 添加
30
      * @param  * @param module
35
      * @param  * @param module
31
      * @return java.lang.Integer
36
      * @return java.lang.Integer
32
      */
37
      */
38
+    @Transactional(rollbackFor = Exception.class)
33
     public Integer add(TModule module){
39
     public Integer add(TModule module){
34
         String id = ApiUtil.getId();
40
         String id = ApiUtil.getId();
35
         module.setModuleid(id);
41
         module.setModuleid(id);
36
-        module.setCreatetime(N_Utils.getSecondTimestamp());
37
-        return moduleMapper.insertSelective(module);
42
+        int timestamp = N_Utils.getSecondTimestamp();
43
+        module.setCreatetime(timestamp);
44
+        int result = moduleMapper.insertSelective(module);
45
+        Integer schoolid = module.getSchoolid();
46
+        Integer createid = module.getCreateid();
47
+        Integer roleid=moduleMapper.getRoleIdBySchoolId(schoolid);//根据学校id获取管理员角色id
48
+        //角色模块
49
+        TRoleModule rm=new TRoleModule();
50
+        rm.setRoleid(roleid);
51
+        rm.setModuleid(id);
52
+        rm.setCreateid(createid);
53
+        rm.setCreatetime(timestamp);
54
+        rm.setSchoolid(schoolid);
55
+        roleModuleMapper.insertSelective(rm);
56
+        return result;
38
     }
57
     }
39
 
58
 
40
     /**
59
     /**

+ 1
- 0
sapi/src/main/java/com/xhkjedu/sapi/service/system/SchoolService.java View File

130
         role.setCreateid(userid);
130
         role.setCreateid(userid);
131
         role.setCreatetime(N_Utils.getSecondTimestamp());
131
         role.setCreatetime(N_Utils.getSecondTimestamp());
132
         role.setSchoolid(schoolid);
132
         role.setSchoolid(schoolid);
133
+        role.setRoletype(0);
133
         roleMapper.insertUseGeneratedKeys(role);
134
         roleMapper.insertUseGeneratedKeys(role);
134
         return role.getId();
135
         return role.getId();
135
     }
136
     }

+ 4
- 0
sapi/src/main/resources/mapper/system/ModuleMapper.xml View File

79
     <update id="updateModuleDisplay">
79
     <update id="updateModuleDisplay">
80
         update t_module set display=#{display} where moduleid=#{moduleid}
80
         update t_module set display=#{display} where moduleid=#{moduleid}
81
     </update>
81
     </update>
82
+    <!--根据学校id获取管理员角色id-->
83
+    <select id="getRoleIdBySchoolId" resultType="java.lang.Integer">
84
+        select roleid from t_role where schoolid=#{schoolid} and roletype=0 limit 1
85
+    </select>
82
 </mapper>
86
 </mapper>

+ 3
- 0
suser/src/main/java/com/xhkjedu/suser/mapper/system/RoleMapper.java View File

33
      * @return RoleVo
33
      * @return RoleVo
34
      */
34
      */
35
     RoleVo getRoleDetail(@Param("roleid")Integer roleid);
35
     RoleVo getRoleDetail(@Param("roleid")Integer roleid);
36
+
37
+    //根据角色id获取角色类型
38
+    Integer getTypeById(@Param("roleid") Integer roleid);
36
 }
39
 }

+ 3
- 0
suser/src/main/java/com/xhkjedu/suser/model/system/TRole.java View File

20
     //角色名称
20
     //角色名称
21
     private String rolename;
21
     private String rolename;
22
 
22
 
23
+    //角色类型0管理员1其他角色
24
+    private Integer roletype;
25
+
23
     //角色备注
26
     //角色备注
24
     private String comm;
27
     private String comm;
25
 
28
 

+ 5
- 0
suser/src/main/java/com/xhkjedu/suser/service/system/RoleService.java View File

1
 package com.xhkjedu.suser.service.system;
1
 package com.xhkjedu.suser.service.system;
2
 
2
 
3
+import com.xhkjedu.config.MissingParametersException;
3
 import com.xhkjedu.suser.mapper.system.RoleMapper;
4
 import com.xhkjedu.suser.mapper.system.RoleMapper;
4
 import com.xhkjedu.suser.mapper.system.RoleModuleMapper;
5
 import com.xhkjedu.suser.mapper.system.RoleModuleMapper;
5
 import com.xhkjedu.suser.mapper.system.UserRoleMapper;
6
 import com.xhkjedu.suser.mapper.system.UserRoleMapper;
40
     public Integer save(TRole role) throws Exception {
41
     public Integer save(TRole role) throws Exception {
41
         try {
42
         try {
42
             role.setCreatetime(N_Utils.getSecondTimestamp());
43
             role.setCreatetime(N_Utils.getSecondTimestamp());
44
+            role.setRoletype(1);
43
             //保存角色信息
45
             //保存角色信息
44
             roleMapper.insertUseGeneratedKeys(role);
46
             roleMapper.insertUseGeneratedKeys(role);
45
             role.setRoleid(role.getId());
47
             role.setRoleid(role.getId());
97
                 saveRoleModules(role.getModules(),role);
99
                 saveRoleModules(role.getModules(),role);
98
             }
100
             }
99
             deleteNoRoleUserModule(role.getRoleid());//删除没有权限的用户常用模块
101
             deleteNoRoleUserModule(role.getRoleid());//删除没有权限的用户常用模块
102
+            role.setRoletype(null);
100
             return roleMapper.updateByPrimaryKeySelective(role);
103
             return roleMapper.updateByPrimaryKeySelective(role);
101
         } catch (Exception e) {
104
         } catch (Exception e) {
102
             log.error("教师修改失败:"+e.getMessage());
105
             log.error("教师修改失败:"+e.getMessage());
119
 
122
 
120
     //删除
123
     //删除
121
     public Integer del(Integer roleid){
124
     public Integer del(Integer roleid){
125
+        Integer roletype = roleMapper.getTypeById(roleid);//根据角色id获取角色类型
126
+        if (roletype == 0) throw new MissingParametersException("管理员角色禁止删除");
122
         Integer result = roleMapper.deleteByPrimaryKey(roleid);
127
         Integer result = roleMapper.deleteByPrimaryKey(roleid);
123
         deleteNoRoleUserModule(roleid);//删除没有权限的用户常用模块
128
         deleteNoRoleUserModule(roleid);//删除没有权限的用户常用模块
124
         return result;
129
         return result;

+ 5
- 1
suser/src/main/resources/mapper/system/RoleMapper.xml View File

3
 <mapper namespace="com.xhkjedu.suser.mapper.system.RoleMapper">
3
 <mapper namespace="com.xhkjedu.suser.mapper.system.RoleMapper">
4
     <!-- 获取所有角色 -->
4
     <!-- 获取所有角色 -->
5
     <select id="listAllRoles" resultType="com.xhkjedu.suser.model.system.TRole">
5
     <select id="listAllRoles" resultType="com.xhkjedu.suser.model.system.TRole">
6
-        SELECT r.roleid,r.rolename,r.comm,r.createid,r.createtime,u.username AS createname,
6
+        SELECT r.roleid,r.rolename,r.roletype,r.comm,r.createid,r.createtime,u.username AS createname,
7
         (SELECT COUNT(*) FROM t_user_role ur WHERE ur.roleid=r.roleid) AS usernum
7
         (SELECT COUNT(*) FROM t_user_role ur WHERE ur.roleid=r.roleid) AS usernum
8
         FROM t_role r LEFT JOIN t_user u ON r.createid = u.userid
8
         FROM t_role r LEFT JOIN t_user u ON r.createid = u.userid
9
         WHERE r.schoolid=#{schoolid} ORDER BY createtime desc
9
         WHERE r.schoolid=#{schoolid} ORDER BY createtime desc
14
         SELECT r.roleid,r.rolename,r.comm from t_role r
14
         SELECT r.roleid,r.rolename,r.comm from t_role r
15
         WHERE r.roleid=#{roleid} limit 1
15
         WHERE r.roleid=#{roleid} limit 1
16
     </select>
16
     </select>
17
+    <!--根据角色id获取角色类型-->
18
+    <select id="getTypeById" resultType="java.lang.Integer">
19
+        select roletype from t_role where roleid=#{roleid}
20
+    </select>
17
 </mapper>
21
 </mapper>

Loading…
Cancel
Save