|
@@ -1,47 +1,33 @@
|
|
package com.qmth.eds.service.impl;
|
|
package com.qmth.eds.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.io.FileUtil;
|
|
|
|
-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.query.QueryWrapper;
|
|
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
import com.google.common.reflect.TypeToken;
|
|
import com.google.common.reflect.TypeToken;
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
-import com.qmth.boot.core.enums.Platform;
|
|
|
|
import com.qmth.eds.bean.auth.AuthBean;
|
|
import com.qmth.eds.bean.auth.AuthBean;
|
|
-import com.qmth.eds.bean.auth.ExpireTimeBean;
|
|
|
|
import com.qmth.eds.bean.dto.MenuDto;
|
|
import com.qmth.eds.bean.dto.MenuDto;
|
|
import com.qmth.eds.bean.dto.MenuPrivilegeDto;
|
|
import com.qmth.eds.bean.dto.MenuPrivilegeDto;
|
|
-import com.qmth.eds.bean.dto.OrgDto;
|
|
|
|
-import com.qmth.eds.bean.dto.PrivilegeCacheDto;
|
|
|
|
-import com.qmth.eds.bean.result.*;
|
|
|
|
|
|
+import com.qmth.eds.bean.dto.syssetting.SimpleObject;
|
|
|
|
+import com.qmth.eds.bean.result.MenuResult;
|
|
import com.qmth.eds.common.contant.SpringContextHolder;
|
|
import com.qmth.eds.common.contant.SpringContextHolder;
|
|
import com.qmth.eds.common.contant.SystemConstant;
|
|
import com.qmth.eds.common.contant.SystemConstant;
|
|
import com.qmth.eds.common.entity.*;
|
|
import com.qmth.eds.common.entity.*;
|
|
-import com.qmth.eds.common.enums.*;
|
|
|
|
-import com.qmth.eds.common.util.*;
|
|
|
|
-import com.qmth.eds.core.config.DictionaryConfig;
|
|
|
|
|
|
+import com.qmth.eds.common.enums.ExceptionResultEnum;
|
|
|
|
+import com.qmth.eds.common.enums.PrivilegeEnum;
|
|
|
|
+import com.qmth.eds.common.enums.PrivilegePropertyEnum;
|
|
|
|
+import com.qmth.eds.common.enums.RoleTypeEnum;
|
|
|
|
+import com.qmth.eds.common.util.JacksonUtil;
|
|
import com.qmth.eds.service.*;
|
|
import com.qmth.eds.service.*;
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
|
-import java.io.*;
|
|
|
|
-import java.security.NoSuchAlgorithmException;
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @Description: 公共服务service impl
|
|
|
|
- * @Param:
|
|
|
|
- * @return:
|
|
|
|
- * @Author: wangliang
|
|
|
|
- * @Date: 2021/3/26
|
|
|
|
|
|
+ * 公共服务service impl
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
public class CommonServiceImpl implements CommonService {
|
|
public class CommonServiceImpl implements CommonService {
|
|
@@ -50,9 +36,6 @@ public class CommonServiceImpl implements CommonService {
|
|
@Resource
|
|
@Resource
|
|
CommonCacheService commonCacheService;
|
|
CommonCacheService commonCacheService;
|
|
|
|
|
|
- @Resource
|
|
|
|
- CommonService commonService;
|
|
|
|
-
|
|
|
|
@Resource
|
|
@Resource
|
|
SysUserRoleService sysUserRoleService;
|
|
SysUserRoleService sysUserRoleService;
|
|
|
|
|
|
@@ -65,32 +48,10 @@ public class CommonServiceImpl implements CommonService {
|
|
@Resource
|
|
@Resource
|
|
SysRoleService sysRoleService;
|
|
SysRoleService sysRoleService;
|
|
|
|
|
|
- @Resource
|
|
|
|
- TBSessionService tbSessionService;
|
|
|
|
-
|
|
|
|
- @Resource
|
|
|
|
- RedisUtil redisUtil;
|
|
|
|
-
|
|
|
|
- @Resource
|
|
|
|
- DictionaryConfig dictionaryConfig;
|
|
|
|
-
|
|
|
|
- @Resource
|
|
|
|
- BasicAttachmentService basicAttachmentService;
|
|
|
|
-
|
|
|
|
- @Resource
|
|
|
|
- FileStoreUtil fileStoreUtil;
|
|
|
|
-
|
|
|
|
- @Resource
|
|
|
|
- private BasicSchoolService basicSchoolService;
|
|
|
|
-
|
|
|
|
- @Resource
|
|
|
|
- SysUserService sysUserService;
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 获取用户菜单
|
|
* 获取用户菜单
|
|
*
|
|
*
|
|
- * @param userId
|
|
|
|
- * @return
|
|
|
|
|
|
+ * @param userId 用户ID
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public MenuResult getUserMenu(Long userId) {
|
|
public MenuResult getUserMenu(Long userId) {
|
|
@@ -156,52 +117,10 @@ public class CommonServiceImpl implements CommonService {
|
|
return new MenuResult(sysUser.getId(), menuPrivilegeDtoList);
|
|
return new MenuResult(sysUser.getId(), menuPrivilegeDtoList);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 新增用户权限
|
|
|
|
- *
|
|
|
|
- * @param sysUser
|
|
|
|
- * @param roleId
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public void addUserRolePrivilege(SysUser sysUser, Long roleId) {
|
|
|
|
- List<SysRolePrivilege> sysRolePrivilegeList = commonCacheService.rolePrivilegeCache(roleId);
|
|
|
|
- List<SysUserRole> sysUserRoleList = new ArrayList<>();
|
|
|
|
- sysRolePrivilegeList.forEach(s -> {
|
|
|
|
- sysUserRoleList.add(new SysUserRole(sysUser.getId(), s.getRoleId(), s.getPrivilegeId()));
|
|
|
|
- });
|
|
|
|
- sysUserRoleService.saveBatch(sysUserRoleList);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 新增用户权限
|
|
|
|
- *
|
|
|
|
- * @param sysUser
|
|
|
|
- * @param roleIds
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public void addUserRolePrivilege(SysUser sysUser, Long[] roleIds) {
|
|
|
|
- List<SysUserRole> sysUserRoleList = new ArrayList<>();
|
|
|
|
- for (int i = 0; i < roleIds.length; i++) {
|
|
|
|
- sysUserRoleList.add(new SysUserRole(sysUser.getId(), roleIds[i]));
|
|
|
|
- }
|
|
|
|
- sysUserRoleService.saveBatch(sysUserRoleList);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public List<SysUserRole> disposeUserPrivilege(SysUser sysUser, Long[] roleIds) {
|
|
|
|
- List<SysUserRole> sysUserRoleList = new ArrayList<>();
|
|
|
|
- for (int i = 0; i < roleIds.length; i++) {
|
|
|
|
- sysUserRoleList.add(new SysUserRole(sysUser.getId(), roleIds[i]));
|
|
|
|
- }
|
|
|
|
- return sysUserRoleList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 获取用户角色权限
|
|
* 获取用户角色权限
|
|
*
|
|
*
|
|
- * @param userId
|
|
|
|
- * @return
|
|
|
|
|
|
+ * @param userId 用户ID
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public List<SysUserRole> getUserRolePrivilege(Long userId) {
|
|
public List<SysUserRole> getUserRolePrivilege(Long userId) {
|
|
@@ -214,8 +133,7 @@ public class CommonServiceImpl implements CommonService {
|
|
/**
|
|
/**
|
|
* 获取角色权限
|
|
* 获取角色权限
|
|
*
|
|
*
|
|
- * @param roleId
|
|
|
|
- * @return
|
|
|
|
|
|
+ * @param roleId 角色ID
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public List<SysRolePrivilege> getRolePrivilege(Long roleId) {
|
|
public List<SysRolePrivilege> getRolePrivilege(Long roleId) {
|
|
@@ -227,8 +145,7 @@ public class CommonServiceImpl implements CommonService {
|
|
/**
|
|
/**
|
|
* 获取用户权限
|
|
* 获取用户权限
|
|
*
|
|
*
|
|
- * @param userId
|
|
|
|
- * @return
|
|
|
|
|
|
+ * @param userId 用户ID
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public AuthBean getUserAuth(Long userId) {
|
|
public AuthBean getUserAuth(Long userId) {
|
|
@@ -255,9 +172,7 @@ public class CommonServiceImpl implements CommonService {
|
|
int count = Objects.nonNull(sysRoleList) && sysRoleList.size() > 0 ? (int) sysRoleList.stream().filter(s -> Objects.equals(s.getName(), RoleTypeEnum.ADMIN.getDesc())).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<>();
|
|
QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
|
|
if (count > 0) {//超级系统管理员
|
|
if (count > 0) {//超级系统管理员
|
|
-// Long schoolId = Long.parseLong(ServletUtil.getRequestSchoolByNotVaild().toString());
|
|
|
|
sysPrivilegeQueryWrapper.lambda()
|
|
sysPrivilegeQueryWrapper.lambda()
|
|
-// .eq(SysPrivilege::getSchoolId, schoolId)
|
|
|
|
.eq(SysPrivilege::getType, PrivilegeEnum.URL)
|
|
.eq(SysPrivilege::getType, PrivilegeEnum.URL)
|
|
.eq(SysPrivilege::getProperty, PrivilegePropertyEnum.AUTH);
|
|
.eq(SysPrivilege::getProperty, PrivilegePropertyEnum.AUTH);
|
|
List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
|
|
List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
|
|
@@ -268,11 +183,6 @@ public class CommonServiceImpl implements CommonService {
|
|
sysPrivilegeQueryWrapper.lambda().in(SysPrivilege::getId, privilegeIds)
|
|
sysPrivilegeQueryWrapper.lambda().in(SysPrivilege::getId, privilegeIds)
|
|
.eq(SysPrivilege::getType, PrivilegeEnum.URL)
|
|
.eq(SysPrivilege::getType, PrivilegeEnum.URL)
|
|
.eq(SysPrivilege::getProperty, PrivilegePropertyEnum.AUTH);
|
|
.eq(SysPrivilege::getProperty, PrivilegePropertyEnum.AUTH);
|
|
-// if (Objects.isNull(tbSchool)) {
|
|
|
|
-// sysPrivilegeQueryWrapper.lambda().isNull(SysPrivilege::getSchoolId);
|
|
|
|
-// } else {
|
|
|
|
-// sysPrivilegeQueryWrapper.lambda().eq(SysPrivilege::getSchoolId, user.getSchoolId());
|
|
|
|
-// }
|
|
|
|
List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
|
|
List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
|
|
authBean = new AuthBean(sysRoleList, sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()), tbSchool, org);
|
|
authBean = new AuthBean(sysRoleList, sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()), tbSchool, org);
|
|
}
|
|
}
|
|
@@ -286,9 +196,6 @@ public class CommonServiceImpl implements CommonService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取鉴权url
|
|
* 获取鉴权url
|
|
- *
|
|
|
|
- * @param privilegePropertyEnum
|
|
|
|
- * @return
|
|
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public Set<String> getPrivilegeUrl(PrivilegePropertyEnum privilegePropertyEnum) {
|
|
public Set<String> getPrivilegeUrl(PrivilegePropertyEnum privilegePropertyEnum) {
|
|
@@ -302,10 +209,6 @@ public class CommonServiceImpl implements CommonService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取鉴权url
|
|
* 获取鉴权url
|
|
- *
|
|
|
|
- * @param privilegePropertyEnum
|
|
|
|
- * @param schoolId
|
|
|
|
- * @return
|
|
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public Set<String> getPrivilegeUrl(PrivilegePropertyEnum privilegePropertyEnum, Long schoolId) {
|
|
public Set<String> getPrivilegeUrl(PrivilegePropertyEnum privilegePropertyEnum, Long schoolId) {
|
|
@@ -314,580 +217,21 @@ public class CommonServiceImpl implements CommonService {
|
|
.eq(SysPrivilege::getProperty, privilegePropertyEnum)
|
|
.eq(SysPrivilege::getProperty, privilegePropertyEnum)
|
|
.eq(SysPrivilege::getEnable, true)
|
|
.eq(SysPrivilege::getEnable, true)
|
|
.eq(SysPrivilege::getDefaultAuth, true);
|
|
.eq(SysPrivilege::getDefaultAuth, true);
|
|
-// .eq(SysPrivilege::getSchoolId, schoolId);
|
|
|
|
List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
|
|
List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
|
|
return Objects.nonNull(sysPrivilegeList) && sysPrivilegeList.size() > 0 ? sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()) : null;
|
|
return Objects.nonNull(sysPrivilegeList) && sysPrivilegeList.size() > 0 ? sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()) : null;
|
|
}
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
|
@Override
|
|
@Override
|
|
- public void addSchoolPrivilege(Set<Long> schoolIdSet) {
|
|
|
|
-// Set<Long> pidSet = sysPrivilegeService.list().stream().map(SysPrivilege::getSchoolId).collect(Collectors.toSet());
|
|
|
|
-// // 权限表里没有该学校主键的
|
|
|
|
-// Set<Long> targetSchoolIdSet = schoolIdSet.stream().filter(e -> !pidSet.contains(e)).collect(Collectors.toSet());
|
|
|
|
- QueryWrapper<SysPrivilege> queryWrapper = new QueryWrapper<>();
|
|
|
|
-// queryWrapper.lambda().eq(SysPrivilege::getSchoolId, SystemConstant.DEFAULT_PRIVILEGE_SCHOOL);
|
|
|
|
- queryWrapper.lambda().eq(SysPrivilege::getDefaultAuth, true)
|
|
|
|
- .eq(SysPrivilege::getEnable, true);
|
|
|
|
- List<SysPrivilege> sysPrivileges = sysPrivilegeService.list(queryWrapper);
|
|
|
|
- if (sysPrivileges.size() == 0) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("默认学校权限不存在");
|
|
|
|
|
|
+ public String getSysSettingValue(Long schoolId, String code) {
|
|
|
|
+ Map<String, SimpleObject> simpleObjectMap = commonCacheService.getSysSetting(schoolId);
|
|
|
|
+ if (simpleObjectMap == null) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("系统参数未设置");
|
|
}
|
|
}
|
|
-// for (Long newSchoolId : targetSchoolIdSet) {
|
|
|
|
-// // 一个学校一个学校的权限加 如果放在外面的话必须在map的key中关联进学校主键
|
|
|
|
-// Map<Long, Long> map = new HashMap<>();
|
|
|
|
-// List<SysPrivilege> newList = new ArrayList<>();
|
|
|
|
-// BasicSchool basicSchool = basicSchoolService.getById(newSchoolId);
|
|
|
|
-// if (Objects.isNull(basicSchool)) {
|
|
|
|
-// throw ExceptionResultEnum.ERROR.exception("未找到学校信息");
|
|
|
|
-// }
|
|
|
|
-// for (SysPrivilege sysPrivilege : sysPrivileges) {
|
|
|
|
-// SysPrivilege cell = new SysPrivilege();
|
|
|
|
-// BeanUtils.copyProperties(sysPrivilege, cell);
|
|
|
|
-// Long id = SystemConstant.getDbUuid();
|
|
|
|
-// map.put(cell.getId(), id);
|
|
|
|
-// cell.setId(id);
|
|
|
|
-// cell.setSchoolId(newSchoolId);
|
|
|
|
-// cell.setEnable(basicSchool.getEnable());
|
|
|
|
-// newList.add(cell);
|
|
|
|
-// }
|
|
|
|
-// for (SysPrivilege sysPrivilege : newList) {
|
|
|
|
-// if (Objects.nonNull(sysPrivilege.getParentId())) {
|
|
|
|
-// sysPrivilege.setParentId(map.get(sysPrivilege.getParentId()));
|
|
|
|
-// }
|
|
|
|
-// String relateId = sysPrivilege.getRelated();
|
|
|
|
-// if (StringUtils.isNotBlank(relateId)) {
|
|
|
|
-// String[] relateIds = relateId.split(",");
|
|
|
|
-// List<String> newRelateIds = new ArrayList<>();
|
|
|
|
-// for (String id : relateIds) {
|
|
|
|
-// Long lid = Long.valueOf(id.trim());
|
|
|
|
-// newRelateIds.add(String.valueOf(map.get(lid)));
|
|
|
|
-// }
|
|
|
|
-// String newRelateId = String.join(",", newRelateIds);
|
|
|
|
-// sysPrivilege.setRelated(newRelateId);
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// sysPrivilegeService.saveBatch(newList);
|
|
|
|
-// }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 删除用户信息
|
|
|
|
- *
|
|
|
|
- * @param userId
|
|
|
|
- * @param all
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public void removeUserInfo(Long userId, boolean all) throws NoSuchAlgorithmException {
|
|
|
|
- AuthBean authBean = commonCacheService.userAuthCache(userId);
|
|
|
|
- if (Objects.isNull(authBean)) {
|
|
|
|
- throw ExceptionResultEnum.NOT_LOGIN.exception();
|
|
|
|
- }
|
|
|
|
- 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());
|
|
|
|
- }
|
|
|
|
- commonCacheService.removeUserCache(userId);
|
|
|
|
- commonCacheService.removeUserAuthCache(userId);
|
|
|
|
- commonCacheService.removeUserMenuCache(userId);
|
|
|
|
- commonCacheService.removeUserRolePrivilegeCache(userId);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-// /**
|
|
|
|
-// * 批量删除用户信息
|
|
|
|
-// *
|
|
|
|
-// * @param userIds
|
|
|
|
-// * @param all
|
|
|
|
-// */
|
|
|
|
-// @Override
|
|
|
|
-// public void removeUserInfoBatch(List<Long> userIds, boolean all) {
|
|
|
|
-// new Thread(() -> {
|
|
|
|
-// if (all) {
|
|
|
|
-// Set<String> sessionIdSet = new HashSet<>(Platform.values().length * userIds.size());
|
|
|
|
-// int min = 0;
|
|
|
|
-// int max = SystemConstant.IN_SIZE_MAX, size = userIds.size();
|
|
|
|
-// if (max >= size) {
|
|
|
|
-// max = size;
|
|
|
|
-// }
|
|
|
|
-// while (max <= size) {
|
|
|
|
-// List<UserRoleNameResult> userRoleNameResultList = sysUserService.selectRoleNames(userIds.subList(min, max));
|
|
|
|
-// for (UserRoleNameResult userRoleNameResult : userRoleNameResultList) {
|
|
|
|
-// for (Platform p : Platform.values()) {
|
|
|
|
-// String sessionId = null;
|
|
|
|
-// try {
|
|
|
|
-// sessionId = SessionUtil.digest(userRoleNameResult.getUserId(), Math.abs(Arrays.asList(userRoleNameResult.getRoleNames().split(",")).toString().hashCode()), p.name());
|
|
|
|
-// } catch (NoSuchAlgorithmException e) {
|
|
|
|
-// e.printStackTrace();
|
|
|
|
-// }
|
|
|
|
-// sessionIdSet.add(sessionId);
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// if (max == size) {
|
|
|
|
-// break;
|
|
|
|
-// }
|
|
|
|
-// min = max;
|
|
|
|
-// max += SystemConstant.IN_SIZE_MAX;
|
|
|
|
-// if (max >= size) {
|
|
|
|
-// max = size;
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// 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();
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 修改角色状态
|
|
|
|
- *
|
|
|
|
- * @param roleIds
|
|
|
|
- * @param enable
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public void updateRoleEnable(Long[] roleIds, Boolean enable) {
|
|
|
|
- SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
|
- List<SysRole> dbRoleList = sysRoleService.listByIds(Arrays.asList(roleIds));
|
|
|
|
- if (Objects.isNull(dbRoleList) || dbRoleList.size() == 0) {
|
|
|
|
- throw ExceptionResultEnum.ROLE_NO_DATA.exception();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //修改角色
|
|
|
|
- UpdateWrapper<SysRole> sysRoleUpdateWrapper = new UpdateWrapper<>();
|
|
|
|
- sysRoleUpdateWrapper.lambda().in(SysRole::getId, roleIds)
|
|
|
|
- .set(SysRole::getEnable, enable)
|
|
|
|
- .set(SysRole::getUpdateId, requestUser.getId())
|
|
|
|
- .set(SysRole::getUpdateTime, System.currentTimeMillis());
|
|
|
|
- sysRoleService.update(sysRoleUpdateWrapper);
|
|
|
|
-
|
|
|
|
- //修改角色权限
|
|
|
|
- UpdateWrapper<SysRolePrivilege> sysRolePrivilegeUpdateWrapper = new UpdateWrapper<>();
|
|
|
|
- sysRolePrivilegeUpdateWrapper.lambda().in(SysRolePrivilege::getRoleId, roleIds)
|
|
|
|
- .set(SysRolePrivilege::getEnable, enable);
|
|
|
|
- sysRolePrivilegeService.update(sysRolePrivilegeUpdateWrapper);
|
|
|
|
-
|
|
|
|
- //修改用户角色权限
|
|
|
|
- UpdateWrapper<SysUserRole> sysUserRoleUpdateWrapper = new UpdateWrapper<>();
|
|
|
|
- sysUserRoleUpdateWrapper.lambda().in(SysUserRole::getRoleId, roleIds)
|
|
|
|
- .set(SysUserRole::getEnable, enable);
|
|
|
|
- sysUserRoleService.update(sysUserRoleUpdateWrapper);
|
|
|
|
-
|
|
|
|
- List<Long> updateRoleIds = new ArrayList<>();
|
|
|
|
- for (SysRole dbRole : dbRoleList) {
|
|
|
|
- //如果数据库的状态和修改的状态不同
|
|
|
|
- if (Objects.nonNull(dbRole.getEnable()) && dbRole.getEnable().booleanValue() != enable.booleanValue()) {
|
|
|
|
- //更新角色权限
|
|
|
|
- commonCacheService.updateRolePrivilegeCache(dbRole.getId());
|
|
|
|
- updateRoleIds.add(dbRole.getId());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //更新用户权限状态
|
|
|
|
- QueryWrapper<SysUserRole> sysUserRoleQueryWrapper = new QueryWrapper<>();
|
|
|
|
- sysUserRoleQueryWrapper.lambda().eq(SysUserRole::getRoleId, updateRoleIds);
|
|
|
|
- List<SysUserRole> sysUserRoleList = sysUserRoleService.list(sysUserRoleQueryWrapper);
|
|
|
|
- Set<Long> userIds = sysUserRoleList.stream().map(s -> s.getUserId()).collect(Collectors.toSet());
|
|
|
|
- for (Long l : userIds) {
|
|
|
|
- commonCacheService.updateUserRolePrivilegeCache(l);
|
|
|
|
- commonCacheService.updateUserAuthCache(l);
|
|
|
|
|
|
+ SimpleObject simpleObject = simpleObjectMap.get(code);
|
|
|
|
+ if (simpleObject == null) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("系统参数[" + code + "]未设置");
|
|
}
|
|
}
|
|
|
|
+ return simpleObject.getValue();
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 查询用户或者角色权限信息
|
|
|
|
- *
|
|
|
|
- * @param privilegeCacheDtoList
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public RolePrivilegeResult getUserOrRolePrivilege(List<PrivilegeCacheDto> privilegeCacheDtoList) {
|
|
|
|
- LinkedMultiValueMap<Long, PrivilegeResult> buttonsLinkedMultiValueMap = new LinkedMultiValueMap<>(), linksLinkedMultiValueMap = new LinkedMultiValueMap<>();
|
|
|
|
- List<PrivilegeCacheDto> buttonsFilterList = new ArrayList<>(), linksFilterList = new ArrayList<>();
|
|
|
|
-
|
|
|
|
- for (PrivilegeCacheDto privilegeCacheDto : privilegeCacheDtoList) {
|
|
|
|
- if (privilegeCacheDto.getPrivilegeType() == PrivilegeEnum.BUTTON) {
|
|
|
|
- buttonsFilterList.add(privilegeCacheDto);
|
|
|
|
- buttonsLinkedMultiValueMap.add(privilegeCacheDto.getParentId(), new PrivilegeResult(privilegeCacheDto));
|
|
|
|
- } else if (privilegeCacheDto.getPrivilegeType() == PrivilegeEnum.LINK) {
|
|
|
|
- linksFilterList.add(privilegeCacheDto);
|
|
|
|
- linksLinkedMultiValueMap.add(privilegeCacheDto.getParentId(), new PrivilegeResult(privilegeCacheDto));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- privilegeCacheDtoList.removeAll(buttonsFilterList);
|
|
|
|
- privilegeCacheDtoList.removeAll(linksFilterList);
|
|
|
|
-
|
|
|
|
- RolePrivilegeResult rolePrivilegeResult = new RolePrivilegeResult();
|
|
|
|
- List<PrivilegeResult> privilegeResultList = new ArrayList<>();
|
|
|
|
- for (PrivilegeCacheDto privilegeCacheDto : privilegeCacheDtoList) {
|
|
|
|
- rolePrivilegeResult.setInfo(privilegeCacheDto);
|
|
|
|
- PrivilegeResult privilegeResult = new PrivilegeResult(privilegeCacheDto);
|
|
|
|
- privilegeResult.setButtons(buttonsLinkedMultiValueMap.get(privilegeResult.getId()));
|
|
|
|
- privilegeResult.setLinks(linksLinkedMultiValueMap.get(privilegeResult.getId()));
|
|
|
|
- privilegeResultList.add(privilegeResult);
|
|
|
|
- }
|
|
|
|
- rolePrivilegeResult.setPrivileges(privilegeResultList);
|
|
|
|
- return rolePrivilegeResult;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 文件预览
|
|
|
|
- *
|
|
|
|
- * @param path
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public String filePreview(String path) {
|
|
|
|
- String url = null;
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(path);
|
|
|
|
- String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
|
|
|
|
- String filePath = (String) jsonObject.get(SystemConstant.PATH);
|
|
|
|
- UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
|
|
|
|
- if (Objects.equals(attachmentType, SystemConstant.LOCAL)) {
|
|
|
|
- url = SystemConstant.HTTP + dictionaryConfig.sysDomain().getFileHost() + File.separator + filePath;
|
|
|
|
- } else {
|
|
|
|
-// if (uploadFileEnum == UploadFileEnum.PAPER) {
|
|
|
|
-// url = ossUtil.getPrivateUrl(filePath);
|
|
|
|
- url = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
|
|
|
|
-// } else {
|
|
|
|
-// url = dictionaryConfig.aliYunOssDomain().getUrl() + File.separator + filePath;
|
|
|
|
-// url = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
|
|
|
|
-// }
|
|
|
|
- }
|
|
|
|
- return url;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 文件预览
|
|
|
|
- *
|
|
|
|
- * @param path 附件路径
|
|
|
|
- * @param type 保存类型:本地、OSS
|
|
|
|
- * @param isExpire url是否带过期时间
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public String filePreviewByPathAndType(String path, String type, Boolean isExpire) {
|
|
|
|
- if (StringUtils.isBlank(path)) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- String pathUrl;
|
|
|
|
- if (Objects.equals(type, SystemConstant.LOCAL)) {
|
|
|
|
- pathUrl = SystemConstant.HTTP + dictionaryConfig.sysDomain().getFileHost() + File.separator + path;
|
|
|
|
- } else {
|
|
|
|
- if (isExpire) {
|
|
|
|
-// pathUrl = ossUtil.getPrivateUrl(path);
|
|
|
|
- pathUrl = fileStoreUtil.getPrivateUrl(path, fileStoreUtil.getUploadEnumByPath(path).getFssType());
|
|
|
|
- } else {
|
|
|
|
-// pathUrl = dictionaryConfig.aliYunOssDomain().getUrl() + File.separator + path;
|
|
|
|
- pathUrl = fileStoreUtil.getPrivateUrl(path, fileStoreUtil.getUploadEnumByPath(path).getFssType());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- return pathUrl;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 文件预览
|
|
|
|
- *
|
|
|
|
- * @param attachmentId 附件路径
|
|
|
|
- * @param isExpire url是否带过期时间
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public Map<String, String> filePreviewByAttachmentId(Long attachmentId, Boolean isExpire) {
|
|
|
|
- BasicAttachment attachment = basicAttachmentService.getById(attachmentId);
|
|
|
|
- if (attachment == null) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
|
-
|
|
|
|
- String pathUrl;
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(attachment.getPath());
|
|
|
|
- String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
|
|
|
|
- String filePath = (String) jsonObject.get(SystemConstant.PATH);
|
|
|
|
- UploadFileEnum uploadFileEnum = jsonObject.get(SystemConstant.UPLOAD_TYPE).toString().contains(UploadFileEnum.HTML.name()) ? UploadFileEnum.HTML : UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
|
|
|
|
-
|
|
|
|
- if (Objects.equals(attachmentType, SystemConstant.LOCAL)) {
|
|
|
|
- pathUrl = SystemConstant.HTTP + dictionaryConfig.sysDomain().getFileHost() + File.separator + filePath;
|
|
|
|
- } else {
|
|
|
|
- pathUrl = fileStoreUtil.getPrivateUrl(filePath, uploadFileEnum.getFssType());
|
|
|
|
- }
|
|
|
|
- map.put("url", pathUrl);
|
|
|
|
- if (attachment.getType().equals(".html")) {
|
|
|
|
- String htmlMd5 = (String) jsonObject.get("htmlMd5");
|
|
|
|
- map.put("md5", htmlMd5);
|
|
|
|
- } else {
|
|
|
|
- map.put("md5", attachment.getMd5());
|
|
|
|
- }
|
|
|
|
- return map;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public String readFileContent(String path) {
|
|
|
|
- // 解析path
|
|
|
|
- JSONObject object = JSONObject.parseObject(path);
|
|
|
|
- String filePath = object.getString(SystemConstant.PATH);
|
|
|
|
- String type = object.getString(SystemConstant.TYPE);
|
|
|
|
- UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class, (String) object.get(SystemConstant.UPLOAD_TYPE));
|
|
|
|
-
|
|
|
|
- if (filePath.endsWith(SystemConstant.HTML_PREFIX) || filePath.endsWith(SystemConstant.FTL_PREFIX)) {
|
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
|
- try {
|
|
|
|
- InputStream fis;
|
|
|
|
- if (type.equals(SystemConstant.OSS)) {
|
|
|
|
- fis = fileStoreUtil.ossDownloadIs(filePath, uploadType.getFssType());
|
|
|
|
- } else {
|
|
|
|
- String url = SystemConstant.HTTP + dictionaryConfig.sysDomain().getFileHost() + File.separator + filePath;
|
|
|
|
- File file = new File(url);
|
|
|
|
- if (!file.exists()) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("附件文件不存在");
|
|
|
|
- }
|
|
|
|
- fis = new FileInputStream(file);
|
|
|
|
- }
|
|
|
|
- BufferedReader br = new BufferedReader(new InputStreamReader(fis));
|
|
|
|
- String s;
|
|
|
|
- while ((s = br.readLine()) != null) {
|
|
|
|
- sb.append(s).append("\n");
|
|
|
|
- }
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("文件读取异常");
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error(SystemConstant.LOG_ERROR, e);
|
|
|
|
- }
|
|
|
|
- return sb.toString();
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public File copyFile(String rootPath, String fileName, BasicAttachment attachment) throws Exception {
|
|
|
|
- JSONObject object = JSONObject.parseObject(attachment.getPath());
|
|
|
|
- String filePath = object.getString(SystemConstant.PATH);
|
|
|
|
- String type = object.getString(SystemConstant.TYPE);
|
|
|
|
- UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class, (String) object.get(SystemConstant.UPLOAD_TYPE));
|
|
|
|
-
|
|
|
|
- if (type.equals(SystemConstant.OSS)) {
|
|
|
|
- File localPath = new File(rootPath, fileName);
|
|
|
|
- try {
|
|
|
|
-// File file = ossUtil.ossDownload(filePath, localPath.getPath());
|
|
|
|
- File file = fileStoreUtil.ossDownload(filePath, localPath.getPath(), uploadType.getFssType());
|
|
|
|
- return file;
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("从OSS上下载文件失败");
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- File file = new File(filePath);
|
|
|
|
- if (!file.exists()) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("本地文件不存在");
|
|
|
|
- }
|
|
|
|
- return file;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void downloadFileAndZip(HttpServletResponse response, String rootPath, List<File> files) {
|
|
|
|
- String schoolId = ServletUtil.getRequestHeaderSchoolId().toString();
|
|
|
|
- long time = System.nanoTime();
|
|
|
|
- File rootFile = new File(rootPath);
|
|
|
|
- // 创建保存目录
|
|
|
|
- if (!rootFile.exists()) {
|
|
|
|
- rootFile.mkdirs();
|
|
|
|
- }
|
|
|
|
- File zipFile = null;
|
|
|
|
- try {
|
|
|
|
- String zipPath = SystemConstant.TEMP_FILES_DIR + File.separator + schoolId;
|
|
|
|
- File zipPathFile = new File(zipPath);
|
|
|
|
- if (!zipPathFile.exists()) {
|
|
|
|
- zipPathFile.mkdirs();
|
|
|
|
- }
|
|
|
|
- zipFile = FileUtil.file(zipPath, time + ".zip");
|
|
|
|
-
|
|
|
|
- // 压缩文件
|
|
|
|
- if (!zipFile.exists()) {
|
|
|
|
- zipFile.createNewFile();
|
|
|
|
- }
|
|
|
|
- File[] srcFiles = files.toArray(new File[files.size()]);
|
|
|
|
-// ZipUtil.zip(rootFile.getAbsolutePath(), zipFile.getAbsolutePath(), false);
|
|
|
|
-
|
|
|
|
- ZipUtil.zip(zipFile, true, srcFiles);
|
|
|
|
- outputFile(response, zipFile, String.valueOf(time));
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("下载失败");
|
|
|
|
- } finally {
|
|
|
|
- // 删除zip文件
|
|
|
|
- FileUtil.del(zipFile);
|
|
|
|
- // 删除压缩内容
|
|
|
|
- FileUtil.del(rootPath);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void downloadFileAndZip(HttpServletResponse response, String rootPath, long time) {
|
|
|
|
- File rootFile = new File(rootPath);
|
|
|
|
- // 创建保存目录
|
|
|
|
- if (!rootFile.exists()) {
|
|
|
|
- rootFile.mkdirs();
|
|
|
|
- }
|
|
|
|
- File zipFile = null;
|
|
|
|
- try {
|
|
|
|
- zipFile = FileUtil.file(SystemConstant.TEMP_FILES_DIR, time + ".zip");
|
|
|
|
- // 压缩文件
|
|
|
|
- if (!zipFile.exists()) {
|
|
|
|
- zipFile.createNewFile();
|
|
|
|
- }
|
|
|
|
- ZipUtil.zip(rootPath, zipFile.getAbsolutePath(), true);
|
|
|
|
- outputFile(response, zipFile, String.valueOf(time));
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("下载失败");
|
|
|
|
- } finally {
|
|
|
|
- // 删除zip文件
|
|
|
|
- FileUtil.del(zipFile);
|
|
|
|
- // 删除压缩内容
|
|
|
|
- FileUtil.del(rootPath);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-// @Override
|
|
|
|
-// public Set<Long> listSubOrgIds(Long id) {
|
|
|
|
-// SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
|
-// Long orgId;
|
|
|
|
-// if (id == null) {
|
|
|
|
-// orgId = sysUser.getOrgId();
|
|
|
|
-// } else {
|
|
|
|
-// orgId = id;
|
|
|
|
-// }
|
|
|
|
-// if (orgId == null) {
|
|
|
|
-// return null;
|
|
|
|
-// }
|
|
|
|
-// List<OrgDto> orgDtos = sysOrgService.listOrgTree(null);
|
|
|
|
-// Set<Long> stringSet = new HashSet<>();
|
|
|
|
-// stringSet.add(orgId);
|
|
|
|
-// stringSet = getOrgIds(stringSet, orgDtos, orgId);
|
|
|
|
-// return stringSet;
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 登录公用
|
|
|
|
- *
|
|
|
|
- * @param password
|
|
|
|
- * @param sysUser
|
|
|
|
- * @param appSource
|
|
|
|
- * @return
|
|
|
|
- * @throws NoSuchAlgorithmException
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public LoginResult login(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.getUserAuth(sysUser.getId());
|
|
|
|
- //添加用户鉴权缓存
|
|
|
|
- if (Objects.isNull(authBean)) {
|
|
|
|
- throw ExceptionResultEnum.ROLE_ENABLE_AUTHORIZATION.exception();
|
|
|
|
- }
|
|
|
|
- //生成token
|
|
|
|
- String token = SystemConstant.getUuid();
|
|
|
|
- commonCacheService.userCache(sysUser.getId());
|
|
|
|
- //添加用户会话缓存
|
|
|
|
- Set<String> roleNames = new HashSet<>(), roleTypes = new HashSet<>();
|
|
|
|
- for (SysRole s : authBean.getRoleList()) {
|
|
|
|
- roleNames.add(s.getName());
|
|
|
|
- if (Objects.nonNull(s.getType())) {
|
|
|
|
- roleTypes.add(s.getType().name());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- 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()), 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, Objects.nonNull(roleTypes) && roleTypes.size() > 0 ? roleTypes : roleNames, appSource);
|
|
|
|
- LoginResult loginResult = new LoginResult(sysUser, sessionId, token, Objects.nonNull(roleTypes) && roleTypes.size() > 0 ? roleTypes : roleNames, 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);
|
|
|
|
- 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;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private Set<Long> getOrgIds(Set<Long> stringSet, List<OrgDto> orgDtos, Long parentId) {
|
|
|
|
- for (OrgDto orgDto : orgDtos) {
|
|
|
|
- Long tempParentId = orgDto.getParentId();
|
|
|
|
- if (parentId.equals(tempParentId) && stringSet.contains(parentId)) {
|
|
|
|
- stringSet.add(Long.valueOf(orgDto.getId()));
|
|
|
|
- }
|
|
|
|
- if (orgDto.getChildren().isEmpty()) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- getOrgIds(stringSet, orgDto.getChildren(), Long.valueOf(orgDto.getId()));
|
|
|
|
- }
|
|
|
|
- return stringSet;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public static void outputFile(HttpServletResponse response, File file, String fileName) {
|
|
|
|
- try {
|
|
|
|
-
|
|
|
|
- if (!file.exists()) {
|
|
|
|
- response.sendError(404, "File not found!");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- BufferedInputStream br = new BufferedInputStream(new FileInputStream(file));
|
|
|
|
- byte[] buf = new byte[1024];
|
|
|
|
- int len = 0;
|
|
|
|
-
|
|
|
|
- String fName = new String(fileName.getBytes(), "ISO-8859-1");
|
|
|
|
-
|
|
|
|
- response.reset();
|
|
|
|
- response.setContentType("application/x-msdownload");
|
|
|
|
- response.setHeader("Content-Disposition", "attachment; filename=" + fName);
|
|
|
|
-
|
|
|
|
- OutputStream outStream = response.getOutputStream();
|
|
|
|
-
|
|
|
|
- while ((len = br.read(buf)) > 0) {
|
|
|
|
- outStream.write(buf, 0, len);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- br.close();
|
|
|
|
- outStream.close();
|
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
|
- log.error(SystemConstant.LOG_ERROR, e);
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- log.error(SystemConstant.LOG_ERROR, e);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|