dingxin 6 年之前
父節點
當前提交
c4b673f766

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

4
 import com.community.commom.mode.ResponseBean;
4
 import com.community.commom.mode.ResponseBean;
5
 import com.community.commom.session.UserElement;
5
 import com.community.commom.session.UserElement;
6
 import com.community.huiju.common.base.BaseController;
6
 import com.community.huiju.common.base.BaseController;
7
+import com.community.huiju.model.SysMenu;
8
+import com.community.huiju.model.SysRole;
7
 import com.community.huiju.service.RoleServiceI;
9
 import com.community.huiju.service.RoleServiceI;
8
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.Api;
9
 import io.swagger.annotations.ApiImplicitParam;
11
 import io.swagger.annotations.ApiImplicitParam;
11
 import io.swagger.annotations.ApiOperation;
13
 import io.swagger.annotations.ApiOperation;
12
 import org.springframework.beans.factory.annotation.Autowired;
14
 import org.springframework.beans.factory.annotation.Autowired;
13
 import org.springframework.cloud.context.config.annotation.RefreshScope;
15
 import org.springframework.cloud.context.config.annotation.RefreshScope;
16
+import org.springframework.web.bind.annotation.RequestBody;
14
 import org.springframework.web.bind.annotation.RequestMapping;
17
 import org.springframework.web.bind.annotation.RequestMapping;
15
 import org.springframework.web.bind.annotation.RequestMethod;
18
 import org.springframework.web.bind.annotation.RequestMethod;
16
 import org.springframework.web.bind.annotation.RequestParam;
19
 import org.springframework.web.bind.annotation.RequestParam;
47
 		responseBean = roleService.getRoleList(roleName,userElement,pageNum,pageSize);
50
 		responseBean = roleService.getRoleList(roleName,userElement,pageNum,pageSize);
48
 		return responseBean;
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
 import com.community.commom.mode.ResponseBean;
4
 import com.community.commom.mode.ResponseBean;
5
 import com.community.commom.session.UserElement;
5
 import com.community.commom.session.UserElement;
6
 import com.community.huiju.common.base.BaseController;
6
 import com.community.huiju.common.base.BaseController;
7
+import com.community.huiju.model.SysMenu;
7
 import com.community.huiju.service.ISysMenuService;
8
 import com.community.huiju.service.ISysMenuService;
8
 import io.swagger.annotations.Api;
9
 import io.swagger.annotations.Api;
9
 import io.swagger.annotations.ApiImplicitParam;
10
 import io.swagger.annotations.ApiImplicitParam;
11
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiOperation;
12
 import org.springframework.beans.factory.annotation.Autowired;
13
 import org.springframework.beans.factory.annotation.Autowired;
13
 import org.springframework.cloud.context.config.annotation.RefreshScope;
14
 import org.springframework.cloud.context.config.annotation.RefreshScope;
15
+import org.springframework.web.bind.annotation.RequestBody;
14
 import org.springframework.web.bind.annotation.RequestMapping;
16
 import org.springframework.web.bind.annotation.RequestMapping;
15
 import org.springframework.web.bind.annotation.RequestMethod;
17
 import org.springframework.web.bind.annotation.RequestMethod;
16
 import org.springframework.web.bind.annotation.RequestParam;
18
 import org.springframework.web.bind.annotation.RequestParam;
37
 	
39
 	
38
 	@ApiOperation(value = "根据搜索条件获取菜单列表", notes = "根据搜索条件获取菜单列表")
40
 	@ApiOperation(value = "根据搜索条件获取菜单列表", notes = "根据搜索条件获取菜单列表")
39
 	@ApiImplicitParams({
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
 	@RequestMapping(value = "/menus",method = RequestMethod.GET)
45
 	@RequestMapping(value = "/menus",method = RequestMethod.GET)
42
 	public ResponseBean getInfo(HttpSession session) {
46
 	public ResponseBean getInfo(HttpSession session) {

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

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

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

1
 package com.community.huiju.model;
1
 package com.community.huiju.model;
2
 
2
 
3
+import com.baomidou.mybatisplus.annotation.TableField;
3
 import com.baomidou.mybatisplus.annotation.TableName;
4
 import com.baomidou.mybatisplus.annotation.TableName;
4
 import lombok.Data;
5
 import lombok.Data;
5
 import lombok.EqualsAndHashCode;
6
 import lombok.EqualsAndHashCode;
7
 
8
 
8
 import java.io.Serializable;
9
 import java.io.Serializable;
9
 import java.time.LocalDateTime;
10
 import java.time.LocalDateTime;
11
+import java.util.List;
10
 
12
 
11
 /**
13
 /**
12
  * <p>
14
  * <p>
24
 
26
 
25
     private static final long serialVersionUID = 1L;
27
     private static final long serialVersionUID = 1L;
26
 
28
 
29
+    private Integer id;
27
     /**
30
     /**
28
      * 小区id
31
      * 小区id
29
      */
32
      */
68
      * 更新人
71
      * 更新人
69
      */
72
      */
70
     private String updateName;
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 查看文件

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
 	 * @return
16
 	 * @return
17
 	 */
17
 	 */
18
 	ResponseBean getRoleList(String roleName, UserElement userElement, Integer pageNum, Integer pageSize);
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
 import com.community.commom.mode.ResponseBean;
6
 import com.community.commom.mode.ResponseBean;
7
 import com.community.commom.session.UserElement;
7
 import com.community.commom.session.UserElement;
8
 import com.community.huiju.dao.RoleMapper;
8
 import com.community.huiju.dao.RoleMapper;
9
+import com.community.huiju.dao.SysRoleMenuMapper;
9
 import com.community.huiju.model.SysRole;
10
 import com.community.huiju.model.SysRole;
11
+import com.community.huiju.model.SysRoleMenu;
10
 import com.community.huiju.model.TpTransaction;
12
 import com.community.huiju.model.TpTransaction;
11
 import com.community.huiju.service.RoleServiceI;
13
 import com.community.huiju.service.RoleServiceI;
12
 import com.google.common.collect.Maps;
14
 import com.google.common.collect.Maps;
14
 import org.springframework.beans.factory.annotation.Autowired;
16
 import org.springframework.beans.factory.annotation.Autowired;
15
 import org.springframework.stereotype.Service;
17
 import org.springframework.stereotype.Service;
16
 
18
 
19
+import java.time.LocalDateTime;
20
+import java.util.ArrayList;
17
 import java.util.List;
21
 import java.util.List;
18
 import java.util.Map;
22
 import java.util.Map;
19
 
23
 
27
 	
31
 	
28
 	@Autowired
32
 	@Autowired
29
 	private RoleMapper roleMapper;
33
 	private RoleMapper roleMapper;
34
+	
35
+	@Autowired
36
+	private SysRoleMenuMapper sysRoleMenuMapper;
30
 	/**
37
 	/**
31
 	 * 获取角色列表
38
 	 * 获取角色列表
32
 	 *
39
 	 *
51
 		responseBean.addSuccess(map);
58
 		responseBean.addSuccess(map);
52
 		return responseBean;
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
 import com.community.huiju.service.ISysMenuService;
9
 import com.community.huiju.service.ISysMenuService;
10
 import org.springframework.beans.factory.annotation.Autowired;
10
 import org.springframework.beans.factory.annotation.Autowired;
11
 import org.springframework.stereotype.Service;
11
 import org.springframework.stereotype.Service;
12
+import org.springframework.transaction.annotation.Transactional;
12
 
13
 
13
 import java.util.ArrayList;
14
 import java.util.ArrayList;
14
 import java.util.List;
15
 import java.util.List;
22
  * @since 2019-01-17
23
  * @since 2019-01-17
23
  */
24
  */
24
 @Service
25
 @Service
26
+@Transactional(rollbackFor = Exception.class)
25
 public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {
27
 public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {
26
 	
28
 	
27
 	@Autowired
29
 	@Autowired
39
 		List<SysMenu> menuList = new ArrayList<SysMenu>();
41
 		List<SysMenu> menuList = new ArrayList<SysMenu>();
40
 		sysMenuList.stream().forEach(sysMenu -> {
42
 		sysMenuList.stream().forEach(sysMenu -> {
41
 			//父节点是0的,为根节点。
43
 			//父节点是0的,为根节点。
42
-			if(sysMenu.getParentId().equals("0")){
44
+			if(sysMenu.getParentId().equals(0)){
43
 				menuList.add(sysMenu);
45
 				menuList.add(sysMenu);
44
 			}
46
 			}
45
 		});
47
 		});

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

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
     method: 'get'
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
-import { fetchList, fetchMenuList } from '@/api/role'
1
+import { fetchList, fetchMenuList, addMenuInfo } from '@/api/role'
2
 
2
 
3
 const transaction = {
3
 const transaction = {
4
   namespaced: true,
4
   namespaced: true,
33
           reject(error)
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
 <template>
1
 <template>
2
   <div class="root">
2
   <div class="root">
3
     <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="add-ruleForm">
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
       </el-form-item>
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
       </el-form-item>
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
       <el-form-item>
19
       <el-form-item>
17
         <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
20
         <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
18
         <el-button @click="resetForm('ruleForm')">重置</el-button>
21
         <el-button @click="resetForm('ruleForm')">重置</el-button>
35
   data() {
38
   data() {
36
     return {
39
     return {
37
       ruleForm: {
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
       rules: {
45
       rules: {
47
-        phase: [
46
+        roleName: [
48
           { required: true, message: '请输入角色名称', trigger: 'blur' }
47
           { required: true, message: '请输入角色名称', trigger: 'blur' }
48
+        ],
49
+        menuArray: [
50
+          { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
49
         ]
51
         ]
50
       },
52
       },
51
       defaultProps: {
53
       defaultProps: {
61
     ...mapMutations('role', {
63
     ...mapMutations('role', {
62
     }),
64
     }),
63
     ...mapActions('role', [
65
     ...mapActions('role', [
64
-      'FetchMenuList'
66
+      'FetchMenuList',
67
+      'AddMenuInfo'
65
     ]),
68
     ]),
66
     submitForm(formName) { // 提交
69
     submitForm(formName) { // 提交
70
+      // 获取选中的树形节点 key
71
+      this.ruleForm.menuArray = this.$refs.tree.getCheckedKeys()
72
+      console.log(this.ruleForm.menuArray)
67
       this.$refs[formName].validate((valid) => {
73
       this.$refs[formName].validate((valid) => {
68
         if (valid) {
74
         if (valid) {
69
-          this.addBuilding()
75
+          this.addRole()
70
         } else {
76
         } else {
71
           console.log('error submit!!')
77
           console.log('error submit!!')
72
           return false
78
           return false
82
     resetForm(formName) { // 重置
88
     resetForm(formName) { // 重置
83
       this.$refs[formName].resetFields()
89
       this.$refs[formName].resetFields()
84
     },
90
     },
85
-    addBuilding() {
91
+    addRole() {
86
       // 加载框
92
       // 加载框
87
       const loading = this.$loading({
93
       const loading = this.$loading({
88
         lock: true,
94
         lock: true,
90
         spinner: 'el-icon-loading',
96
         spinner: 'el-icon-loading',
91
         background: 'rgba(0, 0, 0, 0.7)'
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
         if (res.code === '0') {
100
         if (res.code === '0') {
95
           this.$message({
101
           this.$message({
96
             message: res.message,
102
             message: res.message,
97
             type: 'success'
103
             type: 'success'
98
           })
104
           })
99
-          this.$router.push({ name: 'building-index' })
105
+          this.$router.push({ name: 'role-index' })
100
           loading.close()
106
           loading.close()
101
           return
107
           return
102
         }
108
         }
104
         loading.close()
110
         loading.close()
105
       }).catch(() => {
111
       }).catch(() => {
106
         loading.close()
112
         loading.close()
107
-        console.log('error AddBuilding')
113
+        console.log('error addRole')
108
       })
114
       })
109
     }
115
     }
110
   }
116
   }