From b8c92ee62a5aac953048778e6b4409154f3c0ce0 Mon Sep 17 00:00:00 2001 From: chengli <783535094@qq.com> Date: Wed, 6 Jul 2022 21:35:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E8=A1=A8=E5=8D=95=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E7=94=9F=E6=88=90=E6=97=B6=20=E6=97=A0=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=80=BC=E5=BE=97=E6=83=85=E5=86=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/readtable/ReadTable.java | 139 +++++++++++++++--- 1 file changed, 121 insertions(+), 18 deletions(-) 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 2ab95b89..743c5ecc 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 @@ -37,6 +37,7 @@ import java.util.*; public class ReadTable { public static Map wordAttributeMap = new HashMap<>(); public static Map nameToIdMap = new HashMap<>(); + public static Map idToNameMap = new HashMap<>(); //基础字段 public Map fieldMap = new HashMap<>(); @@ -59,6 +60,7 @@ public class ReadTable { }); nameToId.forEach(wordAttribute -> { nameToIdMap.put(wordAttribute.getTitle(), wordAttribute.getType()); + idToNameMap.put(wordAttribute.getType(), wordAttribute.getTitle()); }); } @@ -110,7 +112,18 @@ public class ReadTable { InputStream docfile = SDK.getDCAPI().read(dcContextpdfdoc); //画一个图形 并返回图形ID String shapId = createOneMap(wsId, docname.replace(".doc", ""), userContext, docfile); - + //先把默认属性给他弄上~~~然后再赋值 + 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"); + Map> methodAttrsMap = new HashMap<>(); + //handleShapeDefaultAttr("", palRepositoryModel, elements, methodAttrsMap, docfile); + //writeAttrbute(userContext, docfile, docname.replace(".doc", ""), elements.getJSONObject(shapId)); //解析附件进行复制 DCContext dcContextpdf1 = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, docxname); InputStream docxfile = SDK.getDCAPI().read(dcContextpdf1); @@ -129,7 +142,7 @@ public class ReadTable { nameToIdMap.forEach((key, value) -> { //根据key去更新 WordField tmpw = fileFieldMap.get(key); - if (tmpw != null) { + /*if (tmpw != null) { JSONObject tmp = new JSONObject(); tmp.put("ref", ""); tmp.put("icon", "../apps/com.actionsoft.apps.coe.pal/img/icon/shape_attribute.png"); @@ -142,7 +155,7 @@ public class ReadTable { tmp.put("groupPath", "baseAttribute"); tmp.put("key", value); attribute.add(tmp); - } + }*/ }); } return shapeze; @@ -181,8 +194,10 @@ public class ReadTable { props1.put("w", 110); props1.put("h", 50); props1.put("zindex", 0); - writeAttrbute(userContext, docfile, name, shapeze); elements.put(shapeIdz, shapeze); + + Map> methodAttrsMap = new HashMap<>(); + handleShapeDefaultAttr("", palRepositoryModel, elements, methodAttrsMap, docfile); // 设置画布大小 defineModel.setDefinition(definition.toString()); // 保存文件 @@ -225,20 +240,20 @@ public class ReadTable { break; } }*/ - //标题后续直接为table - if (nowPara.isInTable()) { - Table table = range.getTable(nowPara); - Map> tabelDocText = this.getHorizontalTableMapText(table); - tabelDocText.keySet().forEach(key -> { - List 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; + //标题后续直接为table + if (nowPara.isInTable()) { + Table table = range.getTable(nowPara); + Map> tabelDocText = this.getHorizontalTableMapText(table); + tabelDocText.keySet().forEach(key -> { + List 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) { @@ -292,4 +307,92 @@ public class ReadTable { return result; } + /** + * 自定义属性 + * + * @param wsId + * @param palModel + * @param elements + * @param methodAttrsMap + */ + public void handleShapeDefaultAttr(String wsId, PALRepositoryModel palModel, JSONObject elements, Map> methodAttrsMap, InputStream file) { + boolean result = analysisWordTable(file); + for (String key : elements.keySet()) { + JSONObject shape = elements.getJSONObject(key); + if ("linker".equals(shape.getString("name"))) { + continue; + } + String shapeMehtodId = shape.getString("category").replace("_", "."); + String shapeName = shape.getString("name"); + + if (methodAttrsMap.containsKey(palModel.getMethodId()) && methodAttrsMap.containsKey(shapeName)) { + } else { + if (!methodAttrsMap.containsKey(palModel.getMethodId())) { + methodAttrsMap.put(palModel.getMethodId(), new HashMap<>()); + } + JSONObject attrs = ShapeUtil.getProcessUseShapeMethodAttrByShapeName(palModel.getWsId(), shapeMehtodId, palModel.getMethodId(), shapeName); + if (attrs != null) { + methodAttrsMap.get(palModel.getMethodId()).put(shapeName, attrs); + } + } + JSONObject attrs = methodAttrsMap.get(palModel.getMethodId()).get(shapeName);// 最终属性内容 + attrs = JSONObject.parseObject(attrs.toString());// 复制 + JSONArray dataAttributes = shape.getJSONArray("dataAttributes"); + if (!dataAttributes.isEmpty() && dataAttributes.size() > 0) { + for (Object attribute : dataAttributes) { + JSONObject obj = (JSONObject) attribute; + if (obj.containsKey("attributesJsonArray")) { + JSONArray attributesJsonArray = obj.getJSONArray("attributesJsonArray"); + Set attrIds = new HashSet<>(); + for (int i = 0; i < attributesJsonArray.size(); i++) { + if (attributesJsonArray.getJSONObject(i).containsKey("id")) { + attrIds.add(attributesJsonArray.getJSONObject(i).getString("id")); + } + } + 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); + } + } + } + } + } + } + } + + /** + * 获取默认属性内容 + * + * @param attr + * @return + */ + public JSONObject getDefaultAttrObj(JSONObject attr) { + String ref = attr.getString("ref"); + boolean readonly = attr.getBooleanValue("readonly"); + String scope = attr.getString("scope"); + String attrName = attr.getString("title"); + String attrId = attr.getString("id"); + String type = attr.getString("type"); + String groupPath = attr.getString("groupPath"); + String attrKey = attr.getString("key"); + String attrValue = ""; + JSONObject object2 = new JSONObject(); + object2.put("ref", ref); + object2.put("readonly", readonly); + object2.put("scope", scope); + object2.put("name", attrName); + object2.put("id", attrId); + object2.put("type", type); + object2.put("groupPath", groupPath); + object2.put("key", attrKey); + object2.put("value", ""); + return object2; + } }