diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/ReadTable.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/ReadTable.java index 64e1b801..7ac0dce0 100644 --- a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/ReadTable.java +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/ReadTable.java @@ -12,6 +12,7 @@ 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; @@ -97,13 +98,14 @@ public class ReadTable { } DCPluginProfile dcProfilepdfdoc = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", "migration"); + //进行文件解析 写基本信息 - //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); - if(shapId.isEmpty()){ + if (shapId.isEmpty()) { return; } String title = fileFieldMap.get("标题").getData().toString(); @@ -113,11 +115,12 @@ public class ReadTable { return; } String id = palRepositoryModel.getId(); + writeAttrbute(id); //将文件挂载到附件里面 DCContext dcContextorigin = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, fileName); InputStream originfile = SDK.getDCAPI().read(dcContextorigin); try { - new ReadWordUtil().writeFileTodisk(userContext, "", fileName, originfile, palRepositoryModel.getId(),"f"); + new ReadWordUtil().writeFileTodisk(userContext, "", fileName, originfile, palRepositoryModel.getId(), "f"); } catch (FileNotFoundException e) { e.printStackTrace(); } @@ -143,31 +146,25 @@ public class ReadTable { } } - 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) { + /** + * 给表单文件属性赋值 + * + * @param file + * @param plid + */ + public void writeAttrbute(String plid) { + //boolean result = analysisWordTable(file); //根据名称获取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; + 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) { + String sql1 = String.format(sql, tmp.getData().toString(), value, plid); + System.out.println("执行的sql有:" + sql1); + DBSql.update(sql1); + } + }); } /** @@ -179,12 +176,12 @@ public class ReadTable { */ public String createOneMap(String plId, String name, UserContext userContext, InputStream docfile) { boolean result = analysisWordTable(docfile); - if(fileFieldMap.get("标题") == null){ + if (fileFieldMap.get("标题") == null) { return ""; } String title = fileFieldMap.get("标题").getData().toString(); PALRepositoryModel palRepositoryModel = ReadWordUtil.getRepositoryByName(plId, title); - if(palRepositoryModel == null){ + if (palRepositoryModel == null) { return ""; } BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(palRepositoryModel.getId(), 0); @@ -195,7 +192,6 @@ public class ReadTable { 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"); } @@ -229,6 +225,8 @@ public class ReadTable { * @return */ public boolean analysisWordTable(InputStream file) { + fieldMap.clear(); + fileFieldMap.clear(); boolean ischeck = false; try { HWPFDocument doc = new HWPFDocument(file); @@ -240,17 +238,17 @@ public class ReadTable { if (StringUtils.isEmpty(text)) { continue; } - if(nowPara.text().contains("文件编码")){ + if (nowPara.text().contains("文件编码")) { ischeck = true; } - if(ischeck){ + if (ischeck) { boolean isTitle = isTitle(nowPara); - if(isTitle){ + if (isTitle) { String title = ""; - if(fieldMap.get("标题") != null){ + if (fieldMap.get("标题") != null) { title = fieldMap.get("标题").toString(); } - title = title+nowPara.text().replace("\r",""); + title = title + nowPara.text().replace("\r", ""); fieldMap.put("标题", title); fileFieldMap.put("标题", new WordField<>(title)); } @@ -307,7 +305,6 @@ public class ReadTable { 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; @@ -316,7 +313,6 @@ public class ReadTable { //取得单元格 TableCell td = tr.getCell(j); StringBuffer sb = new StringBuffer(); - String text = td.text(); //取得单元格的内容 for (int k = 0; k < td.numParagraphs(); k++) { @@ -328,15 +324,30 @@ public class ReadTable { } sb.append(s); } - if (x == 0) { - key = sb.toString(); - } else { - String value = sb.toString(); - list.add(value == null || Objects.deepEquals(value, "") ? null : value.replace(",", "")); + key = sb.toString().replaceAll(" ",""); + //看看是否是键值 + if(nameToIdMap.containsKey(key) && result.get(key) == null && j < (tr.numCells()-1)){ + //取得单元格 + j += 1; + TableCell tdtmp = tr.getCell(j); + StringBuffer sb1 = new StringBuffer(); + List list = new ArrayList<>(16); + //取得单元格的内容 + for (int k = 0; k < tdtmp.numParagraphs(); k++) { + Paragraph paragraph = tdtmp.getParagraph(k); + String s = paragraph.text(); + //去除后面的特殊符号 + if (null != s && !"".equals(s)) { + s = s.substring(0, s.length() - 1); + } + sb1.append(s); + } + String tmpvalue = sb1.toString(); + list.add(tmpvalue == null || Objects.deepEquals(tmpvalue, "") ? null : tmpvalue.replace(",", "")); + result.put(key, list); } - x++; } - result.put(key, list); + //result.put(key, list); } return result; } @@ -385,12 +396,6 @@ public class ReadTable { for (String attrId : attrs.keySet()) { if (!attrIds.contains(attrId)) { JSONObject eleAttrObj = getDefaultAttrObj(attrs.getJSONObject(attrId)); - String id = eleAttrObj.getString("id"); - String name = idToNameMap.get(id); - WordField tmpw = fileFieldMap.get(name); - if (tmpw != null) { - eleAttrObj.put("value", tmpw.getData()); - } attributesJsonArray.add(eleAttrObj); } } @@ -428,23 +433,25 @@ public class ReadTable { object2.put("value", ""); return object2; } + /** * 判断是否为文档标题 - * 标志:黑体一号 + * 标志:黑体一号 + * * @param paragraph * @return */ - public boolean isTitle(Paragraph paragraph){ + public boolean isTitle(Paragraph paragraph) { int size = paragraph.numCharacterRuns(); String fontName = ""; int fontSize = 0; - boolean bold ; + boolean bold; for (int j = 0; j < size; j++) { CharacterRun characterRun = paragraph.getCharacterRun(j); fontName = characterRun.getFontName(); - if (fontName.contains("黑体")){ + if (fontName.contains("黑体")) { //与文档fontsize标号2倍关系 ,黑体一号 等于 26号size - return characterRun.getFontSize() == 44; + return characterRun.getFontSize() == 44; } } return false; diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/TableConstant.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/TableConstant.java index f6350d39..bc4a1d8a 100644 --- a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/TableConstant.java +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/TableConstant.java @@ -3,5 +3,13 @@ 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\"}]"; + 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\"}," + + "{\"title\":\"L1\",\"type\":\"Process_Architecture_L1\"}," + + "{\"title\":\"L2\",\"type\":\"Process_Architecture_L2\"}," + + "{\"title\":\"L3\",\"type\":\"Process_Architecture_L3\"}]"; } \ No newline at end of file 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 index bee2ea1e..fa7c9e26 100644 --- 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 @@ -6,7 +6,28 @@ public class Constant { public final static String UPFILE = "migration"; public final static String WORDIMPORT = "[{\"title\":\"基本信息\",\"type\":\"DirectFeild\"},{\"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 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\":\"Organizational_role\"}," + + "{\"title\":\"组织/角色职责\",\"type\":\"Organization_and_role_responsibilities\"}," + + "{\"title\":\"相关文件\",\"type\":\"relevant_flies\"}," + + "{\"title\":\"支持文件\",\"type\":\"support_files\"}," + + "{\"title\":\"相关知识\",\"type\":\"relevant_flies\"}," + + "{\"title\":\"附则\",\"type\":\"T_supplementary_articles\"}," + + "{\"title\":\"L1\",\"type\":\"Process_Architecture_L1\"}," + + "{\"title\":\"L2\",\"type\":\"Process_Architecture_L2\"}," + + "{\"title\":\"L3\",\"type\":\"Process_Architecture_L3\"}," + + "{\"title\":\"文件编码\",\"type\":\"file_number\"}," + + "{\"title\":\"适用范围\",\"type\":\"application\"}," + + "{\"title\":\"版本\",\"type\":\"versions\"}," + + "{\"title\":\"生效日期\",\"type\":\"effective_date\"}," + + "{\"title\":\"修订内容及理由\",\"type\":\"Contents_and_reasons_for_revision\"}" + + "]"; // 构造连线时的几个固定参数 public final static double ANGLE_RIGHT = 0; public final static double ANGLE_DOWN = 1.5707963267948968; 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 index aa738662..3c07664b 100644 --- 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 @@ -119,12 +119,35 @@ public class ReadWordUtil { }); jsonObject.put("table", jsonArray); new CoeProcessLevelWeb(userContext).moreAttrContentSave(id, "term", jsonObject.toJSONString()); + }else 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, "Organizational_role", 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); + //System.out.println("执行的sql有:" + sql1); DBSql.update(sql1); } else { String sql1 = String.format(sql, tmp.getData().toString(), value, id); @@ -272,7 +295,7 @@ public class ReadWordUtil { //标题后续直接为table if (paragraph.isInTable()) { Table table = range.getTable(paragraph); - Map> tabelDocText = this.getHorizontalTableMapText(table); + Map> tabelDocText = this.getHorizontalTableMapTextTwo(table); //在基本信息中特殊获取文件名称和版本号 if (text.trim().equals("文控信息") || text.trim().equals("基本信息")) { @@ -411,6 +434,62 @@ public class ReadWordUtil { return result; } + /** + * 将所有的属性解析出来 + * @param tb + * @return + */ + private Map> getHorizontalTableMapTextTwo(Table tb) { + Map> result = new HashMap<>(16); + //迭代行,默认从0开始,可以依据需要设置i的值,改变起始行数,也可设置读取到那行,只需修改循环的判断条件即可 + for (int i = 0; i < tb.numRows(); i++) { + 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(); + + //取得单元格的内容 + 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); + } + key = sb.toString().replaceAll(" ",""); + //看看是否是键值 + if(nameToIdMap.containsKey(key) && result.get(key) == null && j < (tr.numCells()-1)){ + //取得单元格 + j += 1; + TableCell tdtmp = tr.getCell(j); + StringBuffer sb1 = new StringBuffer(); + List list = new ArrayList<>(16); + //取得单元格的内容 + for (int k = 0; k < tdtmp.numParagraphs(); k++) { + Paragraph paragraph = tdtmp.getParagraph(k); + String s = paragraph.text(); + //去除后面的特殊符号 + if (null != s && !"".equals(s)) { + s = s.substring(0, s.length() - 1); + } + sb1.append(s); + } + String tmpvalue = sb1.toString(); + list.add(tmpvalue == null || Objects.deepEquals(tmpvalue, "") ? null : tmpvalue.replace(",", "")); + result.put(key, list); + } + } + //result.put(key, list); + } + return result; + } + private List> getHorizontalTableText(Table table) { List> list = new ArrayList<>();