KMS移动端搜索后点击下载打开文档预览功能
This commit is contained in:
parent
16b0f20147
commit
0ffc7dad26
Binary file not shown.
@ -3,9 +3,11 @@ package com.actionsoft.apps.kms.web;
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Date;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -23,12 +25,7 @@ import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel;
|
||||
import com.actionsoft.apps.kms.KMSConstant;
|
||||
import com.actionsoft.apps.kms.KMSUtil;
|
||||
import com.actionsoft.apps.kms.ac.XpageMgrACCM;
|
||||
import com.actionsoft.apps.kms.cache.CardCache;
|
||||
import com.actionsoft.apps.kms.cache.CardPermCache;
|
||||
import com.actionsoft.apps.kms.cache.DimensionCache;
|
||||
import com.actionsoft.apps.kms.cache.DimensionPermCache;
|
||||
import com.actionsoft.apps.kms.cache.DimensionTreeCache;
|
||||
import com.actionsoft.apps.kms.cache.PublishCache;
|
||||
import com.actionsoft.apps.kms.cache.*;
|
||||
import com.actionsoft.apps.kms.model.CardModel;
|
||||
import com.actionsoft.apps.kms.model.DimensionModel;
|
||||
import com.actionsoft.apps.kms.model.FileModel;
|
||||
@ -686,127 +683,134 @@ public class KnwlSearchWeb extends ActionWeb {
|
||||
* @return
|
||||
*/
|
||||
public String filePreview(UserContext uc,String fileId) {
|
||||
ResponseObject responseObject = ResponseObject.newOkResponse();
|
||||
String sqls = "select taskId from (select * from BO_ACT_COE_PUBLISH_N where PUBLISHFILEID = '" + fileId
|
||||
+ "' order by CREATEDATE desc) where rownum = 1";
|
||||
String taskId = DBSql.getString(sqls);
|
||||
FileModel fileModel = FileCache.getCache().get(fileId);
|
||||
CardModel cardModel = CardCache.getCache().get(fileModel.getCardId());
|
||||
|
||||
String resultUrl=outputReportPreview(uc, taskId, fileId);
|
||||
String cardName=cardModel.getCardName();
|
||||
|
||||
String plname=cardName.substring(0,cardName.indexOf("V"));
|
||||
String plver=cardName.substring(cardName.indexOf("V")+1);
|
||||
String firstPlver =plver.substring(0,plver.indexOf("."));
|
||||
|
||||
String secondPlver=plver.substring(plver.indexOf(".")+1);
|
||||
DecimalFormat df = new DecimalFormat("000");
|
||||
String formattedNumber = df.format(Double.parseDouble(secondPlver));
|
||||
|
||||
String version=firstPlver+"."+formattedNumber;
|
||||
|
||||
ResponseObject responseObject = ResponseObject.newOkResponse();
|
||||
|
||||
|
||||
String resultUrl=outputReportPreview(uc, plname,version);
|
||||
responseObject.setData(resultUrl);
|
||||
return responseObject.toString();
|
||||
}
|
||||
|
||||
|
||||
public String getLastPublishTaskIdByModelId(String repositoryId) {
|
||||
String sql = "SELECT pl.TASKID FROM APP_ACT_COE_PAL_PUBLISH p, APP_ACT_COE_PAL_PUBLISH_LIST pl WHERE pl.pid = p.id AND pl.palrepositoryid = ? ORDER BY publishdate DESC";
|
||||
|
||||
|
||||
public String outputReportPreview(UserContext _uc, String taskId, String palId) {
|
||||
return DBSql.getString(sql,new Object[]{repositoryId});
|
||||
}
|
||||
|
||||
public String outputReportPreview(UserContext _uc, String plname,String version) {
|
||||
|
||||
String returnUrl="";
|
||||
|
||||
String sql = "select * from App_Act_Coe_Pal_Repository where id = '" + palId + "' ";
|
||||
String sql = "select ID,ISPUBLISH,PLNAME,PLMETHODID,PLPARENTID from APP_ACT_COE_PAL_REPOSITORY where plname = '" + plname + "' AND PLVER= '"+version+"'";
|
||||
RowMap map = DBSql.getMap(sql);
|
||||
if (map != null) {
|
||||
String ispulish = map.getString("ISPUBLISH");
|
||||
String palname = map.getString("PLNAME");
|
||||
String methodid = map.getString("PLMETHODID");
|
||||
String plparid = map.getString("PLPARENTID");
|
||||
if ("1".equals(ispulish)) {
|
||||
// if ("control.policy".equals(methodid)) {
|
||||
if ("control.policy".equals(methodid) || "data.form".equals(methodid) || "process.epc".equals(methodid)
|
||||
|| "process.flowchart".equals(methodid) || "process.scheme".equals(methodid) || "engineering.standard".equals(methodid)) {
|
||||
try {
|
||||
OutputTaskModel model = new OutputTask().getTaskReportById(taskId);
|
||||
ResponseObject result = ResponseObject.newOkResponse();
|
||||
if (model != null) {
|
||||
UtilFile file = OutputAPIManager.getInstance().getFilePath(model.getWsId(), taskId,
|
||||
model.getProfileId());
|
||||
if (file.exists()) {
|
||||
File[] fileList = file.listFiles();
|
||||
if (fileList.length > 0) {
|
||||
File docFile = null;
|
||||
for (File file2 : fileList) {
|
||||
if (file2.isFile() && "doc".equals(
|
||||
(file2.getName().substring(file2.getName().lastIndexOf(".") + 1)))) {
|
||||
docFile = file2;
|
||||
break;
|
||||
String plid=map.getString("ID");
|
||||
|
||||
System.out.println("plid===="+plid);
|
||||
|
||||
String taskId=getLastPublishTaskIdByModelId(plid);
|
||||
|
||||
System.out.println("taskId====="+taskId);
|
||||
OutputTaskModel model = new OutputTask().getTaskReportById(taskId);
|
||||
ResponseObject result = ResponseObject.newOkResponse();
|
||||
if (model != null) {
|
||||
try {
|
||||
UtilFile file = OutputAPIManager.getInstance().getFilePath(model.getWsId(), taskId, model.getProfileId());
|
||||
if (file.exists()) {
|
||||
File[] fileList = file.listFiles();
|
||||
if (fileList.length > 0) {
|
||||
File docFile = null;
|
||||
for (File file2 : fileList) {
|
||||
if (file2.isFile() && "doc".equals((file2.getName().substring(file2.getName().lastIndexOf(".") + 1))) || file2.isFile() && "pptx".equals((file2.getName().substring(file2.getName().lastIndexOf(".") + 1))) || "xlsx".equals((file2.getName().substring(file2.getName().lastIndexOf(".") + 1))) || "xls".equals((file2.getName().substring(file2.getName().lastIndexOf(".") + 1)))) {
|
||||
docFile = file2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (docFile == null) {
|
||||
return ResponseObject.newErrResponse("没有找到文件").toString();
|
||||
}
|
||||
|
||||
if ("xls".equals((docFile.getName().substring(docFile.getName().lastIndexOf(".") + 1))) || "xlsx".equals((docFile.getName().substring(docFile.getName().lastIndexOf(".") + 1)))) {
|
||||
OutputAppProfile appFile = OutputAppManager.getProfile(model.getProfileId());
|
||||
String sourceAppId = appFile.getAppContext().getId();
|
||||
String filename = docFile.getName();
|
||||
DCContext sourceDc = new DCContext(_uc, DCProfileManager.getDCProfile(sourceAppId, "output"), sourceAppId, model.getWsId(), taskId, filename);
|
||||
String dcPath = sourceDc.getDownloadURL();
|
||||
if (!UtilString.isEmpty(dcPath)) {
|
||||
dcPath = dcPath.substring(1);
|
||||
String portalUrl = SDK.getAppAPI().getProperty("com.actionsoft.apps.addons.onlinedoc", "portalurl");
|
||||
if (portalUrl.isEmpty()) {
|
||||
portalUrl = SDK.getPortalAPI().getPortalUrl();
|
||||
}
|
||||
String p = portalUrl + "/r" + dcPath;
|
||||
String url = "https://view.officeapps.live.com/op/view.aspx?src=" + URLEncoder.encode(p, "UTF-8");
|
||||
result.put("url", url);
|
||||
result.put("filename", filename);
|
||||
|
||||
}
|
||||
} else {
|
||||
if (SDK.getAppAPI().isActive("com.actionsoft.apps.addons.onlinedoc")) {
|
||||
OutputAppProfile appFile = OutputAppManager.getProfile(model.getProfileId());
|
||||
String sourceAppId = appFile.getAppContext().getId();
|
||||
String filename = docFile.getName();
|
||||
DCContext sourceDc = new DCContext(_uc, DCProfileManager.getDCProfile(sourceAppId, "output"), sourceAppId, model.getWsId(), taskId, filename);
|
||||
Map<String, Object> aslpParams = new HashMap<String, Object>();
|
||||
aslpParams.put("sid", _uc.getSessionId());
|
||||
aslpParams.put("fileNameOriginal", filename);
|
||||
aslpParams.put("sourceDc", sourceDc);
|
||||
aslpParams.put("isShowDefaultToolbar", true);
|
||||
aslpParams.put("isShowBackbtn", false);
|
||||
aslpParams.put("isEncrypt", true);
|
||||
aslpParams.put("isCopy", true);
|
||||
aslpParams.put("isPrint", true);
|
||||
aslpParams.put("isDownload", true);
|
||||
AppAPI appAPI = SDK.getAppAPI();
|
||||
ResponseObject responseObject = appAPI.callASLP(appAPI.getAppContext(sourceAppId), "aslp://com.actionsoft.apps.addons.onlinedoc/filePreview", aslpParams);
|
||||
if (responseObject != null) {
|
||||
if (responseObject.isOk()) {
|
||||
String url = SDK.getPortalAPI().getPortalUrl() + "/r" +responseObject.get("url").toString().substring(1);
|
||||
returnUrl=url.replaceAll("\\s+", "");
|
||||
} else {
|
||||
result = ResponseObject.newErrResponse("文档转换服务不可用,请联系管理员");
|
||||
}
|
||||
}
|
||||
if (docFile == null) {
|
||||
result = ResponseObject.newErrResponse("没有手册文件!");
|
||||
}
|
||||
if (SDK.getAppAPI().isActive("com.actionsoft.apps.addons.onlinedoc")) {
|
||||
OutputAppProfile appFile = OutputAppManager.getProfile(model.getProfileId());
|
||||
String sourceAppId = appFile.getAppContext().getId();
|
||||
String filename = docFile.getName();
|
||||
System.err.println("开始转换===>" + filename + "===>" + sourceAppId);
|
||||
DCContext sourceDc = new DCContext(_uc,
|
||||
DCProfileManager.getDCProfile(sourceAppId, "output"), sourceAppId,
|
||||
model.getWsId(), taskId, filename);
|
||||
|
||||
|
||||
// 调用App
|
||||
// aslp服务地址
|
||||
String aslp = "aslp://com.actionsoft.apps.addons.onlinedoc/fileConvert";
|
||||
// 参数定义列表
|
||||
HashMap<String, Object> params = new HashMap<String, Object>();
|
||||
// PDF转图片处理选项。- 0代表只在需要时做转换;- 1代表打开即检查是否已转换成图片,如未处理,强制转换。默认0,非必填
|
||||
params.put("isPDFCovertPNG", "0");
|
||||
// 原文件DC,必填
|
||||
params.put("sourceDc", sourceDc);
|
||||
// 文档是否允许复制。true为允许复制,转换结果为PDF格式文件;false为不可复制,转换结果为PNG格式文件(注意参数值为false时转换时间稍长),必填
|
||||
params.put("isCopy", true);
|
||||
// sessionid,必填
|
||||
params.put("sid", _uc.getSessionId());
|
||||
AppAPI appAPI = SDK.getAppAPI();
|
||||
// 调用转换服务.在预览之前提前进行转换,预览时直接打开转换后的文件
|
||||
String sourceId = "com.actionsoft.apps.coe.pal.publisher";
|
||||
AppContext appContext = appAPI.getAppContext(sourceId);
|
||||
ResponseObject responseObject = appAPI.callASLP(appContext, aslp, params);
|
||||
System.err.println("转换结果=======>" + responseObject);
|
||||
if (responseObject != null) {
|
||||
String results = responseObject.toString();
|
||||
if (UtilString.isNotEmpty(results)) {
|
||||
if (results.contains("200")) {
|
||||
Map<String, Object> aslpParams = new HashMap<String, Object>();
|
||||
aslpParams.put("sid", _uc.getSessionId());
|
||||
aslpParams.put("fileNameOriginal", filename);
|
||||
aslpParams.put("sourceDc", sourceDc);
|
||||
aslpParams.put("isShowDefaultToolbar", true);
|
||||
aslpParams.put("isShowBackbtn", false);
|
||||
aslpParams.put("isEncrypt", true);
|
||||
aslpParams.put("isCopy", true);
|
||||
aslpParams.put("isPrint", true);
|
||||
aslpParams.put("isDownload", true);
|
||||
ResponseObject responseObjects = appAPI.callASLP(
|
||||
appAPI.getAppContext(sourceAppId),
|
||||
"aslp://com.actionsoft.apps.addons.onlinedoc/filePreview",
|
||||
aslpParams);
|
||||
|
||||
if (responseObjects != null) {
|
||||
if (responseObjects.isOk()) {
|
||||
String url = responseObjects.get("url").toString();
|
||||
returnUrl= url.substring(url.indexOf("&cmd"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result = ResponseObject.newErrResponse("文档转换服务不可用,请联系管理员");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
result = ResponseObject.newErrResponse("文档转换服务不可用,请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
|
||||
} else {
|
||||
result = ResponseObject.newErrResponse("没有可预览文件");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResponseObject.newErrResponse().toString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
System.out.println("returnUrl========"+returnUrl);
|
||||
return returnUrl;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user