diff --git a/com.actionsoft.apps.coe.pal.datamigration/lib/10976337_3.jar b/com.actionsoft.apps.coe.pal.datamigration/lib/10976337_3.jar new file mode 100644 index 00000000..119e1fd3 Binary files /dev/null and b/com.actionsoft.apps.coe.pal.datamigration/lib/10976337_3.jar differ diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/DataMigrationController.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/DataMigrationController.java index 99b50486..cc84e98a 100644 --- a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/DataMigrationController.java +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/DataMigrationController.java @@ -22,4 +22,19 @@ public class DataMigrationController { public String ITAttributeImport(UserContext uc, String wsId,String groupValue,String fileValue,String fileName){ return new DataMigrationWeb(uc).ITAttributeImport(wsId,groupValue,fileValue,fileName); } + /** + * by bzp 制度文件上传之后 解析文件 + * @param me + * @param wsId + * @param groupValue + * @param fileValue + * @param fileName + * @return + */ + @Mapping("com.actionsoft.apps.coe.pal.systemImport_process_attribute_import") + public String processattributeimport(UserContext me,String wsId,String groupValue,String fileValue,String fileName){ + new ReadWordUtil().translateDocTDocx(me,wsId,groupValue,fileValue,fileName); + ResponseObject ro = ResponseObject.newOkResponse(); + return ro.toString(); + } } diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/Constant.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/Constant.java new file mode 100644 index 00000000..11542d5e --- /dev/null +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/Constant.java @@ -0,0 +1,16 @@ +package com.actionsoft.apps.coe.pal.datamigration.util.readword; + +public class Constant { + + public final static String APP_ID = "com.actionsoft.apps.coe.pal.datamigration"; + public final static String UPFILE = "migration"; + public final static String WORDIMPORT = "[{\"title\":\"文控信息\",\"type\":\"DirectFeild\"},{\"title\":\"修订记录\",\"type\":\"VerticalFeild\"},{\"title\":\"术语\",\"type\":\"Table\"},{\"title\":\"组织/角色与职责\",\"type\":\"Table\"},{\"title\":\"相关文件\",\"type\":\"File\"},{\"title\":\"支持文件\",\"type\":\"File\"}]"; + //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\":\"Purpose\"},{\"title\":\"拟制/修订人\",\"type\":\"Drafted_and_revised_by\"},{\"title\":\"拟制/修订日期\",\"type\":\"Drafted_and_revised_date\"},{\"title\":\"审核人\",\"type\":\"auditor\"},{\"title\":\"复核人\",\"type\":\"reviewer\"},{\"title\":\"审批人\",\"type\":\"approver\"},{\"title\":\"术语\",\"type\":\"term\"},{\"title\":\"组织/角色名称\",\"type\":\"Organization_role_name\"},{\"title\":\"组织/角色职责\",\"type\":\"Organization_and_role_responsibilities\"},{\"title\":\"相关文件\",\"type\":\"relevant_flies\"},{\"title\":\"支持文件\",\"type\":\"support_files\"},{\"title\":\"相关知识\",\"type\":\"relevant_flies\"},{\"title\":\"附则\",\"type\":\"T_supplementary_articles\"}]"; + + // 构造连线时的几个固定参数 + public final static double ANGLE_RIGHT = 0; + public final static double ANGLE_DOWN = 1.5707963267948968; + public final static double ANGLE_LEFT = 3.141592653589793; + public final static double ANGLE_UP = 4.71238898038469; +} \ No newline at end of file diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/CreateMaps.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/CreateMaps.java new file mode 100644 index 00000000..4e1948c5 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/CreateMaps.java @@ -0,0 +1,301 @@ +package com.actionsoft.apps.coe.pal.datamigration.util.readword; + +import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache; +import com.actionsoft.apps.coe.pal.pal.repository.dao.CoeProcessLevelDaoFacotory; +import com.actionsoft.apps.coe.pal.pal.repository.dao.PALRepository; +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.coe.pal.pal.repository.model.impl.PALRepositoryModelImpl; +import com.actionsoft.apps.coe.pal.pal.repository.util.CoeProcessLevelUtil; +import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile; +import com.actionsoft.bpms.commons.database.RowMap; +import com.actionsoft.bpms.schedule.IJob; +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.DBSql; +import com.actionsoft.bpms.util.UUIDGener; +import com.actionsoft.sdk.local.SDK; +import com.alibaba.fastjson.JSONObject; +import lombok.SneakyThrows; +import org.apache.commons.lang.StringUtils; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +import java.io.InputStream; +import java.sql.Timestamp; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +public class CreateMaps implements IJob { + + + /** + * 定时从 + * + * @param jobExecutionContext + * @throws JobExecutionException + */ + @SneakyThrows + @Override + public void execute(JobExecutionContext jobExecutionContext) { + + /*Map idRelationMap = new HashMap<>(); + //先执行新建操作产生plid + PALRepository coeProcessLevel = CoeProcessLevelDaoFacotory.createCoeProcessLevel(); + + + String plRid = UUIDGener.getUUID(); + String id = UUIDGener.getUUID(); + + String parentId = "org"; + String parentVersionId = ""; + int level = 1; + if (parentId.length() < 36) {// 父节点是大类 + parentVersionId = parentId; + } else { + PALRepositoryModel parentModel = PALRepositoryCache.getCache().get(parentId); + parentVersionId = parentModel.getVersionId(); + level = parentModel.getLevel() + 1; + } + + Timestamp nowTime = new Timestamp(System.currentTimeMillis()); + PALRepositoryModelImpl model = CoeProcessLevelUtil.createPALRepositoryModel(id, plRid, "f71ba89d-a594-4144-b89b-25324d67f310", "伊利集团", + "", 1, "control", "control", true, 1, + id, false, "control.policy", "0", 1, null, + null, "admin", "admin", nowTime, null, null, + null, null, null, null, null, null, null, 1); + + System.out.println(model.getId()); + coeProcessLevel.insert(model); + + + BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(model.getId(), 0); + if (defineModel == null) { + defineModel = CoeDesignerUtil.createModel(model.getId(), 0); + defineModel.setCreateHistory(false); + } + String define = defineModel.getDefinition(); + JSONObject definition = JSONObject.parseObject(define); + JSONObject elements = definition.getJSONObject("elements"); + + //新建一个uuid + String shapeId = UUIDGener.getObjectId(); + + //拿到基础结构 + //JSONObject shape = ShapeUtil.getProcessShapeDefinitionByName("org.normal", "position"); + + if (StringUtils.isNotEmpty(definition.getString("commonShapeConfig"))) { + definition.remove("commonShapeConfig"); + } + + List orgdepartmentList = DBSql.getMaps("select * from ORGUSER "); + + int zindex = 1; +*//* + if(orgdepartmentList.size()>0){ + + for(int i=0;i idRelationMap = new HashMap<>(); + //先执行新建操作产生plid + PALRepository coeProcessLevel = CoeProcessLevelDaoFacotory.createCoeProcessLevel(); + + String parentId = "org"; + String parentVersionId = ""; + int level = 1; + if (parentId.length() < 36) {// 父节点是大类 + parentVersionId = parentId; + } else { + PALRepositoryModel parentModel = PALRepositoryCache.getCache().get(parentId); + parentVersionId = parentModel.getVersionId(); + level = parentModel.getLevel() + 1; + } + + Timestamp nowTime = new Timestamp(System.currentTimeMillis()); + PALRepositoryModelImpl model = CoeProcessLevelUtil.createPALRepositoryModel(id, plRid, "f71ba89d-a594-4144-b89b-25324d67f310", name, + "", 1, "control", "control", true, 1, + id, false, "control.policy", "0", 1, null, + null, "admin", "admin", nowTime, null, null, + null, null, null, null, null, null, null, 1); + + System.out.println(model.getId()); + coeProcessLevel.insert(model); + + + BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(model.getId(), 0); + if (defineModel == null) { + defineModel = CoeDesignerUtil.createModel(model.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"); + } + + List orgdepartmentList = DBSql.getMaps("select * from ORGUSER "); + + int zindex = 1; + elements = new WordUtilXWPF().rewritContent(elements, inputStream, "制度名称"); + + // 设置画布大小 + setDiagramHeightWidth(definition, elements); + defineModel.setDefinition(definition.toString()); + // 保存文件 + CoeDesignerAPIManager.getInstance().storeDefinition(defineModel);// dao操作 + } + + public void updateMaps(String id, InputStream file, String name) { + PALRepositoryModel palRepositoryModel = ReadWordUtil.getRepositoryByName(id, 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"); + } + + List orgdepartmentList = DBSql.getMaps("select * from ORGUSER "); + + int zindex = 1; + elements = new WordUtilXWPF().rewritContent(elements, file, name); + + // 设置画布大小 + setDiagramHeightWidth(definition, elements); + defineModel.setDefinition(definition.toString()); + // 保存文件 + CoeDesignerAPIManager.getInstance().storeDefinition(defineModel);// dao操作 + } + + + /** + * 设置画布大小 + * + * @param elements + */ + private void setDiagramHeightWidth(JSONObject definition, JSONObject elements) { + // 获取最大宽高,给100长度富余 + JSONObject maxHW = getMaxPositionXY(elements); + int maxX = maxHW.getInteger("maxX") + 400; + int maxH = maxHW.getInteger("maxY") + 150; + JSONObject page = definition.getJSONObject("page"); + int pageW = page.getInteger("width"); + int pageH = page.getInteger("height"); + page.put("width", pageW > maxX ? pageW : maxX); + page.put("height", pageH > maxH ? pageH : maxH); + definition.put("page", page); + } + + + private JSONObject getMaxPositionXY(JSONObject elements) { + int maxX = -99999; + int maxY = -99999; + Iterator it = elements.keySet().iterator(); + while (it.hasNext()) { + String key = it.next(); + JSONObject shape = elements.getJSONObject(key); + String shapeName = shape.getString("name"); + if (!"linker".equals(shapeName)) { + JSONObject props = shape.getJSONObject("props"); + if (props == null || props.get("x") == null) { + continue; + } + int x = props.getInteger("x"); + int y = props.getInteger("y"); + maxX = maxX < x ? x : maxX; + maxY = maxY < y ? y : maxY; + } + } + JSONObject result = new JSONObject(); + result.put("maxX", maxX); + result.put("maxY", maxY); + return result; + } + + +} diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/ReadDocxTable.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/ReadDocxTable.java new file mode 100644 index 00000000..1bd4dff7 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/ReadDocxTable.java @@ -0,0 +1,241 @@ +package com.actionsoft.apps.coe.pal.datamigration.util.readword; + +import com.actionsoft.apps.coe.pal.datamigration.model.po.WordAttribute; +import com.actionsoft.apps.coe.pal.datamigration.model.po.WordField; +import com.alibaba.fastjson.JSON; +import org.apache.poi.xwpf.usermodel.*; + +import java.io.*; +import java.util.*; + +/** + * @author baizp + * @Description: + * @date 2022/6/30 16:00 + */ +public class ReadDocxTable { + + //相关文件、存文件名称 + private String version = ""; + + private String fileName = ""; + public static Map wordAttributeMap = new HashMap<>(); + public static Map nameToIdMap = new HashMap<>(); + public Map fieldMap = new HashMap<>(); + + //表格字段 + public Map>> tableMap = new HashMap<>(); + + //文档字段 + public Map> fileMap = new HashMap<>(); + + + public Map> fileFieldMap = new HashMap<>(); + static { + List wordAttributes = JSON.parseArray(Constant.WORDIMPORT, WordAttribute.class); + List nameToId = JSON.parseArray(Constant.NAMETOID, WordAttribute.class); + wordAttributes.forEach(wordAttribute -> { + wordAttributeMap.put(wordAttribute.getTitle(), wordAttribute); + }); + nameToId.forEach(wordAttribute -> { + nameToIdMap.put(wordAttribute.getTitle(), wordAttribute.getType()); + }); + } + + public static void main(String[] args) throws IOException { + InputStream docfile = new FileInputStream(new File("/Users/jiuyabai/Desktop/yili项目/制度样例1—伊利集团流程制度类文件管理规范(2).docx")); + new ReadDocxTable().analysisDocxTable(docfile); + } + public boolean analysisDocxTable(InputStream file) throws IOException { + XWPFDocument doc = new XWPFDocument(file); + Iterator iter = doc.getBodyElementsIterator(); + List listIbody = doc.getBodyElements(); + String lastStr = ""; + for(int i=0;i < listIbody.size();i++){ + IBodyElement element = listIbody.get(i); + if (element instanceof XWPFParagraph) { + XWPFParagraph paragraph = (XWPFParagraph) element; + String text = paragraph.getText(); + if(!text.isEmpty()){ + lastStr = paragraph.getParagraphText(); + } + if("目的".equals(text.trim())){ + int index = i + 1 > listIbody.size() ? i : i + 1; + XWPFParagraph paragraph1 = (XWPFParagraph)listIbody.get(index); + fieldMap.put("目的", paragraph1.getParagraphText()); + fileFieldMap.put("目的", new WordField<>(paragraph1.getParagraphText())); + continue; + } + if ("附则".equals(text.trim())) { + int index = i + 1 > listIbody.size() ? i : i + 1; + XWPFParagraph paragraph1 = (XWPFParagraph)listIbody.get(index); + fieldMap.put("目的", paragraph1.getParagraphText()); + fileFieldMap.put("目的", new WordField<>(paragraph1.getParagraphText())); + continue; + } + continue; + } + if(element instanceof XWPFTable){ + XWPFTable nowtable = (XWPFTable) element; + WordAttribute wordAttribute = wordAttributeMap.get(lastStr.trim()); + if(wordAttribute == null){ + continue; + } + if (wordAttribute.getType().equals("DirectFeild")) { + Map tabelDocText = this.getHorizontalTableMapText(nowtable,nameToIdMap); + //在基本信息中特殊获取文件名称和版本号 + if (lastStr.trim().equals("文控信息")) { + tabelDocText.keySet().forEach(key -> { + if (key.replaceAll(" ", "").equals("版本")) { + String strings = tabelDocText.get(key); + if (!strings.isEmpty()) { + version = strings; + } + } + /* if (key.equals("文件名称")) { + List strings = tabelDocText.get(key); + if (!strings.isEmpty()) { + fileName = strings.get(0); + } + }*/ + }); + } + + tabelDocText.keySet().forEach(key -> { + String strings = tabelDocText.get(key); + if (!strings.isEmpty()) { + fieldMap.put(key, strings); + fileFieldMap.put(key, new WordField<>(strings)); + } + }); + continue; + } + + //修订信息 + if (wordAttribute.getType().equals("VerticalFeild")) { + Map> verticalTableText = this.getVerticalTableText(nowtable,nameToIdMap); + if (lastStr.trim().equals("修订记录")) { + List strings = verticalTableText.get("版本"); + int subIndex = 0; + for (int j = 0; j < strings.size(); j++) { + String s = strings.get(j); + if (s.equals(version)) { + subIndex = j; + } + } + for (String key : verticalTableText.keySet()) { + List values = verticalTableText.get(key); + fieldMap.put(key, values.get(subIndex)); + fileFieldMap.put(key, new WordField<>(values.get(subIndex))); + } + } else { + + } + continue; + } + //术语 + if (wordAttribute.getType().equals("Table")) { + List> horizontalTableText = this.getHorizontalTableText(nowtable,nameToIdMap); + tableMap.put(wordAttribute.getTitle(), horizontalTableText); + fileFieldMap.put(wordAttribute.getTitle(), new WordField<>(horizontalTableText)); + continue; + } + //支持文件 相关文件 + if (wordAttribute.getType().equals("File")) { + if ("相关文件,支持文件".contains(lastStr.trim())) { + //取文件名名称即可 + Map> verticalTableText = this.getVerticalTableText(nowtable,nameToIdMap); + List strings = verticalTableText.get("文件"); + fileMap.put(wordAttribute.getTitle(), strings); + fileFieldMap.put(wordAttribute.getTitle(), new WordField<>(strings)); + } + continue; + } + + } + } + return true; + } + + /** + * 横着key:value + * @param xwpfTable + * @param nameToid + * @return + */ + private Map getHorizontalTableMapText(XWPFTable xwpfTable,Map nameToid) { + Map result = new HashMap<>(16); + for(XWPFTableRow xwpfTableRow : xwpfTable.getRows()){ + List tableCells = xwpfTableRow.getTableCells(); + int cllnum = tableCells.size(); + //单元格 + for(int i =0 ;i<=cllnum;i++){ + XWPFTableCell xwpfTableCell = tableCells.get(i); + String text = xwpfTableCell.getText(); + if(nameToid.containsKey(text)){ + if(i+1 < cllnum){ + XWPFTableCell xwpfTableCell1 = tableCells.get(i+1); + String text1 = xwpfTableCell.getText(); + result.put(text,text1); + } + } + } + } + return result; + } + + /** + *处理术语 + * @param table + * @return + */ + private List> getHorizontalTableText(XWPFTable xwpfTable,Map nameToid) { + List> list = new ArrayList<>(); + for(XWPFTableRow xwpfTableRow : xwpfTable.getRows()){ + List tableCells = xwpfTableRow.getTableCells(); + List rowList = new ArrayList<>(); + int cllnum = tableCells.size(); + //单元格 + for(int i =0 ;i<=cllnum;i++){ + XWPFTableCell xwpfTableCell = tableCells.get(i); + String text = xwpfTableCell.getText(); + //去除text特殊符号 + if (null != text && !"".equals(text)) { + text = text.replaceAll("\\p{C}", ""); + } + rowList.add(text); + } + list.add(rowList); + } + return list; + } + + /** + * 处理修订记录 + * @param xwpfTable + * @param nameToid + * @return + */ + private Map> getVerticalTableText(XWPFTable xwpfTable,Map nameToid) { + Map> result = new HashMap<>(); + List stringList = new ArrayList<>(); + for(XWPFTableRow xwpfTableRow : xwpfTable.getRows()) { + List tableCells = xwpfTableRow.getTableCells(); + List rowList = new ArrayList<>(); + int cllnum = tableCells.size(); + //单元格 + for (int i = 0; i <= cllnum; i++) { + XWPFTableCell xwpfTableCell = tableCells.get(i); + String text = xwpfTableCell.getText(); + if (i == 0) { + //首行为标题行 + result.put(text, new ArrayList<>()); + stringList.add(text); + } else { + result.get(stringList.get(i)).add(text); + } + } + } + return result; + } +} diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/ReadWordUtil.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/ReadWordUtil.java new file mode 100644 index 00000000..62720b0e --- /dev/null +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/ReadWordUtil.java @@ -0,0 +1,454 @@ +package com.actionsoft.apps.coe.pal.datamigration.util.readword; + +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.model.PALRepositoryModel; +import com.actionsoft.apps.coe.pal.pal.repository.web.CoeProcessLevelWeb; +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.DBSql; +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.*; +import java.util.*; +import java.util.stream.Collectors; + +public class ReadWordUtil { + //相关文件、存文件名称 + private String version = ""; + + private String fileName = ""; + + public static Map wordAttributeMap = new HashMap<>(); + public static Map nameToIdMap = new HashMap<>(); + + //基础字段 + public Map fieldMap = new HashMap<>(); + + //表格字段 + public Map>> tableMap = new HashMap<>(); + + //文档字段 + public Map> fileMap = new HashMap<>(); + + + public Map> fileFieldMap = new HashMap<>(); + + + static { + List wordAttributes = JSON.parseArray(Constant.WORDIMPORT, WordAttribute.class); + List nameToId = JSON.parseArray(Constant.NAMETOID, WordAttribute.class); + wordAttributes.forEach(wordAttribute -> { + wordAttributeMap.put(wordAttribute.getTitle(), wordAttribute); + }); + nameToId.forEach(wordAttribute -> { + nameToIdMap.put(wordAttribute.getTitle(), wordAttribute.getType()); + }); + } + + public static void main(String[] args) throws FileNotFoundException { + String id = "b8f71f46-a8fa-4add-9bc0-5713b028ea5f"; + String name = "制度样例1—伊利集团流程制度类文件管理规范(2)"; + InputStream docfile = new FileInputStream(new File("/Users/jiuyabai/Desktop/yili项目/制度样例1—伊利集团流程制度类文件管理规范(2).doc")); + ReadWordUtil tmp = new ReadWordUtil(); + boolean result = tmp.analysisWordTable(docfile); + tmp.writeAttrbute(null,docfile, name, id); + + InputStream docxfile = new FileInputStream(new File("/Users/jiuyabai/Desktop/yili项目/制度样例1—伊利集团流程制度类文件管理规范(2).docx")); + new CreateMaps().updateMaps(id, docxfile, name); + System.out.println(result); + } + + public ReadWordUtil() { + } + + public void writeAttrbute(UserContext userContext,InputStream file, String name, String wsdl) { + boolean result = analysisWordTable(file); + if (result) { + //根据名称获取PAL制度模型 + PALRepositoryModel palRepositoryModel = getRepositoryByName(wsdl, name); + if (palRepositoryModel != null) { + String id = palRepositoryModel.getId(); + String sql = "update APP_ACT_COE_PAL_PROP set PROPERTYVALUE='%s' where PROPERTYID='%s' AND PLID='%s'"; + nameToIdMap.forEach((key, value) -> { + //根据key去更新 + WordField tmp = fileFieldMap.get(key); + if (tmp != null) { + //如果是术语~则特殊处理 还有相关文件 + if ("术语".equals(key)) { + List nowdata = (List) tmp.getData(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name","术语"); + JSONArray jsonArray = new JSONArray(); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("name","名称"); + jsonObject1.put("id", "table_head"); + jsonObject1.put("desc","定义"); + jsonArray.add(jsonObject1); + //存表格 将名称过滤掉 + nowdata.stream().filter(datatmp->{ + return !"名称".equals(((List)datatmp).get(0)); + }).forEach(datatmp->{ + JSONObject tmpjb = new JSONObject(); + tmpjb.put("name",((List)datatmp).get(0)); + tmpjb.put("id", UUIDGener.getUUID()); + tmpjb.put("desc",((List)datatmp).get(1)); + //{"name":"术语","table":[{"name":"名称","id":"table_head","desc":"定义"},{"name":"流程责任人","id":"c0723266-bff1-410c-b49e-4332e58cc633","desc":"流程责任人是指对流程全生命周期管理负责的人,流程责任人拥有流程全生命周期管理的权力,同时承担相应的职责,是流程绩效的第一负责人。"},{"name":"业务归属","id":"2e3bbc32-1d3d-4f19-8b2e-75302bf2aed4","desc":"是指流程制度文件所属的流程架构位置以及文件适用范围。"}]} + jsonArray.add(tmpjb); + }); + jsonObject.put("table",jsonArray); + new CoeProcessLevelWeb(userContext).moreAttrContentSave(id,"term",jsonObject.toJSONString()); + } else if ("支持文件".equals(key) || "相关文件".equals(key)) { + //拼文件 + List nowdata = (List) tmp.getData(); + String alldata = nowdata.stream().collect(Collectors.joining(",")).toString(); + String sql1 = String.format(sql, alldata, value, id); + System.out.println("执行的sql有:" + sql1); + DBSql.update(sql1); + } else { + String sql1 = String.format(sql, tmp.getData().toString(), value, id); + System.out.println("执行的sql有:" + sql1); + DBSql.update(sql1); + } + } + }); + } + } + } + + public void translateDocTDocx(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(); + } + } + //进行文件解析 + 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); + ReadWordUtil tmp = new ReadWordUtil(); + tmp.writeAttrbute(userContext,docfile, docname.replace(".doc",""), wsId); + + DCContext dcContextpdf1 = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, docxname); + InputStream docxfile = SDK.getDCAPI().read(dcContextpdf1); + new CreateMaps().updateMaps(wsId, docxfile, docxname.replace(".docx","")); + + } + + + 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 ("目的".equals(text.trim())) { + int index = i + 1 > range.numParagraphs() ? i : i + 1; + Paragraph tmpPara = range.getParagraph(index); + fieldMap.put("目的", tmpPara.text()); + fileFieldMap.put("目的", new WordField<>(tmpPara.text())); + continue; + } + if ("附则".equals(text.trim())) { + int index = i + 1 > range.numParagraphs() ? i : i + 1; + Paragraph tmpPara = range.getParagraph(index); + fieldMap.put("附则", tmpPara.text()); + fileFieldMap.put("附则", new WordField<>(tmpPara.text())); + continue; + } + 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 (paragraph.isInTable()) { + Table table = range.getTable(paragraph); + Map> tabelDocText = this.getHorizontalTableMapText(table); + + //在基本信息中特殊获取文件名称和版本号 + if (text.trim().equals("文控信息")) { + tabelDocText.keySet().forEach(key -> { + if (key.replaceAll(" ", "").equals("版本")) { + List strings = tabelDocText.get(key); + if (!strings.isEmpty()) { + version = strings.get(0); + } + } + if (key.equals("文件名称")) { + List strings = tabelDocText.get(key); + if (!strings.isEmpty()) { + fileName = strings.get(0); + } + } + }); + } + + tabelDocText.keySet().forEach(key -> { + List strings = tabelDocText.get(key); + if (!strings.isEmpty()) { + fieldMap.put(key, strings.get(0)); + fileFieldMap.put(key, new WordField<>(strings.get(0))); + } + }); + i += table.numParagraphs(); + } + continue; + } + //修订信息 + if (wordAttribute.getType().equals("VerticalFeild")) { + int index = i + 1 > range.numParagraphs() ? i : i + 1; + Paragraph paragraph = range.getParagraph(index); + int level = paragraph.getIlvl(); + if (paragraph.isInTable()) { + Table table = range.getTable(paragraph); + Map> verticalTableText = this.getVerticalTableText(table); + + if (text.trim().equals("修订记录")) { + List strings = verticalTableText.get("版本"); + int subIndex = 0; + for (int j = 0; j < strings.size(); j++) { + String s = strings.get(j); + if (s.equals(version)) { + subIndex = j; + } + } + for (String key : verticalTableText.keySet()) { + List values = verticalTableText.get(key); + fieldMap.put(key, values.get(subIndex)); + fileFieldMap.put(key, new WordField<>(values.get(subIndex))); + } + } else { + + } + i += table.numParagraphs(); + } + continue; + } + //术语 + if (wordAttribute.getType().equals("Table")) { + int index = i + 1 > range.numParagraphs() ? i : i + 1; + Paragraph paragraph = range.getParagraph(index); + if (paragraph.isInTable()) { + Table table = range.getTable(paragraph); + List> horizontalTableText = this.getHorizontalTableText(table); + tableMap.put(wordAttribute.getTitle(), horizontalTableText); + fileFieldMap.put(wordAttribute.getTitle(), new WordField<>(horizontalTableText)); + i += table.numParagraphs(); + } + continue; + } + //支持文件 相关文件 + if (wordAttribute.getType().equals("File")) { + int index = i + 1 > range.numParagraphs() ? i : i + 1; + Paragraph paragraph = range.getParagraph(index); + if (paragraph.isInTable()) { + if ("相关文件,支持文件".contains(text.trim())) { + //取文件名名称即可 + Table table = range.getTable(paragraph); + Map> verticalTableText = this.getVerticalTableText(table); + List strings = verticalTableText.get("文件"); + fileMap.put(wordAttribute.getTitle(), strings); + fileFieldMap.put(wordAttribute.getTitle(), new WordField<>(strings)); + i += table.numParagraphs(); + } + } + continue; + } + } + } catch (IOException e) { + e.printStackTrace(); + return false; + } + + return true; + } + + + private Map> getHorizontalTableMapText(Table tb) { + Map> result = new HashMap<>(16); + //迭代行,默认从0开始,可以依据需要设置i的值,改变起始行数,也可设置读取到那行,只需修改循环的判断条件即可 + for (int i = 0; i < tb.numRows(); i++) { + List 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; + } + + private List> getHorizontalTableText(Table table) { + List> list = new ArrayList<>(); + + for (int i = 0; i < table.numRows(); i++) { + List rowList = new ArrayList<>(); + + TableRow row = table.getRow(i); + for (int j = 0; j < row.numCells(); j++) { + TableCell cell = row.getCell(j); + String text = cell.text(); + //去除text特殊符号 + if (null != text && !"".equals(text)) { + text = text.replaceAll("\\p{C}", ""); + } + rowList.add(text); + } + + list.add(rowList); + } + + return list; + } + + private Map> getVerticalTableText(Table table) { + Map> result = new HashMap<>(); + + List stringList = new ArrayList<>(); + for (int i = 0; i < table.numRows(); i++) { + TableRow row = table.getRow(i); + for (int j = 0; j < row.numCells(); j++) { + TableCell cell = row.getCell(j); + String text = cell.text(); + //去除text特殊符号 + if (null != text && !"".equals(text)) { + text = text.replaceAll("\\p{C}", ""); + } + + if (i == 0) { + //首行为标题行 + result.put(text, new ArrayList<>()); + stringList.add(text); + } else { + result.get(stringList.get(j)).add(text); + } + } + } + + return result; + } + + /** + * 根据名字寻找palmode + * + * @param wsId + * @param repositoryName + * @return + */ + public static PALRepositoryModel getRepositoryByName(String wsId, String repositoryName) { + List palRepositoryModels = CoeProcessLevelDaoFacotory.createCoeProcessLevel().getAllCoeProcessLevelByWsId(wsId); + for (PALRepositoryModel palRepositoryModel : palRepositoryModels) { + if (palRepositoryModel.getName().equals(repositoryName)) { + return palRepositoryModel; + } + } + return null; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public Map> getFileFieldMap() { + return fileFieldMap; + } + + public void setFileFieldMap(Map> fileFieldMap) { + this.fileFieldMap = fileFieldMap; + } +} diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/WordCreatFile.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/WordCreatFile.java new file mode 100644 index 00000000..f535efbf --- /dev/null +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/WordCreatFile.java @@ -0,0 +1,61 @@ +package com.actionsoft.apps.coe.pal.datamigration.util.readword; + +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFParagraph; +import org.apache.poi.xwpf.usermodel.XWPFRun; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; + +/** + * @author baizp + * @Description:将doc生成附件 + * @date 2022/6/21 15:41 + */ +public class WordCreatFile { + public void createFile(XWPFDocument doc) throws IOException { + String absolutePath = "/Users/jiuyabai/Desktop/yili项目/生成测试文件/测试.docx"; + File file = new File(absolutePath); + File pFile = file.getParentFile(); + if (!pFile.exists()) { + pFile.mkdirs(); + } + FileOutputStream out = new FileOutputStream(file); + doc.write(out); + out.close(); + } + public static void copyAllRunsToAnotherParagraph(XWPFParagraph oldPar, XWPFParagraph newPar) { + final int DEFAULT_FONT_SIZE = 10; + + for (XWPFRun run : oldPar.getRuns()) { + String textInRun = run.getText(0); + if (textInRun == null || textInRun.isEmpty()) { + continue; + } + + int fontSize = run.getFontSize(); + //System.out.println("run text = '" + textInRun + "' , fontSize = " + fontSize); + + XWPFRun newRun = newPar.createRun(); + + // Copy text + newRun.setText(textInRun); + + // Apply the same style + newRun.setFontSize( ( fontSize == -1) ? DEFAULT_FONT_SIZE : run.getFontSize() ); + newRun.setFontFamily( run.getFontFamily() ); + newRun.setBold( run.isBold() ); + newRun.setItalic( run.isItalic() ); + newRun.setStrike( run.isStrike() ); + newRun.setColor( run.getColor() ); + newRun.setUnderline(run.getUnderline()); + newRun.setCapitalized(run.isCapitalized()); + newRun.setTextPosition(run.getTextPosition()); + newRun.setItalic(run.isItalic()); + newRun.setShadow(run.isShadowed()); + + } + } + +} diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/WordFinal.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/WordFinal.java new file mode 100644 index 00000000..50c6787d --- /dev/null +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/WordFinal.java @@ -0,0 +1,297 @@ +package com.actionsoft.apps.coe.pal.datamigration.util.readword; + +/** + * @author baizp + * @Description: + * @date 2022/6/21 17:21 + */ + +import com.actionsoft.apps.coe.pal.datamigration.constant.CoEConstant; +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; + +public class WordFinal { + public static void main(String[] args) throws IOException, OpenXML4JException { + new WordFinal().emedFileCopy(); + } + + /** + * 文档内附件复制 + * + * @param args + * @throws IOException + * @throws XmlException + * @throws OpenXML4JException + */ + public void copyWord(UserContext me, String reid, InputStream inputStream, String pluuid) 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 = ""; + for (IBodyElement bodyElement : srcDoc.getBodyElements()) { + BodyElementType elementType = bodyElement.getElementType(); + if (elementType == BodyElementType.PARAGRAPH) { + XWPFParagraph srcPr = (XWPFParagraph) bodyElement; + String tmptext = srcPr.getParagraphText(); + if (tmptext.matches("附件\\d{1,}:")) { + //if (tmptext.matches("附件:")) { + if (count != 1) { + destDoc.write(out); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + writeFileTodisk(me, reid, filename, in, pluuid); + out.close(); + } + isstart = true; + //out = new FileOutputStream("/Users/jiuyabai/Desktop/yili项目/生成测试文件/管理办法11"+count+".docx"); + filename = "上传附件测试" + count + ".docx"; + out = new ByteArrayOutputStream(); + destDoc = new CustomXWPFDocument(); + copyLayout(srcDoc, destDoc); + count += 1; + continue; + } + } + if (!isstart) { + continue; + } + + + if (elementType == BodyElementType.PARAGRAPH) { + + 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); + 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) 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); + boolean isOK = false; + //DataInputStream ds = new DataInputStream(ins); + //isOK = WriteDCFile.getInstance().write(inputStream, dcContextpdf); + SDK.getDCAPI().write(inputStream, dcContextpdf); + //创建数据库数据 + UpfileModel model = new UpfileModel(); + model.setShape_uuid(""); + model.setType("f"); + model.setUuid(UUIDGener.getUUID()); + model.setPl_uuid(reid); + 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 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); + } +} \ No newline at end of file diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/WordUtilXWPF.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/WordUtilXWPF.java new file mode 100644 index 00000000..c704d530 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readword/WordUtilXWPF.java @@ -0,0 +1,651 @@ +package com.actionsoft.apps.coe.pal.datamigration.util.readword; + +import cn.jpush.api.utils.StringUtils; +import com.actionsoft.apps.coe.pal.datamigration.aris.mapping.ModelMappingAPIManager; +import com.actionsoft.apps.coe.pal.datamigration.constant.Constant; +import com.actionsoft.apps.coe.pal.datamigration.util.ShapeUtil; +import com.actionsoft.bpms.util.UUIDGener; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import org.apache.poi.hwpf.usermodel.Paragraph; +import org.apache.poi.xwpf.usermodel.*; + +import java.io.*; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +/** + * @author baizp + * @Description: + * @date 2022/6/16 15:53 + */ +public class WordUtilXWPF { + private static final String WORD_BLANK = "[\u00a0|\u3000|\u0020|\b|\t]"; + + /** + * word的它自己造换行符 要换成string的换行符 + */ + private static final String WORD_LINE_BREAK = "[\u000B|\r]"; + + + /** + * 抽取文字时去掉不必须字符正则 + */ + private static final String splitter = "[\\t|\\n|\\r|\\s+|\u00a0+]"; + + 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);*/ + String filePath = "/Users/jiuyabai/Desktop/yili项目/制度样例1—伊利集团流程制度类文件管理规范1.docx"; + File file = null; + try { + file = new File(filePath); + XWPFDocument doc = new XWPFDocument(new FileInputStream(filePath)); + JSONArray jsonArray = getXParagraph(doc); + System.out.println(""); + } catch (Exception e) { + + } + //new WordUtilXWPF().importWordLibrary(elements); + + } + + public static JSONArray getXParagraph(XWPFDocument doc) { + JSONArray jsons = new JSONArray(); + Iterator iter = doc.getBodyElementsIterator(); + int count = 1; + int img = 1; + int table = 1; + while (iter.hasNext()) { + IBodyElement element = iter.next(); + if (element instanceof XWPFParagraph) { + // 获取段落元素 + XWPFParagraph paragraph = (XWPFParagraph) element; + Paragraph paragraph1 = (Paragraph)element; + String text = paragraph.getText(); + 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"); + // 去除word特有的不可见字符 + String textClearBeginBlank = textWithSameBlankAndBreak.replaceAll(regexClearBeginBlank, ""); + // 为抽取的每一个段落加上\n作为换行符标识 + //System.out.println("text="+textClearBeginBlank); + //System.out.println("style="+style); + //System.out.println("------"); + JSONObject json = new JSONObject(); + json.put("text", text); + json.put("style", style); + json.put("index", count); + json.put("flag", "text"); + jsons.add(json); + count++; + } + } + } + + return jsons; + } + + /** + * 重写解析代码 + * + * @param elements + * @return + */ + public JSONObject rewritContent(JSONObject elements,InputStream inputStream,String name) { + //File file = null; + List failTitleList = new ArrayList<>(); + //String filePath = "/Users/jiuyabai/Desktop/yili项目/制度样例1—伊利集团流程制度类文件管理规范1.docx"; + try { + //file = new File(filePath); + XWPFDocument doc = new XWPFDocument(inputStream); + 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); + //获取段落 + List 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 onlinedata = new ArrayList(); + JSONArray onlinedata = new JSONArray(); + onlinedata.add(shapeze); + boolean lastislast = false; + XWPFDocument newfile = new XWPFDocument(); + boolean isend = false; + boolean isstart = true; + for (XWPFParagraph para : paras) { + BigInteger numlevel = para.getNumIlvl(); + countall += 1; + if("内容".equals(para.getParagraphText()) && numlevel == null){ + 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()); + shap.put("id", shapeId1); + shap.put("text", getShowText(para.getParagraphText())); + shap.put("level", nowlevel); + shap.put("p", pnode); + elements.put(shapeId1, shap); + 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()) && numlevel == null){ + islast = true; + } + break; + } + } + } + } + + if (islast) { + strb.append(para.getParagraphText()); + } + if (strb.length() > 0 && islast) { + 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()); + shap.put("id", shapeId1); + shap.put("text", getShowText(strb.toString())); + //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()); + } + lastislast = true; + lastindex = 0; + } + } + } + new WordCreatFile().createFile(newfile); + } catch (Exception e) { + e.printStackTrace(); + } finally { + // 会在本地产生临时文件,用完后需要删除 + /*if (file.exists()) { + //file.delete(); + }*/ + } + return elements; + } + + /** + * 处理超长的字符 + * + * @param text + * @return + */ + public String getShowText(String text) { + if (!text.isEmpty() && text.length() >= 64) { + return text.substring(0, 64) + "..."; + } + return text; + } + + public JSONObject importWordLibrary(JSONObject elements) { + File file = null; + List failTitleList = new ArrayList<>(); + String filePath = "/Users/jiuyabai/Desktop/yili项目/制度样例1—伊利集团流程制度类文件管理规范1.docx"; + try { + file = new File(filePath); + XWPFDocument doc = new XWPFDocument(new FileInputStream(filePath)); + JSONObject shapeze = ShapeUtil.getProcessShapeDefinitionByName("control.policy", "regulation"); + String shapeIdz = UUIDGener.getObjectId(); + shapeze.put("text", "12312312312");//不生效 + 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); + elements.put(shapeIdz, shapeze); + //获取段落 + List paras = doc.getParagraphs(); + int f = 0;//判断只从标题开始 + int inE = 0;//判断词条库什么时候添加 + int inT = 0;//判断词条库什么时候添加 + int level = 1;//判断级别什么时候添加 + Integer libraryTypeId = 0;//类型id + int leavone = 0; + int leatwo = 0; + int leatthee = 0; + int countall = 1; + int x = 2; + int y = 2; + int lastindex = 0; + StringBuilder strb = new StringBuilder(); + JSONObject leoj = new JSONObject(); + JSONObject letj = new JSONObject(); + //JSONObject lethreej = new JSONObject(); + for (XWPFParagraph para : paras) { + String failTitle = "";//返回错误标题 + String shapeId1 = UUIDGener.getObjectId(); + try { + 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) { + titleLvl = "8"; + } + Date date = new Date();//时间 + JSONObject shap = new JSONObject(); + if (null != titleLvl && !"".equals(titleLvl) && !"8".equals(titleLvl)) { + if (f != 1 && "0".equals(titleLvl)) {//这里是去除目录,只从内容标题开始 + f = 1; + } + if ("0".equals(titleLvl)) { + ++inT; + level = 0; + if (inT != 1) {//第一次不添加,第二次到的时候说明前边的段落内容已经循环完成然后添加 + //System.out.println("级别===" + titleLvl + " 数值======= " + para.getNumLevelText() + " 内容===" + para.getParagraphText()); + leavone += 1; + countall += 1; + lastindex = 0; + int len = para.getParagraphText().length() / 8 - 2; + shap = getSharp(x, y, countall, len, null,""); + shap.put("id", shapeId1); + shap.put("text", para.getParagraphText()); + } + } else if ("1".equals(titleLvl)) { + ++inE; + if (inE != 1 && level == 1) {//第一次不添加,第二次到的时候说明前边的段落内容已经循环完成然后添加 + //System.out.println("级别===" + titleLvl + " 数值======= " + para.getNumLevelText() + " 内容===" + para.getParagraphText()); + leavone += 1; + countall += 1; + if (lastindex == 2) { + x -= 1; + y += 1; + } + if (lastindex == 3) { + x -= 2; + y += 1; + } + if (lastindex == 1) { + y += 1; + } + if (x < 2) { + x = 2; + } + lastindex = 1; + int len = para.getParagraphText().length() / 8 - 2; + shap = getSharp(x, y, countall, len, null,""); + shap.put("id", shapeId1); + shap.put("text", para.getParagraphText()); + leoj = shap; + craetline(elements, shapeze, shap, countall); + } + level = 1; + } else if ("2".equals(titleLvl)) { + //level = 2; + //System.out.println("级别===" + titleLvl + " 数值======= " + para.getNumLevelText() + " 内容===" + para.getParagraphText()); + leatwo += 1; + countall += 1; + if (lastindex == 1) { + x += 1; + } + if (lastindex == 2) { + y += 1; + } + if (lastindex == 3) { + x -= 1; + y += 1; + } + lastindex = 2; + int len = para.getParagraphText().length() / 8 - 2; + shap = getSharp(x, y, countall, len, null,""); + shap.put("id", shapeId1); + shap.put("text", para.getParagraphText()); + letj = shap; + craetline(elements, leoj, shap, countall); + } else { + System.out.println("未匹配到级别"); + } + } else { + //if (f != 1) {//这里是去除目录,只从内容标题开始 + if (StringUtils.isNotEmpty(para.getParagraphText())) { + leatthee += 1; + countall += 1; + if (strb.length() > 0 && lastindex != 3) { + JSONObject tmpshap = new JSONObject(); + //System.out.println("段落内容===" + para.getParagraphText());//段落内容 + if (lastindex == 3) { + y += 1; + } + if (lastindex == 2) { + x += 1; + tmpshap = letj; + } + if (lastindex == 1) { + x += 2; + tmpshap = leoj; + } + int len = para.getParagraphText().length() / 8 - 2; + shap = getSharp(x, y, countall, len, null,""); + shap.put("id", shapeId1); + shap.put("text", para.getParagraphText()); + craetline(elements, tmpshap, shap, countall); + strb = new StringBuilder(); + } + strb.append(para.getParagraphText()); + lastindex = 3; + } + // } + } + if (shap != null && !shap.isEmpty()) { + elements.put(shapeId1, shap); + } + + } catch (Exception e) { + failTitleList.add(failTitle); + } + + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + + // 会在本地产生临时文件,用完后需要删除 + /*if (file.exists()) { + //file.delete(); + }*/ + } + return elements; + } + + /** + * 连线处理 + * + * @param x + * @param y + * @param zindex + * @return + */ + public void craetline(JSONObject elements, JSONObject shapef1, JSONObject shapt1, int zindex) { + JSONObject linkerObj = ModelMappingAPIManager.getInstance().getLinkerDef(); + JSONObject shafp = shapef1.getJSONObject("props"); + JSONObject shatp = shapt1.getJSONObject("props"); + String linkerId = UUIDGener.getObjectId(); + linkerObj.put("id", linkerId); + JSONObject props = linkerObj.getJSONObject("props"); + props.put("zindex", zindex);// 层次 + linkerObj.put("props", props); + //linkerObj.put("points", getLinkerPoints(positionModels)); + JSONObject from = linkerObj.getJSONObject("from"); + from.put("id", shapef1.get("id")); + from.put("angle", Constant.ANGLE_LEFT); + from.put("x", shafp.getInteger("x") + shafp.getInteger("w")); + from.put("y", shafp.getInteger("y") + 25); + linkerObj.put("from", from); + JSONObject to = linkerObj.getJSONObject("to"); + to.put("id", shapt1.get("id")); + to.put("angle", Constant.ANGLE_RIGHT); + to.put("x", shatp.getInteger("x")); + to.put("y", shatp.getInteger("y") + 25); + linkerObj.put("to", to); + elements.put(linkerId, linkerObj); + } + + public JSONObject getSharp(int x, int y, int zindex, int len, JSONObject lastshap, String str) { +// String shapeId1 = UUIDGener.getObjectId(); + JSONObject shape1 = ShapeUtil.getProcessShapeDefinitionByName("control.policy", "item"); +// shape1.put("id", shapeId1); + JSONArray attribute = shape1.getJSONArray("dataAttributes").getJSONObject(0).getJSONArray("attributesJsonArray"); + JSONObject tmp = new JSONObject(); + tmp.put("ref", ""); + tmp.put("readonly", false); + tmp.put("scope", "%,*"); + tmp.put("name", "描述"); + tmp.put("id", "desc"); + tmp.put("type", "textarea"); + tmp.put("value", str); + tmp.put("groupPath", "baseAttribute"); + tmp.put("key", "desc"); + attribute.add(tmp); + // shape1.put("text",orgdepartmentList.get(i).getString("POSITION_NAME")); + if (lastshap.getString("text").contains("适用范围设定")) { + System.out.println("断点"); + } + lastshap = lastshap.getJSONObject("props"); + + JSONObject props1 = shape1.getJSONObject("props");// 位置大小 + if (len < 0) { + len = 0; + } + int xtmp = lastshap.getInteger("x") + (lastshap.getInteger("w") + 100) * x; + props1.put("x", xtmp); + props1.put("y", 100 * y); + //props1.put("w", 150 + (len * 35)); + props1.put("w", 325); + props1.put("h", 50); + //System.out.println("坐标为:x" + xtmp + " y:" + y); + props1.put("zindex", zindex); + return shape1; + } + + /** + * Word中的大纲级别,可以通过getPPr().getOutlineLvl()直接提取,但需要注意,Word中段落级别,通过如下三种方式定义: + * 1、直接对段落进行定义; + * 2、对段落的样式进行定义; + * 3、对段落样式的基础样式进行定义。 + * 因此,在通过“getPPr().getOutlineLvl()”提取时,需要依次在如上三处读取。 + * + * @param doc + * @param para + * @return + */ + private String getTitleLvl(XWPFDocument doc, XWPFParagraph para) { + String titleLvl = ""; + try { + //判断该段落是否设置了大纲级别 + if (para.getCTP().getPPr().getOutlineLvl() != null) { + return String.valueOf(para.getCTP().getPPr().getOutlineLvl().getVal()); + } + } catch (Exception e) { + + } + try { + //判断该段落的样式是否设置了大纲级别 + if (doc.getStyles().getStyle(para.getStyle()).getCTStyle().getPPr().getOutlineLvl() != null) { + return String.valueOf(doc.getStyles().getStyle(para.getStyle()).getCTStyle().getPPr().getOutlineLvl().getVal()); + } + } catch (Exception e) { + + } + + try { + //判断该段落的样式的基础样式是否设置了大纲级别 + 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()); + } + } catch (Exception e) { + + } + try { + if (para.getStyleID() != null) { + return para.getStyleID(); + } + } catch (Exception e) { + + } + return titleLvl; + } +} diff --git a/com.actionsoft.apps.coe.pal.datamigration/web/com.actionsoft.apps.coe.pal.datamigration/action.xml b/com.actionsoft.apps.coe.pal.datamigration/web/com.actionsoft.apps.coe.pal.datamigration/action.xml index 7d9cebcb..3dcebc0d 100644 --- a/com.actionsoft.apps.coe.pal.datamigration/web/com.actionsoft.apps.coe.pal.datamigration/action.xml +++ b/com.actionsoft.apps.coe.pal.datamigration/web/com.actionsoft.apps.coe.pal.datamigration/action.xml @@ -18,4 +18,11 @@ + + + + + + + \ No newline at end of file