diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/CoEDesignerVersionController.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/CoEDesignerVersionController.java index aa54e270..51dc778d 100644 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/CoEDesignerVersionController.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/CoEDesignerVersionController.java @@ -1,5 +1,6 @@ package com.actionsoft.apps.coe.pal; +import com.actionsoft.apps.coe.pal.pal.repository.designer.dto.VersionCompareDTO; import com.actionsoft.apps.coe.pal.pal.repository.designer.dto.VersionListDTO; import com.actionsoft.apps.coe.pal.pal.repository.designer.web.CoeDesignerVersionWeb; import com.actionsoft.bpms.server.UserContext; @@ -28,4 +29,16 @@ public class CoEDesignerVersionController { VersionListDTO versionListDTO = new VersionListDTO(wsId, teamId, id); return new CoeDesignerVersionWeb(uc).getVersionList(versionListDTO); } + /** + * 设计器版本对比 + * + * @param uc 用户上下文 + * @param wsId 资产库Id + * @return 模型版本对比页面 + */ + @Mapping("com.actionsoft.apps.coe.pal_pl_repository_designer_version_compare") + public String designerVersionCompare(UserContext uc, String wsId, String teamId, String compareVerId, String curId) { + VersionCompareDTO versionCompareDTO = new VersionCompareDTO(wsId, teamId, compareVerId, curId); + return new CoeDesignerVersionWeb(uc).designerVersionCompare(versionCompareDTO); + } } diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/components/model/PALSecurityLevelModel.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/components/model/PALSecurityLevelModel.java new file mode 100644 index 00000000..669950d0 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/components/model/PALSecurityLevelModel.java @@ -0,0 +1,56 @@ +package com.actionsoft.apps.coe.pal.components.model; + +/** + * 密级实体类 + */ +public class PALSecurityLevelModel { + + /** + * 密级code + */ + private String code; + + /** + * 密级名称 + */ + private String name; + + /** + * 密级颜色 + */ + private String color; + + public PALSecurityLevelModel() { + + } + + public PALSecurityLevelModel(String code, String name, String color) { + this.code = code; + this.name = name; + this.color = color; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/PALBasicMethodCache.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/PALBasicMethodCache.java new file mode 100644 index 00000000..8d4762f2 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/PALBasicMethodCache.java @@ -0,0 +1,133 @@ +package com.actionsoft.apps.coe.pal.pal.method.cache; + +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; + +import com.actionsoft.apps.coe.pal.pal.method.cache.index.PALBasicMethodCacheIndex1; +import com.actionsoft.apps.coe.pal.pal.method.cache.index.PALBasicMethodCacheIndex2; +import com.actionsoft.apps.coe.pal.pal.method.cache.index.PALBasicMethodCacheIndex3; +import com.actionsoft.apps.coe.pal.pal.method.model.PALBasicMethodModel; +import com.actionsoft.apps.resource.plugin.profile.CachePluginProfile; +import com.actionsoft.bpms.commons.cache.Cache; +import com.actionsoft.bpms.commons.cache.CacheManager; + +/** + * 建模方法基础信息缓存Cache + */ +public class PALBasicMethodCache extends Cache { + + public PALBasicMethodCache(CachePluginProfile configuration) { + super(configuration); + registeIndex(PALBasicMethodCacheIndex1.class, new PALBasicMethodCacheIndex1()); // methodId-wsId + registeIndex(PALBasicMethodCacheIndex2.class, new PALBasicMethodCacheIndex2()); // wsId + registeIndex(PALBasicMethodCacheIndex3.class, new PALBasicMethodCacheIndex3()); // methodId + } + + /** + * getCache + * + * @return + */ + public static PALBasicMethodCache getCache() { + return CacheManager.getCache(PALBasicMethodCache.class); + } + + /** + * put + */ + public static void putModel(PALBasicMethodModel model) { + putModel(model, true); + } + + public static void putModel(PALBasicMethodModel model, boolean notifyCluster) { + getCache().put(model.getId(), model, notifyCluster); + } + + /** + * 根据建模方法Id和资产库Id + * + * @param methodId 建模方法Id + * @param wsId 资产库Id + * @return + */ + public static PALBasicMethodModel getModelByMethodIdAndWsId(String methodId, String wsId) { + return getCache().getByIndexSingle(PALBasicMethodCacheIndex1.class, methodId + "-" + wsId); + } + + /** + * 获取全部建模方法基础信息List + * + * @return + */ + public static List getAllBasicMethodModel() { + Iterator iterator = getCache().iterator(); + return iteratorToList(iterator); + } + + /** + * 根据资产库获取该资产库下全部建模方法基础信息List + * + * @return + */ + public static List getAllBasicMethodModel(String wsId) { + Iterator iterators = getCache().getByIndex(PALBasicMethodCacheIndex2.class, wsId); + return iteratorToList(iterators); + } + + /** + * 根据appId获取该appId下全部建模方法 + * + * @param appId 应用id + * @return methodIds + */ + public static List getMethodIdByAppId(String appId) { + List methodModels = getAllBasicMethodModel(); + return methodModels.stream().filter(model -> appId.equals(model.getAppId())).map(PALBasicMethodModel::getMethodId).distinct().collect(Collectors.toList()); + + } + + /** + * 根据id删除建模方法基础信息 + * + * @param methodId + */ + public static void removeById(String methodId) { + getCache().removeIndexByKey(PALBasicMethodCacheIndex3.class, methodId); + } + + /** + * 清除全部建模方法基础信息 + */ + public static void removeAllBasicMethodModel() { + List list = getAllBasicMethodModel(); + if (list != null && list.size() > 0) { + for (PALBasicMethodModel model : list) { + getCache().remove(model.getId()); + } + } + } + + /** + * 清除资产库建模方法缓存 + * + * @param wsId 资产库id + */ + public static void removeByWsId(String wsId) { + getCache().removeIndexByKey(PALBasicMethodCacheIndex2.class, wsId); + } + + /** + * 清除资产库建模方法缓存 + * + * @param wsId 资产库Id + * @param methodId 建模方法Id + */ + public static void removeByWsIdAndMethodId(String wsId, String methodId) { + getCache().removeIndexByKey(PALBasicMethodCacheIndex1.class, methodId + "-" + wsId); + } + + @Override + protected void load() { + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/PALMethodSchemaCache.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/PALMethodSchemaCache.java new file mode 100644 index 00000000..4473a09b --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/PALMethodSchemaCache.java @@ -0,0 +1,156 @@ +package com.actionsoft.apps.coe.pal.pal.method.cache; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import com.actionsoft.apps.coe.pal.pal.method.cache.index.PALMethodSchemaCacheIndex1; +import com.actionsoft.apps.coe.pal.pal.method.cache.index.PALMethodSchemaCacheIndex2; +import com.actionsoft.apps.coe.pal.pal.method.cache.index.PALMethodSchemaCacheIndex3; +import com.actionsoft.apps.coe.pal.pal.method.cache.index.PALMethodSchemaCacheIndex4; +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodSchemaModel; +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodShapeSchemaModel; +import com.actionsoft.apps.resource.plugin.profile.CachePluginProfile; +import com.actionsoft.bpms.commons.cache.Cache; +import com.actionsoft.bpms.commons.cache.CacheManager; +import com.actionsoft.i18n.I18nRes; + +/** + * 形状定义schema cache + * + * @author sunlianhui + */ +public class PALMethodSchemaCache extends Cache { + + public PALMethodSchemaCache(CachePluginProfile configuration) { + super(configuration); + registeIndex(PALMethodSchemaCacheIndex1.class, new PALMethodSchemaCacheIndex1()); // methodId + registeIndex(PALMethodSchemaCacheIndex2.class, new PALMethodSchemaCacheIndex2()); // methodId-lang + registeIndex(PALMethodSchemaCacheIndex3.class, new PALMethodSchemaCacheIndex3()); // methodId-wsId-lang + registeIndex(PALMethodSchemaCacheIndex4.class, new PALMethodSchemaCacheIndex4()); // wsId + } + + /** + * getCache + * + * @return + */ + public static PALMethodSchemaCache getCache() { + return CacheManager.getCache(PALMethodSchemaCache.class); + } + + /** + * getModel + * + * @param id + * @return + */ + public static PALMethodSchemaModel getModelById(String id) { + return getCache().get(id); + } + + public static List getModelListByMethodId(String methodId) { + return iteratorToList(getCache().getByIndex(PALMethodSchemaCacheIndex1.class, methodId)); + } + + public static PALMethodSchemaModel getModelListByMethodIdAndLang(String methodId, String lang) { + return getCache().getByIndexSingle(PALMethodSchemaCacheIndex2.class, methodId + "-" + lang); + } + + public static PALMethodSchemaModel getModelListByMethodIdAndLangAndWsId(String methodId, String lang, String wsId) { + return getCache().getByIndexSingle(PALMethodSchemaCacheIndex3.class, methodId + "-" + wsId + "-" + lang); + } + + /** + * 获取图元是否允许出现复制Map + * + * @param wsId 资产库id + * @param methodId 建模方法Id + * @return map + */ + public static Map shapeAllowOccurrence(String wsId, String methodId) { + PALMethodSchemaModel schemaModel = getModelListByMethodIdAndLangAndWsId(methodId, I18nRes.getUserLanguage(), wsId); + if (schemaModel != null) { + List shapeSchemaList = schemaModel.getShapeSchemaList(); + return shapeSchemaList.stream().collect(Collectors.toMap(PALMethodShapeSchemaModel::getKey, PALMethodShapeSchemaModel::isAllowOccurrence, (existingValue, newValue) -> existingValue)); + } + return new HashMap<>(); + } + + /** + * 根据形状key值获取形状 + * + * @param wsId 资产库Id + * @param lang 语言 + * @param methodId 建模方法Id + * @param shapeKey 形状key + * @return 形状模型 + */ + public static PALMethodShapeSchemaModel getShapeByKey(String wsId, String lang, String methodId, String shapeKey) { + PALMethodSchemaModel schemaModel = getModelListByMethodIdAndLangAndWsId(methodId, lang, wsId); + List shapeSchemaList = schemaModel.getShapeSchemaList(); + return shapeSchemaList.stream().filter(shape -> { + return shape.getKey().equals(shapeKey); + }).findFirst().orElse(null); + } + + /** + * put + */ + public static void putModel(PALMethodSchemaModel model) { + putModel(model, true); + } + + public static void putModel(PALMethodSchemaModel model, boolean notifyCluster) { + if (model != null) { + getCache().put(model.getId(), model, notifyCluster); + } + } + + /** + * 根据id删除属性定义 + * + * @param id + */ + public static void removeModelById(String id) { + getCache().remove(id); + } + + public static void removeByMethodId(String methodId) { + List list = getModelListByMethodId(methodId); + if (list != null) { + for (PALMethodSchemaModel model : list) { + removeModelById(model.getId()); + } + } + } + + public static void removeByMethodIdAndWsId(String methodId, String wsId) { + List list = getModelListByMethodId(methodId); + if (list != null) { + for (PALMethodSchemaModel model : list) { + if (model.getWsId().equals(wsId)) + removeModelById(model.getId()); + } + } + } + + public static void removeAll() { + Iterator iterator = getCache().iterator(); + while (iterator.hasNext()) { + PALMethodSchemaModel next = iterator.next(); + getCache().remove(next.getId()); + } + } + + public static void removeByWsId(String wsId) { + getCache().removeIndexByKey(PALMethodSchemaCacheIndex4.class, wsId); + } + + @Override + protected void load() { + } + +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALBasicMethodCacheIndex1.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALBasicMethodCacheIndex1.java new file mode 100644 index 00000000..a2dddf05 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALBasicMethodCacheIndex1.java @@ -0,0 +1,11 @@ +package com.actionsoft.apps.coe.pal.pal.method.cache.index; + +import com.actionsoft.apps.coe.pal.pal.method.model.PALBasicMethodModel; +import com.actionsoft.bpms.commons.cache.ListValueIndex; + +public class PALBasicMethodCacheIndex1 extends ListValueIndex { + @Override + public String key(PALBasicMethodModel t) { + return t.getMethodId() + "-" + t.getWsId(); + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALBasicMethodCacheIndex2.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALBasicMethodCacheIndex2.java new file mode 100644 index 00000000..5550d868 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALBasicMethodCacheIndex2.java @@ -0,0 +1,11 @@ +package com.actionsoft.apps.coe.pal.pal.method.cache.index; + +import com.actionsoft.apps.coe.pal.pal.method.model.PALBasicMethodModel; +import com.actionsoft.bpms.commons.cache.ListValueIndex; + +public class PALBasicMethodCacheIndex2 extends ListValueIndex { + @Override + public String key(PALBasicMethodModel t) { + return t.getWsId(); + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALBasicMethodCacheIndex3.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALBasicMethodCacheIndex3.java new file mode 100644 index 00000000..dc230286 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALBasicMethodCacheIndex3.java @@ -0,0 +1,11 @@ +package com.actionsoft.apps.coe.pal.pal.method.cache.index; + +import com.actionsoft.apps.coe.pal.pal.method.model.PALBasicMethodModel; +import com.actionsoft.bpms.commons.cache.ListValueIndex; + +public class PALBasicMethodCacheIndex3 extends ListValueIndex { + @Override + public String key(PALBasicMethodModel t) { + return t.getMethodId(); + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALMethodSchemaCacheIndex1.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALMethodSchemaCacheIndex1.java new file mode 100644 index 00000000..f2c60c9c --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALMethodSchemaCacheIndex1.java @@ -0,0 +1,14 @@ +package com.actionsoft.apps.coe.pal.pal.method.cache.index; + +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodSchemaModel; +import com.actionsoft.bpms.commons.cache.ListValueIndex; + +/** + * 以methodId建立索引 + */ +public class PALMethodSchemaCacheIndex1 extends ListValueIndex { + @Override + public String key(PALMethodSchemaModel palMethodSchemaModel) { + return palMethodSchemaModel.getMethodId(); + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALMethodSchemaCacheIndex2.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALMethodSchemaCacheIndex2.java new file mode 100644 index 00000000..5ddd6694 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALMethodSchemaCacheIndex2.java @@ -0,0 +1,14 @@ +package com.actionsoft.apps.coe.pal.pal.method.cache.index; + +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodSchemaModel; +import com.actionsoft.bpms.commons.cache.SingleValueIndex; + +/** + * 以methodId-lang建立索引 + */ +public class PALMethodSchemaCacheIndex2 extends SingleValueIndex { + @Override + public String key(PALMethodSchemaModel palMethodSchemaModel) { + return palMethodSchemaModel.getMethodId() + "-" + palMethodSchemaModel.getLang(); + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALMethodSchemaCacheIndex3.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALMethodSchemaCacheIndex3.java new file mode 100644 index 00000000..14412a77 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALMethodSchemaCacheIndex3.java @@ -0,0 +1,11 @@ +package com.actionsoft.apps.coe.pal.pal.method.cache.index; + +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodSchemaModel; +import com.actionsoft.bpms.commons.cache.ListValueIndex; + +public class PALMethodSchemaCacheIndex3 extends ListValueIndex { + @Override + public String key(PALMethodSchemaModel model) { + return model.getMethodId() + "-" + model.getWsId() + "-" + model.getLang(); + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALMethodSchemaCacheIndex4.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALMethodSchemaCacheIndex4.java new file mode 100644 index 00000000..52b829ab --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/cache/index/PALMethodSchemaCacheIndex4.java @@ -0,0 +1,14 @@ +package com.actionsoft.apps.coe.pal.pal.method.cache.index; + +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodSchemaModel; +import com.actionsoft.bpms.commons.cache.ListValueIndex; + +/** + * 以methodId建立索引 + */ +public class PALMethodSchemaCacheIndex4 extends ListValueIndex { + @Override + public String key(PALMethodSchemaModel palMethodSchemaModel) { + return palMethodSchemaModel.getWsId(); + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/constant/MethodSchemaConst.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/constant/MethodSchemaConst.java new file mode 100644 index 00000000..e33ccdec --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/constant/MethodSchemaConst.java @@ -0,0 +1,10 @@ +package com.actionsoft.apps.coe.pal.pal.method.constant; + +public interface MethodSchemaConst { + + String SCHEMA_CATEGORY = "Schema.addCategory(*?);\r\n"; + + String SCHEMA_GLOBAL_COMMAND = "Schema.addGlobalCommand(*?);\r\n"; + + String SCHEMA_SHAPE = "Schema.addShape(*?);\r\n"; +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/constant/PALMethodConst.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/constant/PALMethodConst.java index a7bf7cd2..fac9fe15 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/constant/PALMethodConst.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/constant/PALMethodConst.java @@ -59,4 +59,7 @@ public interface PALMethodConst { * flowchart的AppId */ public final static String APP_PROCESS_FLOWCHART = "com.actionsoft.apps.coe.method.process.flowchart"; + + + String ATTR_FILE_DC_REPOSITORY_NAME = "attr_upfile"; } diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALBasicMethodModel.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALBasicMethodModel.java new file mode 100644 index 00000000..019299d5 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALBasicMethodModel.java @@ -0,0 +1,297 @@ +package com.actionsoft.apps.coe.pal.pal.method.model; + +import java.io.Serializable; + +import com.actionsoft.apps.coe.pal.pal.method.util.PALMethodSchemaUtil; +import com.actionsoft.i18n.I18nRes; + +/** + * 建模方法基础信息model + */ +public class PALBasicMethodModel implements Serializable { + + /** + * methodId 全局唯一标识 + */ + private String id; + /** + * 所属资产库Id + */ + private String wsId; + /** + * 建模方法Id + */ + private String methodId; + /** + * 建模方法标题 + */ + private String title; + /** + * 建模方法标题-英文 + */ + private String titleEn; + /** + * 建模方法标题-繁体 + */ + private String titleBig5; + /** + * 建模方法描述 + */ + private String desc; + /** + * 建模方法描述-英文 + */ + private String descEn; + /** + * 建模方法描述-繁体 + */ + private String descBig5; + /** + * 建模方法所属的建模分类,多个之间,用逗号分割 + */ + private String category; + /** + * 所属appId + */ + private String appId; + /** + * 是否文件夹类型建模方法 + */ + private boolean isFolder; + /** + * 当前建模方法的分类 + */ + private String methodType; + /** + * 建模方法图标 + */ + private String iconCode; + /** + * 建模方法图标颜色 + */ + private String iconColor; + /** + * 支持的建模方式,多个则逗号分隔 + */ + private String modelingMode; + /** + * 默认的建模方式 + */ + private String defaultModelingMode; + /** + * 建模方法类型,normal:普通建模方法,image:图片库类型建模方法 + */ + private String type; + /** + * 形状排序 + */ + private String shapeSort; + /** + * 是否为自定义建模方法 + */ + private boolean isCustom; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getWsId() { + return wsId; + } + + public void setWsId(String wsId) { + this.wsId = wsId; + } + + public String getMethodId() { + return methodId; + } + + public void setMethodId(String methodId) { + this.methodId = methodId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitleEn() { + return titleEn; + } + + public void setTitleEn(String titleEn) { + this.titleEn = titleEn; + } + + public String getTitleBig5() { + return titleBig5; + } + + public void setTitleBig5(String titleBig5) { + this.titleBig5 = titleBig5; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + + public String getDescEn() { + return descEn; + } + + public void setDescEn(String descEn) { + this.descEn = descEn; + } + + public String getDescBig5() { + return descBig5; + } + + public void setDescBig5(String descBig5) { + this.descBig5 = descBig5; + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public boolean isFolder() { + return isFolder; + } + + public void setFolder(boolean folder) { + isFolder = folder; + } + + public String getMethodType() { + return methodType; + } + + public void setMethodType(String methodType) { + this.methodType = methodType; + } + + public String getIconCode() { + return iconCode; + } + + public void setIconCode(String iconCode) { + this.iconCode = iconCode; + } + + public String getIconColor() { + return iconColor; + } + + public void setIconColor(String iconColor) { + this.iconColor = iconColor; + } + + public String getModelingMode() { + return modelingMode; + } + + public void setModelingMode(String modelingMode) { + this.modelingMode = modelingMode; + } + + public String getDefaultModelingMode() { + return defaultModelingMode; + } + + public void setDefaultModelingMode(String defaultModelingMode) { + this.defaultModelingMode = defaultModelingMode; + } + + public String getSchema() { + return PALMethodSchemaUtil.getSchema(id, wsId); + } + + public String getCustomSchema() { + return ""; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getShapeSort() { + return shapeSort; + } + + public void setShapeSort(String shapeSort) { + this.shapeSort = shapeSort; + } + + public boolean isCustom() { + return isCustom; + } + + public void setCustom(boolean custom) { + isCustom = custom; + } + + /** + * title 多语言数据 标识:建模方法名称 + */ + public String getTitleI18N() { + String lang = I18nRes.getUserLanguage(); + if ("cn".equals(lang)) { + return title; + } else if ("en".equals(lang)) { + return titleEn; + } else if ("big5".equals(lang)) { + return titleBig5; + } + return desc; + } + + /** + * desc 多语言数据 + */ + public String getDescI18N() { + String lang = I18nRes.getUserLanguage(); + if ("cn".equals(lang)) { + return desc; + } else if ("en".equals(lang)) { + return descEn; + } else if ("big5".equals(lang)) { + return descBig5; + } + return desc; + } + + @Override + public String toString() { + return "PALBasicMethodModel{" + "id='" + id + '\'' + ", wsId='" + wsId + '\'' + ", methodId='" + methodId + '\'' + ", title='" + title + '\'' + ", titleEn='" + titleEn + '\'' + ", titleBig5='" + titleBig5 + '\'' + ", desc='" + desc + '\'' + ", descEn='" + descEn + '\'' + ", descBig5='" + descBig5 + '\'' + ", category='" + category + '\'' + ", appId='" + appId + '\'' + ", isFolder=" + isFolder + ", methodType='" + methodType + '\'' + ", iconCode='" + iconCode + '\'' + ", iconColor='" + iconColor + '\'' + ", modelingMode='" + modelingMode + '\'' + + ", defaultModelingMode='" + defaultModelingMode + '\'' + ", type='" + type + '\'' + ", shapeSort='" + shapeSort + '\'' + ", isCustom=" + isCustom + '}'; + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodAttributeModel.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodAttributeModel.java index 137fe1db..87f126e1 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodAttributeModel.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodAttributeModel.java @@ -33,6 +33,7 @@ public final class PALMethodAttributeModel implements Cloneable { //新增两个属性desc和isRequired private String desc; private boolean isRequired; + private int index;// 用于排序 /** * 该定义由哪个App提供 @@ -237,4 +238,14 @@ public final class PALMethodAttributeModel implements Cloneable { } return null; } + /** + * 用于排序 + */ + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } } diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodCategorySchemaModel.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodCategorySchemaModel.java new file mode 100644 index 00000000..dc64a1e8 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodCategorySchemaModel.java @@ -0,0 +1,108 @@ +package com.actionsoft.apps.coe.pal.pal.method.model; + +import java.io.Serializable; + +import com.actionsoft.i18n.I18nRes; +import com.alibaba.fastjson.JSONObject; + +/** + * 图元分组实体类 + */ +public class PALMethodCategorySchemaModel implements Serializable { + + /** + * 全局唯一标识(36位) + **/ + private String id; + + /** + * category标识 + */ + private String key; + + /** + * 分组标题-中文 + */ + private String text; + + /** + * 分组标题-英文 + */ + private String textEn; + + /** + * 分组标题-繁体 + */ + private String textBig5; + + /** + * category内容 + */ + private JSONObject content; + + public PALMethodCategorySchemaModel() { + } + + /** + * Getter And Setter + */ + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public String getTextEn() { + return textEn; + } + + public void setTextEn(String textEn) { + this.textEn = textEn; + } + + public String getTextBig5() { + return textBig5; + } + + public void setTextBig5(String textBig5) { + this.textBig5 = textBig5; + } + + public JSONObject getContent() { + return content; + } + + public void setContent(JSONObject content) { + this.content = content; + } + + public String getTextI18N() { + String lang = I18nRes.getUserLanguage(); + if ("cn".equals(lang)) { + return text; + } else if ("en".equals(lang)) { + return textEn; + } else if ("big5".equals(lang)) { + return textBig5; + } + return text; + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodFunctionSchemaModel.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodFunctionSchemaModel.java new file mode 100644 index 00000000..0224b88d --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodFunctionSchemaModel.java @@ -0,0 +1,49 @@ +package com.actionsoft.apps.coe.pal.pal.method.model; + +import java.io.Serializable; + +public class PALMethodFunctionSchemaModel implements Serializable { + + /** + * 全局唯一标识(36位) + */ + private String id; + + /** + * shape标识 + */ + private String key; + + /** + * shape内容 + */ + private String content; + + public PALMethodFunctionSchemaModel() { + + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodGlobalCommandSchemaModel.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodGlobalCommandSchemaModel.java new file mode 100644 index 00000000..3172493f --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodGlobalCommandSchemaModel.java @@ -0,0 +1,54 @@ +package com.actionsoft.apps.coe.pal.pal.method.model; + +import java.io.Serializable; + +import com.alibaba.fastjson.JSONArray; + +/** + * canvas片段引用实体类 + */ +public class PALMethodGlobalCommandSchemaModel implements Serializable { + + /** + * 全局唯一标识(36位) + */ + private String id; + + /** + * globalCommand标识 + */ + private String key; + + /** + * globalCommand内容 + */ + private JSONArray content; + + public PALMethodGlobalCommandSchemaModel() { + + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public JSONArray getContent() { + return content; + } + + public void setContent(JSONArray content) { + this.content = content; + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodSchemaModel.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodSchemaModel.java new file mode 100755 index 00000000..a6acccc5 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodSchemaModel.java @@ -0,0 +1,142 @@ +package com.actionsoft.apps.coe.pal.pal.method.model; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.collections.CollectionUtils; + +import com.actionsoft.apps.coe.pal.pal.method.util.PALMethodSchemaUtil; + +/** + * 形状定义schema + * + * @author sunlianhui + */ +public final class PALMethodSchemaModel implements Serializable { + private String id;// 全局唯一标识 + private String methodId;// 建模方法标识 + private String wsId;// 资产库Id + private String appId;// 哪个App提供的 + private String lang;// 语言标识 + private Long lastModified;// xml最后修改日期,用于scanner扫描更新 + private String schema;// 形状定义 + private String customSchema;// 自定义形状定义 + private List categorySchemaList;// 图元分组List + private List globalCommandSchemaList;// canvas片段引用List + private List shapeSchemaList;// 形状定义List + private List functionSchemaList;// 函数定义List + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getMethodId() { + return methodId; + } + + public void setMethodId(String methodId) { + this.methodId = methodId; + } + + public String getWsId() { + return wsId; + } + + public void setWsId(String wsId) { + this.wsId = wsId; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public String getLang() { + return lang; + } + + public void setLang(String lang) { + this.lang = lang; + } + + public Long getLastModified() { + return lastModified; + } + + public void setLastModified(Long lastModified) { + this.lastModified = lastModified; + } + + public String getSchema() { + return PALMethodSchemaUtil.getSchema(methodId, wsId); + } + + public void setSchema(String schema) { + this.schema = schema; + } + + public String getCustomSchema() { + return customSchema; + } + + public void setCustomSchema(String customSchema) { + this.customSchema = customSchema; + } + + public List getCategorySchemaList() { + if (CollectionUtils.isEmpty(categorySchemaList)) { + return new ArrayList<>(); + } + return categorySchemaList; + } + + public void setCategorySchemaList(List categorySchemaList) { + this.categorySchemaList = categorySchemaList; + } + + public List getGlobalCommandSchemaList() { + if (CollectionUtils.isEmpty(globalCommandSchemaList)) { + return new ArrayList<>(); + } + return globalCommandSchemaList; + } + + public void setGlobalCommandSchemaList(List globalCommandSchemaList) { + this.globalCommandSchemaList = globalCommandSchemaList; + } + + public List getShapeSchemaList() { + if (CollectionUtils.isEmpty(shapeSchemaList)) { + return new ArrayList<>(); + } + return shapeSchemaList; + } + + public void setShapeSchemaList(List shapeSchemaList) { + this.shapeSchemaList = shapeSchemaList; + } + + public List getFunctionSchemaList() { + if (CollectionUtils.isEmpty(functionSchemaList)) { + return new ArrayList<>(); + } + return functionSchemaList; + } + + public void setFunctionSchemaList(List functionSchemaList) { + this.functionSchemaList = functionSchemaList; + } + + @Override + public String toString() { + return "PALMethodSchemaModel{" + "id='" + id + '\'' + ", methodId='" + methodId + '\'' + ", appId='" + appId + '\'' + ", lang='" + lang + '\'' + ", lastModified=" + lastModified + ", schema='" + schema + '\'' + ", customSchema='" + customSchema + '\'' + '}'; + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodShapeSchemaModel.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodShapeSchemaModel.java new file mode 100644 index 00000000..8ad8d27f --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/model/PALMethodShapeSchemaModel.java @@ -0,0 +1,184 @@ +package com.actionsoft.apps.coe.pal.pal.method.model; + +import java.io.Serializable; + +import com.actionsoft.i18n.I18nRes; +import com.alibaba.fastjson.JSONObject; + +/** + * 形状定义实体类 + */ +public class PALMethodShapeSchemaModel implements Serializable { + + /** + * 全局位置标识(36位) + */ + private String id; + + /** + * shape标识 + */ + private String key; + + /** + * 样式分类(colorOverlay:颜色叠加,noColorOverlay:没有颜色叠加) + */ + private String styleType; + + /** + * 是否出厂自带的形状 + */ + private boolean isDefault; + + /** + * 形状类型(image:全部是图片类型,canvas:canvas画出来或canvas+图标类型) + */ + private String shapeType; + + /** + * 是否允许出现复制 + */ + private boolean allowOccurrence; + + /** + * 是否启用 + */ + private boolean isAvailable; + + /** + * 标题-中文 + */ + private String title; + + /** + * 标题-英文 + */ + private String titleEn; + + /** + * 标题-繁体 + */ + private String titleBig5; + + /** + * 是否为自定义图元 + */ + private boolean isCustomSchema; + + /** + * shape内容 + */ + private JSONObject content; + + public PALMethodShapeSchemaModel() { + + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getStyleType() { + return styleType; + } + + public void setStyleType(String styleType) { + this.styleType = styleType; + } + + public boolean isDefault() { + return isDefault; + } + + public void setDefault(boolean aDefault) { + isDefault = aDefault; + } + + public String getShapeType() { + return shapeType; + } + + public void setShapeType(String shapeType) { + this.shapeType = shapeType; + } + + public boolean isAllowOccurrence() { + return allowOccurrence; + } + + public void setAllowOccurrence(boolean allowOccurrence) { + this.allowOccurrence = allowOccurrence; + } + + public boolean isAvailable() { + return isAvailable; + } + + public void setAvailable(boolean available) { + isAvailable = available; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitleEn() { + return titleEn; + } + + public void setTitleEn(String titleEn) { + this.titleEn = titleEn; + } + + public String getTitleBig5() { + return titleBig5; + } + + public void setTitleBig5(String titleBig5) { + this.titleBig5 = titleBig5; + } + + public boolean isCustomSchema() { + return isCustomSchema; + } + + public void setCustomSchema(boolean customSchema) { + isCustomSchema = customSchema; + } + + public JSONObject getContent() { + return content; + } + + public void setContent(JSONObject content) { + this.content = content; + } + + public String getTitleI18N() { + String lang = I18nRes.getUserLanguage(); + if ("cn".equals(lang)) { + return title; + } else if ("en".equals(lang)) { + return titleEn; + } else if ("big5".equals(lang)) { + return titleBig5; + } + return title; + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/util/PALMethodSchemaUtil.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/util/PALMethodSchemaUtil.java new file mode 100644 index 00000000..c95868c1 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/util/PALMethodSchemaUtil.java @@ -0,0 +1,888 @@ +package com.actionsoft.apps.coe.pal.pal.method.util; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.actionsoft.apps.coe.pal.pal.method.cache.PALBasicMethodCache; +import com.actionsoft.apps.coe.pal.pal.method.cache.PALMethodSchemaCache; +import com.actionsoft.apps.coe.pal.pal.method.constant.MethodSchemaConst; +import com.actionsoft.apps.coe.pal.pal.method.model.PALBasicMethodModel; +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodCategorySchemaModel; +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodFunctionSchemaModel; +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodGlobalCommandSchemaModel; +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodSchemaModel; +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodShapeSchemaModel; +import com.actionsoft.apps.coe.pal.pal.repository.designer.image.util.CoeDesignerImageUtil; +import com.actionsoft.bpms.server.conf.portal.AWSPortalConf; +import com.actionsoft.i18n.I18nRes; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + +public class PALMethodSchemaUtil { + + private static final Logger LOGGER = LoggerFactory.getLogger(PALMethodSchemaUtil.class); + + public static String getSchema(String methodId, String wsId) { + + PALBasicMethodModel basicModel = PALBasicMethodCache.getModelByMethodIdAndWsId(methodId, wsId); + PALMethodSchemaModel schemaModel = PALMethodSchemaCache.getModelListByMethodIdAndLangAndWsId(methodId, I18nRes.getUserLanguage(), wsId); + if (schemaModel == null || basicModel == null) { + return ""; + } + + StringBuilder schemaBuilder = new StringBuilder(); + + // 拼接图元分组 + List categorySchemaList = schemaModel.getCategorySchemaList(); + if (CollectionUtils.isNotEmpty(categorySchemaList)) { + for (PALMethodCategorySchemaModel categorySchema : categorySchemaList) { + JSONObject content = categorySchema.getContent(); + String contentStr = content.toJSONString(); + if (StringUtils.isEmpty(contentStr)) { + continue; + } + String replace = MethodSchemaConst.SCHEMA_CATEGORY.replace("*?", contentStr); + schemaBuilder.append(replace); + } + } + + // 拼接function + List functionSchemaList = schemaModel.getFunctionSchemaList(); + if (CollectionUtils.isNotEmpty(functionSchemaList)) { + for (PALMethodFunctionSchemaModel functionSchemaModel : functionSchemaList) { + String content = functionSchemaModel.getContent(); + if (StringUtils.isEmpty(content)) { + continue; + } + schemaBuilder.append(content); + schemaBuilder.append("\r\n"); + } + } + + // 拼接canvas引用片段 + List globalCommandSchemaList = schemaModel.getGlobalCommandSchemaList(); + if (CollectionUtils.isNotEmpty(globalCommandSchemaList)) { + for (PALMethodGlobalCommandSchemaModel globalCommandSchemaModel : globalCommandSchemaList) { + String key = globalCommandSchemaModel.getKey(); + JSONArray content = globalCommandSchemaModel.getContent(); + if (content == null || content.isEmpty() || StringUtils.isEmpty(key)) { + continue; + } + String contentStr = content.toJSONString(); + String replace = MethodSchemaConst.SCHEMA_GLOBAL_COMMAND.replace("*?", "\"" + key + "\", " + contentStr); + schemaBuilder.append(replace); + } + } + // 拼接形状定义 + String shapeSort = basicModel.getShapeSort(); + if (shapeSort == null) { + shapeSort = ""; + } + List shapeSortList = new ArrayList<>(Arrays.asList(shapeSort.split(","))); + Map schemaMap = new HashMap<>(); + List shapeSchemaList = schemaModel.getShapeSchemaList(); + if (CollectionUtils.isNotEmpty(shapeSchemaList)) { + for (PALMethodShapeSchemaModel shapeSchemaModel : shapeSchemaList) { + // 禁用则跳过 + if (!shapeSchemaModel.isAvailable()) { + continue; + } + JSONObject content = shapeSchemaModel.getContent(); + if (content == null || content.isEmpty()) { + continue; + } + String png = "../apps/" + schemaModel.getAppId() + "/img/method/" + methodId + "/icon/" + shapeSchemaModel.getKey() + ".png"; + String schemaPng = ""; + // 是否使用canvas + boolean isCanvasDraw = false; + // 临时转换png为base64 + try { + File file = new File(AWSPortalConf.getLocation() + png.substring(3)); + if (!shapeSchemaModel.isCustomSchema() && file.exists()) { + // schemaPng = png; + schemaPng = CoeDesignerImageUtil.convertCommonImageToBase64(file); + } else { + isCanvasDraw = true; + } + } catch (IOException e) { + LOGGER.error("图片转base64失败,路径{}", png, e); + } + content.put("schemaPng", schemaPng); + content.put("isCanvasDraw", isCanvasDraw); + String contentStr = content.toJSONString(); + String replace = MethodSchemaConst.SCHEMA_SHAPE.replace("*?", contentStr); + schemaMap.put(replace, shapeSortList.indexOf(shapeSchemaModel.getKey())); + } + // 将Map转换为List并排序 + List sortedKeys = schemaMap.entrySet().stream().sorted(Map.Entry.comparingByValue()).map(Map.Entry::getKey).collect(Collectors.toList()); + schemaBuilder.append(String.join("", sortedKeys)); + } + return schemaBuilder.toString(); + } +// +// /** +// * 获取形状Map +// * +// * @param wsId 资产库Id +// * @param methodId 建模方法Id +// * @param shapes map +// */ +// public static void getShapesMap(String wsId, String methodId, Map shapes) { +// String lang = I18nRes.getUserLanguage(); +// PALMethodSchemaModel schemaModel = PALMethodSchemaCache.getModelListByMethodIdAndLangAndWsId(methodId, lang, wsId); +// if (schemaModel == null) { +// return; +// } +// List shapeSchemaList = schemaModel.getShapeSchemaList(); +// for (PALMethodShapeSchemaModel shapeSchemaModel : shapeSchemaList) { +// String name = shapeSchemaModel.getKey(); +// shapes.put(name, shapeSchemaModel.getTitleI18N()); +// } +// } +// +// /** +// * 更新形状定义缓存 +// * 通过给定的建模方法ID和原始的形状定义,更新针对所有语言的模式缓存。 +// * +// * @param methodId 建模方法ID +// * @param originalSchema schema定义 +// */ +// public static void updateSchemaCache(String methodId, String originalSchema, String wsId) { +// PALBasicMethodModel basicModel = PALBasicMethodCache.getModelByMethodIdAndWsId(methodId, wsId); +// if (basicModel != null) { +// String appId = basicModel.getAppId(); +// List languageModels = AWSPortalConf.getLanguages(); +// for (LanguageModel languageModel : languageModels) { +// String lang = languageModel.getName(); +// String schema = transformSchemaByLanguage(appId, originalSchema, lang); +// PALMethodSchemaCache.getModelListByMethodIdAndLangAndWsId(methodId, lang, wsId).setSchema(schema); +// } +// } +// } +// +// /** +// * 更新自定义的形状定义缓存 +// * 通过给定的建模方法ID和原始的自定义形状定义,更新针对所有语言的模式缓存。 +// * +// * @param methodId 建模方法ID +// * @param originalSchema 自定义schema定义 +// */ +// public static void updateCustomSchemaCache(String methodId, String originalSchema, String wsId) { +// PALBasicMethodModel basicModel = PALBasicMethodCache.getModelByMethodIdAndWsId(methodId, wsId); +// if (basicModel != null) { +// String appId = basicModel.getAppId(); +// List languageModels = AWSPortalConf.getLanguages(); +// for (LanguageModel languageModel : languageModels) { +// String lang = languageModel.getName(); +// String customSchema = transformSchemaByLanguage(appId, originalSchema, lang); +// PALMethodSchemaCache.getModelListByMethodIdAndLangAndWsId(methodId, lang, wsId).setCustomSchema(customSchema); +// } +// } +// } +// +// /** +// * 更新指定应用下指定建模方法的自定义形状定义缓存 +// * +// * @param app AppContext对象 +// * @param methodId 建模方法ID +// * @param fileName 自定义形状定义文件名称 +// * 该方法通过建模方法ID和文件名从应用的建模方法中加载自定义形状定义内容,然后更新对应的自定义形状定义缓存。 +// */ +// public static void updateCustomSchemaCache(AppContext app, String methodId, String fileName, String wsId, boolean isCustom) { +// String customSchema = MethodAppManager.loadCustomSchemaByApp(app, methodId, fileName, wsId, isCustom); +// updateCustomSchemaCache(methodId, customSchema, wsId); +// } +// +// /** +// * 更新指定应用下指定建模方法的形状定义缓存 +// * +// * @param app AppContext对象 +// * @param methodId 建模方法ID +// * @param fileName 形状定义文件名称 +// * 该方法通过建模方法ID和文件名从应用的建模方法中加载形状定义内容,然后更新对应的形状定义缓存。 +// */ +// public static void updateSchemaCache(AppContext app, String methodId, String fileName, String wsId, boolean isCustom) { +// String schema = MethodAppManager.loadSchemaByApp(app, methodId, fileName, wsId, isCustom); +// updateSchemaCache(methodId, schema, wsId); +// } +// +// /** +// * 根据指定语言翻译形状定义信息 +// * +// * @param app AppContext对象 +// * @param originalSchema 原始形状定义信息 +// * @param lang 目标语言代码,指定要将词汇翻译成的语言,例如cn、en、big5 +// * @return 转换后的模式字符串,其中的关键词被翻译成指定语言 +// */ +// public static String transformSchemaByLanguage(AppContext app, String originalSchema, String lang) { +// return transformSchemaByLanguage(app.getId(), originalSchema, lang); +// } +// +// /** +// * 根据指定语言翻译形状定义信息 +// * +// * @param appId 应用ID +// * @param originalSchema 原始形状定义信息 +// * @param lang 目标语言代码,指定要将词汇翻译成的语言,例如cn、en、big5 +// * @return 转换后的模式字符串,其中的关键词被翻译成指定语言 +// */ +// public static String transformSchemaByLanguage(String appId, String originalSchema, String lang) { +// Map> map = I18nRes.getResourceMapByApp(appId); +// // 对map的键进行排序,确保更长的键先被处理,并且只包含中文字符的键被加入 +// Map> sortedMap = new TreeMap<>(Comparator.comparingInt(String::length).reversed() // 首先根据字符串长度排序 +// .thenComparing(Comparator.naturalOrder())); // 长度相同则根据字符串的自然顺序排序 +// +// // 正则表达式,用于检测字符串中是否包含中文字符(不含中文字符,会造成后续判断误伤) +// String chineseCharactersPattern = "[\u4e00-\u9fa5]"; +// +// // 过滤并放入sortedMap +// for (Map.Entry> entry : map.entrySet()) { +// if (entry.getKey().matches(".*" + chineseCharactersPattern + ".*")) { +// sortedMap.put(entry.getKey(), entry.getValue()); +// } +// } +// +// StringBuilder result = new StringBuilder(); +// int start = 0; +// +// // 遍历替换 +// for (int i = 0; i < originalSchema.length(); i++) { +// if (originalSchema.charAt(i) == '"') { // 检测到双引号,寻找下一个双引号以确定完整的词汇 +// int nextQuote = originalSchema.indexOf('"', i + 1); +// if (nextQuote > i) { +// String completeWord = originalSchema.substring(i, nextQuote + 1); // 包括双引号的完整词汇 +// for (String key : sortedMap.keySet()) { +// // 如果找到匹配的完整词汇 +// if (completeWord.contains("\"" + key + "\"")) { +// String replacement = sortedMap.get(key).containsKey(lang) ? sortedMap.get(key).get(lang) : sortedMap.get(key).get("cn"); +// completeWord = completeWord.replace("\"" + key + "\"", "\"" + replacement + "\""); +// } +// } +// result.append(originalSchema, start, i).append(completeWord); // 添加替换后的完整词汇 +// i = nextQuote; // 跳到下一个双引号之后 +// start = i + 1; +// } +// } +// } +// if (start < originalSchema.length()) { +// result.append(originalSchema.substring(start)); // 添加剩余部分 +// } +// return result.toString(); +// } +// +// private static JSONObject transformContentByLanguage(String methodId, Element element, String content, String lang, String elementType) { +// return transformContentByLanguage(methodId, element, content, lang, elementType, "", ""); +// } +// +// /** +// * 根据指定语言翻译形状定义信息 +// * +// * @param element xml中需要国际化的标签元素 +// * @param content 原始形状定义信息 +// * @param lang 目标语言代码,指定要将词汇翻译成的语言,例如cn、en、big5 +// * @param elementType 标签元素类型(category:图元分组,shape:形状定义) +// * @param drawIcon shape中drawIcon函数 +// * @param onCreated shape中onCreated函数 +// * @return 转换后的模式jsonObject对象 +// */ +// private static JSONObject transformContentByLanguage(String methodId, Element element, String content, String lang, String elementType, String drawIcon, String onCreated) { +// if (StringUtils.isEmpty(content)) { +// return new JSONObject(); +// } +// String type = ""; +// String replace = ""; +// +// if ("category".equals(elementType)) { +// type = "text"; +// } else if ("shape".equals(elementType)) { +// type = "title"; +// } +// +// if ("cn".equals(lang)) { +// replace = element.attributeValue(type); +// } else if ("en".equals(lang)) { +// replace = element.attributeValue(type + "-en"); +// } else if ("big5".equals(lang)) { +// replace = element.attributeValue(type + "-big5"); +// } +// JSONObject contentObj; +// try { +// // 替换所有换行以及前后空格 +// content = content.replaceAll("\\s*\\n\\s*", ""); +// contentObj = JSONObject.parseObject(content); +// if ("category".equals(elementType)) { +// // 替换text +// contentObj.put("text", replace); +// } else if ("shape".equals(elementType)) { +// if (UtilString.isNotEmpty(replace)) { +// contentObj.put("title", replace); +// } +// } +// if (StringUtils.isNotEmpty(drawIcon)) { +// contentObj.put("drawIcon", drawIcon); +// } +// if (StringUtils.isNotEmpty(onCreated)) { +// contentObj.put("onCreated", onCreated); +// } +// } catch (JSONException e) { +// LOGGER.error("[methodId={}, key={}]String transform to JSONObject error:{}", methodId, element.attributeValue("key"), content, e); +// return new JSONObject(); +// } +// +// return contentObj; +// } +// +// /** +// * 加载默认的例如基础形状、泳池泳道这类公共的形状定义 +// * +// * @param methodId 建模方法ID +// * @param fileName tpl文件名称 +// */ +// public static void loadDefaultSchemaCache(String methodId, String fileName) { +// String path = AppsAPIManager.getInstance().getAppContext(CoEConstant.APP_ID).getPath() + PALMethodConst.DIR_ROOT_CONFIG + fileName; +// Document xmlDocument = XMLUtil.readXML(path); +// if (xmlDocument != null) { +// List languageModels = AWSPortalConf.getLanguages(); +// for (LanguageModel languageModel : languageModels) { +// String lang = languageModel.getName(); +// PALMethodSchemaModel psmm = new PALMethodSchemaModel(); +// psmm.setId(PALMethodUtil.getMethodSchemaModelId("default", CoEConstant.APP_ID, methodId, lang)); +// psmm.setMethodId(methodId); +// psmm.setAppId(CoEConstant.APP_ID); +// psmm.setLang(lang); +// psmm.setWsId("default"); +// //psmm.setSchema(PALMethodSchemaUtil.transformSchemaByLanguage(CoEConstant.APP_ID, basicTpl, lang)); +// buildSchemaConfig(CoEConstant.APP_ID, methodId, psmm, xmlDocument, lang, null); +// // 放入缓存 +// PALMethodSchemaCache.putModel(psmm); +// } +// } +// } +// +// /** +// * 初始化 diagram.schema.xml 文件 +// */ +// public static void initSchemaXml(DCContext configDc, String wsId, String methodId, PALBasicMethodModel basicModel) { +// DCContext dcContext = configDc.clone(); +// dcContext.setFileName(MethodConfigEnum.SCHEMA_CONFIG.getFile()); +// Document document = DocumentHelper.createDocument(); +// Element schema = document.addElement("schema"); +// Element categories = schema.addElement("categories"); +// Element category = categories.addElement("category"); +// String categoryStr = handleMethodToCategory(methodId); +// category.addAttribute("key", categoryStr); +// category.addAttribute("text", basicModel.getTitle()); +// category.addAttribute("text-en", basicModel.getTitleEn()); +// category.addAttribute("text-big5", basicModel.getTitleBig5()); +// JSONObject jo = new JSONObject(); +// jo.put("name", categoryStr); +// jo.put("text", basicModel.getTitle()); +// jo.put("dataAttributes", new JSONArray()); +// category.setText(jo.toJSONString()); +// // 新增三个空标签 +// schema.addElement("functions"); +// schema.addElement("globalCommands"); +// schema.addElement("shapes"); +// +// XMLUtil.writeXml(document, dcContext); +// +// // 缓存重新加载 +// PALMethodSchemaUtil.reloadCache(CoEConstant.APP_ID, wsId, methodId, document, null); +// } +// +// /** +// * 建模方法转category +// */ +// public static String handleMethodToCategory(String methodId) { +// if (methodId == null) { +// return null; +// } +// return methodId.replace("_", "-").replace(".", "_"); +// } +// +// /** +// * 构建schema配置。 +// * 该方法通过解析XML文档,构建出图元分类、函数、全局命令和形状定义等配置信息,并填充到PALMethodSchemaModel对象中。 +// * +// * @param appId AppId。 +// * @param psmm PAL方法模式模型,用于接收构建好的schema配置信息。 +// * @param schemaDocument schema文档,包含待解析的XML文档。 +// * @param lang 语言代码,指定解析时使用的语言。 +// * @param schemaKeys 图元key集合,用于判断是否为自定义图元 +// */ +// public static void buildSchemaConfig(String appId, String methodId, PALMethodSchemaModel psmm, Document schemaDocument, String lang, Set schemaKeys) { +// try { +// Element rootElement = schemaDocument.getRootElement(); +// +// // 构建图元分类 +// List categoryList = buildSchemaList(methodId, rootElement, MethodSchemaEnum.SCHEMA_CATEGORY, PALMethodCategorySchemaModel.class, appId, lang); +// psmm.setCategorySchemaList(categoryList); +// +// // 构建function +// List functionList = buildSchemaList(methodId, rootElement, MethodSchemaEnum.SCHEMA_FUNCTION, PALMethodFunctionSchemaModel.class, appId, lang); +// psmm.setFunctionSchemaList(functionList); +// +// // 构建canvas片段引用 +// List globalCommandList = buildSchemaList(methodId, rootElement, MethodSchemaEnum.SCHEMA_GLOBAL_COMMAND, PALMethodGlobalCommandSchemaModel.class, appId, lang); +// psmm.setGlobalCommandSchemaList(globalCommandList); +// +// // 构建形状定义 +// List shapeList = buildSchemaList(methodId, rootElement, MethodSchemaEnum.SCHEMA_SHAPE, PALMethodShapeSchemaModel.class, appId, lang, schemaKeys); +// psmm.setShapeSchemaList(shapeList); +// +// } catch (Exception e) { +// LOGGER.error(e.getMessage(), e); +// } +// } +// +// /** +// * 重新加载 图元缓存数据 +// */ +// public static void reloadCache(String appId, String wsId, String methodId, Document document, Set schemaKeys) { +// // 缓存更新 +// PALMethodSchemaCache.removeByMethodIdAndWsId(methodId, wsId); +// List languageModels = AWSPortalConf.getLanguages(); +// for (LanguageModel languageModel : languageModels) { +// String lang = languageModel.getName(); +// PALMethodSchemaModel psmm = new PALMethodSchemaModel(); +// psmm.setId(PALMethodUtil.getMethodSchemaModelId(wsId, appId, methodId, lang)); +// psmm.setAppId(appId); +// psmm.setMethodId(methodId); +// psmm.setWsId(wsId); +// psmm.setLang(lang); +// PALMethodSchemaUtil.buildSchemaConfig(appId, methodId, psmm, document, lang, schemaKeys); +// // 放入缓存 +// PALMethodSchemaCache.putModel(psmm); +// } +// } +// +// /** +// * 根据给定的XML根元素,构建并返回一个模型列表。 +// * +// * @param rootElement XML文档的根元素。 +// * @param schemaEnum 指定的模式枚举,用于确定要解析的XML子元素。 +// * @param modelClass 模型类的Class对象,用于实例化模型对象。 +// * @param appId 应用Id +// * @param lang 国际化参数 +// * @return 返回一个包含解析和实例化后模型对象的列表。 +// */ +// private static List buildSchemaList(String methodId, Element rootElement, MethodSchemaEnum schemaEnum, Class modelClass, String appId, String lang) { +// return buildSchemaList(methodId, rootElement, schemaEnum, modelClass, appId, lang, null); +// } +// +// /** +// * 根据给定的XML根元素,构建并返回一个模型列表。 +// * +// * @param rootElement XML文档的根元素。 +// * @param schemaEnum 指定的模式枚举,用于确定要解析的XML子元素。 +// * @param modelClass 模型类的Class对象,用于实例化模型对象。 +// * @param appId 应用Id +// * @param lang 国际化参数 +// * @param schemaKeys 图元key集合,用于判断是否为自定义图元 +// * @return 返回一个包含解析和实例化后模型对象的列表。 +// */ +// private static List buildSchemaList(String methodId, Element rootElement, MethodSchemaEnum schemaEnum, Class modelClass, String appId, String lang, Set schemaKeys) { +// List modelList = new ArrayList<>(); +// Element schemaElement = rootElement.element(schemaEnum.getTagGroupName()); +// if (schemaElement != null) { +// List elements = schemaElement.elements(schemaEnum.getTagName()); +// for (Element element : elements) { +// T model; +// try { +// // 实例化 +// model = modelClass.getDeclaredConstructor().newInstance(); +// // 设置公共部分 +// model.getClass().getMethod("setId", String.class).invoke(model, UUIDGener.getUUID()); +// model.getClass().getMethod("setKey", String.class).invoke(model, element.attributeValue("key")); +// +// // 设置PALMethodCategorySchemaModel独有部分 +// Method textMethod = CoEReflectionUtils.findMethod(model.getClass(), "setText", String.class); +// if (textMethod != null && StringUtils.isNotEmpty(element.attributeValue("text"))) { +// textMethod.invoke(model, element.attributeValue("text")); +// } +// Method textEnMethod = CoEReflectionUtils.findMethod(model.getClass(), "setTextEn", String.class); +// if (textEnMethod != null && StringUtils.isNotEmpty(element.attributeValue("text-en"))) { +// textEnMethod.invoke(model, element.attributeValue("text-en")); +// } +// Method textBig5Method = CoEReflectionUtils.findMethod(model.getClass(), "setTextBig5", String.class); +// if (textBig5Method != null && StringUtils.isNotEmpty(element.attributeValue("text-big5"))) { +// textBig5Method.invoke(model, element.attributeValue("text-big5")); +// } +// +// // 设置PALMethodShapeSchemaModel独有部分 +// Method styleTypeMethod = CoEReflectionUtils.findMethod(model.getClass(), "setStyleType", String.class); +// if (styleTypeMethod != null && StringUtils.isNotEmpty(element.attributeValue("styleType"))) { +// styleTypeMethod.invoke(model, element.attributeValue("styleType")); +// } +// Method defaultMethod = CoEReflectionUtils.findMethod(model.getClass(), "setDefault", boolean.class); +// if (defaultMethod != null && StringUtils.isNotEmpty(element.attributeValue("isDefault"))) { +// defaultMethod.invoke(model, Boolean.valueOf(element.attributeValue("isDefault"))); +// } +// Method shapeTypeMethod = CoEReflectionUtils.findMethod(model.getClass(), "setShapeType", String.class); +// if (shapeTypeMethod != null && StringUtils.isNotEmpty(element.attributeValue("shapeType"))) { +// shapeTypeMethod.invoke(model, element.attributeValue("shapeType")); +// } +// Method allowOccurenceMethod = CoEReflectionUtils.findMethod(model.getClass(), "setAllowOccurrence", boolean.class); +// if (allowOccurenceMethod != null && StringUtils.isNotEmpty(element.attributeValue("allowOccurrence"))) { +// allowOccurenceMethod.invoke(model, Boolean.valueOf(element.attributeValue("allowOccurrence"))); +// } +// Method availableMethod = CoEReflectionUtils.findMethod(model.getClass(), "setAvailable", boolean.class); +// if (availableMethod != null && StringUtils.isNotEmpty(element.attributeValue("isAvailable"))) { +// availableMethod.invoke(model, Boolean.valueOf(element.attributeValue("isAvailable"))); +// } +// Method titleMethod = CoEReflectionUtils.findMethod(model.getClass(), "setTitle", String.class); +// if (titleMethod != null && StringUtils.isNotEmpty(element.attributeValue("title"))) { +// titleMethod.invoke(model, element.attributeValue("title")); +// } +// Method titleEnMethod = CoEReflectionUtils.findMethod(model.getClass(), "setTitleEn", String.class); +// if (titleEnMethod != null && StringUtils.isNotEmpty(element.attributeValue("title-en"))) { +// titleEnMethod.invoke(model, element.attributeValue("title-en")); +// } +// Method titleBig5Method = CoEReflectionUtils.findMethod(model.getClass(), "setTitleBig5", String.class); +// if (titleBig5Method != null && StringUtils.isNotEmpty(element.attributeValue("title-big5"))) { +// titleBig5Method.invoke(model, element.attributeValue("title-big5")); +// } +// if (schemaKeys != null) { +// Method customSchemaMethod = CoEReflectionUtils.findMethod(model.getClass(), "setCustomSchema", boolean.class); +// if (customSchemaMethod != null) { +// customSchemaMethod.invoke(model, schemaKeys.contains(element.attributeValue("key"))); +// } +// } +// +// // 设置content部分 +// String content = element.getText(); +// String drawIcon = ""; +// String onCreated = ""; +// Element drawIconElement = element.element("drawIcon"); +// if (drawIconElement != null) { +// drawIcon = drawIconElement.getText(); +// } +// Element onCreatedElement = element.element("onCreated"); +// if (onCreatedElement != null) { +// onCreated = onCreatedElement.getText(); +// } +// if (schemaEnum.name().equals(MethodSchemaEnum.SCHEMA_FUNCTION.name())) { +// model.getClass().getMethod("setContent", String.class).invoke(model, content); +// } else if (schemaEnum.name().equals(MethodSchemaEnum.SCHEMA_CATEGORY.name())) { +// // 对图元分组content进行国际化处理 +// JSONObject contentObj = transformContentByLanguage(methodId, element, content, lang, "category"); +// model.getClass().getMethod("setContent", JSONObject.class).invoke(model, contentObj); +// } else if (schemaEnum.name().equals(MethodSchemaEnum.SCHEMA_SHAPE.name())) { +// // 对形状定义进行国际化处理 +// JSONObject contentObj = transformContentByLanguage(methodId, element, content, lang, "shape", drawIcon, onCreated); +// // 放入建模方法Id +// contentObj.put("methodId", methodId); +// model.getClass().getMethod("setContent", JSONObject.class).invoke(model, contentObj); +// } else if (schemaEnum.name().equals(MethodSchemaEnum.SCHEMA_GLOBAL_COMMAND.name())) { +// try { +// model.getClass().getMethod("setContent", JSONArray.class).invoke(model, JSONArray.parseArray(content)); +// } catch (JSONException e) { +// LOGGER.error("[method={}, key={}]String transform to JSONArray error:{}", methodId, element.attributeValue("key"), content, e); +// } +// } +// modelList.add(model); +// } catch (Exception e) { +// // 适当的异常处理逻辑 +// LOGGER.error(e.getMessage(), e); +// } +// } +// } +// return modelList; +// } +// +// /** +// * 返回对应图元id的 model数据 +// */ +// public static PALMethodShapeSchemaModel getShapeSchemaBySchemaId(String wsId, String methodId, String lang, String schemaId) { +// PALMethodSchemaModel schemaModel = PALMethodSchemaCache.getModelListByMethodIdAndLangAndWsId(methodId, lang, wsId); +// if (schemaModel != null) { +// return schemaModel.getShapeSchemaList().stream().filter(item -> item.getKey().equals(schemaId)).findFirst().orElse(null); +// } +// return null; +// } +// +// /** +// * 获取 默认 globalCommand 数据 +// */ +// public static JSONObject getDefaultGlobalCommand() { +// JSONObject jo = new JSONObject(); +// String rectangle = "[{\n" + " action: \"move\",\n" + " x: \"0\",\n" + " y: \"0\"\n" + "},\n" + " {\n" + " action: \"line\",\n" + " x: \"w\",\n" + " y: \"0\"\n" + " },\n" + " {\n" + " action: \"line\",\n" + " x: \"w\",\n" + " y: \"h\"\n" + " },\n" + " {\n" + " action: \"line\",\n" + " x: \"0\",\n" + " y: \"h\"\n" + " },\n" + " {\n" + " action: \"close\"\n" + " }]"; +// jo.put("rectangle", JSONArray.parseArray(rectangle)); +// String round = "[{\n" + " action: \"move\",\n" + " x: \"0\",\n" + " y: \"h/2\"\n" + "},\n" + " {\n" + " action: \"curve\",\n" + " x1: \"0\",\n" + " y1: \"-h/6\",\n" + " x2: \"w\",\n" + " y2: \"-h/6\",\n" + " x: \"w\",\n" + " y: \"h/2\"\n" + " },\n" + " {\n" + " action: \"curve\",\n" + " x1: \"w\",\n" + " y1: \"h+h/6\",\n" + " x2: \"0\",\n" + " y2: \"h+h/6\",\n" + " x: \"0\",\n" + " y: \"h/2\"\n" + " },\n" + " {\n" + " action: \"close\"\n" + " }]"; +// jo.put("round", JSONArray.parseArray(round)); +// String roundRectangle = +// "[{\n" + " action: \"move\",\n" + " x: \"0\",\n" + " y: \"4\"\n" + "},\n" + " {\n" + " action: \"quadraticCurve\",\n" + " x1: \"0\",\n" + " y1: \"0\",\n" + " x: \"4\",\n" + " y: \"0\"\n" + " },\n" + " {\n" + " action: \"line\",\n" + " x: \"w-4\",\n" + " y: \"0\"\n" + " },\n" + " {\n" + " action: \"quadraticCurve\",\n" + " x1: \"w\",\n" + " y1: \"0\",\n" + " x: \"w\",\n" + " y: \"4\"\n" + " },\n" + " {\n" + " action: \"line\",\n" + " x: \"w\",\n" + " y: \"h-4\"\n" + " },\n" + " {\n" + " action: \"quadraticCurve\",\n" + " x1: \"w\",\n" +// + " y1: \"h\",\n" + " x: \"w-4\",\n" + " y: \"h\"\n" + " },\n" + " {\n" + " action: \"line\",\n" + " x: \"4\",\n" + " y: \"h\"\n" + " },\n" + " {\n" + " action: \"quadraticCurve\",\n" + " x1: \"0\",\n" + " y1: \"h\",\n" + " x: \"0\",\n" + " y: \"h-4\"\n" + " },\n" + " {\n" + " action: \"close\"\n" + " }]"; +// jo.put("roundRectangle", JSONArray.parseArray(roundRectangle)); +// return jo; +// } +// +// /** +// * 获取图元中 图片的 base64 数据 +// * +// * @param wsId 资产库id +// * @param methodId 建模方法 +// * @param schemaTypeEnum 图元类型枚举 +// * @param isCustom 是否自定义 +// * @param schemaDataModel 图元数据model +// */ +// public static JSONObject getImageBase64InSchemaData(String wsId, String methodId, PalSchemaTypeEnum schemaTypeEnum, boolean isCustom, PalSchemaDataModel schemaDataModel) { +// String iconFileName = ""; +// JSONObject jo = new JSONObject(); +// String imageId = null; +// String oldImagePath = null; +// JSONArray pathJa = schemaDataModel.getPath(); +// if (pathJa != null) { +// for (int i = 0; i < pathJa.size(); i++) { +// JSONObject pathJo = pathJa.getJSONObject(i); +// if (schemaTypeEnum == PalSchemaTypeEnum.CANVAS) { +// if (pathJo.containsKey("iconImage")) { +// JSONObject iconImage = pathJo.getJSONObject("iconImage"); +// imageId = iconImage.getString("imageId"); +// iconFileName = iconImage.getString("iconFileName"); +// break; +// } +// } +// if (schemaTypeEnum == PalSchemaTypeEnum.IMAGE) { +// if (pathJo.containsKey("fillStyle")) { +// JSONObject fillStyle = pathJo.getJSONObject("fillStyle"); +// String type = fillStyle.getString("type"); +// String fileId = fillStyle.getString("fileId"); +// iconFileName = fillStyle.getString("iconFileName"); +// if ("imageDef".equals(type) && fileId != null) { +// imageId = fileId; +// break; +// } +// if ("image".equals(type) && fileId != null) { +// oldImagePath = fileId; +// break; +// } +// } +// } +// } +// } +// jo.put("base64", ""); +// jo.put("iconFileName", iconFileName); +// if (imageId != null) { +// DCContext imageFileDc = PALWorkSpaceMethodConfigUtil.getMethodConfigDc(wsId, methodId, imageId, isCustom); +// jo.put("imageFilePath", imageFileDc.getFilePath()); +// jo.put("base64", CoeDcUtil.dcContextToString(imageFileDc)); +// } +// if (oldImagePath != null) { +// // 以../apps开头默认为web下目录,替换路径 +// if (oldImagePath.indexOf("../apps") == 0) { +// oldImagePath = AWSPortalConf.getLocation() + oldImagePath.substring(3); +// } +// File imageFile = new File(oldImagePath.replaceAll("\\.svg$", ".png")); +// try { +// String base64 = CoeDesignerImageUtil.convertCommonImageToBase64(imageFile); +// jo.put("imageFilePath", imageFile.getAbsolutePath()); +// jo.put("base64", base64); +// jo.put("iconFileName", imageFile.getName()); +// } catch (IOException e) { +// LOGGER.error("文件转换base64失败,文件路径{}", imageFile.getPath(), e); +// throw new AWSException("文件转换base64失败"); +// } +// } +// return jo; +// } +// +// /** +// * 获取iconColor +// */ +// public static String getIconColor(JSONArray iconJa) { +// String iconColor = "51,51,51"; +// for (int i = 0; i < iconJa.size(); i++) { +// JSONObject iconJo = iconJa.getJSONObject(i); +// JSONObject lineStyle = iconJo.getJSONObject("lineStyle"); +// JSONObject fillStyle = iconJo.getJSONObject("fillStyle"); +// if (lineStyle != null) { +// String lineColor = lineStyle.getString("lineColor"); +// if (lineColor != null) { +// iconColor = lineColor; +// } +// } +// if (fillStyle != null) { +// String fillColor = fillStyle.getString("color"); +// if (fillColor != null) { +// iconColor = fillColor; +// } +// } +// } +// return iconColor; +// } +// +// /** +// * 获取形状是否允许出现复制 +// * +// * @param wsId 资产库Id +// * @param methodId 建模方法Id +// * @param shapeName 形状name +// * @return 是否允许出现复制 +// */ +// public static boolean getSchemaShapeAllowOccurrence(String wsId, String methodId, String shapeName) { +// PALMethodSchemaModel schemaModel = PALMethodSchemaCache.getModelListByMethodIdAndLangAndWsId(methodId, I18nRes.getUserLanguage(), wsId); +// if (schemaModel == null) { +// return false; +// } +// List shapeSchemaList = schemaModel.getShapeSchemaList(); +// for (PALMethodShapeSchemaModel shapeSchema : shapeSchemaList) { +// if (shapeSchema.getKey().equals(shapeName)) { +// return shapeSchema.isAllowOccurrence(); +// } +// } +// return false; +// } +// +// /** +// * 获取当前资产库下所有形状定义文件里面的functions定义 +// * +// * @param wsId 资产库ID +// * @return 当前资产库下所有形状定义文件里面的functions定义 +// */ +// public static JSONObject getMethodFunctions(String wsId) { +// List methodList = new ArrayList<>(); +// List categories = PALMethodCache.getPALMethodList(true, wsId); +// for (String category : categories) { +// methodList.addAll(PALMethodCache.getPALMethodModelListByMethod(category, wsId)); +// } +// // 单独处理泳池泳道和基本形状 +// PALMethodModel lane = PALMethodCache.getPALMethodModelById("lane", wsId); +// if (lane != null) { +// methodList.add(lane); +// } +// PALMethodModel basic = PALMethodCache.getPALMethodModelById("basic", wsId); +// if (basic != null) { +// methodList.add(basic); +// } +// List methodIds = methodList.stream().map(PALMethodModel::getMethodId).collect(Collectors.toList()); +// // 获取所有的functions +// return getMethodIdsFunctions(wsId, methodIds); +// } +// +// /** +// * 获取当前资产库下建模方法的functions定义 +// * +// * @param wsId 资产库ID +// * @param methodIds 建模方法ID集合 +// * @return 获取当前资产库下建模方法的functions定义 +// */ +// public static JSONObject getMethodIdsFunctions(String wsId, List methodIds) { +// JSONObject functionObj = new JSONObject(); +// // 获取所有的functions +// for (String methodId : methodIds) { +// PALMethodSchemaModel schemaModel = PALMethodSchemaCache.getModelListByMethodIdAndLangAndWsId(methodId, I18nRes.getUserLanguage(), wsId); +// if (schemaModel == null) { +// continue; +// } +// // 拼接function +// List functionSchemaList = schemaModel.getFunctionSchemaList(); +// if (CollectionUtils.isNotEmpty(functionSchemaList)) { +// for (PALMethodFunctionSchemaModel functionSchemaModel : functionSchemaList) { +// String content = functionSchemaModel.getContent(); +// String key = functionSchemaModel.getKey(); +// if (StringUtils.isEmpty(content)) { +// continue; +// } +// content = content.trim(); +// // 使用正则表达式提取函数名称 +// String functionName = extractFunctionName(key); +// // 转换函数声明格式 +// content = transformFunctionDeclaration(content, functionName); +// functionObj.put(functionName, content); +// } +// } +// } +// return functionObj; +// } +// +// /** +// * 转换函数声明格式 +// */ +// public static String transformFunctionDeclaration(String content, String functionName) { +// // 检查输入是否为空或不以"function"开头 +// if (UtilString.isEmpty(content) || UtilString.isEmpty(functionName) || !content.trim().startsWith("function")) { +// return content; +// } +// // 替换函数名称 +// return content.replaceFirst("^\\s*function\\s+" + functionName, "function"); +// } +// +// /** +// * 使用正则表达式提取函数名称 +// */ +// private static String extractFunctionName(String key) { +// String regex = "^(\\w+)\\("; +// Pattern pattern = Pattern.compile(regex); +// Matcher matcher = pattern.matcher(key); +// if (matcher.find()) { +// return matcher.group(1); +// } +// return ""; +// } +// +// /** +// * 获取图元数据 +// */ +// public static String getSchemaByMethodIds(boolean isAdmin, String wsId, String methodId, List methodIds) { +// StringBuilder shapes = new StringBuilder(); +// PALMethodModel mModel = PALMethodCache.getPALMethodModelByMethodIdAndWsId(methodId, wsId); +// +// // 是否允许用户自定义模板,0:不允许;1:允许。 +// String isCustomDefine = SDK.getAppAPI().getProperty(CoEConstant.APP_ID, CoEConstant.PROPERTY_CUSTOM_DEFINE_SCHEMA); +// +// if (mModel != null) { +// String schema = mModel.getSchema(); +// shapes.append(schema).append("\r\n"); +// } +// for (String cate : methodIds) { +// if ("basic".equals(cate)) { +// shapes.append(PALMethodCache.getBasicTpl(wsId)).append("\r\n"); +// continue; +// } +// if ("lane".equals(cate)) { +// String laneTpl = PALMethodCache.getLaneTpl(wsId); +// shapes.append(laneTpl).append("\r\n"); +// continue; +// } +// PALMethodModel methodModel = PALMethodCache.getPALMethodModelByMethodIdAndWsId(cate, wsId); +// if (methodModel == null) { +// continue; +// } +// String schema = methodModel.getSchema(); +// if ("0".equals(isCustomDefine)) { +// shapes.append(schema).append("\r\n"); +// } else { +// if (isAdmin) { +// shapes.append(schema).append("\r\n"); +// } else { +// shapes.append(MethodSchemaConst.SCHEMA_SHAPE.replace("*?", schema)).append("\r\n"); +// } +// shapes.append(methodModel.getCustomSchema()).append("\r\n"); +// } +// } +// return shapes.toString(); +// } +// +// /** +// * 获取图元数据 根据建模方法ID +// */ +// public static String getSchemaByMethodId(String wsId, String methodId) { +// PALMethodModel model = PALMethodCache.getPALMethodModelByMethodIdAndWsId(methodId, wsId); +// if (model == null) { +// return ""; +// } +// return model.getSchema(); +// } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/util/PALMethodUtil.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/util/PALMethodUtil.java index 22174538..f3ed9ca0 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/util/PALMethodUtil.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/method/util/PALMethodUtil.java @@ -14,6 +14,8 @@ import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodModel; import com.actionsoft.apps.coe.pal.system.logger.CoeLogger; import com.actionsoft.apps.coe.pal.system.property.CoePropertyUtil; import com.actionsoft.i18n.I18nRes; +import com.actionsoft.apps.coe.pal.pal.method.model.PALBasicMethodModel; +import com.actionsoft.apps.coe.pal.pal.method.cache.PALBasicMethodCache; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -286,4 +288,32 @@ public class PALMethodUtil { // System.out.println(getShapeDialog("process.epc","basic")); } + + /** + * 获取建模方法的图标 + * + * @param methodId + * @return + */ + public static JSONObject getPALMethodIconById(String methodId, String wsId) { + String code = ""; + String color = ""; + if ("default".equals(methodId)) {// 默认文件夹 + code = ""; + color = "#FFB718"; + } else { + PALBasicMethodModel model = PALBasicMethodCache.getModelByMethodIdAndWsId(methodId, wsId); + if (model == null) { + code = ""; + color = "#FFB718"; + } else { + code = model.getIconCode(); + color = model.getIconColor(); + } + } + JSONObject result = new JSONObject(); + result.put("code", code); + result.put("color", color); + return result; + } } diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/CoeDesignerShapeAPIManager.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/CoeDesignerShapeAPIManager.java index 6fc49534..c3bdd709 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/CoeDesignerShapeAPIManager.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/CoeDesignerShapeAPIManager.java @@ -2,6 +2,8 @@ package com.actionsoft.apps.coe.pal.pal.repository.designer; import java.io.File; import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; import com.actionsoft.apps.coe.pal.pal.manage.util.PalManageUtil; import com.actionsoft.bpms.bpmn.engine.cache.ProcessDefCache; @@ -1431,5 +1433,15 @@ public class CoeDesignerShapeAPIManager { } return jsVal; } + /** + * 获取所有已排序的有效且使用中的形状属性 + * + * @param wsId 资产库ID + * @param methodId 建模方法ID + * @return key 为 attrKey value 为 PALMethodAttributeModel + */ + public Map getAllValidAndUseShapeAttributeModelsMap(String wsId, String methodId) { + return getAllValidAndUseShapeAttributeModels(wsId, methodId).stream().collect(Collectors.toMap(PALMethodAttributeModel::getKey, Function.identity())); + } } diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/constant/CoeDesignerConstant.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/constant/CoeDesignerConstant.java index 8ebc1879..0cbabcd4 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/constant/CoeDesignerConstant.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/constant/CoeDesignerConstant.java @@ -96,5 +96,9 @@ public class CoeDesignerConstant { public final static int ADAPTER_DESGINER_PROCESS = 1; public final static int REALTIME_LISTEN_TIME = 30; + /** + * 版本对比页面 + */ + public final static String DESIGNER_VERSION_COMPARE_PAGE = "pal.pl.repository.designer.graph.versionCompare.htm"; } diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/constant/DiffNodeTypeEnum.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/constant/DiffNodeTypeEnum.java new file mode 100644 index 00000000..170d8206 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/constant/DiffNodeTypeEnum.java @@ -0,0 +1,59 @@ +package com.actionsoft.apps.coe.pal.pal.repository.designer.constant; + +/** + * @author oYang + * @Description 节点变化类型(连线只有新增) + * @createTime 2024年08月07日 11:47:00 + */ +public enum DiffNodeTypeEnum { + + /** + * 新增 + */ + ADD("add", "新增"), + + /** + * 删除 + */ + DELETE("delete", "删除"), + + /** + * 位置 + */ + POSITION("position", "位置"), + + /** + * 信息 + */ + INFO("info", "信息"), + + /** + * 样式 + */ + STYLE("style", "样式"); + + private final String code; + private final String desc; + + DiffNodeTypeEnum(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public static DiffNodeTypeEnum getByCode(String code) { + for (DiffNodeTypeEnum type : DiffNodeTypeEnum.values()) { + if (type.getCode().equals(code)) { + return type; + } + } + return null; + } + + public String getCode() { + return code; + } + + public String getDesc() { + return desc; + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/dto/VersionCompareDTO.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/dto/VersionCompareDTO.java new file mode 100644 index 00000000..59871aa2 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/dto/VersionCompareDTO.java @@ -0,0 +1,56 @@ +package com.actionsoft.apps.coe.pal.pal.repository.designer.dto; + +/** + * @author oYang + * @Description 版本对比参数 + * @createTime 2024年08月02日 11:43:00 + */ +public class VersionCompareDTO { + + private String wsId; + private String teamId; + private String compareVerId; + private String curId; + + public VersionCompareDTO() { + } + + public VersionCompareDTO(String wsId, String teamId, String compareVerId, String curId) { + this.wsId = wsId; + this.teamId = teamId; + this.compareVerId = compareVerId; + this.curId = curId; + } + + public String getWsId() { + return wsId; + } + + public void setWsId(String wsId) { + this.wsId = wsId; + } + + public String getTeamId() { + return teamId; + } + + public void setTeamId(String teamId) { + this.teamId = teamId; + } + + public String getCompareVerId() { + return compareVerId; + } + + public void setCompareVerId(String compareVerId) { + this.compareVerId = compareVerId; + } + + public String getCurId() { + return curId; + } + + public void setCurId(String curId) { + this.curId = curId; + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/image/util/CoeDesignerImageUtil.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/image/util/CoeDesignerImageUtil.java new file mode 100644 index 00000000..ec056f6a --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/image/util/CoeDesignerImageUtil.java @@ -0,0 +1,411 @@ +package com.actionsoft.apps.coe.pal.pal.repository.designer.image.util; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.Base64; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.batik.ext.awt.image.codec.imageio.ImageIOJPEGImageWriter; +import org.apache.batik.ext.awt.image.spi.ImageWriterRegistry; +import org.apache.batik.transcoder.TranscoderException; +import org.apache.batik.transcoder.TranscoderInput; +import org.apache.batik.transcoder.TranscoderOutput; +import org.apache.batik.transcoder.image.JPEGTranscoder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.actionsoft.apps.coe.pal.constant.CoEConstant; +import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache; +import com.actionsoft.apps.coe.pal.pal.repository.designer.constant.CoeDesignerConstant; +//import com.actionsoft.apps.coe.pal.pal.repository.designer.image.dao.CoeUserShapeImageDao; +//import com.actionsoft.apps.coe.pal.pal.repository.designer.image.model.CoeUserShapeImageModel; +//import com.actionsoft.apps.coe.pal.pal.repository.designer.util.CoeDesignerDcUtil; +import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel; +import com.actionsoft.apps.coe.pal.util.CoeDcUtil; +import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile; +import com.actionsoft.bpms.server.fs.DCContext; +import com.actionsoft.bpms.server.fs.dc.DCProfileManager; +import com.actionsoft.bpms.server.fs.dc.DCUtil; +import com.actionsoft.bpms.util.UtilFile; +import com.actionsoft.bpms.util.UtilString; +import com.actionsoft.exception.AWSException; +import com.actionsoft.i18n.I18nRes; +import com.actionsoft.sdk.local.SDK; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + +/** + * 设计器图片处理工具类 + */ +public class CoeDesignerImageUtil { + + private static final Logger LOGGER = LoggerFactory.getLogger(CoeDesignerImageUtil.class); + + /** + * 图片正则校验 + */ + public static final String imgReg = ".*\\.(jpg|jpeg|png|gif|svg|tiff|bmp)$"; + +// /** +// * 获取前端上传DC的临时目录 +// * +// * @param userId 用户id +// */ +// public static DCContext getTmpShapeImageDc(String userId) { +// return DCUtil.createTempFileContext(CoEConstant.APP_ID, CoeDesignerConstant.DESIGNER_SHAPE_IMAGES, userId, null); +// } +// +// /** +// * 获取 形状图片数据 名称,内容数据
+// * 即key:imageId, value:图片的base64 数据 +// * +// * @param wsId 资产库id +// * @param uuid 模型id +// */ +// public static JSONObject getImageBase64Jo(String wsId, String uuid) { +// DCContext defineDc = CoeDesignerDcUtil.getDefineDc(wsId, uuid); +// return getImageBase64JoByPlDc(defineDc); +// } +// +// /** +// * 获取 形状图片数据 名称,内容数据
+// * 即key:imageId, value:图片的base64 数据 +// * +// * @param dcContext 模型文件所在的DC对象 +// */ +// public static JSONObject getImageBase64JoByPlDc(DCContext dcContext) { +// JSONObject result = new JSONObject(); +// if (dcContext == null) { +// return result; +// } +// dcContext.setFileName(CoeDesignerConstant.PL_IMAGE_FILE_NAME); +// if (dcContext.existFile()) { +// JSONArray array = CoeDcUtil.dcContextToJa(dcContext); +// for (int i = 0; i < array.size(); i++) { +// String name = array.getString(i); +// if (name.contains(".")) { +// continue; +// } +// dcContext.setFileName(name); +// String base64 = CoeDcUtil.dcContextToString(dcContext); +// result.put(name, base64); +// } +// } +// return result; +// } +// +// /** +// * 处理 形状图片文件夹 shapeimages +// */ +// public static void handleShapeImagesByDefine(JSONObject definition, PALRepositoryModel plModel, boolean isCustom) { +// // 获取形状 json中 形状图片 fileId 内容集合 +// List shapeImageList = new ArrayList<>(); +// JSONObject elements = definition.getJSONObject("elements"); +// for (String key : elements.keySet()) { +// JSONObject shape = elements.getJSONObject(key); +// // 统计形状文件id +// if (shape.containsKey("fillStyle")) { +// JSONObject fillStyle = shape.getJSONObject("fillStyle"); +// String fileId = fillStyle.getString("fileId"); +// if (fileId != null) { +// shapeImageList.add(fileId); +// } +// } +// if (shape.containsKey("path")) { +// JSONArray pathJa = shape.getJSONArray("path"); +// for (int i = 0; i < pathJa.size(); i++) { +// JSONObject path = pathJa.getJSONObject(i); +// if (path.containsKey("fillStyle")) { +// JSONObject fillStyle = path.getJSONObject("fillStyle"); +// String fileId = fillStyle.getString("fileId"); +// if (fileId != null) { +// shapeImageList.add(fileId); +// } +// } +// if (path.containsKey("iconImage")) { +// JSONObject iconImage = path.getJSONObject("iconImage"); +// String imageId = iconImage.getString("imageId"); +// if (imageId != null) { +// shapeImageList.add(imageId); +// } +// } +// } +// } +// } +// // 生成并复制图片定义中的图片 并删除冗余文件 +// CoeDesignerImageDefUtil.generateAndCopyImageDef(shapeImageList, plModel.getWsId(), plModel.getMethodId(), plModel.getId(), isCustom); +// } +// +// /** +// * 组装 define 数据 在 fillStyle和path 中添加 base64数据。 +// */ +// public static String wrapperShapeImagesIntoDefine(String define, PALRepositoryModel plModel) { +// JSONObject imageBase64Jo = CoeDesignerImageUtil.getImageBase64Jo(plModel.getWsId(), plModel.getId()); +// return wrapperShapeImagesIntoDefine(define, imageBase64Jo); +// } +// +// /** +// * 组装 define 数据 在 fillStyle和path 中添加 base64数据。 +// */ +// public static String wrapperShapeImagesIntoDefine(String define, JSONObject imageBase64Jo) { +// if (UtilString.isEmpty(define) || imageBase64Jo == null || imageBase64Jo.isEmpty()) { +// return define; +// } +// JSONObject definition = JSONObject.parseObject(define); +// JSONObject elements = definition.getJSONObject("elements"); +// for (String key : elements.keySet()) { +// JSONObject shape = elements.getJSONObject(key); +// JSONObject fillStyle = shape.getJSONObject("fillStyle"); +// if (fillStyle != null) { +// // 数据为paste的来源 +// String fileId = fillStyle.getString("fileId"); +// String from = fillStyle.getString("from"); +// // 存在 fileId 及 from +// if (fileId != null && from != null) { +// if (imageBase64Jo.containsKey(fileId)) { +// fillStyle.put("base64", imageBase64Jo.getString(fileId)); +// } else { +// LOGGER.error("图片生成处理,填充图片错误[错误],图片ID:{}", fileId); +// } +// } +// } +// JSONArray pathJa = shape.getJSONArray("path"); +// if (pathJa != null) { +// for (int i = 0; i < pathJa.size(); i++) { +// JSONObject path = pathJa.getJSONObject(i); +// JSONObject pathFileStyle = path.getJSONObject("fillStyle"); +// if (pathFileStyle != null) { +// String fileId = pathFileStyle.getString("fileId"); +// if (fileId != null) { +// if (imageBase64Jo.containsKey(fileId)) { +// pathFileStyle.put("base64", imageBase64Jo.getString(fileId)); +// } else { +// LOGGER.error("图片生成处理,填充图元icon错误[错误],图片ID:{}", fileId); +// } +// } +// } +// } +// } +// } +// return definition.toJSONString(); +// } +// +// /** +// * 将base64转换为bytes数据 +// * +// * @param base64String 图片image +// * @return base64数据 +// */ +// public static byte[] convertBase64ToBytes(String base64String) { +// // 组装参数 +// try { +// // 去掉"data:image/png;base64,"前缀 +// String[] baseSplit = base64String.split(","); +// String base64Data; +// String imageType = "png"; +// // 定义正则表达式 +// String regex = "data:image\\/([^;]+);base64"; +// if (baseSplit.length > 1) { +// // 获取图片类型 +// base64Data = baseSplit[1]; +// // 编译正则表达式 +// Pattern pattern = Pattern.compile(regex); +// // 创建匹配器 +// Matcher matcher = pattern.matcher(baseSplit[0]); +// // 使用非贪婪匹配 +// if (matcher.find()) { +// imageType = matcher.group(1); +// // 处理svg类型 +// if ("svg+xml".equalsIgnoreCase(imageType)) { +// imageType = "svg"; +// } +// } +// } else { +// base64Data = baseSplit[0]; +// } +// byte[] bytes = Base64.getDecoder().decode(base64Data); +// if ("svg".equals(imageType)) { +// String base64Str = svgBytesToBase64(bytes); +// base64Str = base64Str.replaceAll("\r?\n", ""); +// bytes = Base64.getDecoder().decode(base64Str); +// // 存入携带前缀的base64数据 +// } +// return bytes; +// } catch (TranscoderException e) { +// throw new AWSException(I18nRes.findValue(CoEConstant.APP_ID, "base64数据存储错误"), e); +// } +// } +// +// /** +// * 将图片转存储为base64 转 PNG + base64 存储两个文件、且删除原文件 +// * +// * @param imageFileDc 图片文件 +// */ +// public static String dumpImageToBase64(DCContext imageFileDc) { +// try { +// String fileName = imageFileDc.getFileName(); +// if (!imageFileDc.existFile() || !fileName.contains(".")) { +// return ""; +// } +// // 获取无后缀的路径 +// int i = fileName.lastIndexOf("."); +// String sFileName = fileName.substring(0, i); +// String base64String; +// if (fileName.endsWith(".svg")) { +// base64String = convertSvgToBase64(imageFileDc); +// } else { +// base64String = convertCommonImageToBase64(imageFileDc); +// } +// if (!fileName.matches(".png$")) { +// // 删除原本文件 +// imageFileDc.delete(); +// // 将base64转为png存储 +// imageFileDc.setFileName(sFileName + ".png"); +// SDK.getDCAPI().write(base64StringToInputStream(base64String), imageFileDc); +// } +// // 将base64直接存入文件 +// DCContext cloneImageFileDc = imageFileDc.clone(); +// cloneImageFileDc.setFileName(sFileName); +// base64String = base64String.replaceAll("\\s", "+"); +// CoeDcUtil.write(base64String, cloneImageFileDc); +// return base64String; +// } catch (IOException e) { +// throw new AWSException(I18nRes.findValue(CoEConstant.APP_ID, "图片存储失败")); +// } +// } + + /** + * 常规图片转base64 + */ + public static String convertCommonImageToBase64(DCContext imageFileDc) throws IOException { + byte[] bytes = CoeDcUtil.dcContextToByte(imageFileDc); + return "data:image/png;base64," + Base64.getEncoder().encodeToString(bytes); + } + + /** + * 常规图片转base64 + */ + public static String convertCommonImageToBase64(File imageFile) throws IOException { + byte[] imageBytes = Files.readAllBytes(imageFile.toPath()); + return "data:image/png;base64," + Base64.getEncoder().encodeToString(imageBytes); + } + +// /** +// * 转换svg图片为base64 +// */ +// private static String convertSvgToBase64(DCContext imageFileDc) { +// byte[] bytes = CoeDcUtil.dcContextToByte(imageFileDc); +// try { +// String base64Str = svgBytesToBase64(bytes); +// base64Str = base64Str.replaceAll("\r?\n", ""); +// return "data:image/png;base64," + base64Str; +// } catch (Exception e) { +// throw new AWSException(I18nRes.findValue(CoEConstant.APP_ID, "转换svg文件发生错误"), e); +// } +// } +// +// /** +// * svg 二进制数据 转换为 base64 数据 +// */ +// private static String svgBytesToBase64(byte[] bytes) throws TranscoderException { +// String decodedSvg = new String(bytes, StandardCharsets.UTF_8); +// if (decodedSvg.contains("href=\"")) { +// String substring = decodedSvg.substring(decodedSvg.indexOf("href=\"") + 6, decodedSvg.lastIndexOf("\"")); +// if (substring.split("\\.").length > 1) { +// return substring.split("\\.")[1]; +// } else { +// return substring; +// } +// } else if (!decodedSvg.contains(" +// * 即 DC/shapeimages/userId/imageId/ +// */ +// public static DCContext getCommonShapeImageDc(String userId, String imageId, String fileName) { +// DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeDesignerConstant.DESIGNER_SHAPE_IMAGES); +// return new DCContext(null, dcProfile, CoEConstant.APP_ID, userId, imageId, fileName); +// } +// +// /** +// * 依据用户删除文件目录 +// */ +// public static void deleteDirByUserId(String userId) { +// List imageModels = new CoeUserShapeImageDao().queryListByUserId(userId); +// for (CoeUserShapeImageModel imageModel : imageModels) { +// DCContext commonShapeImageDc = getCommonShapeImageDc(userId, imageModel.getImageId(), imageModel.getFileName()); +// commonShapeImageDc.delete(); +// } +// } +// +// /** +// * 获取图片base64内容并转换为 InputStream 对象 +// */ +// @Deprecated +// public static InputStream getShapeImagesIS(String filePath) { +// UtilFile file = new UtilFile(filePath); +// if (file.exists()) { +// if (!file.getName().contains(".")) { +// String base64String = file.readStrUTF8(); +// String base64Data = base64String.substring(base64String.indexOf(",") + 1); +// base64Data = base64Data.replaceAll("\\s", "+"); +// byte[] bytes = Base64.getDecoder().decode(base64Data); +// return new ByteArrayInputStream(bytes); +// } +// } +// return null; +// } +// +// /** +// * 获取图片base64内容并转换为 InputStream 对象 +// */ +// public static InputStream getShapeImagesIS(String plId, String imageId) { +// PALRepositoryModel plModel = PALRepositoryCache.getCache().get(plId); +// if (plModel != null) { +// DCContext dcContext = CoeDesignerDcUtil.getDefineDc(plModel.getWsId(), plModel.getId()); +// dcContext.setFileName(imageId); +// if (dcContext.existFile()) { +// return base64StringToInputStream(CoeDcUtil.dcContextToString(dcContext)); +// } +// } +// return null; +// } +// +// /** +// * 将 Base64 编码的字符串转换为 InputStream。 +// * +// * @param base64String Base64 编码的字符串 +// * @return 转换后的 InputStream +// */ +// public static InputStream base64StringToInputStream(String base64String) { +// if (UtilString.isEmpty(base64String)) { +// return null; +// } +// // 解码 Base64 字符串为字节数组 +// byte[] bytes = Base64.getDecoder().decode(base64String.replace("data:image/png;base64,", "")); +// // 创建 ByteArrayInputStream +// return new ByteArrayInputStream(bytes); +// } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/util/DesignerVersionUtil.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/util/DesignerVersionUtil.java index e82d440b..18c86968 100644 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/util/DesignerVersionUtil.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/util/DesignerVersionUtil.java @@ -3,22 +3,59 @@ package com.actionsoft.apps.coe.pal.pal.repository.designer.util; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.IteratorUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.actionsoft.apps.coe.pal.components.model.PALSecurityLevelModel; +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodAttributeModel; +import com.actionsoft.apps.coe.pal.pal.method.util.PALMethodUtil; import com.actionsoft.apps.coe.pal.pal.processexec.ProcessExecAPIManager; +import com.actionsoft.apps.coe.pal.pal.repository.PALRepositoryAPIManager; import com.actionsoft.apps.coe.pal.pal.repository.PALRepositoryQueryAPIManager; import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache; +import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryPropertyCache; +import com.actionsoft.apps.coe.pal.pal.repository.designer.CoeDesignerShapeAPIManager; +import com.actionsoft.apps.coe.pal.pal.repository.designer.constant.DiffNodeTypeEnum; import com.actionsoft.apps.coe.pal.pal.repository.designer.constant.VersionStatusEnum; +import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.cache.DesignerShapeRelationCache; +import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.dao.DesignerShapeRelationDao; +import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.model.DesignerShapeRelationModel; +import com.actionsoft.apps.coe.pal.pal.repository.designer.vo.AttrVO; +import com.actionsoft.apps.coe.pal.pal.repository.designer.vo.DiffNodeVO; +import com.actionsoft.apps.coe.pal.pal.repository.designer.vo.ShapeLinkVO; +import com.actionsoft.apps.coe.pal.pal.repository.designer.vo.UpFileVO; import com.actionsoft.apps.coe.pal.pal.repository.designer.vo.VersionListVO; import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel; +import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryPropertyModel; +import com.actionsoft.apps.coe.pal.pal.repository.upfile.cache.PALUpfileCache; +import com.actionsoft.apps.coe.pal.pal.repository.upfile.model.UpfileModel; +import com.actionsoft.apps.coe.pal.pal.repository.upfile.util.CoeUpFileUtil; import com.actionsoft.apps.coe.pal.pal.ws.web.VersionUtil; +import com.actionsoft.apps.coe.pal.util.HighSecurityUtil; import com.actionsoft.bpms.bpmn.engine.model.def.ProcessDefinition; +import com.actionsoft.bpms.org.model.DepartmentModel; +import com.actionsoft.bpms.org.model.RoleModel; +import com.actionsoft.bpms.org.model.UserModel; +import com.actionsoft.bpms.server.UserContext; +import com.actionsoft.bpms.server.fs.DCContext; import com.actionsoft.bpms.util.UtilDate; +import com.actionsoft.bpms.util.UtilString; import com.actionsoft.sdk.local.SDK; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; /** * @author oYang @@ -140,4 +177,1231 @@ public class DesignerVersionUtil { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); return sdf.format(date); } + + /** + * 获取版本对比数据 + * + * @param plId pal模型Id + */ + public static JSONObject getVersionData(UserContext uc, String plId, String teamId) { + PALRepositoryModel plModel = PALRepositoryCache.getCache().get(plId); + if (plModel == null) { + return null; + } + String definition = PALRepositoryQueryAPIManager.getInstance().getProcessDefinition(uc, plId); + return getVersionData(uc, plModel, teamId, definition); + } + + + /** + * 获取版本对比数据 + * + * @param plModel pal模型 + */ + public static JSONObject getVersionData(UserContext uc, PALRepositoryModel plModel, String teamId, String definition) { + if (plModel == null) { + return null; + } + String plId = plModel.getId(); + JSONObject result = new JSONObject(); + // 版本号 + String versionNo = String.valueOf(plModel.getVersion()); + result.put("versionNo", versionNo); + result.put("plId", plId); + result.put("updateTime", getModifyDate(plModel.getModifyDate())); + // 模型定义信息 + result.put("definition", definition); + // 形状属性 + Map attrKeyAndModelMap = CoeDesignerShapeAPIManager.getInstance().getAllValidAndUseShapeAttributeModelsMap(plModel.getWsId(), plModel.getMethodId()); + Map> shapeAttr = getShapeAttrForCompare(uc, plId, definition, attrKeyAndModelMap); + result.put("shapeAttr", shapeAttr); + // 形状附件 + Map shapeFile = getShapeFileList(uc, plId, definition); + result.put("shapeUpFile", shapeFile); + // 形状关联附件 + Map relationShapeFileList = getRelationShapeFileList(uc, plId, definition); + result.put("shapeRelationUpFile", relationShapeFileList); + // 形状链接 + Map shapeLink = getShapeLinkList(uc, definition, teamId); + result.put("shapeLink", shapeLink); + // 文件属性 + List fileAttrForCompare = getFileAttrForCompare(uc, plId); + result.put("fileAttr", fileAttrForCompare); + // 文件附件 + JSONObject fileUpFileList = getFileUpFileList(uc, plId); + result.put("fileUpFile", fileUpFileList); + // 文件关联附件 + JSONObject fileRelationUpFileList = getFileRelationUpFileList(uc, plId); + result.put("fileRelationUpFile", fileRelationUpFileList); + return result; + } + + /** + * 获取形状Id集合 + * + * @param definition 模型定义信息 + * @return List + */ + public static List getShapeIdsByDefinition(String definition) { + JSONObject definitionObj = validateDefinition(definition); + if (definitionObj == null) { + return null; + } + JSONObject elements = definitionObj.getJSONObject("elements"); + return elements.values().stream().map(o -> (JSONObject) o).filter(o -> !"linker".equals(o.getString("name"))).map(o -> o.getString("id")).collect(Collectors.toList()); + } + + /** + * 获取形状属性 + * + * @param definition 模型定义信息 + */ + public static Map> getShapeAttrForCompare(UserContext uc, String plId, String definition, Map attrKeyAndModelMap) { + JSONObject definitionObj = validateDefinition(definition); + + if (definitionObj != null) { + JSONObject elements = definitionObj.getJSONObject("elements"); + List listOfShapeId = getShapeIdsByDefinition(definition); + if (CollectionUtils.isNotEmpty(listOfShapeId)) { + Map> mapOfShapeAttr = new HashMap<>(); + listOfShapeId.forEach(shapeId -> { + List listOfShapeAttr = new ArrayList<>(); + JSONObject shape = elements.getJSONObject(shapeId); + if (shape.containsKey("dataAttributes")) { + JSONArray dataAttributes = shape.getJSONArray("dataAttributes"); + if (CollectionUtils.isNotEmpty(dataAttributes)) { + dataAttributes.stream().map(o -> (JSONObject) o).forEach(o -> { + if (o.containsKey("attributesJsonArray")) { + JSONArray attributesJsonArray = o.getJSONArray("attributesJsonArray"); + attributesJsonArray.stream().map(item -> (JSONObject) item).forEach(item -> { + String key = item.getString("key"); + if (attrKeyAndModelMap.containsKey(key)) { + PALMethodAttributeModel attrModel = attrKeyAndModelMap.get(key); + String name = attrModel.getNewTitle(); + String type = attrModel.getType(); + Object value = item.getString("value"); + String ref = attrModel.getRef(); + + Map shapeAttrValue = getShapeAttrValue(uc, plId, shapeId, type, key, value, ref); + value = shapeAttrValue.get("value"); + Object compareAccord = shapeAttrValue.get("compareAccord"); + AttrVO shapeAttrVO = AttrVO.Builder.createBuilder().withId(key).withName(name).withType(type).withValue(value).withCompareAccord(compareAccord).withIsDiff(false).build(); + listOfShapeAttr.add(shapeAttrVO); + } + }); + } + }); + } + } + sortAttrVO(listOfShapeAttr, attrKeyAndModelMap); + mapOfShapeAttr.put(shapeId, listOfShapeAttr); + }); + return mapOfShapeAttr; + } + } + return null; + } + + private static Map getShapeAttrValue(UserContext uc, String plId, String shapeId, String type, String attrId, Object value, String ref) { + Map result = null; + switch (type) { + case "relation": + result = getShapeAttrOfRelation(plId, shapeId, attrId, ref); + break; + case "awsorg": + result = getShapeAttrOfAwsOrg(plId, shapeId, attrId); + break; + case "file": + result = getShapeAttrUpFileList(uc, plId, shapeId, attrId); + break; + default: + result = new HashMap<>(); + result.put("value", value); + result.put("compareAccord", sortStringContent(value.toString())); + break; + } + return result; + } + + /** + * 获取形状属性(附件信息) + * + * @param uc 用户上下文 + * @param plId pal模型Id + * @param shapeId 形状Id + * @param attrId 属性Id + * @return Map + */ + public static Map getShapeAttrUpFileList(UserContext uc, String plId, String shapeId, String attrId) { + JSONArray listOfFileAttrValue = new JSONArray(); + JSONArray listOfCompareAccord = new JSONArray(); + List upfileModelList = PALUpfileCache.getByPlUuid(plId); + upfileModelList = upfileModelList.stream().filter(upfileModel -> upfileModel.getType().equals("a")).filter(upfileModel -> shapeId.equals(upfileModel.getShape_uuid())).filter(upfileModel -> attrId.equals(upfileModel.getAttrId())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(upfileModelList)) { + upfileModelList.forEach(upfileModel -> { + JSONObject valueObj = new JSONObject(); + String fileName = upfileModel.getFileName(); + String downloadUrl = getDownloadUrl(uc, upfileModel); + valueObj.put("fileName", fileName); + valueObj.put("downloadUrl", downloadUrl); + listOfFileAttrValue.add(valueObj); + String compareAccord = upfileModel.getShape_uuid() + "_" + upfileModel.getAttrId() + "_" + upfileModel.getFileName(); + listOfCompareAccord.add(compareAccord); + }); + } + Map mapOfFileAttrValue = new HashMap<>(); + mapOfFileAttrValue.put("value", listOfFileAttrValue); + mapOfFileAttrValue.put("compareAccord", listOfCompareAccord); + return mapOfFileAttrValue; + } + + /** + * 获取形状属性(模型关联) + * + * @param plId pal模型Id + * @param shapeId 形状Id + * @param attrId 属性Id + * @param ref 关联属性配置信息 + * @return Map + */ + private static Map getShapeAttrOfRelation(String plId, String shapeId, String attrId, String ref) { + JSONArray fileAttrValueArray = new JSONArray(); + JSONArray compareAccordArray = new JSONArray(); + List relationModelList = DesignerShapeRelationCache.getListByAttrId(plId, shapeId, attrId); + if (CollectionUtils.isNotEmpty(relationModelList)) { + relationModelList.forEach(relationModel -> { + JSONObject refObj = JSONObject.parseObject(ref); + String relationTyp = refObj.containsKey("type") ? refObj.getString("type") : "shape"; + String relationFileId = relationModel.getRelationFileId(); + if ("file".equals(relationTyp)) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(relationFileId); + if (model != null) { + fileAttrValueArray.add(model.getName()); + compareAccordArray.add(relationFileId); + } + } else { + fileAttrValueArray.add(relationModel.getRelationShapeText()); + compareAccordArray.add(relationFileId + "_" + relationModel.getRelationShapeId()); + } + }); + } + Map fileAttrValueMap = new HashMap<>(); + fileAttrValueMap.put("value", fileAttrValueArray); + fileAttrValueMap.put("compareAccord", compareAccordArray); + return fileAttrValueMap; + } + + /** + * 获取形状属性(关联AWS组织) + * + * @param plId pal模型Id + * @param shapeId 形状Id + * @param attrId 属性Id + * @return Map + */ + private static Map getShapeAttrOfAwsOrg(String plId, String shapeId, String attrId) { + JSONArray listOfFileAttrValue = new JSONArray(); + JSONArray listOfCompareAccord = new JSONArray(); + List listOfRelationModel = DesignerShapeRelationCache.getListByAttrId(plId, shapeId, attrId); + if (CollectionUtils.isNotEmpty(listOfRelationModel)) { + listOfRelationModel.forEach(relationModel -> { + if ("00000000-0000-0000-0000-000000000000".equals(relationModel.getRelationFileId()) && "00000000-0000-0000-0000-000000000000".equals(relationModel.getRelationShapeId())) { + JSONObject object = JSONObject.parseObject(relationModel.getRelationShapeText()); + listOfCompareAccord.add(shapeId + "_" + object.getString("type") + "_" + object.getString("id")); + if ("department".equals(object.getString("type"))) { + DepartmentModel dept = SDK.getORGAPI().getDepartmentById(object.getString("id")); + if (dept != null) { + listOfFileAttrValue.add(dept.getName()); + } + } + if ("position".equals(object.getString("type"))) {// 岗位,先用角色代替 + RoleModel role = SDK.getORGAPI().getRoleById(object.getString("id")); + if (role != null) { + listOfFileAttrValue.add(role.getName()); + } + } + if ("user".equals(object.getString("type"))) { + UserModel user = SDK.getORGAPI().getUser(object.getString("id")); + if (user != null) { + listOfFileAttrValue.add(user.getUserName()); + } + } + if ("role".equals(object.getString("type"))) { + RoleModel role = SDK.getORGAPI().getRoleById(object.getString("id")); + if (role != null) { + listOfFileAttrValue.add(role.getName()); + } + } + } + }); + } + Map mapOfFileAttrValue = new HashMap<>(); + mapOfFileAttrValue.put("value", listOfFileAttrValue); + mapOfFileAttrValue.put("compareAccord", listOfCompareAccord); + return mapOfFileAttrValue; + } + + /** + * 获取形状文件信息 + * + * @param plId pal模型Id + * @param definition 模型定义信息 + * @return Map> + */ + public static Map getShapeFileList(UserContext uc, String plId, String definition) { + List listOfShapeId = getShapeIdsByDefinition(definition); + if (CollectionUtils.isNotEmpty(listOfShapeId)) { + Map mapOfShapeFile = new HashMap<>(); + listOfShapeId.forEach(shapeId -> { + JSONObject shapeFileObj = new JSONObject(); + shapeFileObj.put("isDiff", false); + List listOfShapeFile = new ArrayList<>(); + List listOfUpFile = PALUpfileCache.getByPlUuid(plId); + if (CollectionUtils.isNotEmpty(listOfUpFile)) { + listOfUpFile.stream().filter(item -> item.getType().equals("s")).filter(item -> item.getShape_uuid().equals(shapeId)).forEach(item -> { + UpFileVO upFileVO = getUpFileVO(uc, item); + listOfShapeFile.add((JSONObject) JSONObject.toJSON(upFileVO)); + }); + } + shapeFileObj.put("value", listOfShapeFile); + mapOfShapeFile.put(shapeId, shapeFileObj); + }); + return mapOfShapeFile; + } + return null; + } + + /** + * 获取关联的形状文件信息 + * + * @param uc 用户上下文 + * @param plId pal模型Id + * @param definition 模型定义信息 + * @return Map> + */ + public static Map getRelationShapeFileList(UserContext uc, String plId, String definition) { + List listOfShapeId = getShapeIdsByDefinition(definition); + if (CollectionUtils.isNotEmpty(listOfShapeId)) { + Map mapOfRelationShapeFile = new HashMap<>(); + listOfShapeId.forEach(shapeId -> { + JSONObject shapeFileObj = new JSONObject(); + shapeFileObj.put("isDiff", false); + List listOfShapeFile = new ArrayList<>(); + List listOfShapeRelation = IteratorUtils.toList(DesignerShapeRelationCache.getByShapeId(plId, shapeId)); + if (CollectionUtils.isNotEmpty(listOfShapeRelation)) { + listOfShapeRelation.forEach(item -> { + String relationFileId = item.getRelationFileId(); + String relationShapeId = item.getRelationShapeId(); + List listOfUpFile = PALUpfileCache.getByPlUuid(relationFileId); + if (UtilString.isEmpty(relationShapeId)) { // 关联的文件 获取关联文件的附件 + listOfUpFile = listOfUpFile.stream().filter(u -> u.getType().equals("f")).collect(Collectors.toList()); + } else { // 关联的形状 获取关联的形状附件 + listOfUpFile = listOfUpFile.stream().filter(u -> u.getType().equals("s")).filter(u -> u.getShape_uuid().equals(item.getRelationShapeId())).collect(Collectors.toList()); + } + if (CollectionUtils.isNotEmpty(listOfUpFile)) { + listOfUpFile.forEach(u -> { + UpFileVO upFileVO = getUpFileVO(uc, u); + listOfShapeFile.add((JSONObject) JSONObject.toJSON(upFileVO)); + }); + } + }); + } + shapeFileObj.put("value", listOfShapeFile); + mapOfRelationShapeFile.put(shapeId, shapeFileObj); + }); + return mapOfRelationShapeFile; + } + return null; + } + + private static UpFileVO getUpFileVO(UserContext uc, UpfileModel model) { + String downloadUrl = getDownloadUrl(uc, model); + boolean hasSecurity = true; + if (HighSecurityUtil.isON() && HighSecurityUtil.fileSecuritySwitch()) { + int userSecurityLevel = uc.getUserModel().getSecurityLevel(); + PALSecurityLevelModel upFileSecurityLevelInfo = HighSecurityUtil.getUpFileSecurityLevelInfo(model.getUuid()); + int upFileSecurityLevel = Integer.parseInt(upFileSecurityLevelInfo.getCode()); + if (userSecurityLevel < upFileSecurityLevel) { + hasSecurity = false; + } + } + return UpFileVO.Builder.createBuilder().withFileId(model.getUuid()).withFileName(model.getFileName()).withDownloadUrl(downloadUrl).withHasSecurity(hasSecurity).build(); + } + + /** + * 获取下载地址 + * + * @param uc UserContext + * @param model UpfileModel + * @return String + */ + private static String getDownloadUrl(UserContext uc, UpfileModel model) { + DCContext dcContext = CoeUpFileUtil.getUpFileDCContext(uc, model); + return dcContext != null ? dcContext.getDownloadURL() : ""; + } + + /** + * 获取形状链接信息 + * + * @param definition 模型定义信息 + * @return Map> + */ + public static Map getShapeLinkList(UserContext uc, String definition, String teamId) { + JSONObject definitionObj = validateDefinition(definition); + + if (definitionObj != null) { + JSONObject elements = definitionObj.getJSONObject("elements"); + List listOfShapeId = getShapeIdsByDefinition(definition); + if (CollectionUtils.isNotEmpty(listOfShapeId)) { + Map mapOfShapeLink = new HashMap<>(); + listOfShapeId.forEach(shapeId -> { + JSONObject shapeLinkObj = new JSONObject(); + JSONObject fileLink = new JSONObject(); + fileLink.put("isDiff", false); + JSONObject customLink = new JSONObject(); + customLink.put("isDiff", false); + List listOfShapeCustomLink = new ArrayList<>(); + List listOfShapeFileLink = new ArrayList<>(); + JSONObject shape = elements.getJSONObject(shapeId); + if (shape.containsKey("dataAttributes")) { + JSONArray dataAttributes = shape.getJSONArray("dataAttributes"); + if (CollectionUtils.isNotEmpty(dataAttributes)) { + dataAttributes.stream().map(o -> (JSONObject) o).forEach(o -> { + if (o.containsKey("linksArray")) { + JSONArray linksArray = o.getJSONArray("linksArray"); + linksArray.stream().map(item -> (JSONObject) item).forEach(item -> { + String url = item.getString("url"); + ShapeLinkVO.Builder builder = ShapeLinkVO.Builder.createBuilder().withName(item.getString("name")).withTarget(item.getString("target")).withType(item.getString("type")).withUuid(item.getString("uuid")).withValue(item.getString("value")).withVersionId(item.getString("versionId")); + if ("file".equals(item.getString("type"))) { + String[] split = url.split("&"); + String uuidStr = Arrays.stream(split).filter(s -> s.startsWith("uuid=")).findAny().orElse(""); + String newUrl = "./w?" + uuidStr + "&teamId=" + teamId + "&cmd=com.actionsoft.apps.coe.pal_pl_repository_designer_main&sid=" + uc.getSessionId(); + ShapeLinkVO shapeLinkVO = builder.withUrl(newUrl).build(); + listOfShapeFileLink.add((JSONObject) JSONObject.toJSON(shapeLinkVO)); + } else { + ShapeLinkVO shapeLinkVO = builder.withUrl(url).build(); + listOfShapeCustomLink.add((JSONObject) JSONObject.toJSON(shapeLinkVO)); + } + }); + } + }); + } + } + fileLink.put("value", listOfShapeFileLink); + customLink.put("value", listOfShapeCustomLink); + shapeLinkObj.put("file", fileLink); + shapeLinkObj.put("custom", customLink); + mapOfShapeLink.put(shapeId, shapeLinkObj); + }); + return mapOfShapeLink; + } + } + return null; + } + + /** + * 解析模型定义信息 + * + * @param definition 模型定义信息 + * @return JSONObject + */ + private static JSONObject validateDefinition(String definition) { + if (UtilString.isEmpty(definition)) { + return null; + } + JSONObject definitionObj = null; + try { + definitionObj = JSONObject.parseObject(definition); + } catch (Exception e) { + e.printStackTrace(); + log.error("设计器版本信息对比时,模型定义信息解析失败", e); + } + return definitionObj; + } + + /** + * 获取文件属性信息 + * + * @param uc UserContext + * @param plId pal模型Id + * @return List + */ + public static List getFileAttrForCompare(UserContext uc, String plId) { + PALRepositoryModel repositoryModel = PALRepositoryCache.getCache().get(plId); + if (repositoryModel == null) { + return null; + } + // 获取属性配置信息 + List listOfMethodAttrModel = PALRepositoryAPIManager.getInstance().getValidAttributeModels(repositoryModel.getWsId(), repositoryModel.getMethodId()); + Map mapOfMethodAttrModel = listOfMethodAttrModel.stream().collect(Collectors.toMap(PALMethodAttributeModel::getKey, item -> item)); + // 获取文件属性数据 + List listOfPropertyModel = PALRepositoryPropertyCache.getPropertyByPlId(plId); + if (CollectionUtils.isNotEmpty(listOfPropertyModel)) { + List listOfAttrVO = new ArrayList<>(); + listOfPropertyModel.forEach(propertyModel -> { + if (mapOfMethodAttrModel.containsKey(propertyModel.getPropertyId()) && mapOfMethodAttrModel.get(propertyModel.getPropertyId()).getUse()) { + String id = propertyModel.getPropertyId(); + PALMethodAttributeModel methodAttributeModel = mapOfMethodAttrModel.get(id); + String name = methodAttributeModel.getNewTitle(); + Object value = propertyModel.getPropertyValue(); + String type = methodAttributeModel.getType(); + Map mapOfFileAttrValue = getFileAttrValue(uc, plId, methodAttributeModel, propertyModel); + value = mapOfFileAttrValue.get("value"); + Object compareAccord = mapOfFileAttrValue.get("compareAccord"); + AttrVO attrVO = AttrVO.Builder.createBuilder().withId(id).withName(name).withType(type).withValue(value).withIsDiff(false).withCompareAccord(compareAccord).withOrderIndex(methodAttributeModel.getIndex()).build(); + listOfAttrVO.add(attrVO); + } + }); + sortAttrVO(listOfAttrVO); // 排序 + return listOfAttrVO; + } + return null; + } + + /** + * 属性信息排序 按照属性Id的字符的自然排序 + * + * @param listOfAttrVO 属性集合 + */ + private static void sortAttrVO(List listOfAttrVO) { + if (CollectionUtils.isNotEmpty(listOfAttrVO)) { + listOfAttrVO.sort(Comparator.comparing(AttrVO::getOrderIndex)); + } + } + + private static void sortAttrVO(List listOfAttrVO, Map attrKeyAndModelMap) { + if (CollectionUtils.isNotEmpty(listOfAttrVO)) { + listOfAttrVO.sort(Comparator.comparing(o -> !attrKeyAndModelMap.containsKey(o.getId()) ? 0 : attrKeyAndModelMap.get(o.getId()).getIndex())); + } + } + + /** + * 获取文件属性信息 + * + * @param uc UserContext + * @param plId pal模型Id + * @param methodAttributeModel 属性配置信息 + * @param propertyModel 属性数据 + * @return Map + */ + public static Map getFileAttrValue(UserContext uc, String plId, PALMethodAttributeModel methodAttributeModel, PALRepositoryPropertyModel propertyModel) { + Map result = null; + switch (methodAttributeModel.getType()) { + case "relation": + result = getFileAttrOfRelation(plId, methodAttributeModel); + break; + case "awsorg": + result = getFileAttrOfAwsOrg(plId, methodAttributeModel); + break; + case "file": + result = getFileAttrUpFileList(uc, plId, methodAttributeModel); + break; + default: + result = new HashMap<>(); + result.put("value", propertyModel.getPropertyValue()); + result.put("compareAccord", sortStringContent(propertyModel.getPropertyValue())); + break; + } + return result; + } + + private static String sortStringContent(String input) { + if (!input.contains(",")) { + return input; + } + // 1. 拆分字符串 + String[] items = input.split(","); + + // 2. 对数组进行排序 + Arrays.sort(items); + + // 3. 将排序后的数组重新组合成字符串 + return String.join(",", items); + } + + /** + * 获取文件属性(附件信息) + * + * @param uc UserContext + * @param plId pal模型Id + * @param methodAttributeModel 属性配置信息 + * @return Map + */ + public static Map getFileAttrUpFileList(UserContext uc, String plId, PALMethodAttributeModel methodAttributeModel) { + JSONArray listOfFileAttrValue = new JSONArray(); + JSONArray listOfCompareAccord = new JSONArray(); + List upfileModelList = PALUpfileCache.getByPlUuid(plId); + upfileModelList = upfileModelList.stream().filter(upfileModel -> upfileModel.getType().equals("a")).filter(upfileModel -> UtilString.isEmpty(upfileModel.getShape_uuid())).filter(upfileModel -> methodAttributeModel.getKey().equals(upfileModel.getAttrId())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(upfileModelList)) { + upfileModelList.forEach(upfileModel -> { + JSONObject valueObj = new JSONObject(); + String fileName = upfileModel.getFileName(); + String downloadUrl = getDownloadUrl(uc, upfileModel); + valueObj.put("fileName", fileName); + valueObj.put("downloadUrl", downloadUrl); + listOfFileAttrValue.add(valueObj); + String compareAccord = upfileModel.getAttrId() + "_" + upfileModel.getFileName(); + listOfCompareAccord.add(compareAccord); + }); + } + Map mapOfFileAttrValue = new HashMap<>(); + mapOfFileAttrValue.put("value", listOfFileAttrValue); + mapOfFileAttrValue.put("compareAccord", listOfCompareAccord); + return mapOfFileAttrValue; + } + + /** + * 获取文件属性(模型关联) + * + * @param plId pal模型Id + * @param methodAttributeModel 属性配置信息 + * @return Map 显示信息及对比依据 + */ + private static Map getFileAttrOfRelation(String plId, PALMethodAttributeModel methodAttributeModel) { + JSONArray listOfFileAttrValue = new JSONArray(); + JSONArray listOfCompareAccord = new JSONArray(); + List listOfRelationModel = DesignerShapeRelationCache.getListByAttrId(plId, "", methodAttributeModel.getKey()); + if (CollectionUtils.isNotEmpty(listOfRelationModel)) { + listOfRelationModel.forEach(relationModel -> { + JSONObject refObj = JSONObject.parseObject(methodAttributeModel.getRef()); + String relationTyp = refObj.containsKey("type") ? refObj.getString("type") : "shape"; + String relationFileId = relationModel.getRelationFileId(); + if ("file".equals(relationTyp)) { + listOfFileAttrValue.add(PALRepositoryCache.getCache().get(relationFileId).getName()); + listOfCompareAccord.add(relationFileId); + } else { + listOfFileAttrValue.add(relationModel.getRelationShapeText()); + listOfCompareAccord.add(relationFileId + "_" + relationModel.getRelationShapeId()); + } + }); + } + Map mapOfFileAttrValue = new HashMap<>(); + mapOfFileAttrValue.put("value", listOfFileAttrValue); + mapOfFileAttrValue.put("compareAccord", listOfCompareAccord); + return mapOfFileAttrValue; + } + + /** + * 获取文件属性(关联AWS组织) + * + * @param plId pal模型Id + * @param methodAttributeModel 属性配置信息 + * @return Map 显示信息及对比依据 + */ + private static Map getFileAttrOfAwsOrg(String plId, PALMethodAttributeModel methodAttributeModel) { + JSONArray listOfFileAttrValue = new JSONArray(); + JSONArray listOfCompareAccord = new JSONArray(); + List listOfRelationModel = DesignerShapeRelationCache.getListByAttrId(plId, "", methodAttributeModel.getKey()); + if (CollectionUtils.isNotEmpty(listOfRelationModel)) { + listOfRelationModel.forEach(relationModel -> { + if ("00000000-0000-0000-0000-000000000000".equals(relationModel.getRelationFileId()) && "00000000-0000-0000-0000-000000000000".equals(relationModel.getRelationShapeId())) { + JSONObject object = JSONObject.parseObject(relationModel.getRelationShapeText()); + listOfCompareAccord.add(object.getString("type") + "_" + object.getString("id")); + if ("department".equals(object.getString("type"))) { + DepartmentModel dept = SDK.getORGAPI().getDepartmentById(object.getString("id")); + if (dept != null) { + listOfFileAttrValue.add(dept.getName()); + } + } + if ("position".equals(object.getString("type"))) {// 岗位,先用角色代替 + RoleModel role = SDK.getORGAPI().getRoleById(object.getString("id")); + if (role != null) { + listOfFileAttrValue.add(role.getName()); + } + } + if ("user".equals(object.getString("type"))) { + UserModel user = SDK.getORGAPI().getUser(object.getString("id")); + if (user != null) { + listOfFileAttrValue.add(user.getUserName()); + } + } + if ("role".equals(object.getString("type"))) { + RoleModel role = SDK.getORGAPI().getRoleById(object.getString("id")); + if (role != null) { + listOfFileAttrValue.add(role.getName()); + } + } + } + }); + } + Map mapOfFileAttrValue = new HashMap<>(); + mapOfFileAttrValue.put("value", listOfFileAttrValue); + mapOfFileAttrValue.put("compareAccord", listOfCompareAccord); + return mapOfFileAttrValue; + } + + /** + * 获取模型附件 + * + * @param uc 用户上下文 + * @param plId 模型ID + * @return List 附件列表 + */ + public static JSONObject getFileUpFileList(UserContext uc, String plId) { + JSONObject result = new JSONObject(); + result.put("isDiff", false); + List listOfShapeFile = new ArrayList<>(); + List listOfUpFile = PALUpfileCache.getByPlUuid(plId); + if (CollectionUtils.isNotEmpty(listOfUpFile)) { + listOfUpFile.stream().filter(item -> item.getType().equals("f")).forEach(item -> { + UpFileVO upFileVO = getUpFileVO(uc, item); + listOfShapeFile.add((JSONObject) JSONObject.toJSON(upFileVO)); + }); + } + result.put("value", listOfShapeFile); + return result; + } + + /** + * 获取模型关联附件 + * + * @param uc 用户上下文 + * @param plId 模型ID + * @return List 附件列表 + */ + public static JSONObject getFileRelationUpFileList(UserContext uc, String plId) { + JSONObject result = new JSONObject(); + result.put("isDiff", false); + List listOfShapeFile = new ArrayList<>(); + DesignerShapeRelationDao dao = new DesignerShapeRelationDao(); + List listOfShapeRelation = dao.getModelListByFileId(plId); + if (CollectionUtils.isNotEmpty(listOfShapeRelation)) { + listOfShapeRelation.stream().filter(item -> UtilString.isEmpty(item.getRelationShapeId())).forEach(item -> { + String relationFileId = item.getRelationFileId(); + String relationShapeId = item.getRelationShapeId(); + List listOfUpFile = PALUpfileCache.getByPlUuid(relationFileId); + if (UtilString.isEmpty(relationShapeId)) { // 关联的文件 获取关联文件的附件 + listOfUpFile = listOfUpFile.stream().filter(u -> u.getType().equals("f")).collect(Collectors.toList()); + } else { // 关联的形状 获取关联的形状附件 + listOfUpFile = listOfUpFile.stream().filter(u -> u.getType().equals("s")).filter(u -> u.getShape_uuid().equals(item.getRelationShapeId())).collect(Collectors.toList()); + } + if (CollectionUtils.isNotEmpty(listOfUpFile)) { + listOfUpFile.forEach(u -> { + UpFileVO upFileVO = getUpFileVO(uc, u); + listOfShapeFile.add((JSONObject) JSONObject.toJSON(upFileVO)); + }); + } + }); + } + result.put("value", listOfShapeFile); + return result; + } + + /** + * 比对文件属性 + * + * @param versionData 比对的版本 + * @param curData 当前使用版本 + */ + public static void compareFileAttr(JSONObject versionData, JSONObject curData) { + JSONArray hisShapeAttr = versionData.getJSONArray("fileAttr"); + JSONArray curShapeAttr = curData.getJSONArray("fileAttr"); + compareAttr(hisShapeAttr, curShapeAttr); + } + + /** + * 比对形状属性 + * + * @param versionData 比对的版本 + * @param curData 当前使用版本 + * @return 返回属性有差异的形状ID + */ + public static Set compareShapeAttr(JSONObject versionData, JSONObject curData) { + JSONObject hisShapeAttr = versionData.getJSONObject("shapeAttr"); + JSONObject curShapeAttr = curData.getJSONObject("shapeAttr"); + return compareAttr(hisShapeAttr, curShapeAttr); + } + + /** + * 比对属性 + * + * @param hisShapeAttr 待比对的版本 + * @param curShapeAttr 当前使用版本 + * @return 返回属性有差异的形状ID + */ + private static Set compareAttr(JSONObject hisShapeAttr, JSONObject curShapeAttr) { + Set setOfShapeId = new HashSet<>(); + if (hisShapeAttr != null && curShapeAttr != null) { + // 遍历当前形状属性 + curShapeAttr.keySet().forEach(curShapeId -> { + // 获取当前形状属性集合 + JSONArray curShapeAttrs = curShapeAttr.getJSONArray(curShapeId); + if (curShapeAttrs.size() > 0) { + for (int i = 0; i < curShapeAttrs.size(); i++) { + JSONObject curShapeAttrItem = curShapeAttrs.getJSONObject(i); + String curType = curShapeAttrItem.getString("type"); + Object compareAccord = curShapeAttrItem.get("compareAccord"); + String attrId = curShapeAttrItem.getString("id"); + // 判断对比的版本数据是否存在当前形状 不存在不用对比 + if (hisShapeAttr.containsKey(curShapeId)) { + JSONArray hisShapeAttrItem = hisShapeAttr.getJSONArray(curShapeId); + Map mapOfShapeAttrItem = new HashMap<>(); + for (int j = 0; j < hisShapeAttrItem.size(); j++) { + JSONObject hisItem = hisShapeAttrItem.getJSONObject(j); + String hisType = hisItem.getString("type"); + String hisAttrId = hisItem.getString("id"); + Object hisCompareAccord = hisItem.get("compareAccord"); + mapOfShapeAttrItem.put(hisType + "_" + hisAttrId, hisCompareAccord); + } + if (mapOfShapeAttrItem.containsKey(curType + "_" + attrId)) { + Object hisCompareAccord = mapOfShapeAttrItem.get(curType + "_" + attrId); + boolean isDiff = checkDiffCompareAccord(curType, hisCompareAccord, compareAccord); + if (isDiff) { + curShapeAttrItem.put("isDiff", true); + curShapeAttrs.set(i, curShapeAttrItem); + setOfShapeId.add(curShapeId); + } + } + } + } + } + }); + } + return setOfShapeId; + } + + /** + * 比对属性 + * + * @param hisShapeAttr 待比对的版本 + * @param curShapeAttr 当前使用版本 + * @return 返回属性有差异的形状ID + */ + private static void compareAttr(JSONArray hisShapeAttr, JSONArray curShapeAttr) { + if (hisShapeAttr != null && curShapeAttr != null) { + Map mapOfAttrItem = new HashMap<>(); + for (Object hisO : hisShapeAttr) { + JSONObject hisItem = (JSONObject) JSONObject.toJSON(hisO); + String hisType = hisItem.getString("type"); + String hisAttrId = hisItem.getString("id"); + Object hisCompareAccord = hisItem.get("compareAccord"); + mapOfAttrItem.put(hisType + "_" + hisAttrId, hisCompareAccord); + } + for (int i = 0; i < curShapeAttr.size(); i++) { + JSONObject curShapeAttrItem = curShapeAttr.getJSONObject(i); + String curType = curShapeAttrItem.getString("type"); + Object compareAccord = curShapeAttrItem.get("compareAccord"); + String attrId = curShapeAttrItem.getString("id"); + // 判断对比的版本数据是否存在当前形状 不存在不用对比 + if (mapOfAttrItem.containsKey(curType + "_" + attrId)) { + Object hisCompareAccord = mapOfAttrItem.get(curType + "_" + attrId); + boolean isDiff = checkDiffCompareAccord(curType, hisCompareAccord, compareAccord); + if (isDiff) { + curShapeAttrItem.put("isDiff", true); + curShapeAttr.set(i, curShapeAttrItem); + } + } + } + } + } + + private static boolean checkDiffCompareAccord(String type, Object hisCompareAccord, Object curCompareAccord) { + boolean isDiff = false; + if ("relation".equals(type) || "awsorg".equals(type) || "file".equals(type)) { + if (hisCompareAccord instanceof JSONArray && curCompareAccord instanceof JSONArray) { + if (((JSONArray) hisCompareAccord).size() == ((JSONArray) curCompareAccord).size()) { + // 排序 + hisCompareAccord = sortJSONArrayOfCompareAccord((JSONArray) hisCompareAccord); + curCompareAccord = sortJSONArrayOfCompareAccord((JSONArray) curCompareAccord); + for (int i = 0; i < ((JSONArray) hisCompareAccord).size(); i++) { + if (!((JSONArray) hisCompareAccord).get(i).equals(((JSONArray) curCompareAccord).get(i))) { + isDiff = true; + break; + } + } + } else { + isDiff = true; + } + } + } else { + isDiff = !hisCompareAccord.equals(curCompareAccord); + } + return isDiff; + } + + private static JSONArray sortJSONArrayOfCompareAccord(JSONArray compareAccord) { + String[] array = new String[compareAccord.size()]; + for (int i = 0; i < compareAccord.size(); i++) { + array[i] = compareAccord.getString(i); + } + Arrays.sort(array); + JSONArray result = new JSONArray(); + Collections.addAll(result, array); + return result; + } + + public static List compareNodeAndLinkInfo(JSONObject versionData, JSONObject curDate, Set setOfShapeIdInfoDiff) { + String compareDefinition = versionData.getString("definition"); + JSONObject compareDefineObj = JSONObject.parseObject(compareDefinition); + String curDefinition = curDate.getString("definition"); + JSONObject curDefineObj = JSONObject.parseObject(curDefinition); + + JSONObject compareElements = compareDefineObj.getJSONObject("elements"); + JSONObject elements = curDefineObj.getJSONObject("elements"); + List diffNodeVOList = new ArrayList<>(); + if (compareElements != null && elements != null) { + elements.keySet().forEach(key -> { + JSONObject curElement = elements.getJSONObject(key); + List types = predicateEleDiffType(compareElements, curElement, setOfShapeIdInfoDiff); + DiffNodeVO diffNodeVO = DiffNodeVO.Builder.create().withId(key).withType(types).build(); + diffNodeVOList.add(diffNodeVO); + }); + // 节点删除 + compareElements.keySet().forEach(key -> { + if (!elements.containsKey(key)) { + // 节点删除 + List types = new ArrayList<>(); + types.add(DiffNodeTypeEnum.DELETE.getCode()); + DiffNodeVO diffNodeVO = DiffNodeVO.Builder.create().withId(key).withType(types).build(); + diffNodeVOList.add(diffNodeVO); + } + }); + } + + return diffNodeVOList; + } + + public static List predicateEleDiffType(JSONObject compareElements, JSONObject curElement, Set setOfShapeIdInfoDiff) { + + List types = null; + String curEleName = curElement.getString("name"); + + if ("linker".equals(curEleName)) { + types = predicateLinkerDiffType(compareElements, curElement); + } else { + types = predicateNodeDiffType(compareElements, curElement, setOfShapeIdInfoDiff); + } + return types; + } + + private static List predicateLinkerDiffType(JSONObject compareElements, JSONObject curElement) { + List types = new ArrayList<>(); + String curEleId = curElement.getString("id"); // 连线Id + // 对比版本中不存在 视为新增 + if (!compareElements.containsKey(curEleId)) { + types.add(DiffNodeTypeEnum.ADD.getCode()); + return types; + } + // 连线两端的节点 与对比版本中相同连线ID的两端节点ID 不一致 视为新增连线 + JSONObject fromObj = curElement.getJSONObject("from"); + String fromShapeId = fromObj.getString("id"); + fromShapeId = UtilString.isEmpty(fromShapeId) ? "" : fromShapeId; + JSONObject toObj = curElement.getJSONObject("to"); + String toShapeId = toObj.getString("id"); + toShapeId = UtilString.isEmpty(toShapeId) ? "" : toShapeId; + + JSONObject compareLinker = compareElements.getJSONObject(curEleId); + JSONObject compareFromObj = compareLinker.getJSONObject("from"); + String compareFromShapeId = compareFromObj.getString("id"); + compareFromShapeId = UtilString.isEmpty(compareFromShapeId) ? "" : compareFromShapeId; + JSONObject compareToObj = compareLinker.getJSONObject("to"); + String compareToShapeId = compareToObj.getString("id"); + compareToShapeId = UtilString.isEmpty(compareToShapeId) ? "" : compareToShapeId; + + if (!fromShapeId.equals(compareFromShapeId) || !toShapeId.equals(compareToShapeId)) { + types.add(DiffNodeTypeEnum.ADD.getCode()); + } + return types; + } + + private static List predicateNodeDiffType(JSONObject compareElements, JSONObject curElement, Set setOfShapeIdInfoDiff) { + List types = new ArrayList<>(); + String curEleId = curElement.getString("id"); + // 对比版本中不存在 视为新增 + if (!compareElements.containsKey(curEleId)) { + types.add(DiffNodeTypeEnum.ADD.getCode()); + return types; + } + // 形状位置 + JSONObject curProps = curElement.getJSONObject("props"); + double curX = curProps.getDoubleValue("x"); + double curY = curProps.getDoubleValue("y"); + JSONObject compareEle = compareElements.getJSONObject(curEleId); + JSONObject compareProps = compareEle.getJSONObject("props"); + double compareX = compareProps.getDoubleValue("x"); + double compareY = compareProps.getDoubleValue("y"); + if (curX != compareX || curY != compareY) { + types.add(DiffNodeTypeEnum.POSITION.getCode()); + } + // 形状名称、样式 + String text = curElement.getString("text"); + String compareText = compareEle.getString("text"); + if (!text.equals(compareText)) { + types.add(DiffNodeTypeEnum.STYLE.getCode()); + } + String curShowConfig = ""; + if (curElement.containsKey("dataAttributes")) { + JSONArray dataAttributes = curElement.getJSONArray("dataAttributes"); + for (int i = 0; i < dataAttributes.size(); i++) { + JSONObject dataAttribute = dataAttributes.getJSONObject(i); + if (dataAttribute.containsKey("dataShowConfig")) { + curShowConfig = dataAttribute.getJSONObject("dataShowConfig").toJSONString(); + } + } + } + String compareShowConfig = ""; + if (compareEle.containsKey("dataAttributes")) { + JSONArray compareDataAttributes = compareEle.getJSONArray("dataAttributes"); + for (int i = 0; i < compareDataAttributes.size(); i++) { + JSONObject compareDataAttribute = compareDataAttributes.getJSONObject(i); + if (compareDataAttribute.containsKey("dataShowConfig")) { + compareShowConfig = compareDataAttribute.getJSONObject("dataShowConfig").toJSONString(); + } + } + } + if (!curShowConfig.equals(compareShowConfig) && !types.contains(DiffNodeTypeEnum.STYLE.getCode())) { + types.add(DiffNodeTypeEnum.STYLE.getCode()); + } + + // 节点信息 + if (setOfShapeIdInfoDiff.contains(curEleId)) { + types.add(DiffNodeTypeEnum.INFO.getCode()); + } + return types; + } + + /** + * 对比形状文件 + * + * @param versionData 待对比的数据 + * @param curData 当前数据 + */ + public static Set compareShapeFile(JSONObject versionData, JSONObject curData) { + JSONObject hisShapeUpFile = versionData.getJSONObject("shapeUpFile"); + JSONObject curShapeUpFile = curData.getJSONObject("shapeUpFile"); + return compareFileIsDiff(hisShapeUpFile, curShapeUpFile); + } + + /** + * 对比形状关联文件 + * + * @param versionData 待对比的数据 + * @param curData 当前数据 + */ + public static Set compareShapeRelationFile(JSONObject versionData, JSONObject curData) { + JSONObject hisShapeRelationFile = versionData.getJSONObject("shapeRelationUpFile"); + JSONObject curShapeRelationFile = curData.getJSONObject("shapeRelationUpFile"); + return compareFileIsDiff(hisShapeRelationFile, curShapeRelationFile); + } + + private static Set compareFileIsDiff(JSONObject hisShapeUpFile, JSONObject curShapeUpFile) { + Set setOfShapeId = new HashSet<>(); + if (hisShapeUpFile != null && curShapeUpFile != null) { + curShapeUpFile.keySet().forEach(key -> { + JSONObject curShapeUpFileObj = curShapeUpFile.getJSONObject(key); + JSONArray curValue = curShapeUpFileObj.getJSONArray("value"); + if (hisShapeUpFile.containsKey(key)) { + JSONObject hisShapeUpFileObj = hisShapeUpFile.getJSONObject(key); + JSONArray hisValue = hisShapeUpFileObj.getJSONArray("value"); + if (predicateUpFileISDiff(hisValue, curValue)) { + curShapeUpFileObj.put("isDiff", true); + setOfShapeId.add(key); + } + } + }); + } + return setOfShapeId; + } + + /** + * 判断文件是否存在差异 判断依据:文件数量 文件Id + * + * @param hisValue 待对比的数据 + * @param curValue 当前数据 + * @return boolean + */ + private static boolean predicateUpFileISDiff(JSONArray hisValue, JSONArray curValue) { + boolean isDiff = hisValue.size() != curValue.size(); + Map mapOfHisValue = new HashMap<>(); + for (int i = 0; i < hisValue.size(); i++) { + JSONObject hisValItem = hisValue.getJSONObject(i); + mapOfHisValue.put(hisValItem.getString("fileName"), hisValItem); + } + for (int i = 0; i < curValue.size(); i++) { + JSONObject curValItem = curValue.getJSONObject(i); + if (!mapOfHisValue.containsKey(curValItem.getString("fileName"))) { + isDiff = true; + break; + } + } + return isDiff; + } + + public static Set compareShapeLink(JSONObject versionData, JSONObject curData) { + Set setOfShapeId = new HashSet<>(); + JSONObject hisShapeLink = versionData.getJSONObject("shapeLink"); + JSONObject curShapeLink = curData.getJSONObject("shapeLink"); + if (hisShapeLink != null && curShapeLink != null) { + curShapeLink.keySet().forEach(key -> { + JSONObject curShapeLinkObj = curShapeLink.getJSONObject(key); + JSONObject fileLinkObj = curShapeLinkObj.getJSONObject("file"); + JSONArray fileLinkValue = fileLinkObj.getJSONArray("value"); + JSONObject customLinkObj = curShapeLinkObj.getJSONObject("custom"); + JSONArray customLinkValue = customLinkObj.getJSONArray("value"); + if (hisShapeLink.containsKey(key)) { + JSONObject hisShapeLinkObj = hisShapeLink.getJSONObject(key); + JSONObject hisFileLinkObj = hisShapeLinkObj.getJSONObject("file"); + JSONArray hisFileLinkValue = hisFileLinkObj.getJSONArray("value"); + JSONObject hisCustomLinkObj = hisShapeLinkObj.getJSONObject("custom"); + JSONArray hisCustomLinkValue = hisCustomLinkObj.getJSONArray("value"); + + // 比较文件链接 + if (!fileLinkValue.toJSONString().equals(hisFileLinkValue.toJSONString())) { + fileLinkObj.put("isDiff", true); + setOfShapeId.add(key); + } + // 比较自定义链接 + if (!customLinkValue.toJSONString().equals(hisCustomLinkValue.toJSONString())) { + customLinkObj.put("isDiff", true); + setOfShapeId.add(key); + } + } + }); + } + return setOfShapeId; + } + + /** + * 比对模型附件 + * + * @param versionData 待对比的数据 + * @param curData 当前数据 + */ + public static void compareFileUpFileList(JSONObject versionData, JSONObject curData) { + JSONObject hisFileUpFileObj = versionData.getJSONObject("fileUpFile"); + JSONArray hisValue = hisFileUpFileObj.getJSONArray("value"); + JSONObject curFileUpFileObj = curData.getJSONObject("fileUpFile"); + JSONArray curValue = curFileUpFileObj.getJSONArray("value"); + if (predicateUpFileISDiff(hisValue, curValue)) { + curFileUpFileObj.put("isDiff", true); + } + } + + /** + * 比对模型关联附件 + * + * @param versionData 待对比的数据 + * @param curData 当前数据 + */ + public static void compareFileRelationUpFileList(JSONObject versionData, JSONObject curData) { + JSONObject hisFileUpFileObj = versionData.getJSONObject("fileRelationUpFile"); + JSONArray hisValue = hisFileUpFileObj.getJSONArray("value"); + JSONObject curFileUpFileObj = curData.getJSONObject("fileRelationUpFile"); + JSONArray curValue = curFileUpFileObj.getJSONArray("value"); + if (predicateUpFileISDiff(hisValue, curValue)) { + curFileUpFileObj.put("isDiff", true); + } + } + + /** + * 获取 版本对比 map参数 + * + * @param compareVerId 对比模型版本ID + * @param versionData 对比版本的模型数据 + * @param curId 当前模型版本ID + * @param curData 当前模型数据 + * @param ifHideUI 是否隐藏属性等UI + */ + public static Map queryDesignerVersionCompareMap(String wsId, String methodId, String fileName, String compareVerId, JSONObject versionData, String curId, JSONObject curData, boolean isProcessExec, boolean ifHideUI) { + Map macroLibraries = new HashMap<>(); + + // 节点与连线对比信息 + Set setOfShapeIdInfoDiff = new HashSet<>(); + if (!ifHideUI) { + // 对比形状属性差异 + Set setOfShapeIdAttrDiff = compareShapeAttr(versionData, curData); + // 对比文件属性 + compareFileAttr(versionData, curData); + // 对比形状附件 + Set setOfShapeIdFileDiff = compareShapeFile(versionData, curData); + // 对比形状关联附件 + Set setOfShapeIdRelationFileDiff = compareShapeRelationFile(versionData, curData); + // 对比形状链接 + Set setOfShapeIdLinkDiff = compareShapeLink(versionData, curData); + // 对比文件附件 + compareFileUpFileList(versionData, curData); + // 对比文件关联附件 + compareFileRelationUpFileList(versionData, curData); + setOfShapeIdInfoDiff.addAll(setOfShapeIdAttrDiff); + setOfShapeIdInfoDiff.addAll(setOfShapeIdFileDiff); + setOfShapeIdInfoDiff.addAll(setOfShapeIdRelationFileDiff); + setOfShapeIdInfoDiff.addAll(setOfShapeIdLinkDiff); + } + macroLibraries.put("versionData", versionData); + macroLibraries.put("curData", curData); + List listOfDiffNodeVO = compareNodeAndLinkInfo(versionData, curData, setOfShapeIdInfoDiff); + macroLibraries.put("diffNode", JSON.toJSON(listOfDiffNodeVO)); + + PALRepositoryModel compareModel = PALRepositoryCache.getCache().get(compareVerId); + Map mapOfLeft = getRelationShapeInfo(compareModel, versionData.getString("definition")); + macroLibraries.put("leftOfRelationShapes", mapOfLeft.get("relationShapes")); + PALRepositoryModel curModel = PALRepositoryCache.getCache().get(curId); + Map mapOfRight = getRelationShapeInfo(curModel, curData.getString("definition")); + macroLibraries.put("rightOfRelationShapes", mapOfRight.get("relationShapes")); + // 版本对比页面与梳理到执行流程对比页面共用 以此进行区分 方便页面屏蔽一些逻辑与数据 + macroLibraries.put("isProcessExec", isProcessExec); + macroLibraries.put("ifHideUI", ifHideUI); + JSONObject methodIcon = PALMethodUtil.getPALMethodIconById(methodId, wsId); + macroLibraries.put("methodIcon", methodIcon); + macroLibraries.put("methodId", methodId); + macroLibraries.put("fileName", fileName); + return macroLibraries; + } + + public static Map getRelationShapeInfo(String plId) { + PALRepositoryModel plModel = PALRepositoryCache.getCache().get(plId); + String define = PALRepositoryQueryAPIManager.getInstance().getProcessDefinition(null, plId); + return getRelationShapeInfo(plModel, define); + } + + public static Map getRelationShapeInfo(PALRepositoryModel plModel, String define) { + Map mapOfResult = new HashMap<>(); + JSONObject relationShapeIds = new JSONObject(); + JSONObject relationShapeModels = new JSONObject(); + if (plModel == null || UtilString.isEmpty(define)) { + mapOfResult.put("relationShapes", relationShapeIds); + mapOfResult.put("relationShapeModels", relationShapeModels); + return mapOfResult; + } + List> elements = ShapeUtil.getShapeJson(define, plModel.getId(), plModel.getName()); + if (!elements.isEmpty()) { + for (Map element : elements) { + String elementId = element.containsKey("id") ? element.get("id").toString() : ""; + if (!UtilString.isEmpty(elementId)) { + List modelList = DesignerShapeRelationCache.getListByShapeId(plModel.getId(), elementId); + // relation类型数据去重 + List tempList = new ArrayList<>(); + Set ids = new HashSet<>(); + for (DesignerShapeRelationModel model : modelList) { + if ("00000000-0000-0000-0000-000000000000".equals(model.getRelationFileId()) && "00000000-0000-0000-0000-000000000000".equals(model.getRelationShapeId())) { + tempList.add(model); + continue; + } + String id = model.getFileId() + model.getShapeId() + model.getAttrId() + model.getRelationFileId() + model.getRelationShapeId(); + if (!ids.contains(id)) { + tempList.add(model); + ids.add(id); + } + } + modelList = tempList; + for (DesignerShapeRelationModel shapeRelationModel : modelList) { + PALRepositoryModel relationPalModel = PALRepositoryCache.getCache().get(shapeRelationModel.getRelationFileId()); + if (relationPalModel != null) { + relationShapeIds.put(shapeRelationModel.getRelationShapeId(), shapeRelationModel); + String key = shapeRelationModel.getShapeId() + "_" + shapeRelationModel.getAttrId(); + if (relationShapeModels.containsKey(key)) { + String value = relationShapeModels.getString(key) + "|" + shapeRelationModel.getRelationShapeText(); + relationShapeModels.put(key, value); + } else { + relationShapeModels.put(key, shapeRelationModel.getRelationShapeText()); + } + } + } + } + } + } + mapOfResult.put("relationShapes", relationShapeIds); + mapOfResult.put("relationShapeModels", relationShapeModels); + return mapOfResult; + } } diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/vo/AttrVO.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/vo/AttrVO.java new file mode 100644 index 00000000..e9409bd6 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/vo/AttrVO.java @@ -0,0 +1,115 @@ +package com.actionsoft.apps.coe.pal.pal.repository.designer.vo; + +import com.alibaba.fastjson.annotation.JSONField; + +/** + * @author oYang + * @Description 形状属性VO + * @createTime 2024年08月02日 17:51:00 + */ +public class AttrVO { + + private final String id; // 属性id + private final String name; // 属性名称 + private final Object value; // 属性值 + private final String type; // 属性类型 + private final Boolean isDiff; // 是否有差异 + private final Object compareAccord; // 对比依据 + private final Integer orderIndex; // 用于排序 + + private AttrVO(Builder builder) { + this.id = builder.id; + this.name = builder.name; + this.value = builder.value; + this.type = builder.type; + this.isDiff = builder.isDiff; + this.compareAccord = builder.compareAccord; + this.orderIndex = builder.orderIndex; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public Object getValue() { + return value; + } + + public String getType() { + return type; + } + + public Boolean getIsDiff() { + return isDiff; + } + + // @JSONField(serialize = false) + public Object getCompareAccord() { + return compareAccord; + } + + @JSONField(serialize = false) + public Integer getOrderIndex() { + return orderIndex; + } + + public static final class Builder { + private String id; + private String name; + private Object value; + private String type; + private Boolean isDiff; + private Object compareAccord; + private Integer orderIndex; + + private Builder() { + } + + public static Builder createBuilder() { + return new Builder(); + } + + public Builder withId(String id) { + this.id = id; + return this; + } + + public Builder withName(String name) { + this.name = name; + return this; + } + + public Builder withValue(Object value) { + this.value = value; + return this; + } + + public Builder withType(String type) { + this.type = type; + return this; + } + + public Builder withIsDiff(Boolean isDiff) { + this.isDiff = isDiff; + return this; + } + + public Builder withCompareAccord(Object compareAccord) { + this.compareAccord = compareAccord; + return this; + } + + public Builder withOrderIndex(Integer orderIndex) { + this.orderIndex = orderIndex; + return this; + } + + public AttrVO build() { + return new AttrVO(this); + } + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/vo/DiffNodeVO.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/vo/DiffNodeVO.java new file mode 100644 index 00000000..70cd038a --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/vo/DiffNodeVO.java @@ -0,0 +1,53 @@ +package com.actionsoft.apps.coe.pal.pal.repository.designer.vo; + +import java.util.List; + +/** + * @author oYang + * @Description 节点及连线对比 + * @createTime 2024年08月07日 13:45:00 + */ +public class DiffNodeVO { + + private final String id; // 节点id或者连线id + private final List type; // 节点或者连线变化类型(多个,连线只有新增) + + private DiffNodeVO(Builder builder) { + this.id = builder.id; + this.type = builder.type; + } + + public String getId() { + return id; + } + + public List getType() { + return type; + } + + public static final class Builder { + private String id; + private List type; + + private Builder() { + } + + public static Builder create() { + return new Builder(); + } + + public Builder withId(String id) { + this.id = id; + return this; + } + + public Builder withType(List type) { + this.type = type; + return this; + } + + public DiffNodeVO build() { + return new DiffNodeVO(this); + } + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/vo/ShapeLinkVO.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/vo/ShapeLinkVO.java new file mode 100644 index 00000000..a337d7a9 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/vo/ShapeLinkVO.java @@ -0,0 +1,111 @@ +package com.actionsoft.apps.coe.pal.pal.repository.designer.vo; + +/** + * @author oYang + * @Description 形状链接 + * @createTime 2024年08月05日 15:08:00 + */ +public class ShapeLinkVO { + + private final String name; + private final String target; + private final String type; + private final String url; + private final String uuid; + private final String value; + private final String versionId; + + public ShapeLinkVO(Builder builder) { + this.name = builder.name; + this.target = builder.target; + this.type = builder.type; + this.url = builder.url; + this.uuid = builder.uuid; + this.value = builder.value; + this.versionId = builder.versionId; + } + + public String getName() { + return name; + } + + public String getTarget() { + return target; + } + + public String getType() { + return type; + } + + public String getUrl() { + return url; + } + + public String getUuid() { + return uuid; + } + + public String getValue() { + return value; + } + + public String getVersionId() { + return versionId; + } + + public static final class Builder { + private String name; + private String target; + private String type; + private String url; + private String uuid; + private String value; + private String versionId; + + private Builder() { + } + + public static Builder createBuilder() { + return new Builder(); + } + + public Builder withName(String name) { + this.name = name; + return this; + } + + public Builder withTarget(String target) { + this.target = target; + return this; + } + + public Builder withType(String type) { + this.type = type; + return this; + } + + public Builder withUrl(String url) { + this.url = url; + return this; + } + + public Builder withUuid(String uuid) { + this.uuid = uuid; + return this; + } + + public Builder withValue(String value) { + this.value = value; + return this; + } + + public Builder withVersionId(String versionId) { + this.versionId = versionId; + return this; + } + + public ShapeLinkVO build() { + return new ShapeLinkVO(this); + } + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/vo/UpFileVO.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/vo/UpFileVO.java new file mode 100644 index 00000000..8b9ea19d --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/vo/UpFileVO.java @@ -0,0 +1,75 @@ +package com.actionsoft.apps.coe.pal.pal.repository.designer.vo; + +/** + * @author oYang + * @Description 形状附件 + * @createTime 2024年08月05日 11:27:00 + */ +public class UpFileVO { + + private final String fileId; + private final String fileName; + private final String downloadUrl; + private final Boolean hasSecurity; + + private UpFileVO(Builder builder) { + this.fileId = builder.fileId; + this.fileName = builder.fileName; + this.downloadUrl = builder.downloadUrl; + this.hasSecurity = builder.hasSecurity; + } + + public String getFileId() { + return fileId; + } + + public String getFileName() { + return fileName; + } + + public String getDownloadUrl() { + return downloadUrl; + } + + public Boolean getHasSecurity() { + return hasSecurity; + } + + public static final class Builder { + private String fileId; + private String fileName; + private String downloadUrl; + private Boolean hasSecurity; + + private Builder() { + } + + public static Builder createBuilder() { + return new Builder(); + } + + public Builder withFileId(String fileId) { + this.fileId = fileId; + return this; + } + + public Builder withFileName(String fileName) { + this.fileName = fileName; + return this; + } + + public Builder withDownloadUrl(String downloadUrl) { + this.downloadUrl = downloadUrl; + return this; + } + + public Builder withHasSecurity(Boolean hasSecurity) { + this.hasSecurity = hasSecurity; + return this; + } + + public UpFileVO build() { + return new UpFileVO(this); + } + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/web/CoeDesignerVersionWeb.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/web/CoeDesignerVersionWeb.java index b5e0d7f3..ef903163 100644 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/web/CoeDesignerVersionWeb.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/web/CoeDesignerVersionWeb.java @@ -3,85 +3,109 @@ package com.actionsoft.apps.coe.pal.pal.repository.designer.web; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +//import com.actionsoft.apps.AppsConst; +import com.actionsoft.apps.coe.pal.constant.CoEConstant; +//import com.actionsoft.apps.coe.pal.pal.method.validate.constant.ValidateStatusEnum; +//import com.actionsoft.apps.coe.pal.pal.processexec.ProcessExecAPIManager; +//import com.actionsoft.apps.coe.pal.pal.processexec.util.ProcessExecUtil; +//import com.actionsoft.apps.coe.pal.pal.repository.PALRepositoryQueryAPIManager; import com.actionsoft.apps.coe.pal.pal.repository.cache.CoeProcessLevelCorrelateCache; import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache; +import com.actionsoft.apps.coe.pal.pal.repository.designer.constant.CoeDesignerConstant; +import com.actionsoft.apps.coe.pal.pal.repository.designer.dto.VersionCompareDTO; import com.actionsoft.apps.coe.pal.pal.repository.designer.dto.VersionListDTO; +//import com.actionsoft.apps.coe.pal.pal.repository.designer.util.CoeDesignerDcUtil; import com.actionsoft.apps.coe.pal.pal.repository.designer.util.DesignerVersionUtil; import com.actionsoft.apps.coe.pal.pal.repository.designer.vo.VersionListVO; import com.actionsoft.apps.coe.pal.pal.repository.model.CoeProcessLevelCorrelateModel; import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel; +import com.actionsoft.apps.coe.pal.pal.repository.util.CoeProcessLevelUtil; +import com.actionsoft.apps.coe.pal.pal.ws.web.VersionUtil; +//import com.actionsoft.apps.coe.pal.util.CoeDcUtil; +import com.actionsoft.bpms.bpmn.constant.ProcessDefinitionConst; import com.actionsoft.bpms.bpmn.engine.cache.ProcessDefCache; +import com.actionsoft.bpms.bpmn.engine.cache.util.ProcessDefVersionUtil; import com.actionsoft.bpms.bpmn.engine.model.def.ProcessDefinition; +import com.actionsoft.bpms.commons.htmlframework.HtmlPageTemplate; import com.actionsoft.bpms.commons.mvc.view.ActionWeb; import com.actionsoft.bpms.commons.mvc.view.ResponseObject; import com.actionsoft.bpms.server.UserContext; +import com.actionsoft.bpms.server.fs.DCContext; +import com.actionsoft.bpms.util.UtilDate; import com.actionsoft.bpms.util.UtilString; +import com.actionsoft.exception.AWSException; +import com.actionsoft.i18n.I18nRes; +import com.actionsoft.sdk.local.SDK; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; /** * 设计器流程版本对比 web层 */ public class CoeDesignerVersionWeb extends ActionWeb { - private static final Logger LOGGER = LoggerFactory.getLogger(CoeDesignerVersionWeb.class); + private static final Logger LOGGER = LoggerFactory.getLogger(CoeDesignerVersionWeb.class); - private final UserContext uc; + private final UserContext uc; - public CoeDesignerVersionWeb(UserContext uc) { - super(uc); - this.uc = uc; - } + public CoeDesignerVersionWeb(UserContext uc) { + super(uc); + this.uc = uc; + } - /** - * 获取版本列表 - * - * @param versionListDTO 版本对比参数 - */ - public String getVersionList(VersionListDTO versionListDTO) { - ResponseObject ro = ResponseObject.newOkResponse(); - String id = versionListDTO.getId(); - List versionListVoList = new ArrayList<>(); - List historyVersionListVoList = new ArrayList<>(); - PALRepositoryModel palModel = PALRepositoryCache.getCache().get(id); - if (palModel != null) { - // 维护pal模型Id与bpm平台模型Id映射 - Map mapOfProcessDefId = new HashMap<>(); - List plVersionModels = PALRepositoryCache.getByVersionId(palModel.getVersionId()); - for (PALRepositoryModel model : plVersionModels) { - CoeProcessLevelCorrelateModel correlateModel = CoeProcessLevelCorrelateCache.getCache().get(model.getId()); - if (correlateModel == null) { - continue; - } - String processDefId = correlateModel.isCorrelate() ? correlateModel.getPlAwsId() : correlateModel.getSourceAwsId(); - if (UtilString.isEmpty(processDefId)) { - continue; - } - ProcessDefinition processDefinition = ProcessDefCache.getInstance().get(processDefId); - if (processDefinition == null) { - continue; - } - mapOfProcessDefId.put(model.getId(), processDefId); - VersionListVO versionListVo = DesignerVersionUtil.getVersionListVo(model, processDefinition, correlateModel.getCreateDate()); - versionListVoList.add(versionListVo); - } - if (!versionListVoList.isEmpty()) { - versionListVoList.sort(Comparator.comparing(VersionListVO::getCorrelateTime).reversed()); - // 历史版本 - historyVersionListVoList = DesignerVersionUtil.getVersionListVoList(id, mapOfProcessDefId); - } else { - versionListVoList = DesignerVersionUtil.getVersionListVoList(id, mapOfProcessDefId); - } - } + /** + * 获取版本列表 + * + * @param versionListDTO 版本对比参数 + */ + public String getVersionList(VersionListDTO versionListDTO) { + ResponseObject ro = ResponseObject.newOkResponse(); + String id = versionListDTO.getId(); + List versionListVoList = new ArrayList<>(); + List historyVersionListVoList = new ArrayList<>(); + PALRepositoryModel palModel = PALRepositoryCache.getCache().get(id); + if (palModel != null) { + // 维护pal模型Id与bpm平台模型Id映射 + Map mapOfProcessDefId = new HashMap<>(); + List plVersionModels = PALRepositoryCache.getByVersionId(palModel.getVersionId()); + for (PALRepositoryModel model : plVersionModels) { + CoeProcessLevelCorrelateModel correlateModel = CoeProcessLevelCorrelateCache.getCache().get(model.getId()); + if (correlateModel == null) { + continue; + } + String processDefId = correlateModel.isCorrelate() ? correlateModel.getPlAwsId() : correlateModel.getSourceAwsId(); + if (UtilString.isEmpty(processDefId)) { + continue; + } + ProcessDefinition processDefinition = ProcessDefCache.getInstance().get(processDefId); + if (processDefinition == null) { + continue; + } + mapOfProcessDefId.put(model.getId(), processDefId); + VersionListVO versionListVo = DesignerVersionUtil.getVersionListVo(model, processDefinition, correlateModel.getCreateDate()); + versionListVoList.add(versionListVo); + } + if (!versionListVoList.isEmpty()) { + versionListVoList.sort(Comparator.comparing(VersionListVO::getCorrelateTime).reversed()); + // 历史版本 + historyVersionListVoList = DesignerVersionUtil.getVersionListVoList(id, mapOfProcessDefId); + } else { + versionListVoList = DesignerVersionUtil.getVersionListVoList(id, mapOfProcessDefId); + } + } - ro.put("versionList", versionListVoList); - ro.put("historyList", historyVersionListVoList); - return ro.toString(); - } + ro.put("versionList", versionListVoList); + ro.put("historyList", historyVersionListVoList); + return ro.toString(); + } // /** // * PAL版本管理-查询版本数据 @@ -245,16 +269,16 @@ public class CoeDesignerVersionWeb extends ActionWeb { // } // return obj; // } -// -// /** -// * 版本对比 -// * -// * @param versionCompareDTO 版本对比参数 -// */ -// public String designerVersionCompare(VersionCompareDTO versionCompareDTO) { -// Map macroLibraries = queryDesignerVersionCompareMap(versionCompareDTO); -// return HtmlPageTemplate.merge(CoEConstant.APP_ID, CoeDesignerConstant.DESIGNER_VERSION_COMPARE_PAGE, macroLibraries); -// } + + /** + * 版本对比 + * + * @param versionCompareDTO 版本对比参数 + */ + public String designerVersionCompare(VersionCompareDTO versionCompareDTO) { + Map macroLibraries = queryDesignerVersionCompareMap(versionCompareDTO); + return HtmlPageTemplate.merge(CoEConstant.APP_ID, CoeDesignerConstant.DESIGNER_VERSION_COMPARE_PAGE, macroLibraries); + } // // /** // * 版本对比 @@ -269,27 +293,27 @@ public class CoeDesignerVersionWeb extends ActionWeb { // ro.setData(macroLibraries); // return ro.toString(); // } -// -// /** -// * 获取 版本对比 map参数 -// * -// * @param versionCompareDTO 版本对比参数 -// */ -// private Map queryDesignerVersionCompareMap(VersionCompareDTO versionCompareDTO) { -// // 获取对比版本的模型数据 -// PALRepositoryModel plModel = PALRepositoryCache.getCache().get(versionCompareDTO.getCompareVerId()); -// JSONObject versionData = DesignerVersionUtil.getVersionData(uc, versionCompareDTO.getCompareVerId(), versionCompareDTO.getTeamId()); -// if (versionData == null) { -// throw new AWSException(I18nRes.findValue(CoEConstant.APP_ID, "获取待比对的版本数据失败")); -// } -// // 获取当前模型数据 -// JSONObject curData = DesignerVersionUtil.getVersionData(uc, versionCompareDTO.getCurId(), versionCompareDTO.getTeamId()); -// if (curData == null) { -// throw new AWSException(I18nRes.findValue(CoEConstant.APP_ID, "获取当前使用的版本数据失败")); -// } -// return DesignerVersionUtil.queryDesignerVersionCompareMap(plModel.getWsId(), plModel.getMethodId(), plModel.getName(), versionCompareDTO.getCompareVerId(), versionData, versionCompareDTO.getCurId(), curData, false, false); -// } -// + + /** + * 获取 版本对比 map参数 + * + * @param versionCompareDTO 版本对比参数 + */ + private Map queryDesignerVersionCompareMap(VersionCompareDTO versionCompareDTO) { + // 获取对比版本的模型数据 + PALRepositoryModel plModel = PALRepositoryCache.getCache().get(versionCompareDTO.getCompareVerId()); + JSONObject versionData = DesignerVersionUtil.getVersionData(uc, versionCompareDTO.getCompareVerId(), versionCompareDTO.getTeamId()); + if (versionData == null) { + throw new AWSException(I18nRes.findValue(CoEConstant.APP_ID, "获取待比对的版本数据失败")); + } + // 获取当前模型数据 + JSONObject curData = DesignerVersionUtil.getVersionData(uc, versionCompareDTO.getCurId(), versionCompareDTO.getTeamId()); + if (curData == null) { + throw new AWSException(I18nRes.findValue(CoEConstant.APP_ID, "获取当前使用的版本数据失败")); + } + return DesignerVersionUtil.queryDesignerVersionCompareMap(plModel.getWsId(), plModel.getMethodId(), plModel.getName(), versionCompareDTO.getCompareVerId(), versionData, versionCompareDTO.getCurId(), curData, false, false); + } + // /** // * 与BPM端流程对比 // * diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/cache/PALUpfileCache.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/cache/PALUpfileCache.java new file mode 100644 index 00000000..9840a031 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/cache/PALUpfileCache.java @@ -0,0 +1,163 @@ +package com.actionsoft.apps.coe.pal.pal.repository.upfile.cache; + +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.actionsoft.apps.coe.pal.constant.CoEConstant; +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.CachePluginProfile; +import com.actionsoft.bpms.commons.cache.Cache; +import com.actionsoft.bpms.commons.cache.CacheManager; +import com.actionsoft.bpms.util.UtilString; +import com.actionsoft.exception.AWSException; +import com.actionsoft.i18n.I18nRes; +import com.actionsoft.sdk.local.SDK; + +/** + * 资产文件附件Cache + */ +public class PALUpfileCache extends Cache { + + private static final Logger LOGGER = LoggerFactory.getLogger(PALUpfileCache.class); + + public PALUpfileCache(CachePluginProfile profile) { + super(profile); + registeIndex(PALUpfileCacheIndex1.class, new PALUpfileCacheIndex1()); // key pl_uuid + } + + public static PALUpfileCache getCache() { + return CacheManager.getCache(PALUpfileCache.class); + } + + public static void putModel(UpfileModel model) { + if (model == null) { + String msg = I18nRes.findValue(CoEConstant.APP_ID, "附件") + "model" + I18nRes.findValue(CoEConstant.APP_ID, "不允许为空"); + throw new AWSException(msg); + } + getCache().put(model.getUuid(), model); + } + + public static void removeById(String uuid) { + if (StringUtils.isEmpty(uuid)) { + throw new AWSException(I18nRes.findValue(CoEConstant.APP_ID, "附件") + "uuid" + I18nRes.findValue(CoEConstant.APP_ID, "不允许为空")); + } + getCache().remove(uuid); + } + + public static List getByPlUuid(String plUuid) { + List upfileModels = iteratorToList(getCache().getByIndex(PALUpfileCacheIndex1.class, plUuid)); + if (upfileModels.isEmpty()) { + return Collections.emptyList(); + } + upfileModels.sort(new UpfileComparator());// 排序 + return upfileModels; + } + + /** + * 根据 plId 和 附件类型 删除缓存数据 + */ + public static void removeByPlIdAndType(String plUuid, String type) { + if (plUuid == null || type == null) { + return; + } + Iterator iter = getCache().getByIndex(PALUpfileCacheIndex1.class, plUuid); + while (iter.hasNext()) { + UpfileModel next = iter.next(); + if (next.getType().equals(type)) { + getCache().remove(next.getUuid()); + } + } + } + + /** + * 根据 plId 删除缓存数据 + */ + public static void removeByPlId(String plUuid) { + if (plUuid == null) { + return; + } + Iterator iter = getCache().getByIndex(PALUpfileCacheIndex1.class, plUuid); + while (iter.hasNext()) { + UpfileModel next = iter.next(); + getCache().remove(next.getUuid()); + } + } + + public static List getByPlUuidAndType(String plUuid, String type) { + List listByPlUuid = getByPlUuid(plUuid); + if (listByPlUuid.isEmpty()) { + return Collections.emptyList(); + } + listByPlUuid = listByPlUuid.stream() + // 过滤 + .filter(item -> type.equals(item.getType())) + // 排序 + .sorted(new UpfileComparator()).collect(Collectors.toList()); + return listByPlUuid; + } + + public static List getByPlUuidAndShapeIds(String plUuid, List shapeIds) { + if (UtilString.isEmpty(plUuid) || shapeIds == null || shapeIds.isEmpty()) { + return Collections.emptyList(); + } + List listByPlUuid = getByPlUuid(plUuid); + if (listByPlUuid.isEmpty()) { + return Collections.emptyList(); + } + listByPlUuid = listByPlUuid.stream() + // 过滤 + .filter(item -> shapeIds.contains(item.getShape_uuid())) + // 排序 + .sorted(new UpfileComparator()).collect(Collectors.toList()); + return listByPlUuid; + } + + public static List getByPlUuidAndShapeId(String plUuid, String shapeId) { + if (UtilString.isEmpty(plUuid) || UtilString.isEmpty(shapeId)) { + return Collections.emptyList(); + } + List listByPlUuid = getByPlUuid(plUuid); + if (listByPlUuid.isEmpty()) { + return Collections.emptyList(); + } + return listByPlUuid.stream().filter(item -> shapeId.equals(item.getShape_uuid())).collect(Collectors.toList()); + } + + @Override + protected void load() { + load(this); + } + + protected void load(Cache t) { + UpFileDao upFileDao = new UpFileDao(); + List _list = upFileDao.queryAll(); + if (_list != null && _list.size() > 0) { + for (UpfileModel model : _list) { + t.put(model.getUuid(), model, false); + } + } + LOGGER.info("[{}]Cache加载CoE流程资产库附件配置 [{}个]", SDK.getAppAPI().getAppContext(CoEConstant.APP_ID).getNameI18N(), ((_list == null) ? 0 : _list.size())); + } + + static class UpfileComparator implements Comparator { + @Override + public int compare(UpfileModel o1, UpfileModel o2) { + // 首先比较创建时间,倒序 + int createTimeComparison = o2.getCreateTime().compareTo(o1.getCreateTime()); + if (createTimeComparison != 0) { + return createTimeComparison; + } + + // 如果创建时间相同,比较名字(默认升序) + return o1.getFileName().compareTo(o2.getFileName()); + } + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/cache/PALUpfileCacheIndex1.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/cache/PALUpfileCacheIndex1.java new file mode 100644 index 00000000..193877a3 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/cache/PALUpfileCacheIndex1.java @@ -0,0 +1,11 @@ +package com.actionsoft.apps.coe.pal.pal.repository.upfile.cache; + +import com.actionsoft.apps.coe.pal.pal.repository.upfile.model.UpfileModel; +import com.actionsoft.bpms.commons.cache.ListValueIndex; + +public class PALUpfileCacheIndex1 extends ListValueIndex { + @Override + public String key(UpfileModel upfileModel) { + return upfileModel.getPl_uuid(); + } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/constant/CoeFileConstant.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/constant/CoeFileConstant.java index cbfeb0d3..655a0d94 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/constant/CoeFileConstant.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/constant/CoeFileConstant.java @@ -14,4 +14,7 @@ public interface CoeFileConstant { */ String COE_UPFILE = "COE_Upfile"; String TMP_UPFILE = "tmp"; + String FILE_TYPE_F = "f"; // 模型附件 + String FILE_TYPE_S = "s"; // 形状附件 + String FILE_TYPE_A = "a"; // 属性附件 } diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/dao/UpFileDao.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/dao/UpFileDao.java index 58fd8e63..89e1e906 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/dao/UpFileDao.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/dao/UpFileDao.java @@ -5,6 +5,8 @@ import com.actionsoft.bpms.commons.database.RowMapper; import com.actionsoft.bpms.util.DBSql; import com.actionsoft.bpms.util.UtilString; import com.actionsoft.exception.AWSDataAccessException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.sql.Connection; import java.sql.PreparedStatement; @@ -20,6 +22,7 @@ import java.util.Map; * @version 创建时间:2014-4-8 */ public class UpFileDao { + private static final Logger LOGGER = LoggerFactory.getLogger(UpFileDao.class); /** * 创建附件Model * @@ -251,4 +254,18 @@ public class UpFileDao { return DBSql.query(sql, new UpfileModelMapper(), new Object[]{uuid, shapeId}); } } + /** + * 获取所有文件附件 + * + * @return + */ + public List queryAll() { + String sql = "SELECT * FROM " + UpfileModel.DATABASE_ENTITY; + try { + return DBSql.query(sql, new UpfileModelMapper()); + } catch (AWSDataAccessException e) { + LOGGER.error(e.getMessage(), e); + } + return new ArrayList(); + } } diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/model/UpfileModel.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/model/UpfileModel.java index 2a9a5d78..7923c1b0 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/model/UpfileModel.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/model/UpfileModel.java @@ -3,6 +3,7 @@ */ package com.actionsoft.apps.coe.pal.pal.repository.upfile.model; +import java.io.Serializable; import java.sql.Timestamp; /** @@ -10,7 +11,7 @@ import java.sql.Timestamp; * @version 创建时间:2014-4-8 * */ -public class UpfileModel { +public class UpfileModel implements Serializable { public static final String DATABASE_ENTITY = "APP_ACT_COE_PAL_UPFILE"; public static final String FIELD_UUID = "ID"; public static final String FIELD_PL_UUID = "PALREPOSITORYID"; @@ -22,6 +23,7 @@ public class UpfileModel { public static final String FIELD_SECURITY_LEVEL = "SECURITYLEVEL"; public static final String FIELD_CREATEUSER = "CREATEUSER"; public static final String FIELD_CREATETIME = "CREATETIME"; + public static final String FIELD_ATTRID = "ATTRID"; private String uuid; /** @@ -65,6 +67,10 @@ public class UpfileModel { * 上传时间 */ private Timestamp createTime; + /** + * 属性id + */ + private String attrId; /** * 下载url,数据库无该字段,后期自行拼装 @@ -150,5 +156,12 @@ public class UpfileModel { public void setCreateTime(Timestamp createTime) { this.createTime = createTime; } + public String getAttrId() { + return attrId; + } + + public void setAttrId(String attrId) { + this.attrId = attrId; + } } diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/util/CoeUpFileUtil.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/util/CoeUpFileUtil.java new file mode 100644 index 00000000..e591a743 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/util/CoeUpFileUtil.java @@ -0,0 +1,304 @@ +package com.actionsoft.apps.coe.pal.pal.repository.upfile.util; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.actionsoft.apps.coe.pal.components.model.PALSecurityLevelModel; +import com.actionsoft.apps.coe.pal.constant.CoEConstant; +//import com.actionsoft.apps.coe.pal.pal.method.cache.PALMethodAttributeCache; +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodAttributeModel; +import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.cache.DesignerShapeRelationCache; +import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.model.DesignerShapeRelationModel; +import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel; +import com.actionsoft.apps.coe.pal.pal.repository.upfile.cache.PALUpfileCache; +import com.actionsoft.apps.coe.pal.pal.repository.upfile.constant.CoeFileConstant; +import com.actionsoft.apps.coe.pal.pal.repository.upfile.model.UpfileModel; +import com.actionsoft.apps.coe.pal.pal.repository.util.CoeProcessLevelUtil; +import com.actionsoft.apps.coe.pal.util.HighSecurityUtil; +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.server.fs.dc.DCUtil; +import com.actionsoft.bpms.util.UtilString; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + +/** + * COE 附件上传工具类 处理设计器中 文件附件、形状附件
+ * 属性附件参考: {@link MethodAttrUpFileUtil} + */ +public class CoeUpFileUtil { + + private static final Logger LOGGER = LoggerFactory.getLogger(CoeUpFileUtil.class); + + /** + * DCPluginProfile 对象 COE_Upfile + */ + private static final DCPluginProfile DC_UPFILE_PROFILE = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE); + + /** + * 获取 DCContext + * + * @param uc 用户上下文 + * @param model 上传文件模型 + */ + public static DCContext getUpFileDCContext(UserContext uc, UpfileModel model) { + DCContext dcContext = null; + if (DC_UPFILE_PROFILE != null) { + if (CoeFileConstant.FILE_TYPE_F.equals(model.getType())) { + // 文件 + dcContext = new DCContext(uc, DC_UPFILE_PROFILE, CoEConstant.APP_ID, "file", model.getPl_uuid(), model.getFileName()); + } else if (CoeFileConstant.FILE_TYPE_S.equals(model.getType())) { + // 图形 + dcContext = new DCContext(uc, DC_UPFILE_PROFILE, CoEConstant.APP_ID, model.getPl_uuid(), model.getShape_uuid(), model.getFileName()); + } else { + // 属性 + dcContext = MethodAttrUpFileUtil.getDCContext(model, uc); + } + } + return dcContext; + } + + /** + * 获取 上传文件的 DCContext + */ + public static DCContext getUpFileDCContext(UserContext uc, String groupValue, String fileValue, String fileName) { + DCContext dcContext = null; + if (DC_UPFILE_PROFILE != null) { + dcContext = new DCContext(uc, DC_UPFILE_PROFILE, CoEConstant.APP_ID, groupValue, fileValue, fileName); + } + return dcContext; + } +// +// /** +// * 获取tmp目录对应DCContext +// *
+//	 *     文件附件:tmp/upfile/uuid/fileName
+//	 *     形状附件:tmp/upfile/uuid_shapeId/fileName
+//	 *     文件属性附件:tmp/attr_upfile/uuid_attrId/fileName
+//	 *     形状属性附件:tmp/attr_upfile/uuid_shapeId_attrId/fileName
+//	 * 
+// * +// * @param model 上传文件模型 +// */ +// public static DCContext getTmpUpFileDCContext(UpfileModel model) { +// return getTmpUpFileDCContext(model.getType(), model.getPl_uuid(), model.getShape_uuid(), model.getAttrId(), model.getFileName()); +// } +// +// /** +// * 获取tmp目录对应DCContext +// *
+//	 *     文件附件:tmp/upfile/uuid/fileName
+//	 *     形状附件:tmp/upfile/uuid_shapeId/fileName
+//	 *     文件属性附件:tmp/attr_upfile/uuid_attrId/fileName
+//	 *     形状属性附件:tmp/attr_upfile/uuid_shapeId_attrId/fileName
+//	 * 
+// */ +// public static DCContext getTmpUpFileDCContext(String type, String plId, String shapeId, String attrId, String fileName) { +// DCContext dcContext = null; +// if (CoeFileConstant.FILE_TYPE_F.equals(type)) { +// // 文件 +// dcContext = DCUtil.createTempFileContext(CoEConstant.APP_ID, "upfile", plId, null); +// } else if (CoeFileConstant.FILE_TYPE_S.equals(type)) { +// // 图形 +// dcContext = DCUtil.createTempFileContext(CoEConstant.APP_ID, "upfile", plId + "_" + shapeId, null); +// } else if (CoeFileConstant.FILE_TYPE_A.equals(type)) { +// // 属性 +// dcContext = MethodAttrUpFileUtil.getTmpUpFileDCContext(plId, shapeId, attrId, fileName); +// } +// // 设置文件名称 +// if (dcContext != null) { +// dcContext.setFileName(fileName); +// } +// return dcContext; +// } +// +// /** +// * 将tmp目录中文件移动到COE目录下,移动后删除tmp目录文件 +// */ +// public static void moveTmpFileToCOE(UpfileModel model) { +// DCContext tmpContext = CoeUpFileUtil.getTmpUpFileDCContext(model); +// DCContext coeContext = CoeUpFileUtil.getUpFileDCContext(null, model); +// if (tmpContext != null && coeContext != null) { +// String fName = model.getFileName(); +// tmpContext.setFileName(fName); +// coeContext.setFileName(fName); +// if (tmpContext.existFile()) { +// DCUtil.copyDCFile(tmpContext, coeContext); +// tmpContext.delete(); +// } +// } +// } +// +// /** +// * 删除DC目录及文件 +// * +// * @param dcContext 文件上传 DC对象 +// * @throws Exception 异常抛出 +// */ +// public static void removeUpFileDc(DCContext dcContext) throws Exception { +// if (dcContext != null) { +// dcContext.delete(); +// String fName = dcContext.getFileName(); +// if (!fName.contains(".")) { +// return; +// } +// String dirName = fName.substring(0, fName.lastIndexOf(".")); +// dcContext.setFileName(dirName); +// if (dcContext.existFile()) { +// dcContext.delete(); +// } +// // pdf 删除 +// if (!fName.endsWith(".pdf")) { +// dcContext.setFileName(dirName + ".pdf"); +// if (dcContext.existFile()) { +// dcContext.delete(); +// } +// } +// } +// } +// +// /** +// * 组装附件列表信息 +// * +// * @param wsId 资产库ID +// * @param methodId 建模方法ID +// * @param plId 模型ID +// * @param fileAttachmentList 文件附件列表 +// * @param shapeAttachmentMap 形状附件map数据 key:shapeId,value JSONArray +// * @param relationAttachmentList 文件关联附件列表 +// * @param relationShapeAttachmentMap 关联形状附件map数据 key:shapeId,value JSONArray +// */ +// public static void wrapperAttachmentList(UserContext uc, String wsId, String methodId, String plId, JSONArray fileAttachmentList, Map shapeAttachmentMap, JSONArray relationAttachmentList, Map relationShapeAttachmentMap) { +// List upfileModels = PALUpfileCache.getByPlUuid(plId); +// for (UpfileModel model : upfileModels) { +// String shapeUuid = model.getShape_uuid(); +// JSONObject object = wrapperAttachmentObj(uc, model); +// if ("f".equals(model.getType())) { +// fileAttachmentList.add(object); +// } else if ("s".equals(model.getType()) && UtilString.isNotEmpty(shapeUuid)) { +// shapeAttachmentMap.computeIfAbsent(shapeUuid, k -> new JSONArray()).add(object); +// } +// } +// List relationModels = DesignerShapeRelationCache.getListByFileId(plId); +// Map> relationModelsMap = relationModels.stream().collect(Collectors.groupingBy(item -> UtilString.isEmpty(item.getShapeId()))); +// // 关联附件列表 +// List fileRelationModels = relationModelsMap.getOrDefault(true, Collections.emptyList()); +// List shapeRelationModels = relationModelsMap.getOrDefault(false, Collections.emptyList()); +// +// // 文件关联附件组装 +// List relFileUpfileModels = getRelationAttachmentList(wsId, methodId, fileRelationModels); +// relFileUpfileModels.forEach(model -> relationAttachmentList.add(wrapperAttachmentObj(uc, model))); +// // 形状关联附件组装 +// Map> shapeRelationModelsMap = shapeRelationModels.stream().filter(item -> UtilString.isNotEmpty(item.getShapeId())).collect(Collectors.groupingBy(DesignerShapeRelationModel::getShapeId)); +// for (Map.Entry> entry : shapeRelationModelsMap.entrySet()) { +// String shapeId = entry.getKey(); +// List models = entry.getValue(); +// List relShapeUpfileModels = getRelationAttachmentList(wsId, methodId, models); +// relShapeUpfileModels.forEach(model -> { +// // 组装附件信息 +// JSONObject object = wrapperAttachmentObj(uc, model); +// relationShapeAttachmentMap.computeIfAbsent(shapeId, k -> new JSONArray()).add(object); +// }); +// } +// } +// +// /** +// * 组装附件信息 +// */ +// public static JSONObject wrapperAttachmentObj(UserContext uc, UpfileModel model) { +// return wrapperAttachmentObj(uc, model, null); +// } +// +// /** +// * 组装附件信息 +// */ +// public static JSONObject wrapperAttachmentObj(UserContext uc, UpfileModel model, JSONObject refObj) { +// JSONObject object = new JSONObject(); +// object.put("fileName", model.getFileName()); +// object.put("fileId", model.getUuid()); +// object.put("uuid", model.getUuid()); +// object.put("attrId", model.getAttrId()); +// object.put("shapeId", model.getShape_uuid()); +// object.put("download", model.getDownload()); +// object.put("securityLevel", model.getSecurityLevel()); +// object.put("hasSecurity", true); +// if (HighSecurityUtil.isON() && HighSecurityUtil.fileSecuritySwitch()) { +// int userSecurityLevel = uc.getUserModel().getSecurityLevel(); +// PALSecurityLevelModel upFileSecurityLevelInfo = HighSecurityUtil.getUpFileSecurityLevelInfo(model.getUuid()); +// int upfileSecurityLevel = Integer.parseInt(upFileSecurityLevelInfo.getCode()); +// if (userSecurityLevel < upfileSecurityLevel) { +// object.put("hasSecurity", false); +// } +// object.put("securityInfo", upFileSecurityLevelInfo); +// } +// boolean isDownload = true; +// // 判断ref是否存在 +// if (refObj != null) { +// isDownload = refObj.getBooleanValue("isDownload"); +// boolean isPreview = refObj.getBooleanValue("isPreview"); +// object.put("isDownload", isDownload); +// object.put("isPreview", isPreview); +// } +// String downloadURL = ""; +// if (isDownload) { +// DCContext dcContext = CoeUpFileUtil.getUpFileDCContext(uc, model); +// if (dcContext != null) { +// downloadURL = dcContext.getDownloadURL() + "&isInline=false"; +// } +// } +// object.put("url", downloadURL); +// return object; +// } +// +// /** +// * 获取当前模型关联的其他模型的附件集合 +// */ +// public static List getRelationAttachmentList(String wsId, String methodId, List relationModels) { +// List relUpfileModels = new ArrayList<>(); +// // attrKey , relationType[ref中的type] +// Map relationTypeMap = new HashMap<>(); +// // 获取属性列表 +// List attributeList = PALMethodAttributeCache.getListByMethodIdAndWsId(methodId, wsId); +// for (PALMethodAttributeModel model : attributeList) { +// String relationType = "shape"; +// if ("relation".equals(model.getType())) { +// JSONObject refObj = JSONObject.parseObject(model.getRef()); +// relationType = refObj.containsKey("type") ? refObj.getString("type") : "shape"; +// } +// relationTypeMap.put(model.getKey(), relationType); +// } +// for (DesignerShapeRelationModel relationModel : relationModels) { +// String attrId = relationModel.getAttrId(); +// if (!relationTypeMap.containsKey(attrId)) { +// continue; +// } +// String type = relationTypeMap.get(attrId); +// if ("file".equals(type)) { +// String relationFileId = relationModel.getRelationFileId(); +// PALRepositoryModel uesRelPlModel = CoeProcessLevelUtil.getUseRepositoryByVersionId(relationFileId); +// if (uesRelPlModel != null) { +// List useRelUpFileList = PALUpfileCache.getByPlUuid(uesRelPlModel.getId()); +// if (!useRelUpFileList.isEmpty()) { +// relUpfileModels.addAll(useRelUpFileList); +// } +// } +// } else { +// List useRelUpFileList = PALUpfileCache.getByPlUuidAndShapeId(relationModel.getRelationFileId(), relationModel.getRelationShapeId()); +// if (!useRelUpFileList.isEmpty()) { +// relUpfileModels.addAll(useRelUpFileList); +// } +// } +// } +// return relUpfileModels; +// } + +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/util/MethodAttrUpFileUtil.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/util/MethodAttrUpFileUtil.java new file mode 100644 index 00000000..d6e989b3 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/upfile/util/MethodAttrUpFileUtil.java @@ -0,0 +1,125 @@ +package com.actionsoft.apps.coe.pal.pal.repository.upfile.util; + +import java.util.HashSet; +import java.util.Set; + +import com.actionsoft.apps.coe.pal.constant.CoEConstant; +import com.actionsoft.apps.coe.pal.pal.method.constant.PALMethodConst; +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.server.fs.dc.DCUtil; +import com.actionsoft.bpms.util.UtilString; + +/** + * @author oYang + * @Description 建模属性附件工具类 + * @createTime 2024年03月26日 17:06:00 + */ +public class MethodAttrUpFileUtil { + + private static final Set audioAndImageTypes = new HashSet<>(); + + static { + audioAndImageTypes.add("jpg"); + audioAndImageTypes.add("jpeg"); + audioAndImageTypes.add("png"); + audioAndImageTypes.add("gif"); + + audioAndImageTypes.add("mp3"); + audioAndImageTypes.add("mp4"); + audioAndImageTypes.add("avi"); + } + + /** + * 获取DCContext + * + * @param upfileModel 文件模型 + * @param userContext 用户上下文 + * @return DCContext + */ + public static DCContext getDCContext(UpfileModel upfileModel, UserContext userContext) { + DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, PALMethodConst.ATTR_FILE_DC_REPOSITORY_NAME); + DCContext dcContext = null; + String fileName = upfileModel.getFileName(); + if (dcProfile != null) { + if (UtilString.isEmpty(upfileModel.getShape_uuid())) { // 文件属性附件 + dcContext = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getAttrId(), fileName); + } else { + dcContext = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid() + "_" + upfileModel.getAttrId(), fileName); + } + } + return dcContext; + } + + /** + * 获取DCContext + * + * @param dcPluginProfile + * @param userContext + * @param upfileModel + * @return + */ + public static DCContext getDCContext(DCPluginProfile dcPluginProfile, UserContext userContext, UpfileModel upfileModel) { + DCContext dcContext = null; + if (UtilString.isEmpty(upfileModel.getShape_uuid())) { // 文件属性附件 + dcContext = new DCContext(userContext, dcPluginProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getAttrId()); + } else { + dcContext = new DCContext(userContext, dcPluginProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid() + "_" + upfileModel.getAttrId()); + } + return dcContext; + } +// +// /** +// * 获取属性附件临时目录 +// *
+//	 *     文件属性附件:tmp/attr_upfile/uuid_attrId/fileName
+//	 *     形状属性附件:tmp/attr_upfile/uuid_shapeId_attrId/fileName
+//	 * 
+// * +// * @return DCContext 对象 +// */ +// public static DCContext getTmpUpFileDCContext(UpfileModel upfileModel) { +// DCContext dcContext; +// if (UtilString.isEmpty(upfileModel.getShape_uuid())) { +// // 文件属性附件 +// dcContext = DCUtil.createTempFileContext(CoEConstant.APP_ID, PALMethodConst.ATTR_FILE_DC_REPOSITORY_NAME, upfileModel.getPl_uuid() + "_" + upfileModel.getAttrId(), upfileModel.getFileName()); +// } else { +// dcContext = DCUtil.createTempFileContext(CoEConstant.APP_ID, PALMethodConst.ATTR_FILE_DC_REPOSITORY_NAME, upfileModel.getPl_uuid() + "_" + upfileModel.getShape_uuid() + "_" + upfileModel.getAttrId(), upfileModel.getFileName()); +// } +// return dcContext; +// } +// +// /** +// * 获取属性附件临时目录 +// *
+//	 *     文件属性附件:tmp/attr_upfile/uuid_attrId/fileName
+//	 *     形状属性附件:tmp/attr_upfile/uuid_shapeId_attrId/fileName
+//	 * 
+// * +// * @return DCContext 对象 +// */ +// public static DCContext getTmpUpFileDCContext(String plId, String shapeId, String attrId, String fileName) { +// DCContext dcContext; +// if (UtilString.isEmpty(shapeId)) { +// // 文件属性附件 +// dcContext = DCUtil.createTempFileContext(CoEConstant.APP_ID, PALMethodConst.ATTR_FILE_DC_REPOSITORY_NAME, plId + "_" + attrId, null); +// } else { +// dcContext = DCUtil.createTempFileContext(CoEConstant.APP_ID, PALMethodConst.ATTR_FILE_DC_REPOSITORY_NAME, plId + "_" + shapeId + "_" + attrId, null); +// } +// dcContext.setFileName(fileName); +// return dcContext; +// } +// +// /** +// * 判断文件类型是否是音频或图片 +// * +// * @param fileType 文件类型 +// * @return true/false +// */ +// public static boolean predicateFileTypeIsAudioOrImage(String fileType) { +// return audioAndImageTypes.contains(fileType); +// } +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/plugin/Plugins.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/plugin/Plugins.java index adb18440..3a8cd488 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/plugin/Plugins.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/plugin/Plugins.java @@ -63,6 +63,8 @@ import com.actionsoft.apps.coe.pal.pal.manage.publish.cache.PublishUserGroupCach import com.actionsoft.apps.coe.pal.pal.manage.publish.cache.PublishUserGroupPermCache; import com.actionsoft.apps.coe.pal.pal.manage.publish.cache.PublishUserGroupRoleCache; import com.actionsoft.apps.coe.pal.pal.method.aslp.RegisterMethodApp; +import com.actionsoft.apps.coe.pal.pal.method.cache.PALBasicMethodCache; +import com.actionsoft.apps.coe.pal.pal.method.cache.PALMethodSchemaCache; import com.actionsoft.apps.coe.pal.pal.output.aslp.RegisterOutputApp; import com.actionsoft.apps.coe.pal.pal.repository.addons.RepositoryDiagramExistMark; import com.actionsoft.apps.coe.pal.pal.repository.cache.CoeProcessLevelCorrelateCache; @@ -80,6 +82,7 @@ import com.actionsoft.apps.coe.pal.pal.repository.designer.realtime.manage.CoeLi import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.cache.DesignerShapeRelationCache; import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.manager.DesignerShapeCopyCache; import com.actionsoft.apps.coe.pal.pal.repository.upfile.CoeFileProcessor; +import com.actionsoft.apps.coe.pal.pal.repository.upfile.cache.PALUpfileCache; import com.actionsoft.apps.coe.pal.pal.repository.upfile.constant.CoeFileConstant; import com.actionsoft.apps.coe.pal.teamwork.cache.TeamMemberPermCache; import com.actionsoft.apps.coe.pal.teamwork.cache.TeamPermCache; @@ -134,6 +137,9 @@ public class Plugins implements PluginListener { list.add(new CachePluginProfile(CoeCooperationTeamPermCache.class)); list.add(new CachePluginProfile(CoeCooperationRoleCache.class)); list.add(new CachePluginProfile(CoeCooperationRolePermCache.class)); + list.add(new CachePluginProfile(PALUpfileCache.class)); + list.add(new CachePluginProfile(PALBasicMethodCache.class)); + list.add(new CachePluginProfile(PALMethodSchemaCache.class)); list.add(new AtFormulaPluginProfile("PAL应用", "@getDWCondition(*fieldName,*fieldValue)", GetDWConditionExpression.class.getName(), "获取DW中的自定义查询条件", "返回DW中自定义的查询条件")); diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/util/CoeDcUtil.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/util/CoeDcUtil.java new file mode 100644 index 00000000..d240f879 --- /dev/null +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/util/CoeDcUtil.java @@ -0,0 +1,171 @@ +package com.actionsoft.apps.coe.pal.util; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; + +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.actionsoft.bpms.server.fs.DCContext; +import com.actionsoft.bpms.util.Base64; +import com.actionsoft.sdk.local.SDK; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + +/** + * COE处理DC工具类 + */ +public class CoeDcUtil { + + private static final Logger LOGGER = LoggerFactory.getLogger(CoeDcUtil.class); + + /** + * 类型转换 {@link DCContext } 转换为 {@link JSONArray}
+ * DC判空,且判断DC文件是否存在,不存在则返回 null + * + * @return 返回 JSONArray ,若为空则返回 null + */ + public static JSONArray dcContextToJa(DCContext dcContext) { + if (dcContext == null || !dcContext.existFile()) { + return null; + } + InputStream read = SDK.getDCAPI().read(dcContext); + return inputStreamToJa(read); + } + + /** + * 类型转换 {@link DCContext } 转换为 {@link JSONObject}
+ * DC判空,且判断DC文件是否存在,不存在则返回 null + * + * @return 返回 JSONObject ,若为空则返回 null + */ + public static JSONObject dcContextToJo(DCContext dcContext) { + if (dcContext == null || !dcContext.existFile()) { + return null; + } + InputStream read = SDK.getDCAPI().read(dcContext); + return inputStreamToJo(read); + } + + /** + * 类型转换 {@link DCContext } 转换为 {@link String}
+ * DC判空,且判断DC文件是否存在,不存在则返回 null + * + * @return 返回 String ,若为空则返回 ""; + */ + public static String dcContextToString(DCContext dcContext) { + if (dcContext == null || !dcContext.existFile()) { + return ""; + } + InputStream read = SDK.getDCAPI().read(dcContext); + return inputStreamToString(read); + } + + /** + * 类型转换 {@link DCContext } 转换为 {@link String}
+ * DC判空,且判断DC文件是否存在,不存在则返回 null + * + * @return 返回 byte ,若为空则返回 null + */ + public static byte[] dcContextToByte(DCContext dcContext) { + if (dcContext == null || !dcContext.existFile()) { + return null; + } + InputStream read = SDK.getDCAPI().read(dcContext); + return inputStreamToByte(read); + } + + /** + * 类型转换 {@link DCContext } 转换为 base64 数据 {@link String}
+ * DC判空,且判断DC文件是否存在,不存在则返回 null
+ * 携带前缀:data:image/png;base64, + * + * @return 返回 byte ,若为空则返回 null + */ + public static String dcContextToBase64(DCContext dcContext) { + byte[] bytes = dcContextToByte(dcContext); + if (bytes == null) { + return null; + } + byte[] base64Bytes = Base64.encode(bytes); + return "data:image/png;base64," + new String(base64Bytes, StandardCharsets.UTF_8); + } + + /** + * 类型转换 {@link InputStream } 转换为 {@link JSONArray} + * + * @return 返回 JSONArray ,若为空则返回 null + */ + public static JSONArray inputStreamToJa(InputStream inputStream) { + String str = inputStreamToString(inputStream); + try { + return JSONArray.parseArray(str); + } catch (Exception e) { + LOGGER.error("inputStream[{}]格式不正确,转换JSONArray[失败]", str, e); + return null; + } + } + + /** + * 类型转换 {@link InputStream } 转换为 {@link JSONObject} + * + * @return 返回 JSONObject ,若为空则返回 null + */ + public static JSONObject inputStreamToJo(InputStream inputStream) { + String str = inputStreamToString(inputStream); + try { + return JSON.parseObject(str); + } catch (Exception e) { + LOGGER.error("inputStream[{}]格式不正确,转换JSONObject[失败]", str, e); + return null; + } + } + + /** + * 类型转换 {@link InputStream } 转换为 {@link String} + * + * @return 返回 String ,若为空则返回 null + */ + public static String inputStreamToString(InputStream inputStream) { + if (inputStream == null) { + return null; + } + try { + return IOUtils.toString(inputStream, StandardCharsets.UTF_8); + } catch (Exception e) { + LOGGER.error(e.getMessage(), e); + return null; + } + } + + /** + * 类型转换 {@link InputStream } 转换为 byte[] + * + * @return 返回 byte[] ,若为空则返回 null + */ + public static byte[] inputStreamToByte(InputStream inputStream) { + if (inputStream == null) { + return null; + } + try { + return IOUtils.toByteArray(inputStream); + } catch (Exception e) { + LOGGER.error(e.getMessage(), e); + return null; + } + } + + /** + * 数据写入 DC + */ + public static boolean write(String define, DCContext dcContext) { + if (define == null || dcContext == null) { + return false; + } + return SDK.getDCAPI().write(new ByteArrayInputStream(define.getBytes(StandardCharsets.UTF_8)), dcContext); + } + +} diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/util/HighSecurityUtil.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/util/HighSecurityUtil.java index 8d507dd8..fbf6c66b 100644 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/util/HighSecurityUtil.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/util/HighSecurityUtil.java @@ -13,6 +13,10 @@ import com.actionsoft.i18n.I18nRes; import com.actionsoft.sdk.local.SDK; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.actionsoft.apps.coe.pal.components.model.PALSecurityLevelModel; +import com.actionsoft.apps.coe.pal.pal.repository.upfile.cache.PALUpfileCache; +import com.actionsoft.apps.coe.pal.constant.CoEConstant; +import com.actionsoft.exception.AWSException; import java.lang.reflect.Field; import java.util.*; @@ -222,5 +226,65 @@ public class HighSecurityUtil { boolean fileSwitch = Boolean.parseBoolean(param); return fileSwitch; } - + /** + * 获取附件密级信息 + * + * @param upfileId 附件Id + * @return 密级信息 + */ + public static PALSecurityLevelModel getUpFileSecurityLevelInfo(String upfileId) { + UpfileModel upfileModel = PALUpfileCache.getCache().get(upfileId); + Integer securityLevel = upfileModel.getSecurityLevel(); + return getSecurityLevelModel(securityLevel); + } + private static PALSecurityLevelModel getSecurityLevelModel(Integer securityLevel) { + if (securityLevel == null || securityLevel == -1) { + return new PALSecurityLevelModel("-1", I18nRes.findValue(CoEConstant.APP_ID, "未标密"), "#f56c6c"); + } + Map securityInfoMap = getSecurityInfoMap(); + PALSecurityLevelModel userSecurityInfo = securityInfoMap.get(String.valueOf(securityLevel)); + if (userSecurityInfo == null) { + return new PALSecurityLevelModel("-1", I18nRes.findValue(CoEConstant.APP_ID, "未知密级"), "#f56c6c"); + } + return userSecurityInfo; + } + /** + * 获取密级列表Map + * + * @return 密级列表Map + */ + public static Map getSecurityInfoMap() { + Map map = new HashMap<>(); + if (isON()) { + // 获取平台的对象秘级参数设置 + HashMap securityMap = getObjSecurityMap(); + // 获取PAL应用参数密级颜色设置 + JSONObject highSecurityFontStyle = getHighSecurityFontStyle(); + Set> entries = securityMap.entrySet(); + for (Map.Entry entry : entries) { + String key = entry.getKey(); + String value = entry.getValue(); + JSONObject colorObject = highSecurityFontStyle.getJSONObject(key); + String color = ""; + if (colorObject != null) { + color = colorObject.getString("color"); + } + PALSecurityLevelModel palSecurityLevelModel = new PALSecurityLevelModel(key, value, color); + map.put(key, palSecurityLevelModel); + } + } + return map; + } + /** + * 获取密级样式设置 + * + * @return + */ + public static JSONObject getHighSecurityFontStyle() { + JSONObject highSecurityFontStyle = SDK.getAppAPI().getPropertyJSONObjectValue(CoEConstant.APP_ID, "HighSecurityFontStyle", new JSONObject()); + if (highSecurityFontStyle == null || highSecurityFontStyle.isEmpty()) { + throw new AWSException("请设置密级样式"); + } + return highSecurityFontStyle; + } } diff --git a/com.actionsoft.apps.coe.pal/template/page/pal.pl.repository.designer.htm b/com.actionsoft.apps.coe.pal/template/page/pal.pl.repository.designer.htm index f7ec0dd6..7ec90139 100755 --- a/com.actionsoft.apps.coe.pal/template/page/pal.pl.repository.designer.htm +++ b/com.actionsoft.apps.coe.pal/template/page/pal.pl.repository.designer.htm @@ -1109,10 +1109,11 @@ }*/ - + +
diff --git a/com.actionsoft.apps.coe.pal/web/com.actionsoft.apps.coe.pal/lib/designer/scripts/versionCompare/version.core.debug.js b/com.actionsoft.apps.coe.pal/web/com.actionsoft.apps.coe.pal/lib/designer/scripts/versionCompare/version.core.debug.js deleted file mode 100644 index fab58bd8..00000000 --- a/com.actionsoft.apps.coe.pal/web/com.actionsoft.apps.coe.pal/lib/designer/scripts/versionCompare/version.core.debug.js +++ /dev/null @@ -1,3641 +0,0 @@ -/** - * 抽取的核心渲染画布的代码 - */ - -const VersionDesigner = { - config: { - panelItemWidth: 30, - panelItemHeight: 30, - pageMargin: 10, - anchorSize: 8, - rotaterSize: 9, - anchorColor: "#833", - selectorColor: "#833", - scale: { - left: 1, - right: 1 - } - }, - init(pos) { - this.initialize.initModel(pos) - this.initialize.initCanvas(pos) - this.initialize.initPageShapes(pos) - this.initialize.initEvent(pos) - }, - initialize: { - initModel: function (pos) { - let definition = pageDefinition[pos], Model = PageModel[pos] - if (definition != undefined && definition.localAttribute != undefined) { - Model.define.localAttribute = definition.localAttribute - } else { - Model.define.localAttribute = {} - } - if (definition != undefined && definition.commonShapeConfig != undefined) { - Model.define.commonShapeConfig = definition.commonShapeConfig - } else { - Model.define.commonShapeConfig = {} - } - Model.shapeTemplateObj = {} - Model.persistence = { - page: Utils.copy(Model.define.page), - elements: {}, - localAttribute: {}, - commonShapeConfig: {} - } - }, - initCanvas: function (pos) { - let Model = PageModel[pos]; - var q = Model.define.page.width.toScale(pos); - var v = Model.define.page.height.toScale(pos); - var B = Model.define.page.backgroundColor; - var s = Utils.getDarkerColor(B); - var A = Utils.getDarkestColor(B); - $("#designer-canvas-" + pos).css({ - "background-color": "rgb(" + s + ")" - }); - var w = $("#designer-grids-" + pos); - w.attr({ - width: q, - height: v - }); - var h = w[0].getContext("2d"); - h.clearRect(0, 0, q, v); - var r = Model.define.page.padding.toScale(pos); - var y = q - r * 2; - var p = v - r * 2; - h.fillStyle = "rgb(" + B + ")"; - h.beginPath(); - h.rect(r, r, y, p); - h.fill(); - var x = Math.round(Model.define.page.gridSize.toScale(pos)); - if (x < 10) { - x = 10 - } - if (Model.define.page.showGrid) { - h.translate(r, r); - h.lineWidth = 1; - h.save(); - var t = 0.5; - var u = 0; - while (t <= p) { - h.restore(); - if (u % 4 == 0) { - h.strokeStyle = "rgb(" + A + ")" - } else { - h.strokeStyle = "rgb(" + s + ")" - } - h.beginPath(); - h.moveTo(0, t); - h.lineTo(y, t); - t += x; - u++; - h.stroke() - } - t = 0.5; - u = 0; - while (t <= y) { - h.restore(); - if (u % 4 == 0) { - h.strokeStyle = "rgb(" + A + ")" - } else { - h.strokeStyle = "rgb(" + s + ")" - } - h.beginPath(); - h.moveTo(t, 0); - h.lineTo(t, p); - t += x; - u++; - h.stroke() - } - } - $("#canvas-container-" + pos).css({ - width: q, - height: v, - padding: VersionDesigner.config.pageMargin - }); - }, - initPageShapes: function (pos) { - var shapes = pageDefinition[pos].elements; - let Model = PageModel[pos]; - var shapeCount = 0; - for (var shapeId in shapes) { - var shape = shapes[shapeId]; - if (shape.name != "linker") { - Schema.initShapeFunctions(shape); - VersionDesigner.painter.renderShape(shape, pos); - Model.add(shape, false); - } - shapeCount++; - } - for (var shapeId in shapes) { - var shape = shapes[shapeId]; - if (shape.name == "linker") { - VersionDesigner.painter.renderLinker(pos, shape); - Model.add(shape, false); - } - } - if (shapeCount == 0) { - Model.build(); - } - // 绘制差异节点中的删除(已经不在当前版本中了具体信息要从对比版本获取) - let diffDelete = diffNode.filter(i => i.type.includes('delete')) - diffDelete.forEach(i => { - let shape = PageModel.left.getShapeById(i.id) - if (shape.name !== 'linker') { - VersionDesigner.painter.renderDiffNode(shape, 'right') - } - }) - }, - initEvent: function (pos) { - $("#designer-canvas-" + pos).off("mousedown").on("mousedown", function (g) { - var b = $("#designer-canvas-" + pos); - var f = Utils.getRelativePos(g.pageX, g.pageY, b); - var c = Utils.getShapeByPosition(pos, f.x, f.y); - if (c != null) { - if (c.type == "dataAttribute") { - } else { - Utils.unselect(pos); - Utils.selectShape(pos, c.shape.id); - } - } else { - Utils.unselect(pos); - } - versionCompareFun.updateAttributeView(pos) - $('.shape-tip').hide() - Utils.selectedOtherShape(pos) - }); - document.addEventListener('wheel', function (event) { - if (event.ctrlKey) { - if ($(event.target).closest('.version-designer-layout').length > 0) { - event.preventDefault() - let isUp = event.deltaY < 0 // 大于0向下滚动 -- 缩小 小于0向上滚动 -- 放大 - let pos = $(event.target).closest('.version-designer-layout').attr('position') - versionCompareFun.pageZoom(pos, isUp ? 'zoomIn' : 'zoomOut') - } - } - }, {passive: false}) // 添加事件监听器时明确指定 { passive: false } 这告诉浏览器该监听器可能需要调用 preventDefault() - } - }, - painter: { - controlStatus: { - resizeDir: [], - rotatable: true - }, - actions: { - move: function (b) { - this.moveTo(b.x, b.y); - this.prePoint = b; - if (this.beginPoint == null) { - this.beginPoint = b - } - }, - line: function (d) { - if (typeof this.webkitLineDash != "undefined" && typeof this.lineDashOffset == "undefined" && this.lineWidth != 0) { - var f = this.webkitLineDash; - var c = this.prePoint; - var h = Utils.measureDistance(c, d); - var k = 0; - var b = 1 / h; - var j = c; - var e = 0; - var g = true; - while (k < 1) { - k += b; - if (k > 1) { - k = 1 - } - var i = { - x: (1 - k) * c.x + k * d.x, - y: (1 - k) * c.y + k * d.y - }; - var a = Utils.measureDistance(j, i); - if (a >= f[e] || k >= 1) { - if (g) { - this.lineTo(i.x, i.y) - } else { - this.moveTo(i.x, i.y) - } - g = !g; - j = i; - e++; - if (e >= f.length) { - e = 0 - } - } - } - this.moveTo(d.x, d.y) - } else { - this.lineTo(d.x, d.y) - } - this.prePoint = d; - if (this.beginPoint == null) { - this.beginPoint = d - } - }, - curve: function (e) { - if (typeof this.webkitLineDash != "undefined" && typeof this.lineDashOffset == "undefined" && this.lineWidth != 0) { - var g = this.webkitLineDash; - var d = this.prePoint; - var i = Utils.measureDistance(d, e); - var n = 0; - var b = 1 / i; - var l = d; - var f = 0; - var h = true; - var c = 0; - while (n < 1) { - n += b; - if (n > 1) { - n = 1 - } - var k = { - x: d.x * Math.pow((1 - n), 3) + e.x1 * n * Math.pow((1 - n), 2) * 3 + e.x2 * Math.pow(n, 2) * (1 - n) * 3 + e.x * Math.pow(n, 3), - y: d.y * Math.pow((1 - n), 3) + e.y1 * n * Math.pow((1 - n), 2) * 3 + e.y2 * Math.pow(n, 2) * (1 - n) * 3 + e.y * Math.pow(n, 3) - }; - var a = Utils.measureDistance(l, k); - if (a >= g[f] || n >= 1) { - if (h) { - var m = c + (n - c) / 2; - var j = { - x: d.x * Math.pow((1 - m), 3) + e.x1 * m * Math.pow((1 - m), 2) * 3 + e.x2 * Math.pow(m, 2) * (1 - m) * 3 + e.x * Math.pow(m, 3), - y: d.y * Math.pow((1 - m), 3) + e.y1 * m * Math.pow((1 - m), 2) * 3 + e.y2 * Math.pow(m, 2) * (1 - m) * 3 + e.y * Math.pow(m, 3) - }; - this.lineTo(j.x, j.y); - this.lineTo(k.x, k.y) - } else { - this.moveTo(k.x, k.y) - } - h = !h; - l = k; - c = n; - f++; - if (f >= g.length) { - f = 0 - } - } - } - this.moveTo(e.x, e.y) - } else { - this.bezierCurveTo(e.x1, e.y1, e.x2, e.y2, e.x, e.y) - } - this.prePoint = e; - if (this.beginPoint == null) { - this.beginPoint = e - } - }, - quadraticCurve: function (e) { - if (typeof this.webkitLineDash != "undefined" && typeof this.lineDashOffset == "undefined" && this.lineWidth != 0) { - var g = this.webkitLineDash; - var d = this.prePoint; - var i = Utils.measureDistance(d, e); - var n = 0; - var b = 1 / i; - var l = d; - var f = 0; - var h = true; - var c = 0; - while (n < 1) { - n += b; - if (n > 1) { - n = 1 - } - var k = { - x: d.x * Math.pow((1 - n), 2) + e.x1 * n * (1 - n) * 2 + e.x * Math.pow(n, 2), - y: d.y * Math.pow((1 - n), 2) + e.y1 * n * (1 - n) * 2 + e.y * Math.pow(n, 2) - }; - var a = Utils.measureDistance(l, k); - if (a >= g[f] || n >= 1) { - if (h) { - var m = c + (n - c) / 2; - var j = { - x: d.x * Math.pow((1 - m), 2) + e.x1 * m * (1 - m) * 2 + e.x * Math.pow(m, 2), - y: d.y * Math.pow((1 - m), 2) + e.y1 * m * (1 - m) * 2 + e.y * Math.pow(m, 2) - }; - this.lineTo(j.x, j.y); - this.lineTo(k.x, k.y) - } else { - this.moveTo(k.x, k.y) - } - h = !h; - l = k; - c = n; - f++; - if (f >= g.length) { - f = 0 - } - } - } - this.moveTo(e.x, e.y) - } else { - this.quadraticCurveTo(e.x1, e.y1, e.x, e.y) - } - this.prePoint = e; - if (this.beginPoint == null) { - this.beginPoint = e - } - }, - close: function () { - if (typeof this.webkitLineDash != "undefined" && typeof this.lineDashOffset == "undefined" && this.lineWidth != 0) { - var f = this.webkitLineDash; - var c = this.prePoint; - var d = this.beginPoint; - var h = Utils.measureDistance(c, d); - var k = 0; - var b = 1 / h; - var j = c; - var e = 0; - var g = true; - while (k < 1) { - k += b; - if (k > 1) { - k = 1 - } - var i = { - x: (1 - k) * c.x + k * d.x, - y: (1 - k) * c.y + k * d.y - }; - var a = Utils.measureDistance(j, i); - if (a >= f[e] || k >= 1) { - if (g) { - this.lineTo(i.x, i.y) - } else { - this.moveTo(i.x, i.y) - } - g = !g; - j = i; - e++; - if (e >= f.length) { - e = 0 - } - } - } - } - this.closePath() - }, - curveArc: function (a) { - this.arc(a.centerX, a.centerY, a.radius, a.startAngle, a.endAngle, true); - } - }, - setLineDash: function (d, c) { - if (!d.setLineDash) { - d.setLineDash = function () { - } - } - d.setLineDash(c); - d.mozDash = c; - d.webkitLineDash = c - }, - renderShapePath: function (pos, f, e, h) { - var g; - if (h && e.drawIcon) { - g = e.drawIcon(e.props.w, e.props.h) - } else { - g = e.getPath(pos) - } - this.renderPath(f, e, g, h) - }, - renderPath: function (m, o, i, t) { - for (var q = 0; q < i.length; q++) { - var s = i[q]; - m.save(); - m.beginPath(); - var p = $.extend({}, - o.lineStyle, s.lineStyle); - var n = $.extend({}, - o.fillStyle, s.fillStyle); - if (s.textStyle) { - // path 中文字处理 - m.font = s.textStyle.size + " " + o.fontStyle.fontFamily; - m.fillStyle = "rgb(" + s.textStyle.color + ")"; - m.fillText(s.textStyle.text, s.textStyle.x, s.textStyle.y); - } - for (var r = 0; r < s.actions.length; r++) { - var j = s.actions[r]; - this.actions[j.action].call(m, j) - } - this.fillShape(o, m, n); - this.iconImage(o, m, s.iconImage); - if (p.lineWidth) { - m.lineWidth = p.lineWidth; - m.strokeStyle = "rgb(" + p.lineColor + ")"; - if (p.lineStyle == "dashed") { - if (t) { - this.setLineDash(m, [p.lineWidth * 4, p.lineWidth * 2]) - } else { - this.setLineDash(m, [p.lineWidth * 6, p.lineWidth * 3]) - } - } else if (p.lineStyle == "dot") { - this.setLineDash(m, [p.lineWidth, p.lineWidth * 2]) - } else if (p.lineStyle == "dashdot") { - this.setLineDash(m, [p.lineWidth * 6, p.lineWidth * 2, p.lineWidth, p.lineWidth * 2]) - } - m.stroke() - } - m.restore() - } - }, - handleShapeConfigData: function (dataArray, q, attributesJsonArray) { - //先去除重复的配置--在拼装数据前,先删除数据 - var temp1; - for (var i = q.dataAttributes.length - 1; i >= 0; i--) { - temp1 = q.dataAttributes[i]; - var hor = temp1.horizontal; - var ver = temp1.vertical; - if (temp1.hasOwnProperty("attributesJsonArray")) { - var temp2 = temp1.dataShowConfig; - if (temp2 != undefined) { - temp2.value = []; - } - break - } - } - var key = q.name; - for (var i = 0; i < dataArray.length; i++) { - var temp = dataArray[i]; - var showType = temp.showType; - var horizontal = temp.horizontal; - horizontal = horizontal.toLowerCase(); - var verity = temp.verity; - verity = verity.toLowerCase(); - if (verity == "center") { - verity = "middle"; - } - if (showType == "text" || showType == "attribute") { - var cfgContent = temp.cfgContent; - var params = { - "w": 30, - "h": 30, - "textw": 20, - "texth": 17, - "imgT": 0, - "category": "custom", - "icon": "", - "name": key, - "showName": false, - "showType": "text", //text icon - "type": "string", - "value": cfgContent, - "horizontal": horizontal, - "vertical": verity, - "radius": 5, - "title": "", - "color": temp.color - }; - if (showType == "attribute") { - var attrId = temp.key; - var attrType = "string"; - if (attributesJsonArray.length > 0) { - for (var j = 0; j < attributesJsonArray.length; j++) { - var attr = attributesJsonArray[j]; - if (attr.key == attrId) { - attrType = attr.type; - cfgContent = attr.value; - break; - } - } - } - var attrTypeArray = ['string', 'select', 'select_m', 'textarea']; - if (temp.isShowAttrName && attrTypeArray.indexOf(attrType) >= 0 && (cfgContent + '').trim().length > 0) { - cfgContent = "(" + temp.attrName + ")" + cfgContent; - } - if (attrType == "relation") { - var shapeIdAttrId = q.id + "_" + attrId; - var relationData = relationShapeModelObject; - var relationValue = ""; - // for (var j = 0; j < cfgContent.length; j++) { - // if (j == cfgContent.length - 1) { - // if (relationData.hasOwnProperty(shapeIdAttrId)) { - // var tempRelationValue = relationData[shapeIdAttrId]; - // relationValue = relationValue + tempRelationValue; - // } - // } else if (relationData.hasOwnProperty(shapeIdAttrId)) { - // var tempRelationValue = relationData[shapeIdAttrId] + "|"; - // relationValue = relationValue + tempRelationValue; - // } - // } - if (relationData.hasOwnProperty(shapeIdAttrId)) { - relationValue = relationData[shapeIdAttrId] - } - cfgContent = relationValue; - if (temp.isShowAttrName) { - cfgContent = "(" + temp.attrName + ")" + cfgContent; - } - } - params.showType = "attr"; - params.value = cfgContent; - params.color = temp.color - } - if (!q.dataAttributes) { - q.dataAttributes = []; - } - params.id = Utils.newId(); - params.category = "custom"; - if (!temp1.dataShowConfig) { - temp1.dataShowConfig = {}; - if (!temp1.dataShowConfig.value) { - temp1.dataShowConfig.value = []; - } - } - temp1.dataShowConfig.value.push(params); - //Model.updateMulti([q]); - } else { - var iconContent = temp.iconContent; - var params = { - "w": 16, - "h": 16, - "textw": 20, - "texth": 17, - "imgT": 0, - "category": "custom", - "icon": iconContent, - "name": key, - "showName": false, - "showType": "icon", //text icon - "type": "string", - "value": "", - "horizontal": horizontal, - "vertical": verity - }; - if (!q.dataAttributes) { - q.dataAttributes = []; - } - params.id = Utils.newId(); - params.category = "custom"; - if (!temp1.dataShowConfig) { - temp1.dataShowConfig = {}; - if (!temp1.dataShowConfig.value) { - temp1.dataShowConfig.value = []; - } - } - temp1.dataShowConfig.value.push(params); - //Model.updateMulti([q]); - } - } - }, - renderShape: function (q, pos) { - if (q.name == "linker") { - this.renderLinker(pos, q); - return - } - let Model = PageModel[pos]; - var commonShapeConfig = Utils.copy(Model.define.commonShapeConfig); - var specialShapeConfig; - var attributesJsonArray; - var dataAttributes = q.dataAttributes; - for (var i = 0; i < dataAttributes.length; i++) { - var temp = dataAttributes[i]; - if (temp.hasOwnProperty("attributesJsonArray")) { - if (temp.dataShowConfig) { - specialShapeConfig = temp.dataShowConfig.config; - } - attributesJsonArray = temp.attributesJsonArray; - break; - } - } - var key = q.name; - if (specialShapeConfig == undefined) { - if (commonShapeConfig != undefined && commonShapeConfig[key] != undefined) { - commonShapeConfig = commonShapeConfig[key]; - this.handleShapeConfigData(commonShapeConfig, q, attributesJsonArray); - } - } else { - if (commonShapeConfig == undefined) { - this.handleShapeConfigData(Utils.copy(specialShapeConfig), q, attributesJsonArray); - } else { - commonShapeConfig = commonShapeConfig[key]; - var tempCommonShapeConfig = []; - if (commonShapeConfig != undefined) { - var dataArray = []; - var tempArray = []; - for (i = 0; i < commonShapeConfig.length; i++) { - var temp1 = commonShapeConfig[i]; - for (j = 0; j < specialShapeConfig.length; j++) { - var temp2 = specialShapeConfig[j]; - if (temp1.horizontal == temp2.horizontal && temp1.verity == temp2.verity) { - tempArray.push(i); - break; - } - } - } - if (tempArray.length > 0) { - for (i = 0; i < commonShapeConfig.length; i++) { - if (!(tempArray.indexOf(i) >= 0)) { - tempCommonShapeConfig.push(commonShapeConfig[i]); - } - } - } - } - if (tempCommonShapeConfig.length > 0) { - dataArray = specialShapeConfig.concat(tempCommonShapeConfig); - } else { - dataArray = specialShapeConfig; - } - this.handleShapeConfigData(dataArray, q, attributesJsonArray); - } - } - var v = $("#designer-canvas-" + pos); - var o = v.find("#" + q.id); - if (o.length == 0) { - if (q.category == 'lane') { - o = $("
").appendTo(v) - } else { - o = $("
").appendTo(v) - } - } - var t = Utils.getShapeBox(q); - var w = (t.w + 20).toScale(pos); - var s = (t.h + 20).toScale(pos); - o.find(".shape_canvas").attr({ - width: w, - height: s - }); - o.css({ - left: (t.x - 10).toScale(pos) + "px", - top: (t.y - 10).toScale(pos) + "px", - width: w, - height: s - }); - var n = o.find(".shape_canvas")[0].getContext("2d"); - n.clearRect(0, 0, q.props.w + 20, q.props.h + 20); - n.scale(VersionDesigner.config.scale[pos], VersionDesigner.config.scale[pos]); - n.translate(10, 10); - n.translate(q.props.x - t.x, q.props.y - t.y); - n.translate(q.props.w / 2, q.props.h / 2); - n.rotate(q.props.angle); - n.translate(-(q.props.w / 2), -(q.props.h / 2)); - if (q.highLight) { - n.shadowBlur = 9; - n.shadowColor = "rgba(0, 0, 0, 0.5)"; - } - var x = q.lineStyle; - n.globalAlpha = q.shapeStyle.alpha; - n.lineJoin = "round"; - this.renderShapePath(pos, n, q); - this.renderMarkers(n, q); - var m = q.getPath(pos); - var p = Utils.copy(m[m.length - 1]); - p.fillStyle = { - type: "none" - }; - p.lineStyle = { - lineWidth: 0 - }; - var u = [p]; - this.renderPath(n, q, u); - this.renderText(pos, q, t); - this.renderDataAttributes(pos, q, t); - this.renderTitleShow(pos, q, t); - if (!isProcessExec) { - VersionDesigner.painter.renderShapeLink(o, q); //节点链接 - VersionDesigner.painter.renderSahpeAttachment(pos, o, q); //节点附件 - if (attributesJsonArray != undefined && attributesJsonArray.length > 0) { - o.find(".shape_danger").remove(); - o.find(".shape_regulate").remove(); - var A = false; - var z = false; - for (var r in attributesJsonArray) { - var l = attributesJsonArray[r]; - if (l != undefined && l.key == "danger" && l.value != undefined && l.value != "" && relationShapeInfo[pos] != undefined) { - if (typeof l.value == 'object' && l.value.constructor == Array) { - for (var m = 0; m < l.value.length; m++) { - if (relationShapeInfo[pos][l.value[m]] != undefined) { - A = true; - break; - } - } - } else if (relationShapeInfo[pos][l.value] != undefined) { - A = true; - } - } else { - if (l != undefined && l.key == "regulate" && l.value != undefined && l.value != "" && relationShapeInfo[pos] != undefined) { - if (typeof l.value == 'object' && l.value.constructor == Array) { - for (var m = 0; m < l.value.length; m++) { - if (relationShapeInfo[pos][l.value[m]] != undefined) { - z = true; - break; - } - } - } else if (relationShapeInfo[pos][l.value] != undefined) { - z = true; - } - } - } - } - if (A) { - var y = $("
").appendTo(o) - } - if (z) { - var y = $("
").appendTo(o) - } - } - } - this.renderDiffNode(q, pos) - }, - renderDiffNode: function (q, pos) { - if (pos === 'right') { - // 右侧是当前版本 差异图元只会在右侧渲染 - let index = diffNode.findIndex(i => i.id === q.id) - if (index !== -1) { - const v = $("#designer-canvas-" + pos); - const icon = { - add: { - code: '', - color: '#E02020', - qtip: 新增图元 - }, - delete: { - code: '', - color: '#E02020', - qtip: 删除图元 - }, - position: { - code: '', - color: '#FF8F0B', - qtip: 图元位置变化 - }, - info: { - code: '', - color: '#FF8F0B', - qtip: 图元信息变化 - }, - style: { - code: '', - color: '#FF8F0B', - qtip: 图元名称样式变化 - }, - } - let type = diffNode[index].type - let iconStr = '' - type.forEach(i => { - iconStr += ` - ${icon[i].code} - ` - }) - let diffDom = v.find("#diff-node-" + q.id) - let width, height, left, top, background, border - if (diffDom.length === 0) { - diffDom = $(`
`).appendTo(v) - } - if (type.includes('delete')) { - let a = $("#designer-canvas-left").find("#" + q.id) - width = parseInt(a.css('width')).restoreScale('left').toScale('right') - height = parseInt(a.css('height')).restoreScale('left').toScale('right') - left = parseInt(a.css('left')).restoreScale('left').toScale('right') - top = parseInt(a.css('top')).restoreScale('left').toScale('right') - background = 'rgba(224, 32, 32, 0.15)' - border = '#E02020' - } else { - let a = v.find("#" + q.id) - width = parseInt(a.css('width')) - height = parseInt(a.css('height')) - left = parseInt(a.css('left')) - top = parseInt(a.css('top')) - background = type.includes('add') ? 'rgba(224, 32, 32, 0.15)' : 'rgba(255, 143, 11, 0.15)' - border = type.includes('add') ? '#E02020' : '#FF8F0B' - } - diffDom.css({ - boxSizing: 'border-box', - left: left + 'px', - top: top + 'px', - width: width + 'px', - height: height + 'px', - background: background, - border: `1.2px dashed ${border}` - }) - let a = diffDom.find(".diff-icon-wrapper") - if (a.length === 0) { - let b = $(`
${iconStr}
`).appendTo(diffDom) - b.children('span[type=info]').off('mousedown').on('mousedown', function (eve) { - eve.stopPropagation() - }) - b.children('span[type=info]').off('click').on('click', function (eve) { - eve.stopPropagation() - Utils.unselect(pos); - Utils.selectShape(pos, q.id) - versionCompareFun.openAttributeView(pos) - Utils.selectedOtherShape(pos) - }) - } - } - } - }, - iconImage: function (n, i, h) { - if (!h) { - return; - } - // 画布保存 - i.save(); - var m = imageDefMap[h.imageId]; - var maxLength = n.props.h, relLength; - if (h.type === "colorOverlay") { - maxLength = 30; - } - relLength = maxLength * 0.65 - // 获取或创建图片元素 - var k = $(".shape_img[src='" + m + "']"); - if (k.length === 0) { - k = $("").appendTo("#shape_img_container"); - k.one("load.drawshape", function () { - i.translate(0, 0); - drawIcon(k, maxLength, relLength); - k.attr("loaded", "1"); - }); - } else if (k.attr("loaded") === "0") { - k.one("load.drawshape", function () { - i.translate(0, 0); - drawIcon(k, maxLength, relLength); - }); - } else { - drawIcon(k, maxLength, relLength); - } - - // 图片icon绘制,按图片比例处理 - function drawIcon(r, maxLength, relLength) { - i.save(); - var desiredHeight, desiredWidth; - var aspectRatio = r[0].width / r[0].height; - if (aspectRatio > 1) { - desiredWidth = relLength; - desiredHeight = desiredWidth * aspectRatio; - } else { - desiredHeight = relLength; - desiredWidth = desiredHeight * aspectRatio; - } - var center = maxLength / 2 - var adjustedX = center - desiredWidth / 2; - var adjustedY = center - desiredHeight / 2; - i.drawImage(r[0], adjustedX, adjustedY, desiredWidth, desiredHeight); - i.restore(); - } - }, - fillShape: function (n, i, h) { - i.save(); - // 颜色叠加 - if (typeof h.colorOverlay !== 'undefined') { - if (h.colorOverlay === 'multiplyOverlay') { - h.color = multiplyColors(h.color); - } - } - if (h.type == "solid") { - i.fillStyle = "rgb(" + h.color + ")"; - i.fill() - } else if (h.type == "gradient") { - var j; - if (h.gradientType == "linear") { - j = GradientHelper.createLinearGradient(n, i, h) - } else { - j = GradientHelper.createRadialGradient(n, i, h) - } - i.fillStyle = j; - i.fill() - } else if (h.type === "image" || h.type === "imageDef") { - let isInvalidImage = false // 自定义图片图元 图片是否被替换标志位 - let m = h.fileId - if (h.from === 'insert') { - m = shapeImages[h.fileId] - } - if (h.type === "imageDef") { - if (imageDefMap[h.fileId]) { - m = imageDefMap[h.fileId] - } else { - m = shapeImages[h.fileId] - isInvalidImage = true - } - } - var k = $(".shape_img[src='" + m + "']"); - if (k.length == 0) { - k = $("").appendTo("#shape_img_container"); - k.bind("load.drawshape", - function () { - var b = h.from === 'insert' ? 0 : (VersionDesigner.config.panelItemWidth - n.props.w) / 2; - var a = h.from === 'insert' ? 0 : (VersionDesigner.config.panelItemHeight - n.props.h) / 2; - if (isInvalidImage) { - a = 0 - b = 0 - } - i.translate(b, a); - l(k); - i.restore(); - $(this).attr("loaded", "1") - }); - k.attr("src", m) - } else if (k.attr("loaded") == "0") { - k.bind("load.drawshape", - function () { - // var b = (VersionDesigner.config.panelItemWidth - n.props.w) / 2; - // var a = (VersionDesigner.config.panelItemHeight - n.props.h) / 2; - var b = 0;// by sunlh 20200716 svg shape - var a = 0; - i.translate(b, a); - l(k); - i.restore() - }) - } else { - l(k) - } - } - - // 颜色叠加 乘法处理 - function multiplyColors(color1) { - // 将颜色转换为RGB数组格式 - let [r1, g1, b1] = color1.split(',').map(Number); - let [r2, g2, b2] = color1.split(',').map(Number); - let r = (r1 / 255) * (r2 / 255) * 255; - let g = (g1 / 255) * (g2 / 255) * 255; - let b = (b1 / 255) * (b2 / 255) * 255; - // 返回新的RGB颜色字符串 - return `${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)}`; - } - - i.restore(); - - function l(r) { - i.save(); - i.clip(); - if (h.display == "fit") { - var d = r.width(); - var q = r.height(); - var a = d / q; - var e = n.props.w / n.props.h; - if (a > e) { - var g = n.props.w; - var b = 0; - var s = g / a; - var c = n.props.h / 2 - s / 2; - i.drawImage(r[0], b, c, g, s) - } else { - var s = n.props.h; - var c = 0; - var g = s * a; - var b = n.props.w / 2 - g / 2; - i.drawImage(r[0], b, c, g, s) - } - } else { - if (h.display == "stretch") { - i.drawImage(r[0], 0, 0, n.props.w, n.props.h) - } else { - if (h.display == "original") { - var d = r.width(); - var q = r.height(); - var b = n.props.w / 2 - d / 2; - var c = n.props.h / 2 - q / 2; - i.drawImage(r[0], b, c, d, q) - } else { - if (h.display == "tile") { - var b = 0; - var d = r.width(); - var q = r.height(); - while (b < n.props.w) { - var c = 0; - while (c < n.props.h) { - i.drawImage(r[0], b, c, d, q); - c += q - } - b += d - } - } else { - if (h.display == "static") { - var u = 0; - var t = r.width(); - var f = r.height(); - i.drawImage(r[0], h.imageX, h.imageY, t, f) - } else { - if (h.display == "zoom") { - var u = 0; - var t = r.width(); - var f = r.height(); - i.drawImage(r[0], h.imageX, h.imageY, t, f, h.canvasX, h.canvasY, h.canvasW, h.canvasH) - } else { - var d = r.width(); - var q = r.height(); - var a = d / q; - var e = n.props.w / n.props.h; - if (a > e) { - var s = n.props.h; - var c = 0; - var g = s * a; - var b = n.props.w / 2 - g / 2; - i.drawImage(r[0], b, c, g, s) - } else { - var g = n.props.w; - var b = 0; - var s = g / a; - var c = n.props.h / 2 - s / 2; - i.drawImage(r[0], b, c, g, s) - } - } - } - } - } - } - } - i.restore() - } - }, - renderText: function (pos, z, r) { - var B = $("#designer-canvas-" + pos).find("#" + z.id); - var v = B.find(".text_canvas[forshape=" + z.id + "]"); - if (v.length == 0) { - v = $("").appendTo(B); - v.bind("focus", - function () { - $(this).blur() - }) - } - v.attr("readonly", "readonly"); - if (z.text == null || z.text.trim() == "" || (z.attribute.editable == false && z.title == z.text)) { - v.css({ - height: "0px", - width: "0px" - }).hide(); - return - } - var C = z.fontStyle; - var G = { - "line-height": Math.round(C.size * 1.25) + "px", - "font-size": C.size + "px", - "font-family": C.fontFamily, - "font-weight": C.bold ? "bold" : "normal", - "font-style": C.italic ? "italic" : "normal", - "text-align": C.textAlign, - color: "rgb(" + C.color + ")", - "text-decoration": C.underline ? "underline" : "none", - opacity: z.shapeStyle.alpha - }; - v.css(G); - v.show(); - var s = z.getTextBlock(); - if (z.fontStyle.orientation == "horizontal") { - var D = { - x: s.x + s.w / 2, - y: s.y + s.h / 2 - }; - s = { - x: D.x - s.h / 2, - y: D.y - s.w / 2, - w: s.h, - h: s.w - } - } - v.css({ - width: s.w - }); - v.height(0); - v.val(z.text); - v.scrollTop(99999); - var E = v.scrollTop(); - var y = 0; - if (C.vAlign == "middle") { - y = (s.y + s.h / 2 - E / 2) - } else { - if (z.fontStyle.vAlign == "bottom") { - y = (s.y + s.h - E) - } else { - y = s.y - } - } - var t = { - x: s.x + s.w / 2, - y: y + E / 2 - }; - var w = z.props.angle; - if (w != 0) { - var H = { - x: z.props.w / 2, - y: z.props.h / 2 - }; - t = Utils.getRotated(H, t, w) - } - if (C.orientation == "horizontal") { - w = (Math.PI * 1.5 + w) % (Math.PI * 2) - } - var F = Math.round(w / (Math.PI * 2) * 360); - var x = "rotate(" + F + "deg) scale(" + VersionDesigner.config.scale[pos] + ")"; - var A = s.w; - var u = E; - v.css({ - width: A, - height: u, - left: (t.x + (z.props.x - r.x) + 10).toScale(pos) - s.w / 2, - top: (t.y + (z.props.y - r.y) + 10).toScale(pos) - E / 2, - "-webkit-transform": x, - "-ms-transform": x, - "-o-transform": x, - "-moz-transform": x, - transform: x - }) - }, - renderLinker: function (pos, h) { - let Model = PageModel[pos] - if (h.linkerType == "curve" || h.linkerType == "broken") { - if (!h.points || h.points.length == 0) { - h.points = Utils.getLinkerPoints(h) - } - } - var q = h.points; - var o = Utils.copy(h.from); - var a = Utils.copy(h.to); - if (h.attribute && h.attribute.collapseBy) { - $("#designer-canvas-" + pos).find("#" + h.id).hide() - return - } else { - $("#designer-canvas-" + pos).find("#" + h.id).show() - } - var p = Utils.getEndpointAngle(h, "from"); - var d = Utils.getEndpointAngle(h, "to"); - var b = Utils.getLinkerLineStyle(pos, h.lineStyle); - l(pos, o, h, b.beginArrowStyle, p); - l(pos, a, h, b.endArrowStyle, d); - var B = a.x; - var x = a.y; - var y = o.x; - var w = o.y; - if (a.x < o.x) { - B = a.x; - y = o.x - } else { - B = o.x; - y = a.x - } - if (a.y < o.y) { - x = a.y; - w = o.y - } else { - x = o.y; - w = a.y - } - for (var r = 0; r < q.length; r++) { - var n = q[r]; - if (n.x < B) { - B = n.x - } else { - if (n.x > y) { - y = n.x - } - } - if (n.y < x) { - x = n.y - } else { - if (n.y > w) { - w = n.y - } - } - } - var f = { - x: B, - y: x, - w: y - B, - h: w - x - }; - var C = $("#designer-canvas-" + pos).find("#" + h.id); - if (C.length == 0) { - var g = $("#designer-canvas-" + pos); - C = $("
").appendTo(g) - } - if (!Model.getShapeById(h.id)) { - C.css("z-index", Model.orderList.length + 1) - C.css({'pointer-events': 'none'}) - } - var A = C.find(".shape_canvas"); - A.attr({ - width: (f.w + 20).toScale(pos), - height: (f.h + 20).toScale(pos) - }); - C.css({ - left: (f.x - 10).toScale(pos), - top: (f.y - 10).toScale(pos), - width: (f.w + 20).toScale(pos), - height: (f.h + 20).toScale(pos) - }); - var m = A[0].getContext("2d"); - m.scale(VersionDesigner.config.scale[pos], VersionDesigner.config.scale[pos]); - m.translate(10, 10); - var s = Utils.getLinkerLineStyle(pos, h.lineStyle); - m.lineWidth = s.lineWidth; - m.strokeStyle = "rgb(" + s.lineColor + ")"; - m.fillStyle = "rgb(" + s.lineColor + ")"; - if (h.highLight) { - m.shadowBlur = 15; - m.shadowColor = "rgba(0, 0, 0, 0.5)"; - } - m.save(); - var z = { - x: o.x - f.x, - y: o.y - f.y - }; - var c = { - x: a.x - f.x, - y: a.y - f.y - }; - m.save(); - if (s.lineStyle == "dashed") { - this.setLineDash(m, [s.lineWidth * 5, s.lineWidth * 2]) - } else { - if (s.lineStyle == "dot") { - this.setLineDash(m, [s.lineWidth, s.lineWidth * 1.5]) - } else { - if (s.lineStyle == "dashdot") { - this.setLineDash(m, [s.lineWidth * 5, s.lineWidth * 2, s.lineWidth, s.lineWidth * 2]) - } - } - } - m.lineJoin = "round"; - m.beginPath(); - this.actions.move.call(m, z); - if (h.linkerType == "curve") { - var v = q[0]; - var u = q[1]; - var t = { - x1: v.x - f.x, - y1: v.y - f.y, - x2: u.x - f.x, - y2: u.y - f.y, - x: c.x, - y: c.y - }; - this.actions.curve.call(m, t) - } else { - for (var r = 0; r < q.length; r++) { - var D = q[r]; - this.actions.line.call(m, { - x: D.x - f.x, - y: D.y - f.y - }) - } - this.actions.line.call(m, c) - } - var j = Utils.isSelected(h.id, pos); - if (j) { - m.shadowBlur = 4; - m.shadowColor = "#833"; - if (h.linkerType == "curve" && Utils.getSelectedIds(pos).length == 1) { - } - } - // region 差异线 - if (pos === 'right') { - let index = diffNode.findIndex(i => i.id === h.id) - if (index !== -1) { - m.shadowBlur = 4; - m.shadowColor = "#833"; - } - } - // endregion - m.stroke(); - m.restore(); - delete m.webkitLineDash; - e(z, p, o.id, s.beginArrowStyle, h, o.angle); - e(c, d, a.id, s.endArrowStyle, h, a.angle); - m.restore(); - this.renderLinkerText(pos, h); - - function l(pos, M, H, i, J) { - let Model = PageModel[pos] - if (M.id) { - var E = Model.getShapeById(M.id); - if (E) { - var G = { - x: 0, - y: 0 - }; - var I = Utils.getShapeLineStyle(pos, E.lineStyle); - var L = Utils.getLinkerLineStyle(pos, H.lineStyle); - if (i == "none" || i == "cross") { - G.x = -I.lineWidth / 2 - } else { - if (i == "solidArrow" || i == "dashedArrow") { - G.x = -I.lineWidth / 2 - L.lineWidth * 1.3 - } else { - if (i == "solidDiamond" || i == "dashedDiamond") { - G.x = -I.lineWidth / 2 - L.lineWidth - } else { - G.x = -I.lineWidth / 2 - L.lineWidth / 2 - } - } - } - var K = { - x: 0, - y: 0 - }; - var F = Utils.getRotated(K, G, J); - M.x += F.x; - M.y += F.y - } - } - } - - function e(W, M, Q, Y, R, E) { - if (Y == "normal") { - var S = 12; - var ac = Math.PI / 5; - var V = S / Math.cos(ac); - var L = W.x - V * Math.cos(M - ac); - var K = W.y - V * Math.sin(M - ac); - var O = W.x - V * Math.sin(Math.PI / 2 - M - ac); - var N = W.y - V * Math.cos(Math.PI / 2 - M - ac); - m.beginPath(); - m.moveTo(L, K); - m.lineTo(W.x, W.y); - m.lineTo(O, N); - m.stroke() - } else { - if (Y == "solidArrow") { - var S = 12; - var ac = Math.PI / 10; - var V = S / Math.cos(ac); - var L = W.x - V * Math.cos(M - ac); - var K = W.y - V * Math.sin(M - ac); - var O = W.x - V * Math.sin(Math.PI / 2 - M - ac); - var N = W.y - V * Math.cos(Math.PI / 2 - M - ac); - m.beginPath(); - m.moveTo(W.x, W.y); - m.lineTo(L, K); - m.lineTo(O, N); - m.lineTo(W.x, W.y); - m.closePath(); - m.fill(); - m.stroke() - } else { - if (Y == "dashedArrow") { - m.save(); - var S = 12; - var ac = Math.PI / 10; - var V = S / Math.cos(ac); - var L = W.x - V * Math.cos(M - ac); - var K = W.y - V * Math.sin(M - ac); - var O = W.x - V * Math.sin(Math.PI / 2 - M - ac); - var N = W.y - V * Math.cos(Math.PI / 2 - M - ac); - m.beginPath(); - m.moveTo(W.x, W.y); - m.lineTo(L, K); - m.lineTo(O, N); - m.lineTo(W.x, W.y); - m.closePath(); - m.fillStyle = "white"; - m.fill(); - m.stroke(); - m.restore() - } else { - if (Y == "solidCircle") { - m.save(); - var i = 4; - var J = W.x - i * Math.cos(M); - var I = W.y - i * Math.sin(M); - m.beginPath(); - m.arc(J, I, i, 0, Math.PI * 2, false); - m.closePath(); - m.fill(); - m.stroke(); - m.restore() - } else { - if (Y == "dashedCircle") { - m.save(); - var i = 4; - var J = W.x - i * Math.cos(M); - var I = W.y - i * Math.sin(M); - m.beginPath(); - m.arc(J, I, i, 0, Math.PI * 2, false); - m.closePath(); - m.fillStyle = "white"; - m.fill(); - m.stroke(); - m.restore() - } else { - if (Y == "solidDiamond") { - m.save(); - var S = 8; - var ac = Math.PI / 7; - var V = S / Math.cos(ac); - var L = W.x - V * Math.cos(M - ac); - var K = W.y - V * Math.sin(M - ac); - var O = W.x - V * Math.sin(Math.PI / 2 - M - ac); - var N = W.y - V * Math.cos(Math.PI / 2 - M - ac); - var U = W.x - S * 2 * Math.cos(M); - var T = W.y - S * 2 * Math.sin(M); - m.beginPath(); - m.moveTo(W.x, W.y); - m.lineTo(L, K); - m.lineTo(U, T); - m.lineTo(O, N); - m.lineTo(W.x, W.y); - m.closePath(); - m.fill(); - m.stroke(); - m.restore() - } else { - if (Y == "dashedDiamond") { - m.save(); - var S = 8; - var ac = Math.PI / 7; - var V = S / Math.cos(ac); - var L = W.x - V * Math.cos(M - ac); - var K = W.y - V * Math.sin(M - ac); - var O = W.x - V * Math.sin(Math.PI / 2 - M - ac); - var N = W.y - V * Math.cos(Math.PI / 2 - M - ac); - var U = W.x - S * 2 * Math.cos(M); - var T = W.y - S * 2 * Math.sin(M); - m.beginPath(); - m.moveTo(W.x, W.y); - m.lineTo(L, K); - m.lineTo(U, T); - m.lineTo(O, N); - m.lineTo(W.x, W.y); - m.closePath(); - m.fillStyle = "white"; - m.fill(); - m.stroke(); - m.restore() - } else { - if (Y == "cross") { - var H = 6; - var P = 14; - var ab = H * Math.cos(Math.PI / 2 - M); - var aa = H * Math.sin(Math.PI / 2 - M); - var Z = W.x + ab; - var G = W.y - aa; - var U = W.x - P * Math.cos(M); - var T = W.y - P * Math.sin(M); - var X = U - ab; - var F = T + aa; - m.beginPath(); - m.moveTo(Z, G); - m.lineTo(X, F); - m.stroke() - } - } - } - } - } - } - } - } - } - }, - renderLinkerText: function (pos, l) { - var m = $("#designer-canvas-" + pos).find("#" + l.id); - var q = m.find(".text_canvas"); - if (q.length == 0) { - q = $("
").appendTo(m) - } - var n = l.fontStyle; - var p = "scale(" + VersionDesigner.config.scale[pos] + ")"; - var r = { - "line-height": Math.round(n.size * 1.25) + "px", - "font-size": n.size + "px", - "font-family": n.fontFamily, - "font-weight": n.bold ? "bold" : "normal", - "font-style": n.italic ? "italic" : "normal", - "text-align": n.textAlign, - color: "rgb(" + n.color + ")", - "text-decoration": n.underline ? "underline" : "none", - "-webkit-transform": p, - "-ms-transform": p, - "-o-transform": p, - "-moz-transform": p, - transform: p - }; - q.css(r); - if (l.text == null || l.text == "") { - q.hide(); - return - } - q.show(); - var k = l.text.replace(//g, ">").replace(/\n/g, "
"); - q.html(k + "
"); - var j = this.getLinkerMidpoint(l); - var o = m.position(); - q.css({ - left: j.x.toScale(pos) - o.left - q.width() / 2, - top: j.y.toScale(pos) - o.top - q.height() / 2 - }) - }, - renderMarkers: function (n, r, v) { - if (r.attribute && r.attribute.markers && r.attribute.markers.length > 0) { - var u = r.attribute.markers; - var i = Schema.config.markerSize; - var q = 4; - if (v) { - i = 10 - } - var t = r.attribute.markerOffset; - if (v) { - t = 5 - } - var w = u.length * i + (u.length - 1) * q; - var p = r.props.w / 2 - w / 2; - for (var s = 0; s < u.length; s++) { - var o = u[s]; - n.save(); - n.translate(p, r.props.h - i - t); - var x = Schema.markers[o].call(r, i); - this.renderPath(n, r, x); - n.restore(); - p += i + q - } - } - }, - renderTitleShow: function (pos, i, k) { - if (i.props.titleProps) { - var H = $("").appendTo($("#designer-canvas-" + pos).find("#" + i.id)); - H.css({ - left: (10 + i.props.titleProps.x) * VersionDesigner.config.scale[pos] + 'px', - top: (17 + i.props.titleProps.y) * VersionDesigner.config.scale[pos] + 'px', - }); - var b = H[0].getContext("2d"); - var w = "13px "; - let metrics = b.measureText(i.title) - let width = (metrics.width + 20).toScale(pos) ,height = parseInt(w).toScale(pos) + 10 - H.attr({ - width: width, - height: height - }) - w += i.fontStyle.fontFamily; - b.font = w; - b.fillStyle = "#696969"; - if (i.titleStyle && i.titleStyle.titleColor) { - b.fillStyle = i.titleStyle.titleColor; - } - b.scale(VersionDesigner.config.scale[pos], VersionDesigner.config.scale[pos]); - b.fillText(i.title, 0, 12); - } - }, - renderDataAttributes: function (pos, i, k) { - $("#designer-canvas-" + pos).find("#" + i.id).children(".attr_canvas").remove(); - if (!i.dataAttributes || i.dataAttributes.length == 0) { - return - } - var n = { - x: i.props.w / 2, - y: i.props.h / 2 - }; - for (var p = 0; p < i.dataAttributes.length; p++) { - var j = i.dataAttributes[p]; - if (j.hasOwnProperty("attributesJsonArray")) { - if (!j.dataShowConfig) { - continue - } - var jj = j.dataShowConfig.value; - if (jj && jj.length > 0) { - for (var n = 0; n < jj.length; n++) { - var jjj = jj[n]; - var l = ""; - var o = ""; - if (jjj.showName) { - l = j.name + ": " - } - if (jjj.showType == "text" || jjj.showType == "attr") { - l += jjj.value - } else { - if (jjj.showType == "icon") { - o = jjj.icon - } - } - if (l == "" && o == "") { - continue - } - m(jjj, l, o) - } - } - } - } - - function m(c, y, x) { - var h = c.horizontal; - var I = c.vertical; - var H = $("").appendTo($("#designer-canvas-" + pos).find("#" + i.id)); - var b = H[0].getContext("2d"); - var w = "12px "; - w += i.fontStyle.fontFamily; - b.font = w; - var D = b.measureText(y).width; - var a = 20; - if (x != "") { - D += 20 - } - var E, F; - if (h == "mostleft") { - E = -D - 2 - } else { - if (h == "leftedge") { - E = -D / 2 - } else { - if (h == "left") { - E = 2 - } else { - if (h == "center") { - E = (i.props.w - D) / 2; - } else { - if (h == "right") { - E = i.props.w - D - 2; - if (h == "rightedge") { - E = i.props.w - D / 2 - } else { - E = i.props.w + 2 - } - } - } - } - } - } - if (I == "mosttop") { - F = -a - } else { - if (I == "topedge") { - F = -a / 2 - } else { - if (I == "top") { - F = 0 - } else { - if (I == "middle") { - F = (i.props.h - a) / 2 - } else { - if (I == "bottom") { - F = i.props.h - a - } else { - if (I == "bottomedge") { - F = i.props.h - a / 2 - } else { - F = i.props.h - } - } - } - } - } - } - var g = { - x: E, - y: F, - w: D, - h: a - }; - var G = Utils.getRotatedBox(g, i.props.angle, n); - H.attr({ - width: G.w.toScale(pos), - height: G.h.toScale(pos) - }); - b.font = w; - var d = (G.x + (i.props.x - k.x) + 10).toScale(pos); - var e = (G.y + (i.props.y - k.y) + 10).toScale(pos); - if (h != "mostleft" || h == "left" || h != "right") { - H.css({ - left: d, - top: e - }); - } - b.scale(VersionDesigner.config.scale[pos], VersionDesigner.config.scale[pos]); - b.translate(G.w / 2, G.h / 2); - b.rotate(i.props.angle); - b.translate(-G.w / 2, -G.h / 2); - b.translate((G.w - g.w) / 2, (G.h - g.h) / 2); - b.globalAlpha = i.shapeStyle.alpha; - if (c.type == "link") { - b.fillStyle = "#4183C4" - } else { - b.fillStyle = "#333" - } - if (c.showType == "text") { - b.fillStyle = c.color; - } - if (c.showType == "attr") { - b.fillStyle = c.color; - } - b.textBaseline = "middle"; - if (D > i.props.w) { - var tempShapeWidth = i.props.w; - if (tempShapeWidth < 100) { - tempShapeWidth = 100; - } - H[0].width = tempShapeWidth + 10; - H[0].height = Math.ceil(D / tempShapeWidth) * 10 + 15; - for (var v = 0; v < Math.ceil(D / tempShapeWidth); v++) { - var tempL = (v + 1) * tempShapeWidth; - var tempX = 0; - if (c.showType == "text") { - b.fillStyle = c.color; - } - if (c.showType == "attr") { - b.fillStyle = c.color; - } - var tempY = a / 2 + v * 12; - if (tempL < D) { - b.fillText(y.substring(v * tempShapeWidth / (D / y.length), tempL / (D / y.length)), tempX, tempY); - } else { - b.fillText(y.substring(v * tempShapeWidth / (D / y.length), D / (D / y.length)), tempX, tempY); - } - } - if (h == "mostleft") { - d = -tempShapeWidth + tempShapeWidth * 0.2; - H.css({ - left: d, - top: e - }); - } - if (h == "left") { - H.css({ - left: d, - top: e - 5 - }); - } - if (h == "left" && I != "bottom") { - H.css({ - left: d, - top: e - }); - } - if (h == "right") { - d = tempShapeWidth / 4; - H.css({ - left: d, - top: e - 5 - }); - } - if (I == "mosttop" || I == "bottom") { - e = e - Math.ceil(D / tempShapeWidth) * 5; - H.css({ - left: d, - top: e - }); - } - if (h == "center" && Math.ceil(D / tempShapeWidth) > 1) { - H.css({ - left: 15, - top: e - }); - } - if (h == "right" && I != "mosttop" && I != "bottom") { - d = tempShapeWidth / 4; - H.css({ - left: d, - top: e - }); - } - } else { - if (h == "mostleft") { - d = -D; - H.css({ - left: d, - top: e - }); - } - if (h == "right") { - d = i.props.w - D; - H.css({ - left: d, - top: e - }); - } - b.fillText(y, 0, a / 2); - } - if (x != "") { - if (x.indexOf("&#x") >= 0) { - var icon = x.split("|")[0]; - var iconColor = x.split("|")[1]; - b.font = "19px awsui-iconfont"; - icon = eval("('" + icon.replace('&#x', '\\u').replace(';', '') + "')"); - b.fillStyle = iconColor; - b.fillText(icon, 0, a / 2); - iconCavCode = H[0].toDataURL("image/png"); - c.iconCavCode = iconCavCode; - } else { - var J = "/images/data-attr/" + x + ".png"; - var f = $(".shape_img[src='" + J + "']"); - if (f.length == 0) { - f = $("").appendTo("#shape_img_container") - } - if (f.attr("loaded") == "true") { - b.drawImage(f[0], g.w - 20, 0, 20, 20) - } else { - f.bind("load.drawshape", - function () { - $(this).attr("loaded", "true"); - b.drawImage(f[0], g.w - 20, 0, 20, 20) - }) - } - } - } - b.beginPath(); - b.rect(0, 0, D, a); - b.closePath() - } - }, - // 形状链接 - renderShapeLink: function (o, q) { - o.find(".shape_link_point").remove(); - if (q.link) { - let icon = $(``).appendTo(o) - } - }, - // 形状附件 - renderSahpeAttachment: function (pos, o, q) { - const allData = pos === 'left' ? versionData : curData - let shapeUpFile = allData.shapeUpFile[q.id].value, shapeRelationUpFile = allData.shapeRelationUpFile[q.id].value - o.find(".shape_attachment_point").remove() - if (shapeUpFile.length > 0 || shapeRelationUpFile.length > 0) { - let icon = $(`
`).appendTo(o) - } - }, - drawControls: function (pos, m) { - let Model = PageModel[pos] - var n = $("#shape-controls-" + pos); - if (n.length == 0) { - var r = $("#designer-canvas-" + pos); - n = $(`
`).appendTo(r); - n.append(``); - n.append("
"); - n.append("
"); - n.append("
"); - n.append("
"); - n.append("
"); - n.append("
"); - n.append("
"); - n.append("
"); - $(".shape_controller").css({ - "border-color": VersionDesigner.config.anchorColor, - width: VersionDesigner.config.anchorSize - 2, - height: VersionDesigner.config.anchorSize - 2 - }) - } - $(".shape_controller").css({ - "z-index": Model.orderList.length + 3 - }); - n.show(); - var p = 0; - var i; - var q; - if (m.length == 1) { - var l = Model.getShapeById(m[0]); - i = l.props; - p = l.props.angle; - q = l.resizeDir; - } else { - i = Utils.getControlBox(pos, m); - q = ["tl", "tr", "br", "bl"] - } - var t = true; - let pass = false; - // 查找是否有别的元素 - const index = m.findIndex(item => { - return !(Model.getShapeById(item).hasOwnProperty('e2eContainerId')) - }) - // 查找是否有范围选择框 - const index1 = m.findIndex(item => { - return Model.getShapeById(item).name === 'scopeLimitation' - }) - // 查找是否有范围选择框内元素 - const index2 = m.findIndex(item => { - return Model.getShapeById(item).name !== 'scopeLimitation' && Model.getShapeById(item).hasOwnProperty('e2eContainerId') - }) - if (index == -1 && index1 == -1 && index2 !== -1) { - pass = true - } else if (index2 !== -1) { - const rangeEles = m.filter(item => { - return Model.getShapeById(item).name !== 'scopeLimitation' && Model.getShapeById(item).hasOwnProperty('e2eContainerId') - }) - let range = [] - rangeEles.forEach(item => { - const index = m.findIndex(it => { - return it === Model.getShapeById(item).e2eContainerId - }) - if (index == -1) { - pass = true - } - }) - } - for (var o = 0; o < m.length; o++) { - var s = m[o]; - var l = Model.getShapeById(s); - if (l.attribute && l.attribute.rotatable == false) { - t = false - } - if ((l.resizeDir && l.resizeDir.length == 0) || (l.parent && m.length > 1)) { - q = [] - } - } - if (pass) { - t = false - q = [] - } - this.controlStatus.rotatable = t; - this.controlStatus.resizeDir = q; - this.rotateControls(i, p, pos); - return n - }, - rotateControls: function (R, E, pos) { - var O = $("#shape-controls-" + pos); - var N = Utils.getRotatedBox(R, E); - var i = N.w.toScale(pos); - var Q = N.h.toScale(pos); - O.css({ - left: N.x.toScale(pos), - top: N.y.toScale(pos), - width: i, - height: Q - // "z-index": Model.orderList.length - }); - var P = i + 20; - var K = Q + 20; - var S = $("#controls-bounding-" + pos); - S.attr({ - width: P, - height: K - }); - var J = S[0].getContext("2d"); - J.lineJoin = "round"; - if (this.controlStatus.resizeDir.length == 0) { - J.lineWidth = 2; - J.strokeStyle = VersionDesigner.config.selectorColor; - J.globalAlpha = 0.8 - } else { - J.lineWidth = 1; - J.strokeStyle = VersionDesigner.config.selectorColor; - J.globalAlpha = 0.5 - } - J.save(); - J.clearRect(0, 0, P, K); - J.translate(P / 2, K / 2); - J.rotate(E); - J.translate(-P / 2, -K / 2); - J.translate(9.5, 9.5); - var W = { - x: Math.round((R.x - N.x).toScale(pos)), - y: Math.round((R.y - N.y).toScale(pos)), - w: Math.floor(R.w.toScale(pos) + 1), - h: Math.floor(R.h.toScale(pos) + 1) - }; - J.strokeRect(W.x, W.y, W.w, W.h); - J.restore(); - var A = 0 - VersionDesigner.config.anchorSize / 2; - var G = {}; - R = Utils.toScale(pos, R); - N = Utils.toScale(pos, N); - var D = { - x: (R.x + R.w / 2), - y: R.y + R.h / 2 - }; - O.children(".shape_controller").hide(); - for (var H = 0; H < this.controlStatus.resizeDir.length; H++) { - var L = this.controlStatus.resizeDir[H]; - var X = O.children(".shape_controller[resizeDir=" + L + "]"); - X.show(); - var U, V; - if (L.indexOf("l") >= 0) { - U = R.x - } else { - if (L.indexOf("r") >= 0) { - U = R.x + R.w - } else { - U = R.x + R.w / 2 - } - } - if (L.indexOf("t") >= 0) { - V = R.y - } else { - if (L.indexOf("b") >= 0) { - V = R.y + R.h - } else { - V = R.y + R.h / 2 - } - } - var T = Utils.getRotated(D, { - x: U, - y: V - }, - E); - X.css({ - left: T.x - N.x + A, - top: T.y - N.y + A - }) - } - var M = Math.PI / 8; - O.children(".shape_controller").removeClass("s n e w"); - if (E > M && E <= M * 3) { - O.children("div[resizeDir=tl]").addClass("n"); - O.children("div[resizeDir=tr]").addClass("e"); - O.children("div[resizeDir=br]").addClass("s"); - O.children("div[resizeDir=bl]").addClass("w"); - O.children("div[resizeDir=l]").addClass("n w"); - O.children("div[resizeDir=r]").addClass("s e"); - O.children("div[resizeDir=b]").addClass("s w"); - O.children("div[resizeDir=t]").addClass("n e") - } else { - if (E > M * 3 && E <= M * 5) { - O.children("div[resizeDir=tl]").addClass("n e"); - O.children("div[resizeDir=tr]").addClass("s e"); - O.children("div[resizeDir=br]").addClass("s w"); - O.children("div[resizeDir=bl]").addClass("n w"); - O.children("div[resizeDir=l]").addClass("n"); - O.children("div[resizeDir=r]").addClass("s"); - O.children("div[resizeDir=b]").addClass("w"); - O.children("div[resizeDir=t]").addClass("e") - } else { - if (E > M * 5 && E <= M * 7) { - O.children("div[resizeDir=tl]").addClass("e"); - O.children("div[resizeDir=tr]").addClass("s"); - O.children("div[resizeDir=br]").addClass("w"); - O.children("div[resizeDir=bl]").addClass("n"); - O.children("div[resizeDir=l]").addClass("n e"); - O.children("div[resizeDir=r]").addClass("s w"); - O.children("div[resizeDir=b]").addClass("n w"); - O.children("div[resizeDir=t]").addClass("s e") - } else { - if (E > M * 7 && E <= M * 9) { - O.children("div[resizeDir=tl]").addClass("s e"); - O.children("div[resizeDir=tr]").addClass("s w"); - O.children("div[resizeDir=br]").addClass("n w"); - O.children("div[resizeDir=bl]").addClass("n e"); - O.children("div[resizeDir=l]").addClass("e"); - O.children("div[resizeDir=r]").addClass("w"); - O.children("div[resizeDir=b]").addClass("n"); - O.children("div[resizeDir=t]").addClass("s") - } else { - if (E > M * 9 && E <= M * 11) { - O.children("div[resizeDir=tl]").addClass("s"); - O.children("div[resizeDir=tr]").addClass("w"); - O.children("div[resizeDir=br]").addClass("n"); - O.children("div[resizeDir=bl]").addClass("e"); - O.children("div[resizeDir=l]").addClass("s e"); - O.children("div[resizeDir=r]").addClass("n w"); - O.children("div[resizeDir=b]").addClass("n e"); - O.children("div[resizeDir=t]").addClass("s w") - } else { - if (E > M * 11 && E <= M * 13) { - O.children("div[resizeDir=tl]").addClass("s w"); - O.children("div[resizeDir=tr]").addClass("n w"); - O.children("div[resizeDir=br]").addClass("n e"); - O.children("div[resizeDir=bl]").addClass("s e"); - O.children("div[resizeDir=l]").addClass("s"); - O.children("div[resizeDir=r]").addClass("n"); - O.children("div[resizeDir=b]").addClass("e"); - O.children("div[resizeDir=t]").addClass("w") - } else { - if (E > M * 13 && E <= M * 15) { - O.children("div[resizeDir=tl]").addClass("w"); - O.children("div[resizeDir=tr]").addClass("n"); - O.children("div[resizeDir=br]").addClass("e"); - O.children("div[resizeDir=bl]").addClass("s"); - O.children("div[resizeDir=l]").addClass("s w"); - O.children("div[resizeDir=r]").addClass("n e"); - O.children("div[resizeDir=b]").addClass("s e"); - O.children("div[resizeDir=t]").addClass("n w") - } else { - O.children("div[resizeDir=tl]").addClass("n w"); - O.children("div[resizeDir=tr]").addClass("n e"); - O.children("div[resizeDir=br]").addClass("s e"); - O.children("div[resizeDir=bl]").addClass("s w"); - O.children("div[resizeDir=l]").addClass("w"); - O.children("div[resizeDir=r]").addClass("e"); - O.children("div[resizeDir=b]").addClass("s"); - O.children("div[resizeDir=t]").addClass("n") - } - } - } - } - } - } - } - }, - getLinkerMidpoint: function (z) { - var w = {}; - if (z.linkerType == "normal") { - w = { - x: 0.5 * z.from.x + 0.5 * z.to.x, - y: 0.5 * z.from.y + 0.5 * z.to.y - } - } else { - if (z.linkerType == "curve") { - var d = z.from; - var q = z.points[0]; - var v = z.points[1]; - var x = z.to; - w = { - x: d.x * 0.125 + q.x * 0.375 + v.x * 0.375 + x.x * 0.125, - y: d.y * 0.125 + q.y * 0.375 + v.y * 0.375 + x.y * 0.125 - } - } else { - var u = []; - u.push(z.from); - u = u.concat(z.points); - u.push(z.to); - var r = 0; - for (var A = 1; A < u.length; A++) { - var q = u[A - 1]; - var v = u[A]; - var y = Utils.measureDistance(q, v); - r += y - } - var s = r / 2; - var B = 0; - for (var A = 1; A < u.length; A++) { - var q = u[A - 1]; - var v = u[A]; - var y = Utils.measureDistance(q, v); - var t = B + y; - if (t > s) { - var p = (s - B) / y; - w = { - x: (1 - p) * q.x + p * v.x, - y: (1 - p) * q.y + p * v.y - }; - break - } - B = t - } - } - } - return w - }, - }, - bindEvent: { - designerLayoutScroll: function (pos) { - let dom1 = $("#designer-layout-" + pos) - dom1.bind("scroll", function () { - Navigator.setView(pos); - if (isSameOperate) { - let otherPos = pos === "left" ? "right" : "left"; - let dom2 = $("#designer-layout-" + otherPos); - dom2.scrollTop(dom1.scrollTop()); - dom2.scrollLeft(dom1.scrollLeft()); - } - }); - } - }, - setZoomScale: function (pos, newScale) { - if (newScale < 0.25) { - newScale = 0.25; - } - if (newScale > 4) { - newScale = 4; - } - VersionDesigner.config.scale[pos] = newScale; - VersionDesigner.initialize.initCanvas(pos); - let Model = PageModel[pos] - for (var shapeId in Model.define.elements) { - var shape = Model.define.elements[shapeId]; - VersionDesigner.painter.renderShape(shape, pos); - } - //重新选中 - var selectedIds = Utils.getSelectedIds(pos); - Utils.unselect(pos); - Utils.selectShape(pos, selectedIds); - // 绘制差异节点中的删除 - let diffDelete = diffNode.filter(i => i.type.includes('delete')) - diffDelete.forEach(i => { - let shape = PageModel.left.getShapeById(i.id) - if (shape.name !== 'linker') { - VersionDesigner.painter.renderDiffNode(shape, 'right') - } - }) - } -} -const PageModel = { - left: { - define: { - page: { - "padding": 60, - "backgroundColor": "255,255,255", - "gridSize": 15, - "width": 1600, - "showGrid": true, - "height": 2500 - }, - elements: {} - }, - persistence: {}, - orderList: [], - maxZIndex: 0, - linkerMap: { - map: {}, - add: function (c, d) { - if (!this.map[c]) { - this.map[c] = [] - } - if (this.map[c].indexOf(d) < 0) { - this.map[c].push(d) - } - }, - remove: function (c, d) { - if (this.map[c]) { - Utils.removeFromArray(this.map[c], d) - } - }, - empty: function () { - this.map = {} - } - }, - groupMap: { - map: {}, - add: function (d, c) { - this.map[d] = c - }, - push: function (d, c) { - if (!this.map[d]) { - this.map[d] = [] - } - this.map[d].push(c) - }, - remove: function (b) { - delete this.map[b] - }, - empty: function () { - this.map = {} - } - }, - add: function (d, c) { - this.addMulti([d], c) - }, - addMulti: function (shapes, popMsg) { - if (typeof popMsg == "undefined") { - popMsg = true; - } - var addShapes = []; - for (var i = 0; i < shapes.length; i++) { - var shape = shapes[i]; - if (shape.name != "linker") { - //shape.textBlock = shape.getTextBlock(); - shape.textBlockFinal = shape.getTextBlock(); - } - addShapes.push(Utils.copy(shape)); - this.define.elements[shape.id] = Utils.copy(shape); - // 重新创建,以免互相影响 - this.persistence.elements[shape.id] = Utils.copy(shape); - } - this.build(); - }, - getShapeById: function (b) { - return this.define.elements[b] - }, - getGroupShapes: function (b) { - return this.groupMap.map[b] - }, - build: function () { - this.orderList = []; - this.linkerMap.empty(); - for (var h in this.define.elements) { - var g = this.getShapeById(h); - this.orderList.push({ - id: g.id, - zindex: g.props.zindex - }); - if (g.name == "linker") { - if (g.from.id != null) { - this.linkerMap.add(g.from.id, g.id) - } - if (g.to.id != null) { - this.linkerMap.add(g.to.id, g.id) - } - } - if (g.group) { - this.groupMap.push(g.group, g.id) - } - } - this.orderList.sort(function i(a, b) { - return a.zindex - b.zindex; - }); - for (var j = 0; j < this.orderList.length; j++) { - var h = this.orderList[j].id; - var g = this.getShapeById(h); - if (methodId === 'process.endtoend') { - $("#" + h).css("z-index", g.props.zindex); - } else { - $("#" + h).css("z-index", j); - } - } - var f = 0; - if (this.orderList.length > 0) { - f = this.orderList[this.orderList.length - 1].zindex - } - this.maxZIndex = f - }, - }, - right: {} -} -PageModel.right = deepCopy(PageModel.left) -Number.prototype.toScale = function (pos) { - return this * VersionDesigner.config.scale[pos] -}; -Number.prototype.restoreScale = function (pos) { - return this / VersionDesigner.config.scale[pos] -}; -const Utils = { - selectIds: { - left: [], - right: [] - }, - selectShape: function (pos, s, w) { - let Model = PageModel[pos]; - if (typeof s == "string") { - var o = s; - s = []; - s.push(o) - } - if (s.length <= 0) { - return - } - var r = Utils.mergeArray([], s); - for (var u = 0; u < s.length; u++) { - var p = Model.getShapeById(s[u]); - if (p && p.group) { - var x = Model.getGroupShapes(p.group); - Utils.mergeArray(r, x) - } - } - var z = []; - for (var u = 0; u < r.length; u++) { - var y = r[u]; - var p = Model.getShapeById(y); - if (p && p.parent && p.resizeDir.length == 0 && z.indexOf(p.parent) < 0) { - z.push(p.parent) - } else { - if (z.indexOf(y) < 0) { - z.push(y) - } - } - } - s = z; - Utils.removeAnchors(); - Utils.selectIds[pos] = []; - for (var q = 0; q < s.length; q++) { - var o = s[q]; - var p = Model.getShapeById(o); - Utils.selectIds[pos].push(o); - if (p && p.name == "linker") { - if (this.isLocked(pos, p.id)) { - Utils.showLockers(pos, p) - } else { - VersionDesigner.painter.renderLinker(pos, p) - } - } else { - if (p && this.isLocked(pos, p.id)) { - Utils.showLockers(pos, p) - } - } - } - var z = Utils.getSelectedIds(pos); - var i = false; - if (z.length == 1) { - var t = Model.getShapeById(z[0]); - if (t.name == "linker") { - i = true; - } - } - if (z.length > 0 && !i) { - var v = VersionDesigner.painter.drawControls(pos, z) - } - if (typeof w == "undefined") { - w = true - } - if (this.selectCallback && w) { - this.selectCallback() - } - let pass = true - if (s.length === 1) { - const shape = Model.getShapeById(s[0]); - if (shape.hasOwnProperty('e2eContainerId') && shape.e2eContainerId !== "" && shape.name !== 'scopeLimitation') { - pass = false - } else { - pass = true - } - } else { - const shapes = [] - for (let i = 0; i < s.length; i++) { - shapes.push(Model.getShapeById(s[i])); - } - const index = shapes.findIndex(item => { - return !item.hasOwnProperty('e2eContainerId') || item.name === 'scopeLimitation' - }) - if (index == -1) { - pass = false - } else { - pass = true - } - } - // if (pass) { - // VersionDesigner.events.push("selectChanged"); - // } - }, - selectedOtherShape: function (pos) { - if (isSameOperate) { - let otherPos = pos === 'left' ? 'right' : 'left' - if (Utils.getSelectedIds(pos).length > 0) { - let selectedIds = Utils.getSelectedIds(pos)[0] - let ele = PageModel[otherPos].define.elements - if (ele[selectedIds]) { - Utils.unselect(otherPos); - Utils.selectShape(otherPos, selectedIds) - let layoutDom = $("#designer-layout-" + otherPos) - let layoutWidth = layoutDom.width(), layoutHeight = layoutDom.height(), layoutScrollTop = layoutDom.scrollTop(), layoutScrollLeft = layoutDom.scrollLeft() - let shapeDom = $("#designer-canvas-" + otherPos).find("#" + selectedIds) - let x = parseInt(shapeDom.css('left')), y = parseInt(shapeDom.css('top')), w = parseInt(shapeDom.css('width')), h = parseInt(shapeDom.css('height')) - let text = '' - if (layoutScrollLeft - 10 >= x + w / 2) { - text = 图元位于画布左侧可解除同步锁定查看 - } - if (x - layoutScrollLeft >= layoutWidth - 20 - w / 2) { - text = 图元位于画布右侧可解除同步锁定查看 - } - if (layoutScrollTop - 10 >= y + h / 2) { - text = 图元位于画布顶部可解除同步锁定查看 - } - if (y - layoutScrollTop >= layoutHeight - 20 - h / 2) { - text = 图元位于画布底部可解除同步锁定查看 - } - let tip = $('.shape-tip-' + otherPos) - if (text) { - tip.text(text) - tip.show() - } - } - } else { - Utils.unselect(otherPos) - } - versionCompareFun.updateAttributeView(otherPos) - } - }, - getDarkerColor: function (q, m) { - if (!m) { - m = 13 - } - var n = q.split(","); - var r = parseInt(n[0]); - var o = parseInt(n[1]); - var l = parseInt(n[2]); - var p = Math.round(r - r / 255 * m); - if (p < 0) { - p = 0 - } - var g = Math.round(o - o / 255 * m); - if (g < 0) { - g = 0 - } - var b = Math.round(l - l / 255 * m); - if (b < 0) { - b = 0 - } - return p + "," + g + "," + b - }, - getDarkestColor: function (b) { - return this.getDarkerColor(b, 26) - }, - copy: function (b) { - return $.extend(true, {}, b) - }, - getEndpointAngle: function (m, k) { - var i; - if (k == "from") { - i = m.from - } else { - i = m.to - } - var n; - if (m.linkerType == "normal") { - if (k == "from") { - n = m.to - } else { - n = m.from - } - } else { - if (m.linkerType == "broken") { - if (k == "from") { - n = m.points[0] - } else { - n = m.points[m.points.length - 1] - } - } else { - var l = 12; - var h; - var j = Utils.measureDistance(m.from, m.to); - if (k == "from") { - h = l / j - } else { - h = 1 - l / j - } - n = { - x: (1 - h) * (1 - h) * (1 - h) * m.from.x + 3 * (1 - h) * (1 - h) * h * m.points[0].x + 3 * (1 - h) * h * h * m.points[1].x + h * h * h * m.to.x, - y: (1 - h) * (1 - h) * (1 - h) * m.from.y + 3 * (1 - h) * (1 - h) * h * m.points[0].y + 3 * (1 - h) * h * h * m.points[1].y + h * h * h * m.to.y - } - } - } - return this.getAngle(n, i) - }, - getAngle: function (f, e) { - var d = isNaN(Math.atan(Math.abs(f.y - e.y) / Math.abs(f.x - e.x))) ? 0 : Math.atan(Math.abs(f.y - e.y) / Math.abs(f.x - e.x)); - if (e.x <= f.x && e.y > f.y) { - d = Math.PI - d - } else { - if (e.x < f.x && e.y <= f.y) { - d = Math.PI + d - } else { - if (e.x >= f.x && e.y < f.y) { - d = Math.PI * 2 - d - } - } - } - return d - }, - getLinkerLineStyle: function (pos, a, b) { - let Model = PageModel[pos] - if (b == false || !Model.define.theme || !Model.define.theme.linker) { - return $.extend({}, Schema.linkerDefaults.lineStyle, a) - } else { - return $.extend({}, Schema.linkerDefaults.lineStyle, Model.define.theme.linker.lineStyle, a) - } - }, - getShapeLineStyle: function (pos, a, b) { - let Model = PageModel[pos] - if (b == false || !Model.define.theme || !Model.define.theme.shape) { - return $.extend({}, Schema.shapeDefaults.lineStyle, a) - } else { - return $.extend({}, Schema.shapeDefaults.lineStyle, Model.define.theme.shape.lineStyle, a) - } - }, - getShapeFillStyle: function (pos, a, b) { - let Model = PageModel[pos] - if (b == false || !Model.define.theme || !Model.define.theme.shape) { - return $.extend({}, Schema.shapeDefaults.fillStyle, a) - } else { - return $.extend({}, Schema.shapeDefaults.fillStyle, Model.define.theme.shape.fillStyle, a) - } - }, - getRotated: function (n, h, j) { - var k = this.measureDistance(n, h); - if (k == 0 || j == 0) { - return h - } - var m = Math.atan(Math.abs(h.x - n.x) / Math.abs(n.y - h.y)); - if (h.x >= n.x && h.y >= n.y) { - m = Math.PI - m - } else { - if (h.x <= n.x && h.y >= n.y) { - m = Math.PI + m - } else { - if (h.x <= n.x && h.y <= n.y) { - m = Math.PI * 2 - m - } - } - } - m = m % (Math.PI * 2); - var l = (m + j) % (Math.PI * 2); - var i = { - x: n.x + Math.sin(l) * k, - y: n.y - Math.cos(l) * k - }; - return i - }, - measureDistance: function (g, h) { - var e = h.y - g.y; - var f = h.x - g.x; - return Math.sqrt(Math.pow(e, 2) + Math.pow(f, 2)) - }, - isSelected: function (b, pos) { - if (this.selectIds[pos].indexOf(b) >= 0 && !this.isLocked(pos, b)) { - return true - } - return false - }, - isLocked: function (pos, b) { - let Model = PageModel[pos] - if (Model.getShapeById(b) && Model.getShapeById(b).locked) { - return true - } else { - return false - } - }, - getShapeBox: function (e) { - var d = e.props; - var f = e.props.angle; - return this.getRotatedBox(d, f) - }, - getLinkerLinePoints: function (i) { - var f = []; - if (i.linkerType != "curve") { - f.push(i.from); - f = f.concat(i.points) - } else { - var j = 0.05; - var g = 0; - while (g <= 1) { - var h = { - x: (1 - g) * (1 - g) * (1 - g) * i.from.x + 3 * (1 - g) * (1 - g) * g * i.points[0].x + 3 * (1 - g) * g * g * i.points[1].x + g * g * g * i.to.x, - y: (1 - g) * (1 - g) * (1 - g) * i.from.y + 3 * (1 - g) * (1 - g) * g * i.points[0].y + 3 * (1 - g) * g * g * i.points[1].y + g * g * g * i.to.y - }; - f.push(h); - g += j - } - } - f.push(i.to); - return f - }, - getLinkerBox: function (l) { - var i = this.getLinkerLinePoints(l); - var o = i[0].x; - var p = i[0].y; - var q = i[0].x; - var r = i[0].y; - for (var n = 0; n < i.length; n++) { - var k = i[n]; - if (k.x < o) { - o = k.x - } else { - if (k.x > q) { - q = k.x - } - } - if (k.y < p) { - p = k.y - } else { - if (k.y > r) { - r = k.y - } - } - } - var m = { - x: o, - y: p, - w: q - o, - h: r - p - }; - return m - }, - pointInLinker: function (q, t, s) { - var o = this.getLinkerLinePoints(t); - var v = { - x: q.x - s, - y: q.y - }; - var w = { - x: q.x + s, - y: q.y - }; - var x = { - x: q.x, - y: q.y - s - }; - var m = { - x: q.x, - y: q.y + s - }; - for (var u = 1; u < o.length; u++) { - var n = o[u - 1]; - var p = o[u]; - var r = this.checkCross(v, w, n, p); - if (r) { - return u - } - r = this.checkCross(x, m, n, p); - if (r) { - return u - } - } - return -1 - }, - getRotatedBox: function (p, r, u) { - if (r == 0) { - return p - } else { - if (!u) { - u = { - x: p.x + p.w / 2, - y: p.y + p.h / 2 - } - } - var l = this.getRotated(u, { - x: p.x, - y: p.y - }, - r); - var m = this.getRotated(u, { - x: p.x + p.w, - y: p.y - }, - r); - var n = this.getRotated(u, { - x: p.x + p.w, - y: p.y + p.h - }, - r); - var o = this.getRotated(u, { - x: p.x, - y: p.y + p.h - }, - r); - var q = Math.min(l.x, m.x, n.x, o.x); - var t = Math.max(l.x, m.x, n.x, o.x); - var s = Math.min(l.y, m.y, n.y, o.y); - var v = Math.max(l.y, m.y, n.y, o.y); - return { - x: q, - y: s, - w: t - q, - h: v - s - } - } - }, - newId: function () { - var c = Math.random(); - var d = (c + new Date().getTime()); - return d.toString(16).replace(".", "") - }, - getRelativePos: function (h, e, g) { - var f = g.offset(); - if (f == null) { - f = { - left: 0, - top: 0 - } - } - return { - x: h - f.left + g.scrollLeft(), - y: e - f.top + g.scrollTop() - } - }, - getShapeByPosition: function (pos, V, W, ab) { - let Model = PageModel[pos] - var at = []; - for (var x = Model.orderList.length - 1; x >= 0; x--) { - var S = Model.orderList[x].id; - var i = $("#designer-canvas-" + pos).find("#" + S); - var am = Model.getShapeById(S); - var ak = i.position(); - var ac = V - ak.left; - var ad = W - ak.top; - var R = { - x: ak.left, - y: ak.top, - w: i.width(), - h: i.height() - }; - var y = i.find(".shape_canvas")[0]; - var av = y.getContext("2d"); - var aB = this.pointInRect(V, W, R); - if (am.name == "linker") { - if (!aB) { - continue - } - if (ab) { - continue - } - var U = 10; - U = U.toScale(pos); - var ae = { - x: V - U, - y: W - U, - w: U * 2, - h: U * 2 - }; - if (this.pointInRect(am.to.x.toScale(pos), am.to.y.toScale(pos), ae)) { - var al = { - type: "linker_point", - point: "end", - shape: am - }; - at.push(al); - } else { - if (this.pointInRect(am.from.x.toScale(pos), am.from.y.toScale(pos), ae)) { - var al = { - type: "linker_point", - point: "from", - shape: am - }; - at.push(al); - } else { - var aj = i.find(".text_canvas"); - var ah = aj.position(); - var ae = { - x: ah.left, - y: ah.top, - w: aj.width(), - h: aj.height() - }; - if (this.pointInRect(ac, ad, ae)) { - var al = { - type: "linker_text", - shape: am - }; - at.push(al); - continue - } - U = 7; - U = U.toScale(pos); - var ag = this.pointInLinker({ - x: V.restoreScale(pos), - y: W.restoreScale(pos) - }, - am, U); - if (ag > -1) { - var al = { - type: "linker", - shape: am, - pointIndex: ag - }; - at.push(al); - } - } - } - } else { - if (aB && am.locked && !ab) { - if (av.isPointInPath(ac, ad)) { - var al = { - type: "shape", - shape: am - }; - at.push(al) - } - continue - } - var U = 7; - if (aB) { - U = U.toScale(pos); - var ae = { - x: V - U, - y: W - U, - w: U * 2, - h: U * 2 - }; - var Z = { - x: am.props.x + am.props.w / 2, - y: am.props.y + am.props.h / 2 - }; - var ao = am.getAnchors(); - var al = null; - for (var aw = 0; aw < ao.length; aw++) { - var ay = ao[aw]; - ay = this.getRotated(Z, { - x: am.props.x + ay.x, - y: am.props.y + ay.y - }, - am.props.angle); - if (Utils.pointInRect(ay.x.toScale(pos), ay.y.toScale(pos), ae)) { - var an = Utils.getPointAngle(pos, S, ay.x, ay.y, U); - ay.angle = an; - al = { - type: "bounding", - shape: am, - linkPoint: ay - }; - if (av.isPointInPath(ac, ad)) { - al.inPath = true - } - break - } - } - if (al != null) { - at.push(al); - continue - } - } - if (am.dataAttributes) { - var al = null; - for (var au = 0; au < am.dataAttributes.length; au++) { - var ap = am.dataAttributes[au]; - if (ap.type == "link" && ap.showType && ap.showType != "none") { - var af = i.children("#attr_canvas_" + ap.id); - if (af.length > 0) { - var ai = af.position(); - var X = ac - ai.left; - var Y = ad - ai.top; - var ar = af[0].getContext("2d"); - if (ar.isPointInPath(X, Y)) { - al = { - type: "dataAttribute", - shape: am, - attribute: ap - }; - break - } - } - } - } - if (al != null) { - at.push(al); - continue - } - } - if (!aB) { - continue - } - if (av.isPointInPath(ac, ad)) { - if (ab) { - var ao = am.getAnchors(); - if (ao && ao.length) { - var al = { - type: "shape", - shape: am - }; - at.push(al); - } else { - } - } else { - var al = { - type: "shape", - shape: am - }; - at.push(al); - } - } else { - if (!am.attribute || typeof am.attribute.linkable == "undefined" || am.attribute.linkable) { - var an = Utils.getPointAngle(pos, S, V.restoreScale(pos), W.restoreScale(pos), U); - if (an != null) { - var al = null; - var aC = { - angle: an - }; - for (var aa = 1; aa <= U; aa++) { - if (an == 0) { - aC.x = ac + aa; - aC.y = ad - } else { - if (an < Math.PI / 2) { - aC.x = ac + aa * Math.cos(an); - aC.y = ad + aa * Math.sin(an) - } else { - if (an == Math.PI / 2) { - aC.x = ac; - aC.y = ad + aa - } else { - if (an < Math.PI) { - aC.x = ac - aa * Math.sin(an - Math.PI / 2); - aC.y = ad + aa * Math.cos(an - Math.PI / 2) - } else { - if (an == Math.PI / 2) { - aC.x = ac - aa; - aC.y = ad - } else { - if (an < Math.PI / 2 * 3) { - aC.x = ac - aa * Math.cos(an - Math.PI); - aC.y = ad - aa * Math.sin(an - Math.PI) - } else { - if (an == Math.PI / 2 * 3) { - aC.x = ac; - aC.y = ad - aa - } else { - aC.x = ac + aa * Math.sin(an - Math.PI / 2 * 3); - aC.y = ad - aa * Math.cos(an - Math.PI / 2 * 3) - } - } - } - } - } - } - } - if (av.isPointInPath(aC.x, aC.y)) { - aC.x += ak.left; - aC.y += ak.top; - aC.x = aC.x.restoreScale(pos); - aC.y = aC.y.restoreScale(pos); - al = { - type: "bounding", - shape: am, - linkPoint: aC - }; - break - } - } - if (al != null) { - at.push(al); - } - } - } - } - } - } - var al = null; - if (at.length == 1) { - al = at[0] - } - if (at.length > 1 && ab) { - al = at[0] - } else { - if (at.length > 1) { - var ax = at[0]; - if (ax.type == "bounding" && ax.type != "linker_point" && ax.type != "linker") { - return ax - } - var ag = []; - var aA = []; - var aq = []; - for (var x = 0; x < at.length; x++) { - var T = at[x]; - if (T.type == "bounding") { - aq.push(T) - } else { - if (T.type == "linker") { - ag.push(T) - } else { - if (T.type == "linker_point") { - aA.push(T) - } - } - } - } - if (aq.length > 0 && aA.length > 0) { - for (var x = 0; x < aq.length; x++) { - var T = aq[x]; - if (T.inPath) { - al = T; - break - } - } - } - if (al == null && aA.length > 0) { - aA.sort(function az(a, b) { - if (Utils.isSelected(a.shape.id) && !Utils.isSelected(b.shape.id)) { - return -1 - } else { - if (!Utils.isSelected(a.shape.id) && Utils.isSelected(b.shape.id)) { - return 1 - } else { - return b.shape.props.zindex - a.shape.props.zindex - } - } - }); - al = aA[0] - } - if (al == null && ag.length > 0) { - ag.sort(function az(a, b) { - if (Utils.isSelected(a.shape.id) && !Utils.isSelected(b.shape.id)) { - return -1 - } else { - if (!Utils.isSelected(a.shape.id) && Utils.isSelected(b.shape.id)) { - return 1 - } else { - return b.shape.props.zindex - a.shape.props.zindex - } - } - }); - al = ag[0] - } - if (al == null) { - al = at[0] - } - } - } - return al - }, - getCirclePoints: function (j, k, n) { - var l = Math.PI / 18; - var o = []; - for (var p = 0; p < 36; p++) { - var i = l * p; - var m = { - x: j - Math.cos(i) * n, - y: k - Math.sin(i) * n, - angle: i - }; - o.push(m) - } - return o - }, - getPointAngle: function (pos, r, i, p, F) { - var x = $("#" + r).position(); - var y = Utils.getShapeContext(r); - i = i.toScale(pos) - x.left; - p = p.toScale(pos) - x.top; - var E = this.getCirclePoints(i, p, F); - var u = E.length; - var G = false; - for (var w = 0; w < u; w++) { - var D = E[w]; - if (y.isPointInPath(D.x, D.y)) { - D.inPath = true; - G = true - } else { - D.inPath = false - } - } - if (G == false) { - return null - } - var C = null; - var z = null; - for (var w = 0; w < u; w++) { - var D = E[w]; - if (!D.inPath) { - if (C == null) { - var A = E[(w - 1 + u) % u]; - if (A.inPath) { - C = D.angle - } - } - if (z == null) { - var v = E[(w + 1 + u) % u]; - if (v.inPath) { - z = D.angle - } - } - if (C != null && z != null) { - break - } - } - } - var H = (Math.PI * 2 + z - C) % (Math.PI * 2) / 2; - var B = (C + H) % (Math.PI * 2); - return B - }, - checkCross: function (k, m, n, o) { - var j = false; - var l = (m.x - k.x) * (o.y - n.y) - (m.y - k.y) * (o.x - n.x); - if (l != 0) { - var p = ((k.y - n.y) * (o.x - n.x) - (k.x - n.x) * (o.y - n.y)) / l; - var d = ((k.y - n.y) * (m.x - k.x) - (k.x - n.x) * (m.y - k.y)) / l; - if ((p >= 0) && (p <= 1) && (d >= 0) && (d <= 1)) { - j = true - } - } - return j - }, - pointInRect: function (d, e, f) { - if (d >= f.x && d <= f.x + f.w && e >= f.y && e <= f.y + f.h) { - return true - } - return false - }, - unselect: function (pos) { - let Model = PageModel[pos]; - var h = this.selectIds[pos]; - this.selectIds[pos] = []; - for (var e = 0; e < h.length; e++) { - var g = h[e]; - var f = Model.getShapeById(g); - if (f.name == "linker") { - VersionDesigner.painter.renderLinker(pos, f) - } - } - Utils.removeLockers() - $("#shape-controls-" + pos).hide(); - }, - mergeArray: function (e, f) { - for (var h = 0; h < f.length; h++) { - var g = f[h]; - if (e.indexOf(g) < 0) { - e.push(g) - } - } - return e - }, - removeAnchors: function () { - $(".shape_contour").remove() - }, - getSelectedIds: function (pos) { - var e = []; - for (var d = 0; d < this.selectIds[pos].length; d++) { - var f = this.selectIds[pos][d]; - e.push(f) - } - return e - }, - toScale: function (pos, f) { - var e = {}; - for (var d in f) { - e[d] = f[d]; - if (typeof f[d] == "number") { - e[d] = e[d].toScale(pos) - } - } - return e - }, - getShapeContext: function (c) { - var d = document.getElementById(c) - return d.getElementsByTagName("canvas")[0].getContext("2d") - }, - getControlBox: function (pos, l) { - let Model = PageModel[pos]; - var j = { - x1: null, - y1: null, - x2: null, - y2: null - }; - for (var h = 0; h < l.length; h++) { - var k = l[h]; - var i = Model.getShapeById(k); - var m; - if (i.name == "linker") { - m = this.getLinkerBox(i) - } else { - m = this.getShapeBox(i) - } - if (j.x1 == null || m.x < j.x1) { - j.x1 = m.x - } - if (j.y1 == null || m.y < j.y1) { - j.y1 = m.y - } - if (j.x2 == null || m.x + m.w > j.x2) { - j.x2 = m.x + m.w - } - if (j.y2 == null || m.y + m.h > j.y2) { - j.y2 = m.y + m.h - } - } - var n = { - x: j.x1, - y: j.y1, - w: j.x2 - j.x1, - h: j.y2 - j.y1 - }; - return n - }, - getSelected: function (pos) { - let Model = PageModel[pos]; - var f = []; - for (var e = 0; e < this.selectIds[pos].length; e++) { - var g = this.selectIds[pos][e]; - if (!Utils.isLocked(pos, g)) { - var h = Model.getShapeById(g); - f.push(h) - } - } - return f - }, - showLockers: function (pos, s) { - var m = $("#" + s.id); - var q = m.position(); - - function t() { - var c = $("").appendTo(m); - var a = c[0].getContext("2d"); - a.strokeStyle = "#777"; - a.lineWidth = 1; - var b = 9; - a.beginPath(); - a.moveTo(2, 2); - a.lineTo(b, b); - a.moveTo(2, b); - a.lineTo(b, 2); - a.stroke(); - return c - } - - function r(b) { - var a = t(); - a.css({ - left: b.x.toScale(pos) - q.left - 5, - top: b.y.toScale(pos) - q.top - 5 - }) - } - - if (s.name != "linker") { - var u = s.props; - var v = { - x: u.x + u.w / 2, - y: u.y + u.h / 2 - }; - var l = this.getRotated(v, { - x: u.x, - y: u.y - }, - s.props.angle); - r(l); - var n = this.getRotated(v, { - x: u.x + u.w, - y: u.y - }, - s.props.angle); - r(n); - var o = this.getRotated(v, { - x: u.x + u.w, - y: u.y + u.h - }, - s.props.angle); - r(o); - var p = this.getRotated(v, { - x: u.x, - y: u.y + u.h - }, - s.props.angle); - r(p) - } else { - r(s.from); - r(s.to) - } - }, - removeLockers: function () { - $(".shape_locker").remove() - } -} -const GradientHelper = { - createLinearGradient: function (m, j, k) { - var q = m.props; - var p; - var n; - var o; - if (q.w > q.h) { - p = { - x: 0, - y: q.h / 2 - }; - n = { - x: q.w, - y: q.h / 2 - }; - o = (k.angle + Math.PI / 2) % (Math.PI * 2) - } else { - p = { - x: q.w / 2, - y: 0 - }; - n = { - x: q.w / 2, - y: q.h - }; - o = k.angle - } - if (o != 0) { - var r = { - x: q.w / 2, - y: q.h / 2 - }; - p = Utils.getRotated(r, p, o); - n = Utils.getRotated(r, n, o); - if (p.x < 0) { - p.x = 0 - } - if (p.x > m.props.w) { - p.x = m.props.w - } - if (p.y < 0) { - p.y = 0 - } - if (p.y > m.props.h) { - p.y = m.props.h - } - if (n.x < 0) { - n.x = 0 - } - if (n.x > m.props.w) { - n.x = m.props.w - } - if (n.y < 0) { - n.y = 0 - } - if (n.y > m.props.h) { - n.y = m.props.h - } - } - var l = j.createLinearGradient(p.x, p.y, n.x, n.y); - l.addColorStop(0, "rgb(" + k.beginColor + ")"); - l.addColorStop(1, "rgb(" + k.endColor + ")"); - return l - }, -}; -var Navigator = { - /** - * 初始化 - */ - init: function (pos) { - VersionDesigner.bindEvent.designerLayoutScroll(pos) - // 绑定拖动 - $("#navigation-eye-" + pos).bind("mousedown", function (downE) { - var eye = $(this); - var beginPos = eye.position(); - // 先取消滚动事件 - $("#designer-layout-" + pos).unbind("scroll"); - var layout = $("#designer-layout-" + pos); - var beginTop = layout.scrollTop(); - var beginLeft = layout.scrollLeft(); - // 设计器画布 - var designerCanvas = $("#designer-canvas-" + pos); - var canvasW = designerCanvas.width(); - var canvasH = designerCanvas.height(); - // 鹰眼视图画布 - var canvas = $("#navigation-canvas-" + pos); - var navW = canvas.width(); - var navH = canvas.height(); - // 宽高比例 - var scaleW = canvasW / navW; - var scaleH = canvasH / navH; - $(document).bind("mousemove.navigator", function (moveE) { - var offsetX = moveE.pageX - downE.pageX; - var offsetY = moveE.pageY - downE.pageY; - var newLeft = beginLeft + offsetX * scaleW; - layout.scrollLeft(newLeft); - var newTop = beginTop + offsetY * scaleH; - layout.scrollTop(newTop); - eye.css({ - left: beginPos.left + offsetX, - top: beginPos.top + offsetY - }); - if (isSameOperate) { - let otherPos = pos === "left" ? "right" : "left"; - let otherLayout = $("#designer-layout-" + otherPos); - let otherEye = $("#navigation-eye-" + otherPos); - otherLayout.scrollLeft(newLeft); - otherLayout.scrollTop(newTop); - otherEye.css({ - left: beginPos.left + offsetX, - top: beginPos.top + offsetY - }) - } - }); - $(document).bind("mouseup.navigator", function (moveE) { - $(document).unbind("mousemove.navigator"); - $(document).unbind("mouseup.navigator"); - Navigator.setView(pos); - // 重新绑定 - VersionDesigner.bindEvent.designerLayoutScroll(pos) - }); - }); - $("#navigation-canvas-" + pos).bind("click", function (e) { - var point = Utils.getRelativePos(e.pageX, e.pageY, $(this)); - // 设计器画布 - var designerCanvas = $("#designer-canvas-" + pos); - var canvasW = designerCanvas.width(); - var canvasH = designerCanvas.height(); - // 鹰眼视图画布 - var canvas = $("#navigation-canvas-" + pos); - var navW = canvas.width(); - var navH = canvas.height(); - // 宽高比例 - var scaleW = canvasW / navW; - var scaleH = canvasH / navH; - // 得到点击位置,相对于设计器画布的坐标 - var canvasX = point.x * scaleW; - var canvasY = point.y * scaleH; - // 把点击坐标,置于屏幕中心 - var layout = $("#designer-layout-" + pos); - var margin = VersionDesigner.config.pageMargin; - layout.scrollLeft(canvasX + margin - layout.width() / 2); - layout.scrollTop(canvasY + margin - layout.height() / 2); - }); - this.setView(pos); - }, - /** - * 绘制鹰眼视图 - */ - drawNavigationTimeout: { - left: null, - right: null - }, - draw: function (pos) { - let Model = PageModel[pos]; - if (this.drawNavigationTimeout[pos]) { - window.clearTimeout(this.drawNavigationTimeout[pos]); - } - this.drawNavigationTimeout[pos] = setTimeout(function () { - var canvas = $("#navigation-canvas-" + pos); - var ctx = canvas[0].getContext("2d"); - ctx.save(); - ctx.clearRect(0, 0, canvas.width(), canvas.height()); - ctx.scale(canvas.width() / Model.define.page.width, canvas - .height() - / Model.define.page.height); - // 从最底层开始绘制图形 - for (var i = 0; i < Model.orderList.length; i++) { - var shapeId = Model.orderList[i].id; - var shape = Model.getShapeById(shapeId); - ctx.save(); - if (shape.name != "linker") { - // 对图形执行绘制 - var p = shape.props; - var style = shape.lineStyle; - ctx.translate(p.x, p.y); - ctx.translate(p.w / 2, p.h / 2); - ctx.rotate(p.angle); - ctx.translate(-(p.w / 2), -(p.h / 2)); - ctx.globalAlpha = shape.shapeStyle.alpha; - VersionDesigner.painter.renderShapePath(pos, ctx, shape); - } else { - var linker = shape; - var style = linker.lineStyle; - var points = linker.points; - var from = linker.from; - var to = linker.to; - ctx.beginPath(); - ctx.moveTo(from.x, from.y); - if (linker.linkerType == "curve") { - var cp1 = points[0]; - var cp2 = points[1]; - ctx.bezierCurveTo(cp1.x, cp1.y, cp2.x, cp2.y, - to.x, to.y); - } else { - for (var j = 0; j < points.length; j++) { - // 如果是折线,会有折点 - var linkerPoint = points[j]; - ctx.lineTo(linkerPoint.x, linkerPoint.y); - } - ctx.lineTo(to.x, to.y); - } - ctx.lineWidth = style.lineWidth; - ctx.strokeStyle = "rgb(" + style.lineColor + ")"; - ctx.stroke(); - } - ctx.restore(); - } - ctx.restore(); - Navigator.setView(pos); - this.drawNavigationTimeout = { - left: null, - right: null - }; - }, 100); - }, - /** - * 设置鹰眼视图 - */ - setView: function (pos) { - var navigator = $("#navigation-eye-" + pos); - // 设计器可见视图 - var layout = $("#designer-layout-" + pos); - var viewW = layout.width(); - var viewH = layout.height(); - // 鹰眼视图画布 - var canvas = $("#navigation-canvas-" + pos); - var navW = canvas.width(); - var navH = canvas.height(); - // 设计器画布 - var designerCanvas = $("#designer-canvas-" + pos); - var canvasW = designerCanvas.width(); - var canvasH = designerCanvas.height(); - var margin = VersionDesigner.config.pageMargin; - // 得到设计器画布在可视窗口中的left, top - var visibleLeft = margin - layout.scrollLeft(); - var visibleRight = visibleLeft + canvasW; - if (visibleLeft < 0) { - visibleLeft = 0; - } else if (visibleLeft > viewW) { - visibleLeft = viewW; - } - if (visibleRight > viewW) { - visibleRight = viewW; - } else if (visibleRight < 0) { - visibleRight = 0; - } - var visibleTop = margin - layout.scrollTop(); - var visibleBottom = visibleTop + canvasH; - if (visibleTop < 0) { - visibleTop = 0; - } else if (visibleTop > viewH) { - visibleTop = viewH; - } - if (visibleBottom > viewH) { - visibleBottom = viewH; - } else if (visibleBottom < 0) { - visibleBottom = 0; - } - var visibleW = visibleRight - visibleLeft; - var visibleH = visibleBottom - visibleTop; - if (visibleW == 0 || visibleH == 0) { - // 画布已经不可见 - navigator.hide(); - } else { - // 换算成鹰眼视图中的left, top - var navLeft = layout.scrollLeft() - margin; - if (navLeft < 0) { - navLeft = 0; - } - navLeft = navLeft * (navW / canvasW); - var navTop = layout.scrollTop() - margin; - if (navTop < 0) { - navTop = 0; - } - navTop = navTop * (navH / canvasH); - var navViewW = visibleW * (navW / canvasW); - var navViewH = visibleH * (navH / canvasH); - navigator.css({ - left: navLeft - 1, - top: navTop - 1, - width: navViewW, - height: navViewH - }).show(); - } - } -}; -$(function () { - VersionDesigner.init('left') - VersionDesigner.init('right') - Navigator.init('left'); - Navigator.init('right'); -}) -Schema.initShapeFunctions = function (shape) { - var pathEval = "shape.getPath = function(pos){var color = [255,255,255];var fillStyle = Utils.getShapeFillStyle(pos,this.fillStyle, false);if(fillStyle.color && fillStyle.color.length > 0){color = fillStyle.color.split(',');}var r = color[0]; var g = color[1]; var b = color[2]; var a = color[3] || 1,radial = 'radial',linear = 'linear';var w = this.props.w; var height = this.props.height; var h = this.props.h;var lineStyle = Utils.getShapeLineStyle(pos,this.lineStyle, false); var lineWidth = lineStyle.lineWidth; "; - pathEval += SchemaHelper.constructPathFunBody(shape.path) + "}"; - eval(pathEval); - var block = shape.textBlock; - var textEval = "shape.getTextBlock = function(){var w = this.props.w; var h = this.props.h; var height = this.props.height; return {x:"; - textEval += block.x + ",y:" + block.y + ",w:" + block.w + ",h:" + block.h + "}}"; - eval(textEval); - var anchorsEval = "shape.getAnchors = function(){var w = this.props.w; var h = this.props.h; return ["; - for (var i = 0; i < shape.anchors.length; i++) { - var anchor = shape.anchors[i]; - anchorsEval += "{x:" + anchor.x + ", y:" + anchor.y + "}"; - if (i < shape.anchors.length - 1) { - anchorsEval += "," - } - } - anchorsEval += "];}"; - eval(anchorsEval) -} -Schema.init(true); -Schema.initMarkers(); - -function deepCopy(obj) { - if (typeof obj !== 'object' || obj === null) { - return obj; - } - let newObj = Array.isArray(obj) ? [] : {} - for (let key in obj) { - if (obj.hasOwnProperty(key)) { - newObj[key] = deepCopy(obj[key]); - } - } - return newObj; -} \ No newline at end of file diff --git a/com.actionsoft.apps.coe.pal/web/com.actionsoft.apps.coe.pal/lib/designer/scripts/versionCompare/version.core.js b/com.actionsoft.apps.coe.pal/web/com.actionsoft.apps.coe.pal/lib/designer/scripts/versionCompare/version.core.js deleted file mode 100644 index ecc5e418..00000000 --- a/com.actionsoft.apps.coe.pal/web/com.actionsoft.apps.coe.pal/lib/designer/scripts/versionCompare/version.core.js +++ /dev/null @@ -1 +0,0 @@ -const VersionDesigner={config:{panelItemWidth:30,panelItemHeight:30,pageMargin:10,anchorSize:8,rotaterSize:9,anchorColor:"#833",selectorColor:"#833",scale:{left:1,right:1}},init(e){this.initialize.initModel(e),this.initialize.initCanvas(e),this.initialize.initPageShapes(e),this.initialize.initEvent(e)},initialize:{initModel:function(e){let t=pageDefinition[e],i=PageModel[e];null!=t&&null!=t.localAttribute?i.define.localAttribute=t.localAttribute:i.define.localAttribute={},null!=t&&null!=t.commonShapeConfig?i.define.commonShapeConfig=t.commonShapeConfig:i.define.commonShapeConfig={},i.shapeTemplateObj={},i.persistence={page:Utils.copy(i.define.page),elements:{},localAttribute:{},commonShapeConfig:{}}},initCanvas:function(e){let t=PageModel[e];var i=t.define.page.width.toScale(e),a=t.define.page.height.toScale(e),n=t.define.page.backgroundColor,r=Utils.getDarkerColor(n),s=Utils.getDarkestColor(n);$("#designer-canvas-"+e).css({"background-color":"rgb("+r+")"});var o=$("#designer-grids-"+e);o.attr({width:i,height:a});var l=o[0].getContext("2d");l.clearRect(0,0,i,a);var h=t.define.page.padding.toScale(e),d=i-2*h,p=a-2*h;l.fillStyle="rgb("+n+")",l.beginPath(),l.rect(h,h,d,p),l.fill();var c=Math.round(t.define.page.gridSize.toScale(e));if(c<10&&(c=10),t.define.page.showGrid){l.translate(h,h),l.lineWidth=1,l.save();for(var f=.5,g=0;f<=p;)l.restore(),l.strokeStyle=g%4==0?"rgb("+s+")":"rgb("+r+")",l.beginPath(),l.moveTo(0,f),l.lineTo(d,f),f+=c,g++,l.stroke();for(f=.5,g=0;f<=d;)l.restore(),l.strokeStyle=g%4==0?"rgb("+s+")":"rgb("+r+")",l.beginPath(),l.moveTo(f,0),l.lineTo(f,p),f+=c,g++,l.stroke()}$("#canvas-container-"+e).css({width:i,height:a,padding:VersionDesigner.config.pageMargin})},initPageShapes:function(e){var t=pageDefinition[e].elements;let i=PageModel[e];var a=0;for(var n in t){"linker"!=(r=t[n]).name&&(Schema.initShapeFunctions(r),VersionDesigner.painter.renderShape(r,e),i.add(r,!1)),a++}for(var n in t){var r;"linker"==(r=t[n]).name&&(VersionDesigner.painter.renderLinker(e,r),i.add(r,!1))}0==a&&i.build(),diffNode.filter(e=>e.type.includes("delete")).forEach(e=>{let t=PageModel.left.getShapeById(e.id);"linker"!==t.name&&VersionDesigner.painter.renderDiffNode(t,"right")})},initEvent:function(e){$("#designer-canvas-"+e).off("mousedown").on("mousedown",function(t){var i=$("#designer-canvas-"+e),a=Utils.getRelativePos(t.pageX,t.pageY,i),n=Utils.getShapeByPosition(e,a.x,a.y);null!=n?"dataAttribute"==n.type||(Utils.unselect(e),Utils.selectShape(e,n.shape.id)):Utils.unselect(e),versionCompareFun.updateAttributeView(e),$(".shape-tip").hide(),Utils.selectedOtherShape(e)}),document.addEventListener("wheel",function(e){if(e.ctrlKey&&$(e.target).closest(".version-designer-layout").length>0){e.preventDefault();let t=e.deltaY<0,i=$(e.target).closest(".version-designer-layout").attr("position");versionCompareFun.pageZoom(i,t?"zoomIn":"zoomOut")}},{passive:!1})}},painter:{controlStatus:{resizeDir:[],rotatable:!0},actions:{move:function(e){this.moveTo(e.x,e.y),this.prePoint=e,null==this.beginPoint&&(this.beginPoint=e)},line:function(e){if(void 0!==this.webkitLineDash&&void 0===this.lineDashOffset&&0!=this.lineWidth){for(var t=this.webkitLineDash,i=this.prePoint,a=0,n=1/Utils.measureDistance(i,e),r=i,s=0,o=!0;a<1;){(a+=n)>1&&(a=1);var l={x:(1-a)*i.x+a*e.x,y:(1-a)*i.y+a*e.y};(Utils.measureDistance(r,l)>=t[s]||a>=1)&&(o?this.lineTo(l.x,l.y):this.moveTo(l.x,l.y),o=!o,r=l,++s>=t.length&&(s=0))}this.moveTo(e.x,e.y)}else this.lineTo(e.x,e.y);this.prePoint=e,null==this.beginPoint&&(this.beginPoint=e)},curve:function(e){if(void 0!==this.webkitLineDash&&void 0===this.lineDashOffset&&0!=this.lineWidth){for(var t=this.webkitLineDash,i=this.prePoint,a=0,n=1/Utils.measureDistance(i,e),r=i,s=0,o=!0,l=0;a<1;){(a+=n)>1&&(a=1);var h={x:i.x*Math.pow(1-a,3)+e.x1*a*Math.pow(1-a,2)*3+e.x2*Math.pow(a,2)*(1-a)*3+e.x*Math.pow(a,3),y:i.y*Math.pow(1-a,3)+e.y1*a*Math.pow(1-a,2)*3+e.y2*Math.pow(a,2)*(1-a)*3+e.y*Math.pow(a,3)};if(Utils.measureDistance(r,h)>=t[s]||a>=1){if(o){var d=l+(a-l)/2,p={x:i.x*Math.pow(1-d,3)+e.x1*d*Math.pow(1-d,2)*3+e.x2*Math.pow(d,2)*(1-d)*3+e.x*Math.pow(d,3),y:i.y*Math.pow(1-d,3)+e.y1*d*Math.pow(1-d,2)*3+e.y2*Math.pow(d,2)*(1-d)*3+e.y*Math.pow(d,3)};this.lineTo(p.x,p.y),this.lineTo(h.x,h.y)}else this.moveTo(h.x,h.y);o=!o,r=h,l=a,++s>=t.length&&(s=0)}}this.moveTo(e.x,e.y)}else this.bezierCurveTo(e.x1,e.y1,e.x2,e.y2,e.x,e.y);this.prePoint=e,null==this.beginPoint&&(this.beginPoint=e)},quadraticCurve:function(e){if(void 0!==this.webkitLineDash&&void 0===this.lineDashOffset&&0!=this.lineWidth){for(var t=this.webkitLineDash,i=this.prePoint,a=0,n=1/Utils.measureDistance(i,e),r=i,s=0,o=!0,l=0;a<1;){(a+=n)>1&&(a=1);var h={x:i.x*Math.pow(1-a,2)+e.x1*a*(1-a)*2+e.x*Math.pow(a,2),y:i.y*Math.pow(1-a,2)+e.y1*a*(1-a)*2+e.y*Math.pow(a,2)};if(Utils.measureDistance(r,h)>=t[s]||a>=1){if(o){var d=l+(a-l)/2,p={x:i.x*Math.pow(1-d,2)+e.x1*d*(1-d)*2+e.x*Math.pow(d,2),y:i.y*Math.pow(1-d,2)+e.y1*d*(1-d)*2+e.y*Math.pow(d,2)};this.lineTo(p.x,p.y),this.lineTo(h.x,h.y)}else this.moveTo(h.x,h.y);o=!o,r=h,l=a,++s>=t.length&&(s=0)}}this.moveTo(e.x,e.y)}else this.quadraticCurveTo(e.x1,e.y1,e.x,e.y);this.prePoint=e,null==this.beginPoint&&(this.beginPoint=e)},close:function(){if(void 0!==this.webkitLineDash&&void 0===this.lineDashOffset&&0!=this.lineWidth)for(var e=this.webkitLineDash,t=this.prePoint,i=this.beginPoint,a=0,n=1/Utils.measureDistance(t,i),r=t,s=0,o=!0;a<1;){(a+=n)>1&&(a=1);var l={x:(1-a)*t.x+a*i.x,y:(1-a)*t.y+a*i.y};(Utils.measureDistance(r,l)>=e[s]||a>=1)&&(o?this.lineTo(l.x,l.y):this.moveTo(l.x,l.y),o=!o,r=l,++s>=e.length&&(s=0))}this.closePath()},curveArc:function(e){this.arc(e.centerX,e.centerY,e.radius,e.startAngle,e.endAngle,!0)}},setLineDash:function(e,t){e.setLineDash||(e.setLineDash=function(){}),e.setLineDash(t),e.mozDash=t,e.webkitLineDash=t},renderShapePath:function(e,t,i,a){var n;n=a&&i.drawIcon?i.drawIcon(i.props.w,i.props.h):i.getPath(e),this.renderPath(t,i,n,a)},renderPath:function(e,t,i,a){for(var n=0;n=0;n--){(a=t.dataAttributes[n]).horizontal,a.vertical;if(a.hasOwnProperty("attributesJsonArray")){var r=a.dataShowConfig;null!=r&&(r.value=[]);break}}var s=t.name;for(n=0;n0)for(var v=0;v=0&&(p+"").trim().length>0&&(p="("+o.attrName+")"+p),"relation"==g){var u=t.id+"_"+f,x=relationShapeModelObject,m="";x.hasOwnProperty(u)&&(m=x[u]),p=m,o.isShowAttrName&&(p="("+o.attrName+")"+p)}c.showType="attr",c.value=p,c.color=o.color}t.dataAttributes||(t.dataAttributes=[]),c.id=Utils.newId(),c.category="custom",a.dataShowConfig||(a.dataShowConfig={},a.dataShowConfig.value||(a.dataShowConfig.value=[])),a.dataShowConfig.value.push(c)}else{c={w:16,h:16,textw:20,texth:17,imgT:0,category:"custom",icon:o.iconContent,name:s,showName:!1,showType:"icon",type:"string",value:"",horizontal:h,vertical:d};t.dataAttributes||(t.dataAttributes=[]),c.id=Utils.newId(),c.category="custom",a.dataShowConfig||(a.dataShowConfig={},a.dataShowConfig.value||(a.dataShowConfig.value=[])),a.dataShowConfig.value.push(c)}}},renderShape:function(e,t){if("linker"==e.name)return void this.renderLinker(t,e);let i=PageModel[t];for(var a,n,r=Utils.copy(i.define.commonShapeConfig),s=e.dataAttributes,o=0;o0)for(o=0;o=0||d.push(r[o])}p=d.length>0?a.concat(d):a,this.handleShapeConfigData(p,e,n)}var v=$("#designer-canvas-"+t),y=v.find("#"+e.id);0==y.length&&(y="lane"==e.category?$("
").appendTo(v):$("
").appendTo(v));var u=Utils.getShapeBox(e),x=(u.w+20).toScale(t),m=(u.h+20).toScale(t);y.find(".shape_canvas").attr({width:x,height:m}),y.css({left:(u.x-10).toScale(t)+"px",top:(u.y-10).toScale(t)+"px",width:x,height:m});var w=y.find(".shape_canvas")[0].getContext("2d");w.clearRect(0,0,e.props.w+20,e.props.h+20),w.scale(VersionDesigner.config.scale[t],VersionDesigner.config.scale[t]),w.translate(10,10),w.translate(e.props.x-u.x,e.props.y-u.y),w.translate(e.props.w/2,e.props.h/2),w.rotate(e.props.angle),w.translate(-e.props.w/2,-e.props.h/2),e.highLight&&(w.shadowBlur=9,w.shadowColor="rgba(0, 0, 0, 0.5)");e.lineStyle;w.globalAlpha=e.shapeStyle.alpha,w.lineJoin="round",this.renderShapePath(t,w,e),this.renderMarkers(w,e);var S=e.getPath(t),b=Utils.copy(S[S.length-1]);b.fillStyle={type:"none"},b.lineStyle={lineWidth:0};var D=[b];if(this.renderPath(w,e,D),this.renderText(t,e,u),this.renderDataAttributes(t,e,u),this.renderTitleShow(t,e,u),!isProcessExec&&(VersionDesigner.painter.renderShapeLink(y,e),VersionDesigner.painter.renderSahpeAttachment(t,y,e),null!=n&&n.length>0)){y.find(".shape_danger").remove(),y.find(".shape_regulate").remove();var M=!1,I=!1;for(var k in n){var C=n[k];if(null!=C&&"danger"==C.key&&null!=C.value&&""!=C.value&&null!=relationShapeInfo[t])if("object"==typeof C.value&&C.value.constructor==Array){for(S=0;S
").appendTo(y);if(I)$("
").appendTo(y)}this.renderDiffNode(e,t)},renderDiffNode:function(e,t){if("right"===t){let i=diffNode.findIndex(t=>t.id===e.id);if(-1!==i){const a=$("#designer-canvas-"+t),n={add:{code:"",color:"#E02020",qtip:新增图元},delete:{code:"",color:"#E02020",qtip:删除图元},position:{code:"",color:"#FF8F0B",qtip:图元位置变化},info:{code:"",color:"#FF8F0B",qtip:图元信息变化},style:{code:"",color:"#FF8F0B",qtip:图元名称样式变化}};let r=diffNode[i].type,s="";r.forEach(e=>{s+=`\n\t\t\t\t\t\t\t\t\t\t${n[e].code}\n\t\t\t\t\t\t\t\t\t`});let o,l,h,d,p,c,f=a.find("#diff-node-"+e.id);if(0===f.length&&(f=$(`
`).appendTo(a)),r.includes("delete")){let t=$("#designer-canvas-left").find("#"+e.id);o=parseInt(t.css("width")).restoreScale("left").toScale("right"),l=parseInt(t.css("height")).restoreScale("left").toScale("right"),h=parseInt(t.css("left")).restoreScale("left").toScale("right"),d=parseInt(t.css("top")).restoreScale("left").toScale("right"),p="rgba(224, 32, 32, 0.15)",c="#E02020"}else{let t=a.find("#"+e.id);o=parseInt(t.css("width")),l=parseInt(t.css("height")),h=parseInt(t.css("left")),d=parseInt(t.css("top")),p=r.includes("add")?"rgba(224, 32, 32, 0.15)":"rgba(255, 143, 11, 0.15)",c=r.includes("add")?"#E02020":"#FF8F0B"}if(f.css({boxSizing:"border-box",left:h+"px",top:d+"px",width:o+"px",height:l+"px",background:p,border:`1.2px dashed ${c}`}),0===f.find(".diff-icon-wrapper").length){let i=$(`
${s}
`).appendTo(f);i.children("span[type=info]").off("mousedown").on("mousedown",function(e){e.stopPropagation()}),i.children("span[type=info]").off("click").on("click",function(i){i.stopPropagation(),Utils.unselect(t),Utils.selectShape(t,e.id),versionCompareFun.openAttributeView(t),Utils.selectedOtherShape(t)})}}}},iconImage:function(e,t,i){if(i){t.save();var a,n=imageDefMap[i.imageId],r=e.props.h;"colorOverlay"===i.type&&(r=30),a=.65*r;var s=$(".shape_img[src='"+n+"']");0===s.length?(s=$("").appendTo("#shape_img_container")).one("load.drawshape",function(){t.translate(0,0),o(s,r,a),s.attr("loaded","1")}):"0"===s.attr("loaded")?s.one("load.drawshape",function(){t.translate(0,0),o(s,r,a)}):o(s,r,a)}function o(e,i,a){var n,r;t.save();var s=e[0].width/e[0].height;s>1?n=(r=a)*s:r=(n=a)*s;var o=i/2,l=o-r/2,h=o-n/2;t.drawImage(e[0],l,h,r,n),t.restore()}},fillShape:function(e,t,i){if(t.save(),void 0!==i.colorOverlay&&"multiplyOverlay"===i.colorOverlay&&(i.color=function(e){let[t,i,a]=e.split(",").map(Number),[n,r,s]=e.split(",").map(Number),o=t/255*(n/255)*255,l=i/255*(r/255)*255,h=a/255*(s/255)*255;return`${Math.round(o)}, ${Math.round(l)}, ${Math.round(h)}`}(i.color)),"solid"==i.type)t.fillStyle="rgb("+i.color+")",t.fill();else if("gradient"==i.type){var a;a="linear"==i.gradientType?GradientHelper.createLinearGradient(e,t,i):GradientHelper.createRadialGradient(e,t,i),t.fillStyle=a,t.fill()}else if("image"===i.type||"imageDef"===i.type){let a=!1,s=i.fileId;"insert"===i.from&&(s=shapeImages[i.fileId]),"imageDef"===i.type&&(imageDefMap[i.fileId]?s=imageDefMap[i.fileId]:(s=shapeImages[i.fileId],a=!0));var n=$(".shape_img[src='"+s+"']");0==n.length?((n=$("").appendTo("#shape_img_container")).bind("load.drawshape",function(){var s="insert"===i.from?0:(VersionDesigner.config.panelItemWidth-e.props.w)/2,o="insert"===i.from?0:(VersionDesigner.config.panelItemHeight-e.props.h)/2;a&&(o=0,s=0),t.translate(s,o),r(n),t.restore(),$(this).attr("loaded","1")}),n.attr("src",s)):"0"==n.attr("loaded")?n.bind("load.drawshape",function(){t.translate(0,0),r(n),t.restore()}):r(n)}function r(a){if(t.save(),t.clip(),"fit"==i.display)if((c=(l=a.width())/(h=a.height()))>e.props.w/e.props.h){var n=0,r=(o=e.props.w)/c,s=e.props.h/2-r/2;t.drawImage(a[0],n,s,o,r)}else{s=0;var o=(r=e.props.h)*c;n=e.props.w/2-o/2;t.drawImage(a[0],n,s,o,r)}else if("stretch"==i.display)t.drawImage(a[0],0,0,e.props.w,e.props.h);else if("original"==i.display){var l=a.width(),h=a.height();n=e.props.w/2-l/2,s=e.props.h/2-h/2;t.drawImage(a[0],n,s,l,h)}else if("tile"==i.display)for(n=0,l=a.width(),h=a.height();ne.props.w/e.props.h){s=0,o=(r=e.props.h)*c,n=e.props.w/2-o/2;t.drawImage(a[0],n,s,o,r)}else{n=0,r=(o=e.props.w)/c,s=e.props.h/2-r/2;t.drawImage(a[0],n,s,o,r)}}t.restore()}t.restore()},renderText:function(e,t,i){var a=$("#designer-canvas-"+e).find("#"+t.id),n=a.find(".text_canvas[forshape="+t.id+"]");if(0==n.length&&(n=$("").appendTo(a)).bind("focus",function(){$(this).blur()}),n.attr("readonly","readonly"),null==t.text||""==t.text.trim()||0==t.attribute.editable&&t.title==t.text)n.css({height:"0px",width:"0px"}).hide();else{var r=t.fontStyle,s={"line-height":Math.round(1.25*r.size)+"px","font-size":r.size+"px","font-family":r.fontFamily,"font-weight":r.bold?"bold":"normal","font-style":r.italic?"italic":"normal","text-align":r.textAlign,color:"rgb("+r.color+")","text-decoration":r.underline?"underline":"none",opacity:t.shapeStyle.alpha};n.css(s),n.show();var o=t.getTextBlock();if("horizontal"==t.fontStyle.orientation){var l={x:o.x+o.w/2,y:o.y+o.h/2};o={x:l.x-o.h/2,y:l.y-o.w/2,w:o.h,h:o.w}}n.css({width:o.w}),n.height(0),n.val(t.text),n.scrollTop(99999);var h=n.scrollTop(),d=0;d="middle"==r.vAlign?o.y+o.h/2-h/2:"bottom"==t.fontStyle.vAlign?o.y+o.h-h:o.y;var p={x:o.x+o.w/2,y:d+h/2},c=t.props.angle;if(0!=c){var f={x:t.props.w/2,y:t.props.h/2};p=Utils.getRotated(f,p,c)}"horizontal"==r.orientation&&(c=(1.5*Math.PI+c)%(2*Math.PI));var g="rotate("+Math.round(c/(2*Math.PI)*360)+"deg) scale("+VersionDesigner.config.scale[e]+")",v=o.w,y=h;n.css({width:v,height:y,left:(p.x+(t.props.x-i.x)+10).toScale(e)-o.w/2,top:(p.y+(t.props.y-i.y)+10).toScale(e)-h/2,"-webkit-transform":g,"-ms-transform":g,"-o-transform":g,"-moz-transform":g,transform:g})}},renderLinker:function(e,t){let i=PageModel[e];"curve"!=t.linkerType&&"broken"!=t.linkerType||t.points&&0!=t.points.length||(t.points=Utils.getLinkerPoints(t));var a=t.points,n=Utils.copy(t.from),r=Utils.copy(t.to);if(t.attribute&&t.attribute.collapseBy)$("#designer-canvas-"+e).find("#"+t.id).hide();else{$("#designer-canvas-"+e).find("#"+t.id).show();var s=Utils.getEndpointAngle(t,"from"),o=Utils.getEndpointAngle(t,"to"),l=Utils.getLinkerLineStyle(e,t.lineStyle);T(e,n,t,l.beginArrowStyle,s),T(e,r,t,l.endArrowStyle,o);var h=r.x,d=r.y,p=n.x,c=n.y;r.xp&&(p=g.x),g.yc&&(c=g.y)}var v=h,y=d,u=p-h,x=c-d,m=$("#designer-canvas-"+e).find("#"+t.id);if(0==m.length){var w=$("#designer-canvas-"+e);m=$("
").appendTo(w)}i.getShapeById(t.id)||(m.css("z-index",i.orderList.length+1),m.css({"pointer-events":"none"}));var S=m.find(".shape_canvas");S.attr({width:(u+20).toScale(e),height:(x+20).toScale(e)}),m.css({left:(v-10).toScale(e),top:(y-10).toScale(e),width:(u+20).toScale(e),height:(x+20).toScale(e)});var b=S[0].getContext("2d");b.scale(VersionDesigner.config.scale[e],VersionDesigner.config.scale[e]),b.translate(10,10);var D=Utils.getLinkerLineStyle(e,t.lineStyle);b.lineWidth=D.lineWidth,b.strokeStyle="rgb("+D.lineColor+")",b.fillStyle="rgb("+D.lineColor+")",t.highLight&&(b.shadowBlur=15,b.shadowColor="rgba(0, 0, 0, 0.5)"),b.save();var M={x:n.x-v,y:n.y-y},I={x:r.x-v,y:r.y-y};if(b.save(),"dashed"==D.lineStyle?this.setLineDash(b,[5*D.lineWidth,2*D.lineWidth]):"dot"==D.lineStyle?this.setLineDash(b,[D.lineWidth,1.5*D.lineWidth]):"dashdot"==D.lineStyle&&this.setLineDash(b,[5*D.lineWidth,2*D.lineWidth,D.lineWidth,2*D.lineWidth]),b.lineJoin="round",b.beginPath(),this.actions.move.call(b,M),"curve"==t.linkerType){var k=a[0],C=a[1],P={x1:k.x-v,y1:k.y-y,x2:C.x-v,y2:C.y-y,x:I.x,y:I.y};this.actions.curve.call(b,P)}else{for(f=0;fe.id===t.id)&&(b.shadowBlur=4,b.shadowColor="#833")}b.stroke(),b.restore(),delete b.webkitLineDash,L(M,s,n.id,D.beginArrowStyle,t,n.angle),L(I,o,r.id,D.endArrowStyle,t,r.angle),b.restore(),this.renderLinkerText(e,t)}function T(e,t,i,a,n){let r=PageModel[e];if(t.id){var s=r.getShapeById(t.id);if(s){var o={x:0,y:0},l=Utils.getShapeLineStyle(e,s.lineStyle),h=Utils.getLinkerLineStyle(e,i.lineStyle);o.x="none"==a||"cross"==a?-l.lineWidth/2:"solidArrow"==a||"dashedArrow"==a?-l.lineWidth/2-1.3*h.lineWidth:"solidDiamond"==a||"dashedDiamond"==a?-l.lineWidth/2-h.lineWidth:-l.lineWidth/2-h.lineWidth/2;var d=Utils.getRotated({x:0,y:0},o,n);t.x+=d.x,t.y+=d.y}}}function L(e,t,i,a,n,r){if("normal"==a){var s=12,o=Math.PI/5,l=s/Math.cos(o),h=e.x-l*Math.cos(t-o),d=e.y-l*Math.sin(t-o),p=e.x-l*Math.sin(Math.PI/2-t-o),c=e.y-l*Math.cos(Math.PI/2-t-o);b.beginPath(),b.moveTo(h,d),b.lineTo(e.x,e.y),b.lineTo(p,c),b.stroke()}else if("solidArrow"==a){s=12,o=Math.PI/10,l=s/Math.cos(o),h=e.x-l*Math.cos(t-o),d=e.y-l*Math.sin(t-o),p=e.x-l*Math.sin(Math.PI/2-t-o),c=e.y-l*Math.cos(Math.PI/2-t-o);b.beginPath(),b.moveTo(e.x,e.y),b.lineTo(h,d),b.lineTo(p,c),b.lineTo(e.x,e.y),b.closePath(),b.fill(),b.stroke()}else if("dashedArrow"==a){b.save();s=12,o=Math.PI/10,l=s/Math.cos(o),h=e.x-l*Math.cos(t-o),d=e.y-l*Math.sin(t-o),p=e.x-l*Math.sin(Math.PI/2-t-o),c=e.y-l*Math.cos(Math.PI/2-t-o);b.beginPath(),b.moveTo(e.x,e.y),b.lineTo(h,d),b.lineTo(p,c),b.lineTo(e.x,e.y),b.closePath(),b.fillStyle="white",b.fill(),b.stroke(),b.restore()}else if("solidCircle"==a){b.save();var f=4,g=e.x-f*Math.cos(t),v=e.y-f*Math.sin(t);b.beginPath(),b.arc(g,v,f,0,2*Math.PI,!1),b.closePath(),b.fill(),b.stroke(),b.restore()}else if("dashedCircle"==a){b.save();f=4,g=e.x-f*Math.cos(t),v=e.y-f*Math.sin(t);b.beginPath(),b.arc(g,v,f,0,2*Math.PI,!1),b.closePath(),b.fillStyle="white",b.fill(),b.stroke(),b.restore()}else if("solidDiamond"==a){b.save();s=8,o=Math.PI/7,l=s/Math.cos(o),h=e.x-l*Math.cos(t-o),d=e.y-l*Math.sin(t-o),p=e.x-l*Math.sin(Math.PI/2-t-o),c=e.y-l*Math.cos(Math.PI/2-t-o);var y=e.x-2*s*Math.cos(t),u=e.y-2*s*Math.sin(t);b.beginPath(),b.moveTo(e.x,e.y),b.lineTo(h,d),b.lineTo(y,u),b.lineTo(p,c),b.lineTo(e.x,e.y),b.closePath(),b.fill(),b.stroke(),b.restore()}else if("dashedDiamond"==a){b.save();s=8,o=Math.PI/7,l=s/Math.cos(o),h=e.x-l*Math.cos(t-o),d=e.y-l*Math.sin(t-o),p=e.x-l*Math.sin(Math.PI/2-t-o),c=e.y-l*Math.cos(Math.PI/2-t-o),y=e.x-2*s*Math.cos(t),u=e.y-2*s*Math.sin(t);b.beginPath(),b.moveTo(e.x,e.y),b.lineTo(h,d),b.lineTo(y,u),b.lineTo(p,c),b.lineTo(e.x,e.y),b.closePath(),b.fillStyle="white",b.fill(),b.stroke(),b.restore()}else if("cross"==a){var x=6*Math.cos(Math.PI/2-t),m=6*Math.sin(Math.PI/2-t),w=e.x+x,S=e.y-m,D=(y=e.x-14*Math.cos(t))-x,M=(u=e.y-14*Math.sin(t))+m;b.beginPath(),b.moveTo(w,S),b.lineTo(D,M),b.stroke()}}},renderLinkerText:function(e,t){var i=$("#designer-canvas-"+e).find("#"+t.id),a=i.find(".text_canvas");0==a.length&&(a=$("
").appendTo(i));var n=t.fontStyle,r="scale("+VersionDesigner.config.scale[e]+")",s={"line-height":Math.round(1.25*n.size)+"px","font-size":n.size+"px","font-family":n.fontFamily,"font-weight":n.bold?"bold":"normal","font-style":n.italic?"italic":"normal","text-align":n.textAlign,color:"rgb("+n.color+")","text-decoration":n.underline?"underline":"none","-webkit-transform":r,"-ms-transform":r,"-o-transform":r,"-moz-transform":r,transform:r};if(a.css(s),null!=t.text&&""!=t.text){a.show();var o=t.text.replace(//g,">").replace(/\n/g,"
");a.html(o+"
");var l=this.getLinkerMidpoint(t),h=i.position();a.css({left:l.x.toScale(e)-h.left-a.width()/2,top:l.y.toScale(e)-h.top-a.height()/2})}else a.hide()},renderMarkers:function(e,t,i){if(t.attribute&&t.attribute.markers&&t.attribute.markers.length>0){var a=t.attribute.markers,n=Schema.config.markerSize;i&&(n=10);var r=t.attribute.markerOffset;i&&(r=5);for(var s=a.length*n+4*(a.length-1),o=t.props.w/2-s/2,l=0;l").appendTo($("#designer-canvas-"+e).find("#"+t.id));a.css({left:(10+t.props.titleProps.x)*VersionDesigner.config.scale[e]+"px",top:(17+t.props.titleProps.y)*VersionDesigner.config.scale[e]+"px"});var n=a[0].getContext("2d"),r="13px ";let i=(n.measureText(t.title).width+20).toScale(e),s=parseInt(r).toScale(e)+10;a.attr({width:i,height:s}),r+=t.fontStyle.fontFamily,n.font=r,n.fillStyle="#696969",t.titleStyle&&t.titleStyle.titleColor&&(n.fillStyle=t.titleStyle.titleColor),n.scale(VersionDesigner.config.scale[e],VersionDesigner.config.scale[e]),n.fillText(t.title,0,12)}},renderDataAttributes:function(pos,i,k){if($("#designer-canvas-"+pos).find("#"+i.id).children(".attr_canvas").remove(),i.dataAttributes&&0!=i.dataAttributes.length)for(var n={x:i.props.w/2,y:i.props.h/2},p=0;p0)for(var n=0;n").appendTo($("#designer-canvas-"+pos).find("#"+i.id)),b=H[0].getContext("2d"),w="12px ";w+=i.fontStyle.fontFamily,b.font=w;var D=b.measureText(y).width,a=20,E,F;""!=x&&(D+=20),"mostleft"==h?E=-D-2:"leftedge"==h?E=-D/2:"left"==h?E=2:"center"==h?E=(i.props.w-D)/2:"right"==h&&(E=i.props.w-D-2,E="rightedge"==h?i.props.w-D/2:i.props.w+2),F="mosttop"==I?-a:"topedge"==I?-a/2:"top"==I?0:"middle"==I?(i.props.h-a)/2:"bottom"==I?i.props.h-a:"bottomedge"==I?i.props.h-a/2:i.props.h;var g={x:E,y:F,w:D,h:a},G=Utils.getRotatedBox(g,i.props.angle,n);H.attr({width:G.w.toScale(pos),height:G.h.toScale(pos)}),b.font=w;var d=(G.x+(i.props.x-k.x)+10).toScale(pos),e=(G.y+(i.props.y-k.y)+10).toScale(pos);if("mostleft"==h&&"left"!=h&&"right"==h||H.css({left:d,top:e}),b.scale(VersionDesigner.config.scale[pos],VersionDesigner.config.scale[pos]),b.translate(G.w/2,G.h/2),b.rotate(i.props.angle),b.translate(-G.w/2,-G.h/2),b.translate((G.w-g.w)/2,(G.h-g.h)/2),b.globalAlpha=i.shapeStyle.alpha,"link"==c.type?b.fillStyle="#4183C4":b.fillStyle="#333","text"==c.showType&&(b.fillStyle=c.color),"attr"==c.showType&&(b.fillStyle=c.color),b.textBaseline="middle",D>i.props.w){var tempShapeWidth=i.props.w;tempShapeWidth<100&&(tempShapeWidth=100),H[0].width=tempShapeWidth+10,H[0].height=10*Math.ceil(D/tempShapeWidth)+15;for(var v=0;v1&&H.css({left:15,top:e}),"right"==h&&"mosttop"!=I&&"bottom"!=I&&(d=tempShapeWidth/4,H.css({left:d,top:e}))}else"mostleft"==h&&(d=-D,H.css({left:d,top:e})),"right"==h&&(d=i.props.w-D,H.css({left:d,top:e})),b.fillText(y,0,a/2);if(""!=x)if(x.indexOf("&#x")>=0){var icon=x.split("|")[0],iconColor=x.split("|")[1];b.font="19px awsui-iconfont",icon=eval("('"+icon.replace("&#x","\\u").replace(";","")+"')"),b.fillStyle=iconColor,b.fillText(icon,0,a/2),iconCavCode=H[0].toDataURL("image/png"),c.iconCavCode=iconCavCode}else{var J="/images/data-attr/"+x+".png",f=$(".shape_img[src='"+J+"']");0==f.length&&(f=$("").appendTo("#shape_img_container")),"true"==f.attr("loaded")?b.drawImage(f[0],g.w-20,0,20,20):f.bind("load.drawshape",function(){$(this).attr("loaded","true"),b.drawImage(f[0],g.w-20,0,20,20)})}b.beginPath(),b.rect(0,0,D,a),b.closePath()}},renderShapeLink:function(e,t){if(e.find(".shape_link_point").remove(),t.link)$(``).appendTo(e)},renderSahpeAttachment:function(e,t,i){const a="left"===e?versionData:curData;let n=a.shapeUpFile[i.id].value,r=a.shapeRelationUpFile[i.id].value;if(t.find(".shape_attachment_point").remove(),n.length>0||r.length>0)$(`
`).appendTo(t)},drawControls:function(e,t){let i=PageModel[e];var a=$("#shape-controls-"+e);if(0==a.length){var n=$("#designer-canvas-"+e);(a=$(`
`).appendTo(n)).append(``),a.append("
"),a.append("
"),a.append("
"),a.append("
"),a.append("
"),a.append("
"),a.append("
"),a.append("
"),$(".shape_controller").css({"border-color":VersionDesigner.config.anchorColor,width:VersionDesigner.config.anchorSize-2,height:VersionDesigner.config.anchorSize-2})}$(".shape_controller").css({"z-index":i.orderList.length+3}),a.show();var r,s,o=0;1==t.length?(r=(g=i.getShapeById(t[0])).props,o=g.props.angle,s=g.resizeDir):(r=Utils.getControlBox(e,t),s=["tl","tr","br","bl"]);var l=!0;let h=!1;const d=t.findIndex(e=>!i.getShapeById(e).hasOwnProperty("e2eContainerId")),p=t.findIndex(e=>"scopeLimitation"===i.getShapeById(e).name),c=t.findIndex(e=>"scopeLimitation"!==i.getShapeById(e).name&&i.getShapeById(e).hasOwnProperty("e2eContainerId"));if(-1==d&&-1==p&&-1!==c)h=!0;else if(-1!==c){t.filter(e=>"scopeLimitation"!==i.getShapeById(e).name&&i.getShapeById(e).hasOwnProperty("e2eContainerId")).forEach(e=>{-1==t.findIndex(t=>t===i.getShapeById(e).e2eContainerId)&&(h=!0)})}for(var f=0;f1)&&(s=[])}return h&&(l=!1,s=[]),this.controlStatus.rotatable=l,this.controlStatus.resizeDir=s,this.rotateControls(r,o,e),a},rotateControls:function(e,t,i){var a=$("#shape-controls-"+i),n=Utils.getRotatedBox(e,t),r=n.w.toScale(i),s=n.h.toScale(i);a.css({left:n.x.toScale(i),top:n.y.toScale(i),width:r,height:s});var o=r+20,l=s+20,h=$("#controls-bounding-"+i);h.attr({width:o,height:l});var d=h[0].getContext("2d");d.lineJoin="round",0==this.controlStatus.resizeDir.length?(d.lineWidth=2,d.strokeStyle=VersionDesigner.config.selectorColor,d.globalAlpha=.8):(d.lineWidth=1,d.strokeStyle=VersionDesigner.config.selectorColor,d.globalAlpha=.5),d.save(),d.clearRect(0,0,o,l),d.translate(o/2,l/2),d.rotate(t),d.translate(-o/2,-l/2),d.translate(9.5,9.5);var p={x:Math.round((e.x-n.x).toScale(i)),y:Math.round((e.y-n.y).toScale(i)),w:Math.floor(e.w.toScale(i)+1),h:Math.floor(e.h.toScale(i)+1)};d.strokeRect(p.x,p.y,p.w,p.h),d.restore();var c=0-VersionDesigner.config.anchorSize/2;e=Utils.toScale(i,e),n=Utils.toScale(i,n);var f={x:e.x+e.w/2,y:e.y+e.h/2};a.children(".shape_controller").hide();for(var g=0;g=0?e.x:u.indexOf("r")>=0?e.x+e.w:e.x+e.w/2,y=u.indexOf("t")>=0?e.y:u.indexOf("b")>=0?e.y+e.h:e.y+e.h/2;var m=Utils.getRotated(f,{x:v,y:y},t);x.css({left:m.x-n.x+c,top:m.y-n.y+c})}var w=Math.PI/8;a.children(".shape_controller").removeClass("s n e w"),t>w&&t<=3*w?(a.children("div[resizeDir=tl]").addClass("n"),a.children("div[resizeDir=tr]").addClass("e"),a.children("div[resizeDir=br]").addClass("s"),a.children("div[resizeDir=bl]").addClass("w"),a.children("div[resizeDir=l]").addClass("n w"),a.children("div[resizeDir=r]").addClass("s e"),a.children("div[resizeDir=b]").addClass("s w"),a.children("div[resizeDir=t]").addClass("n e")):t>3*w&&t<=5*w?(a.children("div[resizeDir=tl]").addClass("n e"),a.children("div[resizeDir=tr]").addClass("s e"),a.children("div[resizeDir=br]").addClass("s w"),a.children("div[resizeDir=bl]").addClass("n w"),a.children("div[resizeDir=l]").addClass("n"),a.children("div[resizeDir=r]").addClass("s"),a.children("div[resizeDir=b]").addClass("w"),a.children("div[resizeDir=t]").addClass("e")):t>5*w&&t<=7*w?(a.children("div[resizeDir=tl]").addClass("e"),a.children("div[resizeDir=tr]").addClass("s"),a.children("div[resizeDir=br]").addClass("w"),a.children("div[resizeDir=bl]").addClass("n"),a.children("div[resizeDir=l]").addClass("n e"),a.children("div[resizeDir=r]").addClass("s w"),a.children("div[resizeDir=b]").addClass("n w"),a.children("div[resizeDir=t]").addClass("s e")):t>7*w&&t<=9*w?(a.children("div[resizeDir=tl]").addClass("s e"),a.children("div[resizeDir=tr]").addClass("s w"),a.children("div[resizeDir=br]").addClass("n w"),a.children("div[resizeDir=bl]").addClass("n e"),a.children("div[resizeDir=l]").addClass("e"),a.children("div[resizeDir=r]").addClass("w"),a.children("div[resizeDir=b]").addClass("n"),a.children("div[resizeDir=t]").addClass("s")):t>9*w&&t<=11*w?(a.children("div[resizeDir=tl]").addClass("s"),a.children("div[resizeDir=tr]").addClass("w"),a.children("div[resizeDir=br]").addClass("n"),a.children("div[resizeDir=bl]").addClass("e"),a.children("div[resizeDir=l]").addClass("s e"),a.children("div[resizeDir=r]").addClass("n w"),a.children("div[resizeDir=b]").addClass("n e"),a.children("div[resizeDir=t]").addClass("s w")):t>11*w&&t<=13*w?(a.children("div[resizeDir=tl]").addClass("s w"),a.children("div[resizeDir=tr]").addClass("n w"),a.children("div[resizeDir=br]").addClass("n e"),a.children("div[resizeDir=bl]").addClass("s e"),a.children("div[resizeDir=l]").addClass("s"),a.children("div[resizeDir=r]").addClass("n"),a.children("div[resizeDir=b]").addClass("e"),a.children("div[resizeDir=t]").addClass("w")):t>13*w&&t<=15*w?(a.children("div[resizeDir=tl]").addClass("w"),a.children("div[resizeDir=tr]").addClass("n"),a.children("div[resizeDir=br]").addClass("e"),a.children("div[resizeDir=bl]").addClass("s"),a.children("div[resizeDir=l]").addClass("s w"),a.children("div[resizeDir=r]").addClass("n e"),a.children("div[resizeDir=b]").addClass("s e"),a.children("div[resizeDir=t]").addClass("n w")):(a.children("div[resizeDir=tl]").addClass("n w"),a.children("div[resizeDir=tr]").addClass("n e"),a.children("div[resizeDir=br]").addClass("s e"),a.children("div[resizeDir=bl]").addClass("s w"),a.children("div[resizeDir=l]").addClass("w"),a.children("div[resizeDir=r]").addClass("e"),a.children("div[resizeDir=b]").addClass("s"),a.children("div[resizeDir=t]").addClass("n"))},getLinkerMidpoint:function(e){var t={};if("normal"==e.linkerType)t={x:.5*e.from.x+.5*e.to.x,y:.5*e.from.y+.5*e.to.y};else if("curve"==e.linkerType){var i=e.from,a=e.points[0],n=e.points[1],r=e.to;t={x:.125*i.x+.375*a.x+.375*n.x+.125*r.x,y:.125*i.y+.375*a.y+.375*n.y+.125*r.y}}else{var s=[];s.push(e.from),(s=s.concat(e.points)).push(e.to);for(var o=0,l=1;lh){var f=(h-d)/p;t={x:(1-f)*a.x+f*n.x,y:(1-f)*a.y+f*n.y};break}d=c}}return t}},bindEvent:{designerLayoutScroll:function(e){let t=$("#designer-layout-"+e);t.bind("scroll",function(){if(Navigator.setView(e),isSameOperate){let i=$("#designer-layout-"+("left"===e?"right":"left"));i.scrollTop(t.scrollTop()),i.scrollLeft(t.scrollLeft())}})}},setZoomScale:function(e,t){t<.25&&(t=.25),t>4&&(t=4),VersionDesigner.config.scale[e]=t,VersionDesigner.initialize.initCanvas(e);let i=PageModel[e];for(var a in i.define.elements){var n=i.define.elements[a];VersionDesigner.painter.renderShape(n,e)}var r=Utils.getSelectedIds(e);Utils.unselect(e),Utils.selectShape(e,r),diffNode.filter(e=>e.type.includes("delete")).forEach(e=>{let t=PageModel.left.getShapeById(e.id);"linker"!==t.name&&VersionDesigner.painter.renderDiffNode(t,"right")})}},PageModel={left:{define:{page:{padding:60,backgroundColor:"255,255,255",gridSize:15,width:1600,showGrid:!0,height:2500},elements:{}},persistence:{},orderList:[],maxZIndex:0,linkerMap:{map:{},add:function(e,t){this.map[e]||(this.map[e]=[]),this.map[e].indexOf(t)<0&&this.map[e].push(t)},remove:function(e,t){this.map[e]&&Utils.removeFromArray(this.map[e],t)},empty:function(){this.map={}}},groupMap:{map:{},add:function(e,t){this.map[e]=t},push:function(e,t){this.map[e]||(this.map[e]=[]),this.map[e].push(t)},remove:function(e){delete this.map[e]},empty:function(){this.map={}}},add:function(e,t){this.addMulti([e],t)},addMulti:function(e,t){void 0===t&&(t=!0);for(var i=[],a=0;a0&&(a=this.orderList[this.orderList.length-1].zindex),this.maxZIndex=a}},right:{}};PageModel.right=deepCopy(PageModel.left),Number.prototype.toScale=function(e){return this*VersionDesigner.config.scale[e]},Number.prototype.restoreScale=function(e){return this/VersionDesigner.config.scale[e]};const Utils={selectIds:{left:[],right:[]},selectShape:function(e,t,i){let a=PageModel[e];if("string"==typeof t){var n=t;(t=[]).push(n)}if(t.length<=0)return;for(var r=Utils.mergeArray([],t),s=0;s0&&!c)VersionDesigner.painter.drawControls(e,l);void 0===i&&(i=!0),this.selectCallback&&i&&this.selectCallback();let f=!0;if(1===t.length){const e=a.getShapeById(t[0]);f=!e.hasOwnProperty("e2eContainerId")||""===e.e2eContainerId||"scopeLimitation"===e.name}else{const e=[];for(let i=0;i!e.hasOwnProperty("e2eContainerId")||"scopeLimitation"===e.name)}},selectedOtherShape:function(e){if(isSameOperate){let t="left"===e?"right":"left";if(Utils.getSelectedIds(e).length>0){let i=Utils.getSelectedIds(e)[0];if(PageModel[t].define.elements[i]){Utils.unselect(t),Utils.selectShape(t,i);let e=$("#designer-layout-"+t),a=e.width(),n=e.height(),r=e.scrollTop(),s=e.scrollLeft(),o=$("#designer-canvas-"+t).find("#"+i),l=parseInt(o.css("left")),h=parseInt(o.css("top")),d=parseInt(o.css("width")),p=parseInt(o.css("height")),c="";s-10>=l+d/2&&(c=图元位于画布左侧可解除同步锁定查看),l-s>=a-20-d/2&&(c=图元位于画布右侧可解除同步锁定查看),r-10>=h+p/2&&(c=图元位于画布顶部可解除同步锁定查看),h-r>=n-20-p/2&&(c=图元位于画布底部可解除同步锁定查看);let f=$(".shape-tip-"+t);c&&(f.text(c),f.show())}}else Utils.unselect(t);versionCompareFun.updateAttributeView(t)}},getDarkerColor:function(e,t){t||(t=13);var i=e.split(","),a=parseInt(i[0]),n=parseInt(i[1]),r=parseInt(i[2]),s=Math.round(a-a/255*t);s<0&&(s=0);var o=Math.round(n-n/255*t);o<0&&(o=0);var l=Math.round(r-r/255*t);return l<0&&(l=0),s+","+o+","+l},getDarkestColor:function(e){return this.getDarkerColor(e,26)},copy:function(e){return $.extend(!0,{},e)},getEndpointAngle:function(e,t){var i,a;if(i="from"==t?e.from:e.to,"normal"==e.linkerType)a="from"==t?e.to:e.from;else if("broken"==e.linkerType)a="from"==t?e.points[0]:e.points[e.points.length-1];else{var n,r=Utils.measureDistance(e.from,e.to);a={x:(1-(n="from"==t?12/r:1-12/r))*(1-n)*(1-n)*e.from.x+3*(1-n)*(1-n)*n*e.points[0].x+3*(1-n)*n*n*e.points[1].x+n*n*n*e.to.x,y:(1-n)*(1-n)*(1-n)*e.from.y+3*(1-n)*(1-n)*n*e.points[0].y+3*(1-n)*n*n*e.points[1].y+n*n*n*e.to.y}}return this.getAngle(a,i)},getAngle:function(e,t){var i=isNaN(Math.atan(Math.abs(e.y-t.y)/Math.abs(e.x-t.x)))?0:Math.atan(Math.abs(e.y-t.y)/Math.abs(e.x-t.x));return t.x<=e.x&&t.y>e.y?i=Math.PI-i:t.x=e.x&&t.y=e.x&&t.y>=e.y?n=Math.PI-n:t.x<=e.x&&t.y>=e.y?n=Math.PI+n:t.x<=e.x&&t.y<=e.y&&(n=2*Math.PI-n);var r=((n%=2*Math.PI)+i)%(2*Math.PI);return{x:e.x+Math.sin(r)*a,y:e.y-Math.cos(r)*a}},measureDistance:function(e,t){var i=t.y-e.y,a=t.x-e.x;return Math.sqrt(Math.pow(i,2)+Math.pow(a,2))},isSelected:function(e,t){return this.selectIds[t].indexOf(e)>=0&&!this.isLocked(t,e)},isLocked:function(e,t){let i=PageModel[e];return!(!i.getShapeById(t)||!i.getShapeById(t).locked)},getShapeBox:function(e){var t=e.props,i=e.props.angle;return this.getRotatedBox(t,i)},getLinkerLinePoints:function(e){var t=[];if("curve"!=e.linkerType)t.push(e.from),t=t.concat(e.points);else for(var i=0;i<=1;){var a={x:(1-i)*(1-i)*(1-i)*e.from.x+3*(1-i)*(1-i)*i*e.points[0].x+3*(1-i)*i*i*e.points[1].x+i*i*i*e.to.x,y:(1-i)*(1-i)*(1-i)*e.from.y+3*(1-i)*(1-i)*i*e.points[0].y+3*(1-i)*i*i*e.points[1].y+i*i*i*e.to.y};t.push(a),i+=.05}return t.push(e.to),t},getLinkerBox:function(e){for(var t=this.getLinkerLinePoints(e),i=t[0].x,a=t[0].y,n=t[0].x,r=t[0].y,s=0;sn&&(n=o.x),o.yr&&(r=o.y)}return{x:i,y:a,w:n-i,h:r-a}},pointInLinker:function(e,t,i){for(var a=this.getLinkerLinePoints(t),n={x:e.x-i,y:e.y},r={x:e.x+i,y:e.y},s={x:e.x,y:e.y-i},o={x:e.x,y:e.y+i},l=1;l=0;s--){var o=n.orderList[s].id,l=$("#designer-canvas-"+e).find("#"+o),h=n.getShapeById(o),d=l.position(),p=t-d.left,c=i-d.top,f={x:d.left,y:d.top,w:l.width(),h:l.height()},g=l.find(".shape_canvas")[0].getContext("2d"),v=this.pointInRect(t,i,f);if("linker"==h.name){if(!v)continue;if(a)continue;var y={x:t-(w=(w=10).toScale(e)),y:i-w,w:2*w,h:2*w};if(this.pointInRect(h.to.x.toScale(e),h.to.y.toScale(e),y)){var u={type:"linker_point",point:"end",shape:h};r.push(u)}else if(this.pointInRect(h.from.x.toScale(e),h.from.y.toScale(e),y)){u={type:"linker_point",point:"from",shape:h};r.push(u)}else{var x=l.find(".text_canvas"),m=x.position();y={x:m.left,y:m.top,w:x.width(),h:x.height()};if(this.pointInRect(p,c,y)){u={type:"linker_text",shape:h};r.push(u);continue}if(w=(w=7).toScale(e),(W=this.pointInLinker({x:t.restoreScale(e),y:i.restoreScale(e)},h,w))>-1){u={type:"linker",shape:h,pointIndex:W};r.push(u)}}}else{if(v&&h.locked&&!a){if(g.isPointInPath(p,c)){u={type:"shape",shape:h};r.push(u)}continue}var w=7;if(v){y={x:t-(w=w.toScale(e)),y:i-w,w:2*w,h:2*w};for(var S={x:h.props.x+h.props.w/2,y:h.props.y+h.props.h/2},b=h.getAnchors(),D=(u=null,0);D0){var z=P.position(),T=p-z.left,L=c-z.top;if(P[0].getContext("2d").isPointInPath(T,L)){u={type:"dataAttribute",shape:h,attribute:C};break}}}}if(null!=u){r.push(u);continue}}if(!v)continue;if(g.isPointInPath(p,c))if(a){if((b=h.getAnchors())&&b.length){u={type:"shape",shape:h};r.push(u)}}else{u={type:"shape",shape:h};r.push(u)}else if(!h.attribute||void 0===h.attribute.linkable||h.attribute.linkable)if(null!=(I=Utils.getPointAngle(e,o,t.restoreScale(e),i.restoreScale(e),w))){u=null;for(var U={angle:I},A=1;A<=w;A++)if(0==I?(U.x=p+A,U.y=c):I1&&a)u=r[0];else if(r.length>1){var _=r[0];if("bounding"==_.type&&"linker_point"!=_.type&&"linker"!=_.type)return _;var W=[],B=[],V=[];for(s=0;s0&&B.length>0)for(s=0;s0&&(B.sort(function(e,t){return Utils.isSelected(e.shape.id)&&!Utils.isSelected(t.shape.id)?-1:!Utils.isSelected(e.shape.id)&&Utils.isSelected(t.shape.id)?1:t.shape.props.zindex-e.shape.props.zindex}),u=B[0]),null==u&&W.length>0&&(W.sort(function(e,t){return Utils.isSelected(e.shape.id)&&!Utils.isSelected(t.shape.id)?-1:!Utils.isSelected(e.shape.id)&&Utils.isSelected(t.shape.id)?1:t.shape.props.zindex-e.shape.props.zindex}),u=W[0]),null==u&&(u=r[0])}return u},getCirclePoints:function(e,t,i){for(var a=Math.PI/18,n=[],r=0;r<36;r++){var s=a*r,o={x:e-Math.cos(s)*i,y:t-Math.sin(s)*i,angle:s};n.push(o)}return n},getPointAngle:function(e,t,i,a,n){var r=$("#"+t).position(),s=Utils.getShapeContext(t);i=i.toScale(e)-r.left,a=a.toScale(e)-r.top;for(var o=this.getCirclePoints(i,a,n),l=o.length,h=!1,d=0;d=0&&s<=1&&o>=0&&o<=1&&(n=!0)}return n},pointInRect:function(e,t,i){return e>=i.x&&e<=i.x+i.w&&t>=i.y&&t<=i.y+i.h},unselect:function(e){let t=PageModel[e];var i=this.selectIds[e];this.selectIds[e]=[];for(var a=0;aa.x2)&&(a.x2=r.x+r.w),(null==a.y2||r.y+r.h>a.y2)&&(a.y2=r.y+r.h)}return{x:a.x1,y:a.y1,w:a.x2-a.x1,h:a.y2-a.y1}},getSelected:function(e){let t=PageModel[e];for(var i=[],a=0;a").appendTo(i),t=e[0].getContext("2d");return t.strokeStyle="#777",t.lineWidth=1,t.beginPath(),t.moveTo(2,2),t.lineTo(9,9),t.moveTo(2,9),t.lineTo(9,2),t.stroke(),e})().css({left:t.x.toScale(e)-a.left-5,top:t.y.toScale(e)-a.top-5})}if("linker"!=t.name){var r=t.props,s={x:r.x+r.w/2,y:r.y+r.h/2};n(this.getRotated(s,{x:r.x,y:r.y},t.props.angle)),n(this.getRotated(s,{x:r.x+r.w,y:r.y},t.props.angle)),n(this.getRotated(s,{x:r.x+r.w,y:r.y+r.h},t.props.angle)),n(this.getRotated(s,{x:r.x,y:r.y+r.h},t.props.angle))}else n(t.from),n(t.to)},removeLockers:function(){$(".shape_locker").remove()}},GradientHelper={createLinearGradient:function(e,t,i){var a,n,r,s=e.props;if(s.w>s.h?(a={x:0,y:s.h/2},n={x:s.w,y:s.h/2},r=(i.angle+Math.PI/2)%(2*Math.PI)):(a={x:s.w/2,y:0},n={x:s.w/2,y:s.h},r=i.angle),0!=r){var o={x:s.w/2,y:s.h/2};a=Utils.getRotated(o,a,r),n=Utils.getRotated(o,n,r),a.x<0&&(a.x=0),a.x>e.props.w&&(a.x=e.props.w),a.y<0&&(a.y=0),a.y>e.props.h&&(a.y=e.props.h),n.x<0&&(n.x=0),n.x>e.props.w&&(n.x=e.props.w),n.y<0&&(n.y=0),n.y>e.props.h&&(n.y=e.props.h)}var l=t.createLinearGradient(a.x,a.y,n.x,n.y);return l.addColorStop(0,"rgb("+i.beginColor+")"),l.addColorStop(1,"rgb("+i.endColor+")"),l}};var Navigator={init:function(e){VersionDesigner.bindEvent.designerLayoutScroll(e),$("#navigation-eye-"+e).bind("mousedown",function(t){var i=$(this),a=i.position();$("#designer-layout-"+e).unbind("scroll");var n=$("#designer-layout-"+e),r=n.scrollTop(),s=n.scrollLeft(),o=$("#designer-canvas-"+e),l=o.width(),h=o.height(),d=$("#navigation-canvas-"+e),p=d.width(),c=d.height(),f=l/p,g=h/c;$(document).bind("mousemove.navigator",function(o){var l=o.pageX-t.pageX,h=o.pageY-t.pageY,d=s+l*f;n.scrollLeft(d);var p=r+h*g;if(n.scrollTop(p),i.css({left:a.left+l,top:a.top+h}),isSameOperate){let t="left"===e?"right":"left",i=$("#designer-layout-"+t),n=$("#navigation-eye-"+t);i.scrollLeft(d),i.scrollTop(p),n.css({left:a.left+l,top:a.top+h})}}),$(document).bind("mouseup.navigator",function(t){$(document).unbind("mousemove.navigator"),$(document).unbind("mouseup.navigator"),Navigator.setView(e),VersionDesigner.bindEvent.designerLayoutScroll(e)})}),$("#navigation-canvas-"+e).bind("click",function(t){var i=Utils.getRelativePos(t.pageX,t.pageY,$(this)),a=$("#designer-canvas-"+e),n=a.width(),r=a.height(),s=$("#navigation-canvas-"+e),o=n/s.width(),l=r/s.height(),h=i.x*o,d=i.y*l,p=$("#designer-layout-"+e),c=VersionDesigner.config.pageMargin;p.scrollLeft(h+c-p.width()/2),p.scrollTop(d+c-p.height()/2)}),this.setView(e)},drawNavigationTimeout:{left:null,right:null},draw:function(e){let t=PageModel[e];this.drawNavigationTimeout[e]&&window.clearTimeout(this.drawNavigationTimeout[e]),this.drawNavigationTimeout[e]=setTimeout(function(){var i=$("#navigation-canvas-"+e),a=i[0].getContext("2d");a.save(),a.clearRect(0,0,i.width(),i.height()),a.scale(i.width()/t.define.page.width,i.height()/t.define.page.height);for(var n=0;na&&(c=a),f>a?f=a:f<0&&(f=0);var g=p-i.scrollTop(),v=g+d;g<0?g=0:g>n&&(g=n),v>n?v=n:v<0&&(v=0);var y=f-c,u=v-g;if(0==y||0==u)t.hide();else{var x=i.scrollLeft()-p;x<0&&(x=0),x*=s/h;var m=i.scrollTop()-p;m<0&&(m=0),m*=o/d;var w=y*(s/h),S=u*(o/d);t.css({left:x-1,top:m-1,width:w,height:S}).show()}}};function deepCopy(e){if("object"!=typeof e||null===e)return e;let t=Array.isArray(e)?[]:{};for(let i in e)e.hasOwnProperty(i)&&(t[i]=deepCopy(e[i]));return t}$(function(){VersionDesigner.init("left"),VersionDesigner.init("right"),Navigator.init("left"),Navigator.init("right")}),Schema.initShapeFunctions=function(shape){var pathEval="shape.getPath = function(pos){var color = [255,255,255];var fillStyle = Utils.getShapeFillStyle(pos,this.fillStyle, false);if(fillStyle.color && fillStyle.color.length > 0){color = fillStyle.color.split(',');}var r = color[0]; var g = color[1]; var b = color[2]; var a = color[3] || 1,radial = 'radial',linear = 'linear';var w = this.props.w; var height = this.props.height; var h = this.props.h;var lineStyle = Utils.getShapeLineStyle(pos,this.lineStyle, false); var lineWidth = lineStyle.lineWidth; ";pathEval+=SchemaHelper.constructPathFunBody(shape.path)+"}",eval(pathEval);var block=shape.textBlock,textEval="shape.getTextBlock = function(){var w = this.props.w; var h = this.props.h; var height = this.props.height; return {x:";textEval+=block.x+",y:"+block.y+",w:"+block.w+",h:"+block.h+"}}",eval(textEval);for(var anchorsEval="shape.getAnchors = function(){var w = this.props.w; var h = this.props.h; return [",i=0;i 0) { - this.closeVersionList() - return - } - $(`
`).appendTo("#designer_header") - this.loadVersionList() - }, - loadVersionList() { - function versionItem(item) { - return ` -
-
-
- ${item.versionNo} ${item.versionStatus1} - ${item.updateTime}${item.updateUser}${修改} -
-
- ${item.createTime} - ${由}${item.createUser}${创建} -
-
-
- ${item.hasCreatePerm ? `` : ''} - - -
-
-
- ` - } - - awsui.ajax.request({ - url: './jd', - method: 'POST', - data: { - cmd: 'com.actionsoft.apps.coe.pal_pl_repository_designer_version_list', - sid: sid, - wsId: wsId, - teamId: teamId, - id: ruuid - }, - ok: function (res) { - if (res.result === 'ok') { - const status = { - use: 设计中, - publish: 已发布, - stop: 已停用, - approval: 审核中, - designer: 设计 - } - let versionList = res.data.versionList, historyList = res.data.historyList - versionList.forEach(item => { - item.versionStatus1 = status[item.versionStatus] - }) - historyList.forEach(item => { - item.versionStatus1 = status[item.versionStatus] - }) - versionListFun.versionList = [...versionList] - versionListFun.historyList = [...historyList] - let str = '' - versionList.forEach(item => { - str += versionItem(item) - }) - if (historyList.length > 0) { - str += `
${历史版本}
` - historyList.forEach(item => { - str += versionItem({...item, isHistory: true}) - }) - } - $("#versionList").empty() - $("#versionList").append(str) - } - } - }) - }, - closeVersionList() { - if ($("#versionList")) { - $("#versionList").remove() - } - }, - // 创建新版本 - createNewVersion(event, item) { - event.stopPropagation() - if (versionListFun.historyList.length > 0 && isBpmSupportMinor != 'true') { // 不支持小版本迭代 - $.confirm({ - title: 提示, - content: `${确定将} ${item.versionNo} ${item.isHistory ? 历史版本为模板创建新版本文件 : 版本为模板创建新版本文件}?`, - onConfirm: function () { - awsui.ajax.request({ - url: './jd', - method: 'POST', - data: { - cmd: 'com.actionsoft.apps.coe.pal_pl_repository_designer_version_manager_create', - sid: sid, - wsId: wsId, - teamId: teamId, - id: item.plId, - isLargeIteration: true, - isHistory: item.isHistory || false - }, - ok: function (res) { - if (res.result === 'ok') { - versionListFun.loadVersionList() - } - } - }) - } - }) - } else { - let {plId, versionNo} = item - let selectVersion = $("#select_" + plId) - if (selectVersion.is(":visible")) { - selectVersion.empty() - selectVersion.hide() - return - } - $(".select-version").hide() - selectVersion.show() - let smallVersionInteger = parseInt(versionNo.match(/\d+\.\d+/g)[0]); // 小版本整数位 - let smallVersionDecimal; // 小版本小数位 - let arr1 = []; // 大版本号 - let arr2 = []; // 以当前版本为大版本的所有小版本 - let largeVersion, smallVersion - let allVersion = versionListFun.versionList.concat(versionListFun.historyList).map(item => item.versionNo.match(/\d+\.\d+/g)[0].split('.')) - allVersion.forEach(item => { - arr1.push(parseInt(item[0])) - if (item[0] == smallVersionInteger) { - arr2.push(parseInt(item[1])) - } - }) - smallVersionDecimal = Math.max(...arr2) + 1 - largeVersion = 'v' + (Math.max(...arr1) + 1).toFixed(1) - if (item.isHistory) { - smallVersion = 'v' + Math.max(...arr1) + '.' + smallVersionDecimal - } else { - smallVersion = 'v' + smallVersionInteger + '.' + smallVersionDecimal - } - selectVersion.html(` -
${请选择版本号}:
-
- - ${largeVersion} -
-
- - ${smallVersion} -
- `) - $("input[name='versionRadio']").on("click", function (event) { - event.stopPropagation() - let isLargeIteration = $(this).attr("isLargeIteration") == 'true' - awsui.ajax.request({ - url: './jd', - method: 'POST', - data: { - cmd: 'com.actionsoft.apps.coe.pal_pl_repository_designer_version_manager_create', - sid: sid, - wsId: wsId, - teamId: teamId, - id: item.plId, - isLargeIteration: isLargeIteration, - isHistory: item.isHistory || false - }, - ok: function (res) { - if (res.result === 'ok') { - let newId = res.data.uuid - awsui.ajax.request({ - url: './jd', - method: 'POST', - data: { - cmd: 'com.actionsoft.apps.coe.pal_pl_repository_designer_version_manager_use', - sid: sid, - wsId: wsId, - teamId: teamId, - id: newId, - }, - ok: function (res) { - if (res.result === 'ok') { - let currentURL = window.location.href - let url = new URL(currentURL) - let searchParams = new URLSearchParams(url.search) - searchParams.set('uuid', newId); - url.search = searchParams.toString() - window.location.href = url.toString() - } - } - }) - } - } - }) - }); - } - }, - // 打开版本对比 - openComparePage(event, item) { - event.stopPropagation() - let compareBox = $("#versionCompareBox") - compareBox.empty() - compareBox.show() - let str = ''; - compareBox.append(str); - $('#versionCompareContent').attr( - 'src', "./w?sid=" + sid - + "&cmd=com.actionsoft.apps.coe.pal_pl_repository_designer_version_compare" - + "&wsId=" + wsId - + "&compareVerId=" + item.plId - + "&curId=" + ruuid - + "&teamId=" + teamId - // 添加子页面所需参数:是否为历史版本 - + "&isHistory=" + item.isHistory - ) - versionListFun.closeVersionList() - }, - // 关闭版本对比 - closeComparePage() { - parent.$("#versionCompareBox").hide() - parent.$("#versionCompareBox").empty() - }, - // 切换版本 - switchVersion(event, item) { - event.stopPropagation() - if ($("#saving_tip").text() == 文件已修改未保存) { - $.confirm({ - title: 提示, - content: 文件修改未保存 + ',' + 是否继续切换, - onConfirm: function () { - versionListFun.changeCurVersion(item.plId) - } - }) - } else { - versionListFun.changeCurVersion(item.plId) - } - }, - changeCurVersion(uuid) { - awsui.ajax.request({ - url: './jd', - method: 'POST', - data: { - cmd: 'com.actionsoft.apps.coe.pal_pl_repository_designer_version_manager_use', - sid: sid, - wsId: wsId, - teamId: teamId, - id: uuid, - }, - ok: function (res) { - if (res.result === 'ok') { - let currentURL = window.location.href - let url = new URL(currentURL) - let searchParams = new URLSearchParams(url.search) - searchParams.set('uuid', uuid); - url.search = searchParams.toString() - window.location.href = url.toString() - } - } - }) - } -} -// 版本对比页面 -const designerZoomYl = { - left: 100, - right: 100 -} -const fileTabStr = `
-
${文件属性}
-
-
-
${附件}
-
- ` -const shapeTabStr = `
-
${形状属性}
-
-
-
${附件}
-
-
-
${链接}
-
- ` -const versionCompareFun = { - // 缩放 - pageZoom(position, type) { - function handleZoom(position, type) { - if (type == 'zoomIn') { - if (designerZoomYl[position] + 10 > 200) { - designerZoomYl[position] = 200; - } else { - designerZoomYl[position] = designerZoomYl[position] + 10; - } - } else if (type == 'zoomOut') { - if (designerZoomYl[position] - 10 < 50) { - designerZoomYl[position] = 50; - } else { - designerZoomYl[position] = designerZoomYl[position] - 10; - } - } else { - designerZoomYl[position] = 100; - } - VersionDesigner.setZoomScale(position, designerZoomYl[position] / 100); - $("#zoom-value-" + position).text(Math.round(VersionDesigner.config.scale[position] * 100) + '%') - } - - handleZoom(position, type) - if (isSameOperate) { - let otherPos = position === "left" ? "right" : "left"; - designerZoomYl[otherPos] = designerZoomYl[position] - VersionDesigner.setZoomScale(otherPos, designerZoomYl[position] / 100); - $("#zoom-value-" + otherPos).text(Math.round(VersionDesigner.config.scale[otherPos] * 100) + '%') - } - }, - // 鹰眼导航 - openNavigation: function (position, isShow) { - function handleNav(position, isShow) { - if (isShow) { - $("#navigation-view-" + position).show() - Navigator.draw(position) - $('#show-nav-' + position).hide() - $('#close-nav-' + position).show() - } else { - $("#navigation-view-" + position).hide() - $('#show-nav-' + position).show() - $('#close-nav-' + position).hide() - } - } - - handleNav(position, isShow) - if (isSameOperate) { - let otherPos = position === "left" ? "right" : "left"; - handleNav(otherPos, isShow) - } - }, - openAttributeView: function (position) { - function handleAttrView(position) { - let selectedLength = Utils.getSelected(position).length - let view = $("#attribute-view-" + position) - let headLeft = view.find('.head-left') - if (selectedLength > 0) { - headLeft.attr('viewType', 'shape') - headLeft.html(shapeTabStr) - versionCompareFun.writeShapeAttributeHtml(position) - } else { - headLeft.attr('viewType', 'file') - headLeft.html(fileTabStr) - versionCompareFun.writeFileAttributeHtml(position) - } - view.show() - let btn = $("#view-btn-" + position) - btn.find('.btn-text').remove() - btn.css('width', '45px') - btn.hide() - versionCompareFun.attrViewEvent(position) - } - - handleAttrView(position) - if (isSameOperate) { - let otherPos = position === "left" ? "right" : "left"; - handleAttrView(otherPos) - } - }, - closeAttributeView: function (position) { - $("#attribute-view-" + position).hide() - $("#view-btn-" + position).show() - if (isSameOperate) { - let otherPos = position === "left" ? "right" : "left"; - $("#attribute-view-" + otherPos).hide() - $("#view-btn-" + otherPos).show() - } - }, - // view事件 - attrViewEvent: function (position) { - let otherPos = position === "left" ? "right" : "left"; - let view = $("#attribute-view-" + position), viewBody = $("#view-body-" + position) - let otherView = $("#attribute-view-" + otherPos) - // tab点击 - view.find(".head-left").off("click").on("click", ".attr-tab", function () { - view.find(".head-left div.active-tab").removeClass("active-tab"); - $(this).addClass("active-tab"); - let activeTab = $(this).attr("tab") - viewBody.children().css('display', 'none') - viewBody.find('.view-' + activeTab).show() - if (isSameOperate) { - if (otherView.is(":visible")) { - let curType = $(this).parent().attr("viewType") // 当前是文件属性还是数据属性 file/shape - let otherViewHead = otherView.find('.head-left'), otherViewBody = $("#view-body-" + otherPos), otherType = otherViewHead.attr("viewType") - if (curType === otherType) { - updateActiveTab(otherViewHead, otherViewBody, activeTab) - } else { - if (curType === 'shape') { - let selectedId = Utils.getSelectedIds(position)[0] - if (PageModel[otherPos].define.elements[selectedId]) { - Utils.selectShape(otherPos, selectedId) - versionCompareFun.updateAttributeView(otherPos) - updateActiveTab(otherViewHead, otherViewBody, activeTab) - } - } else { - Utils.unselect(otherPos) - versionCompareFun.updateAttributeView(otherPos) - updateActiveTab(otherViewHead, otherViewBody, activeTab) - } - } - } - } - - function updateActiveTab(otherViewHead, otherViewBody, activeTab) { - otherViewHead.children().removeClass("active-tab") - otherViewHead.find(`div[tab=${activeTab}]`).addClass("active-tab") - otherViewBody.children().css('display', 'none') - otherViewBody.find('.view-' + activeTab).show() - } - }) - // 内容滚动 - viewBody.off("scroll").on("scroll", function () { - if (isSameOperate) { - if (otherView.is(":visible")) { - let otherViewBody = $("#view-body-" + otherPos) - otherViewBody.scrollTop($(this).scrollTop()) - } - } - }) - }, - // 点击画布更新属性页面 - updateAttributeView: function (position) { - let view = $("#attribute-view-" + position) - let headLeft = view.find('.head-left') - let viewType = headLeft.attr('viewType') // 当前是文件属性还是数据属性 file/shape - if (view.is(":visible")) { - let selectedLength = Utils.getSelected(position).length - if (viewType === 'file') { // 已经打开了文件属性窗口 - if (selectedLength > 0) { - headLeft.html(shapeTabStr) - headLeft.attr('viewType', 'shape') - this.writeShapeAttributeHtml(position) - } - } else { // 已经打开了数据属性窗口 - if (selectedLength > 0) { - this.writeShapeAttributeHtml(position) - } else { - headLeft.html(fileTabStr) - headLeft.attr('viewType', 'file') - this.writeFileAttributeHtml(position) - } - } - this.attrViewEvent(position) - } - }, - // 文件属性 - writeFileAttributeHtml: function (position) { - const view = $("#attribute-view-" + position) - const activeTab = view.find(".active-tab").attr("tab") - let body = $("#view-body-" + position) - body.empty() - let allData = position === 'left' ? versionData : curData - let attr = allData.fileAttr, upFile = allData.fileUpFile, relationUpFile = allData.fileRelationUpFile - let attrStr = this.getAttrStr(position, attr) - let bodyStr = ` - ` - body.html(bodyStr) - body.find('.view-' + activeTab).show() - // 追加差异样式 - view.find(".tab-name").removeClass('attr-diff') - if (attr && attr.some(i => i.isDiff)) { - view.find('div[tab=attr]').find('.tab-name').addClass('attr-diff') - } - }, - // 形状属性 - writeShapeAttributeHtml: function (position) { - const view = $("#attribute-view-" + position) - const activeTab = view.find(".active-tab").attr("tab") - let body = $("#view-body-" + position) - body.empty() - let shape = Utils.getSelected(position)[0] - const allData = position === 'left' ? versionData : curData - let attributeArr = allData.shapeAttr[shape.id] || [], - shapeUpFile = allData.shapeUpFile[shape.id] || {}, - shapeRelationUpFile = allData.shapeRelationUpFile[shape.id] || {}, - shapeLink = allData.shapeLink[shape.id] || {file: {}, custom: {}} - let attrStr = this.getAttrStr(position, attributeArr) - let bodyStr = ` - - ` - body.html(bodyStr) - body.find('.view-' + activeTab).show() - // 追加差异样式 - view.find(".tab-name").removeClass('attr-diff') - if (attributeArr.some(i => i.isDiff)) { - view.find('div[tab=attr]').find('.tab-name').addClass('attr-diff') - } - if (shapeUpFile.isDiff || shapeRelationUpFile.isDiff) { - view.find('div[tab=upFile]').find('.tab-name').addClass('attr-diff') - } - if (shapeLink.file.isDiff || shapeLink.custom.isDiff) { - view.find('div[tab=link]').find('.tab-name').addClass('attr-diff') - } - }, - getAttrStr: function (position, attr) { - let str = '' - if (!attr) return str; - attr.forEach(item => { - if (item.type === 'relation' || item.type === 'awsorg') { - item.value = item.value.toString() - } - let contentStr = '' - switch (item.type) { - case 'table': - if (item.value) { - let tableStr = '' - let table = JSON.parse(item.value).table - let t1 = table[0].name, t2 = table[0].desc - tableStr += `
-
${t1}
-
${t2}
-
` - for (let i = 1; i < table.length; i++) { - let t1 = table[i].name, t2 = table[i].desc - tableStr += `
-
${t1}
-
${t2}
-
` - } - contentStr = `
${tableStr}
` - } else { - contentStr = `
${暂无}${item.name}
` - } - break; - case 'file': - let isHighSecurity = false - let fileList = item.value || [] - let listStr = '' - fileList.forEach(item => { - let security = '' // 三元 - if (isHighSecurity) { - security = `${item.securityInfo.name}` - } - listStr += `
-
- ${item.fileName} - ${security} -
-
- -
-
` - }) - contentStr = `
${listStr === '' ? `${暂无}${item.name}` : listStr}
` - break; - case 'link': - contentStr = `
- ${item.value === '' ? `${暂无}${item.name}` : `${item.value}`} -
` - break; - case 'shapeLink': - let linkStr = '', list = item.value || [] - list.forEach(i => { - linkStr += `
- -
` - }) - contentStr = `
${linkStr === '' ? `${暂无}${item.name}` : linkStr}
` - break; - default: - contentStr = `
- ${item.value === '' ? `${暂无}${item.name}` : `${item.value}`} -
` - } - str += `
-
${item.name}
- ${contentStr} -
` - }) - return str - }, - // 预览 - previewFile(position, file) { - const imgType = ['jpg', 'jpeg', 'gif', 'png'] - const fileType = file.fileName.split('.').reverse()[0] - if (!imgType.includes(fileType)) { // 不是图片 - window.open(file.downloadUrl) - return - } - $("#attribute-view-" + position).css('opacity', 0) - $('#model-' + position).show() - const otherPos = position === 'left' ? 'right' : 'left' - const windowWidth = document.body.clientWidth - const dialog = $('#file-preview-' + position), otherDialog = $('#file-preview-' + otherPos) - const img = new Image() - img.src = file.downloadUrl - img.addEventListener('load', function () { - dialog.find('img').attr('src', img.src) - dialog.dialog({ - title: file.fileName, - width: 650, - height: 480, - model: false, - onClose: function () { - $('#model-' + position).hide() - $("#attribute-view-" + position).css('opacity', 1) - } - }) - let dialogWidth = dialog.outerWidth(true), otherDialogWidth = otherDialog.outerWidth(true) - let x = windowWidth / 2 / 2 - dialogWidth / 2 - if (position === 'right') { - x += windowWidth / 2 - } - dialog.css({ - left: x + 'px' - }) - if (otherDialog.is(":visible")) { - // dialog机制会把已经打开的dialog居中 这里重新设置一下 - let x = windowWidth / 2 / 2 - otherDialogWidth / 2 - if (otherPos === 'right') { - x += windowWidth / 2 - } - otherDialog.css({ - left: x + 'px' - }) - } - }) - }, - // 同步操作 - isOpenSameOperate(isOpen) { - isSameOperate = isOpen - if (isOpen) { - $('.opend-operate').show() - $('.closed-operate').hide() - } else { - $('.opend-operate').hide() - $('.closed-operate').show() - } - }, - // 版本列表 - openCompareList() { - versionCompareFun.closeAttributeView('left') - versionCompareFun.closeAttributeView('right') - let page = $("#compareVersionList") - if (page.is(":visible")) { - page.hide() - page.empty() - } else { - awsui.ajax.request({ - url: './jd', - method: 'POST', - data: { - cmd: 'com.actionsoft.apps.coe.pal_pl_repository_designer_version_list', - sid: parent.sid, - wsId: parent.wsId, - teamId: parent.teamId, - id: parent.ruuid - }, - ok: function (res) { - if (res.result === 'ok') { - const status = { - use: 设计中, - publish: 已发布, - stop: 已停用, - approval: 审核中, - designer: 设计 - } - let versionList = res.data.versionList, historyList = res.data.historyList - versionList.forEach(item => { - item.versionStatus1 = status[item.versionStatus] - }) - historyList.forEach(item => { - item.isHistory = true - item.versionStatus1 = status[item.versionStatus] - }) - let allList = versionList.concat(historyList) - page.empty() - let str = '' - allList.forEach(item => { - let isDisabled = item.versionNo === versionData.versionNo || item.versionNo === curData.versionNo - str += ` -
-
-
- ${item.versionNo} ${item.versionStatus1} -
-
- ${item.updateTime} ${由}${item.updateUser}${修改} -
-
-
- ${item.versionNo === versionData.versionNo ? '' : ''} -
-
- ` - }) - page.append(str) - page.show() - } - } - }) - } - }, - // 点击监听 关闭版本列表 - closeVersionListByClick(event) { - let page = $("#compareVersionList") - if (!page.is(":visible")) { - return; - } - let targetElement = event.target; // 获取被点击的元素 - let isClickInsideDropdown = document.getElementById('compareVersionList').contains(targetElement); // 检查点击是否在下拉框内 - let isClickOnButton = document.querySelector('.center-top').contains(targetElement); // 检查点击是否在触发按钮内 - if (!isClickInsideDropdown && !isClickOnButton) { - // 关闭下拉框 - page.hide() - page.empty() - } - }, - // 切换对比版本 - changeComparePageUrl($this, compareVerId, isHistory) { - if ($($this).hasClass('disabled')) return - let listBox = $("#compareVersionList"), iframe = parent.$('#versionCompareContent') - listBox.hide() - listBox.empty() - parent.$.simpleAlert(正在切换, 'loading') - iframe.attr( - 'src', "./w?sid=" + parent.sid - + "&cmd=com.actionsoft.apps.coe.pal_pl_repository_designer_version_compare" - + "&wsId=" + parent.wsId - + "&compareVerId=" + compareVerId - + "&curId=" + curData.plId - + "&teamId=" + parent.teamId - // 添加子页面所需参数:是否为历史版本 - + "&isHistory=" + isHistory - ) - iframe.on('load', function () { - parent.$.simpleAlert("close") - }) - }, - // 切换到该版本 - changeToSelectedV() { - $.confirm({ - title: 提示, - content: 是否将 + ` ${versionData.versionNo} ` + 切换为使用中, - onConfirm: function () { - awsui.ajax.request({ - url: './jd', - method: 'POST', - data: { - cmd: 'com.actionsoft.apps.coe.pal_pl_repository_designer_version_manager_use', - sid: parent.sid, - wsId: parent.wsId, - teamId: parent.teamId, - id: versionData.plId, - }, - ok: function (res) { - if (res.result === 'ok') { - let currentURL = parent.window.location.href - let url = new URL(currentURL) - let searchParams = new URLSearchParams(url.search) - searchParams.set('uuid', versionData.plId); - url.search = searchParams.toString() - parent.window.location.href = url.toString() - } - } - }) - } - }) - } -} \ No newline at end of file diff --git a/com.actionsoft.apps.coe.pal/web/com.actionsoft.apps.coe.pal/lib/designer/scripts/versionCompare/version.methods.js b/com.actionsoft.apps.coe.pal/web/com.actionsoft.apps.coe.pal/lib/designer/scripts/versionCompare/version.methods.js deleted file mode 100644 index c7ff0da4..00000000 --- a/com.actionsoft.apps.coe.pal/web/com.actionsoft.apps.coe.pal/lib/designer/scripts/versionCompare/version.methods.js +++ /dev/null @@ -1 +0,0 @@ -const versionListFun={versionList:[],historyList:[],openVersionList(){$("#versionList").length>0?this.closeVersionList():($('
').appendTo("#designer_header"),this.loadVersionList())},loadVersionList(){function t(t){return`\n\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t${t.versionNo} ${t.versionStatus1}\n\t\t\t\t\t\t\t${t.updateTime}${t.updateUser}${修改}\n\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t${t.createTime}\n\t\t\t\t\t\t\t ${由}${t.createUser}${创建}\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t${t.hasCreatePerm?``:""}\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t`}awsui.ajax.request({url:"./jd",method:"POST",data:{cmd:"com.actionsoft.apps.coe.pal_pl_repository_designer_version_list",sid:sid,wsId:wsId,teamId:teamId,id:ruuid},ok:function(e){if("ok"===e.result){const i={use:设计中,publish:已发布,stop:已停用,approval:审核中,designer:设计};let s=e.data.versionList,a=e.data.historyList;s.forEach(t=>{t.versionStatus1=i[t.versionStatus]}),a.forEach(t=>{t.versionStatus1=i[t.versionStatus]}),versionListFun.versionList=[...s],versionListFun.historyList=[...a];let n="";s.forEach(e=>{n+=t(e)}),a.length>0&&(n+=`
${历史版本}
`,a.forEach(e=>{n+=t({...e,isHistory:!0})})),$("#versionList").empty(),$("#versionList").append(n)}}})},closeVersionList(){$("#versionList")&&$("#versionList").remove()},createNewVersion(t,e){if(t.stopPropagation(),versionListFun.historyList.length>0&&"true"!=isBpmSupportMinor)$.confirm({title:提示,content:`${确定将} ${e.versionNo} ${e.isHistory?历史版本为模板创建新版本文件:版本为模板创建新版本文件}?`,onConfirm:function(){awsui.ajax.request({url:"./jd",method:"POST",data:{cmd:"com.actionsoft.apps.coe.pal_pl_repository_designer_version_manager_create",sid:sid,wsId:wsId,teamId:teamId,id:e.plId,isLargeIteration:!0,isHistory:e.isHistory||!1},ok:function(t){"ok"===t.result&&versionListFun.loadVersionList()}})}});else{let{plId:t,versionNo:i}=e,s=$("#select_"+t);if(s.is(":visible"))return s.empty(),void s.hide();$(".select-version").hide(),s.show();let a,n,o,r=parseInt(i.match(/\d+\.\d+/g)[0]),l=[],d=[];versionListFun.versionList.concat(versionListFun.historyList).map(t=>t.versionNo.match(/\d+\.\d+/g)[0].split(".")).forEach(t=>{l.push(parseInt(t[0])),t[0]==r&&d.push(parseInt(t[1]))}),a=Math.max(...d)+1,n="v"+(Math.max(...l)+1).toFixed(1),o=e.isHistory?"v"+Math.max(...l)+"."+a:"v"+r+"."+a,s.html(`\n\t\t\t\t
${请选择版本号}:
\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t${n}\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t${o}\n\t\t\t\t
\n\t\t\t`),$("input[name='versionRadio']").on("click",function(t){t.stopPropagation();let i="true"==$(this).attr("isLargeIteration");awsui.ajax.request({url:"./jd",method:"POST",data:{cmd:"com.actionsoft.apps.coe.pal_pl_repository_designer_version_manager_create",sid:sid,wsId:wsId,teamId:teamId,id:e.plId,isLargeIteration:i,isHistory:e.isHistory||!1},ok:function(t){if("ok"===t.result){let e=t.data.uuid;awsui.ajax.request({url:"./jd",method:"POST",data:{cmd:"com.actionsoft.apps.coe.pal_pl_repository_designer_version_manager_use",sid:sid,wsId:wsId,teamId:teamId,id:e},ok:function(t){if("ok"===t.result){let t=window.location.href,i=new URL(t),s=new URLSearchParams(i.search);s.set("uuid",e),i.search=s.toString(),window.location.href=i.toString()}}})}}})})}},openComparePage(t,e){t.stopPropagation();let i=$("#versionCompareBox");i.empty(),i.show();i.append(''),$("#versionCompareContent").attr("src","./w?sid="+sid+"&cmd=com.actionsoft.apps.coe.pal_pl_repository_designer_version_compare&wsId="+wsId+"&compareVerId="+e.plId+"&curId="+ruuid+"&teamId="+teamId+"&isHistory="+e.isHistory),versionListFun.closeVersionList()},closeComparePage(){parent.$("#versionCompareBox").hide(),parent.$("#versionCompareBox").empty()},switchVersion(t,e){t.stopPropagation(),$("#saving_tip").text()==文件已修改未保存?$.confirm({title:提示,content:文件修改未保存+","+是否继续切换,onConfirm:function(){versionListFun.changeCurVersion(e.plId)}}):versionListFun.changeCurVersion(e.plId)},changeCurVersion(t){awsui.ajax.request({url:"./jd",method:"POST",data:{cmd:"com.actionsoft.apps.coe.pal_pl_repository_designer_version_manager_use",sid:sid,wsId:wsId,teamId:teamId,id:t},ok:function(e){if("ok"===e.result){let e=window.location.href,i=new URL(e),s=new URLSearchParams(i.search);s.set("uuid",t),i.search=s.toString(),window.location.href=i.toString()}}})}},designerZoom={left:100,right:100},fileTabStr=`
\n \t\t\t\t\t\t
${文件属性}
\n \t\t\t\t\t
\n \t\t\t\t\t
\n \t\t\t\t\t\t
${附件}
\n \t\t\t\t\t
\n \t\t\t\t `,shapeTabStr=`
\n \t\t\t\t\t\t
${形状属性}
\n \t\t\t\t\t
\n \t\t\t\t\t
\n \t\t\t\t\t\t
${附件}
\n \t\t\t\t\t
\n \t\t\t\t\t
\n \t\t\t\t\t\t
${链接}
\n \t\t\t\t\t
\n \t\t\t\t `,versionCompareFun={pageZoom(t,e){if(function(t,e){"zoomIn"==e?designerZoom[t]+10>200?designerZoom[t]=200:designerZoom[t]=designerZoom[t]+10:"zoomOut"==e?designerZoom[t]-10<50?designerZoom[t]=50:designerZoom[t]=designerZoom[t]-10:designerZoom[t]=100,VersionDesigner.setZoomScale(t,designerZoom[t]/100),$("#zoom-value-"+t).text(Math.round(100*VersionDesigner.config.scale[t])+"%")}(t,e),isSameOperate){let e="left"===t?"right":"left";designerZoom[e]=designerZoom[t],VersionDesigner.setZoomScale(e,designerZoom[t]/100),$("#zoom-value-"+e).text(Math.round(100*VersionDesigner.config.scale[e])+"%")}},openNavigation:function(t,e){function i(t,e){e?($("#navigation-view-"+t).show(),Navigator.draw(t),$("#show-nav-"+t).hide(),$("#close-nav-"+t).show()):($("#navigation-view-"+t).hide(),$("#show-nav-"+t).show(),$("#close-nav-"+t).hide())}if(i(t,e),isSameOperate){i("left"===t?"right":"left",e)}},openAttributeView:function(t){function e(t){let e=Utils.getSelected(t).length,i=$("#attribute-view-"+t),s=i.find(".head-left");e>0?(s.attr("viewType","shape"),s.html(shapeTabStr),versionCompareFun.writeShapeAttributeHtml(t)):(s.attr("viewType","file"),s.html(fileTabStr),versionCompareFun.writeFileAttributeHtml(t)),i.show();let a=$("#view-btn-"+t);a.find(".btn-text").remove(),a.css("width","45px"),a.hide(),versionCompareFun.attrViewEvent(t)}if(e(t),isSameOperate){e("left"===t?"right":"left")}},closeAttributeView:function(t){if($("#attribute-view-"+t).hide(),$("#view-btn-"+t).show(),isSameOperate){let e="left"===t?"right":"left";$("#attribute-view-"+e).hide(),$("#view-btn-"+e).show()}},attrViewEvent:function(t){let e="left"===t?"right":"left",i=$("#attribute-view-"+t),s=$("#view-body-"+t),a=$("#attribute-view-"+e);i.find(".head-left").off("click").on("click",".attr-tab",function(){i.find(".head-left div.active-tab").removeClass("active-tab"),$(this).addClass("active-tab");let n=$(this).attr("tab");if(s.children().css("display","none"),s.find(".view-"+n).show(),isSameOperate&&a.is(":visible")){let i=$(this).parent().attr("viewType"),s=a.find(".head-left"),r=$("#view-body-"+e);if(i===s.attr("viewType"))o(s,r,n);else if("shape"===i){let i=Utils.getSelectedIds(t)[0];PageModel[e].define.elements[i]&&(Utils.selectShape(e,i),versionCompareFun.updateAttributeView(e),o(s,r,n))}else Utils.unselect(e),versionCompareFun.updateAttributeView(e),o(s,r,n)}function o(t,e,i){t.children().removeClass("active-tab"),t.find(`div[tab=${i}]`).addClass("active-tab"),e.children().css("display","none"),e.find(".view-"+i).show()}}),s.off("scroll").on("scroll",function(){if(isSameOperate&&a.is(":visible")){$("#view-body-"+e).scrollTop($(this).scrollTop())}})},updateAttributeView:function(t){let e=$("#attribute-view-"+t),i=e.find(".head-left"),s=i.attr("viewType");if(e.is(":visible")){let e=Utils.getSelected(t).length;"file"===s?e>0&&(i.html(shapeTabStr),i.attr("viewType","shape"),this.writeShapeAttributeHtml(t)):e>0?this.writeShapeAttributeHtml(t):(i.html(fileTabStr),i.attr("viewType","file"),this.writeFileAttributeHtml(t)),this.attrViewEvent(t)}},writeFileAttributeHtml:function(t){const e=$("#attribute-view-"+t),i=e.find(".active-tab").attr("tab");let s=$("#view-body-"+t);s.empty();let a="left"===t?versionData:curData,n=a.fileAttr,o=a.fileUpFile,r=a.fileRelationUpFile,l=this.getAttrStr(t,n),d=`\n\t\t\t\t\t `;s.html(d),s.find(".view-"+i).show(),e.find(".tab-name").removeClass("attr-diff"),n&&n.some(t=>t.isDiff)&&e.find("div[tab=attr]").find(".tab-name").addClass("attr-diff")},writeShapeAttributeHtml:function(t){const e=$("#attribute-view-"+t),i=e.find(".active-tab").attr("tab");let s=$("#view-body-"+t);s.empty();let a=Utils.getSelected(t)[0];const n="left"===t?versionData:curData;let o=n.shapeAttr[a.id]||[],r=n.shapeUpFile[a.id]||{},l=n.shapeRelationUpFile[a.id]||{},d=n.shapeLink[a.id]||{file:{},custom:{}},c=this.getAttrStr(t,o),p=`\n\t\t\t\t\t \n\t\t\t\t\t `;s.html(p),s.find(".view-"+i).show(),e.find(".tab-name").removeClass("attr-diff"),o.some(t=>t.isDiff)&&e.find("div[tab=attr]").find(".tab-name").addClass("attr-diff"),(r.isDiff||l.isDiff)&&e.find("div[tab=upFile]").find(".tab-name").addClass("attr-diff"),(d.file.isDiff||d.custom.isDiff)&&e.find("div[tab=link]").find(".tab-name").addClass("attr-diff")},getAttrStr:function(t,e){let i="";return e?(e.forEach(e=>{"relation"!==e.type&&"awsorg"!==e.type||(e.value=e.value.toString());let s="";switch(e.type){case"table":if(e.value){let t="",i=JSON.parse(e.value).table;t+=`
\n\t\t\t\t\t\t\t\t\t\t
${i[0].name}
\n\t\t\t\t\t\t\t\t\t\t
${i[0].desc}
\n\t\t\t\t\t\t\t\t\t
`;for(let e=1;e\n\t\t\t\t\t\t\t\t\t\t\t
${i[e].name}
\n\t\t\t\t\t\t\t\t\t\t\t
${i[e].desc}
\n\t\t\t\t\t\t\t\t\t\t`}s=`
${t}
`}else s=`
${暂无}${e.name}
`;break;case"file":let i=!1,a=e.value||[],n="";a.forEach(e=>{let s="";i&&(s=`${e.securityInfo.name}`),n+=`
\n\t\t\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t${e.fileName}\n\t\t\t\t\t\t\t\t\t\t\t${s}\n\t\t\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\t
`}),s=`
${""===n?`${暂无}${e.name}`:n}
`;break;case"link":s=`
\n\t\t\t\t\t\t\t\t\t${""===e.value?`${暂无}${e.name}`:`${e.value}`}\n\t\t\t\t\t\t\t\t
`;break;case"shapeLink":let o="";(e.value||[]).forEach(t=>{o+=`
\n\t\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t${t.value}\n\t\t\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\t
`}),s=`
${""===o?`${暂无}${e.name}`:o}
`;break;default:s=`
\n\t\t\t\t\t\t\t\t\t${""===e.value?`${暂无}${e.name}`:`${e.value}`}\n\t\t\t\t\t\t\t\t
`}i+=`
\n\t\t\t\t\t\t
${e.name}
\n\t\t\t\t\t\t${s}\n\t\t\t\t\t
`}),i):i},previewFile(t,e){const i=e.fileName.split(".").reverse()[0];if(!["jpg","jpeg","gif","png"].includes(i))return void window.open(e.downloadUrl);$("#attribute-view-"+t).css("opacity",0),$("#model-"+t).show();const s="left"===t?"right":"left",a=document.body.clientWidth,n=$("#file-preview-"+t),o=$("#file-preview-"+s),r=new Image;r.src=e.downloadUrl,r.addEventListener("load",function(){n.find("img").attr("src",r.src),n.dialog({title:e.fileName,width:650,height:480,model:!1,onClose:function(){$("#model-"+t).hide(),$("#attribute-view-"+t).css("opacity",1)}});let i=n.outerWidth(!0),l=o.outerWidth(!0),d=a/2/2-i/2;if("right"===t&&(d+=a/2),n.css({left:d+"px"}),o.is(":visible")){let t=a/2/2-l/2;"right"===s&&(t+=a/2),o.css({left:t+"px"})}})},isOpenSameOperate(t){isSameOperate=t,t?($(".opend-operate").show(),$(".closed-operate").hide()):($(".opend-operate").hide(),$(".closed-operate").show())},openCompareList(){versionCompareFun.closeAttributeView("left"),versionCompareFun.closeAttributeView("right");let t=$("#compareVersionList");t.is(":visible")?(t.hide(),t.empty()):awsui.ajax.request({url:"./jd",method:"POST",data:{cmd:"com.actionsoft.apps.coe.pal_pl_repository_designer_version_list",sid:parent.sid,wsId:parent.wsId,teamId:parent.teamId,id:parent.ruuid},ok:function(e){if("ok"===e.result){const i={use:设计中,publish:已发布,stop:已停用,approval:审核中,designer:设计};let s=e.data.versionList,a=e.data.historyList;s.forEach(t=>{t.versionStatus1=i[t.versionStatus]}),a.forEach(t=>{t.isHistory=!0,t.versionStatus1=i[t.versionStatus]});let n=s.concat(a);t.empty();let o="";n.forEach(t=>{let e=t.versionNo===versionData.versionNo||t.versionNo===curData.versionNo;o+=`\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t${t.versionNo} ${t.versionStatus1}\n\t\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t${t.updateTime} ${由}${t.updateUser}${修改}\n\t\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\t\t${t.versionNo===versionData.versionNo?"":""}\n\t\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t`}),t.append(o),t.show()}}})},closeVersionListByClick(t){let e=$("#compareVersionList");if(!e.is(":visible"))return;let i=t.target,s=document.getElementById("compareVersionList").contains(i),a=document.querySelector(".center-top").contains(i);s||a||(e.hide(),e.empty())},changeComparePageUrl(t,e,i){if($(t).hasClass("disabled"))return;let s=$("#compareVersionList"),a=parent.$("#versionCompareContent");s.hide(),s.empty(),parent.$.simpleAlert(正在切换,"loading"),a.attr("src","./w?sid="+parent.sid+"&cmd=com.actionsoft.apps.coe.pal_pl_repository_designer_version_compare&wsId="+parent.wsId+"&compareVerId="+e+"&curId="+curData.plId+"&teamId="+parent.teamId+"&isHistory="+i),a.on("load",function(){parent.$.simpleAlert("close")})},changeToSelectedV(){$.confirm({title:提示,content:是否将+` ${versionData.versionNo} `+切换为使用中,onConfirm:function(){awsui.ajax.request({url:"./jd",method:"POST",data:{cmd:"com.actionsoft.apps.coe.pal_pl_repository_designer_version_manager_use",sid:parent.sid,wsId:parent.wsId,teamId:parent.teamId,id:versionData.plId},ok:function(t){if("ok"===t.result){let t=parent.window.location.href,e=new URL(t),i=new URLSearchParams(e.search);i.set("uuid",versionData.plId),e.search=i.toString(),parent.window.location.href=e.toString()}}})}})}}; \ No newline at end of file