制度上传正文生成条款

This commit is contained in:
lihongyu 2022-11-01 13:47:22 +08:00
parent 2d697f5ba4
commit 16c0b40946
8 changed files with 1237 additions and 661 deletions

View File

@ -228,7 +228,7 @@ public class DataMigrationController {
return ResponseObject.newErrResponse("找不到该流程").toString();
}
String wsId = plModel.getWsId();
new ReadWordUtil().translateDocTDocx(me,wsId,groupValue,ruuid,fileNames);
new ReadWordUtil().translateDoc(me,wsId,groupValue,ruuid,fileNames);
ResponseObject ro = ResponseObject.newOkResponse();
return ro.toString();
}

View File

@ -0,0 +1,124 @@
package com.actionsoft.apps.coe.pal.datamigration.util;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import java.io.*;
/**
* XML读取帮助类
* @author zhouxuan
*/
public class XMLUtil {
/**
* copy数据将unicode数据转换为中文
* @param fromFilePath
* @param toFilePath
*/
public static void unicode2String(String fromFilePath, String toFilePath) throws DocumentException, FileNotFoundException{
Document d = XMLUtil.readXML(fromFilePath, true);
XMLUtil.writeXml(d, toFilePath);
}
public static Document readXML(String filePath, boolean ignoreDtd) throws DocumentException, FileNotFoundException {
if (filePath == null) {
return null;
}
SAXReader reader = new SAXReader();
if (ignoreDtd) {
reader.setValidation(false);
reader.setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
return new InputSource(new ByteArrayInputStream("<?xml version='1.0' encoding='UTF-8'?>".getBytes()));
}
});
}
Document document = null;
try {
int jarIndicator = filePath.indexOf('!');
if (jarIndicator > 0) {
filePath = filePath.substring(5, filePath.indexOf('!'));
}
File f = new File(filePath);
InputStream in = new FileInputStream(f);
if (in != null) {
document = reader.read(in);
} else {
File file = new File(filePath);
document = reader.read(file);
}
return document;
} catch (DocumentException e) {
e.printStackTrace();
throw e;
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
public static Document readXMLFromInputStream(InputStream in) {
Document document = null;
SAXReader reader = new SAXReader();
try {
document = reader.read(in);
} catch (DocumentException e) {
e.printStackTrace();
}
return document;
}
public static void writeXml(Document document, String filePath) {
File xmlFile = new File(filePath);
XMLWriter writer = null;
try {
if (xmlFile.exists())
xmlFile.delete();
writer = new XMLWriter(new FileOutputStream(xmlFile), OutputFormat.createPrettyPrint());
writer.write(document);
writer.close();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static Document createDocument(String rootName, String attributeName, String attributeVaule) {
Document document = null;
try {
document = DocumentHelper.createDocument();
Element root = document.addElement(rootName);
root.addAttribute(attributeName, attributeVaule);
} catch (Exception e) {
throw new RuntimeException(e + "->创建的【" + rootName + "】根节点出现错误");
}
return document;
}
}

View File

@ -155,18 +155,25 @@ public class CreateMaps implements IJob {
} catch (Exception e) {
e.printStackTrace();
}*/
String id = "f71ba89d-a594-4144-b89b-25324d67f310";
String name = "制度样例1—伊利集团流程制度类文件管理规范(2)";
String id = "56409791-2c44-4f0e-85a9-146050053521";
String name = "制度样例1—伊利集团流程制度类文件管理规范2";
DCPluginProfile dcProfilepdf = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", "migration");
DCContext dcContextpdf = new DCContext(UserContext.fromUID("admin"), dcProfilepdf, "com.actionsoft.apps.coe.pal.datamigration", "yili", "SystemType1656565751273", "制度样例1—伊利集团流程制度类文件管理规范(2).doc");
DCContext dcContextpdf = new DCContext(UserContext.fromUID("admin"), dcProfilepdf, "com.actionsoft.apps.coe.pal.datamigration", "yili", "SystemType1656565751273", "制度样例1—伊利集团流程制度类文件管理规范2.doc");
InputStream docfile = SDK.getDCAPI().read(dcContextpdf);
//InputStream docfile = new FileInputStream(new File("/Users/jiuyabai/Desktop/yili项目/制度样例1—伊利集团流程制度类文件管理规范(2).doc"));
ReadWordUtil tmp = new ReadWordUtil();
tmp.writeAttrbute(null,true,null, docfile, name, id);
DCContext dcContextpdf1 = new DCContext(UserContext.fromUID("admin"), dcProfilepdf, "com.actionsoft.apps.coe.pal.datamigration", "yili", "SystemType1656565751273", "制度样例1—伊利集团流程制度类文件管理规范(2).docx");
InputStream docxfile = SDK.getDCAPI().read(dcContextpdf1);
//InputStream docxfile = new FileInputStream(new File("/Users/jiuyabai/Desktop/yili项目/制度样例1—伊利集团流程制度类文件管理规范(2).docx"));
new CreateMaps().updateMaps(null, id, docxfile, name);
//tmp.writeAttrbute(null,true,null, docfile, name, id);
DCContext dcContextpdf1 = new DCContext(UserContext.fromUID("admin"), dcProfilepdf, "com.actionsoft.apps.coe.pal.datamigration", "yili", "SystemType1656565751273", "制度样例1—伊利集团流程制度类文件管理规范2.docx");
//InputStream docxfile = SDK.getDCAPI().read(dcContextpdf1);
InputStream docxfile = null;
try {
docxfile = new FileInputStream(new File("C:/伊利集团公文处理管理办法-新.xml"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
boolean updateMaps = new CreateMaps().updateMaps(null, id, docxfile, name);
System.err.println(updateMaps);
}
/**
@ -262,7 +269,7 @@ public class CreateMaps implements IJob {
}
}
elements = new WordUtilXWPF().rewritContent(userContext, elements, file, name, firstNode, palRepositoryModel.getId(), 1);
// 设置画布大小
setDiagramHeightWidth(definition, elements);
defineModel.setDefinition(definition.toString());
@ -270,8 +277,56 @@ public class CreateMaps implements IJob {
if(CoeDesignerAPIManager.getInstance().storeDefinition(defineModel)>0) {
return true;
}
return false;
return true;
}
/**
* 解析word文件
*
* @param id
* @param file
* @param name
*/
public boolean updateMaps2(UserContext userContext, String id,DCContext dcContextpdf1, String name, String groupValue, String fileValue, String fileName) {
PALRepositoryModel palRepositoryModel = ReadWordUtil.getRepositoryByName(id, name);
if(palRepositoryModel == null){
return false;
}
BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(palRepositoryModel.getId(), 0);
if (defineModel == null) {
defineModel = CoeDesignerUtil.createModel(palRepositoryModel.getId(), 0);
defineModel.setCreateHistory(false);
}
String define = defineModel.getDefinition();
JSONObject definition = JSONObject.parseObject(define);
JSONObject elements = definition.getJSONObject("elements");
String shapeId = UUIDGener.getObjectId();
if (StringUtils.isNotEmpty(definition.getString("commonShapeConfig"))) {
definition.remove("commonShapeConfig");
}
int zindex = 1;
//找到第一个节点
JSONObject firstNode = new JSONObject();
for (Map.Entry<String, Object> entry : elements.entrySet()) {
String key = entry.getKey();
JSONObject value = (JSONObject) entry.getValue();
if ("regulation".equals(value.getString("name"))) {
firstNode = value;
}
}
elements = new WordUtilXWPF().rewritContent2(userContext, elements, dcContextpdf1, name, firstNode, palRepositoryModel.getId(), 1,groupValue,fileValue,fileName);
// 设置画布大小
setDiagramHeightWidth(definition, elements);
System.err.println("==========>"+elements);
defineModel.setDefinition(definition.toString());
// 保存文件
if(CoeDesignerAPIManager.getInstance().storeDefinition(defineModel)>0) {
return true;
}
return true;
}
/**
* 解析富文本代码

View File

@ -4,6 +4,8 @@ import com.actionsoft.apps.coe.pal.constant.CoEConstant;
import com.actionsoft.apps.coe.pal.datamigration.model.po.WordAttribute;
import com.actionsoft.apps.coe.pal.datamigration.model.po.WordField;
import com.actionsoft.apps.coe.pal.pal.repository.dao.CoeProcessLevelDaoFacotory;
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.model.PALRepositoryModel;
import com.actionsoft.apps.coe.pal.pal.repository.upfile.constant.CoeFileConstant;
import com.actionsoft.apps.coe.pal.pal.repository.upfile.dao.UpFileDao;
@ -241,7 +243,72 @@ public class ReadWordUtil {
}
}
public void translateDoc(UserContext userContext, String wsId, String groupValue, String fileValue, String fileName) {
HashMap<String,Object> logMaps = new HashMap<String,Object>();
logMaps.put("FILENAME", fileName);
DCPluginProfile dcProfilepdf = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", "migration");
DCContext dcContextpdf = new DCContext(userContext, dcProfilepdf, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, fileName);
//InputStream docfile = SDK.getDCAPI().read(dcContextpdf);
String filepath = dcContextpdf.getFilePath();
String fileNewPath = dcContextpdf.getFilePath();
String docname = "";
String docxname = fileName;
boolean iscreatemap = true;
String name = "";
if(fileName.endsWith(".doc")||fileName.endsWith(".docx")) {
docname = fileName.replace(".docx", ".doc");
name = fileName.substring(0,fileName.lastIndexOf(".doc"));
}else if(fileName.endsWith(".xml")) {
name = fileName.substring(0,fileName.lastIndexOf(".xml"));
}
DCPluginProfile dcProfilepdfdoc = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", "migration");
//将文件挂载到附件里面
DCContext dcContextorigin = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, fileName);
InputStream originfile = SDK.getDCAPI().read(dcContextorigin);
PALRepositoryModel palRepositoryModel = getRepositoryByName(wsId, name);
try {
String id = palRepositoryModel.getId();
logMaps.put("PALID",id);
//查询对应绩效模型中数据模型进行填充数据
BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(id, 0);
String shpId = "";
String define = defineModel.getDefinition();
JSONObject definition = JSONObject.parseObject(define);
JSONObject elements = definition.getJSONObject("elements");
for (String key : elements.keySet()) {
JSONObject shape1 = elements.getJSONObject(key);
if("regulation".equals(shape1.getString("name"))) {
shpId = key;
break;
}
}
//删除已有xml文件
StringBuffer sql = new StringBuffer();
sql.append("delete from ").append(UpfileModel.DATABASE_ENTITY).append(" WHERE SHAPEID = '" + shpId + "'");
int update = DBSql.update(sql.toString());
boolean writeFileTodisk = writeFileTodisk(userContext, shpId, fileName, originfile, palRepositoryModel.getId(), "s");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//创建图形
if (iscreatemap) {
DCContext dcContextpdf1 = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, fileName);
InputStream docxfile = SDK.getDCAPI().read(dcContextpdf1);
if(new CreateMaps().updateMaps2(userContext, wsId, dcContextpdf1, name, groupValue, fileValue, fileName)) {
logMaps.put("CREATESHAPE", "图形创建成功!");
}else {
logMaps.put("CREATESHAPE", "图形创建失败!");
}
}
}
public void translateDocTDocx(UserContext userContext, String wsId, String groupValue, String fileValue, String fileName) {
HashMap<String,Object> logMaps = new HashMap<String,Object>();

View File

@ -3027,7 +3027,7 @@
<div style="width: 550px;height: 280px;vertical-align: top;">
<button id="pupShapeFile" onclick="return false;" type="button" class="awsui-btn awsui-btn-green" style="margin-left: 20px;margin-top:10px">新增</button>
<div style="margin-left: 20px;padding: 5px; font-size: 12px; color: rgb(120, 120, 120);">
<span>附件格式支持:doc, docx 文件大小不超过10M</span>
<span>附件格式支持:xml, doc, docx 文件大小不超过50M</span>
</div>
<div style="height:210px;overflow-x: hidden;overflow-y:auto;">
<table class="awsui-ux">

View File

@ -4496,10 +4496,10 @@ function addPolicyFile() {
appId: "com.actionsoft.apps.coe.pal.datamigration",
groupValue:"policyFile",
fileValue:ruuid,
filesToFilter : [["Document(*.doc;*.docx;)","*.doc;*.docx;"]],
filesToFilter : [["Document(*.xml;*.doc;*.docx;)","*.xml;*.doc;*.docx;"]],
repositoryName: "migration",
numLimit : 1,
sizeLimit : 10 * 1024 * 1024,
sizeLimit : 50 * 1024 * 1024,
complete:function(){
//事件回调函数
$.simpleAlert('close');
@ -4508,7 +4508,7 @@ function addPolicyFile() {
add: function(e, data) { //附件被添加到上传列表时触发当返回false时可阻止上传
if (data.files.length == 0) {
return false;
} else if (data.files[0].size > 10 * 1024 * 1024) {
} else if (data.files[0].size > 50 * 1024 * 1024) {
$.simpleAlert("文件过大");
return false;
}