|
@@ -5,7 +5,6 @@ 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.update.UpdateWrapper;
|
|
|
import com.google.common.reflect.TypeToken;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.qmth.boot.core.enums.Platform;
|
|
@@ -14,7 +13,6 @@ 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.*;
|
|
|
import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
|
import com.qmth.teachcloud.common.contant.SpringContextHolder;
|
|
@@ -24,12 +22,10 @@ import com.qmth.teachcloud.common.enums.*;
|
|
|
import com.qmth.teachcloud.common.service.*;
|
|
|
import com.qmth.teachcloud.common.util.*;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.apache.tomcat.util.http.fileupload.IOUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -341,58 +337,6 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
return Objects.nonNull(sysPrivilegeList) && sysPrivilegeList.size() > 0 ? sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()) : null;
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
- @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("默认学校权限不存在");
|
|
|
- }
|
|
|
-// 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);
|
|
|
-// }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 删除用户信息
|
|
|
*
|
|
@@ -484,97 +428,6 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
}).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);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询用户或者角色权限信息
|
|
|
- *
|
|
|
- * @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;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 文件预览
|
|
|
*
|
|
@@ -714,61 +567,6 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取文件流
|
|
|
- *
|
|
|
- * @param path
|
|
|
- * @param pdf
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public InputStream getFileInputStream(String path, boolean pdf) throws Exception {
|
|
|
- InputStream inputStream = null;
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(path);
|
|
|
- String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
|
|
|
- String filePath = pdf ? (String) jsonObject.get(SystemConstant.PDF_PATH) : (String) jsonObject.get(SystemConstant.PATH);
|
|
|
- UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class, (String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
|
|
|
-
|
|
|
- if (Objects.equals(attachmentType, SystemConstant.OSS)) {
|
|
|
-// byte[] data = ossUtil.ossDownload(filePath);
|
|
|
-// inputStream = new ByteArrayInputStream(data);
|
|
|
- inputStream = fileStoreUtil.ossDownloadIs(filePath, uploadType.getFssType());
|
|
|
- } else {
|
|
|
- StringJoiner localPath = new StringJoiner("").add(SystemConstant.TEMP_FILES_DIR).add(File.separator).add(filePath);
|
|
|
- inputStream = new FileInputStream(new File(localPath.toString()));
|
|
|
- }
|
|
|
- return inputStream;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取文件数组
|
|
|
- *
|
|
|
- * @param path
|
|
|
- * @param pdf
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- @Override
|
|
|
- public byte[] getFileByte(String path, boolean pdf) throws Exception {
|
|
|
- byte[] data = null;
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(path);
|
|
|
- String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
|
|
|
- String filePath = pdf ? (String) jsonObject.get(SystemConstant.PDF_PATH) : (String) jsonObject.get(SystemConstant.PATH);
|
|
|
- UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class, (String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
|
|
|
-
|
|
|
- if (Objects.equals(attachmentType, SystemConstant.OSS)) {
|
|
|
-// data = ossUtil.ossDownload(filePath);
|
|
|
- data = fileStoreUtil.ossDownload(filePath, uploadType.getFssType());
|
|
|
- } else {
|
|
|
- StringJoiner localPath = new StringJoiner("").add(SystemConstant.TEMP_FILES_DIR).add(File.separator).add(filePath);
|
|
|
- InputStream inputStream = new FileInputStream(new File(localPath.toString()));
|
|
|
- ByteArrayOutputStream ou = new ByteArrayOutputStream();
|
|
|
- IOUtils.copy(inputStream, ou);
|
|
|
- data = ou.toByteArray();
|
|
|
- }
|
|
|
- return data;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 获取文件
|
|
|
*
|