金山WPS在线编辑
This commit is contained in:
@ -2,6 +2,9 @@ package com.chinaunicom.mall.ebtp.extend.wps.controller;
|
|||||||
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.api.AttachmentClient;
|
||||||
|
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentDetail;
|
||||||
|
import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.model.AttachmentEntity;
|
||||||
import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.SecurityEntity;
|
import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.SecurityEntity;
|
||||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
||||||
import com.chinaunicom.mall.ebtp.common.log.OperationLogDetail;
|
import com.chinaunicom.mall.ebtp.common.log.OperationLogDetail;
|
||||||
@ -9,6 +12,7 @@ import com.chinaunicom.mall.ebtp.common.log.enums.EbtpLogBusinessModule;
|
|||||||
import com.chinaunicom.mall.ebtp.common.log.enums.EbtpLogType;
|
import com.chinaunicom.mall.ebtp.common.log.enums.EbtpLogType;
|
||||||
import com.chinaunicom.mall.ebtp.extend.feign.client.UnicomOAuthClient;
|
import com.chinaunicom.mall.ebtp.extend.feign.client.UnicomOAuthClient;
|
||||||
import com.chinaunicom.mall.ebtp.extend.wps.entity.KingSoftFileSaveVo;
|
import com.chinaunicom.mall.ebtp.extend.wps.entity.KingSoftFileSaveVo;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.wps.enums.WpsExceptionEnum;
|
||||||
import com.chinaunicom.mall.ebtp.extend.wps.service.WpsService;
|
import com.chinaunicom.mall.ebtp.extend.wps.service.WpsService;
|
||||||
import com.chinaunicom.mall.ebtp.extend.wps.util.HttpsUtils;
|
import com.chinaunicom.mall.ebtp.extend.wps.util.HttpsUtils;
|
||||||
import com.chinaunicom.mall.ebtp.extend.wps.vo.WpsClientInVo;
|
import com.chinaunicom.mall.ebtp.extend.wps.vo.WpsClientInVo;
|
||||||
@ -18,7 +22,9 @@ import io.swagger.annotations.Api;
|
|||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang3.StringEscapeUtils;
|
import org.apache.commons.lang3.StringEscapeUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
@ -26,9 +32,11 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.PrintWriter;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@ -45,6 +53,11 @@ public class WpsController {
|
|||||||
|
|
||||||
@Value("${KingSoftWps.kswpsurl}")
|
@Value("${KingSoftWps.kswpsurl}")
|
||||||
private String kswpsurl;
|
private String kswpsurl;
|
||||||
|
|
||||||
|
/* 附件工具 */
|
||||||
|
@Autowired
|
||||||
|
private AttachmentClient attachmentClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得编辑或查看链接
|
* 获得编辑或查看链接
|
||||||
*
|
*
|
||||||
@ -123,6 +136,57 @@ public class WpsController {
|
|||||||
public byte[] getKSFile(@RequestParam("key") String key) {
|
public byte[] getKSFile(@RequestParam("key") String key) {
|
||||||
return this.wpsService.getKSWpsFile(key);
|
return this.wpsService.getKSWpsFile(key);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* (金山)沃文档回调-查询文档
|
||||||
|
* 编辑 permission=write
|
||||||
|
* 预览 permission=read
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ApiOperation("(金山)沃文档回调-查询文档")
|
||||||
|
@GetMapping("/kingSoft/file2")
|
||||||
|
public boolean getKSFile2(HttpServletResponse response,@RequestParam("key") String key) {
|
||||||
|
String fileId = this.wpsService.downloadDecrypt(key);
|
||||||
|
|
||||||
|
List<String> businessIdList = new ArrayList<>();
|
||||||
|
|
||||||
|
businessIdList.add(fileId);
|
||||||
|
|
||||||
|
Optional<AttachmentDetail> optional = attachmentClient.findByBusinessId(businessIdList);
|
||||||
|
|
||||||
|
AttachmentDetail detail = optional.get();
|
||||||
|
|
||||||
|
List<AttachmentEntity> entityList = detail.get(fileId);
|
||||||
|
|
||||||
|
Optional<byte[]> optional1 = attachmentClient.downloadFileByObjectId(entityList.get(0).getId());
|
||||||
|
|
||||||
|
// 设置响应的头信息,告诉浏览器文件的大小和下载方式
|
||||||
|
response.setHeader("Content-Length", String.valueOf(optional1.get().length));
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=\"" + entityList.get(0).getFilename() + "\"");
|
||||||
|
|
||||||
|
try{
|
||||||
|
InputStream word = new ByteArrayInputStream(optional1.get());
|
||||||
|
// 创建输入输出流
|
||||||
|
BufferedInputStream inStream = new BufferedInputStream(word);
|
||||||
|
BufferedOutputStream outStream = new BufferedOutputStream(response.getOutputStream());
|
||||||
|
|
||||||
|
// 读取文件并写入到输出流
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = inStream.read(buffer)) != -1) {
|
||||||
|
outStream.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭输入输出流
|
||||||
|
inStream.close();
|
||||||
|
outStream.close();
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("下载失败",e);
|
||||||
|
WpsExceptionEnum.FRAME_EXCEPTION_NO.customValidName("下载失败", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 沃文档回调-保存文档
|
* 沃文档回调-保存文档
|
||||||
* @return
|
* @return
|
||||||
|
@ -24,5 +24,7 @@ public interface WpsService{
|
|||||||
|
|
||||||
byte[] getKSWpsFile(String id);
|
byte[] getKSWpsFile(String id);
|
||||||
|
|
||||||
|
public String downloadDecrypt(String key);
|
||||||
|
|
||||||
Map<String,String> saveKSFile(KingSoftFileSaveVo vo);
|
Map<String,String> saveKSFile(KingSoftFileSaveVo vo);
|
||||||
}
|
}
|
||||||
|
@ -547,8 +547,8 @@ public class WpsServiceImpl implements WpsService {
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
private String downloadDecrypt(String key){
|
public String downloadDecrypt(String key){
|
||||||
String val = RSA.decrypt(key,kswprivateKey);
|
String val = RSA.decrypt(key,kswprivateKey);
|
||||||
CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.customValidName("令牌无效",val.indexOf("_")<0);
|
CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.customValidName("令牌无效",val.indexOf("_")<0);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user