|
|
@@ -1,10 +1,7 @@
|
|
|
package com.hr.system.controller;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
@@ -78,20 +75,203 @@ public class SysUserController extends BaseController
|
|
|
@Autowired
|
|
|
private ISysMenuService menuService;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 获取用户列表
|
|
|
*/
|
|
|
@RequiresPermissions("system:user:list")
|
|
|
- @GetMapping("/list")
|
|
|
- public TableDataInfo list(SysUser user)
|
|
|
+ @PostMapping("/list")
|
|
|
+ public TableDataInfo queryUserList(@RequestBody SysUser user)
|
|
|
{
|
|
|
startPage();
|
|
|
- List<SysUser> list = userService.selectUserListBaseOrg(user);
|
|
|
+ List<SysUser> list = userService.selectUserList(user);
|
|
|
return getDataTable(list);
|
|
|
}
|
|
|
|
|
|
+// /**
|
|
|
+// * 注册用户信息
|
|
|
+// */
|
|
|
+// @InnerAuth
|
|
|
+// @PostMapping("/register")
|
|
|
+// public R<Boolean> register(@RequestBody SysUser sysUser)
|
|
|
+// {
|
|
|
+// String username = sysUser.getUserName();
|
|
|
+// if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser"))))
|
|
|
+// {
|
|
|
+// return R.fail("当前系统没有开启注册功能!");
|
|
|
+// }
|
|
|
+// if (!userService.checkUserNameUnique(sysUser))
|
|
|
+// {
|
|
|
+// return R.fail("保存用户'" + username + "'失败,注册账号已存在");
|
|
|
+// }
|
|
|
+// return R.ok(userService.registerUser(sysUser));
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增用户
|
|
|
+ */
|
|
|
+ @RequiresPermissions("system:user:add")
|
|
|
+ @Log(title = "用户管理", businessType = BusinessType.INSERT)
|
|
|
+ @PostMapping("/add")
|
|
|
+ public AjaxResult add(@Validated @RequestBody SysUser user)
|
|
|
+ {
|
|
|
+ //判断选择的部门和角色是否存在
|
|
|
+ SysDept dept = deptService.selectDeptById(user.getDeptId());
|
|
|
+ if (dept == null || "2".equals(dept.getDelFlag())){
|
|
|
+ return error("新增用户'" + user.getUserName() + "'失败,选择的部门不存在");
|
|
|
+ }
|
|
|
+ SysRole role = roleService.selectRoleById(user.getRoleId());
|
|
|
+ if (role == null || "2".equals(role.getDelFlag())){
|
|
|
+ return error("新增用户'" + user.getUserName() + "'失败,选择的角色不存在");
|
|
|
+ }
|
|
|
+ //检查用户名是否唯一
|
|
|
+ if (!userService.checkUserNameUnique(user))
|
|
|
+ {
|
|
|
+ return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
|
|
|
+ }
|
|
|
+ else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
|
|
|
+ {
|
|
|
+ return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
|
|
|
+ }
|
|
|
+ else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
|
|
|
+ {
|
|
|
+ return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
|
|
+ }
|
|
|
+ user.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
|
|
+ return toAjax(userService.insertUser(user));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改用户
|
|
|
+ */
|
|
|
+ @RequiresPermissions("system:user:edit")
|
|
|
+ @Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
|
|
+ @PostMapping("/edit")
|
|
|
+ public AjaxResult edit(@Validated @RequestBody SysUser user)
|
|
|
+ {
|
|
|
+ //判断选择的部门和角色是否存在
|
|
|
+ SysDept dept = deptService.selectDeptById(user.getDeptId());
|
|
|
+ if (dept == null || "2".equals(dept.getDelFlag())){
|
|
|
+ return error("新增用户'" + user.getUserName() + "'失败,选择的部门不存在");
|
|
|
+ }
|
|
|
+ SysRole role = roleService.selectRoleById(user.getRoleId());
|
|
|
+ if (role == null || "2".equals(role.getDelFlag())){
|
|
|
+ return error("新增用户'" + user.getUserName() + "'失败,选择的角色不存在");
|
|
|
+ }
|
|
|
+ else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
|
|
|
+ {
|
|
|
+ return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
|
|
+ }
|
|
|
+ else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
|
|
|
+ {
|
|
|
+ return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
|
|
+ }
|
|
|
+ user.setUpdateBy(SecurityUtils.getUsername());
|
|
|
+ return toAjax(userService.updateUser(user));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除用户
|
|
|
+ */
|
|
|
+ @RequiresPermissions("system:user:remove")
|
|
|
+ @Log(title = "用户管理", businessType = BusinessType.DELETE)
|
|
|
+ @PostMapping("/delete")
|
|
|
+ public AjaxResult delete(@Validated @RequestBody Long[] userIds)
|
|
|
+ {
|
|
|
+ if (ArrayUtils.contains(userIds, SecurityUtils.getUserId()))
|
|
|
+ {
|
|
|
+ return error("当前登录用户“"+SecurityUtils.getUsername()+"”不能删除");
|
|
|
+ }
|
|
|
+ return toAjax(userService.deleteUserByIds(userIds));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前登录的用户信息
|
|
|
+ *
|
|
|
+ * @return 用户信息
|
|
|
+ */
|
|
|
+ @GetMapping("getInfo")
|
|
|
+ public AjaxResult getInfo()
|
|
|
+ {
|
|
|
+ LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
+ SysUser user = loginUser.getSysUser();
|
|
|
+ // 角色集合
|
|
|
+ Set<String> roles = permissionService.getRolePermission(user);
|
|
|
+ // 权限集合
|
|
|
+ Set<String> permissions = permissionService.getMenuPermission(user);
|
|
|
+ if (!loginUser.getPermissions().equals(permissions))
|
|
|
+ {
|
|
|
+ loginUser.setPermissions(permissions);
|
|
|
+ tokenService.refreshToken(loginUser);
|
|
|
+ }
|
|
|
+ AjaxResult ajax = AjaxResult.success();
|
|
|
+ ajax.put("user", user);
|
|
|
+ ajax.put("roles", roles);
|
|
|
+ ajax.put("permissions", permissions);
|
|
|
+ return ajax;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *记录用户登录IP地址和登录时间
|
|
|
+ */
|
|
|
+ @InnerAuth
|
|
|
+ @PostMapping("/recordlogin")
|
|
|
+ public R<Boolean> recordlogin(@RequestBody SysUser sysUser)
|
|
|
+ {
|
|
|
+ SysUser updateSysUser = userService.selectUserById(sysUser.getUserId());
|
|
|
+ updateSysUser.setLoginIp(sysUser.getLoginIp());
|
|
|
+ updateSysUser.setLoginDate(sysUser.getLoginDate());
|
|
|
+ return R.ok(userService.updateUserProfile(updateSysUser));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据用户ID获取用户信息
|
|
|
+ */
|
|
|
+ @PostMapping("/getUserInfoById")
|
|
|
+ public AjaxResult getUserInfoById(@RequestBody SysUser sysUser)
|
|
|
+ {
|
|
|
+ SysUser user = userService.selectUserById(sysUser.getUserId());
|
|
|
+ AjaxResult ajax = AjaxResult.success();
|
|
|
+ ajax.put("user", user);
|
|
|
+ return ajax;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /****************下面接口无用********************/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户授权角色
|
|
|
+ */
|
|
|
+ @RequiresPermissions("system:user:edit")
|
|
|
+ @Log(title = "用户管理", businessType = BusinessType.GRANT)
|
|
|
+ @PutMapping("/authRole")
|
|
|
+ public AjaxResult insertAuthRole(Long userId, Long[] roleIds)
|
|
|
+ {
|
|
|
+ userService.checkUserDataScope(userId);
|
|
|
+ roleService.checkRoleDataScope(roleIds);
|
|
|
+ userService.insertUserAuth(userId, roleIds);
|
|
|
+ return success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取部门树列表
|
|
|
+ */
|
|
|
+ @RequiresPermissions("system:user:list")
|
|
|
+ @GetMapping("/deptTree")
|
|
|
+ public AjaxResult deptTree(SysDept dept)
|
|
|
+ {
|
|
|
+ return success(deptService.selectDeptTreeList(dept));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Log(title = "用户管理", businessType = BusinessType.EXPORT)
|
|
|
@RequiresPermissions("system:user:export")
|
|
|
@PostMapping("/export")
|
|
|
@@ -134,7 +314,20 @@ public class SysUserController extends BaseController
|
|
|
return R.fail("用户名或密码错误");
|
|
|
}
|
|
|
// 角色集合
|
|
|
- Set<String> roles = permissionService.getRolePermission(sysUser);
|
|
|
+// Set<String> roles = permissionService.getRolePermission(sysUser);
|
|
|
+ List<SysRole> roleslist=permissionService.getRoleList(sysUser);
|
|
|
+
|
|
|
+ Set<String> roles = new HashSet<>();
|
|
|
+ for (SysRole perm : roleslist)
|
|
|
+ {
|
|
|
+ if (StringUtils.isNotNull(perm))
|
|
|
+ {
|
|
|
+ roles.addAll(Arrays.asList(perm.getRoleKey().trim().split(",")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ LoginUser sysUserVo = new LoginUser();
|
|
|
+
|
|
|
// 权限集合
|
|
|
Set<String> permissions = permissionService.getMenuPermission(sysUser);
|
|
|
|
|
|
@@ -142,7 +335,9 @@ public class SysUserController extends BaseController
|
|
|
* 新增代码查询出当前用户的所有菜单(包括按钮),以便获取菜单权限
|
|
|
*/
|
|
|
List<SysMenu> menus = menuService.selectMenuTreeByUserId2(sysUser.getUserId());
|
|
|
- JSONObject menump=dealMenuMap(menus);
|
|
|
+// JSONObject menump=dealMenuMap(menus);
|
|
|
+ JSONObject menump=calcUserMenuList( menus,roleslist);
|
|
|
+ sysUserVo.setSysMenuUrls(menump);
|
|
|
|
|
|
/**
|
|
|
* 新增代码获取当前用户的岗位
|
|
|
@@ -153,13 +348,13 @@ public class SysUserController extends BaseController
|
|
|
userpstlststr.add(_s.getPostCode());
|
|
|
}
|
|
|
|
|
|
- LoginUser sysUserVo = new LoginUser();
|
|
|
+
|
|
|
|
|
|
/***
|
|
|
* 设置当前用户的菜单路径集合
|
|
|
*/
|
|
|
- sysUserVo.setSysMenuUrls(menump);
|
|
|
- sysUserVo.setSysPostsList(userpstlststr);
|
|
|
+// sysUserVo.setSysMenuUrls(menump);
|
|
|
+// sysUserVo.setSysPostsList(userpstlststr);
|
|
|
|
|
|
|
|
|
/*****
|
|
|
@@ -192,135 +387,74 @@ public class SysUserController extends BaseController
|
|
|
// if(_d.getDepType().equals("base")){
|
|
|
// userorgdept=_d;
|
|
|
// }
|
|
|
- sysUserVo.setUserDeptList(deptlist);
|
|
|
- }
|
|
|
-
|
|
|
- //用户只能关联一个基础组织机构id
|
|
|
- if(userorgdept!=null) {
|
|
|
- sysUserVo.setDepCode(userorgdept.getAncestors());
|
|
|
- sysUserVo.setDepId(userorgdept.getDeptId());
|
|
|
-// sysUserVo.setOrgCode(userorgdept.getOrgCode());
|
|
|
+// sysUserVo.setUserDeptList(deptlist);
|
|
|
}
|
|
|
|
|
|
- Map<String, List<SysDeptDto>> groupedByDepTypemap = deptlist.stream()
|
|
|
- .collect(Collectors.groupingBy(SysDeptDto::getDepType));
|
|
|
-
|
|
|
-
|
|
|
- JSONObject depinfo=new JSONObject();
|
|
|
- //filename --> = like in
|
|
|
- //userid 本人
|
|
|
- //dept_id 组织id List Long
|
|
|
- //dept_code 组织编码 List String
|
|
|
- //auth_cs_dept_id 业务组织id List Long
|
|
|
- //auth_cs_dept_code 业务组织编码 List String
|
|
|
-// depinfo.put("userid",sysUser.getUserId());
|
|
|
- depinfo.put("=",new JSONObject());
|
|
|
- depinfo.put("in",new JSONObject());
|
|
|
- depinfo.put("like",new JSONObject());
|
|
|
-
|
|
|
- for(SysRole _r:roleList){
|
|
|
-
|
|
|
- //开始循环不同业务类型下面的数据
|
|
|
- for(String _k:groupedByDepTypemap.keySet()) {
|
|
|
- //1全部数据 2自定义 3本部门权限 4本部门以及以下 5本人
|
|
|
- //如果是2,自定义,需要将当前角色关联的部门Ids加入进来
|
|
|
- if (_r.getDataScope().equals("2") && _k.equals(_r.getRoleDeptType())) {
|
|
|
- String _filename="dep_id";
|
|
|
- if(!_k.equals("base")){
|
|
|
- _filename="auth_"+_k+"_depid";
|
|
|
- }
|
|
|
|
|
|
- JSONObject depinfo1=depinfo.getJSONObject("in");
|
|
|
- if(!depinfo1.containsKey(_filename)){
|
|
|
- depinfo1.put(_filename,new ArrayList<Long>());
|
|
|
- }
|
|
|
- List<Long> _depidlist=depinfo1.getObject( _filename, List.class);
|
|
|
-// deptService.selectDeptListByRoleId(roleId)
|
|
|
- _depidlist.addAll( deptService.selectDeptListByRoleId(_r.getRoleId(),_k));
|
|
|
- depinfo1.put(_filename,_depidlist);
|
|
|
- }
|
|
|
- //3本部门权限
|
|
|
- if (_r.getDataScope().equals("3") && _k.equals(_r.getRoleDeptType())) {
|
|
|
|
|
|
- String _filename="dep_id";
|
|
|
- if(!_k.equals("base")){
|
|
|
- _filename="auth_"+_k+"_depid";
|
|
|
- }
|
|
|
+// Map<String, List<SysDeptDto>> groupedByDepTypemap = deptlist.stream()
|
|
|
+// .collect(Collectors.groupingBy(SysDeptDto::getDepType));
|
|
|
|
|
|
- JSONObject depinfo1=depinfo.getJSONObject("in");
|
|
|
- if(!depinfo1.containsKey(_filename)){
|
|
|
- depinfo1.put(_filename,new ArrayList<Long>());
|
|
|
- }
|
|
|
- List<Long> _depidlist=depinfo1.getObject( _filename, List.class);
|
|
|
- //根据用户id和业务组织类型查询组织id
|
|
|
- _depidlist.addAll( deptService.selectDeptListByuserId(sysUser.getUserId(),_k));
|
|
|
- depinfo1.put(_filename,_depidlist);
|
|
|
|
|
|
- }
|
|
|
-// 4本部门以及以下
|
|
|
- if(_r.getDataScope().equals("4") && _k.equals(_r.getRoleDeptType())){
|
|
|
+ sysUserVo.setSysUser(sysUser);
|
|
|
+ sysUserVo.setRoles(roles);
|
|
|
+ sysUserVo.setPermissions(permissions);
|
|
|
+ return R.ok(sysUserVo);
|
|
|
+ }
|
|
|
|
|
|
- String _filename="dep_code";
|
|
|
- if(!_k.equals("base")){
|
|
|
- _filename="auth_"+_k+"_depcode";
|
|
|
- }
|
|
|
+ private JSONObject calcUserMenuList(List<SysMenu> menus,List<SysRole> roleList){
|
|
|
+ JSONObject menumap=new JSONObject();
|
|
|
+ Map<String,Object> roleKeyMap=new HashMap<>();
|
|
|
+ for(SysRole r:roleList){
|
|
|
+ String[] _spl=r.getRoleKey().split(",");
|
|
|
+ for(String _k:_spl){
|
|
|
+ roleKeyMap.put(_k,null);
|
|
|
+ }
|
|
|
|
|
|
- JSONObject depinfo1=depinfo.getJSONObject("like");
|
|
|
- if(!depinfo1.containsKey(_filename)){
|
|
|
- depinfo1.put(_filename,new ArrayList<Long>());
|
|
|
- }
|
|
|
- List<String> _depidlist=depinfo1.getObject( _filename, List.class);
|
|
|
- //根据用户id和业务组织类型查询组织id
|
|
|
- _depidlist.addAll( deptService.selectDeptListByuserIdChild(sysUser.getUserId(),_k));
|
|
|
- depinfo1.put(_filename,_depidlist);
|
|
|
- }
|
|
|
- //5本人
|
|
|
- if ( _r.getDataScope().equals("5") && _k.equals(_r.getRoleDeptType())) {
|
|
|
- String _filename="creater_id";
|
|
|
- JSONObject depinfo1=depinfo.getJSONObject("=");
|
|
|
- depinfo1.put( _filename, sysUser.getUserId());
|
|
|
+ }
|
|
|
+ for(SysMenu _m:menus){
|
|
|
+ depthCalcMenuMapDealMenu(_m,menumap,menumap,roleKeyMap);
|
|
|
+ }
|
|
|
+ return menumap;
|
|
|
+ }
|
|
|
+ private void depthCalcMenuMapDealMenu(SysMenu _m,JSONObject menumap,JSONObject dynamicmap,Map<String,Object> roleKeyMap){
|
|
|
+ JSONObject _curmap=dynamicmap;
|
|
|
+ if(_m.getUrl()!=null) {
|
|
|
+ _curmap=getLastJson(_m,menumap);
|
|
|
|
|
|
+ if(StringUtils.isNotEmpty(_m.getUrlmatch())) {
|
|
|
+ delPermsSet(_curmap, _m.getUrlmatch());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONArray permsarr=new JSONArray();
|
|
|
+ if (menumap.containsKey(permsKey)) {
|
|
|
+ permsarr = menumap.getJSONArray(permsKey);
|
|
|
+ }
|
|
|
+ boolean flag= false;
|
|
|
+ if(roleKeyMap.size()>0 && permsarr.size()>0){
|
|
|
+ int count=0;
|
|
|
+ for (Object obj : permsarr) {
|
|
|
+ String item = (String) obj;
|
|
|
+ if(roleKeyMap.containsKey(item)){
|
|
|
+ count++;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ if( count>0){
|
|
|
+ flag=true;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ flag=true;
|
|
|
}
|
|
|
- sysUserVo.setAuthInfo(depinfo);
|
|
|
-
|
|
|
-
|
|
|
- /***
|
|
|
- sysUserVo.setDepidlist(depidlist);
|
|
|
-
|
|
|
- sysUserVo.setDatascopelist(new ArrayList<>());
|
|
|
-
|
|
|
-
|
|
|
- for(SysRole _r:roleList){
|
|
|
- //排除超级管理员
|
|
|
- // ##################和自定义数据权限,合并在一起了,权限,只排除超级管理员
|
|
|
- if(_r.getDataScope()!=null &&
|
|
|
- !(_r.getDataScope().equals("1")
|
|
|
-// || _r.getDataScope().equals("2")
|
|
|
- )) {
|
|
|
-// sysUserVo.getDatascopelist().add(_r.getDataScope() + ":" + sysUser.getDept().getAncestors());
|
|
|
- //设置权限2#base:deptid@201,202,203;deptcode@0,100,201#
|
|
|
-
|
|
|
- for(SysDept _d:userdeps){
|
|
|
-
|
|
|
+ if(flag) {
|
|
|
+ if (_m.getChildren() != null && _m.getChildren().size() > 0) {
|
|
|
+ for (SysMenu _m2 : _m.getChildren()) {
|
|
|
+ depthCalcMenuMapDealMenu(_m2, menumap,_curmap, roleKeyMap);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-***/
|
|
|
-
|
|
|
-
|
|
|
-// sysUserVo.setDepId(dep.getDeptId());
|
|
|
-// sysUserVo.setDepCode(dep.getAncestors());
|
|
|
-
|
|
|
-
|
|
|
- sysUserVo.setSysUser(sysUser);
|
|
|
- sysUserVo.setRoles(roles);
|
|
|
- sysUserVo.setPermissions(permissions);
|
|
|
- return R.ok(sysUserVo);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private JSONObject dealMenuMap(List<SysMenu> menus){
|
|
|
JSONObject menumap=new JSONObject();
|
|
|
for(SysMenu _m:menus){
|
|
|
@@ -331,17 +465,16 @@ public class SysUserController extends BaseController
|
|
|
|
|
|
private void depthDealMenuMapDealMenu(SysMenu _m,JSONObject menumap,JSONObject dynamicmap){
|
|
|
JSONObject _curmap=dynamicmap;
|
|
|
- //如果当前没有设置地址的,则看当前的SysMenu是否有权限字段,如果有则设置当前的权限字段permsKey
|
|
|
- if(_m.getComponent()!=null) {
|
|
|
- String _perms=_m.getPerms();
|
|
|
+
|
|
|
+ if(_m.getUrl()!=null) {
|
|
|
+
|
|
|
_curmap=getLastJson(_m,menumap);
|
|
|
- }
|
|
|
- else{
|
|
|
- //如果当前没有设置地址的,则看当前的SysMenu是否有权限字段,如果有则设置当前的权限字段permsKey
|
|
|
- if(StringUtils.isNotEmpty(_m.getPerms())) {
|
|
|
- delPermsSet(_curmap, _m.getPerms());
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(_m.getUrlmatch())) {
|
|
|
+ delPermsSet(_curmap, _m.getUrlmatch());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
if(_m.getChildren()!=null && _m.getChildren().size()>0) {
|
|
|
for(SysMenu _m2:_m.getChildren()) {
|
|
|
depthDealMenuMapDealMenu(_m2,menumap, _curmap);
|
|
|
@@ -351,7 +484,7 @@ public class SysUserController extends BaseController
|
|
|
}
|
|
|
|
|
|
private void delPermsSet(JSONObject menumap,String perms){
|
|
|
- //如果当前已经有权限字段,则需要去重
|
|
|
+
|
|
|
if(StringUtils.isNotEmpty(perms)) {
|
|
|
JSONArray arr=null;
|
|
|
if (menumap.containsKey(permsKey)) {
|
|
|
@@ -373,12 +506,12 @@ public class SysUserController extends BaseController
|
|
|
|
|
|
private JSONObject getLastJson(SysMenu _m,JSONObject menumap){
|
|
|
JSONObject _curmap=menumap;
|
|
|
- String _path=_m.getComponent();
|
|
|
+ String _path=_m.getUrl();
|
|
|
if(StringUtils.isNotEmpty(_path)) {
|
|
|
if (_path.startsWith("/")) {
|
|
|
_path = _path.substring(1);
|
|
|
}
|
|
|
- //如果当前url带?的,则需要去掉?后面的数据
|
|
|
+
|
|
|
int hasparmidx = _path.indexOf("?");
|
|
|
if (hasparmidx > 1) {
|
|
|
_path = _path.substring(0, hasparmidx);
|
|
|
@@ -407,60 +540,8 @@ public class SysUserController extends BaseController
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 注册用户信息
|
|
|
- */
|
|
|
- @InnerAuth
|
|
|
- @PostMapping("/register")
|
|
|
- public R<Boolean> register(@RequestBody SysUser sysUser)
|
|
|
- {
|
|
|
- String username = sysUser.getUserName();
|
|
|
- if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser"))))
|
|
|
- {
|
|
|
- return R.fail("当前系统没有开启注册功能!");
|
|
|
- }
|
|
|
- if (!userService.checkUserNameUnique(sysUser))
|
|
|
- {
|
|
|
- return R.fail("保存用户'" + username + "'失败,注册账号已存在");
|
|
|
- }
|
|
|
- return R.ok(userService.registerUser(sysUser));
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- *记录用户登录IP地址和登录时间
|
|
|
- */
|
|
|
- @InnerAuth
|
|
|
- @PutMapping("/recordlogin")
|
|
|
- public R<Boolean> recordlogin(@RequestBody SysUser sysUser)
|
|
|
- {
|
|
|
- return R.ok(userService.updateUserProfile(sysUser));
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 获取用户信息
|
|
|
- *
|
|
|
- * @return 用户信息
|
|
|
- */
|
|
|
- @GetMapping("getInfo")
|
|
|
- public AjaxResult getInfo()
|
|
|
- {
|
|
|
- LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
- SysUser user = loginUser.getSysUser();
|
|
|
- // 角色集合
|
|
|
- Set<String> roles = permissionService.getRolePermission(user);
|
|
|
- // 权限集合
|
|
|
- Set<String> permissions = permissionService.getMenuPermission(user);
|
|
|
- if (!loginUser.getPermissions().equals(permissions))
|
|
|
- {
|
|
|
- loginUser.setPermissions(permissions);
|
|
|
- tokenService.refreshToken(loginUser);
|
|
|
- }
|
|
|
- AjaxResult ajax = AjaxResult.success();
|
|
|
- ajax.put("user", user);
|
|
|
- ajax.put("roles", roles);
|
|
|
- ajax.put("permissions", permissions);
|
|
|
- return ajax;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 根据用户编号获取详细信息
|
|
|
@@ -484,75 +565,9 @@ public class SysUserController extends BaseController
|
|
|
return ajax;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 新增用户
|
|
|
- */
|
|
|
- @RequiresPermissions("system:user:add")
|
|
|
- @Log(title = "用户管理", businessType = BusinessType.INSERT)
|
|
|
- @PostMapping
|
|
|
- public AjaxResult add(@Validated @RequestBody SysUser user)
|
|
|
- {
|
|
|
- deptService.checkDeptDataScope(user.getDeptId());
|
|
|
- roleService.checkRoleDataScope(user.getRoleIds());
|
|
|
- if (!userService.checkUserNameUnique(user))
|
|
|
- {
|
|
|
- return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
|
|
|
- }
|
|
|
- else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
|
|
|
- {
|
|
|
- return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
|
|
|
- }
|
|
|
- else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
|
|
|
- {
|
|
|
- return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
|
|
- }
|
|
|
- user.setCreateBy(SecurityUtils.getUsername());
|
|
|
- user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
|
|
- return toAjax(userService.insertUser(user));
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 修改用户
|
|
|
- */
|
|
|
- @RequiresPermissions("system:user:edit")
|
|
|
- @Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
|
|
- @PutMapping
|
|
|
- public AjaxResult edit(@Validated @RequestBody SysUser user)
|
|
|
- {
|
|
|
- userService.checkUserAllowed(user);
|
|
|
- userService.checkUserDataScope(user.getUserId());
|
|
|
- deptService.checkDeptDataScope(user.getDeptId());
|
|
|
- roleService.checkRoleDataScope(user.getRoleIds());
|
|
|
- if (!userService.checkUserNameUnique(user))
|
|
|
- {
|
|
|
- return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
|
|
|
- }
|
|
|
- else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
|
|
|
- {
|
|
|
- return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
|
|
- }
|
|
|
- else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
|
|
|
- {
|
|
|
- return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
|
|
- }
|
|
|
- user.setUpdateBy(SecurityUtils.getUsername());
|
|
|
- return toAjax(userService.updateUser(user));
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 删除用户
|
|
|
- */
|
|
|
- @RequiresPermissions("system:user:remove")
|
|
|
- @Log(title = "用户管理", businessType = BusinessType.DELETE)
|
|
|
- @DeleteMapping("/{userIds}")
|
|
|
- public AjaxResult remove(@PathVariable Long[] userIds)
|
|
|
- {
|
|
|
- if (ArrayUtils.contains(userIds, SecurityUtils.getUserId()))
|
|
|
- {
|
|
|
- return error("当前用户不能删除");
|
|
|
- }
|
|
|
- return toAjax(userService.deleteUserByIds(userIds));
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 重置密码
|
|
|
@@ -583,42 +598,5 @@ public class SysUserController extends BaseController
|
|
|
return toAjax(userService.updateUserStatus(user));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 根据用户编号获取授权角色
|
|
|
- */
|
|
|
- @RequiresPermissions("system:user:query")
|
|
|
- @GetMapping("/authRole/{userId}")
|
|
|
- public AjaxResult authRole(@PathVariable("userId") Long userId)
|
|
|
- {
|
|
|
- AjaxResult ajax = AjaxResult.success();
|
|
|
- SysUser user = userService.selectUserById(userId);
|
|
|
- List<SysRole> roles = roleService.selectRolesByUserId(userId);
|
|
|
- ajax.put("user", user);
|
|
|
- ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
|
|
|
- return ajax;
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 用户授权角色
|
|
|
- */
|
|
|
- @RequiresPermissions("system:user:edit")
|
|
|
- @Log(title = "用户管理", businessType = BusinessType.GRANT)
|
|
|
- @PutMapping("/authRole")
|
|
|
- public AjaxResult insertAuthRole(Long userId, Long[] roleIds)
|
|
|
- {
|
|
|
- userService.checkUserDataScope(userId);
|
|
|
- roleService.checkRoleDataScope(roleIds);
|
|
|
- userService.insertUserAuth(userId, roleIds);
|
|
|
- return success();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取部门树列表
|
|
|
- */
|
|
|
- @RequiresPermissions("system:user:list")
|
|
|
- @GetMapping("/deptTree")
|
|
|
- public AjaxResult deptTree(SysDept dept)
|
|
|
- {
|
|
|
- return success(deptService.selectDeptTreeList(dept));
|
|
|
- }
|
|
|
}
|