|
|
|
|
<%@ page import="org.slf4j.Logger" %>
|
|
|
|
|
<%@ page import="org.slf4j.LoggerFactory" %>
|
|
|
|
|
<%@ page import="java.util.HashMap" %>
|
|
|
|
|
<%@ page import="java.util.Map" %>
|
|
|
|
|
<%@ page import="net.sf.json.JSONObject" %>
|
|
|
|
|
<%@ page import="weaver.wps.doccenter.utils.Tools" %>
|
|
|
|
|
<%@ page import="weaver.wps.doccenter.utils.Config" %>
|
|
|
|
|
<%@ page import="weaver.wps.doccenter.utils.FileInfoUtil" %>
|
|
|
|
|
<%@ page import="weaver.wps.doccenter.convert.BaseConvert" %>
|
|
|
|
|
<%@ page import="weaver.general.Util" %>
|
|
|
|
|
<%@ page import="weaver.hrm.User" %>
|
|
|
|
|
<%@page contentType="text/html; charset=UTF-8" %>
|
|
|
|
|
|
|
|
|
|
<%
|
|
|
|
|
|
|
|
|
|
HashMap<String, String> param = new HashMap<>();
|
|
|
|
|
param.put("imagefileid","37304");
|
|
|
|
|
param.put("targetFileFormat","PDF");
|
|
|
|
|
int i = convertDocType(param);
|
|
|
|
|
out.print(i);
|
|
|
|
|
|
|
|
|
|
%>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<%!
|
|
|
|
|
|
|
|
|
|
static Logger log = LoggerFactory.getLogger("CustomBusiness");
|
|
|
|
|
|
|
|
|
|
public Map<String, String> convert(Map<String, String> params) throws Exception {
|
|
|
|
|
Map<String, String> result = new HashMap<String, String>();
|
|
|
|
|
JSONObject requestParams = new JSONObject();
|
|
|
|
|
User user = new User(1);
|
|
|
|
|
String ecfileid = params.get("imagefileid");
|
|
|
|
|
// 判断模块。目前应该只有知识管理的
|
|
|
|
|
String fromMould = Tools.null2String(params.get("fromMould"));
|
|
|
|
|
fromMould = Tools.getFromMould(fromMould);
|
|
|
|
|
|
|
|
|
|
String targetFileFormat = Tools.null2String(params.get("targetFileFormat"));
|
|
|
|
|
|
|
|
|
|
String apiUrl = "";// Config.getCpsV1OfficeConvert();
|
|
|
|
|
if(6 == Config.getProductVersion()) {
|
|
|
|
|
apiUrl = Config.getV6CpsV1OfficeConvert();
|
|
|
|
|
} else if(5 == Config.getProductVersion()) {
|
|
|
|
|
apiUrl = Config.getCpsV1OfficeConvert();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileInfoUtil fileInfoUtil = new FileInfoUtil();
|
|
|
|
|
Map<String,String> fileInfo = fileInfoUtil.getFileInfo(ecfileid, user, fromMould);
|
|
|
|
|
|
|
|
|
|
String filename = fileInfo.get("filename");
|
|
|
|
|
filename = Tools.getFileNameWithLowerCaseSuffix(filename);
|
|
|
|
|
|
|
|
|
|
requestParams = new JSONObject();
|
|
|
|
|
requestParams.put("doc_filename", getTempFileName(filename));
|
|
|
|
|
requestParams.put("doc_url", fileInfo.get("download"));
|
|
|
|
|
requestParams.put("target_file_format", targetFileFormat);
|
|
|
|
|
|
|
|
|
|
//判断下转换格式为PDF且配置文件中未开启时添加参数
|
|
|
|
|
// "to_pdf" = {
|
|
|
|
|
// "show_ins_and_del" = 1
|
|
|
|
|
// }
|
|
|
|
|
// if ("PDF".equals(targetFileFormat) && Config.isProperty("show_ins_and_del", 1, 1)){
|
|
|
|
|
JSONObject to_pdf = new JSONObject();
|
|
|
|
|
to_pdf.put("show_ins_and_del",1);
|
|
|
|
|
requestParams.put("to_pdf", to_pdf);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断如果是excel则优化下转换结果
|
|
|
|
|
String ext = filename.contains(".") ? filename.substring(filename.lastIndexOf(".")+1) : "";
|
|
|
|
|
boolean isExcelFile = ("doc".equals(ext) || "docx".equals(ext) || "wps".equals(ext)|| "xls".equals(ext)|| "xlsx".equals(ext));
|
|
|
|
|
isExcelFile = isExcelFile || ("," + Config.getPropertyValue("doccenter_fit_excel_exts") + ",").contains("," + ext + ",");
|
|
|
|
|
|
|
|
|
|
if( isExcelFile && Config.isProperty("doccenter_fit_excel", 1, 1)) {
|
|
|
|
|
JSONObject et_page_zoom = new JSONObject();
|
|
|
|
|
// 表示是否保持当前客户端的缩放比,true表示保持当前缩放比打印,false表示以100%的缩放比打印,当fit_pagetall或fit_pagewide中有一个为1,或都为1时,该参数不生效
|
|
|
|
|
et_page_zoom.put("keep_pagezoom", "true".equals(Config.getPropString("doccenter_keep_pagezoom", "true")));
|
|
|
|
|
// 表示是否适配所有行,0表示正常分页打印,1表示不分页,所有行在一页上
|
|
|
|
|
et_page_zoom.put("fit_pagewide", Config.getPropIntValue("doccenter_fit_pagewide", 0));
|
|
|
|
|
// 表示是否适配所有列,0表示正常分页打印,1表示不分页,所有列在一页上;当fit_pagetall与fit_pagewide都为1时,表示将所有内容打印到一页上
|
|
|
|
|
et_page_zoom.put("fit_pagetall", Config.getPropIntValue("doccenter_fit_pagetall", 1));
|
|
|
|
|
requestParams.put("et_page_zoom", et_page_zoom);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 结果文件的文件名
|
|
|
|
|
String targetFilename = params.containsKey("targetFilename") ? params.get("targetFilename"): "";
|
|
|
|
|
if(Tools.isEmptyOrNull(targetFilename) && !Tools.isEmptyOrNull(filename)) {
|
|
|
|
|
String nameOnly = filename.contains(".") ? filename.substring(0, filename.lastIndexOf(".")) : filename;
|
|
|
|
|
targetFilename = nameOnly + "." + targetFileFormat.toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BaseConvert baseConvert = new BaseConvert(user);
|
|
|
|
|
if(!params.containsKey("comefrom")) {
|
|
|
|
|
params.put("comefrom", "DocTypeConvert");
|
|
|
|
|
}
|
|
|
|
|
result = baseConvert.convert(apiUrl, requestParams, targetFilename, params);
|
|
|
|
|
// 处理其他的事务
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getTempFileName(String filename) {
|
|
|
|
|
if(Tools.isEmptyOrNull(filename) || !filename.contains(".")){
|
|
|
|
|
return filename;
|
|
|
|
|
}
|
|
|
|
|
int idx = filename.lastIndexOf(".");
|
|
|
|
|
return"1" + filename.substring(idx).toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int convertDocType(Map<String, String> params){
|
|
|
|
|
Map<String, String> result = new HashMap<String, String>();
|
|
|
|
|
try {
|
|
|
|
|
result = convert(params);
|
|
|
|
|
if("0".equals(result.get("status"))){
|
|
|
|
|
return Util.getIntValue(result.get("imagefileid"));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
log.error(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
%>
|