|
@@ -1,27 +1,37 @@
|
|
|
package org.jeecg.modules.wps.service.impl;
|
|
|
|
|
|
+import cn.com.ctop.common.module.file.FileUtil;
|
|
|
+import cn.com.ctop.common.module.utils.CosUtils;
|
|
|
import cn.com.ctop.common.module.utils.ResultMapUtils;
|
|
|
import cn.com.ctop.common.module.utils.StatusCode;
|
|
|
+import cn.com.ctop.common.module.vo.ResFileDTO;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
+import org.jeecg.modules.ctop.entity.Project;
|
|
|
+import org.jeecg.modules.ctop.service.IProjectService;
|
|
|
+import org.jeecg.modules.system.entity.SysUser;
|
|
|
+import org.jeecg.modules.system.service.ISysUserService;
|
|
|
import org.jeecg.modules.wps.config.Context;
|
|
|
import org.jeecg.modules.wps.dto.*;
|
|
|
-import org.jeecg.modules.wps.entity.*;
|
|
|
+import org.jeecg.modules.wps.entity.WpsFile;
|
|
|
+import org.jeecg.modules.wps.entity.WpsFileVersion;
|
|
|
+import org.jeecg.modules.wps.entity.WpsFileWatermark;
|
|
|
+import org.jeecg.modules.wps.entity.WpsUser;
|
|
|
import org.jeecg.modules.wps.mapper.WpsFileMapper;
|
|
|
import org.jeecg.modules.wps.service.*;
|
|
|
import org.jeecg.modules.wps.util.Token;
|
|
|
import org.jeecg.modules.wps.util.WpsUtil;
|
|
|
-import org.jeecg.modules.wps.util.file.FileUtil;
|
|
|
-import org.jeecg.modules.wps.util.upload.ResFileDTO;
|
|
|
import org.jeecg.modules.wps.util.upload.oss.WpsOSSUtil;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -43,6 +53,10 @@ public class WpsFileServiceImpl extends ServiceImpl<WpsFileMapper, WpsFile> impl
|
|
|
private IWpsUserService wpsUserService;
|
|
|
@Autowired
|
|
|
private WpsUtil wpsUtil;
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService sysUserService;
|
|
|
+
|
|
|
+ private static final String OSS_URL_PREFIX = "https://ctop-media.oss-cn-beijing.aliyuncs.com/script-lib/wps/";
|
|
|
@Override
|
|
|
public Token getViewUrl(String fileUrl, boolean checkToken){
|
|
|
Token t = new Token();
|
|
@@ -54,7 +68,7 @@ public class WpsFileServiceImpl extends ServiceImpl<WpsFileMapper, WpsFile> impl
|
|
|
|
|
|
Map<String,String> values = new HashMap<String,String>(){
|
|
|
{
|
|
|
- put("_w_appid", appid);
|
|
|
+ put("_w_appid", WpsUtil.appid);
|
|
|
if (checkToken){
|
|
|
put("_w_tokentype","1");
|
|
|
}
|
|
@@ -72,16 +86,6 @@ public class WpsFileServiceImpl extends ServiceImpl<WpsFileMapper, WpsFile> impl
|
|
|
|
|
|
return t;
|
|
|
}
|
|
|
- @Value("wps.domain")
|
|
|
- private String domain;
|
|
|
- @Value("wps.appid")
|
|
|
- private String appid;
|
|
|
- @Value("wps.appsecret")
|
|
|
- private String appsecret;
|
|
|
- @Value("wps.download_host")
|
|
|
- private String downloadHost;
|
|
|
- @Value("wps.local_Dir")
|
|
|
- private String localDir;
|
|
|
|
|
|
@Override
|
|
|
public Token getViewUrl(String fileId,String userId,boolean checkToken){
|
|
@@ -95,7 +99,7 @@ public class WpsFileServiceImpl extends ServiceImpl<WpsFileMapper, WpsFile> impl
|
|
|
String uuid = randomUuid.toString().replace("-","");
|
|
|
|
|
|
Map<String,String> values = new HashMap<>();
|
|
|
- values.put("_w_appid", appid);
|
|
|
+ values.put("_w_appid", WpsUtil.appid);
|
|
|
if (checkToken){
|
|
|
values.put("_w_tokentype","1");
|
|
|
}
|
|
@@ -114,11 +118,11 @@ public class WpsFileServiceImpl extends ServiceImpl<WpsFileMapper, WpsFile> impl
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<String,Object> getFileInfo(String userId, String filePath,String _w_filetype){
|
|
|
- if ("web".equalsIgnoreCase(_w_filetype)){
|
|
|
+ public Map<String,Object> getFileInfo(String userId, String filePath,String fileType,String fileId){
|
|
|
+ if ("web".equalsIgnoreCase(fileType)){
|
|
|
return getWebFileInfo(filePath);
|
|
|
- }else if ("db".equalsIgnoreCase(_w_filetype)){
|
|
|
- return getDbFileInfo(userId);
|
|
|
+ }else if ("db".equalsIgnoreCase(fileType)){
|
|
|
+ return getDbFileInfo(userId,fileId);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
@@ -143,54 +147,43 @@ public class WpsFileServiceImpl extends ServiceImpl<WpsFileMapper, WpsFile> impl
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- private Map<String,Object> getDbFileInfo(String userId){
|
|
|
- String fileId = Context.getFileId();
|
|
|
- // 获取文件信息
|
|
|
+ private Map<String,Object> getDbFileInfo(String userId,String fileId){
|
|
|
+ log.info("获取dbfileInfo");
|
|
|
+ Map<String,Object>result = new HashMap<>();
|
|
|
WpsFile fileEntity = this.getById(fileId);
|
|
|
+ String permission = "write";
|
|
|
|
|
|
- // 初始化文件读写权限为read
|
|
|
- String permission = "read";
|
|
|
-
|
|
|
- // 增加用户权限
|
|
|
- WpsUserAcl userAclEntity = wpsUserAclService.findFirstByFileIdAndUserId(fileId,userId);
|
|
|
UserAclBO userAcl = new UserAclBO();
|
|
|
- if (userAclEntity != null){
|
|
|
- BeanUtils.copyProperties(userAclEntity,userAcl);
|
|
|
- permission = userAclEntity.getPermission();
|
|
|
- }
|
|
|
-
|
|
|
// 增加水印
|
|
|
WpsFileWatermark watermarkEntity = wpsFileWatermarkService.findFirstByFileId(fileId);
|
|
|
WatermarkBO watermark = new WatermarkBO();
|
|
|
if (watermarkEntity != null){
|
|
|
BeanUtils.copyProperties(watermarkEntity,watermark);
|
|
|
}
|
|
|
-
|
|
|
//获取user
|
|
|
- WpsUser wpsUser = wpsUserService.getById(userId);
|
|
|
+ SysUser loginUser = sysUserService.getById(userId);
|
|
|
UserDTO user = new UserDTO();
|
|
|
- if (wpsUser != null){
|
|
|
- BeanUtils.copyProperties(wpsUser,user);
|
|
|
+ if (loginUser != null){
|
|
|
+ user.setId(loginUser.getId());
|
|
|
+ user.setName(loginUser.getRealname());
|
|
|
user.setPermission(permission);
|
|
|
}
|
|
|
|
|
|
// 构建fileInfo
|
|
|
FileDTO file = new FileDTO();
|
|
|
BeanUtils.copyProperties(fileEntity,file);
|
|
|
+ String url = fileEntity.getDownloadUrl();
|
|
|
+ url = URLEncoder.encode(url.replace(OSS_URL_PREFIX,""));
|
|
|
+ file.setDownload_url(OSS_URL_PREFIX+url);
|
|
|
file.setUser_acl(userAcl);
|
|
|
file.setWatermark(watermark);
|
|
|
-
|
|
|
- return new HashMap<String, Object>(){
|
|
|
- {
|
|
|
- put("file", file);
|
|
|
- put("user", user);
|
|
|
- }
|
|
|
- };
|
|
|
+ result.put("file",file);
|
|
|
+ result.put("user",user);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void fileRename(String fileName, String userId){
|
|
|
- String fileId = Context.getFileId();
|
|
|
+ public void fileRename(String fileName, String userId,String fileId){
|
|
|
WpsFile file = this.getById(fileId);
|
|
|
if (file != null){
|
|
|
file.setName(fileName);
|
|
@@ -213,13 +206,10 @@ public class WpsFileServiceImpl extends ServiceImpl<WpsFileMapper, WpsFile> impl
|
|
|
// 保存文件
|
|
|
WpsFile f = new WpsFile(fileName,1,fileSize,userId,userId,dataTime,dataTime,fileUrl);
|
|
|
this.save(f);
|
|
|
-
|
|
|
// 处理权限
|
|
|
wpsUserAclService.saveUserFileAcl(userId,f.getId());
|
|
|
-
|
|
|
// 处理水印
|
|
|
wpsFileWatermarkService.saveWatermark(f.getId());
|
|
|
-
|
|
|
// 处理返回
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
map.put("redirect_url",this.getViewUrl(f.getId(),userId,false).getWpsUrl());
|
|
@@ -276,13 +266,11 @@ public class WpsFileServiceImpl extends ServiceImpl<WpsFileMapper, WpsFile> impl
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<String,Object> fileSave(MultipartFile mFile,String userId){
|
|
|
+ public Map<String,Object> fileSave(MultipartFile mFile,String userId,String fileId){
|
|
|
Date date = new Date();
|
|
|
// 上传
|
|
|
- ResFileDTO resFileDTO = WpsOSSUtil.uploadMultipartFile(mFile);
|
|
|
+ ResFileDTO resFileDTO = CosUtils.uploadMultipartFile(mFile,"script-lib/wps/");
|
|
|
int size = (int) resFileDTO.getFileSize();
|
|
|
-
|
|
|
- String fileId = Context.getFileId();
|
|
|
WpsFile file = this.getById(fileId);
|
|
|
FileDTO fileInfo = new FileDTO();
|
|
|
|
|
@@ -363,19 +351,18 @@ public class WpsFileServiceImpl extends ServiceImpl<WpsFileMapper, WpsFile> impl
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void uploadFile(MultipartFile file){
|
|
|
- String uploadUserId = "3";
|
|
|
+ public void uploadFile(MultipartFile file,String userId){
|
|
|
ResFileDTO resFileDTO = WpsOSSUtil.uploadMultipartFile(file);
|
|
|
// 上传成功后,处理数据库记录值
|
|
|
Date date = new Date();
|
|
|
long dataTime = date.getTime();
|
|
|
// 保存文件
|
|
|
WpsFile f = new WpsFile(resFileDTO.getFileName(),1,((int) resFileDTO.getFileSize()),
|
|
|
- uploadUserId,uploadUserId,dataTime,dataTime, resFileDTO.getFileUrl());
|
|
|
+ userId,userId,dataTime,dataTime, resFileDTO.getFileUrl());
|
|
|
this.save(f);
|
|
|
|
|
|
// 处理权限
|
|
|
- wpsUserAclService.saveUserFileAcl(uploadUserId,f.getId());
|
|
|
+ wpsUserAclService.saveUserFileAcl(userId,f.getId());
|
|
|
|
|
|
// 处理水印
|
|
|
wpsFileWatermarkService.saveWatermark(f.getId());
|
|
@@ -383,10 +370,31 @@ public class WpsFileServiceImpl extends ServiceImpl<WpsFileMapper, WpsFile> impl
|
|
|
|
|
|
@Override
|
|
|
public String createTemplateFile(String template){
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
boolean typeTrue = FileUtil.checkCode(template);
|
|
|
if (typeTrue){
|
|
|
- return wpsUtil.getTemplateWpsUrl(template,"3");
|
|
|
+ return wpsUtil.getTemplateWpsUrl(template,sysUser.getId());
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
+ @Autowired
|
|
|
+ private IProjectService projectService;
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> bindProject(String fileId, Long projectId) {
|
|
|
+ Map<String,Object> result = new HashMap<>();
|
|
|
+ WpsFile wpsFile = this.getById(fileId);
|
|
|
+ if(null == wpsFile){
|
|
|
+ ResultMapUtils.setResultMap(result,StatusCode.CTOP_SCRIPT_FILE_NOT_EXIST);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ Project project = projectService.getById(projectId);
|
|
|
+ if(null == project){
|
|
|
+ ResultMapUtils.setResultMap(result,StatusCode.CTOP_PROJECT_NOT_EXIST);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ wpsFile.setProjectId(projectId);
|
|
|
+ this.updateById(wpsFile);
|
|
|
+ ResultMapUtils.setResultMap(result,StatusCode.COMMON_SUCCESS);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|