|
|
@ -6,9 +6,14 @@ import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.kms.system.domain.SysRoleMenu; |
|
|
|
import com.kms.common.utils.UserUtils; |
|
|
|
import com.kms.framework.manager.AsyncManager; |
|
|
|
import com.kms.framework.manager.factory.AsyncFactory; |
|
|
|
import com.kms.framework.web.service.SysPermissionService; |
|
|
|
import com.kms.system.service.SysMenuService; |
|
|
|
import com.kms.system.service.SysRoleMenuService; |
|
|
|
import com.kms.system.service.SysRoleService; |
|
|
|
import com.kms.system.service.SysUserService; |
|
|
|
import com.kms.web.utils.WaterRequestUtil; |
|
|
|
import com.kms.web.utils.WaterResult; |
|
|
|
import com.kms.web.utils.singleDomain.SingleMenu; |
|
|
@ -17,7 +22,6 @@ import com.shuili.common.constant.YesOrNo; |
|
|
|
import com.shuili.common.core.controller.BaseController; |
|
|
|
import com.shuili.common.core.domain.AjaxResult; |
|
|
|
import com.shuili.common.core.domain.entity.SysMenu; |
|
|
|
import com.shuili.common.core.domain.entity.SysRole; |
|
|
|
import com.shuili.common.core.domain.entity.SysUser; |
|
|
|
import com.shuili.common.core.domain.model.LoginBody; |
|
|
|
import com.shuili.common.core.redis.RedisCache; |
|
|
@ -27,12 +31,6 @@ import com.shuili.common.exception.CustomException; |
|
|
|
import com.shuili.common.mybaitsplus.BeanToWrapper; |
|
|
|
import com.shuili.common.utils.StringUtils; |
|
|
|
import com.shuili.common.utils.password.PasswordUtil; |
|
|
|
import com.kms.common.utils.UserUtils; |
|
|
|
import com.kms.framework.manager.AsyncManager; |
|
|
|
import com.kms.framework.manager.factory.AsyncFactory; |
|
|
|
import com.kms.framework.web.service.SysPermissionService; |
|
|
|
import com.kms.system.service.SysMenuService; |
|
|
|
import com.kms.system.service.SysUserService; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import lombok.extern.log4j.Log4j2; |
|
|
@ -64,33 +62,33 @@ import java.util.stream.Collectors; |
|
|
|
@Api("用户登录") |
|
|
|
public class SysLoginController extends BaseController { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SysMenuService menuService; |
|
|
|
@Autowired |
|
|
|
private SysMenuService menuService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SysPermissionService permissionService; |
|
|
|
@Autowired |
|
|
|
private SysUserService userService; |
|
|
|
@Autowired |
|
|
|
private RedisCache redisCache; |
|
|
|
@Autowired |
|
|
|
WaterRequestUtil waterRequestUtil; |
|
|
|
@Value("${water.redirect:}") |
|
|
|
private String redirect; |
|
|
|
@Autowired |
|
|
|
private SysPermissionService permissionService; |
|
|
|
@Autowired |
|
|
|
private SysUserService userService; |
|
|
|
@Autowired |
|
|
|
private RedisCache redisCache; |
|
|
|
@Autowired |
|
|
|
WaterRequestUtil waterRequestUtil; |
|
|
|
@Value("${water.redirect:}") |
|
|
|
private String redirect; |
|
|
|
|
|
|
|
@PostMapping("/login") |
|
|
|
@ApiOperation("登录接口") |
|
|
|
public AjaxResult login(@RequestBody LoginBody loginBody) { |
|
|
|
@PostMapping("/login") |
|
|
|
@ApiOperation("登录接口") |
|
|
|
public AjaxResult login(@RequestBody LoginBody loginBody) { |
|
|
|
|
|
|
|
if(StringUtils.isEmpty(loginBody.getUsername())){ |
|
|
|
log.info("登录用户:{} 不存在.", loginBody.getUsername()); |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginBody.getUsername(), Constants.LOGIN_FAIL, "用户不存在")); |
|
|
|
throw new BaseException("对不起,请输入您的账号!!"); |
|
|
|
} |
|
|
|
AjaxResult ajax = AjaxResult.success(); |
|
|
|
if (StringUtils.isEmpty(loginBody.getUsername())) { |
|
|
|
log.info("登录用户:{} 不存在.", loginBody.getUsername()); |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginBody.getUsername(), Constants.LOGIN_FAIL, "用户不存在")); |
|
|
|
throw new BaseException("对不起,请输入您的账号!!"); |
|
|
|
} |
|
|
|
AjaxResult ajax = AjaxResult.success(); |
|
|
|
|
|
|
|
// 验证码校验
|
|
|
|
//TODO
|
|
|
|
// 验证码校验
|
|
|
|
//TODO
|
|
|
|
// String verifyKey = Constants.CAPTCHA_CODE_KEY + loginBody.getUuid();
|
|
|
|
// if(!loginBody.getCode().equals(redisCache.getCacheObject(verifyKey))) {
|
|
|
|
// redisCache.deleteObject(verifyKey);
|
|
|
@ -99,129 +97,131 @@ public class SysLoginController extends BaseController { |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
SysUser user = new SysUser(); |
|
|
|
user.setUserName(loginBody.getUsername()); |
|
|
|
user.setIsPcUser(YesOrNo.NO); |
|
|
|
List<SysUser> selectUserList = userService.list(BeanToWrapper.getWrapper(user)); |
|
|
|
if (StringUtils.isEmpty(selectUserList)) { |
|
|
|
log.info("登录用户:{} 不存在.", loginBody.getUsername()); |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginBody.getUsername(), Constants.LOGIN_FAIL, "用户不存在")); |
|
|
|
throw new BaseException("对不起,您的账号:" + loginBody.getUsername() + " 不存在"); |
|
|
|
} |
|
|
|
user = selectUserList.get(0); |
|
|
|
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) { |
|
|
|
log.info("登录用户:{} 已被删除.", loginBody.getUsername()); |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginBody.getUsername(), Constants.LOGIN_FAIL, "账户已删除")); |
|
|
|
throw new BaseException("对不起,您的账号:" + loginBody.getUsername() + " 已被删除"); |
|
|
|
} else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { |
|
|
|
log.info("登录用户:{} 已被停用.", loginBody.getUsername()); |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginBody.getUsername(), Constants.LOGIN_FAIL, "账户已停用")); |
|
|
|
throw new BaseException("对不起,您的账号:" + loginBody.getUsername() + " 已停用"); |
|
|
|
} |
|
|
|
SysUser user = new SysUser(); |
|
|
|
user.setUserName(loginBody.getUsername()); |
|
|
|
user.setIsPcUser(YesOrNo.NO); |
|
|
|
List<SysUser> selectUserList = userService.list(BeanToWrapper.getWrapper(user)); |
|
|
|
if (StringUtils.isEmpty(selectUserList)) { |
|
|
|
log.info("登录用户:{} 不存在.", loginBody.getUsername()); |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginBody.getUsername(), Constants.LOGIN_FAIL, "用户不存在")); |
|
|
|
throw new BaseException("对不起,您的账号:" + loginBody.getUsername() + " 不存在"); |
|
|
|
} |
|
|
|
user = selectUserList.get(0); |
|
|
|
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) { |
|
|
|
log.info("登录用户:{} 已被删除.", loginBody.getUsername()); |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginBody.getUsername(), Constants.LOGIN_FAIL, "账户已删除")); |
|
|
|
throw new BaseException("对不起,您的账号:" + loginBody.getUsername() + " 已被删除"); |
|
|
|
} else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { |
|
|
|
log.info("登录用户:{} 已被停用.", loginBody.getUsername()); |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginBody.getUsername(), Constants.LOGIN_FAIL, "账户已停用")); |
|
|
|
throw new BaseException("对不起,您的账号:" + loginBody.getUsername() + " 已停用"); |
|
|
|
} |
|
|
|
|
|
|
|
// 判断密码校验
|
|
|
|
if(PasswordUtil.validatePassword(loginBody.getPassword(), user.getPassword())) { |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginBody.getUsername(), Constants.LOGIN_SUCCESS, "登录成功")); |
|
|
|
StpUtil.login(user.getId()); |
|
|
|
StpUtil.getSession().set("shuili-user",user); |
|
|
|
ajax.put("token",StpUtil.getTokenValue()); |
|
|
|
}else { |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginBody.getUsername(), Constants.LOGIN_FAIL, "账号或密码错误")); |
|
|
|
throw new BaseException("对不起,您的账号或密码错误"); |
|
|
|
} |
|
|
|
return ajax; |
|
|
|
} |
|
|
|
// 判断密码校验
|
|
|
|
if (PasswordUtil.validatePassword(loginBody.getPassword(), user.getPassword())) { |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginBody.getUsername(), Constants.LOGIN_SUCCESS, "登录成功")); |
|
|
|
StpUtil.login(user.getId()); |
|
|
|
StpUtil.getSession().set("shuili-user", user); |
|
|
|
ajax.put("token", StpUtil.getTokenValue()); |
|
|
|
} else { |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginBody.getUsername(), Constants.LOGIN_FAIL, "账号或密码错误")); |
|
|
|
throw new BaseException("对不起,您的账号或密码错误"); |
|
|
|
} |
|
|
|
return ajax; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取用户信息 |
|
|
|
* |
|
|
|
* @return 用户信息 |
|
|
|
*/ |
|
|
|
@ApiOperation("获取挡路用户信息") |
|
|
|
@GetMapping("getInfo") |
|
|
|
public AjaxResult getInfo() { |
|
|
|
SysUser user = UserUtils.getUser(); |
|
|
|
// 角色集合
|
|
|
|
Set<String> roles = permissionService.getRolePermission(user); |
|
|
|
// 权限集合
|
|
|
|
Set<String> permissions = permissionService.getMenuPermission(user); |
|
|
|
AjaxResult ajax = AjaxResult.success(); |
|
|
|
/** |
|
|
|
* 获取用户信息 |
|
|
|
* |
|
|
|
* @return 用户信息 |
|
|
|
*/ |
|
|
|
@ApiOperation("获取挡路用户信息") |
|
|
|
@GetMapping("getInfo") |
|
|
|
public AjaxResult getInfo() { |
|
|
|
SysUser user = UserUtils.getUser(); |
|
|
|
// 角色集合
|
|
|
|
Set<String> roles = permissionService.getRolePermission(user); |
|
|
|
// 权限集合
|
|
|
|
Set<String> permissions = permissionService.getMenuPermission(user); |
|
|
|
AjaxResult ajax = AjaxResult.success(); |
|
|
|
|
|
|
|
|
|
|
|
ajax.put("user", user); |
|
|
|
ajax.put("roles", roles); |
|
|
|
ajax.put("permissions", permissions); |
|
|
|
// 判断是否需要展示创建索引按钮
|
|
|
|
ajax.put("user", user); |
|
|
|
ajax.put("roles", roles); |
|
|
|
ajax.put("permissions", permissions); |
|
|
|
// 判断是否需要展示创建索引按钮
|
|
|
|
|
|
|
|
return ajax; |
|
|
|
} |
|
|
|
return ajax; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取路由信息 |
|
|
|
* |
|
|
|
* @return 路由信息 |
|
|
|
*/ |
|
|
|
@GetMapping("getRouters") |
|
|
|
public AjaxResult getRouters() { |
|
|
|
// 用户信息
|
|
|
|
SysUser user = UserUtils.getUser(); |
|
|
|
List<SysMenu> menus = menuService.selectMenuTreeByUserId(user.getId()); |
|
|
|
return AjaxResult.success(menuService.buildMenus(menus)); |
|
|
|
} |
|
|
|
/** |
|
|
|
* 获取路由信息 |
|
|
|
* |
|
|
|
* @return 路由信息 |
|
|
|
*/ |
|
|
|
@GetMapping("getRouters") |
|
|
|
public AjaxResult getRouters() { |
|
|
|
// 用户信息
|
|
|
|
SysUser user = UserUtils.getUser(); |
|
|
|
List<SysMenu> menus = menuService.selectMenuTreeByUserId(user.getId()); |
|
|
|
menus.addAll(permissionService.getUserMenuFromPortal(user.getId())); |
|
|
|
return AjaxResult.success(menuService.buildMenus(menus)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 门户单点认证登录 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@GetMapping("/signOnLogin") |
|
|
|
public ModelAndView signOnLogin(HttpServletRequest request, |
|
|
|
HttpServletResponse response, |
|
|
|
@RequestParam(name = "page",required = false) String page, |
|
|
|
@RequestParam(name = "token")String token) throws IOException { |
|
|
|
WaterResult waterResult; |
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(1); |
|
|
|
try { |
|
|
|
waterResult = waterRequestUtil.authUser(token); |
|
|
|
}catch (Exception e){ |
|
|
|
log.error(e.getMessage()); |
|
|
|
throw new CustomException("登录失败"); |
|
|
|
} |
|
|
|
//异步执行菜单同步
|
|
|
|
executorService.submit(new RolePerms(token,waterResult,countDownLatch)); |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(waterResult.getData()); |
|
|
|
String user = jsonObject.getString("user"); |
|
|
|
JSONObject userJsonObject = JSONObject.parseObject(user); |
|
|
|
String uid = userJsonObject.getString("id"); |
|
|
|
QueryWrapper<SysUser> query = Wrappers.query(); |
|
|
|
query.eq("single_user_id",uid); |
|
|
|
List<SysUser> list = userService.list(query); |
|
|
|
if(CollectionUtil.isEmpty(list)){ |
|
|
|
throw new CustomException("数据异常,登录失败"); |
|
|
|
} |
|
|
|
AjaxResult ajax = AjaxResult.success(); |
|
|
|
SysUser sysUser = list.get(0); |
|
|
|
if (UserStatus.DELETED.getCode().equals(sysUser.getDelFlag())) { |
|
|
|
log.info(" :{} 已被删除.", sysUser.getUserName()); |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_FAIL, "账户已删除")); |
|
|
|
throw new BaseException("对不起,您的账号:" + sysUser.getUserName() + " 已被删除"); |
|
|
|
} else if (UserStatus.DISABLE.getCode().equals(sysUser.getStatus())) { |
|
|
|
log.info("登录用户:{} 已被停用.", sysUser.getUserName()); |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_FAIL, "账户已停用")); |
|
|
|
throw new BaseException("对不起,您的账号:" + sysUser.getUserName() + " 已停用"); |
|
|
|
} |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_SUCCESS, "登录成功")); |
|
|
|
StpUtil.login(sysUser.getId()); |
|
|
|
StpUtil.getSession().set("jianwei-user",sysUser); |
|
|
|
String tokenValue = StpUtil.getTokenValue(); |
|
|
|
userService.updateWithReids(sysUser); |
|
|
|
ajax.put("token",tokenValue); |
|
|
|
ajax.put("authorization",token); |
|
|
|
try { |
|
|
|
countDownLatch.await(); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
/** |
|
|
|
* 门户单点认证登录 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@GetMapping("/signOnLogin") |
|
|
|
public ModelAndView signOnLogin(HttpServletRequest request, |
|
|
|
HttpServletResponse response, |
|
|
|
@RequestParam(name = "page", required = false) String page, |
|
|
|
@RequestParam(name = "token") String token) throws IOException { |
|
|
|
WaterResult waterResult; |
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(1); |
|
|
|
try { |
|
|
|
waterResult = waterRequestUtil.authUser(token); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error(e.getMessage()); |
|
|
|
throw new CustomException("登录失败"); |
|
|
|
} |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(waterResult.getData()); |
|
|
|
String user = jsonObject.getString("user"); |
|
|
|
JSONObject userJsonObject = JSONObject.parseObject(user); |
|
|
|
String uid = userJsonObject.getString("id"); |
|
|
|
QueryWrapper<SysUser> query = Wrappers.query(); |
|
|
|
query.eq("single_user_id", uid); |
|
|
|
List<SysUser> list = userService.list(query); |
|
|
|
if (CollectionUtil.isEmpty(list)) { |
|
|
|
throw new CustomException("数据异常,登录失败"); |
|
|
|
} |
|
|
|
AjaxResult ajax = AjaxResult.success(); |
|
|
|
SysUser sysUser = list.get(0); |
|
|
|
if (UserStatus.DELETED.getCode().equals(sysUser.getDelFlag())) { |
|
|
|
log.info(" :{} 已被删除.", sysUser.getUserName()); |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_FAIL, "账户已删除")); |
|
|
|
throw new BaseException("对不起,您的账号:" + sysUser.getUserName() + " 已被删除"); |
|
|
|
} else if (UserStatus.DISABLE.getCode().equals(sysUser.getStatus())) { |
|
|
|
log.info("登录用户:{} 已被停用.", sysUser.getUserName()); |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_FAIL, "账户已停用")); |
|
|
|
throw new BaseException("对不起,您的账号:" + sysUser.getUserName() + " 已停用"); |
|
|
|
} |
|
|
|
//异步执行菜单同步
|
|
|
|
executorService.submit(new RolePerms(token, waterResult, countDownLatch, sysUser.getId())); |
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_SUCCESS, "登录成功")); |
|
|
|
StpUtil.login(sysUser.getId()); |
|
|
|
StpUtil.getSession().set("jianwei-user", sysUser); |
|
|
|
String tokenValue = StpUtil.getTokenValue(); |
|
|
|
userService.updateWithReids(sysUser); |
|
|
|
ajax.put("token", tokenValue); |
|
|
|
ajax.put("authorization", token); |
|
|
|
try { |
|
|
|
countDownLatch.await(); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
// if(StringUtils.isEmpty(page)){
|
|
|
|
// List<SysMenu> menus = menuService.selectMenuTreeByUserId(sysUser.getId());
|
|
|
|
// List<RouterVo> routerVos = menuService.buildMenus(menus);
|
|
|
@ -240,25 +240,26 @@ public class SysLoginController extends BaseController { |
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
RedirectView redirectView = new RedirectView(redirect+"?token="+tokenValue+"&page="+page); |
|
|
|
ModelAndView modelAndView = new ModelAndView(redirectView); |
|
|
|
return modelAndView; |
|
|
|
} |
|
|
|
RedirectView redirectView = new RedirectView(redirect + "?token=" + tokenValue + "&page=" + page); |
|
|
|
ModelAndView modelAndView = new ModelAndView(redirectView); |
|
|
|
return modelAndView; |
|
|
|
} |
|
|
|
|
|
|
|
@Autowired |
|
|
|
SysRoleService sysRoleService; |
|
|
|
@Autowired |
|
|
|
SysRoleMenuService sysRoleMenuService; |
|
|
|
@Autowired |
|
|
|
SysMenuService sysMenuService; |
|
|
|
@Autowired |
|
|
|
SysRoleService sysRoleService; |
|
|
|
@Autowired |
|
|
|
SysRoleMenuService sysRoleMenuService; |
|
|
|
@Autowired |
|
|
|
SysMenuService sysMenuService; |
|
|
|
|
|
|
|
ExecutorService executorService = Executors.newFixedThreadPool(5); |
|
|
|
ExecutorService executorService = Executors.newFixedThreadPool(5); |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据用户token获取资源权限 |
|
|
|
* @param |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
/** |
|
|
|
* 根据用户token获取资源权限 |
|
|
|
* |
|
|
|
* @param |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
// @GetMapping("/getSingleRotes/{token}")
|
|
|
|
// public AjaxResult getSingleRotes(@PathVariable String token){
|
|
|
|
// WaterResult waterResult = waterRequestUtil.authUser(token);
|
|
|
@ -277,105 +278,69 @@ public class SysLoginController extends BaseController { |
|
|
|
// return AjaxResult.success(menuService.buildMenus(menus));
|
|
|
|
// }
|
|
|
|
|
|
|
|
class RolePerms implements Runnable{ |
|
|
|
class RolePerms implements Runnable { |
|
|
|
|
|
|
|
private final String token; |
|
|
|
private final WaterResult waterResult; |
|
|
|
private final CountDownLatch countDownLatch; |
|
|
|
private final String userId; |
|
|
|
|
|
|
|
public String token; |
|
|
|
public WaterResult waterResult; |
|
|
|
public CountDownLatch countDownLatch; |
|
|
|
public RolePerms(String token, WaterResult waterResult, CountDownLatch countDownLatch, String userId) { |
|
|
|
this.token = token; |
|
|
|
this.waterResult = waterResult; |
|
|
|
this.countDownLatch = countDownLatch; |
|
|
|
this.userId = userId; |
|
|
|
} |
|
|
|
|
|
|
|
public RolePerms(String token,WaterResult waterResult,CountDownLatch countDownLatch){ |
|
|
|
this.token = token; |
|
|
|
this.waterResult = waterResult; |
|
|
|
this.countDownLatch = countDownLatch; |
|
|
|
} |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public void run() { |
|
|
|
try { |
|
|
|
WaterResult result = waterRequestUtil.getUserResource(token); |
|
|
|
List<SingleMenu> singleMenus = JSONObject.parseArray(result.getData(), SingleMenu.class); |
|
|
|
List<SingleMenu> singleAllMenus = new ArrayList<>(); |
|
|
|
setChildren(singleMenus, singleAllMenus); |
|
|
|
String data = waterResult.getData(); |
|
|
|
JSONObject datajson = JSONObject.parseObject(data); |
|
|
|
List<String> functionPerms = datajson.getJSONArray("functionPerms").toJavaList(String.class); |
|
|
|
List<String> menuCode = singleMenus.stream().map(SingleMenu::getCode).distinct().collect(Collectors.toList()); |
|
|
|
permissionService.setUserPermissionFromPortal(userId, functionPerms); |
|
|
|
permissionService.setUserMenuFromPortal(userId, menuCode); |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public void run() { |
|
|
|
try { |
|
|
|
WaterResult result = waterRequestUtil.getUserResource(token); |
|
|
|
List<SingleMenu> singleMenus = JSONObject.parseArray(result.getData(), SingleMenu.class); |
|
|
|
List<SingleMenu> singleAllMenus = new ArrayList<>(); |
|
|
|
setChildren(singleMenus,singleAllMenus); |
|
|
|
String data = waterResult.getData(); |
|
|
|
JSONObject datajson = JSONObject.parseObject(data); |
|
|
|
List<String> functionPerms = datajson.getJSONArray("functionPerms").toJavaList(String.class); |
|
|
|
List<String> collect = singleAllMenus.stream().map(singleMenu -> singleMenu.getPermissionCode()).collect(Collectors.toList()); |
|
|
|
collect.addAll(functionPerms); |
|
|
|
QueryWrapper<SysMenu> menuQueryWrapper = Wrappers.query(); |
|
|
|
menuQueryWrapper.in("perms",collect); |
|
|
|
List<SysMenu> menus = sysMenuService.list(menuQueryWrapper); |
|
|
|
List<String> menuids = menus.stream().map(menu -> { |
|
|
|
return menu.getId(); |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
// WaterResult waterResult = waterRequestUtil.authUser(token);
|
|
|
|
List<String> roles = datajson.getJSONArray("roles").toJavaList(String.class); |
|
|
|
log.info("获取的权限有:"+roles); |
|
|
|
if(CollectionUtil.isNotEmpty(roles)) { |
|
|
|
QueryWrapper<SysRole> sysRoleQueryWrapper = Wrappers.query(); |
|
|
|
sysRoleQueryWrapper.in("role_key", roles); |
|
|
|
List<SysRole> roleList = sysRoleService.list(sysRoleQueryWrapper); |
|
|
|
if (CollectionUtil.isNotEmpty(roleList)) { |
|
|
|
List<String> rids = roleList.stream().map(role -> role.getId()).collect(Collectors.toList()); |
|
|
|
for (SysRole sysRole : roleList) { |
|
|
|
QueryWrapper<SysRoleMenu> sysRoleMenuQueryWrapper = Wrappers.query(); |
|
|
|
if (CollectionUtil.isNotEmpty(rids)) { |
|
|
|
sysRoleMenuQueryWrapper.eq("role_id", sysRole.getId()); |
|
|
|
List<SysRoleMenu> list = sysRoleMenuService.list(sysRoleMenuQueryWrapper); |
|
|
|
List<String> menutwoids = list.stream().map(menu -> { |
|
|
|
return menu.getMenuId(); |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
List<String> disjunction = (List<String>) CollectionUtil.disjunction(menuids, menutwoids); |
|
|
|
menuids.removeAll(menutwoids); |
|
|
|
if(CollectionUtil.isNotEmpty(disjunction)) { //存在不存在的按钮 进行删除
|
|
|
|
sysRoleMenuQueryWrapper.in("menu_id", disjunction); |
|
|
|
sysRoleMenuService.remove(sysRoleMenuQueryWrapper); |
|
|
|
} |
|
|
|
} |
|
|
|
for (String menu : menuids) { |
|
|
|
SysRoleMenu sysRoleMenu = new SysRoleMenu(); |
|
|
|
sysRoleMenu.preInsert(); |
|
|
|
sysRoleMenu.setRoleId(sysRole.getId()); |
|
|
|
sysRoleMenu.setMenuId(menu); |
|
|
|
sysRoleMenuService.save(sysRoleMenu); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}catch (Exception e){ |
|
|
|
log.error("同步菜单权限失败:"+e.getMessage()); |
|
|
|
throw e; |
|
|
|
}finally { |
|
|
|
countDownLatch.countDown(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("同步菜单权限失败:" + e.getMessage()); |
|
|
|
throw e; |
|
|
|
} finally { |
|
|
|
countDownLatch.countDown(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void setChildren(List<SingleMenu> singleMenus,List<SingleMenu> singleAllMenus){ |
|
|
|
if(CollectionUtil.isNotEmpty(singleMenus)) { |
|
|
|
for (SingleMenu singleMenu : |
|
|
|
singleMenus) { //剔除掉不符合的
|
|
|
|
if(singleMenu.getVisible()!=null&&singleMenu.getStatus()!=null) { |
|
|
|
if (singleMenu.getStatus().equals("1")) { |
|
|
|
singleAllMenus.add(singleMenu); |
|
|
|
} |
|
|
|
} |
|
|
|
if (CollectionUtil.isNotEmpty(singleMenu.getChildren())) { |
|
|
|
List<SingleMenu> children = singleMenu.getChildren(); |
|
|
|
for (SingleMenu child : children) { |
|
|
|
if(singleMenu.getVisible()!=null&&singleMenu.getStatus()!=null) { |
|
|
|
if (singleMenu.getStatus().equals("1")) { |
|
|
|
singleAllMenus.add(child); |
|
|
|
} |
|
|
|
} |
|
|
|
if(CollectionUtil.isNotEmpty(child.getChildren())) { |
|
|
|
setChildren(child.getChildren(),singleAllMenus); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
public static void setChildren(List<SingleMenu> singleMenus, List<SingleMenu> singleAllMenus) { |
|
|
|
if (CollectionUtil.isNotEmpty(singleMenus)) { |
|
|
|
for (SingleMenu singleMenu : |
|
|
|
singleMenus) { //剔除掉不符合的
|
|
|
|
if (singleMenu.getVisible() != null && singleMenu.getStatus() != null) { |
|
|
|
if (singleMenu.getStatus().equals("1")) { |
|
|
|
singleAllMenus.add(singleMenu); |
|
|
|
} |
|
|
|
} |
|
|
|
if (CollectionUtil.isNotEmpty(singleMenu.getChildren())) { |
|
|
|
List<SingleMenu> children = singleMenu.getChildren(); |
|
|
|
for (SingleMenu child : children) { |
|
|
|
if (singleMenu.getVisible() != null && singleMenu.getStatus() != null) { |
|
|
|
if (singleMenu.getStatus().equals("1")) { |
|
|
|
singleAllMenus.add(child); |
|
|
|
} |
|
|
|
} |
|
|
|
if (CollectionUtil.isNotEmpty(child.getChildren())) { |
|
|
|
setChildren(child.getChildren(), singleAllMenus); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|