From 3879c4e287199d1d45c305e4a9653c547bed369f Mon Sep 17 00:00:00 2001 From: xiangwb Date: Tue, 14 Nov 2017 16:54:38 +0800 Subject: [PATCH] merge --- .../xwbing/service/SysUserRoleService.java | 2 +- .../com/xwbing/controller/SysRoleControl.java | 46 +++++++++++++++++++ .../com/xwbing/controller/SysUserControl.java | 16 +++---- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/boot-service/src/main/java/com/xwbing/service/SysUserRoleService.java b/boot-service/src/main/java/com/xwbing/service/SysUserRoleService.java index 705b46e..30b2f69 100644 --- a/boot-service/src/main/java/com/xwbing/service/SysUserRoleService.java +++ b/boot-service/src/main/java/com/xwbing/service/SysUserRoleService.java @@ -40,7 +40,7 @@ public class SysUserRoleService { //用户新增角色 list.forEach(sysUserRole -> { sysUserRole.setId(PassWordUtil.createId()); - sysUserRole.setModifiedTime(new Date()); + sysUserRole.setCreateTime(new Date()); }); List save = sysUserRoleRepository.save(list); if (CollectionUtils.isNotEmpty(save)) { diff --git a/boot-web/src/main/java/com/xwbing/controller/SysRoleControl.java b/boot-web/src/main/java/com/xwbing/controller/SysRoleControl.java index 4caa499..4d7f9cb 100644 --- a/boot-web/src/main/java/com/xwbing/controller/SysRoleControl.java +++ b/boot-web/src/main/java/com/xwbing/controller/SysRoleControl.java @@ -2,7 +2,11 @@ package com.xwbing.controller; import com.alibaba.fastjson.JSONObject; import com.xwbing.annotation.LogInfo; +import com.xwbing.entity.SysAuthority; import com.xwbing.entity.SysRole; +import com.xwbing.entity.SysRoleAuthority; +import com.xwbing.service.SysAuthorityService; +import com.xwbing.service.SysRoleAuthorityService; import com.xwbing.service.SysRoleService; import com.xwbing.util.JSONObjResult; import com.xwbing.util.RestMessage; @@ -11,6 +15,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.List; /** @@ -25,6 +30,10 @@ import java.util.List; public class SysRoleControl { @Resource private SysRoleService sysRoleService; + @Resource + private SysAuthorityService sysAuthorityService; + @Resource + private SysRoleAuthorityService sysRoleAuthorityService; @LogInfo("添加角色") @PostMapping("save") @@ -66,6 +75,43 @@ public class SysRoleControl { return JSONObjResult.toJSONObj(sysRole, true, ""); } + @LogInfo("根据角色主键查找权限") + @PostMapping("listAuthorityByRoleId") + public JSONObject listAuthorityByRoleId(@RequestParam String roleId, String enable) { + if (StringUtils.isEmpty(roleId)) { + return JSONObjResult.toJSONObj("角色主键不能为空"); + } + SysRole sysRole = sysRoleService.getById(roleId); + if (sysRole == null) { + return JSONObjResult.toJSONObj("该角色不存在"); + } + List authoritys = sysAuthorityService.listByRoleIdEnable(roleId, enable); + return JSONObjResult.toJSONObj(authoritys, true, ""); + } + + @LogInfo("保存角色 权限主键") + @PostMapping("saveAuthoritys") + public JSONObject saveAuthoritys(@RequestParam String authorityIds, @RequestParam String roleId) { + if (StringUtils.isEmpty(authorityIds)) + return JSONObjResult.toJSONObj("权限主键集合不能为空"); + if (StringUtils.isEmpty(roleId)) + return JSONObjResult.toJSONObj("角色主键不能为空"); + SysRole sysRole = sysRoleService.getById(roleId); + if (sysRole == null) { + return JSONObjResult.toJSONObj("该角色不存在"); + } + String ids[] = authorityIds.split(","); + List list = new ArrayList<>(); + for (String id : ids) { + SysRoleAuthority roleAuthority = new SysRoleAuthority(); + roleAuthority.setRoleId(roleId); + roleAuthority.setAuthorityId(id); + list.add(roleAuthority); + } + RestMessage restMessage = sysRoleAuthorityService.saveBatch(list, roleId); + return JSONObjResult.toJSONObj(restMessage); + } + @LogInfo("根据是否启用查询所有角色") @GetMapping("listAllByEnable") public JSONObject listAllByEnable(@RequestParam String enable) { diff --git a/boot-web/src/main/java/com/xwbing/controller/SysUserControl.java b/boot-web/src/main/java/com/xwbing/controller/SysUserControl.java index ed45aed..0c23f99 100644 --- a/boot-web/src/main/java/com/xwbing/controller/SysUserControl.java +++ b/boot-web/src/main/java/com/xwbing/controller/SysUserControl.java @@ -136,8 +136,6 @@ public class SysUserControl { SysUser sysUser = sysUserService.getOne((String) CommonDataUtil.getToken(CommonConstant.CURRENT_USER_ID)); if (sysUser == null) return JSONObjResult.toJSONObj("未获取到当前登录用户信息"); - SysUser result = new SysUser(); - result.setUserName(sysUser.getUserName()); List other = new ArrayList<>(); List menu = new ArrayList<>(); List list; @@ -153,13 +151,13 @@ public class SysUserControl { other.add(sysAuthority); } } - result.setMenuArray(menu); - result.setOtherArray(other); - return JSONObjResult.toJSONObj(result, true, ""); + sysUser.setMenuArray(menu); + sysUser.setOtherArray(other); + return JSONObjResult.toJSONObj(sysUser, true, ""); } @LogInfo("保存用户角色") - @GetMapping("saveRole") + @PostMapping("saveRole") public JSONObject saveRole(@RequestParam String roleIds, @RequestParam String userId) { if (StringUtils.isEmpty(roleIds)) return JSONObjResult.toJSONObj("角色主键不能为空"); @@ -185,8 +183,8 @@ public class SysUserControl { } @LogInfo("根据用户主键查找所拥有的角色") - @GetMapping("queryRole") - public JSONObject queryRole(@RequestParam String userId, @RequestParam String enable) { + @PostMapping("listRoles") + public JSONObject listRoles(@RequestParam String userId, @RequestParam String enable) { if (StringUtils.isEmpty(userId)) return JSONObjResult.toJSONObj("用户主键不能为空"); if (StringUtils.isEmpty(enable)) @@ -196,7 +194,7 @@ public class SysUserControl { } @LogInfo("根据用户主键查找所拥有的权限") - @GetMapping("queryAuthority") + @PostMapping("queryAuthority") public JSONObject queryAuthority(@RequestParam String userId, @RequestParam String enable) { if (StringUtils.isEmpty(userId)) return JSONObjResult.toJSONObj("用户主键不能为空");