Merge branch 'datamigration-word' of https://e.coding.net/yilidev/yilipalkaifa/apps
Conflicts: com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/DataMigrationController.java com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/htmltodocx/HtmlUtils.java com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/htmltodocx/Test.java com.actionsoft.apps.coe.pal.datamigration/web/com.actionsoft.apps.coe.pal.datamigration/action.xml
This commit is contained in:
commit
df6107eb37
Binary file not shown.
@ -1,9 +1,7 @@
|
||||
package com.actionsoft.apps.coe.pal.datamigration;
|
||||
|
||||
import com.actionsoft.apps.coe.pal.datamigration.aris.web.ArisXmlImportWeb;
|
||||
import com.actionsoft.apps.coe.pal.datamigration.util.readword.ReadWordUtil;
|
||||
import com.actionsoft.apps.coe.pal.datamigration.util.readtable.ReadTable;
|
||||
import com.actionsoft.apps.coe.pal.datamigration.web.DataMigrationWeb;
|
||||
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
|
||||
import com.actionsoft.bpms.server.UserContext;
|
||||
import com.actionsoft.bpms.server.bind.annotation.Controller;
|
||||
import com.actionsoft.bpms.server.bind.annotation.Mapping;
|
||||
@ -51,57 +49,18 @@ public class DataMigrationController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询aris流程导入日志
|
||||
* @param uc
|
||||
* @param logId
|
||||
* @param path
|
||||
* @param timer
|
||||
* @return
|
||||
*/
|
||||
@Mapping("com.actionsoft.apps.coe.pal.datamigration_data_migrate_log_query")
|
||||
public String queryArisXmlImportLog(UserContext uc, String logId, String path, String timer) {
|
||||
ArisXmlImportWeb web = new ArisXmlImportWeb(uc);
|
||||
return web.queryArisXmlImportLog(logId, path, timer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载日志
|
||||
* @param uc
|
||||
* @param logId
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
@Mapping("com.actionsoft.apps.coe.pal.datamigration_data_migrate_log_download")
|
||||
public String downloadArisXmlImportLog(UserContext uc, String logId, String path) {
|
||||
ArisXmlImportWeb web = new ArisXmlImportWeb(uc);
|
||||
return web.downloadArisXmlImportLog(logId, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* by bzp
|
||||
* 富文本保存 并解析
|
||||
*
|
||||
* by bzp 表单文件上传之后 解析文件
|
||||
* @param me
|
||||
* @param content
|
||||
* @param wsId
|
||||
* @param groupValue
|
||||
* @param fileValue
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
@Mapping("com.actionsoft.apps.coe.pal.saveRichtext")
|
||||
public String saveRichtext(UserContext me, String content, String pluuid, String shapId) {
|
||||
DataMigrationWeb web = new DataMigrationWeb(me);
|
||||
return web.saveRichText(me, content, pluuid, shapId).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* by bzp
|
||||
* 富文本加载时 获取内容
|
||||
* @param me
|
||||
* @param pluuid
|
||||
* @param shapId
|
||||
* @return
|
||||
*/
|
||||
@Mapping("com.actionsoft.apps.coe.pal.getRichtext")
|
||||
public String getRichtext(UserContext me, String pluuid, String shapId) {
|
||||
DataMigrationWeb web = new DataMigrationWeb(me);
|
||||
return web.getRichText(me, pluuid, shapId);
|
||||
@Mapping("com.actionsoft.apps.coe.pal.formImport_process_attribute_import")
|
||||
public String formattributeimport(UserContext me,String wsId,String groupValue,String fileValue,String fileName){
|
||||
new ReadTable().getTableInfo(me,wsId,groupValue,fileValue,fileName);
|
||||
ResponseObject ro = ResponseObject.newOkResponse();
|
||||
return ro.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,10 +16,7 @@ import org.jsoup.select.Elements;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,295 @@
|
||||
package com.actionsoft.apps.coe.pal.datamigration.util.readtable;
|
||||
|
||||
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.datamigration.util.ShapeUtil;
|
||||
import com.actionsoft.apps.coe.pal.datamigration.util.readword.ReadWordUtil;
|
||||
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.util.CoeDesignerUtil;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel;
|
||||
import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile;
|
||||
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.UUIDGener;
|
||||
import com.actionsoft.sdk.local.SDK;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aspose.words.Document;
|
||||
import com.aspose.words.SaveFormat;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.hwpf.HWPFDocument;
|
||||
import org.apache.poi.hwpf.usermodel.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author baizp
|
||||
* @Description:
|
||||
* @date 2022/6/30 21:47
|
||||
*/
|
||||
public class ReadTable {
|
||||
public static Map<String, WordAttribute> wordAttributeMap = new HashMap<>();
|
||||
public static Map<String, String> nameToIdMap = new HashMap<>();
|
||||
|
||||
//基础字段
|
||||
public Map<String, String> fieldMap = new HashMap<>();
|
||||
|
||||
//表格字段
|
||||
public Map<String, List<List<String>>> tableMap = new HashMap<>();
|
||||
|
||||
//文档字段
|
||||
public Map<String, List<String>> fileMap = new HashMap<>();
|
||||
|
||||
|
||||
public Map<String, WordField<Object>> fileFieldMap = new HashMap<>();
|
||||
|
||||
|
||||
static {
|
||||
List<WordAttribute> wordAttributes = JSON.parseArray(TableConstant.WORDIMPORT, WordAttribute.class);
|
||||
List<WordAttribute> nameToId = JSON.parseArray(TableConstant.NAMETOID, WordAttribute.class);
|
||||
wordAttributes.forEach(wordAttribute -> {
|
||||
wordAttributeMap.put(wordAttribute.getTitle(), wordAttribute);
|
||||
});
|
||||
nameToId.forEach(wordAttribute -> {
|
||||
nameToIdMap.put(wordAttribute.getTitle(), wordAttribute.getType());
|
||||
});
|
||||
}
|
||||
|
||||
public void getTableInfo(UserContext userContext, String wsId, String groupValue, String fileValue, String 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 = fileName.replace(".docx", ".doc");
|
||||
String docxname = fileName;
|
||||
|
||||
if (fileName.endsWith(".docx")) {
|
||||
docname = dcContextpdf.getFileName().replace(".docx", ".doc");
|
||||
docxname = dcContextpdf.getFileName();
|
||||
fileNewPath = fileNewPath.replace(".docx", ".doc");
|
||||
try {
|
||||
File out = new File(fileNewPath);
|
||||
FileOutputStream outputStream = new FileOutputStream(out);
|
||||
Document doc = new Document(filepath);
|
||||
doc.save(outputStream, SaveFormat.DOC);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
docxname = dcContextpdf.getFileName().replace(".doc", ".docx");
|
||||
docname = dcContextpdf.getFileName();
|
||||
fileNewPath = fileNewPath.replace(".doc", ".docx");
|
||||
try {
|
||||
File out = new File(fileNewPath);
|
||||
FileOutputStream outputStream = new FileOutputStream(out);
|
||||
Document doc = new Document(filepath);
|
||||
doc.save(outputStream, SaveFormat.DOCX);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
//解析文档附件
|
||||
PALRepositoryModel palRepositoryModel = ReadWordUtil.getRepositoryByName(wsId, docxname.replace(".docx", ""));
|
||||
if (palRepositoryModel == null) {
|
||||
return;
|
||||
}
|
||||
String id = palRepositoryModel.getId();
|
||||
|
||||
|
||||
//进行文件解析 写基本信息
|
||||
DCPluginProfile dcProfilepdfdoc = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", "migration");
|
||||
DCContext dcContextpdfdoc = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, docname);
|
||||
InputStream docfile = SDK.getDCAPI().read(dcContextpdfdoc);
|
||||
//画一个图形 并返回图形ID
|
||||
String shapId = createOneMap(wsId, docname.replace(".doc", ""), userContext, docfile);
|
||||
|
||||
//解析附件进行复制
|
||||
DCContext dcContextpdf1 = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, docxname);
|
||||
InputStream docxfile = SDK.getDCAPI().read(dcContextpdf1);
|
||||
try {
|
||||
new WordTableAttrFile().copyWord(userContext, shapId, docxfile, id, "评估表|评价表|表单$", "s");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public JSONObject writeAttrbute(UserContext userContext, InputStream file, String name, JSONObject shapeze) {
|
||||
boolean result = analysisWordTable(file);
|
||||
JSONArray attribute = shapeze.getJSONArray("dataAttributes").getJSONObject(0).getJSONArray("attributesJsonArray");
|
||||
if (result) {
|
||||
//根据名称获取PAL制度模型
|
||||
nameToIdMap.forEach((key, value) -> {
|
||||
//根据key去更新
|
||||
WordField tmpw = fileFieldMap.get(key);
|
||||
if (tmpw != null) {
|
||||
JSONObject tmp = new JSONObject();
|
||||
tmp.put("ref", "");
|
||||
tmp.put("icon", "../apps/com.actionsoft.apps.coe.pal/img/icon/shape_attribute.png");
|
||||
tmp.put("readonly", false);
|
||||
tmp.put("scope", "%,*");
|
||||
tmp.put("name", key);
|
||||
tmp.put("id", value);
|
||||
tmp.put("type", "string");
|
||||
tmp.put("value", tmpw.getData());
|
||||
tmp.put("groupPath", "baseAttribute");
|
||||
tmp.put("key", value);
|
||||
attribute.add(tmp);
|
||||
}
|
||||
});
|
||||
}
|
||||
return shapeze;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建表单图形
|
||||
*
|
||||
* @param plId
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public String createOneMap(String plId, String name, UserContext userContext, InputStream docfile) {
|
||||
PALRepositoryModel palRepositoryModel = ReadWordUtil.getRepositoryByName(plId, name);
|
||||
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");
|
||||
}
|
||||
//增加一个表单图形
|
||||
JSONObject shapeze = ShapeUtil.getProcessShapeDefinitionByName("data.form", "form");
|
||||
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);
|
||||
writeAttrbute(userContext, docfile, name, shapeze);
|
||||
elements.put(shapeIdz, shapeze);
|
||||
// 设置画布大小
|
||||
defineModel.setDefinition(definition.toString());
|
||||
// 保存文件
|
||||
CoeDesignerAPIManager.getInstance().storeDefinition(defineModel);// dao操作
|
||||
return shapeIdz;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分析表格数据
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public boolean analysisWordTable(InputStream file) {
|
||||
try {
|
||||
HWPFDocument doc = new HWPFDocument(file);
|
||||
//XWPFDocument doc = new XWPFDocument(file);
|
||||
Range range = doc.getRange();
|
||||
for (int i = 0; i < range.numParagraphs(); i++) {
|
||||
Paragraph nowPara = range.getParagraph(i);
|
||||
String text = nowPara.text();
|
||||
if (StringUtils.isEmpty(text)) {
|
||||
continue;
|
||||
}
|
||||
/*WordAttribute wordAttribute = wordAttributeMap.get(text.trim());
|
||||
if (null == wordAttribute) {
|
||||
continue;
|
||||
}*/
|
||||
//基本信息
|
||||
/*if (wordAttribute.getType().equals("DirectFeild")) {
|
||||
int index = i + 1 > range.numParagraphs() ? i : i + 1;
|
||||
Paragraph paragraph = range.getParagraph(index);
|
||||
if ("无".equals(paragraph.text())) {
|
||||
continue;
|
||||
}
|
||||
while (!paragraph.isInTable()) {
|
||||
i += 1;
|
||||
paragraph = range.getParagraph(i);
|
||||
if ("无".equals(paragraph.text())) {
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
//标题后续直接为table
|
||||
if (nowPara.isInTable()) {
|
||||
Table table = range.getTable(nowPara);
|
||||
Map<String, List<String>> tabelDocText = this.getHorizontalTableMapText(table);
|
||||
tabelDocText.keySet().forEach(key -> {
|
||||
List<String> strings = tabelDocText.get(key);
|
||||
if (!strings.isEmpty()) {
|
||||
fieldMap.put(key.replace(" ",""), strings.get(0));
|
||||
fileFieldMap.put(key.replace(" ",""), new WordField<>(strings.get(0)));
|
||||
}
|
||||
});
|
||||
i += table.numParagraphs();
|
||||
}
|
||||
// continue;
|
||||
//}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取基本信息
|
||||
*
|
||||
* @param tb
|
||||
* @return
|
||||
*/
|
||||
private Map<String, List<String>> getHorizontalTableMapText(Table tb) {
|
||||
Map<String, List<String>> result = new HashMap<>(16);
|
||||
//迭代行,默认从0开始,可以依据需要设置i的值,改变起始行数,也可设置读取到那行,只需修改循环的判断条件即可
|
||||
for (int i = 0; i < tb.numRows(); i++) {
|
||||
List<String> list = new ArrayList<>(16);
|
||||
int x = 0;
|
||||
TableRow tr = tb.getRow(i);
|
||||
String key = null;
|
||||
//迭代列,默认从0开始
|
||||
for (int j = 0; j < tr.numCells(); j++) {
|
||||
//取得单元格
|
||||
TableCell td = tr.getCell(j);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String text = td.text();
|
||||
|
||||
//取得单元格的内容
|
||||
for (int k = 0; k < td.numParagraphs(); k++) {
|
||||
Paragraph paragraph = td.getParagraph(k);
|
||||
String s = paragraph.text();
|
||||
//去除后面的特殊符号
|
||||
if (null != s && !"".equals(s)) {
|
||||
s = s.substring(0, s.length() - 1);
|
||||
}
|
||||
sb.append(s);
|
||||
}
|
||||
if (x == 0) {
|
||||
key = sb.toString();
|
||||
} else {
|
||||
String value = sb.toString();
|
||||
list.add(value == null || Objects.deepEquals(value, "") ? null : value.replace(",", ""));
|
||||
}
|
||||
x++;
|
||||
}
|
||||
result.put(key, list);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package com.actionsoft.apps.coe.pal.datamigration.util.readtable;
|
||||
|
||||
public class TableConstant {
|
||||
public final static String WORDIMPORT = "[{\"title\":\"基本信息\",\"type\":\"DirectFeild\"}]";
|
||||
//public final static String NAMETOID = "[{\"title\":\"目的\",\"type\":\"goal\"},{\"title\":\"拟制/修订人\",\"type\":\"reviser\"},{\"title\":\"拟制/修订日期\",\"type\":\"reviseddate\"},{\"title\":\"审核人\",\"type\":\"auditor\"},{\"title\":\"复核人\",\"type\":\"reviewer\"},{\"title\":\"审批人\",\"type\":\"approver\"},{\"title\":\"术语\",\"type\":\"term\"},{\"title\":\"术语定义\",\"type\":\"definition\"},{\"title\":\"组织/角色名称\",\"type\":\"Character\"},{\"title\":\"组织/角色职责\",\"type\":\"responsibilities\"},{\"title\":\"相关文件\",\"type\":\"relevant\"},{\"title\":\"支持文件\",\"type\":\"support\"},{\"title\":\"相关知识\",\"type\":\"related\"},{\"title\":\"附则\",\"type\":\"supplementary\"}]";
|
||||
public final static String NAMETOID = "[{\"title\":\"文件名称\",\"type\":\"Form_name\"},{\"title\":\"文件编码\",\"type\":\"form_number\"},{\"title\":\"版本\",\"type\":\"P_versions\"},{\"title\":\"生效日期\",\"type\":\"form_effective_date\"},{\"title\":\"适用范围\",\"type\":\"form_Scope_application\"}]";
|
||||
}
|
||||
@ -0,0 +1,325 @@
|
||||
package com.actionsoft.apps.coe.pal.datamigration.util.readtable;
|
||||
|
||||
/**
|
||||
* @author baizp
|
||||
* @Description:
|
||||
* @date 2022/6/21 17:21
|
||||
*/
|
||||
|
||||
import com.actionsoft.apps.coe.pal.datamigration.constant.CoEConstant;
|
||||
import com.actionsoft.apps.coe.pal.datamigration.util.readword.CustomXWPFDocument;
|
||||
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.server.UserContext;
|
||||
import com.actionsoft.bpms.server.fs.DCContext;
|
||||
import com.actionsoft.bpms.server.fs.dc.DCProfileManager;
|
||||
import com.actionsoft.bpms.util.UUIDGener;
|
||||
import com.actionsoft.sdk.local.SDK;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
||||
import org.apache.poi.poifs.filesystem.FileMagic;
|
||||
import org.apache.poi.xwpf.usermodel.*;
|
||||
import org.apache.xmlbeans.XmlException;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageMar;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageSz;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STPageOrientation.Enum;
|
||||
|
||||
import java.io.*;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class WordTableAttrFile {
|
||||
public static void main(String[] args) throws IOException, OpenXML4JException {
|
||||
new WordTableAttrFile().emedFileCopy();
|
||||
}
|
||||
|
||||
/**
|
||||
* 文档内附件复制
|
||||
* @param me
|
||||
* @param reid PAL模型id
|
||||
* @param inputStream 文档流
|
||||
* @param pluuid
|
||||
* @param mactchs 匹配规则
|
||||
* @param type 类型 f文件 s图形
|
||||
* @throws IOException
|
||||
* @throws XmlException
|
||||
* @throws OpenXML4JException
|
||||
*/
|
||||
public void copyWord(UserContext me, String reid, InputStream inputStream, String pluuid,String mactchs,String type) throws IOException, XmlException, OpenXML4JException {
|
||||
//XWPFDocument srcDoc = new XWPFDocument(new FileInputStream("/Users/jiuyabai/Desktop/yili项目/制度样例2—创新中心功效研究管理办法1.docx"));
|
||||
XWPFDocument srcDoc = new XWPFDocument(inputStream);
|
||||
//XWPFDocument srcDoc = new XWPFDocument(new FileInputStream("/Users/jiuyabai/Desktop/yili项目/测试附件.docx"));
|
||||
//XWPFDocument srcDoc = new XWPFDocument(new FileInputStream("/Users/jiuyabai/Desktop/yili项目/制度样例3-伊利集团关联方关系及关联交易管理规定.docx"));
|
||||
|
||||
CustomXWPFDocument destDoc = new CustomXWPFDocument();
|
||||
// Copy document layout.
|
||||
copyLayout(srcDoc, destDoc);
|
||||
ByteArrayOutputStream out = null;
|
||||
boolean isstart = false;
|
||||
boolean isend = false;
|
||||
int count = 1;
|
||||
String filename = "";
|
||||
List<IBodyElement> elementsList = srcDoc.getBodyElements();
|
||||
Pattern r = Pattern.compile(mactchs);
|
||||
for (int i =0;i<elementsList.size();i++) {
|
||||
IBodyElement bodyElement = elementsList.get(i);
|
||||
BodyElementType elementType = bodyElement.getElementType();
|
||||
System.out.println(elementType);
|
||||
if (elementType == BodyElementType.PARAGRAPH) {
|
||||
XWPFParagraph srcPr = (XWPFParagraph) bodyElement;
|
||||
String tmptext = srcPr.getParagraphText();
|
||||
if(tmptext.isEmpty()){
|
||||
continue;
|
||||
}
|
||||
Matcher m = r.matcher(tmptext);
|
||||
if (m.find()) {
|
||||
//判断是不是附件
|
||||
IBodyElement bodyElementtmp = elementsList.get(i+1);
|
||||
BodyElementType elementTypetmp = bodyElementtmp.getElementType();
|
||||
if(elementTypetmp == BodyElementType.PARAGRAPH){
|
||||
XWPFParagraph srcPrtmp = (XWPFParagraph) bodyElementtmp;
|
||||
String tmptexttmp = srcPrtmp.getParagraphText();
|
||||
if(!tmptexttmp.contains("服务订单编号")){
|
||||
continue;
|
||||
}
|
||||
}else {
|
||||
continue;
|
||||
}
|
||||
if (count != 1) {
|
||||
destDoc.write(out);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
writeFileTodisk(me, reid, filename, in, pluuid,type);
|
||||
out.close();
|
||||
}
|
||||
isstart = true;
|
||||
filename = "上传附件" + count + ".docx";
|
||||
out = new ByteArrayOutputStream();
|
||||
destDoc = new CustomXWPFDocument();
|
||||
copyLayout(srcDoc, destDoc);
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
if (!isstart) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (elementType == BodyElementType.PARAGRAPH) {
|
||||
/*int index = i > 0 ? i-1 : i;
|
||||
IBodyElement bodyElement1 = elementsList.get(index);*/
|
||||
|
||||
XWPFParagraph srcPr = (XWPFParagraph) bodyElement;
|
||||
|
||||
copyStyle(srcDoc, destDoc, srcDoc.getStyles().getStyle(srcPr.getStyleID()));
|
||||
|
||||
boolean hasImage = false;
|
||||
|
||||
XWPFParagraph dstPr = destDoc.createParagraph();
|
||||
|
||||
// Extract image from source docx file and insert into destination docx file.
|
||||
for (XWPFRun srcRun : srcPr.getRuns()) {
|
||||
|
||||
// You need next code when you want to call XWPFParagraph.removeRun().
|
||||
dstPr.createRun();
|
||||
|
||||
if (srcRun.getEmbeddedPictures().size() > 0)
|
||||
hasImage = true;
|
||||
|
||||
for (XWPFPicture pic : srcRun.getEmbeddedPictures()) {
|
||||
|
||||
byte[] img = pic.getPictureData().getData();
|
||||
|
||||
long cx = pic.getCTPicture().getSpPr().getXfrm().getExt().getCx();
|
||||
long cy = pic.getCTPicture().getSpPr().getXfrm().getExt().getCy();
|
||||
|
||||
try {
|
||||
// Working addPicture Code below...
|
||||
String blipId = dstPr.getDocument().addPictureData(new ByteArrayInputStream(img),
|
||||
Document.PICTURE_TYPE_PNG);
|
||||
destDoc.createPictureCxCy(blipId, destDoc.getNextPicNameNumber(Document.PICTURE_TYPE_PNG),
|
||||
cx, cy);
|
||||
|
||||
} catch (InvalidFormatException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasImage == false) {
|
||||
int pos = destDoc.getParagraphs().size() - 1;
|
||||
destDoc.setParagraph(srcPr, pos);
|
||||
}
|
||||
|
||||
} else if (elementType == BodyElementType.TABLE) {
|
||||
|
||||
XWPFTable table = (XWPFTable) bodyElement;
|
||||
|
||||
copyStyle(srcDoc, destDoc, srcDoc.getStyles().getStyle(table.getStyleID()));
|
||||
|
||||
destDoc.createTable();
|
||||
|
||||
int pos = destDoc.getTables().size() - 1;
|
||||
|
||||
destDoc.setTable(pos, table);
|
||||
}
|
||||
}
|
||||
if(count != 1){
|
||||
destDoc.write(out);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
writeFileTodisk(me, reid, filename, in, pluuid,type);
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param me
|
||||
* @param bindId
|
||||
* @param reid 制度图id
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public void writeFileTodisk(UserContext me, String reid, String filename, ByteArrayInputStream inputStream, String pl_uuid,String type) throws FileNotFoundException {
|
||||
//InputStream ins = new FileInputStream("");
|
||||
DCPluginProfile fileProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE);
|
||||
DCContext dcContextpdf = new DCContext(me, fileProfile, CoEConstant.APP_ID, pl_uuid, reid, filename);
|
||||
boolean isOK = false;
|
||||
//DataInputStream ds = new DataInputStream(ins);
|
||||
//isOK = WriteDCFile.getInstance().write(inputStream, dcContextpdf);
|
||||
SDK.getDCAPI().write(inputStream, dcContextpdf);
|
||||
//创建数据库数据
|
||||
UpfileModel model = new UpfileModel();
|
||||
model.setPl_uuid(pl_uuid);
|
||||
if("f".equals(type)){
|
||||
model.setShape_uuid("");
|
||||
model.setType("f");
|
||||
}else {
|
||||
model.setShape_uuid(reid);
|
||||
model.setType("s");
|
||||
}
|
||||
model.setUuid(UUIDGener.getUUID());
|
||||
model.setFileName(filename);
|
||||
model.setDownload(1);
|
||||
model.setCreateUser(me.getUID());
|
||||
model.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
||||
new UpFileDao().create(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文档外文件复制
|
||||
*/
|
||||
public void emedFileCopy() throws IOException, OpenXML4JException {
|
||||
FileInputStream file = new FileInputStream("/Users/jiuyabai/Desktop/yili项目/测试附件.docx");
|
||||
XWPFDocument srcDoc = new XWPFDocument(file);
|
||||
srcDoc.getAllEmbedds().stream().forEach(tmp -> {
|
||||
tmp.getPartName().getExtension();
|
||||
/*System.out.println(tmp.getPartName());
|
||||
System.out.println(tmp.getContentType());
|
||||
System.out.println(tmp.getContentTypeDetails().getSubType());
|
||||
System.out.println(tmp.getContentTypeDetails());*/
|
||||
try {
|
||||
InputStream inputStream = tmp.getInputStream();
|
||||
OutputStream outputStream = tmp.getOutputStream();
|
||||
System.out.println(FileMagic.valueOf(inputStream));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
/*InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = tmp.getInputStream();
|
||||
String filetype = tmp.getContentType();
|
||||
System.out.println("filetype"+filetype);
|
||||
|
||||
byte[] readbyte = new byte[1024];
|
||||
String name = tmp.getPartName().getName();
|
||||
int read = 0;
|
||||
OutputStream out1 = new FileOutputStream("/Users/jiuyabai/Desktop/yili项目/生成测试文件/文件插入附件.doc");;
|
||||
while ((read = inputStream.read(readbyte)) != -1){
|
||||
out1.write(readbyte,0,read);
|
||||
}
|
||||
*//*String xxx = bytesToHexString(readbyte);
|
||||
xxx = xxx.toUpperCase();
|
||||
System.out.println("头文件是:" + xxx);
|
||||
String ooo = checkType(xxx);*//*
|
||||
out1.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Copy Styles of Table and Paragraph.
|
||||
private static void copyStyle(XWPFDocument srcDoc, XWPFDocument destDoc, XWPFStyle style) {
|
||||
if (destDoc == null || style == null)
|
||||
return;
|
||||
|
||||
if (destDoc.getStyles() == null) {
|
||||
destDoc.createStyles();
|
||||
}
|
||||
|
||||
List<XWPFStyle> usedStyleList = srcDoc.getStyles().getUsedStyleList(style);
|
||||
for (XWPFStyle xwpfStyle : usedStyleList) {
|
||||
destDoc.getStyles().addStyle(xwpfStyle);
|
||||
}
|
||||
}
|
||||
|
||||
// Copy Page Layout.
|
||||
//
|
||||
// if next error message shows up, download "ooxml-schemas-1.1.jar" file and
|
||||
// add it to classpath.
|
||||
//
|
||||
// [Error]
|
||||
// The type org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageMar
|
||||
// cannot be resolved.
|
||||
// It is indirectly referenced from required .class files
|
||||
//
|
||||
// This error happens because there is no CTPageMar class in
|
||||
// poi-ooxml-schemas-3.10.1-20140818.jar.
|
||||
//
|
||||
// [ref.] http://poi.apache.org/faq.html#faq-N10025
|
||||
// [ref.] http://poi.apache.org/overview.html#components
|
||||
//
|
||||
// < ooxml-schemas 1.1 download >
|
||||
// http://repo.maven.apache.org/maven2/org/apache/poi/ooxml-schemas/1.1/
|
||||
//
|
||||
private static void copyLayout(XWPFDocument srcDoc, XWPFDocument destDoc) {
|
||||
CTPageMar pgMar = srcDoc.getDocument().getBody().getSectPr().getPgMar();
|
||||
|
||||
BigInteger bottom = pgMar.getBottom();
|
||||
BigInteger footer = pgMar.getFooter();
|
||||
BigInteger gutter = pgMar.getGutter();
|
||||
BigInteger header = pgMar.getHeader();
|
||||
BigInteger left = pgMar.getLeft();
|
||||
BigInteger right = pgMar.getRight();
|
||||
BigInteger top = pgMar.getTop();
|
||||
|
||||
CTPageMar addNewPgMar = destDoc.getDocument().getBody().addNewSectPr().addNewPgMar();
|
||||
|
||||
addNewPgMar.setBottom(bottom);
|
||||
addNewPgMar.setFooter(footer);
|
||||
addNewPgMar.setGutter(gutter);
|
||||
addNewPgMar.setHeader(header);
|
||||
addNewPgMar.setLeft(left);
|
||||
addNewPgMar.setRight(right);
|
||||
addNewPgMar.setTop(top);
|
||||
|
||||
CTPageSz pgSzSrc = srcDoc.getDocument().getBody().getSectPr().getPgSz();
|
||||
|
||||
BigInteger code = pgSzSrc.getCode();
|
||||
BigInteger h = pgSzSrc.getH();
|
||||
Enum orient = pgSzSrc.getOrient();
|
||||
BigInteger w = pgSzSrc.getW();
|
||||
|
||||
CTPageSz addNewPgSz = destDoc.getDocument().getBody().addNewSectPr().addNewPgSz();
|
||||
|
||||
addNewPgSz.setCode(code);
|
||||
addNewPgSz.setH(h);
|
||||
addNewPgSz.setOrient(orient);
|
||||
addNewPgSz.setW(w);
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,7 @@ package com.actionsoft.apps.coe.pal.datamigration.util.readword;
|
||||
* @Description:
|
||||
* @date 2022/6/21 17:21
|
||||
*/
|
||||
|
||||
import com.actionsoft.apps.coe.pal.constant.CoEConstant;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.upfile.constant.CoeFileConstant;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.upfile.dao.UpFileDao;
|
||||
@ -36,13 +37,17 @@ public class WordFinal {
|
||||
|
||||
/**
|
||||
* 文档内附件复制
|
||||
*
|
||||
* @param args
|
||||
* @param me
|
||||
* @param reid PAL模型id
|
||||
* @param inputStream 文档流
|
||||
* @param pluuid
|
||||
* @param mactchs 匹配规则
|
||||
* @param type 类型 f文件 s图形
|
||||
* @throws IOException
|
||||
* @throws XmlException
|
||||
* @throws OpenXML4JException
|
||||
*/
|
||||
public void copyWord(UserContext me, String reid, InputStream inputStream, String pluuid) throws IOException, XmlException, OpenXML4JException {
|
||||
public void copyWord(UserContext me, String reid, InputStream inputStream, String pluuid,String mactchs,String type) throws IOException, XmlException, OpenXML4JException {
|
||||
//XWPFDocument srcDoc = new XWPFDocument(new FileInputStream("/Users/jiuyabai/Desktop/yili项目/制度样例2—创新中心功效研究管理办法1.docx"));
|
||||
XWPFDocument srcDoc = new XWPFDocument(inputStream);
|
||||
//XWPFDocument srcDoc = new XWPFDocument(new FileInputStream("/Users/jiuyabai/Desktop/yili项目/测试附件.docx"));
|
||||
@ -63,12 +68,11 @@ public class WordFinal {
|
||||
if (elementType == BodyElementType.PARAGRAPH) {
|
||||
XWPFParagraph srcPr = (XWPFParagraph) bodyElement;
|
||||
String tmptext = srcPr.getParagraphText();
|
||||
if (tmptext.matches("附件\\d{1,}:")) {
|
||||
//if (tmptext.matches("附件:")) {
|
||||
if (tmptext.matches(mactchs)) {
|
||||
if (count != 1) {
|
||||
destDoc.write(out);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
writeFileTodisk(me, reid, filename, in, pluuid);
|
||||
writeFileTodisk(me, reid, filename, in, pluuid,type);
|
||||
out.close();
|
||||
}
|
||||
isstart = true;
|
||||
@ -146,7 +150,7 @@ public class WordFinal {
|
||||
if(count != 1){
|
||||
destDoc.write(out);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
writeFileTodisk(me, reid, filename, in, pluuid);
|
||||
writeFileTodisk(me, reid, filename, in, pluuid,type);
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
@ -157,7 +161,7 @@ public class WordFinal {
|
||||
* @param reid 制度图id
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public void writeFileTodisk(UserContext me, String reid, String filename, ByteArrayInputStream inputStream, String pl_uuid) throws FileNotFoundException {
|
||||
public void writeFileTodisk(UserContext me, String reid, String filename, ByteArrayInputStream inputStream, String pl_uuid,String type) throws FileNotFoundException {
|
||||
//InputStream ins = new FileInputStream("");
|
||||
DCPluginProfile fileProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE);
|
||||
DCContext dcContextpdf = new DCContext(me, fileProfile, CoEConstant.APP_ID, "file", reid, filename);
|
||||
@ -167,8 +171,13 @@ public class WordFinal {
|
||||
SDK.getDCAPI().write(inputStream, dcContextpdf);
|
||||
//创建数据库数据
|
||||
UpfileModel model = new UpfileModel();
|
||||
model.setShape_uuid("");
|
||||
model.setType("f");
|
||||
if("f".equals(type)){
|
||||
model.setShape_uuid("");
|
||||
model.setType("f");
|
||||
}else {
|
||||
model.setShape_uuid(reid);
|
||||
model.setType("s");
|
||||
}
|
||||
model.setUuid(UUIDGener.getUUID());
|
||||
model.setPl_uuid(reid);
|
||||
model.setFileName(filename);
|
||||
|
||||
@ -25,13 +25,11 @@
|
||||
<param name="fileValue"/>
|
||||
<param name="fileName"/>
|
||||
</cmd-bean>
|
||||
<cmd-bean name="com.actionsoft.apps.coe.pal.datamigration_data_migrate_log_query">
|
||||
<param name="logId"/>
|
||||
<param name="path"/>
|
||||
<param name="timer"/>
|
||||
</cmd-bean>
|
||||
<cmd-bean name="com.actionsoft.apps.coe.pal.datamigration_data_migrate_log_download">
|
||||
<param name="logId"/>
|
||||
<param name="path"/>
|
||||
<!--by bzp-->
|
||||
<cmd-bean name="com.actionsoft.apps.coe.pal.formImport_process_attribute_import">
|
||||
<param name="wsId"/>
|
||||
<param name="groupValue"/>
|
||||
<param name="fileValue"/>
|
||||
<param name="fileName"/>
|
||||
</cmd-bean>
|
||||
</aws-actions>
|
||||
@ -8362,7 +8362,6 @@ public class CoeProcessLevelWeb extends ActionWeb {
|
||||
return ro.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断文件属性、数据属性校验
|
||||
* @param sid
|
||||
@ -9314,6 +9313,7 @@ public class CoeProcessLevelWeb extends ActionWeb {
|
||||
|
||||
return ro.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* by bzp
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user