|
|
@ -2,6 +2,7 @@ package com.kms.web.controller.system; |
|
|
|
|
|
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.http.HttpResponse; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
@ -21,6 +22,9 @@ import com.jianwei.common.exception.CustomException; |
|
|
|
import com.jianwei.common.mybaitsplus.BeanToWrapper; |
|
|
|
import com.jianwei.common.utils.StringUtils; |
|
|
|
import com.jianwei.common.utils.password.PasswordUtil; |
|
|
|
import com.jianwei.ir.Node; |
|
|
|
import com.jianwei.ir.boot.KeywordType; |
|
|
|
import com.jianwei.thrift.ir.OrderItem; |
|
|
|
import com.kms.common.utils.UserUtils; |
|
|
|
import com.kms.config.WaterRequestUtil; |
|
|
|
import com.kms.config.WaterResult; |
|
|
@ -29,6 +33,7 @@ import com.kms.config.singleDomain.SingleRole; |
|
|
|
import com.kms.framework.manager.AsyncManager; |
|
|
|
import com.kms.framework.manager.factory.AsyncFactory; |
|
|
|
import com.kms.framework.web.service.SysPermissionService; |
|
|
|
import com.kms.system.domain.CmsTag; |
|
|
|
import com.kms.system.domain.SysRoleMenu; |
|
|
|
import com.kms.system.service.SysMenuService; |
|
|
|
import com.kms.system.service.SysRoleMenuService; |
|
|
@ -36,7 +41,9 @@ import com.kms.system.service.SysRoleService; |
|
|
|
import com.kms.system.service.SysUserService; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import lombok.SneakyThrows; |
|
|
|
import lombok.extern.log4j.Log4j2; |
|
|
|
import org.apache.commons.lang.SerializationUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@ -49,11 +56,10 @@ import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.Executors; |
|
|
|
import java.util.concurrent.ThreadPoolExecutor; |
|
|
|
import java.util.concurrent.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -173,6 +179,8 @@ public class SysLoginController extends BaseController { |
|
|
|
|
|
|
|
private String DOORURL = "http://19.25.35.204:31190/data_center/gateway/api"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 门户单点认证登录 |
|
|
|
* @return |
|
|
@ -182,12 +190,15 @@ public class SysLoginController extends BaseController { |
|
|
|
HttpServletResponse response, |
|
|
|
@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); |
|
|
@ -217,6 +228,11 @@ public class SysLoginController extends BaseController { |
|
|
|
ajax.put("authorization",token); |
|
|
|
RedirectView redirectView = new RedirectView(redirect+"?token="+tokenValue+"&authorization="+token); |
|
|
|
ModelAndView modelAndView = new ModelAndView(redirectView); |
|
|
|
try { |
|
|
|
countDownLatch.await(); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return modelAndView; |
|
|
|
} |
|
|
|
|
|
|
@ -234,8 +250,8 @@ public class SysLoginController extends BaseController { |
|
|
|
* @param token |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@GetMapping("/getSingleRotes/{token}") |
|
|
|
public AjaxResult getSingleRotes(@PathVariable String token){ |
|
|
|
// @GetMapping("/getSingleRotes/{token}")
|
|
|
|
// public AjaxResult getSingleRotes(@PathVariable String token){
|
|
|
|
// WaterResult waterResult = waterRequestUtil.authUser(token);
|
|
|
|
// String data = waterResult.getData();
|
|
|
|
// JSONObject jsonObject = JSONObject.parseObject(data);
|
|
|
@ -247,56 +263,64 @@ public class SysLoginController extends BaseController { |
|
|
|
// QueryWrapper<SysMenu> menuQueryWrapper = Wrappers.query();
|
|
|
|
// menuQueryWrapper.in("perms",functionPerms);
|
|
|
|
// List<SysMenu> menus = sysMenuService.list(menuQueryWrapper);
|
|
|
|
|
|
|
|
//
|
|
|
|
// return AjaxResult.success(menuService.buildMenus(menus));
|
|
|
|
// }
|
|
|
|
|
|
|
|
class RolePerms implements Runnable{ |
|
|
|
|
|
|
|
public String token; |
|
|
|
public WaterResult waterResult; |
|
|
|
public CountDownLatch countDownLatch; |
|
|
|
|
|
|
|
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<>(); |
|
|
|
if(CollectionUtil.isNotEmpty(singleMenus)) { |
|
|
|
for (SingleMenu singleMenu : singleMenus) { //剔除掉不符合的
|
|
|
|
if(singleMenu.getVisible().equals("1")&&singleMenu.getStats().equals("1")) { |
|
|
|
if (singleMenu.getVisible().equals("1") && singleMenu.getStatus().equals("1")) { |
|
|
|
singleAllMenus.add(singleMenu); |
|
|
|
} |
|
|
|
if(!singleMenu.getChildren().isEmpty()){ |
|
|
|
if (!singleMenu.getChildren().isEmpty()) { |
|
|
|
List<SingleMenu> children = singleMenu.getChildren(); |
|
|
|
for (SingleMenu child : children) { |
|
|
|
if(singleMenu.getVisible().equals("1")&&singleMenu.getStats().equals("1")) { |
|
|
|
if (singleMenu.getVisible().equals("1") && singleMenu.getStatus().equals("1")) { |
|
|
|
singleAllMenus.add(child); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
List<String> collect = singleMenus.stream().map(singleMenu -> singleMenu.getPermissionCode()).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
List<String> collect = singleAllMenus.stream().map(singleMenu -> singleMenu.getPermissionCode()).collect(Collectors.toList()); |
|
|
|
QueryWrapper<SysMenu> menuQueryWrapper = Wrappers.query(); |
|
|
|
menuQueryWrapper.in("perms",collect); |
|
|
|
List<SysMenu> menus = sysMenuService.list(menuQueryWrapper); |
|
|
|
executorService.submit(new RolePerms(token,menus)); |
|
|
|
return AjaxResult.success(menuService.buildMenus(menus)); |
|
|
|
} |
|
|
|
|
|
|
|
class RolePerms implements Runnable{ |
|
|
|
|
|
|
|
public String token; |
|
|
|
|
|
|
|
public List<SysMenu> menus; |
|
|
|
|
|
|
|
public RolePerms(String token,List<SysMenu> menus){ |
|
|
|
this.token = token; |
|
|
|
this.menus = menus; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public void run() { |
|
|
|
WaterResult waterResult = waterRequestUtil.authUser(token); |
|
|
|
// WaterResult waterResult = waterRequestUtil.authUser(token);
|
|
|
|
String data = waterResult.getData(); |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(data); |
|
|
|
List<String> functionPerms = jsonObject.getJSONArray("functionPerms").toJavaList(String.class); |
|
|
|
List<String> roles = jsonObject.getJSONArray("roles").toJavaList(String.class); |
|
|
|
QueryWrapper<SysRole> query = Wrappers.query(); |
|
|
|
query.in("role_key", roles); |
|
|
|
List<SysRole> roleList = sysRoleService.list(query); |
|
|
|
if (!roleList.isEmpty()) { |
|
|
|
JSONObject datajson = JSONObject.parseObject(data); |
|
|
|
// List<String> functionPerms = datajson.getJSONArray("functionPerms").toJavaList(String.class);
|
|
|
|
List<String> roles = datajson.getJSONArray("roles").toJavaList(String.class); |
|
|
|
QueryWrapper<SysRole> sysRoleQueryWrapper = Wrappers.query(); |
|
|
|
sysRoleQueryWrapper.in("role_key", roles); |
|
|
|
List<SysRole> roleList = sysRoleService.list(sysRoleQueryWrapper); |
|
|
|
if (CollectionUtil.isNotEmpty(roleList)) { |
|
|
|
QueryWrapper<SysRoleMenu> sysRoleMenuQueryWrapper = Wrappers.query(); |
|
|
|
query.in("role_id", roleList.stream().map(role -> role.getId()).collect(Collectors.toList())); |
|
|
|
List<String> rids = roleList.stream().map(role -> role.getId()).collect(Collectors.toList()); |
|
|
|
if(CollectionUtil.isNotEmpty(rids)) { |
|
|
|
sysRoleMenuQueryWrapper.in("role_id",rids); |
|
|
|
sysRoleMenuService.remove(sysRoleMenuQueryWrapper); |
|
|
|
} |
|
|
|
for (SysRole sysRole : roleList) { |
|
|
|
for (SysMenu menu : menus) { |
|
|
|
SysRoleMenu sysRoleMenu = new SysRoleMenu(); |
|
|
@ -307,6 +331,11 @@ public class SysLoginController extends BaseController { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}catch (Exception e){ |
|
|
|
log.error("同步菜单权限失败:"+e.getMessage()); |
|
|
|
}finally { |
|
|
|
countDownLatch.countDown(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|