Skip to content

Commit

Permalink
添加ztree树插件,完善用户角色权限管理功能
Browse files Browse the repository at this point in the history
  • Loading branch information
techa03 committed Jul 25, 2018
1 parent 189fc09 commit 6921021
Show file tree
Hide file tree
Showing 34 changed files with 1,661 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.seckill.api.service.PermissionService;
import org.seckill.api.service.RoleService;
import org.seckill.api.service.UserAccountService;
import org.seckill.api.service.UserRoleService;
import org.seckill.api.service.*;
import org.seckill.entity.*;
import org.seckill.web.dto.PermissionDto;
import org.seckill.web.dto.ResponseDto;
import org.seckill.web.dto.RoleDto;
import org.springframework.beans.BeanUtils;
Expand All @@ -32,10 +30,12 @@ public class AdminController {
UserRoleService userRoleService;
@Autowired
PermissionService permissionService;
@Autowired
RolePermissionService rolePermissionService;

@RequestMapping("/role")
@ResponseBody
public ResponseDto role(Model model, @RequestParam(name = "offset", required = false, defaultValue = "0") int offset,
public ResponseDto role(Model model, @RequestParam(name = "page", required = false, defaultValue = "0") int offset,
@RequestParam(name = "limit", required = false, defaultValue = "10") int limit) {
PageInfo<Role> pageInfo = roleService.selectByPage(new RoleExample(), offset, limit);
ResponseDto<Role> responseDto = new ResponseDto<>();
Expand All @@ -46,15 +46,15 @@ public ResponseDto role(Model model, @RequestParam(name = "offset", required = f

@RequestMapping("/roleLess")
@ResponseBody
public ResponseDto roleLess(Model model, @RequestParam(name = "offset", required = false, defaultValue = "0") int offset,
@RequestParam(name = "limit", required = false, defaultValue = "10") int limit) {
public ResponseDto roleLess(Model model, @RequestParam(name = "page", required = false, defaultValue = "0") int offset,
@RequestParam(name = "limit", required = false, defaultValue = "10") int limit) {
PageInfo<Role> pageInfo = roleService.selectByPage(new RoleExample(), offset, limit);
ResponseDto<RoleDto> responseDto = new ResponseDto<>();
List<Role> list = pageInfo.getList();
List<RoleDto> result = new ArrayList();
for (Role role : list) {
RoleDto roleDto = new RoleDto();
BeanUtils.copyProperties(role,roleDto);
BeanUtils.copyProperties(role, roleDto);
result.add(roleDto);
}
responseDto.setData(result.toArray(new RoleDto[result.size()]));
Expand All @@ -81,7 +81,7 @@ public ResponseDto deleteRole(@PathVariable("roleId") int roleId) {

@RequestMapping("/permission")
@ResponseBody
public ResponseDto permission(Model model, @RequestParam(name = "offset", required = false, defaultValue = "0") int offset,
public ResponseDto permission(Model model, @RequestParam(name = "page", required = false, defaultValue = "0") int offset,
@RequestParam(name = "limit", required = false, defaultValue = "10") int limit) {
PageInfo<Permission> pageInfo = permissionService.selectByPage(new PermissionExample(), offset, limit);
ResponseDto<Permission> responseDto = new ResponseDto<>();
Expand All @@ -90,6 +90,28 @@ public ResponseDto permission(Model model, @RequestParam(name = "offset", requir
return responseDto;
}

@RequestMapping("/permissionTree")
@ResponseBody
public ResponseDto permissionTree(Model model, @RequestParam(name = "page", required = false, defaultValue = "0") int offset,
@RequestParam(name = "limit", required = false, defaultValue = "10") int limit) {
PageInfo<Permission> pageInfo = permissionService.selectByPage(new PermissionExample(), offset, limit);
List<Permission> permissions = pageInfo.getList();
List<PermissionDto> permissionDtoList = new ArrayList<>();
for (Permission permission : permissions) {
PermissionDto permissionDto = new PermissionDto();
permissionDto.setId(permission.getPermissionId().toString());
if (permission.getParentPermissionId() != null) {
permissionDto.setPId(permission.getParentPermissionId().toString());
}
permissionDto.setName(permission.getPermissionName());
permissionDtoList.add(permissionDto);
}
ResponseDto<PermissionDto> responseDto = new ResponseDto<>();
responseDto.setData(permissionDtoList.toArray(new PermissionDto[permissionDtoList.size()]));
responseDto.setCount((int) pageInfo.getTotal());
return responseDto;
}

@RequestMapping("/permission/add")
public String addPermission(Permission permission) {
permission.setCreateTime(new Date());
Expand All @@ -109,7 +131,7 @@ public ResponseDto deletePermission(@PathVariable("permissionId") int permission

@RequestMapping("/user")
@ResponseBody
public ResponseDto user(Model model, @RequestParam(name = "offset", required = false, defaultValue = "0") int offset,
public ResponseDto user(Model model, @RequestParam(name = "page", required = false, defaultValue = "0") int offset,
@RequestParam(name = "limit", required = false, defaultValue = "10") int limit) {
PageInfo<User> pageInfo = userService.selectByPage(new UserExample(), offset, limit);
ResponseDto<User> responseDto = new ResponseDto<>();
Expand Down Expand Up @@ -147,4 +169,24 @@ public ResponseDto addRole(@PathVariable("userId") int userId, @RequestBody Role
return responseDto;
}

@PostMapping(value = "/role/{roleId}/updateRolePermission")
@ResponseBody
@Transactional
public ResponseDto updateRolePermission(@PathVariable("roleId") int roleId, @RequestBody String[] permissionIds) {
UserRoleExample example = new UserRoleExample();
RolePermissionExample rolePermissionExample = new RolePermissionExample();
rolePermissionExample.createCriteria().andRoleIdEqualTo(roleId);
rolePermissionService.deleteByExample(rolePermissionExample);
for (String permissionId : permissionIds) {
RolePermission record = new RolePermission();
record.setRoleId(roleId);
record.setPermissionId(Integer.valueOf(permissionId));
record.setCreateTime(new Date());
record.setUpdateTime(new Date());
rolePermissionService.insertSelective(record);
}
ResponseDto<User> responseDto = new ResponseDto<>();
return responseDto;
}

}
12 changes: 12 additions & 0 deletions goodsKill-web/src/main/java/org/seckill/web/dto/PermissionDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.seckill.web.dto;

import lombok.Data;

import java.io.Serializable;

@Data
public class PermissionDto implements Serializable {
private String id;
private String pId;
private String name;
}
72 changes: 47 additions & 25 deletions goodsKill-web/src/main/sql/seckill.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Target Server Type : MYSQL
Target Server Version : 50640
File Encoding : 65001

Date: 2018-07-24 09:50:48
Date: 2018-07-25 21:56:51
*/

SET FOREIGN_KEY_CHECKS=0;
Expand Down Expand Up @@ -66,7 +66,6 @@ INSERT INTO `permission` VALUES ('4', '用户角色管理', '2018-07-14 12:28:25
INSERT INTO `permission` VALUES ('5', '权限管理', '2018-07-14 12:28:25', '2018-07-14 12:28:25', 'admin/permission.html', '7', 'N', '3');
INSERT INTO `permission` VALUES ('6', '角色管理', '2018-07-14 12:28:25', '2018-07-14 12:28:25', 'admin/role.html', '7', 'N', '4');
INSERT INTO `permission` VALUES ('7', '用户角色权限管理', '2018-07-14 12:28:25', '2018-07-14 12:28:25', 'admin', null, 'Y', '0');
INSERT INTO `permission` VALUES ('9', '库存管理', '2018-07-23 16:49:44', '2018-07-23 16:49:44', 'storage', null, 'Y', '1');

-- ----------------------------
-- Table structure for role
Expand Down Expand Up @@ -98,17 +97,36 @@ CREATE TABLE `role_permission` (
`role_id` int(10) unsigned NOT NULL,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
PRIMARY KEY (`id`),
KEY `for_permission_id` (`permission_id`),
KEY `for_role_id` (`role_id`),
CONSTRAINT `for_permission_id` FOREIGN KEY (`permission_id`) REFERENCES `permission` (`permission_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `for_role_id` FOREIGN KEY (`role_id`) REFERENCES `role` (`role_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=51 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

-- ----------------------------
-- Records of role_permission
-- ----------------------------
INSERT INTO `role_permission` VALUES ('4', '3', '1', null, null);
INSERT INTO `role_permission` VALUES ('5', '4', '1', null, null);
INSERT INTO `role_permission` VALUES ('6', '5', '1', null, null);
INSERT INTO `role_permission` VALUES ('7', '6', '1', null, null);
INSERT INTO `role_permission` VALUES ('8', '7', '1', null, null);
INSERT INTO `role_permission` VALUES ('31', '7', '8', '2018-07-25 21:53:28', '2018-07-25 21:53:28');
INSERT INTO `role_permission` VALUES ('32', '3', '8', '2018-07-25 21:53:28', '2018-07-25 21:53:28');
INSERT INTO `role_permission` VALUES ('33', '4', '8', '2018-07-25 21:53:28', '2018-07-25 21:53:28');
INSERT INTO `role_permission` VALUES ('34', '5', '8', '2018-07-25 21:53:28', '2018-07-25 21:53:28');
INSERT INTO `role_permission` VALUES ('35', '6', '8', '2018-07-25 21:53:28', '2018-07-25 21:53:28');
INSERT INTO `role_permission` VALUES ('36', '7', '2', '2018-07-25 21:53:47', '2018-07-25 21:53:47');
INSERT INTO `role_permission` VALUES ('37', '3', '2', '2018-07-25 21:53:47', '2018-07-25 21:53:47');
INSERT INTO `role_permission` VALUES ('38', '4', '2', '2018-07-25 21:53:47', '2018-07-25 21:53:47');
INSERT INTO `role_permission` VALUES ('39', '5', '2', '2018-07-25 21:53:47', '2018-07-25 21:53:47');
INSERT INTO `role_permission` VALUES ('40', '6', '2', '2018-07-25 21:53:47', '2018-07-25 21:53:47');
INSERT INTO `role_permission` VALUES ('41', '7', '7', '2018-07-25 21:53:49', '2018-07-25 21:53:49');
INSERT INTO `role_permission` VALUES ('42', '3', '7', '2018-07-25 21:53:49', '2018-07-25 21:53:49');
INSERT INTO `role_permission` VALUES ('43', '4', '7', '2018-07-25 21:53:49', '2018-07-25 21:53:49');
INSERT INTO `role_permission` VALUES ('44', '5', '7', '2018-07-25 21:53:49', '2018-07-25 21:53:49');
INSERT INTO `role_permission` VALUES ('45', '6', '7', '2018-07-25 21:53:49', '2018-07-25 21:53:49');
INSERT INTO `role_permission` VALUES ('46', '7', '1', '2018-07-25 21:53:52', '2018-07-25 21:53:52');
INSERT INTO `role_permission` VALUES ('47', '3', '1', '2018-07-25 21:53:52', '2018-07-25 21:53:52');
INSERT INTO `role_permission` VALUES ('48', '4', '1', '2018-07-25 21:53:52', '2018-07-25 21:53:52');
INSERT INTO `role_permission` VALUES ('49', '5', '1', '2018-07-25 21:53:52', '2018-07-25 21:53:52');
INSERT INTO `role_permission` VALUES ('50', '6', '1', '2018-07-25 21:53:52', '2018-07-25 21:53:52');

-- ----------------------------
-- Table structure for seckill
Expand Down Expand Up @@ -164,7 +182,7 @@ INSERT INTO `success_killed` VALUES ('1', '1373483423', '0', '2016-08-06 16:36:3
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`account` varchar(45) NOT NULL,
`password` varchar(45) NOT NULL DEFAULT 'aa123456',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
Expand All @@ -173,7 +191,7 @@ CREATE TABLE `user` (
`locked` varchar(1) DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `account_UNIQUE` (`account`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8;
) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of user
Expand All @@ -192,21 +210,25 @@ CREATE TABLE `user_role` (
`role_id` int(10) unsigned DEFAULT NULL,
`create_time` timestamp NULL DEFAULT NULL,
`update_time` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8;
PRIMARY KEY (`id`),
KEY `for_user_role_id` (`role_id`),
KEY `for_user_id` (`user_id`),
CONSTRAINT `for_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `for_user_role_id` FOREIGN KEY (`role_id`) REFERENCES `role` (`role_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=80 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of user_role
-- ----------------------------
INSERT INTO `user_role` VALUES ('31', '15', '1', null, null);
INSERT INTO `user_role` VALUES ('32', '15', '2', null, null);
INSERT INTO `user_role` VALUES ('33', '15', '7', null, null);
INSERT INTO `user_role` VALUES ('34', '15', '8', null, null);
INSERT INTO `user_role` VALUES ('35', '21', '1', null, null);
INSERT INTO `user_role` VALUES ('36', '21', '2', null, null);
INSERT INTO `user_role` VALUES ('37', '21', '7', null, null);
INSERT INTO `user_role` VALUES ('38', '21', '8', null, null);
INSERT INTO `user_role` VALUES ('39', '14', '1', null, null);
INSERT INTO `user_role` VALUES ('40', '14', '2', null, null);
INSERT INTO `user_role` VALUES ('41', '14', '7', null, null);
INSERT INTO `user_role` VALUES ('42', '14', '8', null, null);
INSERT INTO `user_role` VALUES ('60', '15', '1', '2018-07-24 14:43:18', '2018-07-24 14:43:18');
INSERT INTO `user_role` VALUES ('61', '15', '2', '2018-07-24 14:43:18', '2018-07-24 14:43:18');
INSERT INTO `user_role` VALUES ('62', '15', '7', '2018-07-24 14:43:18', '2018-07-24 14:43:18');
INSERT INTO `user_role` VALUES ('63', '15', '8', '2018-07-24 14:43:18', '2018-07-24 14:43:18');
INSERT INTO `user_role` VALUES ('64', '21', '1', '2018-07-24 14:43:21', '2018-07-24 14:43:21');
INSERT INTO `user_role` VALUES ('65', '21', '2', '2018-07-24 14:43:21', '2018-07-24 14:43:21');
INSERT INTO `user_role` VALUES ('66', '21', '7', '2018-07-24 14:43:21', '2018-07-24 14:43:21');
INSERT INTO `user_role` VALUES ('67', '21', '8', '2018-07-24 14:43:21', '2018-07-24 14:43:21');
INSERT INTO `user_role` VALUES ('72', '14', '1', '2018-07-24 14:48:23', '2018-07-24 14:48:23');
INSERT INTO `user_role` VALUES ('73', '14', '2', '2018-07-24 14:48:23', '2018-07-24 14:48:23');
INSERT INTO `user_role` VALUES ('74', '14', '7', '2018-07-24 14:48:23', '2018-07-24 14:48:23');
INSERT INTO `user_role` VALUES ('75', '14', '8', '2018-07-24 14:48:23', '2018-07-24 14:48:23');
13 changes: 4 additions & 9 deletions goodsKill-web/src/main/webapp/html/admin/permission.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="../../layui/css/layui.css">
<link rel="stylesheet" href="../css/zTreeStyle/zTreeStyle.css">
<script src="../js/config.js"></script>
<script src="../js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="../js/jquery.ztree.all.min.js"></script>

<script>
var initCount = 0;
function addPermission() {
Expand Down Expand Up @@ -136,15 +140,6 @@
</form>
</div>
<script src="../../layui/layui.all.js"></script>
<script src="../js/jquery-1.10.2.js"/>
<script src="../js/config.js"/>
<script>
// table.on('checkbox(test)', function(obj){
// console.log(obj);
// var checkStatus = table.checkStatus('userPermission');
// console.log(checkStatus.data);
// });
</script>
</body>
</html>

Expand Down
Loading

0 comments on commit 6921021

Please sign in to comment.