|
@@ -1,20 +1,22 @@
|
|
|
package com.qmth.paper.library.common.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.google.common.reflect.TypeToken;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.qmth.boot.core.enums.Platform;
|
|
|
+import com.qmth.boot.core.solar.model.AppInfo;
|
|
|
+import com.qmth.boot.core.solar.model.OrgInfo;
|
|
|
+import com.qmth.boot.core.solar.service.SolarService;
|
|
|
import com.qmth.paper.library.common.bean.auth.AuthBean;
|
|
|
import com.qmth.paper.library.common.bean.auth.ExpireTimeBean;
|
|
|
+import com.qmth.paper.library.common.bean.dto.AuthOrgInfoDto;
|
|
|
import com.qmth.paper.library.common.bean.dto.MenuDto;
|
|
|
import com.qmth.paper.library.common.bean.dto.MenuPrivilegeDto;
|
|
|
import com.qmth.paper.library.common.bean.dto.OrgDto;
|
|
|
import com.qmth.paper.library.common.bean.result.*;
|
|
|
import com.qmth.paper.library.common.config.DictionaryConfig;
|
|
|
-import com.qmth.paper.library.common.contant.SpringContextHolder;
|
|
|
import com.qmth.paper.library.common.contant.SystemConstant;
|
|
|
import com.qmth.paper.library.common.entity.*;
|
|
|
import com.qmth.paper.library.common.enums.*;
|
|
@@ -49,6 +51,9 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
@Resource
|
|
|
CommonCacheService commonCacheService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ BasicSchoolService basicSchoolService;
|
|
|
+
|
|
|
@Resource
|
|
|
SysUserRoleService sysUserRoleService;
|
|
|
|
|
@@ -64,24 +69,15 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
@Resource
|
|
|
TBSessionService tbSessionService;
|
|
|
|
|
|
- @Resource
|
|
|
- RedisUtil redisUtil;
|
|
|
-
|
|
|
@Resource
|
|
|
DictionaryConfig dictionaryConfig;
|
|
|
|
|
|
-// @Resource
|
|
|
-// OssUtil ossUtil;
|
|
|
-
|
|
|
@Autowired
|
|
|
private SysOrgService sysOrgService;
|
|
|
|
|
|
@Resource
|
|
|
LibraryCommonService commonService;
|
|
|
|
|
|
- @Resource
|
|
|
- BasicAttachmentService basicAttachmentService;
|
|
|
-
|
|
|
@Resource
|
|
|
FileStoreUtil fileStoreUtil;
|
|
|
|
|
@@ -91,6 +87,9 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
@Resource
|
|
|
ConvertUtil convertUtil;
|
|
|
|
|
|
+ @Resource
|
|
|
+ SolarService solarService;
|
|
|
+
|
|
|
/**
|
|
|
* 获取用户菜单
|
|
|
*
|
|
@@ -99,13 +98,13 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
*/
|
|
|
@Override
|
|
|
public MenuResult getUserMenu(Long userId) {
|
|
|
- SysUser sysUser = commonCacheService.userCache(userId);
|
|
|
- List<SysUserRole> sysUserRoleList = commonCacheService.userRolePrivilegeCache(userId);
|
|
|
+ SysUser sysUser = sysUserService.getById(userId);
|
|
|
+ List<SysUserRole> sysUserRoleList = getUserRolePrivilege(userId);
|
|
|
List<SysRolePrivilege> sysRolePrivilegeList = new ArrayList<>();
|
|
|
for (SysUserRole s : sysUserRoleList) {
|
|
|
- SysRole sysRole = commonCacheService.roleCache(s.getRoleId());
|
|
|
+ SysRole sysRole = sysRoleService.getById(s.getRoleId());
|
|
|
if (Objects.nonNull(sysRole) && sysRole.getEnable()) {
|
|
|
- sysRolePrivilegeList.addAll(commonCacheService.rolePrivilegeCache(s.getRoleId()));
|
|
|
+ sysRolePrivilegeList.addAll(getRolePrivilege(s.getRoleId()));
|
|
|
}
|
|
|
}
|
|
|
Set<Long> privilegeIds = sysRolePrivilegeList.stream().map(SysRolePrivilege::getPrivilegeId).collect(Collectors.toSet());
|
|
@@ -176,7 +175,7 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
*/
|
|
|
@Override
|
|
|
public void addUserRolePrivilege(SysUser sysUser, Long roleId) {
|
|
|
- List<SysRolePrivilege> sysRolePrivilegeList = commonCacheService.rolePrivilegeCache(roleId);
|
|
|
+ List<SysRolePrivilege> sysRolePrivilegeList = getRolePrivilege(roleId);
|
|
|
List<SysUserRole> sysUserRoleList = new ArrayList<>();
|
|
|
sysRolePrivilegeList.forEach(s -> {
|
|
|
sysUserRoleList.add(new SysUserRole(sysUser.getId(), s.getRoleId(), s.getPrivilegeId()));
|
|
@@ -246,18 +245,17 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
public AuthBean getUserAuth(Long userId) {
|
|
|
AuthBean authBean = null;
|
|
|
try {
|
|
|
- CommonCacheService commonCacheService = SpringContextHolder.getBean(CommonCacheService.class);
|
|
|
- SysUser user = commonCacheService.userCache(userId);
|
|
|
+ SysUser user = sysUserService.getById(userId);
|
|
|
if (Objects.isNull(user)) {
|
|
|
throw ExceptionResultEnum.USER_NO_DATA.exception();
|
|
|
}
|
|
|
//查询用户角色和权限
|
|
|
- List<SysUserRole> sysUserRoleList = commonCacheService.userRolePrivilegeCache(user.getId());
|
|
|
+ List<SysUserRole> sysUserRoleList = getUserRolePrivilege(user.getId());
|
|
|
if (Objects.nonNull(sysUserRoleList) && sysUserRoleList.size() > 0) {
|
|
|
Set<Long> roleIds = sysUserRoleList.stream().map(s -> s.getRoleId()).collect(Collectors.toSet());
|
|
|
List<SysRolePrivilege> sysRolePrivilegeList = new ArrayList<>();
|
|
|
for (Long l : roleIds) {
|
|
|
- sysRolePrivilegeList.addAll(commonCacheService.rolePrivilegeCache(l));
|
|
|
+ sysRolePrivilegeList.addAll(getRolePrivilege(l));
|
|
|
}
|
|
|
Set<Long> privilegeIds = sysRolePrivilegeList.stream().map(s -> s.getPrivilegeId()).collect(Collectors.toSet());
|
|
|
QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
|
|
@@ -275,8 +273,8 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
|
|
|
authBean = new AuthBean(sysRoleList, sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()));
|
|
|
} else {
|
|
|
- BasicSchool tbSchool = Objects.nonNull(user.getSchoolId()) ? commonCacheService.schoolCache(user.getSchoolId()) : null;
|
|
|
- SysOrg org = Objects.nonNull(user.getOrgId()) ? commonCacheService.orgCache(user.getOrgId()) : null;
|
|
|
+ BasicSchool tbSchool = Objects.nonNull(user.getSchoolId()) ? basicSchoolService.getById(user.getSchoolId()) : null;
|
|
|
+ SysOrg org = Objects.nonNull(user.getOrgId()) ? sysOrgService.getById(user.getOrgId()) : null;
|
|
|
List<SysPrivilege> sysPrivilegeList = new ArrayList<>();
|
|
|
if (privilegeIds.size() > 0) {
|
|
|
sysPrivilegeQueryWrapper.lambda().in(SysPrivilege::getId, privilegeIds)
|
|
@@ -342,7 +340,7 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
*/
|
|
|
@Override
|
|
|
public void removeUserInfo(Long userId, boolean all) throws NoSuchAlgorithmException {
|
|
|
- AuthBean authBean = commonCacheService.userAuthCache(userId);
|
|
|
+ AuthBean authBean = getUserAuth(userId);
|
|
|
if (Objects.isNull(authBean)) {
|
|
|
throw ExceptionResultEnum.NOT_LOGIN.exception();
|
|
|
}
|
|
@@ -354,17 +352,12 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
Collections.sort(roleNames);
|
|
|
String sessionId = SessionUtil.digest(userId, Math.abs(roleNames.toString().hashCode()), p.name());
|
|
|
tbSessionService.removeById(sessionId);
|
|
|
- redisUtil.deleteUserSession(sessionId);
|
|
|
+ // todo xf session
|
|
|
}
|
|
|
} else {
|
|
|
TBSession tbSession = (TBSession) ServletUtil.getRequestSession();
|
|
|
tbSessionService.removeById(tbSession.getId());
|
|
|
- redisUtil.deleteUserSession(tbSession.getId());
|
|
|
}
|
|
|
- commonCacheService.removeUserCache(userId);
|
|
|
- commonCacheService.removeUserAuthCache(userId);
|
|
|
- commonCacheService.removeUserMenuCache(userId);
|
|
|
- commonCacheService.removeUserRolePrivilegeCache(userId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -409,19 +402,9 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
}
|
|
|
}
|
|
|
tbSessionService.removeByIds(sessionIdSet);
|
|
|
- for (String s : sessionIdSet) {
|
|
|
- redisUtil.deleteUserSession(s);
|
|
|
- }
|
|
|
} else {
|
|
|
TBSession tbSession = (TBSession) ServletUtil.getRequestSession();
|
|
|
tbSessionService.removeById(tbSession.getId());
|
|
|
- redisUtil.deleteUserSession(tbSession.getId());
|
|
|
- }
|
|
|
- for (Long l : userIds) {
|
|
|
- commonCacheService.removeUserCache(l);
|
|
|
- commonCacheService.removeUserAuthCache(l);
|
|
|
- commonCacheService.removeUserMenuCache(l);
|
|
|
- commonCacheService.removeUserRolePrivilegeCache(l);
|
|
|
}
|
|
|
}).start();
|
|
|
}
|
|
@@ -661,7 +644,6 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
}
|
|
|
//生成token
|
|
|
String token = SystemConstant.getUuid();
|
|
|
- commonCacheService.userCache(sysUser.getId());
|
|
|
//添加用户会话缓存
|
|
|
Set<String> roleNamesSet = new HashSet<>(), roleTypes = new HashSet<>();
|
|
|
List<RoleResult> roleSource = new ArrayList<>();
|
|
@@ -683,7 +665,7 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
platform.name(), platform.name(), deviceId, ServletUtil.getRequest().getLocalAddr(), token,
|
|
|
expireTime.getDate().getTime(), appSource);
|
|
|
tbSessionService.saveOrUpdate(tbSession);
|
|
|
- redisUtil.setUserSession(sessionId, tbSession, expireTime.getExpireSeconds());
|
|
|
+ commonCacheService.saveTbSession(sessionId, tbSession);
|
|
|
|
|
|
// LoginResult loginResult = new LoginResult(sysUser, sessionId, test, Objects.nonNull(roleTypes) && roleTypes.size() > 0 ? roleTypes : roleNamesSet, appSource, roleSource);
|
|
|
LoginResult loginResult = new LoginResult(sysUser, sessionId, token, Objects.nonNull(roleTypes) && roleTypes.size() > 0 ? roleTypes : roleNamesSet, appSource, roleSource);
|
|
@@ -700,18 +682,6 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
return loginResult;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public String getSysIncrCode(SystemCodeEnum type, SysUser requestUser) {
|
|
|
- Long schoolId = requestUser.getSchoolId();
|
|
|
- String date = DateUtil.today().replace("-", "");
|
|
|
- String paperNumber = "";
|
|
|
- int count = 0;
|
|
|
- do {
|
|
|
- paperNumber = convertUtil.getIncre(date, type.getModel() + schoolId, type.getDigit());
|
|
|
- } while (count > 0);
|
|
|
- return paperNumber;
|
|
|
- }
|
|
|
-
|
|
|
private Set<Long> getOrgIds(Set<Long> stringSet, List<OrgDto> orgDtos, Long parentId) {
|
|
|
for (OrgDto orgDto : orgDtos) {
|
|
|
Long tempParentId = orgDto.getParentId();
|
|
@@ -757,4 +727,16 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
log.error(SystemConstant.LOG_ERROR, e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public AuthOrgInfoDto authInfoCache(String code) {
|
|
|
+ AppInfo appInfo = solarService.getAppInfo();
|
|
|
+ AuthOrgInfoDto authOrgInfoDto = null;
|
|
|
+ if (Objects.nonNull(appInfo)) {
|
|
|
+ List<OrgInfo> orgInfoList = solarService.getOrgList().stream().filter(s -> Objects.equals(s.getCode(), code)).collect(Collectors.toList());
|
|
|
+ if (Objects.nonNull(orgInfoList) && orgInfoList.size() > 0) {
|
|
|
+ authOrgInfoDto = new AuthOrgInfoDto(orgInfoList.get(0), appInfo.getControl());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return authOrgInfoDto;
|
|
|
+ }
|
|
|
}
|