|
@@ -1,6 +1,5 @@
|
|
|
package com.qmth.paper.library.common.service.impl;
|
|
|
|
|
|
-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;
|
|
@@ -17,6 +16,7 @@ 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.SysSettingConstant;
|
|
|
import com.qmth.paper.library.common.contant.SystemConstant;
|
|
|
import com.qmth.paper.library.common.entity.*;
|
|
|
import com.qmth.paper.library.common.enums.*;
|
|
@@ -167,22 +167,6 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
return new MenuResult(sysUser.getId(), menuPrivilegeDtoList);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * 新增用户权限
|
|
|
- *
|
|
|
- * @param sysUser
|
|
|
- * @param roleId
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void addUserRolePrivilege(SysUser sysUser, Long roleId) {
|
|
|
- List<SysRolePrivilege> sysRolePrivilegeList = getRolePrivilege(roleId);
|
|
|
- List<SysUserRole> sysUserRoleList = new ArrayList<>();
|
|
|
- sysRolePrivilegeList.forEach(s -> {
|
|
|
- sysUserRoleList.add(new SysUserRole(sysUser.getId(), s.getRoleId(), s.getPrivilegeId()));
|
|
|
- });
|
|
|
- sysUserRoleService.saveBatch(sysUserRoleList);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
* 新增用户权限
|
|
|
*
|
|
@@ -198,15 +182,6 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
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;
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
|
|
|
* 获取用户角色权限
|
|
@@ -297,22 +272,6 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
return authBean;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * 获取鉴权url
|
|
|
- *
|
|
|
- * @param privilegePropertyEnum
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Set<String> getPrivilegeUrl(PrivilegePropertyEnum privilegePropertyEnum) {
|
|
|
- QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
|
|
|
- sysPrivilegeQueryWrapper.lambda().eq(SysPrivilege::getType, PrivilegeEnum.URL)
|
|
|
- .eq(SysPrivilege::getProperty, privilegePropertyEnum)
|
|
|
- .eq(SysPrivilege::getEnable, true);
|
|
|
- List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
|
|
|
- return Objects.nonNull(sysPrivilegeList) && sysPrivilegeList.size() > 0 ? sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()) : null;
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
* 获取鉴权url
|
|
|
*
|
|
@@ -423,7 +382,7 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
|
|
|
String filePath = (String) jsonObject.get(SystemConstant.PATH);
|
|
|
if (Objects.equals(attachmentType, SystemConstant.LOCAL)) {
|
|
|
- String hostUrl = SystemConstant.getLocalFileHost(dictionaryConfig.fssLocalFileDomain().getServer());
|
|
|
+ String hostUrl = commonCacheService.getSysSettingGlobal().get(SysSettingConstant.SYS_FILE_HOST_URL);
|
|
|
filePath = SystemConstant.getLocalFilePath(hostUrl, filePath);
|
|
|
if (filePath.startsWith("/")) {
|
|
|
url = hostUrl + filePath;
|
|
@@ -445,7 +404,7 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
String pathUrl;
|
|
|
|
|
|
if (Objects.equals(type, SystemConstant.LOCAL)) {
|
|
|
- String hostUrl = SystemConstant.getLocalFileHost(dictionaryConfig.fssLocalFileDomain().getServer());
|
|
|
+ String hostUrl = commonCacheService.getSysSettingGlobal().get(SysSettingConstant.SYS_FILE_HOST_URL);
|
|
|
path = SystemConstant.getLocalFilePath(hostUrl, path);
|
|
|
if (path.startsWith("/")) {
|
|
|
pathUrl = hostUrl + path;
|
|
@@ -463,142 +422,8 @@ public class LibraryCommonServiceImpl implements LibraryCommonService {
|
|
|
return pathUrl;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * 文件预览
|
|
|
- *
|
|
|
- * @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)) {
|
|
|
- String hostUrl = SystemConstant.getLocalFileHost(dictionaryConfig.fssLocalFileDomain().getServer());
|
|
|
- path = SystemConstant.getLocalFilePath(hostUrl, path);
|
|
|
- if (path.startsWith("/")) {
|
|
|
- pathUrl = hostUrl + path;
|
|
|
- } else {
|
|
|
- pathUrl = hostUrl + File.separator + path;
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (isExpire) {
|
|
|
- pathUrl = fileStoreUtil.getPrivateUrl(path, fileStoreUtil.getUploadEnumByPath(path).getFssType());
|
|
|
- } else {
|
|
|
- pathUrl = fileStoreUtil.getPrivateUrl(path, fileStoreUtil.getUploadEnumByPath(path).getFssType());
|
|
|
- }
|
|
|
|
|
|
- }
|
|
|
- return pathUrl;
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- * 获取文件
|
|
|
- *
|
|
|
- * @param path
|
|
|
- * @param pdf
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- @Override
|
|
|
- public File getFile(String path, boolean pdf) throws Exception {
|
|
|
- File file = 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));
|
|
|
-
|
|
|
- StringJoiner localPath = new StringJoiner("");
|
|
|
- if (Objects.equals(attachmentType, SystemConstant.OSS)) {
|
|
|
-
|
|
|
- localPath = localPath.add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator).add(filePath);
|
|
|
- file = fileStoreUtil.ossDownload(filePath, localPath.toString(), uploadType.getFssType());
|
|
|
- } else {
|
|
|
- if (!filePath.contains(dictionaryConfig.fssLocalFileDomain().getConfig())) {
|
|
|
- localPath = localPath.add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator).add(filePath);
|
|
|
- } else {
|
|
|
- localPath = localPath.add(filePath);
|
|
|
- }
|
|
|
- file = new File(localPath.toString());
|
|
|
- }
|
|
|
- return file;
|
|
|
- }
|
|
|
-
|
|
|
- @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 = 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 = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + schoolId;
|
|
|
- zipFile = FileUtil.file(zipPath, time + ".zip");
|
|
|
- Zip4jUtil.zipEncryptFile(zipFile.getPath(), files, SystemConstant.ZIP_ENCRYPT_PWD);
|
|
|
- outputFile(response, zipFile, String.valueOf(time));
|
|
|
- } catch (Exception e) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("下载失败");
|
|
|
- } finally {
|
|
|
-
|
|
|
- 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(dictionaryConfig.fssLocalFileDomain().getConfig(), time + ".zip");
|
|
|
- Zip4jUtil.zipEncryptFile(zipFile.getPath(), rootPath, SystemConstant.ZIP_ENCRYPT_PWD);
|
|
|
- outputFile(response, zipFile, String.valueOf(time));
|
|
|
- } catch (Exception e) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("下载失败");
|
|
|
- } finally {
|
|
|
-
|
|
|
- FileUtil.del(zipFile);
|
|
|
-
|
|
|
- FileUtil.del(rootPath);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public Set<Long> listSubOrgIds(Long id) {
|