Skip to content

Commit b8d3778

Browse files
committed
添加: 中国行政区域 省,市,区, 三级联动
修改: 角色赋值权限 bug
1 parent df8f877 commit b8d3778

File tree

21 files changed

+5003
-103
lines changed

21 files changed

+5003
-103
lines changed

spring-restful-api/src/main/java/com/ifsaid/shark/common/domain/TreeNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class TreeNode implements java.io.Serializable {
3333
* @author Wang Chen Chen<932560435@qq.com>
3434
* @date 2019/12/12 21:32
3535
*/
36-
private int id;
36+
private long id;
3737

3838
/**
3939
* 当前节点标题
@@ -51,7 +51,7 @@ public class TreeNode implements java.io.Serializable {
5151
* @author Wang Chen Chen<932560435@qq.com>
5252
* @date 2019/12/12 21:32
5353
*/
54-
private int parentId;
54+
private long parentId;
5555

5656
/**
5757
* 源属性
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.ifsaid.shark.controller;
2+
3+
import com.github.pagehelper.Page;
4+
import com.github.pagehelper.PageInfo;
5+
import com.ifsaid.shark.common.domain.TreeNode;
6+
import com.ifsaid.shark.entity.ChinaArea;
7+
import com.ifsaid.shark.service.ChinaAreaService;
8+
import com.ifsaid.shark.util.JsonResult;
9+
import com.ifsaid.shark.util.QueryParameter;
10+
import com.ifsaid.shark.util.TreeNodeUtils;
11+
import io.swagger.annotations.Api;
12+
import io.swagger.annotations.ApiOperation;
13+
import lombok.extern.slf4j.Slf4j;
14+
import org.springframework.beans.factory.annotation.Autowired;
15+
import org.springframework.web.bind.annotation.GetMapping;
16+
import org.springframework.web.bind.annotation.PathVariable;
17+
import org.springframework.web.bind.annotation.RequestMapping;
18+
import org.springframework.web.bind.annotation.RestController;
19+
20+
import java.util.List;
21+
import java.util.stream.Collectors;
22+
23+
/**
24+
* All rights Reserved, Designed By www.ifsaid.com
25+
* <p>
26+
* 中国行政地区 Controller
27+
* </p>
28+
*
29+
* @author Wang Chen Chen<932560435@qq.com>
30+
* @version 2.0
31+
* @date 2019/12/25 22:13
32+
* @copyright 2019 http://www.ifsaid.com/ Inc. All rights reserved.
33+
*/
34+
35+
@Slf4j
36+
@Api(tags = "[ 通用 ] 中国行政地区")
37+
@RestController
38+
@RequestMapping("/china/area")
39+
public class ChinaAreaController {
40+
41+
@Autowired
42+
private ChinaAreaService baseService;
43+
44+
@ApiOperation(value = "单个查询", notes = "根据Id查询")
45+
@GetMapping("/{id}")
46+
public JsonResult<ChinaArea> findById(@PathVariable("id") Long id) {
47+
log.info("get ID : {}", id);
48+
return JsonResult.success(baseService.findById(id));
49+
}
50+
51+
@ApiOperation(value = "查询所有", notes = "查询所有")
52+
@GetMapping("/all/{parentCode}")
53+
public JsonResult<List<ChinaArea>> findAll(@PathVariable Long parentCode) {
54+
if (parentCode == null) {
55+
parentCode = 0L;
56+
}
57+
return JsonResult.success(baseService.findAll(ChinaArea.builder().parentCode(parentCode).build()));
58+
}
59+
60+
@ApiOperation(value = "查询所有[树节点]", notes = "以树节点的形式展示")
61+
@GetMapping("/tree")
62+
public JsonResult<Page<ChinaArea>> tree() {
63+
List<TreeNode> collect = baseService.findAll(null)
64+
.stream()
65+
.distinct()
66+
.map(res -> new TreeNode(res.getAreaCode(), res.getName(), res.getParentCode(), res, null))
67+
.collect(Collectors.toList());
68+
return JsonResult.success(TreeNodeUtils.findRoots(collect));
69+
}
70+
71+
72+
}

spring-restful-api/src/main/java/com/ifsaid/shark/controller/SysDepartmentController.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import org.springframework.web.bind.annotation.RequestMapping;
1414
import org.springframework.web.bind.annotation.RestController;
1515

16-
import java.util.HashSet;
1716
import java.util.List;
18-
import java.util.Set;
1917
import java.util.stream.Collectors;
2018

2119

@@ -40,7 +38,7 @@ public class SysDepartmentController extends BaseController<SysDepartment, Integ
4038

4139
@ApiOperation(value = "查询所有[树节点]", notes = "以树节点的形式展示")
4240
@GetMapping("/tree")
43-
public JsonResult<List<TreeNode>> tree() {
41+
public JsonResult tree() {
4442
List<TreeNode> collect = baseService.findAll(null)
4543
.stream()
4644
.distinct()

spring-restful-api/src/main/java/com/ifsaid/shark/controller/SysPermissionController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class SysPermissionController extends BaseController<SysPermission, Integ
4343

4444
@ApiOperation(value = "查询所有[树节点]", notes = "以树节点的形式展示 <br> \n\n 如果 filter 是 true,那么就是要过滤掉,按钮。如果是 false。就是菜单和按钮全要")
4545
@GetMapping("/tree")
46-
public JsonResult<String> tree(@RequestParam(defaultValue = "false") boolean filter) {
46+
public JsonResult tree(@RequestParam(defaultValue = "false") boolean filter) {
4747
List<TreeNode> collect = baseService.findAll(null)
4848
.stream()
4949
.distinct()

spring-restful-api/src/main/java/com/ifsaid/shark/controller/SysRoleController.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.ifsaid.shark.common.controller.BaseController;
44
import com.ifsaid.shark.common.domain.TreeNode;
5+
import com.ifsaid.shark.entity.SysPermission;
56
import com.ifsaid.shark.entity.SysRole;
67
import com.ifsaid.shark.service.SysPermissionService;
78
import com.ifsaid.shark.service.SysRoleService;
@@ -47,23 +48,26 @@ public class SysRoleController extends BaseController<SysRole, Integer, SysRoleS
4748

4849
@ApiOperation(value = "查询角色详情,包括权限列表", notes = "根据Id查询")
4950
@GetMapping("/info/{rid}")
50-
public JsonResult<String> roleInfo(@PathVariable Integer rid) {
51+
public JsonResult roleInfo(@PathVariable Integer rid) {
5152
Map<String, Object> map = new HashMap<>(2);
5253
// 获取当前角色,拥有的权限
53-
List<Integer> have = sysPermissionService.findPermissionByRoleId(rid)
54-
.stream()
55-
.distinct()
56-
.map(res -> res.getPid())
57-
.collect(Collectors.toList());
58-
map.put("have", have);
54+
Set<SysPermission> havePermissionCollect = sysPermissionService.findPermissionByRoleId(rid);
55+
5956
// 获取全部的权限
60-
List<TreeNode> collect = sysPermissionService.findAll(null)
57+
List<TreeNode> allPermissionCollect = sysPermissionService.findAll(null)
6158
.stream()
6259
.distinct()
6360
.map(res -> new TreeNode(res.getPid(), res.getTitle(), res.getParentId(), null, null))
6461
.collect(Collectors.toList());
65-
List<TreeNode> all = TreeNodeUtils.findRoots(collect);
66-
map.put("all", all);
62+
63+
// 将当前角色拥有的权限 pid,挑选出来
64+
Set<Integer> hashSet = havePermissionCollect.stream().map(res -> res.getPid()).collect(Collectors.toSet());
65+
// 再次遍历,当前角色拥有的权限,然后 移除父节点 只留下子节点。
66+
havePermissionCollect.forEach(res -> hashSet.remove(res.getParentId()));
67+
// 将全部权限,递归成树节点的形式
68+
map.put("all", TreeNodeUtils.findRoots(allPermissionCollect));
69+
// 将当前角色拥有的权限Id,以列表的形式返回
70+
map.put("have", hashSet);
6771
return JsonResult.success(map);
6872
}
6973

@@ -76,7 +80,7 @@ public JsonResult updateRolePermissions(@RequestBody @Validated RoleRelatedPermi
7680
return JsonResult.fail(message);
7781
}
7882
int result = baseService.updateRolePermissions(data.getRid(), data.getPermissions());
79-
return JsonResult.success("success", result);
83+
return JsonResult.success(result);
8084
}
8185

8286

spring-restful-api/src/main/java/com/ifsaid/shark/controller/SysUserController.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.ifsaid.shark.controller;
22

3-
import com.github.pagehelper.Page;
43
import com.github.pagehelper.PageInfo;
54
import com.ifsaid.shark.common.controller.BaseController;
65
import com.ifsaid.shark.entity.SysUser;
@@ -39,16 +38,15 @@ public class SysUserController extends BaseController<SysUser, Integer, SysUserS
3938

4039
@ApiOperation(value = "分页,获取用户详情", notes = "分页 查询所有,获取用户详情")
4140
@GetMapping("/info/page")
42-
public JsonResult<Page<SysUserVo>> findAllInfoPage(QueryParameter parameter) {
41+
public JsonResult findAllInfoPage(QueryParameter parameter) {
4342
PageInfo<SysUserVo> page = baseService.findAllPageInfo(parameter);
4443
return JsonResult.success(page.getTotal(), page.getList());
4544
}
4645

4746
@ApiOperation(value = "获取用户详细信息", notes = "获取用户详细信息")
4847
@GetMapping("/info")
4948
public JsonResult<UserVo> findUserInfo() {
50-
UserVo userInfo = baseService.findUserInfo();
51-
return JsonResult.success(userInfo);
49+
return JsonResult.success(baseService.findUserInfo());
5250
}
5351

5452
@ApiOperation(value = "修改用户角色", notes = "修改用户角色,会删除之前的角色信息。")
@@ -59,7 +57,7 @@ public JsonResult updateRolePermissions(@RequestBody @Validated UserRelatedRoleV
5957
return JsonResult.fail(message);
6058
}
6159
int result = baseService.updateUserRoles(data.getUid(), data.getRoles());
62-
return JsonResult.success("success", result);
60+
return JsonResult.success(result);
6361
}
6462

6563

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.ifsaid.shark.entity;
2+
3+
import lombok.*;
4+
5+
import javax.persistence.Entity;
6+
import javax.persistence.Id;
7+
import javax.persistence.Table;
8+
9+
/**
10+
* All rights Reserved, Designed By www.ifsaid.com
11+
* <p>
12+
* [ 通用 ]中国行政地区表
13+
* </p>
14+
*
15+
* @author Wang Chen Chen<932560435@qq.com>
16+
* @version 2.0
17+
* @date 2019/12/25 22:01
18+
* @copyright 2019 http://www.ifsaid.com/ Inc. All rights reserved.
19+
*/
20+
21+
@Entity
22+
@Table(name = "tb_cn_area")
23+
@Getter
24+
@Setter
25+
@ToString
26+
@Builder
27+
@AllArgsConstructor
28+
@NoArgsConstructor
29+
public class ChinaArea implements java.io.Serializable {
30+
31+
/**
32+
* @description: 行政代码 [ 唯一 ]
33+
* @date: 2019/12/11 22:15
34+
*/
35+
@Id
36+
private Long areaCode;
37+
38+
/**
39+
* @description: 级别
40+
* @date: 2019/12/11 22:15
41+
*/
42+
private Integer level;
43+
44+
/**
45+
* @description: 父级行政代码
46+
* @date: 2019/12/11 22:15
47+
*/
48+
private Long parentCode;
49+
50+
/**
51+
* @description: 邮政编码
52+
* @date: 2019/12/11 22:15
53+
*/
54+
private Integer zipCode;
55+
56+
/**
57+
* @description: 区号
58+
* @date: 2019/12/11 22:15
59+
*/
60+
private String cityCode;
61+
62+
/**
63+
* @description: 名称
64+
* @date: 2019/12/11 22:15
65+
*/
66+
private String name;
67+
68+
/**
69+
* @description: 简称
70+
* @date: 2019/12/11 22:15
71+
*/
72+
private String shortName;
73+
74+
/**
75+
* @description: 组合名
76+
* @date: 2019/12/11 22:15
77+
*/
78+
private String mergerName;
79+
80+
/**
81+
* @description: 拼音
82+
* @date: 2019/12/11 22:15
83+
*/
84+
private String pinyin;
85+
86+
/**
87+
* @description: 经度
88+
* @date: 2019/12/11 22:15
89+
*/
90+
private Double lng;
91+
92+
/**
93+
* @description: 纬度
94+
* @date: 2019/12/11 22:15
95+
*/
96+
private Double lat;
97+
98+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.ifsaid.shark.mapper;
2+
3+
import com.ifsaid.shark.common.mapper.BaseMapper;
4+
import com.ifsaid.shark.entity.ChinaArea;
5+
6+
/**
7+
* All rights Reserved, Designed By www.ifsaid.com
8+
* <p>
9+
* 中国行政地区 Mapper
10+
* </p>
11+
*
12+
* @author Wang Chen Chen <932560435@qq.com>
13+
* @version 2.0
14+
* @date 2019/4/18 11:45
15+
* @copyright 2019 http://www.ifsaid.com/ Inc. All rights reserved.
16+
*/
17+
18+
19+
public interface ChinaAreaMapper extends BaseMapper<ChinaArea, Long> {
20+
21+
22+
}

spring-restful-api/src/main/java/com/ifsaid/shark/mapper/SysDepartmentMapper.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@
33
import com.ifsaid.shark.common.mapper.BaseMapper;
44
import com.ifsaid.shark.entity.SysDepartment;
55

6-
/**
7-
* All rights Reserved, Designed By www.ifsaid.com
8-
*
9-
* @description: 部门 Mapper 接口
10-
* @author: Wang Chen Chen <932560435@qq.com>
11-
* @date: 2019/5/10 10:56
12-
* @version: 2.0
13-
* @copyright: 2019 http://www.ifsaid.com/ Inc. All rights reserved.
14-
*/
15-
166
/**
177
* All rights Reserved, Designed By www.ifsaid.com
188
* <p>

0 commit comments

Comments
 (0)