|
@@ -5,14 +5,19 @@ import cn.hutool.core.util.ZipUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.google.common.reflect.TypeToken;
|
|
|
+import com.google.gson.Gson;
|
|
|
import com.qmth.boot.core.enums.Platform;
|
|
|
import com.qmth.boot.tools.signature.SignatureType;
|
|
|
import com.qmth.teachcloud.common.SignatureEntityTest;
|
|
|
import com.qmth.teachcloud.common.bean.auth.AuthBean;
|
|
|
import com.qmth.teachcloud.common.bean.auth.ExpireTimeBean;
|
|
|
+import com.qmth.teachcloud.common.bean.dto.MenuDto;
|
|
|
+import com.qmth.teachcloud.common.bean.dto.MenuPrivilegeDto;
|
|
|
import com.qmth.teachcloud.common.bean.dto.OrgDto;
|
|
|
import com.qmth.teachcloud.common.bean.dto.PrivilegeCacheDto;
|
|
|
import com.qmth.teachcloud.common.bean.result.LoginResult;
|
|
|
+import com.qmth.teachcloud.common.bean.result.MenuResult;
|
|
|
import com.qmth.teachcloud.common.bean.result.PrivilegeResult;
|
|
|
import com.qmth.teachcloud.common.bean.result.RolePrivilegeResult;
|
|
|
import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
@@ -84,6 +89,74 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
@Resource
|
|
|
BasicAttachmentService basicAttachmentService;
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取用户菜单
|
|
|
+ *
|
|
|
+ * @param userId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public MenuResult getUserMenu(Long userId) {
|
|
|
+ SysUser sysUser = cacheService.userCache(userId);
|
|
|
+ List<SysUserRole> sysUserRoleList = cacheService.userRolePrivilegeCache(userId);
|
|
|
+ List<SysRolePrivilege> sysRolePrivilegeList = new ArrayList<>();
|
|
|
+ for (SysUserRole s : sysUserRoleList) {
|
|
|
+ sysRolePrivilegeList.addAll(cacheService.rolePrivilegeCache(s.getRoleId()));
|
|
|
+ }
|
|
|
+ Set<Long> privilegeIds = sysRolePrivilegeList.stream().map(s -> s.getPrivilegeId()).collect(Collectors.toSet());
|
|
|
+ QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
|
|
|
+ sysPrivilegeQueryWrapper.lambda().in(SysPrivilege::getId, privilegeIds);
|
|
|
+ List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
|
|
|
+ Gson gson = new Gson();
|
|
|
+ List<MenuDto> menuDtoList = gson.fromJson(JacksonUtil.parseJson(sysPrivilegeList), new TypeToken<List<MenuDto>>() {
|
|
|
+ }.getType());
|
|
|
+ LinkedMultiValueMap<Long, MenuDto> linkedMultiValueMap = new LinkedMultiValueMap<>();
|
|
|
+ List<MenuPrivilegeDto> menuPrivilegeDtoList = new ArrayList<>();
|
|
|
+ for (MenuDto m : menuDtoList) {
|
|
|
+ if (Objects.isNull(m.getParentId()) || m.getType() == PrivilegeEnum.MENU) {
|
|
|
+ menuPrivilegeDtoList.add(gson.fromJson(gson.toJson(m), MenuPrivilegeDto.class));
|
|
|
+ } else {
|
|
|
+ if (!linkedMultiValueMap.containsKey(m.getParentId())) {
|
|
|
+ linkedMultiValueMap.add(m.getParentId(), m);
|
|
|
+ } else {
|
|
|
+ List<MenuDto> menuDtos = linkedMultiValueMap.get(m.getParentId());
|
|
|
+ menuDtos.add(m);
|
|
|
+ linkedMultiValueMap.put(m.getParentId(), menuDtos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (MenuPrivilegeDto m : menuPrivilegeDtoList) {
|
|
|
+ List<MenuDto> menuDtos = linkedMultiValueMap.get(m.getId());
|
|
|
+ List<MenuDto> urls = null, buttons = null, links = null, lists = null, conditions = null;
|
|
|
+ if (Objects.nonNull(menuDtos)) {
|
|
|
+ for (MenuDto menuDto : menuDtos) {
|
|
|
+ if (menuDto.getType() == PrivilegeEnum.BUTTON) {
|
|
|
+ buttons = Objects.isNull(buttons) ? new ArrayList<>() : buttons;
|
|
|
+ buttons.add(gson.fromJson(gson.toJson(menuDto), MenuPrivilegeDto.class));
|
|
|
+ m.setButtons(buttons);
|
|
|
+ } else if (menuDto.getType() == PrivilegeEnum.LINK) {
|
|
|
+ links = Objects.isNull(links) ? new ArrayList<>() : links;
|
|
|
+ links.add(gson.fromJson(gson.toJson(menuDto), MenuPrivilegeDto.class));
|
|
|
+ m.setLinks(links);
|
|
|
+ } else if (menuDto.getType() == PrivilegeEnum.URL) {
|
|
|
+ urls = Objects.isNull(urls) ? new ArrayList<>() : urls;
|
|
|
+ urls.add(gson.fromJson(gson.toJson(menuDto), MenuPrivilegeDto.class));
|
|
|
+ m.setUrls(urls);
|
|
|
+ } else if (menuDto.getType() == PrivilegeEnum.LIST) {
|
|
|
+ lists = Objects.isNull(lists) ? new ArrayList<>() : lists;
|
|
|
+ lists.add(gson.fromJson(gson.toJson(menuDto), MenuPrivilegeDto.class));
|
|
|
+ m.setLists(lists);
|
|
|
+ } else if (menuDto.getType() == PrivilegeEnum.CONDITION) {
|
|
|
+ conditions = Objects.isNull(conditions) ? new ArrayList<>() : conditions;
|
|
|
+ conditions.add(gson.fromJson(gson.toJson(menuDto), MenuPrivilegeDto.class));
|
|
|
+ m.setConditions(conditions);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new MenuResult(sysUser.getId(), menuPrivilegeDtoList);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 新增用户权限
|
|
|
*
|
|
@@ -171,7 +244,7 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
sysRoleQueryWrapper.lambda().in(SysRole::getId, roleIds)
|
|
|
.eq(SysRole::getEnable, true);
|
|
|
List<SysRole> sysRoleList = sysRoleService.list(sysRoleQueryWrapper);
|
|
|
- int count = Objects.nonNull(sysRoleList) && sysRoleList.size() > 0 ? (int) sysRoleList.stream().filter(s -> s.getType() == RoleTypeEnum.ADMIN).count() : 0;
|
|
|
+ int count = Objects.nonNull(sysRoleList) && sysRoleList.size() > 0 ? (int) sysRoleList.stream().filter(s -> Objects.equals(s.getName(), RoleTypeEnum.ADMIN.getDesc())).count() : 0;
|
|
|
QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
|
|
|
if (count > 0) {//超级系统管理员
|
|
|
Long schoolId = (Long) ServletUtil.getRequestSchoolByNotVaild();
|
|
@@ -218,20 +291,30 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
* 删除用户信息
|
|
|
*
|
|
|
* @param userId
|
|
|
+ * @param all
|
|
|
*/
|
|
|
@Override
|
|
|
- public void removeUserInfo(Long userId) throws NoSuchAlgorithmException {
|
|
|
+ public void removeUserInfo(Long userId, boolean all) throws NoSuchAlgorithmException {
|
|
|
AuthBean authBean = cacheService.userAuthCache(userId);
|
|
|
if (Objects.isNull(authBean)) {
|
|
|
throw ExceptionResultEnum.NOT_LOGIN.exception();
|
|
|
}
|
|
|
- for (Platform p : Platform.values()) {
|
|
|
- String sessionId = SessionUtil.digest(userId, Math.abs(authBean.getRoleList().stream().map(s -> s.getType()).collect(Collectors.toSet()).hashCode()), p.name());
|
|
|
- tbSessionService.removeById(sessionId);
|
|
|
- redisUtil.deleteUserSession(sessionId);
|
|
|
+ if (all) {
|
|
|
+ for (Platform p : Platform.values()) {
|
|
|
+ Set<String> roleNames = authBean.getRoleList().stream().map(s -> s.getName()).collect(Collectors.toSet());
|
|
|
+ String sessionId = SessionUtil.digest(userId, Math.abs(roleNames.toString().hashCode()), p.name());
|
|
|
+ tbSessionService.removeById(sessionId);
|
|
|
+ redisUtil.deleteUserSession(sessionId);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ TBSession tbSession = (TBSession) ServletUtil.getRequestSession();
|
|
|
+ tbSessionService.removeById(tbSession.getId());
|
|
|
+ redisUtil.deleteUserSession(tbSession.getId());
|
|
|
}
|
|
|
cacheService.removeUserCache(userId);
|
|
|
cacheService.removeUserAuthCache(userId);
|
|
|
+ cacheService.removeUserMenuCache(userId);
|
|
|
+ cacheService.removeUserRolePrivilegeCache(userId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -653,18 +736,18 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
String token = SystemConstant.getUuid();
|
|
|
cacheService.userCache(sysUser.getId());
|
|
|
//添加用户会话缓存
|
|
|
- Set<String> roleName = authBean.getRoleList().stream().map(s -> s.getName()).collect(Collectors.toSet());
|
|
|
- String sessionId = SessionUtil.digest(sysUser.getId(), Math.abs(roleName.toString().hashCode()), platform.name());
|
|
|
+ Set<String> roleNames = authBean.getRoleList().stream().map(s -> s.getName()).collect(Collectors.toSet());
|
|
|
+ String sessionId = SessionUtil.digest(sysUser.getId(), Math.abs(roleNames.toString().hashCode()), platform.name());
|
|
|
//TODO 测试用
|
|
|
String test = SignatureEntityTest.build(SignatureType.TOKEN, sessionId, token);
|
|
|
ExpireTimeBean expireTime = AuthUtil.getExpireTime(platform);
|
|
|
- TBSession tbSession = new TBSession(sysUser.getSchoolId(), sessionId, String.valueOf(sysUser.getId()), roleName.toString(),
|
|
|
+ TBSession tbSession = new TBSession(sysUser.getSchoolId(), sessionId, String.valueOf(sysUser.getId()), roleNames.toString(),
|
|
|
platform.name(), platform.name(), deviceId, ServletUtil.getRequest().getLocalAddr(), token,
|
|
|
expireTime.getDate().getTime(), appSource);
|
|
|
tbSessionService.saveOrUpdate(tbSession);
|
|
|
redisUtil.setUserSession(sessionId, tbSession, expireTime.getExpireSeconds());
|
|
|
|
|
|
- LoginResult loginResult = new LoginResult(sysUser, sessionId, test, roleName, appSource);
|
|
|
+ LoginResult loginResult = new LoginResult(sysUser, sessionId, test, roleNames, appSource);
|
|
|
// LoginResult loginResult = new LoginResult(sysUser, sessionId, token, roleName, appSource);
|
|
|
loginResult.setSchoolInfo(Objects.nonNull(authBean.getSchool()) ? loginResult.new SchoolNativeBean(authBean.getSchool()) : null);
|
|
|
loginResult.setOrgInfo(Objects.nonNull(authBean.getOrg()) ? loginResult.new OrgNativeBean(authBean.getOrg()) : null);
|