|
@ -19,7 +19,6 @@ import com.ccsens.util.*; |
|
|
import com.ccsens.util.exception.BaseException; |
|
|
import com.ccsens.util.exception.BaseException; |
|
|
import io.jsonwebtoken.Claims; |
|
|
import io.jsonwebtoken.Claims; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
@ -27,15 +26,12 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
import javax.servlet.http.Part; |
|
|
import javax.servlet.http.Part; |
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
import java.util.Date; |
|
|
import java.util.*; |
|
|
import java.util.HashMap; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @description: |
|
|
* wps文件 |
|
|
* @author: whj |
|
|
* @author: whj |
|
|
* @time: 2020/6/17 18:05 |
|
|
* @date: 2020/6/17 18:05 |
|
|
*/ |
|
|
*/ |
|
|
@Slf4j |
|
|
@Slf4j |
|
|
@Service |
|
|
@Service |
|
@ -55,17 +51,78 @@ public class WpsService implements IWpsService { |
|
|
@Resource |
|
|
@Resource |
|
|
private WpsNotifyMapper wpsNotifyMapper; |
|
|
private WpsNotifyMapper wpsNotifyMapper; |
|
|
@Resource |
|
|
@Resource |
|
|
private IProRoleService proRoleService; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private RedisUtil redisUtil; |
|
|
private RedisUtil redisUtil; |
|
|
@Resource |
|
|
@Resource |
|
|
private Snowflake snowflake; |
|
|
private Snowflake snowflake; |
|
|
|
|
|
|
|
|
private String fileUrl = "http://wwo.wps.cn/office/{}/{}?_w_appid="+WebConstant.Wps.APPID+"&_w_signature={}"; |
|
|
@Override |
|
|
|
|
|
public List<String> queryVisitUrls(long businessId, byte businessType, String token) { |
|
|
|
|
|
log.info("查询访问路径:{},{}", businessId, businessType); |
|
|
|
|
|
List<String> urls = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
List<WpsVo.BusinessFile> files = wpsFileDao.queryFileByBusiness(businessId, businessType); |
|
|
|
|
|
files.forEach(file -> { |
|
|
|
|
|
String name = file.getFileName(); |
|
|
|
|
|
log.info("文件名:{}", name); |
|
|
|
|
|
String url = getUrl(String.valueOf(file.getFileId()), name.substring(name.lastIndexOf(".") + 1), token); |
|
|
|
|
|
urls.add(url); |
|
|
|
|
|
}); |
|
|
|
|
|
log.info("访问路径返回结果:{}", urls); |
|
|
|
|
|
return urls; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void saveFile(WpsDto.Business business) { |
|
|
|
|
|
ProProjectFile proProjectFile = null; |
|
|
|
|
|
if (business.getWpsFileId() != null) { |
|
|
|
|
|
ProProjectFileExample example = new ProProjectFileExample(); |
|
|
|
|
|
example.createCriteria().andBusinessIdEqualTo(business.getBusinessId()) |
|
|
|
|
|
.andBusinessTypeEqualTo(business.getBusinessType()) |
|
|
|
|
|
.andFileIdEqualTo(business.getWpsFileId()); |
|
|
|
|
|
List<ProProjectFile> proProjectFiles = proProjectFileMapper.selectByExample(example); |
|
|
|
|
|
if (CollectionUtil.isEmpty(proProjectFiles)) { |
|
|
|
|
|
throw new BaseException(CodeEnum.PARAM_ERROR); |
|
|
|
|
|
} |
|
|
|
|
|
proProjectFile = proProjectFiles.get(0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 保存文件版本信息
|
|
|
|
|
|
WpsFile wpsFile = saveWpsFile(business.getWpsFileId() == null ? null : String.valueOf(business.getWpsFileId()), |
|
|
|
|
|
business.getFileSize(), business.getUserId(), business.getFilePath(), |
|
|
|
|
|
business.getFileName()); |
|
|
|
|
|
// 更新文件记录
|
|
|
|
|
|
WpsFileVersion version = saveVersion(wpsFile); |
|
|
|
|
|
// 调用接口,更新数据项目接口(异步调用)
|
|
|
|
|
|
// 保存用户提交记录
|
|
|
|
|
|
WpsFileUser wpsFileUser = initFileUser(business.getUserId(), version.getId()); |
|
|
|
|
|
wpsFileUser.setOperation(business.getOperation()); |
|
|
|
|
|
wpsFileUserMapper.insertSelective(wpsFileUser); |
|
|
|
|
|
// 文件ID为空,保存文件和业务的关系
|
|
|
|
|
|
if (proProjectFile == null) { |
|
|
|
|
|
saveBusiness(business, wpsFile); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 保存业务文件关联 |
|
|
|
|
|
* @param business 业务信息 |
|
|
|
|
|
* @param wpsFile 获取文件ID |
|
|
|
|
|
*/ |
|
|
|
|
|
private void saveBusiness(WpsDto.Business business, WpsFile wpsFile) { |
|
|
|
|
|
ProProjectFile proProjectFile; |
|
|
|
|
|
proProjectFile = new ProProjectFile(); |
|
|
|
|
|
proProjectFile.setId(snowflake.nextId()); |
|
|
|
|
|
proProjectFile.setFileId(wpsFile.getId()); |
|
|
|
|
|
proProjectFile.setBusinessId(business.getBusinessId()); |
|
|
|
|
|
proProjectFile.setBusinessType(business.getBusinessType()); |
|
|
|
|
|
proProjectFile.setPrivilege(business.getPrivilege()); |
|
|
|
|
|
proProjectFile.setPrivilegeQueryUrl(business.getPrivilegeQueryUrl()); |
|
|
|
|
|
proProjectFileMapper.insertSelective(proProjectFile); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void notify(String token, WpsDto.NotifyBody body) throws Exception { |
|
|
public void notify(String token, WpsDto.NotifyBody body) throws Exception { |
|
|
Long userId = getUserId(token); |
|
|
getUserId(token); |
|
|
WpsNotify wpsNotify = new WpsNotify(); |
|
|
WpsNotify wpsNotify = new WpsNotify(); |
|
|
wpsNotify.setId(snowflake.nextId()); |
|
|
wpsNotify.setId(snowflake.nextId()); |
|
|
wpsNotify.setCmd(body.getCmd()); |
|
|
wpsNotify.setCmd(body.getCmd()); |
|
@ -73,6 +130,7 @@ public class WpsService implements IWpsService { |
|
|
wpsNotifyMapper.insertSelective(wpsNotify); |
|
|
wpsNotifyMapper.insertSelective(wpsNotify); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void fileRename(String token, long fileId, WpsDto.FileRenameBody renameBody) throws Exception { |
|
|
public void fileRename(String token, long fileId, WpsDto.FileRenameBody renameBody) throws Exception { |
|
|
Long userId = getUserId(token); |
|
|
Long userId = getUserId(token); |
|
@ -106,9 +164,8 @@ public class WpsService implements IWpsService { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public List<WpsVo.FileHistoryMsg> queryFileHistory(String token, WpsDto.FileHistoryBody body) throws Exception { |
|
|
public List<WpsVo.FileHistoryMsg> queryFileHistory(String token, WpsDto.FileHistoryBody body) throws Exception { |
|
|
Long userId = getUserId(token); |
|
|
getUserId(token); |
|
|
List<WpsVo.FileHistoryMsg> msgs = wpsFileDao.queryFileHistory(body); |
|
|
return wpsFileDao.queryFileHistory(body); |
|
|
return msgs; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -132,17 +189,29 @@ public class WpsService implements IWpsService { |
|
|
WpsFile wpsFile = saveWpsFile(token, fileId, file,WebConstant.Wps.USER_OPERATION_NEW); |
|
|
WpsFile wpsFile = saveWpsFile(token, fileId, file,WebConstant.Wps.USER_OPERATION_NEW); |
|
|
String fileName = UploadFileUtil_Servlet3.getFileNameByPart(file); |
|
|
String fileName = UploadFileUtil_Servlet3.getFileNameByPart(file); |
|
|
String ext = FileUtil.extName(fileName); |
|
|
String ext = FileUtil.extName(fileName); |
|
|
|
|
|
String url = getUrl(fileId, ext, token); |
|
|
|
|
|
WpsVo.FileNew fileNew = new WpsVo.FileNew(); |
|
|
|
|
|
fileNew.setRedirect_url(url); |
|
|
|
|
|
fileNew.setUser_id(String.valueOf(wpsFile.getCreator())); |
|
|
|
|
|
return fileNew; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 返回WPS文件访问路径 |
|
|
|
|
|
* @param fileId 文件ID |
|
|
|
|
|
* @param ext 后缀 |
|
|
|
|
|
* @param token token |
|
|
|
|
|
* @return wps访问路径 |
|
|
|
|
|
*/ |
|
|
|
|
|
private String getUrl(String fileId, String ext, String token) { |
|
|
String fileType = WebConstant.Wps.getFileType(ext); |
|
|
String fileType = WebConstant.Wps.getFileType(ext); |
|
|
Map<String, String> paramMap= new HashMap<>(); |
|
|
Map<String, String> paramMap= new HashMap<>(); |
|
|
paramMap.put("_w_appid", WebConstant.Wps.APPID); |
|
|
paramMap.put("_w_appid", WebConstant.Wps.APPID); |
|
|
// paramMap.put("_w_fname", fileName);
|
|
|
// paramMap.put("_w_fname", fileName);
|
|
|
// paramMap.put("_w_userid", String.valueOf(wpsFile.getCreator()));
|
|
|
// paramMap.put("_w_userid", String.valueOf(wpsFile.getCreator()));
|
|
|
String newSignature = WpsSignature.getSignature(paramMap, WebConstant.Wps.APPKEY); |
|
|
String newSignature = WpsSignature.getSignature(paramMap, WebConstant.Wps.APPKEY); |
|
|
String url = StrUtil.format(fileUrl, fileType, wpsFile.getId(), newSignature); |
|
|
String fileUrl = "http://wwo.wps.cn/office/{}/{}?_w_appid=" + WebConstant.Wps.APPID + "&_w_signature={}&token={}"; |
|
|
WpsVo.FileNew fileNew = new WpsVo.FileNew(); |
|
|
return StrUtil.format(fileUrl, fileType, fileId, newSignature, token); |
|
|
fileNew.setRedirect_url(url); |
|
|
|
|
|
fileNew.setUser_id(String.valueOf(wpsFile.getCreator())); |
|
|
|
|
|
return fileNew; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -189,21 +258,39 @@ public class WpsService implements IWpsService { |
|
|
return fileInfo; |
|
|
return fileInfo; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int power = proRoleService.selectPowerByRoleName(userId, proProjectFiles.get(0).getId()); |
|
|
ProProjectFile projectFile = proProjectFiles.get(0); |
|
|
log.info("权限:{}", power); |
|
|
byte businessType = projectFile.getBusinessType(); |
|
|
if (power > 1) { |
|
|
switch (businessType) { |
|
|
user.setPermission(WebConstant.Wps.PERMISSION_WRITE); |
|
|
case WebConstant.Wps.PROJECT_PRIVILEGE_READ : |
|
|
|
|
|
user.setPermission(WebConstant.Wps.PERMISSION_READ); |
|
|
|
|
|
break; |
|
|
|
|
|
case WebConstant.Wps.PROJECT_PRIVILEGE_WRITE: |
|
|
|
|
|
user.setPermission(WebConstant.Wps.PERMISSION_WRITE); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
|
|
json.put("id", projectFile.getBusinessId()); |
|
|
|
|
|
json.put("type", projectFile.getBusinessType()); |
|
|
|
|
|
json.put("fileId", projectFile.getFileId()); |
|
|
|
|
|
String result = RestTemplateUtil.postBody(projectFile.getPrivilegeQueryUrl(), json); |
|
|
|
|
|
user.setPermission(result); |
|
|
} |
|
|
} |
|
|
wpsFileUser.setOperation(power > 1 ? WebConstant.Wps.USER_OPERATION_WRITE : WebConstant.Wps.USER_OPERATION_READ); |
|
|
|
|
|
|
|
|
// int power = proRoleService.selectPowerByRoleName(userId, proProjectFiles.get(0).getId());
|
|
|
|
|
|
// log.info("权限:{}", power);
|
|
|
|
|
|
// if (power > 1) {
|
|
|
|
|
|
// user.setPermission(WebConstant.Wps.PERMISSION_WRITE);
|
|
|
|
|
|
// }
|
|
|
|
|
|
wpsFileUser.setOperation(WebConstant.Wps.PERMISSION_READ.equals(user.getPermission()) ? WebConstant.Wps.USER_OPERATION_READ : WebConstant.Wps.USER_OPERATION_WRITE); |
|
|
wpsFileUserMapper.insertSelective(wpsFileUser); |
|
|
wpsFileUserMapper.insertSelective(wpsFileUser); |
|
|
return fileInfo; |
|
|
return fileInfo; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 初始化用户和文档(无操作类型) |
|
|
* 初始化用户和文档(无操作类型) |
|
|
* @param userId |
|
|
* @param userId 用户id |
|
|
* @param fileId |
|
|
* @param fileId 文件id |
|
|
* @return |
|
|
* @return 用户操作文件记录 |
|
|
*/ |
|
|
*/ |
|
|
private WpsFileUser initFileUser(Long userId, Long fileId) { |
|
|
private WpsFileUser initFileUser(Long userId, Long fileId) { |
|
|
WpsFileUser wpsFileUser = new WpsFileUser(); |
|
|
WpsFileUser wpsFileUser = new WpsFileUser(); |
|
@ -238,7 +325,7 @@ public class WpsService implements IWpsService { |
|
|
String filePath = WebConstant.UPLOAD_PATH_WPS + File.separator + path; |
|
|
String filePath = WebConstant.UPLOAD_PATH_WPS + File.separator + path; |
|
|
String name = UploadFileUtil_Servlet3.getFileNameByPart(file); |
|
|
String name = UploadFileUtil_Servlet3.getFileNameByPart(file); |
|
|
// 保存文件版本信息
|
|
|
// 保存文件版本信息
|
|
|
WpsFile wpsFile = saveWpsFile(fileId, file, userId, filePath, name); |
|
|
WpsFile wpsFile = saveWpsFile(fileId, file.getSize(), userId, filePath, name); |
|
|
// 更新文件记录
|
|
|
// 更新文件记录
|
|
|
WpsFileVersion version = saveVersion(wpsFile); |
|
|
WpsFileVersion version = saveVersion(wpsFile); |
|
|
// 调用接口,更新数据项目接口(异步调用)
|
|
|
// 调用接口,更新数据项目接口(异步调用)
|
|
@ -257,6 +344,7 @@ public class WpsService implements IWpsService { |
|
|
version.setName(wpsFile.getName()); |
|
|
version.setName(wpsFile.getName()); |
|
|
version.setSize(wpsFile.getSize()); |
|
|
version.setSize(wpsFile.getSize()); |
|
|
version.setDownloadUrl(wpsFile.getDownloadUrl()); |
|
|
version.setDownloadUrl(wpsFile.getDownloadUrl()); |
|
|
|
|
|
version.setSaveUrl(wpsFile.getSaveUrl()); |
|
|
version.setModifier(wpsFile.getModifier()); |
|
|
version.setModifier(wpsFile.getModifier()); |
|
|
wpsFileVersionMapper.insertSelective(version); |
|
|
wpsFileVersionMapper.insertSelective(version); |
|
|
return version; |
|
|
return version; |
|
@ -264,14 +352,14 @@ public class WpsService implements IWpsService { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 保存文件信息 |
|
|
* 保存文件信息 |
|
|
* @param fileId |
|
|
* @param fileId 文件ID,无则保存,有则修改 |
|
|
* @param file |
|
|
* @param fileSize 文件大小 |
|
|
* @param userId |
|
|
* @param userId 用户id |
|
|
* @param filePath |
|
|
* @param filePath 文件位置,默认在:WebConstant.UPLOAD_PATH_BASE 下 |
|
|
* @param name |
|
|
* @param name 文件名字 |
|
|
* @return |
|
|
* @return wpsFile |
|
|
*/ |
|
|
*/ |
|
|
private WpsFile saveWpsFile(String fileId, Part file, Long userId, String filePath, String name) { |
|
|
private WpsFile saveWpsFile(String fileId, Long fileSize, Long userId, String filePath, String name) { |
|
|
WpsFile wpsFile; |
|
|
WpsFile wpsFile; |
|
|
if (StrUtil.isEmpty(fileId)) { |
|
|
if (StrUtil.isEmpty(fileId)) { |
|
|
// 创建文件ID
|
|
|
// 创建文件ID
|
|
@ -289,8 +377,9 @@ public class WpsService implements IWpsService { |
|
|
wpsFile.setCreatedAt(new Date()); |
|
|
wpsFile.setCreatedAt(new Date()); |
|
|
wpsFile.setUpdatedAt(new Date()); |
|
|
wpsFile.setUpdatedAt(new Date()); |
|
|
wpsFile.setName(name); |
|
|
wpsFile.setName(name); |
|
|
wpsFile.setSize(file.getSize()); |
|
|
wpsFile.setSize(fileSize); |
|
|
wpsFile.setDownloadUrl(PropUtil.domain + "file/download/" + name + "?path=" + filePath); |
|
|
wpsFile.setDownloadUrl(PropUtil.domain + "file/download/" + name + "?path=" + filePath); |
|
|
|
|
|
wpsFile.setSaveUrl(WebConstant.UPLOAD_PATH_BASE + File.separator + filePath); |
|
|
wpsFile.setModifier(userId); |
|
|
wpsFile.setModifier(userId); |
|
|
|
|
|
|
|
|
if (StrUtil.isEmpty(fileId)) { |
|
|
if (StrUtil.isEmpty(fileId)) { |
|
|