手册合并问题格式丢失问题处理

This commit is contained in:
446052889@qq.com 2023-07-02 17:58:57 +08:00
parent 6c78a374f8
commit 3513333aad
7 changed files with 5729 additions and 863 deletions

View File

@ -18,9 +18,19 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import com.actionsoft.apps.coe.pal.constant.CoEConstant;
import com.actionsoft.apps.coe.pal.pal.repository.PALRepositoryQueryAPIManager;
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.model.UpfileModel;
import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile;
import com.actionsoft.bpms.org.model.DepartmentModel;
import com.actionsoft.bpms.org.model.RoleModel;
import com.actionsoft.bpms.org.model.UserModel;
import com.actionsoft.bpms.server.DispatcherRequest;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.server.fs.DCContext;
import com.actionsoft.bpms.server.fs.dc.DCProfileManager;
import com.actionsoft.bpms.util.UtilFile;
import com.actionsoft.bpms.util.UtilString;
import com.actionsoft.apps.coe.pal.pal.method.cache.PALMethodCache;
@ -33,6 +43,10 @@ import com.actionsoft.apps.coe.pal.pal.repository.designer.util.CoeDesignerUtil;
import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel;
import com.actionsoft.sdk.local.SDK;
import com.spire.doc.*;
import com.spire.doc.documents.*;
import com.spire.doc.fields.DocPicture;
import com.spire.doc.fields.TextRange;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
@ -163,7 +177,7 @@ public class OutputWordUtil {
* @param tempName
* @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.setDefaultEncoding("UTF-8");
@ -202,6 +216,183 @@ public class OutputWordUtil {
}
}
/**
* 生成word文件
*
* @param dataMap
* @param tempPath
* @param tempName
* @param docName
*/
public static void createZdDoc2(JSONObject dataMap, String tempPath, String tempName, String docName,JSONObject wizardJsonData,String repositoryId) {
Configuration configuration = new Configuration();
configuration.setDefaultEncoding("UTF-8");
// 设置模本装置方法和路径
try {
UtilFile temps = new UtilFile(tempPath);
configuration.setDirectoryForTemplateLoading(temps);
} catch (IOException e2) {
e2.printStackTrace();
}
Template t = null;
try {
t = configuration.getTemplate(tempName, "UTF-8");
} catch (IOException e) {
e.printStackTrace();
}
// 输出文档路径及名称
File outFile = new File(docName);
Writer out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8"));
} catch (Exception e1) {
e1.printStackTrace();
}
try {
if (t!= null && out != null) {
t.process(dataMap, out);
out.flush();
out.close();
}
} catch (TemplateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//***********************************************************使用spire 生成模板后复制文件
List<Map<String, Object>> repositoryFileElements = CoeDesignerUtil.getShapeMessageJson4(repositoryId); //流程文件内容
if (wizardJsonData.getBoolean("orderNuberFirst")) { // 根据页面选择进行排序
OutputWordUtil.orderByNumber(repositoryFileElements);
}
String controlShapeId = "";
if (repositoryFileElements != null) {
int index = 1;// 流程步骤序号
int dangerIndex = 1;// 风险序号
int regulateIndex = 1;// 控制序号
for (Map<String, Object> shape : repositoryFileElements) {
String type = shape.get("type").toString();
if ("regulation".equals(type)) {
controlShapeId = shape.get("id").toString();
}else if("I/O_L4".equals(type)) {
controlShapeId = shape.get("id").toString();
}
}
}
UserContext userContext=DispatcherRequest.getUserContext();
Map<String, String> result = new HashMap<>();
result.put("listDef", "");
result.put("content", "");
if (UtilString.isEmpty(controlShapeId)) {
}
PALRepositoryModel repositoryModel = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(repositoryId);
if (repositoryModel == null) {
}
String content = "";
StringBuilder listStr = new StringBuilder();
// 读取附件
// 流程附件列表
UpFileDao upFileDao = new UpFileDao();
List<UpfileModel> search = upFileDao.search(repositoryModel.getId(), controlShapeId, null);
DCContext dcContextpdf = null;
File file = null;
if (search != null && search.size() > 0) {
// 复制附件
for (UpfileModel upfileModel : search) {
DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE);
if (upfileModel.getFileName().contains(".xml")) {
if (dcProfile != null) {
dcContextpdf = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName());
break;
}
}
if (upfileModel.getFileName().contains(".doc")||upfileModel.getFileName().contains(".docx")) {
if (dcProfile != null) {
dcContextpdf = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName());
String path = dcContextpdf.getPath();
String fileName = dcContextpdf.getFileName();
//创建 Document 类的对象并从磁盘加载 Word 文档
Document document = new Document(outFile.getPath());
//将另一个文档插入当前文档
document.insertTextFromFile(path+fileName, FileFormat.Docx_2013);
// document.insertTextFromFile("/Users/sunlh/Downloads/手册格式问题测试文档(3)new.docx", FileFormat.Docx_2013);
//保存结果文档
document.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
}
}
}
}
if (dcContextpdf != null) {
file = new File(dcContextpdf.getFilePath());
}
if (file != null) {
}
}
//自定义方法来添加图片文字页眉及页码
private static void AddHeaderFooter(Section sec){
//加载图片添加到页眉并设置图片在段落中的对齐方式
HeaderFooter header = sec.getHeadersFooters().getHeader();
Paragraph hpara= header.addParagraph();
DocPicture pic =hpara.appendPicture("D:\\xxx.png");
pic.setHorizontalAlignment(ShapeHorizontalAlignment.Right);
pic.setHeight(100);
pic.setWidth(100);
pic.setVerticalOrigin(VerticalOrigin.Inner_Margin_Area);
pic.setVerticalAlignment(ShapeVerticalAlignment.Bottom);
//添加文字到页眉并设置字体字号字体加粗对齐方式
TextRange txt = hpara.appendText("内蒙古伊利集团股份有限公司");
txt.getCharacterFormat().setUnderlineStyle(UnderlineStyle.None);
txt.getCharacterFormat().setFontName("黑体");
txt.getCharacterFormat().setFontSize(10f);
hpara.getFormat().setHorizontalAlignment(HorizontalAlignment.Left);
//添加页码到页脚并设置页脚对齐方式顶部边线粗细间距
HeaderFooter footer = sec.getHeadersFooters().getFooter();
Paragraph fpara= footer.addParagraph();
fpara.appendField("页码",FieldType.Field_Page);
fpara.appendField("总页数",FieldType.Field_Num_Pages);
fpara.getFormat().setHorizontalAlignment(HorizontalAlignment.Right);
fpara.getFormat().getBorders().getTop().setBorderType(BorderStyle.Single);
fpara.getFormat().getBorders().getTop().setLineWidth(1f);
fpara.getFormat().getBorders().getTop().setSpace(2f);
}
/**
* 将文件的扩展属性设置默认值为空字符串防止没有设置扩展属性而使得导出文件出错
*
@ -413,7 +604,7 @@ public class OutputWordUtil {
JSONObject dataAttributes = (JSONObject) element.get("attributes");
if (dataAttributes != null) {
com.alibaba.fastjson.JSONArray dataAttributesJsonArray = dataAttributes.getJSONArray("attributesJsonArray");
JSONArray dataAttributesJsonArray = dataAttributes.getJSONArray("attributesJsonArray");
for (int i = 0; i < dataAttributesJsonArray.size(); i++) {
JSONObject dataAttribute = dataAttributesJsonArray.getJSONObject(i);
if(dataAttribute == null || "null".equals(dataAttribute.toString())) {
@ -461,7 +652,7 @@ public class OutputWordUtil {
* @param relationShapeIds
*/
@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<>();
List<Map<String, Object>> relationFileElements2 = new ArrayList<Map<String,Object>>();
@ -505,17 +696,17 @@ public class OutputWordUtil {
for (Map<String, Object> element : relationFileElements2) {
String id = (String) element.get("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);
String name = specialCharTransfer(element.get("text").toString());
_tr.put(OutputWordUtil.SHAPE_NAME, name.replace("\n", OutputWordUtil.WRAPSTRING));
_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) {
com.alibaba.fastjson.JSONArray dataAttributesJsonArray = dataAttributes.getJSONArray("attributesJsonArray");
JSONArray dataAttributesJsonArray = dataAttributes.getJSONArray("attributesJsonArray");
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())) {
continue;
}
@ -528,7 +719,7 @@ public class OutputWordUtil {
if (!"".equals(privateAttributeContentStr) && !"[]".equals(privateAttributeContentStr)) {
String firstChart = privateAttributeContentStr.substring(0, 1);
if ("{".equals(firstChart)) {
com.alibaba.fastjson.JSONObject privateAttributeContent = dataAttributes.getJSONObject("privateAttributeContent");
JSONObject privateAttributeContent = dataAttributes.getJSONObject("privateAttributeContent");
for (String key : privateAttributeContent.keySet()) {
_tr.put("shape_" + key, specialCharTransfer(privateAttributeContent.getString(key)));
}
@ -591,11 +782,11 @@ public class OutputWordUtil {
sbRole.append(",");
}
com.alibaba.fastjson.JSONObject dataAttributes = (com.alibaba.fastjson.JSONObject) element.get("attributes");
JSONObject dataAttributes = (JSONObject) element.get("attributes");
if (dataAttributes != null) {
com.alibaba.fastjson.JSONArray dataAttributesJsonArray = dataAttributes.getJSONArray("attributesJsonArray");
JSONArray dataAttributesJsonArray = dataAttributes.getJSONArray("attributesJsonArray");
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())) {
continue;
}
@ -788,7 +979,7 @@ public class OutputWordUtil {
* @param relationFileElements
*/
@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) {
String key = dataAttribute.getString("key");
if ("organization".equals(dataAttribute.getString("groupPath")) && "relation".equals(dataAttribute.getString("type"))) {
@ -859,7 +1050,7 @@ public class OutputWordUtil {
* @return
*/
@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 key = dataAttribute.getString("key");
if ("string".equals(dataAttribute.getString("type")) || "textarea".equals(dataAttribute.getString("type"))) {
@ -972,8 +1163,8 @@ public class OutputWordUtil {
return dataJson.getJSONObject("privateAttributeContent").getString("number");
}
}
if(json.get("attributes") instanceof com.alibaba.fastjson.JSONObject) {// fastJson
com.alibaba.fastjson.JSONObject dataJson = (com.alibaba.fastjson.JSONObject) json.get("attributes");
if(json.get("attributes") instanceof JSONObject) {// fastJson
JSONObject dataJson = (JSONObject) json.get("attributes");
if (dataJson.containsKey("privateAttributeContent") && dataJson.get("privateAttributeContent").getClass().getName().contains("JSONObject")) {
return dataJson.getJSONObject("privateAttributeContent").getString("number");
}

View File

@ -1,10 +1,26 @@
package com.awspaas.apps.coe.pal.output.zd.report1;
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.sql.Timestamp;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import com.actionsoft.apps.coe.pal.constant.CoEConstant;
import com.actionsoft.apps.coe.pal.pal.output.extend.GenerLogExd;
@ -16,9 +32,6 @@ import com.actionsoft.apps.coe.pal.pal.output.util.OutputWordUtil;
import com.actionsoft.apps.coe.pal.pal.repository.PALRepositoryQueryAPIManager;
import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache;
import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryPropertyCache;
import com.actionsoft.apps.coe.pal.pal.repository.designer.manage.CoeDesignerAPIManager;
import com.actionsoft.apps.coe.pal.pal.repository.designer.model.BaseModel;
import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.cache.DesignerShapeRelationCache;
import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.dao.DesignerShapeRelationDao;
import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.model.DesignerShapeRelationModel;
import com.actionsoft.apps.coe.pal.pal.repository.designer.util.CoeDesignerUtil;
@ -49,11 +62,6 @@ import com.awspaas.apps.coe.pal.output.zd.util.ReportRepositoryCompare;
import com.awspaas.apps.coe.pal.output.zd.util.XMLUtil;
import com.spire.doc.FileFormat;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import static com.actionsoft.apps.coe.pal.pal.output.util.OutputWordUtil.specialCharTransfer;
/**
@ -87,26 +95,26 @@ public class Report1Gener {
public ResponseObject execute(OutputTaskModel model, String wizardJsonData, DCContext dcContext) {
try {
// synchronized (_lock) {
// isRunning = true;
// userContext = UserContext.fromUID(model.getUserId());
userContext = DispatcherRequest.getUserContext();
String teamId = model.getTeamId();
String wsId = model.getWsId();
log.info("execute ready...");
log.info("-------------------");
log.info("TeamId=" + teamId);
log.info("wsId=" + wsId);
JSONObject jsonObj = JSONObject.parseObject(wizardJsonData);
log.info("dcPath=" + dcContext.getPath());
// ----预处理校验----
OutputAppProfile appModel = OutputAppManager.getProfile(model.getProfileId());
String tempPath = appModel.getAppContext().getPath();
String tempName = "制度-手册4.xml";
log.info("begin...");
log.info("-------------------");
// ----文件处理-----
genarateWord(tempPath, tempName, dcContext.getPath(), jsonObj);
log.info("end");
// isRunning = true;
// userContext = UserContext.fromUID(model.getUserId());
userContext = DispatcherRequest.getUserContext();
String teamId = model.getTeamId();
String wsId = model.getWsId();
log.info("execute ready...");
log.info("-------------------");
log.info("TeamId=" + teamId);
log.info("wsId=" + wsId);
JSONObject jsonObj = JSONObject.parseObject(wizardJsonData);
log.info("dcPath=" + dcContext.getPath());
// ----预处理校验----
OutputAppProfile appModel = OutputAppManager.getProfile(model.getProfileId());
String tempPath = appModel.getAppContext().getPath();
String tempName = "制度-手册5.xml";
log.info("begin...");
log.info("-------------------");
// ----文件处理-----
genarateWord(tempPath, tempName, dcContext.getPath(), jsonObj);
log.info("end");
// }
} finally {
// isRunning = false;
@ -190,240 +198,24 @@ public class Report1Gener {
}
JSONObject dataMap = getData2(repositoryId, wizardJsonData, docPath, fileName);
if (dataMap != null) {
OutputWordUtil.createDoc2(dataMap, tempPath, tempName, docName);
OutputWordUtil.createZdDoc2(dataMap, tempPath, tempName, docName,wizardJsonData, repositoryId);
}
}
}
}
/**
* 获取条款内容xml
* 获取文档数据
* @param repositoryId
* @param controlShapeId
* @param wizardJsonData
* @return
*/
private Map<String, String> getContentData(String repositoryId, String controlShapeId) {
Map<String, String> result = new HashMap<>();
result.put("listDef", "");
result.put("content", "");
if (UtilString.isEmpty(controlShapeId)) {
return result;
}
PALRepositoryModel repositoryModel = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(repositoryId);
if (repositoryModel == null) {
return result;
}
String content = "";
StringBuilder listStr = new StringBuilder();
// 读取附件
// 流程附件列表
UpFileDao upFileDao = new UpFileDao();
List<UpfileModel> search = upFileDao.search(repositoryModel.getId(), controlShapeId, null);
DCContext dcContextpdf = null;
File file = null;
if (search != null && search.size() > 0) {
// 复制附件
for (UpfileModel upfileModel : search) {
DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE);
if (upfileModel.getFileName().contains(".xml")) {
if (dcProfile != null) {
dcContextpdf = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName());
/*
* String path = dcContextpdf.getPath(); String fileName =
* dcContextpdf.getFileName(); com.spire.doc.Document docs = new
* com.spire.doc.Document(); docs.loadFromFile("/"+path+fileName); String
* substring = fileName.substring(0, fileName.lastIndexOf(".xml"));
* docs.saveToFile("/"+path+substring+".xml",FileFormat.Word_ML); dcContextpdf =
* new DCContext(userContext, dcProfile, CoEConstant.APP_ID,
* upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), substring+".xml");
*/
break;
}
}
if (upfileModel.getFileName().contains(".doc")||upfileModel.getFileName().contains(".docx")) {
if (dcProfile != null) {
dcContextpdf = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName());
String path = dcContextpdf.getPath();
String fileName = dcContextpdf.getFileName();
//创建实例加载doc测试文档
String s = path+fileName;
com.spire.doc.Document docs = new com.spire.doc.Document();
docs.loadFromFile(path+fileName);
//保存为xml格式
String substring = fileName.substring(0, fileName.lastIndexOf(".doc"));
docs.saveToFile(path+substring+".xml",FileFormat.Word_ML);
dcContextpdf = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), substring+".xml");
break;
}
}
}
}
if (dcContextpdf != null) {
file = new File(dcContextpdf.getFilePath());
}
if (file != null) {
// 解析xml文件
// 校验xml文档是否能够正常解析
Document doc = analysisXMLFile(file.getPath(), true);
if (doc == null) {
System.out.println("解析xml失败");
return null;
}
int step = 20;// 以20为步长进行批量调整
// 解析根节点
Element root = doc.getRootElement();
// System.out.println(root.getName());
Element lists = root.element("lists");
if (lists != null) {
for (Object obj : lists.elements()) {
Element e = (Element)obj;
String name = e.getName();
if ("listDef".equals(name)) {
e.setAttributeValue("listDefId", Integer.parseInt(e.attributeValue("listDefId")) + step + "");
listStr.append(e.asXML());
}
if ("list".equals(name)) {
e.setAttributeValue("ilfo", Integer.parseInt(e.attributeValue("ilfo")) + step + "");
Element ilst = e.element("ilst");
ilst.setAttributeValue("val", Integer.parseInt(ilst.attributeValue("val")) + step + "");
listStr.append(e.asXML());
}
}
}
// if (listStr.length() > 0) {
// System.out.println(listStr);
// }
// Element body = root.element("body");
// if (body != null) {
// // System.out.println(body.getName());
// //System.out.println(body.asXML());
// List<Element> childList = body.elements();
// if (childList != null) {
// for (Element e : childList) {
// //System.out.println(e.getName());
// // str += e.asXML();
// }
// }
//
// }
// 获取字符串
content = getFileContent(file);
// content = content.substring(content.indexOf("<wx:sect>") + 9, content.indexOf("<w:sectPr"));
content = content.substring(content.indexOf("<w:body>") + 8 , content.indexOf("</w:body>"));
String [] arr = content.split("</wx:sect>");
StringBuilder tmp = new StringBuilder();
for (int i = 0; i < arr.length; i++) {
tmp.append(arr[i].substring(arr[i].indexOf("<wx:sect>") + 9));
}
content = tmp.toString();
// System.out.println(content);
// System.out.println("以上的是替换前文本,以下是替换后文本");
String [] contentArr = content.split("<w:ilfo w:val=\"");
for (int i = 1; i < contentArr.length; i++) {
String c = contentArr[i];
int num = Integer.parseInt(c.substring(0, c.indexOf("\"")));
num += step;
contentArr[i] = num + c.substring(c.indexOf("\""));
}
List<String> list = Arrays.asList(contentArr);
content = StringUtils.join(list, "<w:ilfo w:val=\"");
}
String listStr2 = listStr.toString();
listStr2 = listStr2.replace("xmlns:aml=\"http://schemas.microsoft.com/aml/2001/core\"", "")
.replace("xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\"", "")
.replace("xmlns:cx=\"http://schemas.microsoft.com/office/drawing/2014/chartex\"", "")
.replace("xmlns:cx1=\"http://schemas.microsoft.com/office/drawing/2015/9/8/chartex\"", "")
.replace("xmlns:cx2=\"http://schemas.microsoft.com/office/drawing/2015/10/21/chartex\"", "")
.replace("xmlns:cx3=\"http://schemas.microsoft.com/office/drawing/2016/5/9/chartex\"", "")
.replace("xmlns:cx4=\"http://schemas.microsoft.com/office/drawing/2016/5/10/chartex\"", "")
.replace("xmlns:cx5=\"http://schemas.microsoft.com/office/drawing/2016/5/11/chartex\"", "")
.replace("xmlns:cx6=\"http://schemas.microsoft.com/office/drawing/2016/5/12/chartex\"", "")
.replace("xmlns:cx7=\"http://schemas.microsoft.com/office/drawing/2016/5/13/chartex\"", "")
.replace("xmlns:cx8=\"http://schemas.microsoft.com/office/drawing/2016/5/14/chartex\"", "")
.replace("xmlns:dt=\"uuid:C2F41010-65B3-11d1-A29F-00AA00C14882\"", "")
.replace("xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"", "")
.replace("xmlns:aink=\"http://schemas.microsoft.com/office/drawing/2016/ink\"", "")
.replace("xmlns:am3d=\"http://schemas.microsoft.com/office/drawing/2017/model3d\"", "")
.replace("xmlns:o=\"urn:schemas-microsoft-com:office:office\"", "")
.replace("xmlns:v=\"urn:schemas-microsoft-com:vml\"", "")
.replace("xmlns:w10=\"urn:schemas-microsoft-com:office:word\"", "")
.replace("xmlns:w=\"http://schemas.microsoft.com/office/word/2003/wordml\"", "")
.replace("xmlns:wx=\"http://schemas.microsoft.com/office/word/2003/auxHint\"", "")
.replace("xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\"", "")
.replace("xmlns:wsp=\"http://schemas.microsoft.com/office/word/2003/wordml/sp2\"", "")
.replace("xmlns:sl=\"http://schemas.microsoft.com/schemaLibrary/2003/core\"", "");
result.put("listDef", listStr2);
result.put("content", content);
return result;
}
public static String getFileContent(File file) {
StringBuilder builder = new StringBuilder();
InputStreamReader reader = null;
BufferedReader br = null;
try {
reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
br = new BufferedReader(reader);
String s;
while ((s = br.readLine()) != null) {
builder.append(s);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
}
if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return builder.toString();
}
/**
* 解析xml文档
* @param path
* @param b
* @return
*/
private Document analysisXMLFile(String path, boolean b) {
Document d = null;
try {
d = XMLUtil.readXML(path, true);
} catch (DocumentException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return d;
}
/**
* 获取文档数据
* @param repositoryId
* @param wizardJsonData
* @return
*/
private JSONObject getData2(String repositoryId, JSONObject wizardJsonData, String docPath, String fileName) {
JSONObject dataMap = new JSONObject();
dataMap.put("organizationType", "涉及部门及岗位\\角色");
boolean raciRelationType = SDK.getAppAPI().getPropertyBooleanValue("com.awspaas.user.apps.coe.pal.output.zd", "DETY_POSITION_ROLE_RELATION_TYPE", false);
// 记录关联属性的流程节点防止多次查询重复文件信息耗费时间
// 记录关联属性的流程节点防止多次查询重复文件信息耗费时间
Set<String> relationFileIds = new HashSet<>();
Map<String, Map<String, Object>> relationFileMap = new HashMap<>();
@ -435,469 +227,13 @@ public class Report1Gener {
prReportComment.getCommentContent(dataMap, repositoryModel); // 获取一些公共的数据(手册首页的手册岗位名称部门时间等)
JSONArray repositoryShapeTable = new JSONArray(); //流程步骤Table
JSONArray fileTable = new JSONArray(); //流程附件Table
JSONArray dangerTable = new JSONArray(); //风险Table
JSONArray regulateTable = new JSONArray(); //控制Table
JSONArray KPITable = new JSONArray(); //相关绩效考核Table
Set<String> dangerSet = new HashSet<String>();// 风险
Set<String> regulateSet = new HashSet<String>();// 控制
Set<String> KPISet = new HashSet<String>();// kpi
List<Map<String, Object>> repositoryFileElements = CoeDesignerUtil.getShapeMessageJson4(repositoryId); //流程文件内容
if (wizardJsonData.getBoolean("orderNuberFirst")) { // 根据页面选择进行排序
OutputWordUtil.orderByNumber(repositoryFileElements);
}
// 流程附件列表
String shpId = "";
UpFileDao upFileDao = new UpFileDao();
StringBuffer sqlWhere = new StringBuffer();
sqlWhere.append(" and PALREPOSITORYID ='").append(repositoryModel.getId()).append("'").append(" ORDER BY FILENAME ASC");
List<UpfileModel> search = upFileDao.search(sqlWhere.toString());
File file = null;
//三员管理下用户密级与文件密级过滤显示
if(HighSecurityUtil.isON()){
PALRepositoryQueryAPIManager.getInstance().upFileSecurityFilter(this.userContext,search);
}
if (search != null && search.size() > 0) {
//创建附件目录及复制附件
fileName = fileName + "_file";
file = new File(docPath, fileName);
if (!file.exists()) {
log.info("创建附件");
file.mkdir();
}
}
//文件属性附件
int fileIndex = 1;
ArrayList<String> isNumberAscArray = new ArrayList<String>();
if (search != null && search.size() > 0) {
// 复制附件
for (UpfileModel upfileModel : search) {
if (!"f".equals(upfileModel.getType())) {
continue;
}
// 复制doccenter下的文件
DCContext dcContext = null;
DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE);
if (dcProfile != null) {
dcContext = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, "file", upfileModel.getPl_uuid(), upfileModel.getFileName());
}
File sourceFile = new UtilFile(dcContext.getFilePath());
File targetFile = new UtilFile(file.toString() + File.separator + dcContext.getFileName());
try {
UtilFile.copyFile(sourceFile, targetFile);
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
JSONObject object = new JSONObject();
//按照附件编号排序
String fileNamel= upfileModel.getFileName();
if(UtilString.isNotEmpty(fileNamel)&&fileNamel.contains("附件")&&fileNamel.length()>2&&(fileNamel.contains(":")||fileNamel.contains(""))) {
if(fileNamel.indexOf("附件")==0) {
int indexOf2 = 3;
if(fileNamel.contains(":")) {
indexOf2 = fileNamel.indexOf(":");
}else if(fileNamel.contains("")) {
indexOf2 = fileNamel.indexOf("");
}
String numberStr = fileNamel.substring(2,indexOf2);
if(isNumeric(numberStr)&&!"".equals(numberStr)) {
isNumberAscArray.add("true");
int fileNumber = Integer.parseInt(numberStr);
object.put("file_number", fileNumber);
}else {
isNumberAscArray.add("false");
}
}else {
isNumberAscArray.add("false");
}
}else {
isNumberAscArray.add("false");
}
object.put("file_name", upfileModel.getFileName());
String link = fileName + File.separator + upfileModel.getFileName();
object.put("link", link);
fileTable.add(object);
fileIndex++;
}
}
String controlShapeId = "";
if (repositoryFileElements != null) {
int index = 1;// 流程步骤序号
int dangerIndex = 1;// 风险序号
int regulateIndex = 1;// 控制序号
for (Map<String, Object> shape : repositoryFileElements) {
String type = shape.get("type").toString();
if ("regulation".equals(type)) {
controlShapeId = shape.get("id").toString();
}else if("I/O_L4".equals(type)) {
controlShapeId = shape.get("id").toString();
}
//如果图形元素不是流程步骤不导出该元素
// if (PrReportComment.PROCESS_STEP.indexOf((String)shape.get("type")) == -1) {
// continue;
// }
JSONObject _tr = new JSONObject();
OutputWordUtil.setShapeDefaultValue2(repositoryId, _tr); //设置默认值
_tr.put(OutputWordUtil.SERIAL_NUMBER, index); //序号
_tr.put(OutputWordUtil.REPOSITORY_NAME, specialCharTransfer(repositoryModel.getName().replace("\n", ""))); //流程名称
_tr.put(OutputWordUtil.SHAPE_NAME, specialCharTransfer(shape.get("text").toString()).replace("\n", WRAPSTRING)); //步骤名称
/**序号改为流程编号**/
/*_tr.put(OutputWordUtil.SERIAL_NUMBER, ""); //序号置空
if (shape.containsKey("number")) {
_tr.put(OutputWordUtil.SERIAL_NUMBER, shape.get("number"));
}*/
/**序号改为流程编号**/
// 节点的附件处理
JSONArray shapeFileTable = new JSONArray(); //流程节点附件Table
if (search != null && search.size() > 0) {
// 复制附件
for (UpfileModel upfileModel : search) {
/*
* if ("f".equals(upfileModel.getType())) { continue; } if
* (!shape.get("id").equals(upfileModel.getShape_uuid())) { continue; }
*/
// 复制doccenter下的文件
// DCContext dcContext = null;
// DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE);
// if (dcProfile != null) {
// dcContext = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName());
// }
// File sourceFile = new UtilFile(dcContext.getFilePath());
// File targetFile = new UtilFile(file.toString() + File.separator + dcContext.getFileName());
// try {
// UtilFile.copyFile(sourceFile, targetFile);
// } catch (Exception e) {
// System.out.println(e);
// e.printStackTrace();
// }
/*
* JSONObject object = new JSONObject(); object.put("file_name",
* upfileModel.getFileName()); String link = fileName + File.separator +
* upfileModel.getFileName(); object.put("link", link); fileTable.add(object);
*/
}
}
fileTable.sort(Comparator.comparing(obj -> ((JSONObject) obj).getString("file_name")));
if(shapeFileTable.size() == 0) {// 没有附件时给空值不然使用office打开会解析错误
JSONObject object = new JSONObject();
object.put("shape_file_name", "");
object.put("shape_file_link", "");
shapeFileTable.add(object);
}
_tr.put("shape_File_Table", shapeFileTable);
JSONArray dataAttributes = (JSONArray) shape.get("attributes");
if (!dataAttributes.isEmpty()) {
for (int i = 0; i < dataAttributes.size(); i++) {
JSONObject obj = dataAttributes.getJSONObject(i);
String attrId = obj.getString("key");
String attrValue = obj.getString("value");
_tr.put("shape_" + attrId, attrValue.replace("\n", WRAPSTRING));
if (raciRelationType) {// 涉及部门岗位/角色关联的是bpm组织部门岗位角色
if ("bpm_duty_r".equals(attrId)) {
_tr.put("shape_duty_r", attrValue.replace("\n", WRAPSTRING));
}
if ("bpm_approval_a".equals(attrId)) {
_tr.put("shape_approval_a", attrValue.replace("\n", WRAPSTRING));
}
if ("bpm_counselor_c".equals(attrId)) {
_tr.put("shape_counselor_c", attrValue.replace("\n", WRAPSTRING));
}
if ("bpm_notify_i".equals(attrId)) {
_tr.put("shape_notify_i", attrValue.replace("\n", WRAPSTRING));
}
}
if ("danger".equals(attrId)) {
dangerIndex = setTableValueOfControlAndRisk(attrId, repositoryId, shape.get("id").toString(),dangerTable, dangerIndex, _tr.getString(OutputWordUtil.SHAPE_NAME), relationFileMap);
dangerSet.clear();
}else if ("regulate".equals(attrId)) {
regulateIndex = setTableValueOfControlAndRisk(attrId, repositoryId, shape.get("id").toString(), regulateTable, regulateIndex, _tr.getString(OutputWordUtil.SHAPE_NAME), relationFileMap);
regulateSet.clear();
}
}
}
repositoryShapeTable.add(_tr);
index++;
}
}
// 条款内容xml
Map<String, String> contentMap = getContentData(repositoryId, controlShapeId);
String listDef = contentMap.get("listDef");
String contentXml = contentMap.get("content");
// 流程步骤的指标表格
setTableValueOfKPI("kpi", repositoryId, KPITable, relationFileMap);
if (search != null && search.size() > 0) {
// 复制附件
int index = 1;
for (UpfileModel upfileModel : search) {
if (!"f".equals(upfileModel.getType())) {// 文件
continue;
}
// 复制doccenter下的文件
/*
* DCContext dcContext = null; DCPluginProfile dcProfile =
* DCProfileManager.getDCProfile(CoEConstant.APP_ID,
* CoeFileConstant.COE_UPFILE); if (dcProfile != null) { dcContext = new
* DCContext(userContext, dcProfile, CoEConstant.APP_ID, "file",
* upfileModel.getPl_uuid(), upfileModel.getFileName()); } File sourceFile = new
* UtilFile(dcContext.getFilePath()); File targetFile = new
* UtilFile(file.toString() + File.separator + dcContext.getFileName()); try {
* UtilFile.copyFile(sourceFile, targetFile); } catch (Exception e) {
* System.out.println(e); e.printStackTrace(); } JSONObject object = new
* JSONObject(); object.put("file_name", index + "." +
* upfileModel.getFileName()); String link = fileName + File.separator +
* upfileModel.getFileName(); object.put("link", link);
* System.err.println("==1==>"+object); fileTable.add(object);
* System.err.println("==2==>"+fileTable); index++;
*/
}
}
JSONArray termTable = new JSONArray(); //术语定义Table
// 属性特征 属性代码KEY
try {
PALRepositoryPropertyModel term = PALRepositoryPropertyCache.getPropertyByPropertyId(repositoryModel.getId(),"term");
String termVal = term.getPropertyValue();
JSONObject termObj = JSONObject.parseObject(termVal);
if (termObj != null && !termObj.isEmpty()) {
JSONArray tableArr = termObj.getJSONArray("table");
if (tableArr != null && !tableArr.isEmpty()) {
for (Object obj : tableArr) {
JSONObject obj2 = (JSONObject) obj;
if (!"table_head".equals(obj2.getString("id"))) {
String name = obj2.getString("name");
String desc = obj2.getString("desc");
JSONObject tmp = new JSONObject();
tmp.put("name", specialCharTransfer(name).replace("\n", WRAPSTRING));
tmp.put("desc", specialCharTransfer(desc).replace("\n", WRAPSTRING));
termTable.add(tmp);
}
}
}
}
} catch (Exception e) {
// TODO: handle exception
}
JSONArray organizationTable = new JSONArray(); //组织职责Table
// 属性特征 属性代码KEY
try {
PALRepositoryPropertyModel Organizational = PALRepositoryPropertyCache.getPropertyByPropertyId(repositoryModel.getId(),"Organizational_role");
String OrganizationalVal = Organizational.getPropertyValue();
JSONObject OrganizationalObj = JSONObject.parseObject(OrganizationalVal);
if (OrganizationalObj != null && !OrganizationalObj.isEmpty()) {
JSONArray tableArr = OrganizationalObj.getJSONArray("table");
if (tableArr != null && !tableArr.isEmpty()) {
for (Object obj : tableArr) {
JSONObject obj2 = (JSONObject) obj;
if (!"table_head".equals(obj2.getString("id"))) {
String name = obj2.getString("name");
String desc = obj2.getString("desc");
JSONObject tmp = new JSONObject();
tmp.put("name", specialCharTransfer(name).replace("\n", WRAPSTRING));
tmp.put("desc", specialCharTransfer(desc).replace("\n", WRAPSTRING));
organizationTable.add(tmp);
}
}
}
}
} catch (Exception e) {
// TODO: handle exception
}
//支持文件
JSONArray support_files = new JSONArray();
try {
int count = 0;
String sql = "select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '"+repositoryModel.getId()+"' and PROPERTYID = 'support_files'";
String relatFileJson = DBSql.getString(sql);
if(UtilString.isNotEmpty(relatFileJson)) {
JSONObject parseObject = JSONObject.parseObject(relatFileJson);
String fileNames = parseObject.getString("relationShapeText");
if(UtilString.isNotEmpty(fileNames)) {
String[] names = fileNames.split(",");
for (String name : names) {
count++;
JSONObject tmp = new JSONObject();
tmp.put("name", name);
tmp.put("desc", count);
support_files.add(tmp);
}
}
}
} catch (Exception e) {
// TODO: handle exception
}
/*
* JSONArray support_files = new JSONArray(); //组织职责Table
* List<DesignerShapeRelationModel> relationList =
* DesignerShapeRelationCache.getListByAttrId(repositoryModel.getId(), "",
* "support_files");
*
* relationList.sort(Comparator.comparing(DesignerShapeRelationModel::
* getShapeText));
*
* int index = 0; for (DesignerShapeRelationModel relation : relationList) {
* String relationFileId = relation.getRelationFileId();// 支持或相关文件的ID
* PALRepositoryModel model = PALRepositoryCache.getCache().get(relationFileId);
* if (model != null) { index++; String name = model.getName(); JSONObject tmp =
* new JSONObject(); tmp.put("name", name); tmp.put("desc", index);
* support_files.add(tmp); } }
*/
//相关文件 related_files
JSONArray related_files = new JSONArray();
try {
int count = 0;
String sql = "select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '"+repositoryModel.getId()+"' and PROPERTYID = 'related_files'";
String relatFileJson = DBSql.getString(sql);
if(UtilString.isNotEmpty(relatFileJson)) {
JSONObject parseObject = JSONObject.parseObject(relatFileJson);
String fileNames = parseObject.getString("relationShapeText");
if(UtilString.isNotEmpty(fileNames)) {
String[] names = fileNames.split(",");
for (String name : names) {
count++;
JSONObject tmp = new JSONObject();
tmp.put("name", name);
tmp.put("desc", count);
related_files.add(tmp);
}
}
}
//外部相关文件
String sqlOut = "select PROPERTYVALUE from APP_ACT_COE_PAL_PROP where PLID = '"+repositoryModel.getId()+"' and PROPERTYID = 'Out_related_files'";
String outRelatFileJson = DBSql.getString(sqlOut);
if(UtilString.isNotEmpty(outRelatFileJson)) {
if(outRelatFileJson.contains(",")) {
String[] split = outRelatFileJson.split(",");
for (String str : split) {
count++;
JSONObject tmp = new JSONObject();
tmp.put("name", str+"【外部】");
tmp.put("desc", count);
related_files.add(tmp);
}
}else if(outRelatFileJson.contains("")) {
String[] split = outRelatFileJson.split("");
for (String str : split) {
count++;
JSONObject tmp = new JSONObject();
tmp.put("name", str+"【外部】");
tmp.put("desc", count);
related_files.add(tmp);
}
}else {
count++;
JSONObject tmp = new JSONObject();
tmp.put("name", outRelatFileJson+"【外部】");
tmp.put("desc", count);
related_files.add(tmp);
}
}
} catch (Exception e) {
// TODO: handle exception
}
/*
* JSONArray related_files = new JSONArray(); //组织职责Table
* List<DesignerShapeRelationModel> relationList2 =
* DesignerShapeRelationCache.getListByAttrId(repositoryModel.getId(), "",
* "related_files");
* relationList2.sort(Comparator.comparing(DesignerShapeRelationModel::
* getShapeText)); int count = 0; for (DesignerShapeRelationModel relation :
* relationList2) { String relationFileId = relation.getRelationFileId();//
* 支持或相关文件的ID //System.err.println("生成手册时相关文件id=======>"+relationFileId);
* PALRepositoryModel model = PALRepositoryCache.getCache().get(relationFileId);
* if (model != null) { count++; String name = model.getName(); JSONObject tmp =
* new JSONObject(); tmp.put("name", name); tmp.put("desc", count);
* related_files.add(tmp); } }
*/
//术语
dataMap.put("term_table", termTable);//table4
//如果termTable.size()==0 则显示无
dataMap.put("term_table_count", termTable.size());//table4
//组织和职责
dataMap.put("organization_table", organizationTable);//table5
dataMap.put("organization_table_count",organizationTable.size());//table5
//支持文件
dataMap.put("supports_table", support_files);//table6
dataMap.put("supports_table_count", support_files.size());//table6
//相关文件
dataMap.put("relevant_table", related_files);//table7
dataMap.put("relevant_table_count", related_files.size());//table7
dataMap.put(OutputWordUtil.TABLE_REPOSITORY_SHAPE, repositoryShapeTable);
boolean contains = isNumberAscArray.contains("false");
if(contains) {
fileTable.sort(Comparator.comparing(obj -> ((JSONObject) obj).getString("file_name")));
}else {
try {
fileTable.sort(Comparator.comparing(obj -> ((JSONObject) obj).getInteger("file_number")));
} catch (Exception e) {
throw new AWSQuotaException("附件格式请以《附件1:XXXXXX》格式命名");
}
}
dataMap.put("file_table", fileTable);
dataMap.put("file_table_count", fileTable.size());
//dataMap.put("file_table_count", 0);// 暂时置空
dataMap.put(OutputWordUtil.TABLE_DANGER, dangerTable);
dataMap.put(OutputWordUtil.TABLE_REGULATE, regulateTable);
dataMap.put(OutputWordUtil.TABLE_KPI, KPITable);
ReportRepositoryCompare compare = new ReportRepositoryCompare();
JSONArray historyVersionModify = compare.getModifyVersionHistory(repositoryId);
dataMap.put("history_table", historyVersionModify);
// 修订记录
dataMap.put("version_history_table", getVersionHistoryTable(repositoryModel));
// 附则处理
List<String> T_supplementary_articles_table = new ArrayList<>();
String [] tmp = dataMap.getString("pl_T_supplementary_articles").split("\n");
for (int i = 0; i < tmp.length; i++) {
if (UtilString.isNotEmpty(tmp[i])) {
T_supplementary_articles_table.add(tmp[i]);
}
}
dataMap.put("T_supplementary_articles_table", T_supplementary_articles_table);// 换行
dataMap.put("T_supplementary_articles_count", T_supplementary_articles_table.size());
// 目的处理
List<String> Purpose_table = new ArrayList<>();
String [] tmp2 = dataMap.getString("pl_Purpose").split("\n");
for (int i = 0; i < tmp2.length; i++) {
if (UtilString.isNotEmpty(tmp2[i])) {
Purpose_table.add(tmp2[i]);
}
}
dataMap.put("Purpose_count", Purpose_table.size());
dataMap.put("Purpose_table", Purpose_table);
// 条款word xml内容处理
dataMap.put("control_content_count", contentXml.length());
dataMap.put("control_content", contentXml);
dataMap.put("listDef", listDef);// 列表编号
return dataMap;
}
public static boolean isNumeric(String str) {
@ -982,137 +318,4 @@ public class Report1Gener {
return versionHistoryTable;
}
/**
* 设置风险控制表格
* @param attrId
* @param fileId
* @param shapeId
* @param table
* @param index
* @param relationFileMap
* @return
*/
public int setTableValueOfControlAndRisk(String attrId, String fileId, String shapeId, JSONArray table, int index, String processShapeName, Map<String, Map<String, Object>> relationFileMap) {
JSONArray result = new JSONArray();
DesignerShapeRelationDao dao = new DesignerShapeRelationDao();
List<DesignerShapeRelationModel> list = dao.query(fileId, shapeId, attrId, null, null);
for (DesignerShapeRelationModel model : list) {
String relationFileId = model.getRelationFileId();
if (!relationFileMap.containsKey(relationFileId) && PALRepositoryCache.getCache().get(relationFileId) != null) {
Map<String, Object> shapes = new HashMap<>();
List<Map<String, Object>> fileElements = CoeDesignerUtil.getShapeMessageJson4(relationFileId);
for (Map<String, Object> shape : fileElements) {
String tempShapeId = shape.get("id").toString();
shapes.put(tempShapeId, shape);
}
relationFileMap.put(relationFileId, shapes);
}
}
Set<String> relationShapeIdSet = new HashSet<>(); // 去重
String filterShapeName = "";
if ("danger".equals(attrId)) {// 风险
filterShapeName = "risk";
} else if ("regulate".equals(attrId)) {// 控制
filterShapeName = "control";
}
for (DesignerShapeRelationModel model : list) {
String relationFileId = model.getRelationFileId();
String relationShapeId = model.getRelationShapeId();
if (relationFileMap.containsKey(relationFileId)) {
Map<String, Object> elements = relationFileMap.get(relationFileId);
if (elements != null && elements.containsKey(relationShapeId)) {
Map<String, Object> shape = (Map<String, Object>) elements.get(relationShapeId);
if (!relationShapeIdSet.contains(shape.get("id").toString()) && filterShapeName.equals(shape.get("type"))) {
relationShapeIdSet.add(shape.get("id").toString());
result.add(shape);
}
}
}
}
for (int i = 0; i < result.size(); i++) {
Map<String, Object> shape = result.getJSONObject(i);
JSONObject _tr = new JSONObject();
OutputWordUtil.setShapeDefaultValue2(shape.get("uuid").toString(), _tr); //设置默认值
String name = specialCharTransfer(shape.get("text").toString());
_tr.put("related_" + OutputWordUtil.SHAPE_NAME, processShapeName);
_tr.put(OutputWordUtil.SHAPE_NAME, name.replace("\n", WRAPSTRING));
_tr.put(OutputWordUtil.SERIAL_NUMBER, index);
JSONArray dataAttributes = (JSONArray) shape.get("attributes");
for (int j = 0; j < dataAttributes.size(); j++) {
_tr.put("shape_" + dataAttributes.getJSONObject(j).getString("key"), specialCharTransfer(dataAttributes.getJSONObject(j).getString("value")).replace("\n", " "));
}
table.add(_tr);
index++;
}
return index;
}
/**
* 设置流程步骤的KPI表格
* @param attrId
* @param fileId
* @param table
* @param relationFileMap
* @return
*/
public int setTableValueOfKPI(String attrId, String fileId, JSONArray table, Map<String, Map<String, Object>> relationFileMap) {
int index = 1;
JSONArray result = new JSONArray();
DesignerShapeRelationDao dao = new DesignerShapeRelationDao();
List<DesignerShapeRelationModel> list = dao.query(fileId, null, attrId, null, null);
for (DesignerShapeRelationModel model : list) {
String relationFileId = model.getRelationFileId();
if (!relationFileMap.containsKey(relationFileId) && !UtilString.isEmpty(model.getShapeId())) {
Map<String, Object> shapes = new HashMap<>();
List<Map<String, Object>> fileElements = CoeDesignerUtil.getShapeMessageJson4(relationFileId);
for (Map<String, Object> shape : fileElements) {
String tempShapeId = shape.get("id").toString();
shapes.put(tempShapeId, shape);
}
relationFileMap.put(relationFileId, shapes);
}
}
Set<String> relationShapeIdSet = new HashSet<>(); // 去重
for (DesignerShapeRelationModel model : list) {
String relationFileId = model.getRelationFileId();
String relationShapeId = model.getRelationShapeId();
if (relationFileMap.containsKey(relationFileId)) {
Map<String, Object> elements = relationFileMap.get(relationFileId);
if (elements != null && elements.containsKey(relationShapeId)) {
Map<String, Object> shape = (Map<String, Object>) elements.get(relationShapeId);
if (!relationShapeIdSet.contains(shape.get("id").toString())) {
relationShapeIdSet.add(shape.get("id").toString());
result.add(shape);
}
}
}
}
for (int i = 0; i < result.size(); i++) {
Map<String, Object> shape = result.getJSONObject(i);
JSONObject _tr = new JSONObject();
OutputWordUtil.setShapeDefaultValue2(shape.get("uuid").toString(), _tr); //设置默认值
String name = specialCharTransfer(shape.get("text").toString());
_tr.put(OutputWordUtil.SHAPE_NAME, name.replace("\n", WRAPSTRING));
_tr.put(OutputWordUtil.SERIAL_NUMBER, index);
JSONArray dataAttributes = (JSONArray) shape.get("attributes");
for (int j = 0; j < dataAttributes.size(); j++) {
_tr.put("shape_" + dataAttributes.getJSONObject(j).getString("key"), specialCharTransfer(dataAttributes.getJSONObject(j).getString("value")).replace("\n", " "));
}
table.add(_tr);
index++;
}
return index;
}
}

File diff suppressed because it is too large Load Diff