dingxin 6 年前
父节点
当前提交
c4b673f766

+ 17
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/RoleController.java 查看文件

@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
4 4
 import com.community.commom.mode.ResponseBean;
5 5
 import com.community.commom.session.UserElement;
6 6
 import com.community.huiju.common.base.BaseController;
7
+import com.community.huiju.model.SysMenu;
8
+import com.community.huiju.model.SysRole;
7 9
 import com.community.huiju.service.RoleServiceI;
8 10
 import io.swagger.annotations.Api;
9 11
 import io.swagger.annotations.ApiImplicitParam;
@@ -11,6 +13,7 @@ import io.swagger.annotations.ApiImplicitParams;
11 13
 import io.swagger.annotations.ApiOperation;
12 14
 import org.springframework.beans.factory.annotation.Autowired;
13 15
 import org.springframework.cloud.context.config.annotation.RefreshScope;
16
+import org.springframework.web.bind.annotation.RequestBody;
14 17
 import org.springframework.web.bind.annotation.RequestMapping;
15 18
 import org.springframework.web.bind.annotation.RequestMethod;
16 19
 import org.springframework.web.bind.annotation.RequestParam;
@@ -47,4 +50,18 @@ public class RoleController extends BaseController {
47 50
 		responseBean = roleService.getRoleList(roleName,userElement,pageNum,pageSize);
48 51
 		return responseBean;
49 52
 	}
53
+	
54
+	@ApiOperation(value = "添加角色", notes = "添加角色")
55
+	@ApiImplicitParams({
56
+			@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token"),
57
+			@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "Login-Type", value = "值为 web"),
58
+			@ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "sysRole", value = "roleName角色名称;description角色描述;menuArray菜单id集合")
59
+	})
60
+	@RequestMapping(value = "/role/add", method = RequestMethod.POST)
61
+	public ResponseBean addRole(@RequestBody SysRole sysRole, HttpSession session) {
62
+		ResponseBean responseBean = new ResponseBean();
63
+		UserElement userElement = getUserElement(session);
64
+		responseBean = roleService.addRole(sysRole, userElement);
65
+		return responseBean;
66
+	}
50 67
 }

+ 4
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/SysMenuController.java 查看文件

@@ -4,6 +4,7 @@ package com.community.huiju.controller;
4 4
 import com.community.commom.mode.ResponseBean;
5 5
 import com.community.commom.session.UserElement;
6 6
 import com.community.huiju.common.base.BaseController;
7
+import com.community.huiju.model.SysMenu;
7 8
 import com.community.huiju.service.ISysMenuService;
8 9
 import io.swagger.annotations.Api;
9 10
 import io.swagger.annotations.ApiImplicitParam;
@@ -11,6 +12,7 @@ import io.swagger.annotations.ApiImplicitParams;
11 12
 import io.swagger.annotations.ApiOperation;
12 13
 import org.springframework.beans.factory.annotation.Autowired;
13 14
 import org.springframework.cloud.context.config.annotation.RefreshScope;
15
+import org.springframework.web.bind.annotation.RequestBody;
14 16
 import org.springframework.web.bind.annotation.RequestMapping;
15 17
 import org.springframework.web.bind.annotation.RequestMethod;
16 18
 import org.springframework.web.bind.annotation.RequestParam;
@@ -37,6 +39,8 @@ public class SysMenuController extends BaseController {
37 39
 	
38 40
 	@ApiOperation(value = "根据搜索条件获取菜单列表", notes = "根据搜索条件获取菜单列表")
39 41
 	@ApiImplicitParams({
42
+			@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token"),
43
+			@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "Login-Type", value = "值为 web"),
40 44
 	})
41 45
 	@RequestMapping(value = "/menus",method = RequestMethod.GET)
42 46
 	public ResponseBean getInfo(HttpSession session) {

+ 19
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/SysRoleMenuMapper.java 查看文件

@@ -0,0 +1,19 @@
1
+package com.community.huiju.dao;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.community.huiju.model.SysRoleMenu;
5
+
6
+import java.util.List;
7
+
8
+/**
9
+ * <p>
10
+ * 物业端角色可查看的菜单 Mapper 接口
11
+ * </p>
12
+ *
13
+ * @author jobob
14
+ * @since 2019-01-18
15
+ */
16
+public interface SysRoleMenuMapper extends BaseMapper<SysRoleMenu> {
17
+	
18
+	int insertList(List<SysRoleMenu> sysRoleMenuList);
19
+}

+ 2
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/model/SysMenu.java 查看文件

@@ -1,5 +1,6 @@
1 1
 package com.community.huiju.model;
2 2
 
3
+import com.baomidou.mybatisplus.annotation.TableField;
3 4
 import com.baomidou.mybatisplus.annotation.TableName;
4 5
 import lombok.Data;
5 6
 import lombok.EqualsAndHashCode;
@@ -68,5 +69,6 @@ public class SysMenu implements Serializable {
68 69
     /**
69 70
      * 子节点
70 71
      */
72
+    @TableField(exist = false)
71 73
     private List<SysMenu> children;
72 74
 }

+ 9
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/model/SysRole.java 查看文件

@@ -1,5 +1,6 @@
1 1
 package com.community.huiju.model;
2 2
 
3
+import com.baomidou.mybatisplus.annotation.TableField;
3 4
 import com.baomidou.mybatisplus.annotation.TableName;
4 5
 import lombok.Data;
5 6
 import lombok.EqualsAndHashCode;
@@ -7,6 +8,7 @@ import lombok.experimental.Accessors;
7 8
 
8 9
 import java.io.Serializable;
9 10
 import java.time.LocalDateTime;
11
+import java.util.List;
10 12
 
11 13
 /**
12 14
  * <p>
@@ -24,6 +26,7 @@ public class SysRole implements Serializable {
24 26
 
25 27
     private static final long serialVersionUID = 1L;
26 28
 
29
+    private Integer id;
27 30
     /**
28 31
      * 小区id
29 32
      */
@@ -68,4 +71,10 @@ public class SysRole implements Serializable {
68 71
      * 更新人
69 72
      */
70 73
     private String updateName;
74
+    
75
+    /**
76
+     * 前端的menuId
77
+     */
78
+    @TableField(exist = false)
79
+    private List<Integer> menuArray;
71 80
 }

+ 39
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/model/SysRoleMenu.java 查看文件

@@ -0,0 +1,39 @@
1
+package com.community.huiju.model;
2
+
3
+import com.baomidou.mybatisplus.annotation.TableName;
4
+import lombok.Data;
5
+import lombok.EqualsAndHashCode;
6
+import lombok.experimental.Accessors;
7
+
8
+import java.io.Serializable;
9
+
10
+/**
11
+ * <p>
12
+ * 物业端角色可查看的菜单
13
+ * </p>
14
+ *
15
+ * @author jobob
16
+ * @since 2019-01-18
17
+ */
18
+@Data
19
+@EqualsAndHashCode(callSuper = false)
20
+@Accessors(chain = true)
21
+@TableName("tp_sys_role_menu")
22
+public class SysRoleMenu implements Serializable {
23
+
24
+    private static final long serialVersionUID = 1L;
25
+
26
+    private Integer communityId;
27
+
28
+    /**
29
+     * 角色ID
30
+     */
31
+    private Integer roleId;
32
+
33
+    /**
34
+     * 菜单ID
35
+     */
36
+    private Integer menuId;
37
+
38
+
39
+}

+ 8
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/RoleServiceI.java 查看文件

@@ -16,4 +16,12 @@ public interface RoleServiceI extends IService<SysRole> {
16 16
 	 * @return
17 17
 	 */
18 18
 	ResponseBean getRoleList(String roleName, UserElement userElement, Integer pageNum, Integer pageSize);
19
+	
20
+	/**
21
+	 * 添加角色
22
+	 * @param sysRole
23
+	 * @param userElement
24
+	 * @return
25
+	 */
26
+	ResponseBean addRole(SysRole sysRole, UserElement userElement);
19 27
 }

+ 50
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/RoleServiceImpl.java 查看文件

@@ -6,7 +6,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
6 6
 import com.community.commom.mode.ResponseBean;
7 7
 import com.community.commom.session.UserElement;
8 8
 import com.community.huiju.dao.RoleMapper;
9
+import com.community.huiju.dao.SysRoleMenuMapper;
9 10
 import com.community.huiju.model.SysRole;
11
+import com.community.huiju.model.SysRoleMenu;
10 12
 import com.community.huiju.model.TpTransaction;
11 13
 import com.community.huiju.service.RoleServiceI;
12 14
 import com.google.common.collect.Maps;
@@ -14,6 +16,8 @@ import lombok.extern.slf4j.Slf4j;
14 16
 import org.springframework.beans.factory.annotation.Autowired;
15 17
 import org.springframework.stereotype.Service;
16 18
 
19
+import java.time.LocalDateTime;
20
+import java.util.ArrayList;
17 21
 import java.util.List;
18 22
 import java.util.Map;
19 23
 
@@ -27,6 +31,9 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, SysRole> implements
27 31
 	
28 32
 	@Autowired
29 33
 	private RoleMapper roleMapper;
34
+	
35
+	@Autowired
36
+	private SysRoleMenuMapper sysRoleMenuMapper;
30 37
 	/**
31 38
 	 * 获取角色列表
32 39
 	 *
@@ -51,4 +58,47 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, SysRole> implements
51 58
 		responseBean.addSuccess(map);
52 59
 		return responseBean;
53 60
 	}
61
+	
62
+	/**
63
+	 * 添加角色
64
+	 *
65
+	 * @param sysRole
66
+	 * @param userElement
67
+	 * @return
68
+	 */
69
+	@Override
70
+	public ResponseBean addRole(SysRole sysRole, UserElement userElement) {
71
+		ResponseBean responseBean = new ResponseBean();
72
+		//接收数据
73
+		sysRole.setCommunityId(userElement.getCommunityId());
74
+		Integer userId = userElement.getId();
75
+		LocalDateTime dateTime = LocalDateTime.now();
76
+		sysRole.setCreateUser(userId);
77
+		sysRole.setCreateDate(dateTime);
78
+		sysRole.setUpdateUser(userId);
79
+		sysRole.setUpdateDate(dateTime);
80
+		//插入角色表
81
+		int size = roleMapper.insert(sysRole);
82
+		if (size < 1){
83
+			responseBean.addError("插入失败");
84
+			return responseBean;
85
+		}
86
+		//维护角色与menu的关系表
87
+		List<SysRoleMenu> sysRoleMenuList = new ArrayList<SysRoleMenu>();
88
+		List<Integer> menuIdList = sysRole.getMenuArray();
89
+		menuIdList.stream().forEach(menuId -> {
90
+			SysRoleMenu sysRoleMenu = new SysRoleMenu();
91
+			sysRoleMenu.setCommunityId(userElement.getCommunityId());
92
+			sysRoleMenu.setRoleId(sysRole.getId());
93
+			sysRoleMenu.setMenuId(menuId);
94
+			sysRoleMenuList.add(sysRoleMenu);
95
+		});
96
+		int count = sysRoleMenuMapper.insertList(sysRoleMenuList);
97
+		if (count < 1){
98
+			responseBean.addError("插入失败");
99
+			return responseBean;
100
+		}
101
+		responseBean.addSuccess(size);
102
+		return responseBean;
103
+	}
54 104
 }

+ 3
- 1
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/SysMenuServiceImpl.java 查看文件

@@ -9,6 +9,7 @@ import com.community.huiju.model.SysMenu;
9 9
 import com.community.huiju.service.ISysMenuService;
10 10
 import org.springframework.beans.factory.annotation.Autowired;
11 11
 import org.springframework.stereotype.Service;
12
+import org.springframework.transaction.annotation.Transactional;
12 13
 
13 14
 import java.util.ArrayList;
14 15
 import java.util.List;
@@ -22,6 +23,7 @@ import java.util.List;
22 23
  * @since 2019-01-17
23 24
  */
24 25
 @Service
26
+@Transactional(rollbackFor = Exception.class)
25 27
 public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {
26 28
 	
27 29
 	@Autowired
@@ -39,7 +41,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
39 41
 		List<SysMenu> menuList = new ArrayList<SysMenu>();
40 42
 		sysMenuList.stream().forEach(sysMenu -> {
41 43
 			//父节点是0的,为根节点。
42
-			if(sysMenu.getParentId().equals("0")){
44
+			if(sysMenu.getParentId().equals(0)){
43 45
 				menuList.add(sysMenu);
44 46
 			}
45 47
 		});

+ 12
- 0
CODE/smart-community/property-api/src/main/resources/mapper/SysRoleMenuMapper.xml 查看文件

@@ -0,0 +1,12 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.community.huiju.dao.SysRoleMenuMapper">
4
+
5
+    <insert id="insertList" useGeneratedKeys="true" keyProperty="id" parameterType="java.util.ArrayList">
6
+        insert into tp_sys_role_menu(community_id,role_id,menu_id)
7
+        VALUES
8
+        <foreach collection="list" item="item" index="index" separator=",">
9
+            (#{item.communityId},#{item.roleId},#{item.menuId})
10
+        </foreach>
11
+    </insert>
12
+</mapper>

+ 13
- 0
VUECODE/smart-property-manage/src/api/role.js 查看文件

@@ -14,3 +14,16 @@ export function fetchMenuList() {
14 14
     method: 'get'
15 15
   })
16 16
 }
17
+
18
+export function addMenuInfo(data) {
19
+  return request({
20
+    url: '/role/add',
21
+    method: 'post',
22
+    data: {
23
+      roleName: data.roleName,
24
+      description: data.description,
25
+      menuArray: data.menuArray
26
+    }
27
+  })
28
+}
29
+

+ 21
- 13
VUECODE/smart-property-manage/src/store/modules/role.js 查看文件

@@ -1,4 +1,4 @@
1
-import { fetchList, fetchMenuList } from '@/api/role'
1
+import { fetchList, fetchMenuList, addMenuInfo } from '@/api/role'
2 2
 
3 3
 const transaction = {
4 4
   namespaced: true,
@@ -33,19 +33,27 @@ const transaction = {
33 33
           reject(error)
34 34
         })
35 35
       })
36
-    }
37
-  },
38
-  FetchMenuList({ commit }) {
39
-    console.log(1)
40
-    return new Promise((resolve, reject) => {
41
-      fetchMenuList().then(response => {
42
-        const data = response.data
43
-        commit('SET_MENU_LIST', data)
44
-        resolve()
45
-      }).catch(error => {
46
-        reject(error)
36
+    },
37
+    FetchMenuList({ commit }) {
38
+      return new Promise((resolve, reject) => {
39
+        fetchMenuList().then(response => {
40
+          const data = response.data
41
+          commit('SET_MENU_LIST', data)
42
+          resolve()
43
+        }).catch(error => {
44
+          reject(error)
45
+        })
46
+      })
47
+    },
48
+    AddMenuInfo({ commit }, listQuery) {
49
+      return new Promise((resolve, reject) => {
50
+        addMenuInfo(listQuery).then(response => {
51
+          resolve(response)
52
+        }).catch(error => {
53
+          reject(error)
54
+        })
47 55
       })
48
-    })
56
+    }
49 57
   }
50 58
 }
51 59
 

+ 30
- 24
VUECODE/smart-property-manage/src/views/account/add/role-add.vue 查看文件

@@ -1,18 +1,21 @@
1 1
 <template>
2 2
   <div class="root">
3 3
     <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="add-ruleForm">
4
-      <el-form-item label="角色名称" prop="phase">
5
-        <el-input v-model="ruleForm.phase"/>
4
+      <el-form-item label="角色名称" prop="roleName">
5
+        <el-input v-model="ruleForm.roleName"/>
6 6
       </el-form-item>
7
-      <el-form-item label="角色描述" prop="building">
8
-        <el-input v-model="ruleForm.building"/>
7
+      <el-form-item label="角色描述" prop="description">
8
+        <el-input v-model="ruleForm.description"/>
9 9
       </el-form-item>
10
-      <el-tree
11
-        :data="menuList"
12
-        show-checkbox
13
-        node-key="id"
14
-        :props="defaultProps">
15
-      </el-tree>
10
+      <el-form-item label="资源权限" prop="menuArray">
11
+        <el-tree
12
+          ref="tree"
13
+          :data="menuList"
14
+          show-checkbox
15
+          node-key="id"
16
+          :props="defaultProps">
17
+        </el-tree>
18
+      </el-form-item> 
16 19
       <el-form-item>
17 20
         <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
18 21
         <el-button @click="resetForm('ruleForm')">重置</el-button>
@@ -35,17 +38,16 @@ export default {
35 38
   data() {
36 39
     return {
37 40
       ruleForm: {
38
-        phase: '',
39
-        building: '',
40
-        unit: '',
41
-        level: '',
42
-        roomNo: '',
43
-        ownerName: '',
44
-        ownerTel: ''
41
+        roleName: '',
42
+        description: '',
43
+        menuArray: []
45 44
       },
46 45
       rules: {
47
-        phase: [
46
+        roleName: [
48 47
           { required: true, message: '请输入角色名称', trigger: 'blur' }
48
+        ],
49
+        menuArray: [
50
+          { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
49 51
         ]
50 52
       },
51 53
       defaultProps: {
@@ -61,12 +63,16 @@ export default {
61 63
     ...mapMutations('role', {
62 64
     }),
63 65
     ...mapActions('role', [
64
-      'FetchMenuList'
66
+      'FetchMenuList',
67
+      'AddMenuInfo'
65 68
     ]),
66 69
     submitForm(formName) { // 提交
70
+      // 获取选中的树形节点 key
71
+      this.ruleForm.menuArray = this.$refs.tree.getCheckedKeys()
72
+      console.log(this.ruleForm.menuArray)
67 73
       this.$refs[formName].validate((valid) => {
68 74
         if (valid) {
69
-          this.addBuilding()
75
+          this.addRole()
70 76
         } else {
71 77
           console.log('error submit!!')
72 78
           return false
@@ -82,7 +88,7 @@ export default {
82 88
     resetForm(formName) { // 重置
83 89
       this.$refs[formName].resetFields()
84 90
     },
85
-    addBuilding() {
91
+    addRole() {
86 92
       // 加载框
87 93
       const loading = this.$loading({
88 94
         lock: true,
@@ -90,13 +96,13 @@ export default {
90 96
         spinner: 'el-icon-loading',
91 97
         background: 'rgba(0, 0, 0, 0.7)'
92 98
       })
93
-      this.$store.dispatch('AddBuilding', this.ruleForm).then((res) => {
99
+      this.AddMenuInfo(this.ruleForm).then((res) => {
94 100
         if (res.code === '0') {
95 101
           this.$message({
96 102
             message: res.message,
97 103
             type: 'success'
98 104
           })
99
-          this.$router.push({ name: 'building-index' })
105
+          this.$router.push({ name: 'role-index' })
100 106
           loading.close()
101 107
           return
102 108
         }
@@ -104,7 +110,7 @@ export default {
104 110
         loading.close()
105 111
       }).catch(() => {
106 112
         loading.close()
107
-        console.log('error AddBuilding')
113
+        console.log('error addRole')
108 114
       })
109 115
     }
110 116
   }