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,6 +84,7 @@ public class ModuleController {
84 84
                 module.getModulename(),"应用名称",2,
85 85
                 module.getMinout(),"应用分类",1,
86 86
                 module.getMclass(),"应用分组",1,
87
+                module.getSchoolid(),"学校id",1,
87 88
                 module.getModuletype(),"模块归属",1
88 89
         });
89 90
         int result = moduleService.add(module);

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

@@ -61,4 +61,7 @@ public interface ModuleMapper extends TkMapper<TModule> {
61 61
 
62 62
     //修改模块状态
63 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,6 +20,9 @@ public class TRole extends BaseBean {
20 20
     //角色名称
21 21
     private String rolename;
22 22
 
23
+    //角色类型0管理员1其他角色
24
+    private Integer roletype;
25
+
23 26
     //角色备注
24 27
     private String comm;
25 28
 

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

@@ -1,12 +1,15 @@
1 1
 package com.xhkjedu.sapi.service.system;
2 2
 
3 3
 import com.xhkjedu.sapi.mapper.system.ModuleMapper;
4
+import com.xhkjedu.sapi.mapper.system.RoleModuleMapper;
4 5
 import com.xhkjedu.sapi.model.system.TModule;
6
+import com.xhkjedu.sapi.model.system.TRoleModule;
5 7
 import com.xhkjedu.sapi.utils.ApiUtil;
6 8
 import com.xhkjedu.sapi.vo.system.ModuleSelVo;
7 9
 import com.xhkjedu.utils.N_Utils;
8 10
 import org.springframework.beans.factory.annotation.Autowired;
9 11
 import org.springframework.stereotype.Service;
12
+import org.springframework.transaction.annotation.Transactional;
10 13
 
11 14
 import java.util.ArrayList;
12 15
 import java.util.List;
@@ -22,6 +25,8 @@ import java.util.Map;
22 25
 public class ModuleService {
23 26
     @Autowired
24 27
     private ModuleMapper moduleMapper;
28
+    @Autowired
29
+    private RoleModuleMapper roleModuleMapper;
25 30
 
26 31
     /**
27 32
      *功能描述 添加
@@ -30,11 +35,25 @@ public class ModuleService {
30 35
      * @param  * @param module
31 36
      * @return java.lang.Integer
32 37
      */
38
+    @Transactional(rollbackFor = Exception.class)
33 39
     public Integer add(TModule module){
34 40
         String id = ApiUtil.getId();
35 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,6 +130,7 @@ public class SchoolService {
130 130
         role.setCreateid(userid);
131 131
         role.setCreatetime(N_Utils.getSecondTimestamp());
132 132
         role.setSchoolid(schoolid);
133
+        role.setRoletype(0);
133 134
         roleMapper.insertUseGeneratedKeys(role);
134 135
         return role.getId();
135 136
     }

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

@@ -79,4 +79,8 @@
79 79
     <update id="updateModuleDisplay">
80 80
         update t_module set display=#{display} where moduleid=#{moduleid}
81 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 86
 </mapper>

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

@@ -33,4 +33,7 @@ public interface RoleMapper extends TkMapper<TRole> {
33 33
      * @return RoleVo
34 34
      */
35 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,6 +20,9 @@ public class TRole extends BaseBean {
20 20
     //角色名称
21 21
     private String rolename;
22 22
 
23
+    //角色类型0管理员1其他角色
24
+    private Integer roletype;
25
+
23 26
     //角色备注
24 27
     private String comm;
25 28
 

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

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

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

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

Loading…
Cancel
Save