制度上传正文生成条款
This commit is contained in:
parent
2d697f5ba4
commit
16c0b40946
BIN
com.actionsoft.apps.coe.pal.datamigration/lib/Spire.Doc.jar
Normal file
BIN
com.actionsoft.apps.coe.pal.datamigration/lib/Spire.Doc.jar
Normal file
Binary file not shown.
@ -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();
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -270,8 +277,56 @@ public class CreateMaps implements IJob {
|
||||
if(CoeDesignerAPIManager.getInstance().storeDefinition(defineModel)>0) {
|
||||
return true;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解析富文本代码
|
||||
|
||||
@ -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;
|
||||
@ -242,6 +244,71 @@ 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>();
|
||||
|
||||
@ -12,6 +12,9 @@ import com.actionsoft.bpms.util.UUIDGener;
|
||||
import com.actionsoft.sdk.local.SDK;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.spire.doc.Document;
|
||||
import com.spire.doc.FileFormat;
|
||||
|
||||
import org.apache.poi.hwpf.usermodel.Paragraph;
|
||||
import org.apache.poi.xwpf.usermodel.*;
|
||||
|
||||
@ -39,7 +42,6 @@ public class WordUtilXWPF {
|
||||
*/
|
||||
private static final String WORD_LINE_BREAK = "[\u000B|\r]";
|
||||
|
||||
|
||||
/**
|
||||
* 抽取文字时去掉不必须字符正则
|
||||
*/
|
||||
@ -47,14 +49,13 @@ public class WordUtilXWPF {
|
||||
|
||||
private static final String regexClearBeginBlank = "^" + splitter + "*|" + splitter + "*$";
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
JSONObject elements = null;
|
||||
JSONObject shape = null;
|
||||
/*props1.put("x", 130*zindex);
|
||||
props1.put("y", 277);
|
||||
props1.put("w", 110);
|
||||
props1.put("h", 50);*/
|
||||
/*
|
||||
* props1.put("x", 130*zindex); props1.put("y", 277); props1.put("w", 110);
|
||||
* props1.put("h", 50);
|
||||
*/
|
||||
String filePath = "/Users/jiuyabai/Desktop/yili项目/制度样例1—伊利集团流程制度类文件管理规范1.docx";
|
||||
File file = null;
|
||||
try {
|
||||
@ -85,8 +86,8 @@ public class WordUtilXWPF {
|
||||
String style = paragraph.getStyle();// 标题级别
|
||||
if (org.apache.commons.lang3.StringUtils.isNotEmpty(text)) {// 文字
|
||||
// 将word中的特有字符转化为普通的换行符、空格符等
|
||||
String textWithSameBlankAndBreak = text.replaceAll(WORD_BLANK, " ").replaceAll(WORD_LINE_BREAK, "\n")
|
||||
.replaceAll("\n+", "\n");
|
||||
String textWithSameBlankAndBreak = text.replaceAll(WORD_BLANK, " ")
|
||||
.replaceAll(WORD_LINE_BREAK, "\n").replaceAll("\n+", "\n");
|
||||
// 去除word特有的不可见字符
|
||||
String textClearBeginBlank = textWithSameBlankAndBreak.replaceAll(regexClearBeginBlank, "");
|
||||
// 为抽取的每一个段落加上\n作为换行符标识
|
||||
@ -107,6 +108,322 @@ public class WordUtilXWPF {
|
||||
return jsons;
|
||||
}
|
||||
|
||||
public JSONObject rewritContent2(UserContext userContext, JSONObject elements, DCContext dcContextpdf, String name,
|
||||
JSONObject shapefirst, String plid, int type,String groupValue, String fileValue, String fileName) {
|
||||
|
||||
// File file = null;
|
||||
int count = 0;
|
||||
List<String> failTitleList = new ArrayList<>();
|
||||
StringBuilder richSbuild = new StringBuilder();
|
||||
// String filePath =
|
||||
// "/Users/jiuyabai/Desktop/yili项目/制度样例1—伊利集团流程制度类文件管理规范1.docx";
|
||||
try {
|
||||
// file = new File(filePath);
|
||||
elements.clear();
|
||||
String path = dcContextpdf.getPath();
|
||||
// String filePath = "D:/制度样例1—伊利集团流程制度类文件管理规范2.xml"; //创建实例,加载xml测试文档
|
||||
Document docs = new Document();
|
||||
docs.loadFromFile(path + fileName);
|
||||
|
||||
// 保存为Docx格式
|
||||
|
||||
docs.saveToFile(path+name+".docx",FileFormat.Docx);
|
||||
|
||||
File f = new File(path + fileName);
|
||||
|
||||
InputStream in = new FileInputStream(f);
|
||||
|
||||
byte b[] = new byte[(int) f.length()]; // 创建合适文件大小的数组
|
||||
|
||||
in.read(b); // 读取文件中的内容到b[]数组
|
||||
|
||||
in.close();
|
||||
|
||||
// System.out.println(new String(b));
|
||||
|
||||
// 保存为Doc格式 //docs.saveToFile("toDoc.doc",FileFormat.Doc);
|
||||
|
||||
//
|
||||
DCPluginProfile dcProfilepdfdoc = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", "migration");
|
||||
DCContext dcContextpdf1 = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, name+".docx");
|
||||
InputStream docxfile = SDK.getDCAPI().read(dcContextpdf1);
|
||||
|
||||
XWPFDocument doc = new XWPFDocument(docxfile);
|
||||
JSONArray onlinedata = new JSONArray();
|
||||
if (shapefirst == null || shapefirst.size() == 0) {
|
||||
JSONObject shapeze = ShapeUtil.getProcessShapeDefinitionByName("control.policy", "regulation");
|
||||
String shapeIdz = UUIDGener.getObjectId();
|
||||
shapeze.put("text", name);// 不生效
|
||||
shapeze.put("level", 0);
|
||||
JSONObject props1 = shapeze.getJSONObject("props");// 位置大小
|
||||
shapeze.put("id", shapeIdz);
|
||||
props1.put("x", 100);
|
||||
props1.put("y", 277);
|
||||
props1.put("w", 110);
|
||||
props1.put("h", 50);
|
||||
props1.put("zindex", 0);
|
||||
shapeze.put("next", true);
|
||||
elements.put(shapeIdz, shapeze);
|
||||
shapeze.put("p", 0);
|
||||
onlinedata.add(shapeze);
|
||||
} else {
|
||||
elements.put(shapefirst.getString("id"), shapefirst);
|
||||
shapefirst.put("next", true);
|
||||
shapefirst.put("p", 0);
|
||||
onlinedata.add(shapefirst);
|
||||
}
|
||||
|
||||
// 获取段落
|
||||
List<XWPFParagraph> paras = doc.getParagraphs();
|
||||
// 级别依次
|
||||
// 记录x横向的位置
|
||||
int x = 1;
|
||||
// 记录y轴的位置
|
||||
int y = 1;
|
||||
// 记录上次层级
|
||||
int lastindex = 0;
|
||||
boolean isfirst = true;
|
||||
// 所以条数
|
||||
int countall = 0;
|
||||
// 上级节点是否已有子节点
|
||||
boolean hasnext = false;
|
||||
// 内容的所有数据
|
||||
StringBuilder strb = new StringBuilder();
|
||||
// 记录这条线上的所有节点 顺序就是层级
|
||||
// List<JSONObject> onlinedata = new ArrayList<JSONObject>();
|
||||
boolean lastislast = false;
|
||||
XWPFDocument newfile = new XWPFDocument();
|
||||
boolean isend = false;
|
||||
boolean isstart = true;
|
||||
for (XWPFParagraph para : paras) {
|
||||
BigInteger numlevel = para.getNumIlvl();
|
||||
String paragraphText = para.getParagraphText();
|
||||
countall += 1;
|
||||
// 处理富文本的情况
|
||||
if (shapefirst != null && type == 0) {
|
||||
isstart = false;
|
||||
}
|
||||
if (isstart) {// && numlevel == null && isstart) {
|
||||
count++;
|
||||
isstart = false;
|
||||
//continue;
|
||||
}
|
||||
if (isstart) {
|
||||
continue;
|
||||
}
|
||||
if (!para.getParagraphText().isEmpty()) {
|
||||
if (para.getParagraphText().matches("附件\\d{1,}:")) {
|
||||
isend = true;
|
||||
}
|
||||
XWPFParagraph tmpp = newfile.createParagraph();
|
||||
WordCreatFile.copyAllRunsToAnotherParagraph(para, tmpp);
|
||||
}
|
||||
if (isend) {
|
||||
continue;
|
||||
}
|
||||
hasnext = false;
|
||||
JSONObject shap = new JSONObject();
|
||||
String leveltext = para.getNumLevelText();
|
||||
|
||||
String titleLvl = getTitleLvl(doc, para);// 获取段落级别
|
||||
// System.out.println("numlevel" + numlevel + "======leveltext=====" + leveltext
|
||||
// + "=====获取到的级别为=====" + titleLvl + " =======内容为=====" + para.getText());
|
||||
|
||||
// System.out.println("=====当前level为" + (numlevel != null ? numlevel.intValue()
|
||||
// : "空") + "=====上一节点层级为" + lastindex + " ");
|
||||
|
||||
// 标题级别
|
||||
if (numlevel != null && numlevel.intValue() > 0) {
|
||||
int nowlevel = numlevel.intValue();
|
||||
// 如果换层级了 就清空后面的数据
|
||||
if ((nowlevel < lastindex || lastindex == 0) && onlinedata.size() >= (nowlevel + 1)) {
|
||||
// System.out.println("进行数据清理");
|
||||
JSONArray tmp = new JSONArray();
|
||||
for (int i = 0; i <= nowlevel; i++) {
|
||||
tmp.add(onlinedata.getJSONObject(i));
|
||||
}
|
||||
onlinedata = tmp;
|
||||
}
|
||||
lastislast = false;
|
||||
String shapeId1 = UUIDGener.getObjectId();
|
||||
int pnode = lastindex;
|
||||
boolean issamelevel = false;
|
||||
// 如果是同级,需要找到父节点
|
||||
if (lastindex == nowlevel) {
|
||||
JSONObject tmpshap1 = onlinedata.getJSONObject(lastindex);
|
||||
pnode = tmpshap1.getInteger("p");
|
||||
x = 0;
|
||||
} else {
|
||||
if (nowlevel > lastindex && (lastindex != 0 || isfirst)) {
|
||||
x = 1;
|
||||
} else {
|
||||
x = 0;
|
||||
}
|
||||
/**
|
||||
* 如果不是同级 需要找到同级
|
||||
*/
|
||||
if ((onlinedata.size() - 1) >= nowlevel && onlinedata.get(nowlevel) != null) {
|
||||
JSONObject tmpshap1 = onlinedata.getJSONObject(nowlevel);
|
||||
pnode = tmpshap1.getInteger("p");
|
||||
lastindex = nowlevel;
|
||||
}
|
||||
/**
|
||||
* 找上一级
|
||||
*/
|
||||
if (onlinedata.size() == nowlevel && lastindex == 0) {
|
||||
lastindex = nowlevel - 1;
|
||||
JSONObject tmpshap1 = onlinedata.getJSONObject(lastindex);
|
||||
pnode = lastindex;
|
||||
hasnext = tmpshap1.getBoolean("next");
|
||||
x = 1;
|
||||
}
|
||||
}
|
||||
isfirst = false;
|
||||
// 如果是父节点新增,则要父节点的节点
|
||||
JSONObject tmpshap = onlinedata.getJSONObject(lastindex);
|
||||
// System.out.println("======获取上一节点位置为:" + lastindex + " ====节点内容为:" +
|
||||
// tmpshap.getString("text"));
|
||||
int len = para.getParagraphText().length() / 8 - 2;
|
||||
/**
|
||||
* 计算y
|
||||
*/
|
||||
if (nowlevel <= lastindex || hasnext) {
|
||||
y += 1;
|
||||
}
|
||||
|
||||
shap = getSharp(x, y, countall, len, tmpshap, para.getParagraphText(), "item2");
|
||||
shap.put("id", shapeId1);
|
||||
shap.put("text", getShowText(para.getParagraphText()));
|
||||
shap.put("level", nowlevel);
|
||||
shap.put("p", pnode);
|
||||
elements.put(shapeId1, shap);
|
||||
// 拼接富文本标签
|
||||
richSbuild.append(DocToHtml.getHtml(nowlevel, para.getParagraphText()));
|
||||
JSONObject linkshap = onlinedata.getJSONObject(pnode);
|
||||
linkshap.put("next", true);
|
||||
onlinedata.set(pnode, linkshap);
|
||||
craetline(elements, linkshap, shap, countall);
|
||||
onlinedata.set(nowlevel, shap);
|
||||
lastindex = nowlevel;
|
||||
} else {
|
||||
// 内容
|
||||
if (StringUtils.isNotEmpty(para.getParagraphText())) {
|
||||
if (para.getParagraphText().contains("表单/模板适用范围")) {
|
||||
System.out.println("断电测试11111");
|
||||
}
|
||||
// countall += 1;
|
||||
// 判断下一个是否同一级
|
||||
boolean islast = false;
|
||||
if (countall == paras.size()) {
|
||||
islast = true;
|
||||
}
|
||||
if (countall < paras.size()) {
|
||||
BigInteger nextlevel = paras.get(countall).getNumIlvl();
|
||||
// 后面数据为高级别文字
|
||||
if (nextlevel != null && nextlevel.intValue() > 0) {
|
||||
islast = true;
|
||||
} else {
|
||||
// 后面为图片 或者表格 则要判断这之后是否有同级文字
|
||||
int tmp = countall;
|
||||
while (tmp < paras.size()) {
|
||||
XWPFParagraph paratmp = paras.get(tmp);
|
||||
BigInteger nextleveltmp = paratmp.getNumIlvl();
|
||||
if (nextleveltmp == null && paratmp.getParagraphText().length() == 0) {
|
||||
tmp += 1;
|
||||
} else {
|
||||
// 有同级文字
|
||||
if ((nextleveltmp == null || nextleveltmp.intValue() == 0)
|
||||
&& paratmp.getParagraphText().length() > 0) {
|
||||
islast = false;
|
||||
} else {
|
||||
islast = true;
|
||||
}
|
||||
if (paratmp.getParagraphText().matches("附件\\d{1,}:")) {
|
||||
islast = true;
|
||||
}
|
||||
if ("".equals(para.getParagraphText())) {
|
||||
// System.err.println("========相关文件========");
|
||||
islast = true;
|
||||
isend = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (islast && !isend) {
|
||||
strb.append(para.getParagraphText());
|
||||
// 拼接富文本标签
|
||||
richSbuild.append(DocToHtml.getHtml(0, para.getParagraphText()));
|
||||
}
|
||||
if (strb.length() > 0 && islast) {
|
||||
if ("".equals(para.getParagraphText())) {
|
||||
isend = true;
|
||||
lastislast = true;
|
||||
break;
|
||||
}
|
||||
String shapeId1 = UUIDGener.getObjectId();
|
||||
// System.out.println("段落内容===" + para.getParagraphText());//段落内容
|
||||
lastindex = onlinedata.size() - 1;
|
||||
// 获取级数
|
||||
int len = strb.length() / 8 - 2;
|
||||
int pnode = lastindex;
|
||||
int nowlevel = 0;
|
||||
if (numlevel != null) {
|
||||
nowlevel = numlevel.intValue();
|
||||
}
|
||||
/*
|
||||
* if (lastindex == nowlevel) { JSONObject tmpshap1 =
|
||||
* onlinedata.getJSONObject(lastindex); pnode = tmpshap1.getInteger("p"); }
|
||||
*/
|
||||
x = 1;
|
||||
JSONObject tmpshap = onlinedata.getJSONObject(lastindex);
|
||||
// 根据上一个位置计算当前位置
|
||||
shap = getSharp(x, y, countall, len, tmpshap, strb.toString(), "item1");
|
||||
shap.put("id", shapeId1);
|
||||
shap.put("text", getShowText(strb.toString()).replaceAll("\n", ""));
|
||||
// shap.put("p", pnode);
|
||||
shap.put("level", 0);
|
||||
|
||||
JSONObject linkshap = onlinedata.getJSONObject(lastindex);
|
||||
craetline(elements, linkshap, shap, countall);
|
||||
linkshap.put("next", true);
|
||||
onlinedata.set(pnode, linkshap);
|
||||
elements.put(shapeId1, shap);
|
||||
strb = new StringBuilder();
|
||||
} else {
|
||||
strb.append(para.getParagraphText()).append("\n");
|
||||
// 拼接富文本标签
|
||||
richSbuild.append(DocToHtml.getHtml(0, para.getParagraphText()));
|
||||
}
|
||||
lastislast = true;
|
||||
lastindex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 将doc保存为富文本
|
||||
if (type == 1) {
|
||||
saveRichText(userContext, richSbuild, plid, shapefirst.getString("id"));
|
||||
}
|
||||
// new WordCreatFile().createFile(newfile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 会在本地产生临时文件,用完后需要删除
|
||||
/*
|
||||
* if (file.exists()) { //file.delete(); }
|
||||
*/
|
||||
}
|
||||
if (count > 0) {
|
||||
return elements;
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userContext
|
||||
* @param elements
|
||||
@ -117,12 +434,14 @@ public class WordUtilXWPF {
|
||||
* @param type 是导入还是富文本 1是导入 0是富文本
|
||||
* @return
|
||||
*/
|
||||
public JSONObject rewritContent(UserContext userContext, JSONObject elements, InputStream inputStream, String name, JSONObject shapefirst, String plid, int type) {
|
||||
public JSONObject rewritContent(UserContext userContext, JSONObject elements, InputStream inputStream, String name,
|
||||
JSONObject shapefirst, String plid, int type) {
|
||||
// File file = null;
|
||||
int count = 0;
|
||||
List<String> failTitleList = new ArrayList<>();
|
||||
StringBuilder richSbuild = new StringBuilder();
|
||||
//String filePath = "/Users/jiuyabai/Desktop/yili项目/制度样例1—伊利集团流程制度类文件管理规范1.docx";
|
||||
// String filePath =
|
||||
// "/Users/jiuyabai/Desktop/yili项目/制度样例1—伊利集团流程制度类文件管理规范1.docx";
|
||||
try {
|
||||
// file = new File(filePath);
|
||||
elements.clear();
|
||||
@ -204,9 +523,11 @@ public class WordUtilXWPF {
|
||||
String leveltext = para.getNumLevelText();
|
||||
|
||||
String titleLvl = getTitleLvl(doc, para);// 获取段落级别
|
||||
//System.out.println("numlevel" + numlevel + "======leveltext=====" + leveltext + "=====获取到的级别为=====" + titleLvl + " =======内容为=====" + para.getText());
|
||||
// System.out.println("numlevel" + numlevel + "======leveltext=====" + leveltext
|
||||
// + "=====获取到的级别为=====" + titleLvl + " =======内容为=====" + para.getText());
|
||||
|
||||
//System.out.println("=====当前level为" + (numlevel != null ? numlevel.intValue() : "空") + "=====上一节点层级为" + lastindex + " ");
|
||||
// System.out.println("=====当前level为" + (numlevel != null ? numlevel.intValue()
|
||||
// : "空") + "=====上一节点层级为" + lastindex + " ");
|
||||
|
||||
// 标题级别
|
||||
if (numlevel != null && numlevel.intValue() > 0) {
|
||||
@ -257,7 +578,8 @@ public class WordUtilXWPF {
|
||||
isfirst = false;
|
||||
// 如果是父节点新增,则要父节点的节点
|
||||
JSONObject tmpshap = onlinedata.getJSONObject(lastindex);
|
||||
// System.out.println("======获取上一节点位置为:" + lastindex + " ====节点内容为:" + tmpshap.getString("text"));
|
||||
// System.out.println("======获取上一节点位置为:" + lastindex + " ====节点内容为:" +
|
||||
// tmpshap.getString("text"));
|
||||
int len = para.getParagraphText().length() / 8 - 2;
|
||||
/**
|
||||
* 计算y
|
||||
@ -307,7 +629,8 @@ public class WordUtilXWPF {
|
||||
tmp += 1;
|
||||
} else {
|
||||
// 有同级文字
|
||||
if ((nextleveltmp == null || nextleveltmp.intValue() == 0) && paratmp.getParagraphText().length() > 0) {
|
||||
if ((nextleveltmp == null || nextleveltmp.intValue() == 0)
|
||||
&& paratmp.getParagraphText().length() > 0) {
|
||||
islast = false;
|
||||
} else {
|
||||
islast = true;
|
||||
@ -347,10 +670,10 @@ public class WordUtilXWPF {
|
||||
if (numlevel != null) {
|
||||
nowlevel = numlevel.intValue();
|
||||
}
|
||||
/* if (lastindex == nowlevel) {
|
||||
JSONObject tmpshap1 = onlinedata.getJSONObject(lastindex);
|
||||
pnode = tmpshap1.getInteger("p");
|
||||
}*/
|
||||
/*
|
||||
* if (lastindex == nowlevel) { JSONObject tmpshap1 =
|
||||
* onlinedata.getJSONObject(lastindex); pnode = tmpshap1.getInteger("p"); }
|
||||
*/
|
||||
x = 1;
|
||||
JSONObject tmpshap = onlinedata.getJSONObject(lastindex);
|
||||
// 根据上一个位置计算当前位置
|
||||
@ -385,9 +708,9 @@ public class WordUtilXWPF {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 会在本地产生临时文件,用完后需要删除
|
||||
/*if (file.exists()) {
|
||||
//file.delete();
|
||||
}*/
|
||||
/*
|
||||
* if (file.exists()) { //file.delete(); }
|
||||
*/
|
||||
}
|
||||
if (count > 0) {
|
||||
return elements;
|
||||
@ -396,13 +719,14 @@ public class WordUtilXWPF {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void saveRichText(UserContext userContext, StringBuilder content, String pluuid, String shapid) {
|
||||
// 先保存 将富文本存为附件
|
||||
DCPluginProfile dcProfilepdf = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", "migration");
|
||||
DCContext dcContextpdf = new DCContext(userContext, dcProfilepdf, "com.actionsoft.apps.coe.pal.datamigration", pluuid, shapid, "richText.text");
|
||||
DCPluginProfile dcProfilepdf = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration",
|
||||
"migration");
|
||||
DCContext dcContextpdf = new DCContext(userContext, dcProfilepdf, "com.actionsoft.apps.coe.pal.datamigration",
|
||||
pluuid, shapid, "richText.text");
|
||||
InputStream sbs = new ByteArrayInputStream(content.toString().getBytes(StandardCharsets.UTF_8));
|
||||
SDK.getDCAPI().write(sbs, dcContextpdf);
|
||||
}
|
||||
@ -463,8 +787,10 @@ public class WordUtilXWPF {
|
||||
String leveltext = para.getNumLevelText();
|
||||
BigInteger numlevel = para.getNumIlvl();
|
||||
String titleLvl = getTitleLvl(doc, para);// 获取段落级别
|
||||
System.out.println("numlevel" + numlevel + "======leveltext=====" + leveltext + "=====获取到的级别为=====" + titleLvl + " =======内容为=====" + para.getText());
|
||||
if ("a5".equals(titleLvl) || "a7".equals(titleLvl) || "HTML".equals(titleLvl) || "".equals(titleLvl) || null == titleLvl) {
|
||||
System.out.println("numlevel" + numlevel + "======leveltext=====" + leveltext + "=====获取到的级别为====="
|
||||
+ titleLvl + " =======内容为=====" + para.getText());
|
||||
if ("a5".equals(titleLvl) || "a7".equals(titleLvl) || "HTML".equals(titleLvl) || "".equals(titleLvl)
|
||||
|| null == titleLvl) {
|
||||
titleLvl = "8";
|
||||
}
|
||||
Date date = new Date();// 时间
|
||||
@ -477,7 +803,8 @@ public class WordUtilXWPF {
|
||||
++inT;
|
||||
level = 0;
|
||||
if (inT != 1) {// 第一次不添加,第二次到的时候说明前边的段落内容已经循环完成然后添加
|
||||
//System.out.println("级别===" + titleLvl + " 数值======= " + para.getNumLevelText() + " 内容===" + para.getParagraphText());
|
||||
// System.out.println("级别===" + titleLvl + " 数值======= " +
|
||||
// para.getNumLevelText() + " 内容===" + para.getParagraphText());
|
||||
leavone += 1;
|
||||
countall += 1;
|
||||
lastindex = 0;
|
||||
@ -489,7 +816,8 @@ public class WordUtilXWPF {
|
||||
} else if ("1".equals(titleLvl)) {
|
||||
++inE;
|
||||
if (inE != 1 && level == 1) {// 第一次不添加,第二次到的时候说明前边的段落内容已经循环完成然后添加
|
||||
//System.out.println("级别===" + titleLvl + " 数值======= " + para.getNumLevelText() + " 内容===" + para.getParagraphText());
|
||||
// System.out.println("级别===" + titleLvl + " 数值======= " +
|
||||
// para.getNumLevelText() + " 内容===" + para.getParagraphText());
|
||||
leavone += 1;
|
||||
countall += 1;
|
||||
if (lastindex == 2) {
|
||||
@ -517,7 +845,8 @@ public class WordUtilXWPF {
|
||||
level = 1;
|
||||
} else if ("2".equals(titleLvl)) {
|
||||
// level = 2;
|
||||
//System.out.println("级别===" + titleLvl + " 数值======= " + para.getNumLevelText() + " 内容===" + para.getParagraphText());
|
||||
// System.out.println("级别===" + titleLvl + " 数值======= " +
|
||||
// para.getNumLevelText() + " 内容===" + para.getParagraphText());
|
||||
leatwo += 1;
|
||||
countall += 1;
|
||||
if (lastindex == 1) {
|
||||
@ -585,9 +914,9 @@ public class WordUtilXWPF {
|
||||
} finally {
|
||||
|
||||
// 会在本地产生临时文件,用完后需要删除
|
||||
/*if (file.exists()) {
|
||||
//file.delete();
|
||||
}*/
|
||||
/*
|
||||
* if (file.exists()) { //file.delete(); }
|
||||
*/
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
@ -628,7 +957,8 @@ public class WordUtilXWPF {
|
||||
|
||||
JSONObject shape1 = ShapeUtil.getProcessShapeDefinitionByName("control.policy", type);
|
||||
// shape1.put("id", shapeId1);
|
||||
JSONArray attribute = shape1.getJSONArray("dataAttributes").getJSONObject(0).getJSONArray("attributesJsonArray");
|
||||
JSONArray attribute = shape1.getJSONArray("dataAttributes").getJSONObject(0)
|
||||
.getJSONArray("attributesJsonArray");
|
||||
JSONObject tmp = new JSONObject();
|
||||
tmp.put("ref", "");
|
||||
tmp.put("readonly", false);
|
||||
@ -667,9 +997,7 @@ public class WordUtilXWPF {
|
||||
|
||||
/**
|
||||
* Word中的大纲级别,可以通过getPPr().getOutlineLvl()直接提取,但需要注意,Word中段落级别,通过如下三种方式定义:
|
||||
* 1、直接对段落进行定义;
|
||||
* 2、对段落的样式进行定义;
|
||||
* 3、对段落样式的基础样式进行定义。
|
||||
* 1、直接对段落进行定义; 2、对段落的样式进行定义; 3、对段落样式的基础样式进行定义。
|
||||
* 因此,在通过“getPPr().getOutlineLvl()”提取时,需要依次在如上三处读取。
|
||||
*
|
||||
* @param doc
|
||||
@ -689,7 +1017,8 @@ public class WordUtilXWPF {
|
||||
try {
|
||||
// 判断该段落的样式是否设置了大纲级别
|
||||
if (doc.getStyles().getStyle(para.getStyle()).getCTStyle().getPPr().getOutlineLvl() != null) {
|
||||
return String.valueOf(doc.getStyles().getStyle(para.getStyle()).getCTStyle().getPPr().getOutlineLvl().getVal());
|
||||
return String.valueOf(
|
||||
doc.getStyles().getStyle(para.getStyle()).getCTStyle().getPPr().getOutlineLvl().getVal());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -700,7 +1029,8 @@ public class WordUtilXWPF {
|
||||
if (doc.getStyles().getStyle(doc.getStyles().getStyle(para.getStyle()).getCTStyle().getBasedOn().getVal())
|
||||
.getCTStyle().getPPr().getOutlineLvl() != null) {
|
||||
String styleName = doc.getStyles().getStyle(para.getStyle()).getCTStyle().getBasedOn().getVal();
|
||||
return String.valueOf(doc.getStyles().getStyle(styleName).getCTStyle().getPPr().getOutlineLvl().getVal());
|
||||
return String
|
||||
.valueOf(doc.getStyles().getStyle(styleName).getCTStyle().getPPr().getOutlineLvl().getVal());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
|
||||
@ -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">
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user