预览切换成wps在线预览功能,需要结合文件预览服务应用一起上线
This commit is contained in:
parent
2aa2d0be2d
commit
5ec054dfad
@ -0,0 +1,24 @@
|
||||
package com.awspaas.user.apps.yiliwps;
|
||||
|
||||
import com.actionsoft.apps.listener.PluginListener;
|
||||
import com.actionsoft.apps.resource.AppContext;
|
||||
import com.actionsoft.apps.resource.plugin.profile.ASLPPluginProfile;
|
||||
import com.actionsoft.apps.resource.plugin.profile.AWSPluginProfile;
|
||||
import com.awspaas.user.apps.yiliwps.aslp.WPSOnlineReadOnlyASLP;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:yujh
|
||||
* @Date: 2025/1/21 15:47
|
||||
*/
|
||||
public class Plugins implements PluginListener {
|
||||
public Plugins() {
|
||||
}
|
||||
public List<AWSPluginProfile> register(AppContext context) {
|
||||
List<AWSPluginProfile> list = new ArrayList<AWSPluginProfile>();
|
||||
list.add(new ASLPPluginProfile("wpsOnlineReadOnly", WPSOnlineReadOnlyASLP.class.getName(), "调用转换服务.在预览之前提前进行转换,预览时直接打开转换后的文件", null));
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
package com.awspaas.user.apps.yiliwps.aslp;
|
||||
|
||||
import com.actionsoft.apps.resource.interop.aslp.ASLP;
|
||||
import com.actionsoft.apps.resource.interop.aslp.Meta;
|
||||
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
|
||||
import com.actionsoft.bpms.server.fs.DCContext;
|
||||
import com.awspaas.user.apps.yiliwps.constant.YiliWpsConst;
|
||||
import com.awspaas.user.apps.yiliwps.utils.HttpPostUtil;
|
||||
import com.awspaas.user.apps.yiliwps.utils.WPS4Util;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author:yujh
|
||||
* @Date: 2025/1/21 15:39
|
||||
*/
|
||||
public class WPSOnlineReadOnlyASLP implements ASLP {
|
||||
public WPSOnlineReadOnlyASLP() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Meta(parameter = { "name: 'sid', required: true, desc:'sessionid'",
|
||||
"name: 'sourceDc', required: true, desc:'原文件DC'"})
|
||||
public ResponseObject call(Map<String, Object> params) {
|
||||
ResponseObject result = ResponseObject.newOkResponse();
|
||||
if (params == null) {
|
||||
result.err("不接受参数为空的调用!");
|
||||
return result;
|
||||
}
|
||||
String sid = params.get("sid").toString();
|
||||
DCContext sourceDc = (DCContext) params.get("sourceDc");
|
||||
String fileName = sourceDc.getFileName();
|
||||
String fileType = getFileType(fileName);
|
||||
WPS4Util.initAppInfo(YiliWpsConst.AK, YiliWpsConst.SK);
|
||||
|
||||
String url = String.format("/api/preview/v1/files/%s/link?type=%s&preview_mode=%s&_w_third_sid=%s&_w_third_palId=%s&_w_third_queryFileId=%s&_w_third_fname=%s&_w_third_appId=%s&_w_third_repositoryName=%s&_w_third_groupValue=%s&_w_third_fileValue=%s"
|
||||
,sourceDc.getFileValue(),fileType,"ordinary",sid,sourceDc.getGroupValue(),sourceDc.getFileValue(), URLEncoder.encode(sourceDc.getFileName()),sourceDc.getAppId(),sourceDc.getRepositoryName(),sourceDc.getGroupValue(),sourceDc.getFileValue());
|
||||
System.out.println(">>>>>>>>预览的url = " + url);
|
||||
Map<String,String> headers = null;
|
||||
try {
|
||||
headers = WPS4Util.getSignatureHeaders(url, HttpMethod.GET,null, YiliWpsConst.CONTENT_TYPE);
|
||||
result.setData(HttpPostUtil.sendGetRequest(YiliWpsConst.HOST+"/open"+url,headers));
|
||||
System.out.println(">>>>>>>>>>result.toString() = " + result.toString());
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件名获取文件类型
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public String getFileType(String fileName){
|
||||
//根据文件名获取文件类型
|
||||
if (fileName.endsWith(".doc") || fileName.endsWith(".docx")) {
|
||||
return "w";
|
||||
} else if (fileName.endsWith(".xls") || fileName.endsWith(".xlsx")) {
|
||||
return "s";
|
||||
} else if (fileName.endsWith(".pdf") || fileName.endsWith(".pdfx")) {
|
||||
return "p";
|
||||
}
|
||||
return "w";
|
||||
}
|
||||
}
|
||||
@ -25,13 +25,17 @@ public class YiliWpsApi {
|
||||
@QueryParam("_w_third_palId") String palId,
|
||||
@QueryParam("_w_third_queryFileId") String queryFileId,
|
||||
@QueryParam("_w_third_sid") String sid,
|
||||
@QueryParam("_w_third_fname") String fileName
|
||||
@QueryParam("_w_third_fname") String fileName,
|
||||
@QueryParam("_w_third_appId") String appId,
|
||||
@QueryParam("_w_third_repositoryName") String repositoryName,
|
||||
@QueryParam("_w_third_groupValue") String groupValue,
|
||||
@QueryParam("_w_third_fileValue") String fileValue
|
||||
) {
|
||||
JSONObject params = new JSONObject();
|
||||
UserContext _uc = UserContext.fromSessionId(sid);
|
||||
logApi.consoleInfo(">>>>>文件信息请求成功/v1/3rd/file/info"+palId+","+headFileId+queryFileId+sid+fileName);
|
||||
logApi.consoleInfo(">>>>>文件信息请求成功/v1/3rd/file/info"+palId+","+headFileId+queryFileId+sid+fileName+appId+repositoryName+groupValue+fileValue);
|
||||
WpsWeb web =new WpsWeb(_uc);
|
||||
return web.getFileInfo(sid,palId,queryFileId,fileName);
|
||||
return web.getFileInfo(sid,palId,queryFileId,fileName,appId,repositoryName,groupValue,fileValue);
|
||||
}
|
||||
|
||||
@Path("/v1/3rd/user/info")
|
||||
|
||||
@ -33,6 +33,7 @@ import com.awspaas.user.apps.yiliwps.utils.CallASLPUtil;
|
||||
import com.awspaas.user.apps.yiliwps.utils.HttpPostUtil;
|
||||
import com.awspaas.user.apps.yiliwps.utils.WPS4Util;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import java.io.*;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
@ -81,14 +82,15 @@ public class WpsWeb extends ActionWeb {
|
||||
return HttpPostUtil.sendGetRequest(YiliWpsConst.HOST+"/open"+url,headers);
|
||||
}
|
||||
|
||||
public String getFileInfo(String sid,String palId,String fileId,String fileName){
|
||||
public String getFileInfo(String sid,String palId,String fileId,String fileName,String appId,String repositoryName,String groupValue,String fileValue){
|
||||
String sourceFileName = null;
|
||||
try {
|
||||
sourceFileName = URLDecoder.decode(fileName,"UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
DCContext sourceDc = getFileDCContext(fileId);
|
||||
//DCContext sourceDc = getFileDCContext(fileId);
|
||||
DCContext sourceDc = getFileDCContext(palId,appId,repositoryName,groupValue,fileValue,sourceFileName);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
JSONObject file = new JSONObject();
|
||||
JSONObject user = new JSONObject();
|
||||
@ -279,6 +281,38 @@ public class WpsWeb extends ActionWeb {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取附件的附件ID
|
||||
* @return
|
||||
*/
|
||||
public DCContext getFileDCContext(String palId,String appId,String repositoryName,String groupValue,String fileValue,String fileName) {
|
||||
//先校验DC是否存在
|
||||
DCContext sourceDc = null;
|
||||
System.out.println(">>>>>>>appId = " + appId);
|
||||
System.out.println(">>>>>>>repositoryName = " + repositoryName);
|
||||
DCPluginProfile dcProfile = DCProfileManager.getDCProfile(appId, repositoryName);
|
||||
if (dcProfile != null) {
|
||||
System.out.println(" >>>>进入普通文件");
|
||||
sourceDc = new DCContext(this.getContext(), dcProfile, appId, groupValue,
|
||||
fileValue, fileName);
|
||||
if(null != sourceDc){
|
||||
System.out.println(">>>>>>>>>>>>>>>>sourceDc.getDownloadURL() = " + sourceDc.getDownloadURL());
|
||||
return sourceDc;
|
||||
}
|
||||
//获取的附件为空
|
||||
}
|
||||
//先获取附件模版
|
||||
System.out.println(" >>>>默认附件");
|
||||
repositoryName = "!form-ui-file-";
|
||||
BO bo = SDK.getBOAPI().query(YiliWpsConst.BO_EU_SYSTEM_DEMO_FILE).addQuery("FILESTATE=", true).detail();
|
||||
List<FormFile> files = SDK.getBOAPI().getFiles(bo.getId(), "SYSTEMFILE");
|
||||
FormFile formFile = files.get(0);
|
||||
sourceDc = SDK.getBOAPI().getFileDCContext(formFile, repositoryName);
|
||||
sourceDc.setSession(this.getContext());
|
||||
//往附件表中写入一个附件
|
||||
return sourceDc;
|
||||
}
|
||||
|
||||
public String getCoeDefinition(String palId){
|
||||
// coe所需参数
|
||||
PALRepositoryModel plModel = PALRepositoryCache.getCache().get(palId);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user