优化风控导出bug
This commit is contained in:
parent
434cff69a6
commit
40602abf58
@ -1,6 +1,7 @@
|
|||||||
package com.actionsoft.apps.coe.pal.pal.output.util;
|
package com.actionsoft.apps.coe.pal.pal.output.util;
|
||||||
|
|
||||||
import com.actionsoft.apps.coe.pal.constant.CoEConstant;
|
import com.actionsoft.apps.coe.pal.constant.CoEConstant;
|
||||||
|
import com.actionsoft.apps.coe.pal.constant.YiliWpsConst;
|
||||||
import com.actionsoft.apps.coe.pal.pal.method.cache.PALMethodCache;
|
import com.actionsoft.apps.coe.pal.pal.method.cache.PALMethodCache;
|
||||||
import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodAttributeModel;
|
import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodAttributeModel;
|
||||||
import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodModel;
|
import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodModel;
|
||||||
@ -17,6 +18,8 @@ import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryPropertyMod
|
|||||||
import com.actionsoft.apps.coe.pal.pal.repository.upfile.constant.CoeFileConstant;
|
import com.actionsoft.apps.coe.pal.pal.repository.upfile.constant.CoeFileConstant;
|
||||||
import com.actionsoft.apps.coe.pal.pal.repository.upfile.dao.UpFileDao;
|
import com.actionsoft.apps.coe.pal.pal.repository.upfile.dao.UpFileDao;
|
||||||
import com.actionsoft.apps.coe.pal.pal.repository.upfile.model.UpfileModel;
|
import com.actionsoft.apps.coe.pal.pal.repository.upfile.model.UpfileModel;
|
||||||
|
import com.actionsoft.apps.coe.pal.util.HttpPostUtil;
|
||||||
|
import com.actionsoft.apps.coe.pal.util.WPS4Util;
|
||||||
import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile;
|
import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile;
|
||||||
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
|
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
|
||||||
import com.actionsoft.bpms.org.model.DepartmentModel;
|
import com.actionsoft.bpms.org.model.DepartmentModel;
|
||||||
@ -24,6 +27,7 @@ import com.actionsoft.bpms.org.model.RoleModel;
|
|||||||
import com.actionsoft.bpms.org.model.UserModel;
|
import com.actionsoft.bpms.org.model.UserModel;
|
||||||
import com.actionsoft.bpms.server.DispatcherRequest;
|
import com.actionsoft.bpms.server.DispatcherRequest;
|
||||||
import com.actionsoft.bpms.server.UserContext;
|
import com.actionsoft.bpms.server.UserContext;
|
||||||
|
import com.actionsoft.bpms.server.conf.portal.AWSPortalConf;
|
||||||
import com.actionsoft.bpms.server.fs.DCContext;
|
import com.actionsoft.bpms.server.fs.DCContext;
|
||||||
import com.actionsoft.bpms.server.fs.dc.DCProfileManager;
|
import com.actionsoft.bpms.server.fs.dc.DCProfileManager;
|
||||||
import com.actionsoft.bpms.util.DBSql;
|
import com.actionsoft.bpms.util.DBSql;
|
||||||
@ -52,6 +56,8 @@ import org.apache.commons.lang.StringUtils;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -183,7 +189,7 @@ public class OutputWordUtil {
|
|||||||
* @param tempName
|
* @param tempName
|
||||||
* @param docName
|
* @param docName
|
||||||
*/
|
*/
|
||||||
public static void createDoc2(com.alibaba.fastjson.JSONObject dataMap, String tempPath, String tempName, String docName) {
|
public static void createDoc2(JSONObject dataMap, String tempPath, String tempName, String docName) {
|
||||||
Configuration configuration = new Configuration();
|
Configuration configuration = new Configuration();
|
||||||
configuration.setDefaultEncoding("UTF-8");
|
configuration.setDefaultEncoding("UTF-8");
|
||||||
|
|
||||||
@ -592,7 +598,15 @@ public class OutputWordUtil {
|
|||||||
//保存结果文档
|
//保存结果文档
|
||||||
document.saveToFile(outFile.getPath(), FileFormat.Docx_2013);*/
|
document.saveToFile(outFile.getPath(), FileFormat.Docx_2013);*/
|
||||||
|
|
||||||
|
//此处在合并文档,着重处理此处
|
||||||
|
//先获取第一个文件的下载地址
|
||||||
|
/*String taskId = UUID.randomUUID().toString();
|
||||||
|
String thisFileName = taskId+".doc";
|
||||||
|
String fileURL = outFile.getPath(); // 下载文件的URL
|
||||||
|
String saveDir = "./test"; // 保存文件的目录
|
||||||
|
downloadFile(fileURL, saveDir,thisFileName);
|
||||||
|
//修改成调用wps文件发送
|
||||||
|
mergeFileForWPS(fileURL, thisFileName,dcContextpdf.getDownloadURL(),fileName,taskId);*/
|
||||||
Document docs1 = new Document();
|
Document docs1 = new Document();
|
||||||
docs1.loadFromFile(outFile.getPath());
|
docs1.loadFromFile(outFile.getPath());
|
||||||
|
|
||||||
@ -608,7 +622,6 @@ public class OutputWordUtil {
|
|||||||
docs2.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
|
docs2.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
|
||||||
docs2.dispose();
|
docs2.dispose();
|
||||||
|
|
||||||
|
|
||||||
} else if (suffix.equals("pptx")) {
|
} else if (suffix.equals("pptx")) {
|
||||||
isPPT = true;
|
isPPT = true;
|
||||||
}
|
}
|
||||||
@ -728,63 +741,96 @@ public class OutputWordUtil {
|
|||||||
PALRepositoryPropertyModel riskMatrixInfo = PALRepositoryPropertyCache.getPropertyByPropertyId(repositoryModel.getId(), "riskMatrixInfo");
|
PALRepositoryPropertyModel riskMatrixInfo = PALRepositoryPropertyCache.getPropertyByPropertyId(repositoryModel.getId(), "riskMatrixInfo");
|
||||||
if(null!=riskMatrixInfo){
|
if(null!=riskMatrixInfo){
|
||||||
JSONObject jsonObject = JSONObject.parseObject(riskMatrixInfo.getPropertyValue());
|
JSONObject jsonObject = JSONObject.parseObject(riskMatrixInfo.getPropertyValue());
|
||||||
JSONArray tableInfo = jsonObject.getJSONArray("table");
|
if(null != jsonObject){
|
||||||
//添加段落,设置一级序列
|
JSONArray tableInfo = jsonObject.getJSONArray("table");
|
||||||
Paragraph paragraph_risk = section.addParagraph();
|
//添加段落,设置一级序列
|
||||||
ParagraphFormat paragraphFormat_risk = paragraph_risk.getFormat();
|
Paragraph paragraph_risk = section.addParagraph();
|
||||||
paragraphFormat_risk.setHorizontalAlignment(Left);
|
ParagraphFormat paragraphFormat_risk = paragraph_risk.getFormat();
|
||||||
TextRange tr = paragraph_risk.appendText("关键控制点风险矩阵");
|
paragraphFormat_risk.setHorizontalAlignment(Left);
|
||||||
tr.getCharacterFormat().setBold(true);
|
TextRange tr = paragraph_risk.appendText("关键控制点风险矩阵");
|
||||||
tr.getCharacterFormat().setFontName("宋体");
|
tr.getCharacterFormat().setBold(true);
|
||||||
tr.getCharacterFormat().setFontSize(12f);
|
tr.getCharacterFormat().setFontName("宋体");
|
||||||
paragraph_risk.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式
|
tr.getCharacterFormat().setFontSize(12f);
|
||||||
//定义表格数据
|
paragraph_risk.applyStyle(BuiltinStyle.Body_Text); //应用标题1样式
|
||||||
String[] header = {"关键控制点", "控制描述","对应风险控制","角色/岗位"};
|
|
||||||
//添加表格的表头
|
|
||||||
Table table = section.addTable(true);
|
//定义表格数据
|
||||||
table.resetCells(tableInfo.size(),header.length);
|
String[] header = {"关键控制点", "控制描述","对应风险控制","角色/岗位"};
|
||||||
table.getTableFormat().isAutoResized(true);
|
//添加表格的表头
|
||||||
table.autoFit(AutoFitBehaviorType.Auto_Fit_To_Window);
|
Table table = section.addTable(true);
|
||||||
TableRow row = table.getRows().get(0);
|
table.resetCells(tableInfo.size(),header.length);
|
||||||
row.isHeader(true);
|
//table.getTableFormat().isAutoResized(true);
|
||||||
row.setHeight(20);
|
table.autoFit(AutoFitBehaviorType.Fixed_Column_Widths);
|
||||||
row.setHeightType(TableRowHeightType.Exactly);
|
TableRow row = table.getRows().get(0);
|
||||||
for (int i = 0; i < header.length; i++) {
|
row.isHeader(true);
|
||||||
row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle);
|
row.setHeight(20);
|
||||||
Paragraph p = row.getCells().get(i).addParagraph();
|
row.setHeightType(TableRowHeightType.Exactly);
|
||||||
p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center);
|
for (int i = 0; i < header.length; i++) {
|
||||||
TextRange txtRange = p.appendText(header[i]);
|
row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle);
|
||||||
txtRange.getCharacterFormat().setBold(true);
|
Paragraph p = row.getCells().get(i).addParagraph();
|
||||||
txtRange.getCharacterFormat().setFontName("宋体");
|
p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center);
|
||||||
txtRange.getCharacterFormat().setFontSize(10.5f);
|
TextRange txtRange = p.appendText(header[i]);
|
||||||
}
|
txtRange.getCharacterFormat().setBold(true);
|
||||||
//添加数据到表中
|
txtRange.getCharacterFormat().setFontName("宋体");
|
||||||
for (int i = 1; i < tableInfo.size(); i++) {
|
txtRange.getCharacterFormat().setFontSize(10.5f);
|
||||||
JSONObject cellInfo = tableInfo.getJSONObject(i);
|
|
||||||
TableRow dataRow = table.getRows().get(i);
|
//设置固定列宽
|
||||||
dataRow.setHeight(25);
|
if(i==0){
|
||||||
dataRow.setHeightType(TableRowHeightType.Exactly);
|
row.getCells().get(0).setWidth(50);
|
||||||
dataRow.getRowFormat().setBackColor(Color.white);
|
}else if(i==1){
|
||||||
int flagNum = 0;
|
row.getCells().get(1).setWidth(150);
|
||||||
for (String cellKey : cellInfo.keySet()) {
|
}else if(i==2){
|
||||||
if(cellKey.equals("id")){
|
row.getCells().get(2).setWidth(150);
|
||||||
continue;
|
}else {
|
||||||
}
|
row.getCells().get(3).setWidth(50);
|
||||||
dataRow.getCells().get(flagNum).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle);
|
}
|
||||||
//设置固定列宽
|
|
||||||
//dataRow.getCells().get(0).setWidth(50);
|
|
||||||
//dataRow.getCells().get(1).setWidth(150);
|
|
||||||
//dataRow.getCells().get(c).addParagraph().appendText(data[r][c]);
|
|
||||||
|
|
||||||
TextRange text =dataRow.getCells().get(flagNum).addParagraph().appendText(cellInfo.getString(cellKey));
|
|
||||||
text.getCharacterFormat().setFontName("宋体");
|
|
||||||
text.getCharacterFormat().setFontSize(10.5f);
|
|
||||||
dataRow.getRowFormat().setHorizontalAlignment(RowAlignment.Center);
|
|
||||||
dataRow.getCells().get(flagNum).getCellFormat();
|
|
||||||
flagNum++;
|
|
||||||
}
|
}
|
||||||
|
//添加数据到表中
|
||||||
|
for (int i = 1; i < tableInfo.size(); i++) {
|
||||||
|
JSONObject cellInfo = tableInfo.getJSONObject(i);
|
||||||
|
TableRow dataRow = table.getRows().get(i);
|
||||||
|
dataRow.setHeight(25);
|
||||||
|
dataRow.setHeightType(TableRowHeightType.Auto);
|
||||||
|
dataRow.getRowFormat().setBackColor(Color.white);
|
||||||
|
|
||||||
|
|
||||||
|
int flagNum = 0;
|
||||||
|
for (String cellKey : cellInfo.keySet()) {
|
||||||
|
if(cellKey.equals("id")){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
dataRow.getCells().get(flagNum).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle);
|
||||||
|
//设置固定列宽
|
||||||
|
//dataRow.getCells().get(0).setWidth(50);
|
||||||
|
//dataRow.getCells().get(1).setWidth(150);
|
||||||
|
//dataRow.getCells().get(c).addParagraph().appendText(data[r][c]);
|
||||||
|
|
||||||
|
TextRange text =dataRow.getCells().get(flagNum).addParagraph().appendText(cellInfo.getString(cellKey));
|
||||||
|
text.getCharacterFormat().setFontName("宋体");
|
||||||
|
text.getCharacterFormat().setFontSize(10.5f);
|
||||||
|
dataRow.getRowFormat().setHorizontalAlignment(RowAlignment.Center);
|
||||||
|
dataRow.getCells().get(flagNum).getCellFormat();
|
||||||
|
flagNum++;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置固定列宽
|
||||||
|
if(i==0){
|
||||||
|
row.getCells().get(0).setWidth(50);
|
||||||
|
}else if(i==1){
|
||||||
|
row.getCells().get(1).setWidth(100);
|
||||||
|
}else if(i==2){
|
||||||
|
row.getCells().get(2).setWidth(50);
|
||||||
|
}else {
|
||||||
|
row.getCells().get(3).setWidth(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Paragraph paragraph_blank = section.addParagraph();
|
||||||
}
|
}
|
||||||
Paragraph paragraph_blank = section.addParagraph();
|
|
||||||
}
|
}
|
||||||
//关键控制点风险矩阵 结束
|
//关键控制点风险矩阵 结束
|
||||||
|
|
||||||
@ -1739,7 +1785,7 @@ public class OutputWordUtil {
|
|||||||
|
|
||||||
JSONObject dataAttributes = (JSONObject) element.get("attributes");
|
JSONObject dataAttributes = (JSONObject) element.get("attributes");
|
||||||
if (dataAttributes != null) {
|
if (dataAttributes != null) {
|
||||||
com.alibaba.fastjson.JSONArray dataAttributesJsonArray = dataAttributes.getJSONArray("attributesJsonArray");
|
JSONArray dataAttributesJsonArray = dataAttributes.getJSONArray("attributesJsonArray");
|
||||||
for (int i = 0; i < dataAttributesJsonArray.size(); i++) {
|
for (int i = 0; i < dataAttributesJsonArray.size(); i++) {
|
||||||
JSONObject dataAttribute = dataAttributesJsonArray.getJSONObject(i);
|
JSONObject dataAttribute = dataAttributesJsonArray.getJSONObject(i);
|
||||||
if (dataAttribute == null || "null".equals(dataAttribute.toString())) {
|
if (dataAttribute == null || "null".equals(dataAttribute.toString())) {
|
||||||
@ -1788,7 +1834,7 @@ public class OutputWordUtil {
|
|||||||
* @param relationShapeIds
|
* @param relationShapeIds
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void setTableValue2(String repositoryId, com.alibaba.fastjson.JSONArray table, String relationShapeIds) {
|
public static void setTableValue2(String repositoryId, JSONArray table, String relationShapeIds) {
|
||||||
// 记录关联属性的流程节点,防止多次查询重复文件信息耗费时间
|
// 记录关联属性的流程节点,防止多次查询重复文件信息耗费时间
|
||||||
Set<String> relationFileIds = new HashSet<>();
|
Set<String> relationFileIds = new HashSet<>();
|
||||||
List<Map<String, Object>> relationFileElements2 = new ArrayList<Map<String, Object>>();
|
List<Map<String, Object>> relationFileElements2 = new ArrayList<Map<String, Object>>();
|
||||||
@ -1832,17 +1878,17 @@ public class OutputWordUtil {
|
|||||||
for (Map<String, Object> element : relationFileElements2) {
|
for (Map<String, Object> element : relationFileElements2) {
|
||||||
String id = (String) element.get("id");
|
String id = (String) element.get("id");
|
||||||
if (relationShapeId.equals(id)) {
|
if (relationShapeId.equals(id)) {
|
||||||
com.alibaba.fastjson.JSONObject _tr = new com.alibaba.fastjson.JSONObject();
|
JSONObject _tr = new JSONObject();
|
||||||
OutputWordUtil.setShapeDefaultValue2((String) element.get("pid"), _tr);
|
OutputWordUtil.setShapeDefaultValue2((String) element.get("pid"), _tr);
|
||||||
String name = specialCharTransfer(element.get("text").toString());
|
String name = specialCharTransfer(element.get("text").toString());
|
||||||
_tr.put(OutputWordUtil.SHAPE_NAME, name.replace("\n", OutputWordUtil.WRAPSTRING));
|
_tr.put(OutputWordUtil.SHAPE_NAME, name.replace("\n", OutputWordUtil.WRAPSTRING));
|
||||||
_tr.put(OutputWordUtil.SERIAL_NUMBER, index);
|
_tr.put(OutputWordUtil.SERIAL_NUMBER, index);
|
||||||
|
|
||||||
com.alibaba.fastjson.JSONObject dataAttributes = (com.alibaba.fastjson.JSONObject) element.get("attributes");
|
JSONObject dataAttributes = (JSONObject) element.get("attributes");
|
||||||
if (dataAttributes != null) {
|
if (dataAttributes != null) {
|
||||||
com.alibaba.fastjson.JSONArray dataAttributesJsonArray = dataAttributes.getJSONArray("attributesJsonArray");
|
JSONArray dataAttributesJsonArray = dataAttributes.getJSONArray("attributesJsonArray");
|
||||||
for (int i = 0; i < dataAttributesJsonArray.size(); i++) {
|
for (int i = 0; i < dataAttributesJsonArray.size(); i++) {
|
||||||
com.alibaba.fastjson.JSONObject dataAttribute = dataAttributesJsonArray.getJSONObject(i);
|
JSONObject dataAttribute = dataAttributesJsonArray.getJSONObject(i);
|
||||||
if (dataAttribute == null || "null".equals(dataAttribute.toString())) {
|
if (dataAttribute == null || "null".equals(dataAttribute.toString())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1855,7 +1901,7 @@ public class OutputWordUtil {
|
|||||||
if (!"".equals(privateAttributeContentStr) && !"[]".equals(privateAttributeContentStr)) {
|
if (!"".equals(privateAttributeContentStr) && !"[]".equals(privateAttributeContentStr)) {
|
||||||
String firstChart = privateAttributeContentStr.substring(0, 1);
|
String firstChart = privateAttributeContentStr.substring(0, 1);
|
||||||
if ("{".equals(firstChart)) {
|
if ("{".equals(firstChart)) {
|
||||||
com.alibaba.fastjson.JSONObject privateAttributeContent = dataAttributes.getJSONObject("privateAttributeContent");
|
JSONObject privateAttributeContent = dataAttributes.getJSONObject("privateAttributeContent");
|
||||||
for (String key : privateAttributeContent.keySet()) {
|
for (String key : privateAttributeContent.keySet()) {
|
||||||
_tr.put("shape_" + key, specialCharTransfer(privateAttributeContent.getString(key)));
|
_tr.put("shape_" + key, specialCharTransfer(privateAttributeContent.getString(key)));
|
||||||
}
|
}
|
||||||
@ -1919,11 +1965,11 @@ public class OutputWordUtil {
|
|||||||
sbRole.append(",");
|
sbRole.append(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
com.alibaba.fastjson.JSONObject dataAttributes = (com.alibaba.fastjson.JSONObject) element.get("attributes");
|
JSONObject dataAttributes = (JSONObject) element.get("attributes");
|
||||||
if (dataAttributes != null) {
|
if (dataAttributes != null) {
|
||||||
com.alibaba.fastjson.JSONArray dataAttributesJsonArray = dataAttributes.getJSONArray("attributesJsonArray");
|
JSONArray dataAttributesJsonArray = dataAttributes.getJSONArray("attributesJsonArray");
|
||||||
for (int i = 0; i < dataAttributesJsonArray.size(); i++) {
|
for (int i = 0; i < dataAttributesJsonArray.size(); i++) {
|
||||||
com.alibaba.fastjson.JSONObject dataAttribute = dataAttributesJsonArray.getJSONObject(i);
|
JSONObject dataAttribute = dataAttributesJsonArray.getJSONObject(i);
|
||||||
if (dataAttribute == null || "null".equals(dataAttribute.toString())) {
|
if (dataAttribute == null || "null".equals(dataAttribute.toString())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -2118,7 +2164,7 @@ public class OutputWordUtil {
|
|||||||
* @param relationFileElements
|
* @param relationFileElements
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void setRelationShapeValueByOrgAndRole(com.alibaba.fastjson.JSONObject _tr, com.alibaba.fastjson.JSONObject dataAttribute,
|
public static void setRelationShapeValueByOrgAndRole(JSONObject _tr, JSONObject dataAttribute,
|
||||||
Map<String, String> shapeModelMap, List<Map<String, Object>> relationFileElements, String shapeId, Set<String> relationFileIds) {
|
Map<String, String> shapeModelMap, List<Map<String, Object>> relationFileElements, String shapeId, Set<String> relationFileIds) {
|
||||||
String key = dataAttribute.getString("key");
|
String key = dataAttribute.getString("key");
|
||||||
if ("organization".equals(dataAttribute.getString("groupPath")) && "relation".equals(dataAttribute.getString("type"))) {
|
if ("organization".equals(dataAttribute.getString("groupPath")) && "relation".equals(dataAttribute.getString("type"))) {
|
||||||
@ -2190,7 +2236,7 @@ public class OutputWordUtil {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void setShapeValue2(com.alibaba.fastjson.JSONObject _tr, com.alibaba.fastjson.JSONObject dataAttribute, Map<String, String> shapeRelationModelMap) {
|
public static void setShapeValue2(JSONObject _tr, JSONObject dataAttribute, Map<String, String> shapeRelationModelMap) {
|
||||||
String result = "";
|
String result = "";
|
||||||
String key = dataAttribute.getString("key");
|
String key = dataAttribute.getString("key");
|
||||||
if ("string".equals(dataAttribute.getString("type")) || "textarea".equals(dataAttribute.getString("type"))) {
|
if ("string".equals(dataAttribute.getString("type")) || "textarea".equals(dataAttribute.getString("type"))) {
|
||||||
@ -2305,8 +2351,8 @@ public class OutputWordUtil {
|
|||||||
return dataJson.getJSONObject("privateAttributeContent").getString("number");
|
return dataJson.getJSONObject("privateAttributeContent").getString("number");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (json.get("attributes") instanceof com.alibaba.fastjson.JSONObject) {// fastJson
|
if (json.get("attributes") instanceof JSONObject) {// fastJson
|
||||||
com.alibaba.fastjson.JSONObject dataJson = (com.alibaba.fastjson.JSONObject) json.get("attributes");
|
JSONObject dataJson = (JSONObject) json.get("attributes");
|
||||||
if (dataJson.containsKey("privateAttributeContent") && dataJson.get("privateAttributeContent").getClass().getName().contains("JSONObject")) {
|
if (dataJson.containsKey("privateAttributeContent") && dataJson.get("privateAttributeContent").getClass().getName().contains("JSONObject")) {
|
||||||
return dataJson.getJSONObject("privateAttributeContent").getString("number");
|
return dataJson.getJSONObject("privateAttributeContent").getString("number");
|
||||||
}
|
}
|
||||||
@ -2461,4 +2507,103 @@ public class OutputWordUtil {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 合并文档,wps形式
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String mergeFileForWPS(String docUrl1, String docFileName1, String docUrl2, String docFileName2,String taskId) {
|
||||||
|
try {
|
||||||
|
String url = String.format("/api/cps/sync/v1/merge");
|
||||||
|
WPS4Util.initAppInfo(YiliWpsConst.AK, YiliWpsConst.SK);
|
||||||
|
//组装wps需要的参数
|
||||||
|
JSONObject result = new JSONObject();
|
||||||
|
JSONArray array = new JSONArray();
|
||||||
|
JSONObject merged_file_obj1 = new JSONObject();
|
||||||
|
JSONObject merged_file_obj2 = new JSONObject();
|
||||||
|
result.put("task_id", taskId);
|
||||||
|
merged_file_obj1.put("doc_url",SDK.getAppAPI().getProperty(YiliWpsConst.APPID,"targetPortal")+"/r" + docUrl1.substring(1));
|
||||||
|
merged_file_obj1.put("doc_filename",docFileName1);
|
||||||
|
array.add(merged_file_obj1);
|
||||||
|
merged_file_obj2.put("doc_url",SDK.getAppAPI().getProperty(YiliWpsConst.APPID,"targetPortal")+"/r" + docUrl2.substring(1));
|
||||||
|
merged_file_obj2.put("doc_filename",docFileName2);
|
||||||
|
array.add(merged_file_obj2);
|
||||||
|
result.put("merged_file_list",array);
|
||||||
|
System.out.println("result.toString() = " + result);
|
||||||
|
//组装完毕
|
||||||
|
Map<String,String> headers = WPS4Util.getSignatureHeaders(url, "POST",result.toString(), YiliWpsConst.CONTENT_TYPE);
|
||||||
|
JSONObject json = HttpPostUtil.sendPostRequest(YiliWpsConst.HOST + "/open" + url, result.toString(), headers, JSONObject.class);
|
||||||
|
System.out.println("jsonObject = " + json.toString());
|
||||||
|
if(json.getString("code").equals("200")){
|
||||||
|
System.out.println(">>>>>>>已合并成功");
|
||||||
|
String download_id = json.getJSONObject("data").getString("download_id");
|
||||||
|
String route_key = json.getJSONObject("data").getString("route_key");
|
||||||
|
//String savePath = AWSPortalConf.getUrl() +"/test/123.doc";
|
||||||
|
String savePath = docUrl1;
|
||||||
|
System.out.println("savePath = " + savePath);
|
||||||
|
operateDocumentResultDownload(YiliWpsConst.HOST,download_id,route_key,savePath);
|
||||||
|
return savePath;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据wps的下载id下载替换文件
|
||||||
|
* @param host
|
||||||
|
* @param downloadId
|
||||||
|
* @param routeKey
|
||||||
|
* @param savePath
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static void operateDocumentResultDownload(String host,String downloadId,String routeKey,String savePath) throws Exception {
|
||||||
|
String url = "/api/cps/v1/download/{download_id}";
|
||||||
|
url = url.replace("{download_id}",downloadId);
|
||||||
|
Map<String,String> headers = WPS4Util.getSignatureHeaders(url, "GET",null,YiliWpsConst.CONTENT_TYPE);
|
||||||
|
headers.put("Route-Key",routeKey);
|
||||||
|
HttpPostUtil.sendGetDownloadRequest(host + "/open" + url, headers,savePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void downloadFile(String fileURL, String saveDir,String fileName) {
|
||||||
|
try {
|
||||||
|
File file = new File(saveDir);
|
||||||
|
|
||||||
|
// 确保文件目录存在
|
||||||
|
if (!file.exists()) {
|
||||||
|
file.mkdirs();
|
||||||
|
}
|
||||||
|
// 创建输出流到文件
|
||||||
|
File outputFile = new File(file, fileName);
|
||||||
|
FileOutputStream fos = new FileOutputStream(outputFile);
|
||||||
|
|
||||||
|
URL url = new URL(fileURL);
|
||||||
|
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
|
||||||
|
int responseCode = httpConn.getResponseCode();
|
||||||
|
|
||||||
|
// 检查响应码是否为HTTP_OK
|
||||||
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||||
|
// 通过输入流读取数据
|
||||||
|
InputStream inputStream = httpConn.getInputStream();
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int bytesRead = -1;
|
||||||
|
|
||||||
|
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||||
|
fos.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
fos.close();
|
||||||
|
inputStream.close();
|
||||||
|
|
||||||
|
System.out.println("File downloaded");
|
||||||
|
} else {
|
||||||
|
System.out.println("No file to download. Server replied HTTP code: " + responseCode);
|
||||||
|
}
|
||||||
|
httpConn.disconnect();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user