|
@@ -77,6 +77,8 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
FileStoreUtil fileStoreUtil;
|
|
|
@Resource
|
|
|
SysUserService sysUserService;
|
|
|
+ @Resource
|
|
|
+ TSchoolPrivilegeService tSchoolPrivilegeService;
|
|
|
|
|
|
/**
|
|
|
* 获取用户菜单
|
|
@@ -168,6 +170,77 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
return new MenuResult(sysUser.getId(), menuPrivilegeDtoList);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public MenuResult getUserMenuForReport(Long userId) {
|
|
|
+ SysUser sysUser = commonCacheService.userCache(userId);
|
|
|
+ List<SysUserRole> sysUserRoleList = commonCacheService.userRolePrivilegeCache(userId);
|
|
|
+ List<SysRolePrivilege> sysRolePrivilegeList = new ArrayList<>();
|
|
|
+ for (SysUserRole s : sysUserRoleList) {
|
|
|
+ SysRole sysRole = commonCacheService.roleCache(s.getRoleId());
|
|
|
+ if (Objects.nonNull(sysRole) && sysRole.getEnable()) {
|
|
|
+ sysRolePrivilegeList.addAll(commonCacheService.rolePrivilegeCache(sysUser.getSchoolId(), s.getRoleId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Set<Long> privilegeIds = sysRolePrivilegeList.stream().map(s -> s.getPrivilegeId()).collect(Collectors.toSet());
|
|
|
+ QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
|
|
|
+ sysPrivilegeQueryWrapper.lambda()
|
|
|
+ .eq(SysPrivilege::getEnable, true).eq(SysPrivilege::getFrontDisplay, true)
|
|
|
+ .orderByAsc(SysPrivilege::getSequence);
|
|
|
+
|
|
|
+ if (!privilegeIds.isEmpty()) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 新增用户权限
|
|
|
*
|
|
@@ -318,6 +391,63 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
return authBean;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public AuthBean getUserAuthForReport(Long userId) {
|
|
|
+ AuthBean authBean = null;
|
|
|
+ try {
|
|
|
+ CommonCacheService commonCacheService = SpringContextHolder.getBean(CommonCacheService.class);
|
|
|
+ SysUser user = commonCacheService.userCache(userId);
|
|
|
+ if (Objects.isNull(user)) {
|
|
|
+ throw ExceptionResultEnum.USER_NO_DATA.exception();
|
|
|
+ }
|
|
|
+ //查询用户角色和权限
|
|
|
+ List<SysUserRole> sysUserRoleList = commonCacheService.userRolePrivilegeCache(user.getId());
|
|
|
+ if (Objects.nonNull(sysUserRoleList) && sysUserRoleList.size() > 0) {
|
|
|
+ Set<Long> roleIds = sysUserRoleList.stream().map(SysUserRole::getRoleId).collect(Collectors.toSet());
|
|
|
+ List<SysRolePrivilege> sysRolePrivilegeList = new ArrayList<>();
|
|
|
+ for (Long l : roleIds) {
|
|
|
+ sysRolePrivilegeList.addAll(commonCacheService.rolePrivilegeCache(user.getSchoolId(), l));
|
|
|
+ }
|
|
|
+ Set<Long> privilegeIds = sysRolePrivilegeList.stream().map(SysRolePrivilege::getPrivilegeId).collect(Collectors.toSet());
|
|
|
+ QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
|
|
|
+ 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 -> Objects.equals(s.getName(), RoleTypeEnum.ADMIN.getName())).count() :
|
|
|
+ 0;
|
|
|
+ QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
|
|
|
+ if (count > 0) {//超级系统管理员
|
|
|
+ // Long schoolId = Long.parseLong(ServletUtil.getRequestSchoolByNotVaild().toString());
|
|
|
+ sysPrivilegeQueryWrapper.lambda()
|
|
|
+ // .eq(SysPrivilege::getSchoolId, schoolId)
|
|
|
+ .eq(SysPrivilege::getType, PrivilegeEnum.URL)
|
|
|
+ .eq(SysPrivilege::getProperty, PrivilegePropertyEnum.AUTH);
|
|
|
+ List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
|
|
|
+ authBean = new AuthBean(sysRoleList,
|
|
|
+ sysPrivilegeList.stream().map(SysPrivilege::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;
|
|
|
+ List<SysPrivilege> sysPrivilegeList = new ArrayList<>();
|
|
|
+ if (privilegeIds.size() > 0) {
|
|
|
+ sysPrivilegeQueryWrapper.lambda().in(SysPrivilege::getId, privilegeIds)
|
|
|
+ .eq(SysPrivilege::getType, PrivilegeEnum.URL)
|
|
|
+ .eq(SysPrivilege::getProperty, PrivilegePropertyEnum.AUTH);
|
|
|
+ sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
|
|
|
+ }
|
|
|
+ authBean = new AuthBean(sysRoleList,
|
|
|
+ sysPrivilegeList.stream().map(SysPrivilege::getUrl).collect(Collectors.toSet()), tbSchool, org);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("添加用户鉴权缓存失败");
|
|
|
+ }
|
|
|
+ return authBean;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取鉴权url
|
|
|
*
|
|
@@ -699,7 +829,9 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
if (Objects.isNull(s.getSource()) && Objects.nonNull(s.getType())) {
|
|
|
roleTypes.add(s.getType().name());
|
|
|
}
|
|
|
- roleSource.add(Objects.nonNull(s.getType()) ? new RoleResult(s.getId(), s.getName(), s.getType().name(), s.getSource()) : new RoleResult(s.getId(), s.getName(), s.getSource()));
|
|
|
+ roleSource.add(Objects.nonNull(s.getType()) ?
|
|
|
+ new RoleResult(s.getId(), s.getName(), s.getType().name(), s.getSource()) :
|
|
|
+ new RoleResult(s.getId(), s.getName(), s.getSource()));
|
|
|
}
|
|
|
List<String> roleNames = new ArrayList<>();
|
|
|
roleNames.addAll(roleNamesSet);
|
|
@@ -714,10 +846,16 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
tbSessionService.saveOrUpdate(tbSession);
|
|
|
redisUtil.setUserSession(sessionId, tbSession, expireTime.getExpireSeconds());
|
|
|
|
|
|
-// 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, SystemConstant.VERSION_VALUE);
|
|
|
- loginResult.setSchoolInfo(Objects.nonNull(authBean.getSchool()) ? Lists.newArrayList(loginResult.new SchoolNativeBean(authBean.getSchool())) : null);
|
|
|
- loginResult.setOrgInfo(Objects.nonNull(authBean.getOrg()) ? loginResult.new OrgNativeBean(authBean.getOrg()) : null);
|
|
|
+// 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,
|
|
|
+ SystemConstant.VERSION_VALUE);
|
|
|
+ loginResult.setSchoolInfo(Objects.nonNull(authBean.getSchool()) ?
|
|
|
+ Lists.newArrayList(loginResult.new SchoolNativeBean(authBean.getSchool())) :
|
|
|
+ null);
|
|
|
+ loginResult.setOrgInfo(
|
|
|
+ Objects.nonNull(authBean.getOrg()) ? loginResult.new OrgNativeBean(authBean.getOrg()) : null);
|
|
|
loginResult.setRole(role);
|
|
|
loginResult.setTime(System.currentTimeMillis());
|
|
|
String mobileNumber = sysUser.getMobileNumber();
|
|
@@ -729,8 +867,7 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
loginResult.setUserLoginCheckResult(new UserLoginCheckResult(sysUser.getId(), mobileNumber, pwdCount));
|
|
|
// //TODO 西交大切换学校定制
|
|
|
// QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
|
|
|
-// sysUserQueryWrapper.lambda().eq(SysUser::getLoginName, sysUser.getLoginName())
|
|
|
-// .eq(SysUser::getEnable, true);
|
|
|
+// sysUserQueryWrapper.lambda().eq(SysUser::getLoginName, sysUser.getLoginName()).eq(SysUser::getEnable, true);
|
|
|
// List<SysUser> sysUserList = sysUserService.list(sysUserQueryWrapper);
|
|
|
// if (sysUserList.size() > 1) {
|
|
|
// List<LoginResult.SchoolNativeBean> schoolNativeBeanList = new ArrayList<>(sysUserList.size());
|
|
@@ -743,6 +880,62 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
return loginResult;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public LoginResult loginForReport(String password, SysUser sysUser, AppSourceEnum appSource)
|
|
|
+ throws NoSuchAlgorithmException {
|
|
|
+ //停用
|
|
|
+ if (!sysUser.getEnable()) {
|
|
|
+ throw ExceptionResultEnum.USER_ENABLE.exception();
|
|
|
+ }
|
|
|
+
|
|
|
+ Platform platform = ServletUtil.getRequestPlatform();
|
|
|
+ String deviceId = ServletUtil.getRequestDeviceId();
|
|
|
+ AuthBean authBean = commonService.getUserAuthForReport(sysUser.getId());
|
|
|
+ //添加用户鉴权缓存
|
|
|
+ if (Objects.isNull(authBean)) {
|
|
|
+ throw ExceptionResultEnum.ROLE_ENABLE_AUTHORIZATION.exception();
|
|
|
+ }
|
|
|
+ //生成token
|
|
|
+ String token = SystemConstant.getNanoId();
|
|
|
+ commonCacheService.userCache(sysUser.getId());
|
|
|
+ //添加用户会话缓存
|
|
|
+ Set<String> roleNamesSet = new HashSet<>(), roleTypes = new HashSet<>(), role = new HashSet<>();
|
|
|
+ List<RoleResult> roleSource = new ArrayList<>();
|
|
|
+ for (SysRole s : authBean.getRoleList()) {
|
|
|
+ roleNamesSet.add(s.getName());
|
|
|
+ if (s.getType() != null) {
|
|
|
+ role.add(s.getType().name());
|
|
|
+ }
|
|
|
+ if (Objects.isNull(s.getSource()) && Objects.nonNull(s.getType())) {
|
|
|
+ roleTypes.add(s.getType().name());
|
|
|
+ }
|
|
|
+ roleSource.add(Objects.nonNull(s.getType()) ? new RoleResult(s.getId(), s.getName(), s.getType().name(), s.getSource()) : new RoleResult(s.getId(), s.getName(), s.getSource()));
|
|
|
+ }
|
|
|
+ List<String> roleNames = new ArrayList<>(roleNamesSet);
|
|
|
+ Collections.sort(roleNames);
|
|
|
+ String sessionId = SessionUtil.digest(sysUser.getId(), Math.abs(roleNames.toString().hashCode()), platform.name());
|
|
|
+ ExpireTimeBean expireTime = AuthUtil.getExpireTime(platform);
|
|
|
+ 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, token,
|
|
|
+ roleTypes.size() > 0 ? roleTypes : roleNamesSet, appSource, roleSource, SystemConstant.VERSION_VALUE);
|
|
|
+ loginResult.setSchoolInfo(Objects.nonNull(authBean.getSchool()) ? Lists.newArrayList(loginResult.new SchoolNativeBean(authBean.getSchool())) : null);
|
|
|
+ loginResult.setOrgInfo(Objects.nonNull(authBean.getOrg()) ? loginResult.new OrgNativeBean(authBean.getOrg()) : null);
|
|
|
+ loginResult.setRole(role);
|
|
|
+ loginResult.setTime(System.currentTimeMillis());
|
|
|
+ String mobileNumber = sysUser.getMobileNumber();
|
|
|
+ int pwdCount = sysUser.getPwdCount();
|
|
|
+ if (roleTypes.contains(RoleTypeEnum.ADMIN.name())) {
|
|
|
+ mobileNumber = sysUser.getLoginName() + "(特殊权限)";
|
|
|
+ pwdCount = 1;
|
|
|
+ }
|
|
|
+ loginResult.setUserLoginCheckResult(new UserLoginCheckResult(sysUser.getId(), mobileNumber, pwdCount));
|
|
|
+ return loginResult;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public boolean containsPrivilege(Long userId, String button, String selectStudent) {
|
|
|
MenuResult menuResult = commonCacheService.userMenuCache(userId);
|