Selaa lähdekoodia

角色 前端/后端 完成

weiximei 6 vuotta sitten
vanhempi
commit
a3f8664ad2

+ 2
- 1
CODE/smart-community/operate-api/src/main/java/com/community/huiju/OperateApplication.java Näytä tiedosto

@@ -27,7 +27,8 @@ public class OperateApplication {
27 27
 		FastJsonConfig fastJsonConfig = new FastJsonConfig();
28 28
 		fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat,SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteMapNullValue);
29 29
 		//日期格式化
30
-		//fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
30
+		//	fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
31
+		// fastJsonConfig.setDateFormat("yyyy-MM-dd");
31 32
 		converter.setFastJsonConfig(fastJsonConfig);
32 33
 		return new HttpMessageConverters(converter);
33 34
 	}

+ 15
- 0
CODE/smart-community/operate-api/src/main/java/com/community/huiju/controller/SysRoleController.java Näytä tiedosto

@@ -13,6 +13,7 @@ import org.springframework.cloud.context.config.annotation.RefreshScope;
13 13
 import org.springframework.web.bind.annotation.*;
14 14
 
15 15
 import javax.servlet.http.HttpSession;
16
+import java.util.List;
16 17
 
17 18
 @RefreshScope
18 19
 @RestController
@@ -76,4 +77,18 @@ public class SysRoleController extends BaseController {
76 77
         return responseBean;
77 78
     }
78 79
 
80
+    @RequestMapping(value = "/role/delete", method = RequestMethod.POST)
81
+    @ApiOperation(value = "删除角色", notes = "删除角色")
82
+    @ApiImplicitParams({
83
+            @ApiImplicitParam(dataTypeClass = String.class, paramType = "header", name = "X-Auth-Token", value = "Token"),
84
+            @ApiImplicitParam(dataTypeClass = String.class, paramType = "body", name = "parameter", value = "id角色编号集合")
85
+    })
86
+    public ResponseBean deleteRole(@RequestBody List<Integer> parameter, HttpSession session){
87
+        ResponseBean responseBean = new ResponseBean();
88
+        UserElement userElement = getUserElement(session);
89
+        responseBean = iToSysRoleService.deleteRole(parameter, userElement);
90
+
91
+        return responseBean;
92
+    }
93
+
79 94
 }

+ 9
- 0
CODE/smart-community/operate-api/src/main/java/com/community/huiju/dao/ToSysRoleMapper.java Näytä tiedosto

@@ -45,4 +45,13 @@ public interface ToSysRoleMapper {
45 45
     ToSysRole selectByRoleName(@Param("roleName") String roleName);
46 46
 
47 47
 
48
+    /**
49
+     * 批量删除
50
+     *
51
+     *  只是把 status 改为 0 无效
52
+     *
53
+     * @return
54
+     */
55
+    int banchDeleteRole(List<Integer> list);
56
+
48 57
 }

+ 10
- 0
CODE/smart-community/operate-api/src/main/java/com/community/huiju/dao/ToSysUserRoleMapper.java Näytä tiedosto

@@ -2,6 +2,9 @@ package com.community.huiju.dao;
2 2
 
3 3
 import com.community.huiju.model.ToSysUserRole;
4 4
 import org.apache.ibatis.annotations.Mapper;
5
+import org.apache.ibatis.annotations.Param;
6
+
7
+import java.util.List;
5 8
 
6 9
 @Mapper
7 10
 public interface ToSysUserRoleMapper {
@@ -16,4 +19,11 @@ public interface ToSysUserRoleMapper {
16 19
     int updateByPrimaryKeySelective(ToSysUserRole record);
17 20
 
18 21
     int updateByPrimaryKey(ToSysUserRole record);
22
+
23
+    /**
24
+     * 根据 角色id 查询 用户和角色关联关系
25
+     * @param roleId
26
+     * @return
27
+     */
28
+    List<ToSysUserRole> selelctByRoleId(@Param("roleId") Integer roleId);
19 29
 }

+ 19
- 2
CODE/smart-community/operate-api/src/main/java/com/community/huiju/service/impl/ToSysRoleServiceImpl.java Näytä tiedosto

@@ -11,6 +11,7 @@ import com.github.pagehelper.Page;
11 11
 import com.github.pagehelper.PageHelper;
12 12
 import com.google.common.collect.Maps;
13 13
 import lombok.extern.slf4j.Slf4j;
14
+import org.apache.commons.collections.CollectionUtils;
14 15
 import org.springframework.beans.factory.annotation.Autowired;
15 16
 import org.springframework.stereotype.Service;
16 17
 import org.springframework.transaction.annotation.Transactional;
@@ -34,6 +35,9 @@ public class ToSysRoleServiceImpl implements IToSysRoleService {
34 35
     @Autowired
35 36
     private ToUserMapper toUserMapper;
36 37
 
38
+    @Autowired
39
+    private ToSysUserRoleMapper toSysUserRoleMapper;
40
+
37 41
     @Override
38 42
     public List<ToSysRole> selectRoleByUserId(Integer userId) {
39 43
 
@@ -146,6 +150,7 @@ public class ToSysRoleServiceImpl implements IToSysRoleService {
146 150
     }
147 151
 
148 152
     @Override
153
+    @Transactional(rollbackFor = Exception.class)
149 154
     public ResponseBean updateRole(String parameter, UserElement userElement) {
150 155
         ResponseBean responseBean = new ResponseBean();
151 156
         JSONObject jsonObject = JSONObject.parseObject(parameter);
@@ -178,12 +183,24 @@ public class ToSysRoleServiceImpl implements IToSysRoleService {
178 183
     }
179 184
 
180 185
     @Override
186
+    @Transactional(rollbackFor = Exception.class)
181 187
     public ResponseBean deleteRole(List<Integer> ids, UserElement userElement) {
182 188
         ResponseBean responseBean = new ResponseBean();
183 189
         ids.forEach(e ->{
184
-
190
+            List<ToSysUserRole> userRoleList = toSysUserRoleMapper.selelctByRoleId(e);
191
+            if (CollectionUtils.isNotEmpty(userRoleList)) {
192
+                throw new WisdomException("角色存在用户关联关系, 无法删除!");
193
+            }
194
+            ToSysRole toSysRole = toSysRoleMapper.selectByPrimaryKey(e);
195
+            if (null == toSysRole) {
196
+                throw new WisdomException("删除失败, 角色编号 " + e + " 不存在!");
197
+            }
198
+            toSysRole.setStatus("0");
199
+            toSysRole.setUpdateUser(userElement.getId());
200
+            toSysRole.setUpdateDate(new Date());
201
+            toSysRoleMapper.updateByPrimaryKeySelective(toSysRole);
185 202
         });
186
-
203
+        responseBean.addSuccess("操作成功!");
187 204
         return responseBean;
188 205
     }
189 206
 }

+ 10
- 1
CODE/smart-community/operate-api/src/main/resources/mapper/ToSysRoleMapper.xml Näytä tiedosto

@@ -137,8 +137,9 @@
137 137
     <include refid="Base_Column_List"/>
138 138
     from to_sys_role
139 139
     <where>
140
+      status != 0
140 141
       <if test="roleName != null and roleName != ''">
141
-        role_name like concat('%',#{roleName,jdbcType=VARCHAR},'%')
142
+        and role_name like concat('%',#{roleName,jdbcType=VARCHAR},'%')
142 143
       </if>
143 144
     </where>
144 145
   </select>
@@ -151,4 +152,12 @@
151 152
         role_name = #{roleName,jdbcType=VARCHAR}
152 153
     </where>
153 154
   </select>
155
+
156
+  <update id="banchDeleteRole" parameterType="list">
157
+    update to_sys_role
158
+    set status = 0 where id in
159
+    <foreach collection="list" index="index" separator="," open="(" close=")" item="item">
160
+      #{item}
161
+    </foreach>
162
+  </update>
154 163
 </mapper>

+ 6
- 0
CODE/smart-community/operate-api/src/main/resources/mapper/ToSysUserRoleMapper.xml Näytä tiedosto

@@ -68,4 +68,10 @@
68 68
       role_id = #{roleId,jdbcType=INTEGER}
69 69
     where id = #{id,jdbcType=INTEGER}
70 70
   </update>
71
+  <select id="selelctByRoleId" parameterType="integer" resultMap="BaseResultMap">
72
+    select
73
+    <include refid="Base_Column_List"/>
74
+    from to_sys_user_role
75
+    where role_id = #{roleId,jdbcType=INTEGER}
76
+  </select>
71 77
 </mapper>

+ 9
- 0
VUECODE/smart-operate-manage/src/api/role.js Näytä tiedosto

@@ -45,3 +45,12 @@ export function getRoleInfo(id) {
45 45
     method: 'get'
46 46
   })
47 47
 }
48
+
49
+// 根据 角色id集合 删除
50
+export function deleteRole(data) {
51
+  return request({
52
+    url: '/role/delete',
53
+    method: 'post',
54
+    data
55
+  })
56
+}

+ 10
- 1
VUECODE/smart-operate-manage/src/store/modules/role.js Näytä tiedosto

@@ -1,4 +1,4 @@
1
-import { getRoleList, getMenuList, addRole, updateRole, getRoleInfo } from '@/api/role'
1
+import { getRoleList, getMenuList, addRole, updateRole, getRoleInfo, deleteRole } from '@/api/role'
2 2
 
3 3
 const role = {
4 4
 
@@ -47,6 +47,15 @@ const role = {
47 47
           reject(err)
48 48
         })
49 49
       })
50
+    },
51
+    DeleteRole({ commit }, data) { // 根据 角色id 集合 删除
52
+      return new Promise((resolve, reject) => {
53
+        deleteRole(data).then(response => {
54
+          resolve(response)
55
+        }).catch((err) => {
56
+          reject(err)
57
+        })
58
+      })
50 59
     }
51 60
   }
52 61
 }

+ 17
- 0
VUECODE/smart-operate-manage/src/views/account/role/index.vue Näytä tiedosto

@@ -155,14 +155,31 @@ export default {
155 155
       this.getRoleList()
156 156
     },
157 157
     deleteRole() { // 删除角色
158
+      const ids = this.selectId
159
+      if (ids.length <= 0) {
160
+        this.$message.error('请至少选择一行!')
161
+        return
162
+      }
163
+      this.$store.dispatch('DeleteRole', ids).then((res) => {
164
+        if (res.code === '1') {
165
+          this.$message.error(res.message)
166
+          return
167
+        }
168
+        this.$message.success(res.message)
169
+        this.getRoleList()
170
+      }).catch(() => {
171
+        console.log('error DeleteRole')
172
+      })
158 173
     },
159 174
     updateRole() { // 修改角色
160 175
       const ids = this.selectId
161 176
       if (ids.length <= 0) {
162 177
         this.$message.error('请至少选择一行!')
178
+        return
163 179
       }
164 180
       if (ids.length > 1) {
165 181
         this.$message.error('只能选择一行数据!')
182
+        return
166 183
       }
167 184
       this.$router.push({ name: 'role-edi', params: { id: ids[0] }})
168 185
     },