diff --git a/gjjs-bd-business/pom.xml b/gjjs-bd-business/pom.xml index 5458c25..5b94cd7 100644 --- a/gjjs-bd-business/pom.xml +++ b/gjjs-bd-business/pom.xml @@ -76,6 +76,18 @@ <artifactId>commons-compress</artifactId> </dependency> <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </dependency> + <dependency> + <groupId>com.alibaba</groupId> + <artifactId>fastjson</artifactId> + </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + </dependency> + <dependency> <groupId>com.brilliance</groupId> <artifactId>jrxx-bean</artifactId> <version>0.0.1</version> @@ -129,4 +141,6 @@ </plugin> </plugins> </build> + + </project> \ No newline at end of file diff --git a/gjjs-bd-mybatis-support/pom.xml b/gjjs-bd-mybatis-support/pom.xml index 4a434cf..35b18c6 100644 --- a/gjjs-bd-mybatis-support/pom.xml +++ b/gjjs-bd-mybatis-support/pom.xml @@ -34,10 +34,20 @@ <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> + <dependency> <groupId>com.brilliance</groupId> <artifactId>gjjs-bd-runtime</artifactId> <version>0.0.1</version> </dependency> + <dependency> + <groupId>com.brilliance</groupId> + <artifactId>gjjs-mda</artifactId> + <version>0.0.1</version> + </dependency> </dependencies> + </project> \ No newline at end of file diff --git a/gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/MyBatisDaoSession.java b/gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/MyBatisDaoSession.java index 0ed7425..cf08f1b 100644 --- a/gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/MyBatisDaoSession.java +++ b/gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/MyBatisDaoSession.java @@ -186,6 +186,11 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession } @Override + public <T extends IModule> int dbReadSet(IModuleList<T> list, Object... args) { + return 0; + } + + @Override public <T extends IModule> int dbReadset(IModuleList<T> list, int limitSize, Argument... args) { list.clear(); MybatisArgumentAdapter adapter = new MybatisArgumentAdapter(SELECT, list.getDataClass(), args); @@ -347,6 +352,11 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession } } + @Override + public void dbFetchFields(Argument<?>... arguments) { + + } + private void setArgumentValue(Argument<? extends Object> argument, Object obj) { if (obj == null) return; diff --git a/gjjs-bd-runtime/pom.xml b/gjjs-bd-runtime/pom.xml deleted file mode 100644 index 6881db3..0000000 --- a/gjjs-bd-runtime/pom.xml +++ /dev/null @@ -1,102 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - - <parent> - <artifactId>gjjs-bd-common</artifactId> - <groupId>com.brilliance</groupId> - <version>0.0.1</version> - </parent> - <modelVersion>4.0.0</modelVersion> - - <artifactId>gjjs-bd-runtime</artifactId> - - - <dependencies> - <dependency> - <groupId>com.brilliance</groupId> - <artifactId>gjjs-mda</artifactId> - <version>0.0.1</version> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-annotations</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - </dependency> - <dependency> - <groupId>org.apache.poi</groupId> - <artifactId>poi-ooxml</artifactId> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jdbc</artifactId> - </dependency> - <dependency> - <groupId>org.mybatis.spring.boot</groupId> - <artifactId>mybatis-spring-boot-starter</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-redis</artifactId> - </dependency> - <dependency> - <groupId>com.google.code.gson</groupId> - <artifactId>gson</artifactId> - </dependency> - <dependency> - <groupId>com.alibaba</groupId> - <artifactId>fastjson</artifactId> - </dependency> - <dependency> - <groupId>org.dom4j</groupId> - <artifactId>dom4j</artifactId> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - </dependency> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - </dependency> - <dependency> - <groupId>com.esotericsoftware.kryo</groupId> - <artifactId>kryo5</artifactId> - </dependency> - - - <dependency> - <groupId>com.oracle</groupId> - <artifactId>ojdbc6</artifactId> - <version>12.1.0.2</version> - <scope>system</scope> - <systemPath>${basedir}/../lib/ojdbc6-12.1.0.2.jar</systemPath> - </dependency> - - </dependencies> - -</project> \ No newline at end of file diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/DCR.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/DCR.java deleted file mode 100644 index fc5bf1a..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/DCR.java +++ /dev/null @@ -1,442 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver; - -import com.brilliance.mda.runtime.mda.IModule; -import com.brilliance.mda.runtime.mda.IModuleList; -import com.brilliance.mda.runtime.mda.IRuleEmitter; -import com.brilliance.mda.runtime.mda.impl.AbstractScopeEmitter; -import com.brilliance.mda.runtime.mda.impl.ModuleList; -import com.brilliance.mda.runtime.mda.util.MdaUtils; -import com.brilliance.mda.support.td.ModuleInfoManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - -public class DCR { - private static final Logger log = LoggerFactory.getLogger(DCR.class); - public static final String DCR_SWITCH_KEY = "DCR_SWITCH"; - - public static ThreadLocal<LinkedHashMap<String,TaskCombo>> queueTl = new ThreadLocal<>(); - - public static ThreadLocal<Boolean> voToTradeStateTl = new ThreadLocal<>(); - - public static void emptyDefaultQueue(){ - queueTl.remove(); - } - public static void notifyDefault(String path){ - if (!isEnable()) - return; - path = path.replaceAll("\\([0-9]*\\)", "[i]"); - executeDefaultByPath(path); - } - - private static void executeDefaultByPath(String path){ - String transName = MdaEnv.getContext().getTransName(); - List<String> defaultList = ModuleInfoManager.getDefaultRule(transName, path); - if (defaultList != null) - defaultList.forEach(dr -> { - MdaEnv.getContext().getEmitter().executeDefault(dr); - }); - } - - public static AbstractScopeEmitter getModuleListEmitter(Class<?> moduleClass){ - String moduleName = moduleClass.getSimpleName().toLowerCase(); - String emitterName = AbstractScopeEmitter.EMITTER_PRE+moduleName; - AbstractScopeEmitter emitter = (AbstractScopeEmitter)MdaEnv.getBean(emitterName); - return emitter; - } - - public static void pushQueue(IModule module, String field, Object srcValue, Object value){ - if (!isEnable()) - return; - TaskCombo taskCombo = new TaskCombo(module,field); - //记录当前值和原始值 - taskCombo.srcValue = srcValue; - taskCombo.value = value; - //放置记录 - LinkedHashMap<String,TaskCombo> queueList = queueTl.get(); - if(queueList == null){ - queueList = new LinkedHashMap<>(); - queueTl.set(queueList); -// return; - } - //做一个原始状态合并 - //在一次执行过程中,如果某字段的值没有最终修改,default rule 就不要执行了 - String key = taskCombo.toString(); - TaskCombo srcTaskCombo = queueTl.get().get(key); - if(srcTaskCombo == null){ - queueList.put(key,taskCombo); - return; - } - //发生值回归,清理掉default触发 - if(MdaUtils.compareTo(srcTaskCombo.srcValue,taskCombo.value) == 0){ - queueList.remove(key); - }else{ - srcTaskCombo.value = taskCombo.value; - } - } - - public static void executeQueue() { - executeQueue(true,MdaEnv.getContext().getEmitter(),0); - } - - public static void executeQueue(boolean flag, IRuleEmitter ruleEmitter, int countNum) { - LinkedHashMap<String,TaskCombo> linkedList = queueTl.get(); - if (linkedList == null) { - return; - } - LinkedHashSet<TaskCombo> tempList = new LinkedHashSet<>(); - tempList.addAll(linkedList.values()); - if (flag) - linkedList.clear(); - Map<String,Object> mergeMap = mergeQueue(tempList,ruleEmitter); - Stack<String> keyStack = new Stack<>(); - executeMergedQueue(MdaEnv.getContext().getRoot(),ruleEmitter,mergeMap,mergeMap,keyStack); - // 有些defaultRule在方法内部对自己进行了赋值操作,这样队列还会添加,造成死循环,这里 - // 暂时用次数进行控制,如果执行次数超过5次就退出不再执行 - if(linkedList.size() != 0 && countNum < 5){ - executeQueue(true,ruleEmitter,countNum+1); - }else{ - linkedList.clear(); - } - } - - public static Map<String,Object> mergeQueue(LinkedHashSet<TaskCombo> tempList, IRuleEmitter ruleEmitter){ - log.debug("DCR任务数量:{}",tempList.size()); - long begMillis = System.currentTimeMillis(); - List<IModuleList> transModuleList = ruleEmitter.getAllModuleList(); - Map mergeMap = new LinkedHashMap(); - tempList.forEach(taskCombo -> { - String path = taskCombo.module.getFieldPath(taskCombo.field); - int begPos = path.indexOf("("); - if (begPos < 0) { - collectDefaultByDependency(path,mergeMap,transModuleList); - return; - } - //处理ModuleList的 - int endPos = path.indexOf(")", begPos); - String moduleListPath = path.substring(0, begPos); - collectDefaultByDependency(moduleListPath,mergeMap,transModuleList); - //处理后半段 - //找到其父ModuleList实例 - IModule scopeModule = taskCombo.module.getParent(); - while(!(scopeModule instanceof IModuleList)){ - scopeModule = scopeModule.getParent(); - } - //查找Emitter - String moduleName = ((IModuleList)scopeModule).getDataClass().getSimpleName().toLowerCase(); - AbstractScopeEmitter emitter = getModuleListEmitter(((IModuleList)scopeModule).getDataClass()); - if(emitter == null) { - return; - } - //计算 - String lowerModuleListPath = moduleListPath.substring(1).replaceAll("\\\\","\\.").toLowerCase(); - Object moduleListLeaf = mergeMap.get(lowerModuleListPath); - Map<String, Map<String, Integer>> subMergeQueueTemp = null; - //有可能moduleList自己也有个default rule,这会导致记录点的数据类型为 Integer - if(moduleListLeaf != null && moduleListLeaf instanceof Map) { - subMergeQueueTemp = (Map<String, Map<String, Integer>>) mergeMap.get(lowerModuleListPath); - } - if(subMergeQueueTemp == null){ - subMergeQueueTemp = new LinkedHashMap<>(); - mergeMap.put(lowerModuleListPath,subMergeQueueTemp); - } - String substr = path.substring(endPos + 2).toLowerCase().replaceAll("\\\\","\\."); - //收集外部以[i]表达式的依赖 - String directPath = lowerModuleListPath+"[i]." + substr; - collectDefaultByDependency(directPath,mergeMap,transModuleList); - //收集[i]依赖结束 - Map<String,Map<String,Integer>> subMergeQueue = subMergeQueueTemp; - - List<String> defaultList = ModuleInfoManager.getDefaultRule(moduleName, substr); - if (defaultList != null) { - defaultList.forEach(dr -> { - if (isAbsPath(dr)) { - String realPath = MdaEnv.getContext().getEmitter().getRealPath(dr.substring(1)); - mergeMap.put(realPath,0); - } else { - String index = path.substring(begPos+1,endPos); - Map<String,Integer> subItemQueue = subMergeQueue.get(index); - if(subItemQueue == null){ - subItemQueue = new LinkedHashMap<>(); - subMergeQueue.put(index,subItemQueue); - } - String realPath = emitter.getRealPath(dr); - subItemQueue.put(realPath,0); - } - }); - } - }); - log.debug("合并任务耗时:{}",System.currentTimeMillis() - begMillis); - return mergeMap; - } - private static List<IModuleList> getAllModuleList(IRuleEmitter ruleEmitter){ - return ruleEmitter.getAllModuleList(); - } - private static Map<String,Map<String,Object>> dependencyCache = new ConcurrentHashMap<>(); - - private static void collectDefaultByDependencyWithCache(String path,Map<String,Object> mergeMap){ - - } - private static void collectDefaultByDependency(String path,Map<String,Object> mergeMap,List<IModuleList> moduleList){ - String transName = MdaEnv.getContext().getTransName(); - IRuleEmitter ruleEmitter = MdaEnv.getContext().getEmitter(); - List<String> defaultList = ModuleInfoManager.getDefaultRule(transName, path); - if (defaultList != null) { - defaultList.forEach(dr -> { - String realPath = ruleEmitter.getRealPath(dr); - mergeMap.put(realPath,0); - }); - } - - //检查涉及到ModuleList中涉及的default rule - //moduleList = getAllModuleList(ruleEmitter); - String absPathTemp = path; - if(absPathTemp.startsWith("\\")){ - absPathTemp = absPathTemp.replaceAll("\\\\","\\."); - } - else if(absPathTemp.startsWith(".")){ - - } - else{ - absPathTemp = "."+absPathTemp; - } - String absPath = absPathTemp; - moduleList.forEach(iml->{ - if(iml.size() == 0){ - return; - } - IRuleEmitter emitter = getModuleListEmitter(iml.getDataClass()); - if(emitter == null){ - return; - } - List<String> subDefaultList = ModuleInfoManager.getDefaultRule(iml.getDataClass().getSimpleName().toLowerCase(), absPath); - if(subDefaultList == null){ - return; - } - String moduleListPath = iml.getPath(); - String lowerModuleListPath = moduleListPath.substring(1).replaceAll("\\\\","\\.").toLowerCase(); - //构造ModuleList的default记录项目 - Map<String,Map<String,Integer>> subMergeQueueTemp = (Map<String,Map<String,Integer>>)mergeMap.get(lowerModuleListPath); - if(subMergeQueueTemp == null){ - subMergeQueueTemp = new LinkedHashMap<>(); - mergeMap.put(lowerModuleListPath,subMergeQueueTemp); - } - //结束构建 - //记录要执行的default rule - Map<String,Map<String,Integer>> subMergeQueue = subMergeQueueTemp; - for(int i=1;i<=iml.size();i++){ - String index = String.valueOf(i); - Map<String,Integer> subItemQueue = subMergeQueue.get(index); - if(subItemQueue == null){ - subItemQueue = new LinkedHashMap<>(); - subMergeQueue.put(index,subItemQueue); - } - Map<String,Integer> subItemQueueTemp = subItemQueue; - subDefaultList.forEach(dr->{ - String realPath = emitter.getRealPath(dr); - subItemQueueTemp.put(realPath,0); - }); - } - - }); - - } - public static void executeMergedQueue(IModule rootModule, IRuleEmitter emitter,Map<String,Object> mergeMap,Map<String,Object> scopeMergeMap,Stack<String> keyStack){ - scopeMergeMap.entrySet().forEach(entry -> { - Integer one = new Integer(1); - if (one.equals(entry.getValue())) { - return; - } - //状态标记为0,或为ModuleList的项,继续执行 - String key = entry.getKey(); - cascadeExecute(key, entry.getValue(), rootModule, emitter, mergeMap, scopeMergeMap, keyStack); - - }); - } - private static boolean isAbsPath(String path){ - return path.startsWith("\\") || path.startsWith("."); - } - private static void cascadeExecute(String path, Object flagOrDps, IModule rootModule, IRuleEmitter emitter, - Map<String, Object> rootMergeMap, Map<String, Object> scopeMergeMap, Stack<String> keyStack){ - //当前Path,如果已在栈中存在,则退出。否则入栈 - String absPath = rootModule.getFieldPath(path); - if(keyStack.contains(absPath)){ - return; - } - keyStack.push(absPath); - //扫描依赖是否执行 - List<String> dependency = ModuleInfoManager.getDependency(rootModule.getClass().getSimpleName(),path); - Integer executedFlag = 1; - if(dependency != null) { - dependency.forEach(dp -> { - //执行栈如已包含,不继续执行 - //[i]表达式计算为list的path依赖 - int rowExprIdx = dp.indexOf("[i]"); - if(rowExprIdx > -1){ - dp = dp.substring(0,rowExprIdx); - } - //是否为绝对路径,有不同的判断 - boolean isAbs = isAbsPath(dp); - Object flag = null; - if (isAbs) { - dp = MdaEnv.getContext().getEmitter().getRealPath(dp); - flag = rootMergeMap.get(dp); - } else { - dp = emitter.getRealPath(dp); - flag = scopeMergeMap.get(dp); - } - if (executedFlag.equals(flag) || flag == null) { - return; - } - //该依赖还未执行完成,需要执行此依赖,继续递归深入 - if (isAbs) { - cascadeExecute(dp, flag, MdaEnv.getContext().getRoot(), MdaEnv.getContext().getEmitter(), rootMergeMap, rootMergeMap, keyStack); - } else { - cascadeExecute(dp, flag, rootModule, emitter, rootMergeMap, scopeMergeMap, keyStack); - } - }); - } - //判断完依赖,执行自己 - //1.标记当前key的状态为已执行 - scopeMergeMap.put(path, executedFlag); - //2.正式执行Default Rule - if(flagOrDps instanceof Integer) { - if(isAbsPath(path)){ - MdaEnv.getContext().getEmitter().executeDefault(path); - }else { - emitter.executeDefault(path); - } - keyStack.pop(); - return; - } - //3.如果依赖moduleList,执行ModuleList里面的Default Rule - //3.1查找该ModuleList的Emitter - ModuleList moduleList = (ModuleList)MdaDriver.getBaseObject(null,path); - AbstractScopeEmitter emitterOfModuleList = getModuleListEmitter(moduleList.getDataClass()); - if(emitter == null){ - keyStack.pop(); - return; - } - //3.2深入执行该ModuleList每一项的default rule - Map<String,Map<String,Object>> subMergeQueue = (Map<String,Map<String,Object>>)flagOrDps; - subMergeQueue.entrySet().forEach(entry->{ - String idxStr = entry.getKey(); - int num = Integer.parseInt(idxStr); - if(num <= 0){ - return; - } - if(moduleList.size() <= 0){ - return; - } - if (moduleList == null || moduleList.isEmpty()){ - return; - } - IModule subRootModule = moduleList.getElement(num); - //3.3设置上下文,以当前数据项为root点,执行Default - emitterOfModuleList.acceptContext(subRootModule); - executeMergedQueue(subRootModule,emitterOfModuleList,rootMergeMap,entry.getValue(),keyStack); - emitterOfModuleList.removeContext(); - }); - //执行一下自己 - //emitter.executeDefault(path); - keyStack.pop(); - } - - public static void notifyDefault(IModule module, String field) { - if (!isEnable()) - return; - String path = module.getFieldPath(field); - int begPos = path.indexOf("("); - if (begPos > 0) { - int endPos = path.indexOf(")", begPos); - String moduleListPath = path.substring(0, begPos); - //处理前半段 - executeDefaultByPath(moduleListPath); - //处理后半段 - //找到其父ModuleList实例 - IModule scopeModule = module.getParent(); - while(!(scopeModule instanceof IModuleList)){ - scopeModule = scopeModule.getParent(); - } - //查找Emitter - String moduleName = module.getClass().getSimpleName().toLowerCase(); - AbstractScopeEmitter emitter = getModuleListEmitter(module.getClass()); - if(emitter != null) { - emitter.acceptContext(module); - //执行模型内的Rule - String substr = path.substring(endPos + 1); - List<String> defaultList = ModuleInfoManager.getDefaultRule(moduleName, substr); - if (defaultList != null) - defaultList.forEach(dr -> { - if (dr.startsWith(".")) { - MdaEnv.getContext().getEmitter().executeDefault(dr); - } else { - emitter.executeDefault(dr); - } - }); - emitter.removeContext(); - } - } - notifyDefault(path); - } - - public static void enNotify(boolean flag) { - if (flag) { - MdaEnv.getContext().storeData(DCR_SWITCH_KEY, "0"); - } else { - MdaEnv.getContext().storeData(DCR_SWITCH_KEY, "1"); - } - } - - public static boolean getVoToTradeState() { - Boolean state = voToTradeStateTl.get(); - if (state == null) return false; - return state; - } - - public static void setVoToTradeState(boolean state) { - voToTradeStateTl.set(state); - } - - - public static boolean isEnable() { - if (MdaEnv.getContext() == null) return false; - Object val = MdaEnv.getContext().restoreData(DCR_SWITCH_KEY); - return "0".equals(val); - } - - public static class TaskCombo{ - public IModule module; - public String field; - public Object value; - public Object srcValue; - - public TaskCombo(IModule module, String field) { - this.module = module; - this.field = field; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - TaskCombo taskCombo = (TaskCombo) o; - return Objects.equals(module, taskCombo.module) && Objects.equals(field, taskCombo.field); - } - - @Override - public int hashCode() { - return Objects.hash(module, field); - } - - @Override - public String toString() { - return "TaskCombo{" + - "module=" + module + - ", field='" + field + '\'' + - '}'; - } - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/I18NImpl.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/I18NImpl.java deleted file mode 100644 index c85e178..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/I18NImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver; - -import com.brilliance.mda.runtime.mda.I18n; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Locale; -import java.util.ResourceBundle; - -public class I18NImpl implements I18n { - private static Logger log = LoggerFactory.getLogger(I18NImpl.class); - - public String getString(Locale locale, String resourceName, String resourceKey, int index) { - return getString(locale, resourceName, (index == 0) ? resourceKey : (String.valueOf(resourceKey) + index)); - } - - public String getString(Locale locale, String resourceName, String resourceKey) { - if (locale == null) - locale = Locale.getDefault(); - try { - ResourceBundle rb = ResourceBundle.getBundle("i18n/" + resourceName, locale); - return rb.getString(resourceKey); - } catch (Exception e) { - return "???" + resourceKey + "???"; - } - } - - public String getString(Locale locale, String i18nStr) { - return getString(locale, i18nStr, 0); - } - - public String getString(Locale locale, String i18nStr, int index) { - if (i18nStr == null || !i18nStr.startsWith("/")) - return i18nStr; - String[] values = i18nStr.split("/"); - if (values.length != 3) - return i18nStr; - return getString(locale, values[1], values[2], index); - } - -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/MdaContext.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/MdaContext.java deleted file mode 100644 index aa7ff90..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/MdaContext.java +++ /dev/null @@ -1,506 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver; - -import com.brilliance.mda.runtime.annotation.Transaction; -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.impl.EnvConfig; - -import java.util.*; - -import static com.brilliance.mda.runtime.mda.Constants.NO_ERROR; - - -public class MdaContext implements IContext { - - private transient final IDaoSession daoSession; - private transient final EnvConfig config; - private transient final IDisplay display; - private transient final ILocker locker; - - private Map<String, Object> params = new HashMap<String, Object>(); - private String displayStr; - - private transient IRuleEmitter emmiter; - private Map<String, Object> modifiedMap = new HashMap<String, Object>(); - private Map<String, String> errorsMap = new HashMap<String, String>(); - private Map<String, Pagination> pages = new HashMap<String, Pagination>(); - - private Object vo; - private String errorMessage = ""; - private String message = ""; - private String errorNo = ""; - private IModule root; - private int errorCode = NO_ERROR; - - private String transName; - private String CallStackRootContext = ""; - private Deque<String> ConcurrentCallStack = new LinkedList<>(); - private final Stack<String> rulePathStack = new Stack<>(); - - //支持setValues函数 - private Map<String, CodeEntity> valuesSet = new LinkedHashMap<>(); - - - public MdaContext(IModule root) { - this.root = root; - Class<?> rootClass = root.getClass(); - String transName = ""; - if (rootClass.isAnnotationPresent(Transaction.class)) { - Transaction trnAno = rootClass.getAnnotation(Transaction.class); - transName = trnAno.value(); - } - if (MdaEnv.isEmpty(transName)) - transName = rootClass.getSimpleName().toLowerCase(); - MdaEnv.setContext(this); //注册至环境中 - this.transName = transName; - this.daoSession = MdaEnv.getBean(IDaoSession.class); - this.config = MdaEnv.getBean(EnvConfig.class); - this.display = MdaEnv.getBean(IDisplay.class); - this.locker = MdaEnv.getBean(ILocker.class); - } - - public MdaContext(IRuleEmitter emitter, IModule root) { - this(root); - this.emmiter = emitter; - - } - - - public IDaoSession getDaoSession() { - return daoSession; - } - - public EnvConfig getEnvConfig() { - return config; - } - - public String getTransName() { - return transName; - } - - public Map<String, Object> getModified() { - return modifiedMap; - } - - public Map<String, String> getFieldErrors() { - return errorsMap; - } - - public String getMessage() { - return message == null ? "" : message; - } - - public String getErrorNo() { - return errorNo == null ? "" : errorNo; - } - - public void setModified(String path, Object value) { - this.modifiedMap.put(path, value); - } - - public void setFieldError(String target, String errMsg) { - target = emmiter.getRealPath(target); - this.errorsMap.put(target, errMsg); - } - - public IRuleEmitter getEmitter() { - return this.emmiter; - } - - public void setFieldError(IBaseObject baseobj, String errMsg) { - setFieldError(baseobj.getPath(), errMsg); - } - - @Override - public void setFieldError(IBaseObject baseobj, String format, Object... obj) { - - } - - public void setMessage(String errorNo, String message) { - if (errorNo != null && errorNo.matches("E\\d+")) { - this.errorNo = errorNo; - this.message = message; - } - } - - public boolean checkAll(IModule module) { - return this.postCheck(module.getPath()); - } - - public <T> T getDao(Class<T> clazz) { - return null; - } - - @Override - public boolean postRule(RuleType ruleType, String target) { - if (RuleType.RULE == ruleType) - return emmiter.executeRule(target, -1); - else if (RuleType.CHECK == ruleType) - return emmiter.executeCheck(target, -1); - else - return emmiter.executeInit(-1); - } - - - public boolean postRule(IModule m, String target) { - return postRule(emmiter.getRealPath(target)); - } - - @Override - public boolean postRule(IModule m, String target, boolean isInModuleList) { - return false; - } - - public boolean postRule(String target) { - return this.postRule(RuleType.RULE, target); - } - - @Override - public boolean postRule(IBaseObject baseObject) { - return postRule(baseObject.getPath()); - } - - @Override - public boolean postCheck(String target) { - return this.postRule(RuleType.CHECK, target); - } - - @Override - public boolean postInit() { - return this.postRule(RuleType.INIT, null); - } - - @Override - public void setParams(Map<String, Object> params) { - if (params != null) - this.params.putAll(params); - } - - public Map<String, Object> getRetMap() { - Map<String, Object> map = new HashMap<String, Object>(); - map.put("data", this.modifiedMap); - map.put("errors", this.errorsMap); - map.put("message", this.message); - map.put("errorno", this.errorNo); - return map; - } - - public IModule getRoot() { - return root; - } - - public Pagination getPagination(String path) { - return this.pages.get(path); - } - - @Override - public void storeCacheData(String key, Object data) { - - } - - @Override - public void deleteCacheData(String key) { - - } - - @Override - public void clearCacheData() { - - } - - @Override - public Object restoreCacheData(String key) { - return null; - } - - public Object restoreData(String key) { - return this.params.get(key); - } - - @Override - public void storeData(String key, Object data) { - this.params.put(key, data); - } - - @Override - public void deleteData(String key) { - - } - - @Override - public void clearData() { - - } - - public boolean saveDisplay(String filePathOrKey) { - if (this.display != null && this.displayStr != null) - return this.display.saveDisplay(filePathOrKey, this.displayStr); - return false; - } - - public int getErrorCode() { - int temp = this.errorCode; - this.errorCode = NO_ERROR; - return temp; - } - - public void setErrorCode(int errorCode) { - this.errorCode = errorCode; - } - - @Override - public void setErrorCode(int errorCode, String message) { - - } - - @Override - public void setErrorMessage(String errorMessage) { - - } - - @Override - public void setErrorMessage(String format, Object... values) { - - } - - @Override - public void setMessage(String format, Object... values) { - - } - - public void setFieldError(IModule m, String target, String message) { - setFieldError(m.getFieldPath(target), message); - } - - @Override - public void setFieldError(IModule m, String path, String format, Object... obj) { - - } - - public ILocker getLocker() { - return this.locker; - } - - @Override - public Locale getLocale() { - return Locale.SIMPLIFIED_CHINESE; - } - - @Override - public void setLocale(Locale locale) { - - } - - @Override - public void setEmitter(IRuleEmitter emitter) { - this.emmiter = emitter; - } - - @Override - public void logout() { - - } - - public <T> T getVo() { - return (T) vo; - } - - public void setVo(Object vo) { - this.vo = vo; - } - - public <T> T absGet(Class<T> clazz) { - String name = clazz.getSimpleName().toLowerCase(); - return absGet(clazz, name); - } - - public <T> T absGet(Class<T> clazz, String name) { - return (T) MdaDriver.getBaseObject(MdaEnv.getContext().getRoot(), name); - } - - @Override - public void setConcurrentCallStack(String concurrentCallStack) { - concurrentCallStack = "\\" + concurrentCallStack.replaceAll("\\.", "\\\\"); -// concurrentCallStack = String.format("%68s", "") + concurrentCallStack; - CallStackRootContext = concurrentCallStack; - } - - - @Override - public String getConcurrentCallStack() { - ConcurrentCallStack.clear(); - StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); - for (StackTraceElement stackTraceElement : stackTrace) { - String declaringClass = stackTraceElement.getClassName(); - String className = ""; //长度22 - String methodName = ""; //长度46 - if (declaringClass.startsWith("org")) { - break; - } - if (declaringClass.startsWith("com.ceb") || "getContext".equals(stackTraceElement.getMethodName())) { - String fileName = stackTraceElement.getFileName(); - className = fileName.contains(".") ? fileName.substring(0, fileName.indexOf(".")) : fileName; - if ("Platform".equals(className) || "Dynamic".equals(className)) { - continue; - } - methodName = stackTraceElement.getMethodName(); - if ("init".equals(methodName)) { - break; - } - className = String.format("%-22s", className); - methodName = String.format("%-46s", methodName); - ConcurrentCallStack.addLast((className + methodName).toUpperCase()); - } - } - String rootPath = ConcurrentCallStack.removeLast(); - rootPath += CallStackRootContext; - ConcurrentCallStack.addLast(rootPath); - StringBuilder sb = new StringBuilder(); - for (String s : ConcurrentCallStack) { - sb.append(s); - sb.append("\r\n"); - } - return sb.toString(); - } - - @Override - public void pushEventPath(String path) { - rulePathStack.push(path); - } - - @Override - public String getEventPath() { - return rulePathStack.peek(); - } - - @Override - public void popEventPath() { - rulePathStack.pop(); - } - - @Override - public void setError(IDatafield t) { - - } - - @Override - public void setError(String str) { - - } - - @Override - public void reraise() { - - } - - @Override - public int getErrorState() { - return 0; - } - - @Override - public void resetErrorState() { - - } - - @Override - public void clearEntireError() { - - } - - @Override - public Map<String, CodeEntity> getValuesSet() { - return valuesSet; - } - - public void visitValues() { - valuesSet.forEach((key, codeEntity) -> { - codeEntity.visited = true; - }); - } - - - @Override - public String getErrorMessage() { - return this.errorMessage; - } - - @Override - public void resetParams(Map<String, Object> params) { - this.params.clear(); - if (params != null) - this.params.putAll(params); - } - - @Override - public int assignSerialNo() { - return 0; - } - - - @Override - public <T> void setAttribute(Object parent, String prop, String ATTR, T val) { - if (parent instanceof IModule) { - IModule module = (IModule) parent; - module.getAttrMaps().put(buildAttrKey(prop, ATTR), val); - } - } - - @Override - public <T> T getAttribute(Object parent, String prop, String ATTR) { - if (parent instanceof IModule) { - IModule module = (IModule) parent; - return (T) module.getAttrMaps().get(buildAttrKey(prop, ATTR)); - } - return null; - } - - @Override - public void mallocPrintBuffer() { - - } - - @Override - public String releasePrintBuffer() { - return null; - } - - @Override - public StringBuilder getCurPrintBuffer() { - return null; - } - - @Override - public PrintSegment getCurPrintSegment() { - return null; - } - - @Override - public <T> T getParam(String key) { - return (T) params.get(key); - } - - @Override - public <T> void setParam(String key, T t) { - this.params.put(key, t); - } - - - private String buildAttrKey(String prop, String ATTR) { - return prop + "/" + ATTR; - } - - private String buildAttrKey(Object parent, String prop, String ATTR) { - StringBuilder builder = new StringBuilder(); - if (parent instanceof IModule) { - String serialNum = ((IModule) parent).getSerialNum(); - builder.append(serialNum).append("/"); - } else { - builder.append(parent.toString()).append("/"); - } - builder.append(ATTR).append("/"); - builder.append(prop); - return builder.toString(); - } - - -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/MdaDriver.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/MdaDriver.java deleted file mode 100644 index e36ac9a..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/MdaDriver.java +++ /dev/null @@ -1,671 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver; - -import com.brilliance.mda.runtime.annotation.RelPath; -import com.brilliance.mda.runtime.annotation.Transaction; -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.impl.AbstractModule; -import com.brilliance.mda.runtime.mda.impl.DatafieldImpl; -import com.brilliance.mda.runtime.mda.impl.ModuleList; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.lang.reflect.ParameterizedType; -import java.math.BigDecimal; -import java.util.*; - -public class MdaDriver { - - @SuppressWarnings("rawtypes") - public static IBaseObject getBaseObject(IModule root, String target, boolean helpLoad) { - try { - if (root == null) { - root = MdaEnv.getContext().getRoot(); - } - - if (target == null || target.length() == 0) - return root; - if (MdaEnv.getContext().getRoot() == root && target.charAt(0) == '\\') - target = target.substring(1); - int dotidx = target.indexOf("."); - if (dotidx < 0) - dotidx = target.indexOf("\\"); - String fieldName = target; - String leftPath = null; - if (dotidx > 0) { - fieldName = target.substring(0, dotidx); - leftPath = target.substring(dotidx + 1); - int begIndex = dotidx + 1; - while (target.charAt(begIndex) == '.' || target.charAt(begIndex) == '\\') - begIndex++; - leftPath = target.substring(begIndex); - } - - Class<?> clazz = root.getClass(); - Field field = clazz.getDeclaredField(fieldName); - field.setAccessible(true); - if (field.getType() == ModuleHolder.class) { - IModule module = (IModule) ((ModuleHolder) field.get(root)).get(); - if (dotidx < 0) - return module; - else - return getBaseObject(module, leftPath, helpLoad); - } else if (field.getType() != IModule.class && IModule.class.isAssignableFrom(field.getType())) //模型 - { - IModule module = (IModule) field.get(root); - if (helpLoad && module == null) { - String getMethodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); - try { - Method m = clazz.getMethod(getMethodName); - module = (IModule) m.invoke(root); - } catch (Exception e) { - - } - } - if (module == null) - return null; - - if (dotidx < 0) - return module; - else - return getBaseObject(module, leftPath, helpLoad); - } else if (IModuleList.class.isAssignableFrom(field.getType())) { - IModuleList moduleList = (IModuleList) field.get(root); - if (helpLoad && moduleList == null) { - String getMethodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); - try { - Method m = clazz.getMethod(getMethodName); - moduleList = (IModuleList) m.invoke(root); - } catch (Exception e) { - - } - } - return moduleList; - } else //其他类型默认为字段 - { - DatafieldImpl holder = new DatafieldImpl(root, field); - return holder; - } - - } catch (Exception e) { - - } - return null; - } - - public static IBaseObject getBaseObject(IModule root, String target) { - return getBaseObject(root, target, true); - } - - @SuppressWarnings("rawtypes") - public static DatafieldImpl getDatafield(IModule root, String target) { - return (DatafieldImpl) getBaseObject(root, target); - } - - public static DatafieldImpl getDatafield(String target) { - return (DatafieldImpl) getBaseObject(null, target); - } - - public static IModule getModule(IModule root, String target) { - return (IModule) getBaseObject(root, target); - } - - public static IModule getModule(String target) { - return (IModule) getBaseObject(null, target); - } - - public static IModule getModule(Object o, IModule root, String target) { - return (IModule) getBaseObject(root, target); - } - - @SuppressWarnings("rawtypes") - public static IModuleList getModuleList(IModule root, String target) { - return (IModuleList) getBaseObject(root, target); - } - - public static IModuleList getModuleList(String target) { - return (IModuleList) getBaseObject(null, target); - } - - /** - * 模型拷贝 m2值 深拷贝至m1 - * - * @param m1 - * @param m2 - */ - @SuppressWarnings({"rawtypes", "unchecked"}) - public static void copyValues(Object m1, Object m2) { - if (m1 == null || m2 == null) - return; - if (m1.getClass() != m2.getClass()) - return; - Class<?> clazz = m1.getClass(); - Field[] fields = clazz.getDeclaredFields(); - for (Field field : fields) { - field.setAccessible(true); - if (Modifier.isStatic(field.getModifiers())) - continue; - Class<?> fieldType = field.getType(); - if (AbstractModule.class.isAssignableFrom(fieldType)) //正常模型 - { - try { - Object obj1 = field.get(m1); - Object obj2 = field.get(m2); - if (obj1 == null && obj2 == null) - continue; - else if (obj2 == null && obj1 != null) { - field.set(m1, null); - } else if (obj1 == null && obj2 != null) // 模型类型的字段为null,调用getter - { - String getterStr = "get" + firstUpper(field.getName()); - try { - Method getter = clazz.getMethod(getterStr); - obj1 = getter.invoke(m1); - } catch (Exception e) { - continue; - } - } - copyValues((IModule) obj1, (IModule) obj2); - } catch (Exception e) { - e.printStackTrace(); - } - } else if (ModuleList.class.isAssignableFrom(fieldType)) { - try { - IModuleList obj1 = (IModuleList) field.get(m1); - IModuleList obj2 = (IModuleList) field.get(m2); - if (obj1 == null && obj2 == null) - continue; - else if (obj2 == null && obj1 != null) { - field.set(m1, null); - } else if (obj1 == null && obj2 != null) // 模型类型的字段为null,调用getter - { - String getterStr = "get" + firstUpper(field.getName()); - try { - Method getter = clazz.getMethod(getterStr); - obj1 = (IModuleList) getter.invoke(m1); - } catch (Exception e) { - continue; - } - } - obj1.clear(); - obj1.addAll(obj2); - } catch (Exception e) { - e.printStackTrace(); - } - } else if (FieldHolder.class.isAssignableFrom(fieldType) || ModuleHolder.class.isAssignableFrom(fieldType)) //引用类型不复制 - { - continue; - } else if ("log".equals(field.getName()) || "_parent".equals(field.getName()) || "_path".equals(field.getName())) { - continue; - } else //字段类型 - { - try { - Object obj = field.get(m2); - field.set(m1, obj); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } - - public static void clearModule(IModule module) { - Field[] fields = module.getClass().getDeclaredFields(); - try { - for (Field field : fields) { - Class<?> fieldType = field.getType(); - field.setAccessible(true); - if (Modifier.isStatic(field.getModifiers())) - continue; - if (AbstractModule.class.isAssignableFrom(fieldType)) //正常模型 - { - try { - Object obj1 = field.get(module); - if (obj1 == null) - continue; - clearModule((IModule) obj1); - } catch (Exception e) { - e.printStackTrace(); - } - } else if (ModuleList.class.isAssignableFrom(fieldType)) { - try { - IModuleList obj1 = (IModuleList) field.get(module); - if (obj1 == null) - continue; - obj1.clear(); - } catch (Exception e) { - e.printStackTrace(); - } - } else if (FieldHolder.class.isAssignableFrom(fieldType) || ModuleHolder.class.isAssignableFrom(fieldType)) //引用类型不复制 - { - continue; - } else if ("log".equals(field.getName()) || "_parent".equals(field.getName()) || "_path".equals(field.getName())) { - continue; - } else //字段类型 - { - try { - Class<?> zeroClazz = field.getType(); - Object val = MdaDriver.zero(zeroClazz); - field.set(module, val); - } catch (Exception e) { - e.printStackTrace(); - } - } - - } - } catch (Exception e) { - e.fillInStackTrace(); //加入警告日志 - } - } - - public static Object zero(Class<?> clazz) { - if (clazz == int.class || clazz == Integer.class) - return 0; - if (clazz == float.class || clazz == Float.class) - return 0f; - if (clazz == long.class || clazz == Long.class) - return 0l; - if (clazz == double.class || clazz == Double.class) - return 0d; - if (clazz == char.class || clazz == Character.class) - return (char) 0; - if (clazz == byte.class || clazz == Byte.class) - return (byte) 0; - if (clazz == BigDecimal.class) { - return new BigDecimal("0"); - } - return null; - - } - - public static String getModuleType(IModule m) { - if (m == null) return null; - return m.getClass().getSimpleName().toLowerCase(); - } - - /** - * 兼容设置值 - * - * @param field Class字段 - * @param value 值 - */ - public static void setFieldValue(Field field, Object value) { - - } - - public static <T> void setValueFromVO(IContext ctx, T vo) { - //TODO 直接基于反射实现,后续用动态直接码优化性能 - Class<?> clazz = vo.getClass(); - String parent = ""; - if (clazz.isAnnotationPresent(RelPath.class)) { - RelPath relpath = clazz.getAnnotation(RelPath.class); - parent = relpath.value(); - } - setValueFromVO(ctx.getRoot(), vo, parent); - } - - public static void setValueFromVoByClass(IModule root, Object vo, Class clazz, String parent) { - if (!clazz.getSuperclass().getName().equalsIgnoreCase("java.lang.Object")) { - //父类定义先赋值,子类覆盖父类的设定 - setValueFromVoByClass(root, vo, clazz.getSuperclass(), parent); - } - IModule pntobj = root; //父模型缓存, - String lastPntPath = null; - for (Field fieldVo : clazz.getDeclaredFields()) { - if (fieldVo.getName().equals("")) return; - if (!fieldVo.isAnnotationPresent(RelPath.class)) - continue; - RelPath relAno = fieldVo.getAnnotation(RelPath.class); - if (relAno.dir() == DirType.OUT) // 输出项,不取 - continue; - String subpath = relAno.value(); // 子路径 -// if ("setmod.docamt".equals(subpath)) { -// System.out.println("subpath"); -// String a = subpath; -// String b = a; -// } - String path = parent.length() == 0 ? subpath : parent + "." + subpath; //得到路径 - if (relAno.recursion()) //递归取值 - { - IBaseObject obj = getBaseObject(root, path); - if (obj == null || !(obj instanceof IModule)) - continue; - try { - fieldVo.setAccessible(true); - Object subVo = fieldVo.get(vo); - setValueFromVO((IModule) obj, subVo, path); - } catch (Exception e) { - } - continue; - } - int idx = path.lastIndexOf('.'); - Field fieldModule = null; - if (idx < 0) { - fieldModule = getParentField(root, path); - pntobj = root; - lastPntPath = null; - } else { - String templastPntPath = path.substring(0, idx); - if (!templastPntPath.equals(lastPntPath)) { - IBaseObject obj = getBaseObject(root, templastPntPath); - if (obj == null || !(obj instanceof IModule)) // 找不到父模型,或者父模型不是IModule类型的 - continue; - else { - pntobj = (IModule) obj; - } - } else if (path.startsWith(lastPntPath)) { - //基于上次的查找找父模型 - IBaseObject obj = getBaseObject(pntobj, path.substring(lastPntPath.length(), idx)); - if (obj == null || !(obj instanceof IModule)) // 找不到父模型,或者父模型不是IModule类型的 - continue; - else { - pntobj = (IModule) obj; - } - } - fieldModule = getParentField(pntobj, path.substring(idx + 1)); - lastPntPath = templastPntPath; - } - setFieldValue(fieldVo, vo, fieldModule, pntobj, true); - } - } - - public static <T> void setValueFromVO(IModule root, Object vo, String parent) { - setValueFromVoByClass(root, vo, vo.getClass(), parent); - } - - private static Field getParentField(Object parent, String fieldstr) { - try { - Field field = parent.getClass().getDeclaredField(fieldstr); - return field; - } catch (Exception e) { - - } - return null; - } - - private static void setFieldValue(Field from, Object fromObj, Field to, Object toObj, boolean voToMod) { - try { - if (from == null || fromObj == null || to == null || toObj == null) - return; - Class<?> fromClass = from.getType(); - Class<?> toClass = to.getType(); - from.setAccessible(true); - to.setAccessible(true); - if (List.class.isAssignableFrom(fromClass) - && - List.class.isAssignableFrom(toClass) - && ((ParameterizedType) from.getGenericType()).getActualTypeArguments()[0] == //判断泛型是否相等 - ((ParameterizedType) to.getGenericType()).getActualTypeArguments()[0] - ) { - if (!voToMod) { - to.set(toObj, from.get(fromObj)); //拷贝数据 - } else { - //添加数据、添加分页数据 - List dataList = (List) from.get(fromObj); - IModuleList moduleList = (IModuleList) getBaseObject((IModule) toObj, to.getName()); - if (dataList != null) { - HashMap<String, Object> inrs = new HashMap<>(); - for (Object o : moduleList) { - try { - Field f = o.getClass().getDeclaredField("inr"); - f.setAccessible(true); - inrs.put((String) f.get(o), o); - } catch (NoSuchFieldException ne) { - continue; - } - } - for (Object o : dataList) { - String inr = getFieldValue(o, "inr"); - if (inrs.containsKey(inr)) - moduleList.remove(inrs.get(inr)); - moduleList.add(o); - } - } - } - return; - } - if (!to.getType().equals(from.getType())) //类型不相等 - { - return; - } - - - to.set(toObj, from.get(fromObj)); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public static <T> T getFieldValue(Object o, String fieldName) { - try { - Field f = o.getClass().getDeclaredField(fieldName); - f.setAccessible(true); - return (T) f.get(o); - } catch (NoSuchFieldException | IllegalAccessException e) { - return null; - } - } - - public static <T> void setValueToVO(IContext ctx, T vo) { - //TODO 直接基于反射实现,后续用动态直接码优化性能 - Class<?> clazz = vo.getClass(); - String parent = ""; - if (clazz.isAnnotationPresent(RelPath.class)) { - RelPath relpath = clazz.getAnnotation(RelPath.class); - parent = relpath.value(); - } - setValueToVO(ctx.getRoot(), vo, parent); - } - - public static void setValueToVoByClass(IModule root, Object vo, Class clazz, String parent) { - if (!clazz.getSuperclass().getName().equalsIgnoreCase("java.lang.Object")) { - //父类定义先赋值,子类覆盖父类的设定 - setValueToVoByClass(root, vo, clazz.getSuperclass(), parent); - } - IModule pntobj = root; //父模型缓存, - String lastPntPath = null; - for (Field fieldVo : clazz.getDeclaredFields()) { - if (!fieldVo.isAnnotationPresent(RelPath.class)) - continue; - RelPath relAno = fieldVo.getAnnotation(RelPath.class); - if (relAno.dir() == DirType.IN) // 输入项,不填 - continue; - String subpath = relAno.value(); // 子路径 - String path = parent.length() == 0 ? subpath : parent + "." + subpath; //得到路径 - - if (relAno.recursion()) //递归取值 - { - IBaseObject obj = getBaseObject(root, path, false); - if (obj == null || !(obj instanceof IModule)) - continue; - try { - fieldVo.setAccessible(true); - Object subVo = fieldVo.get(vo); - setValueToVO((IModule) obj, subVo, path); - } catch (Exception e) { - } - continue; - } - int idx = path.lastIndexOf('.'); - Field fieldModule = null; - if (idx < 0) { - fieldModule = getParentField(root, path); - pntobj = root; - lastPntPath = null; - } else { - String templastPntPath = path.substring(0, idx); - if (!templastPntPath.equals(lastPntPath)) { - - IBaseObject obj = getBaseObject(root, templastPntPath, false); //不使用get方法获取 - if (obj == null || !(obj instanceof IModule)) // 找不到父模型,或者父模型不是IModule类型的 - continue; - else { - pntobj = (IModule) obj; - } - } else { - //基于上次的查找找父模型 - IBaseObject obj = null; - if (idx < lastPntPath.length()) - obj = pntobj;//即它自己 - else - obj = getBaseObject(pntobj, path.substring(lastPntPath.length(), idx), false); //不使用get方法获取 - if (obj == null || !(obj instanceof IModule)) // 找不到父模型,或者父模型不是IModule类型的 - continue; - else { - pntobj = (IModule) obj; - } - } - fieldModule = getParentField(pntobj, path.substring(idx + 1)); - lastPntPath = templastPntPath; - } - setFieldValue(fieldModule, pntobj, fieldVo, vo, false); - } - } - - public static void setValueToVO(IModule root, Object vo, String parent) { - setValueToVoByClass(root, vo, vo.getClass(), parent); - } - - public static <T> Map<String, T> translateMapByVoAnotation(String transKey, boolean pathToAlias, Map<String, T> map) { - Map<String, T> trnsMap = new HashMap<String, T>(); - for (Map.Entry<String, T> entry : map.entrySet()) { - String key = entry.getKey(); - T obj = entry.getValue(); - String newKey = null; - if (pathToAlias) - newKey = getPathAlias(transKey, key); - else - newKey = getAliasPath(transKey, key); - if (newKey == null) - continue; - trnsMap.put(newKey, obj); - } - return trnsMap; - } - - public static String getPathAlias(String trnnam, String path) { - NamesMapper.Alias alias = NamesMapper.getAlias(trnnam); - Map<String, String> pathAlias = alias.getPathAliasMap(); - String aliasName = pathAlias.get(path); - if (aliasName != null) - return aliasName; - for (Map.Entry<String, String> entry : pathAlias.entrySet()) { - if (!path.startsWith(entry.getKey())) - continue; - aliasName = entry.getValue() + "." + path.substring(entry.getKey().length()); - return aliasName; - } - return null; - } - - public static String getAliasPath(String trnnam, String aliasName) { - NamesMapper.Alias alias = NamesMapper.getAlias(trnnam); - Map<String, String> aliasPath = alias.getRevertMap(); - String path = aliasPath.get(aliasName); - if (path != null) - return path; - for (Map.Entry<String, String> entry : aliasPath.entrySet()) { - if (!aliasName.startsWith(entry.getKey())) - continue; - path = entry.getValue() + "." + aliasName.substring(entry.getKey().length()); - return path; - } - return null; - } - - public static void createVoSetterAndGetter(Set<Class<?>> clsSet) { - for (Class<?> clazz : clsSet) { - processTransAnotion(clazz); - - } - } - - /** - * 根据交易上的注解,生成别名与长路径的映射 - * - * @param trnCls 交易class - */ - private static void processTransAnotion(Class<?> trnCls) { - Transaction trnAno = trnCls.getAnnotation(Transaction.class); - Class<?> voCls = trnAno.vo(); - if (EmptyVO.class.equals(voCls)) - return; - String modpntpth = null; - if (voCls.isAnnotationPresent(RelPath.class)) { - modpntpth = voCls.getAnnotation(RelPath.class).value(); - } - String trnname = getTransName(trnCls); - NamesMapper.genTransAlias(trnname); //生成一个别名映射 - processTransAnotion(trnCls, voCls, modpntpth, null); - } - - private static void processTransAnotion(Class<?> trnCls, Class<?> voCls, String modPath, String voPath) { - String trnname = getTransName(trnCls); - NamesMapper.Alias alias = NamesMapper.getAlias(trnname); - for (Field fieldVo : voCls.getDeclaredFields()) { - if (!fieldVo.isAnnotationPresent(RelPath.class)) { - continue; - } - RelPath relAno = voCls.getAnnotation(RelPath.class); - String voFieldPath = voPath == null ? fieldVo.getName() : voPath + "." + fieldVo.getName(); - String modFieldPath = modPath == null ? relAno.value() : modPath + ( - relAno.value() == null || relAno.value().length() == 0 ? "" : "." + relAno.value() - ); - if (!isFieldPathExist(trnCls, modFieldPath)) - continue; - if (relAno.recursion()) //递归遍历 - { - processTransAnotion(trnCls, fieldVo.getType(), modFieldPath, voFieldPath); - continue; - } - if (fieldVo.getType().isAssignableFrom(IModule.class)) //模型直接被引用 - { - - //continue; - } - //加入名称映射 - alias.getPathAliasMap().put(modFieldPath, voFieldPath); - alias.getRevertMap().put(voFieldPath, modFieldPath); - } - } - - private static boolean isFieldPathExist(Class<?> trnCls, String path) { - return false; - } - - private static String getTransName(Class<?> trnCls) { - Transaction trnAno = trnCls.getAnnotation(Transaction.class); - if (trnAno.value() != null && trnAno.value().length() != 0) - return trnAno.value(); - return trnCls.getSimpleName(); - } - - public static String firstUpper(String s) { - if (s.length() == 1) - return s.toUpperCase(); - return s.substring(0, 1).toUpperCase() + s.substring(1); - } - - public static Map<String, String> getErrorMap(IContext ctx, Class voClazz) { - Map<String, String> errorsMap = new LinkedHashMap<String, String>(); - IRuleEmitter ruleEmitter = ctx.getEmitter(); - - while (!voClazz.getName().equalsIgnoreCase("java.lang.Object") - && !ctx.getFieldErrors().isEmpty()) { - for (Field fieldVo : voClazz.getDeclaredFields()) { - if (!fieldVo.isAnnotationPresent(RelPath.class)) - continue; - RelPath relAno = fieldVo.getAnnotation(RelPath.class); - String key = relAno.value(); - key = ruleEmitter.getRealPath(key); //取得真实key - //使用remove,这样子类的设置优先 - String errorMessage = ctx.getFieldErrors().remove(key); - if (errorMessage != null) - errorsMap.put(key, errorMessage); - } - voClazz = voClazz.getSuperclass(); - } - return errorsMap; - } -} - diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/MdaEnv.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/MdaEnv.java deleted file mode 100644 index b43d8c7..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/MdaEnv.java +++ /dev/null @@ -1,242 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver; - -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.impl.AbstractDaoSession; -import com.brilliance.mda.runtime.mda.impl.EnvConfig; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; - -import java.math.BigDecimal; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - -public class MdaEnv { - - private static String encoding = "UTF-8"; - public static String LANG = "CN"; - private static Locale locale = Locale.SIMPLIFIED_CHINESE; - - private static Map<String, Map<String, List<Object>>> sessionContext = new ConcurrentHashMap<>(); - - // public static ApplicationContext appContext = null; - public static ConfigurableListableBeanFactory beanFactory = null; - private static ThreadLocal<IContext> tl = new ThreadLocal<IContext>(); - private static ThreadLocal<IAuthInfo> tl_infos = new ThreadLocal<IAuthInfo>(); - private static ThreadLocal<Map<String, Object>> tl_gridEtyData = new ThreadLocal<>(); - private static ThreadLocal<String> moduleListCheckErrorItem = new ThreadLocal<>(); - - public static <T> T getBean(String beanId, Class<T> clazz) { - return beanFactory.getBean(beanId, clazz); - } - - public static <T> T getBean(Class<T> clazz) { - return beanFactory.getBean(clazz); - } - - public static Object getBean(String beanId) { - Object bean = null; - try { - bean = beanFactory.getBean(beanId); - } catch (Exception e) { - } - - return bean; - - } - - - public static void setContext(IContext ctx) { - //取消设置默认语言,因由TD决定 - //ctx.storeData("LANG",LANG); - tl.set(ctx); - } - - public static IContext getContext() { - return tl.get(); - } - - public static void rmContext() { - tl.remove(); - AbstractDaoSession daoSession = beanFactory.getBean(AbstractDaoSession.class); - if (daoSession != null && daoSession.isOpenTrans()) { - //防止有未关闭的事务 - daoSession.dbRollback(); - } - } - - public static void clearContext() { - rmContext(); - tl_infos.remove(); - } - - public static void clear(Object object) { - if (object == null) - return; - if ((object instanceof IBaseObject)) { - ((IBaseObject) object).clear(); - } else if ((object instanceof Collection)) { - ((Collection) object).clear(); - } else if ((object instanceof Map)) { - ((Map) object).clear(); - } - } - - @SuppressWarnings("rawtypes") - public static boolean isEmpty(Object obj) { - if (obj == null) - return true; - if (obj instanceof String) - return ((String) obj).length() == 0 || ((String) obj).equals(" "); - if (obj instanceof BigDecimal) - return ((BigDecimal) obj).doubleValue() == 0.0D; - if ((obj instanceof Number)) { - return ((Number) obj).doubleValue() == 0.0D; - } - if ((obj instanceof Collection)) { - return ((Collection) obj).isEmpty(); - } - if ((obj instanceof Map)) { - return ((Map) obj).isEmpty(); - } - if (obj instanceof IModule) { - return isEmpty(MdaDriver.getDatafield((IModule) obj, "inr")); - } - if (obj instanceof IDatafield) - return isEmpty(((IDatafield) obj).getValue()); - return false; - } - - public static void setAuthInfo(IAuthInfo authInfo) { - tl_infos.set(authInfo); - } - - public static IAuthInfo getAuthInfo() { - return tl_infos.get(); - } - - public static String getLoginUser() { - //结合具体环境,从tl_infos中获取 - return tl_infos.get().getUserId(); - } - - public static String getEncoding() { - return encoding; - } - - public static void setEncoding(String encoding) { - MdaEnv.encoding = encoding; - } - - public static String getLang() { - String lang = (String) getContext().restoreData("LANG"); - return lang; - } - - public static <T> T getSessionContextValue(String key) { - String uid = MdaEnv.getAuthInfo().getUserId(); - if (!sessionContext.containsKey(uid)) { - return null; - } - if (!sessionContext.get(uid).containsKey(key)) { - MdaEnv.getContext().setErrorCode(111); - return null; - } - return (T) sessionContext.get(uid).get(key).get(0); - } - - public static void setSessionContext(String key, Object... obj) { - if (key == null) return; - String uid = MdaEnv.getAuthInfo().getUserId(); - if (!sessionContext.containsKey(uid)) { - sessionContext.put(uid, new ConcurrentHashMap<String, List<Object>>()); - } - sessionContext.get(uid).put(key, Arrays.asList(obj)); - } - - /** - * 该方法需在用户登录时先调用一次,保证把之前的缓存清除 - * - * @param uid - */ - public static void clearSessionContext(String uid) { - if (sessionContext.containsKey(uid)) { - sessionContext.get(uid).clear(); - } - } - - public static String getRootPath() { - return getBean(EnvConfig.class).getRootPath(); - } - - public static void removeAuthInfo() { - tl_infos.remove(); - } - - private static ThreadLocal<Map<String, Object>> attrs = new ThreadLocal<>(); - - public static void removeAttrs() { - attrs.remove(); - } - - public static void setAttribute(String key, Object obj) { - if (attrs.get() == null) { - attrs.set(new HashMap<String, Object>()); - } - attrs.get().put(key, obj); - } - - public static Object getAttribute(String key) { - if (key == null) return null; - return attrs.get().get(key); - } - - public static String getSessionId() { - String sessionId = (String) attrs.get().get("sessionId"); - if (sessionId != null) { - return sessionId; - } - return ""; - } - - public static void setGridData(String title, String columns, IStream vals) { - Map<String, Object> data = new HashMap<>(); - data.put("title", title); - data.put("columns", columns); - data.put("vals", vals); - tl_gridEtyData.set(data); - } - - public static Map<String, Object> getGridData() { - return tl_gridEtyData.get(); - } - - public static void removeGridData() { - tl_gridEtyData.remove(); - } - - public static Locale getLocale() { - if (locale == null) - locale = Locale.SIMPLIFIED_CHINESE; - return locale; - } - - public static void setLocale(Locale temp_locale) { - locale = temp_locale; - } - - public static String getModuleListCheckErrorItem() { - return moduleListCheckErrorItem.get(); - } - - /** - * ModuleList 执行checkAll时,记录 module 的 path + index,方便前端页面显示错误信息 - * - * @param prefix - */ - public static void setModuleListCheckItem(String prefix) { - moduleListCheckErrorItem.set(prefix); - } - - public static void removeModuleListCheckErrorItem() { - moduleListCheckErrorItem.remove(); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/EmitterFactory.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/EmitterFactory.java deleted file mode 100644 index b82fccc..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/EmitterFactory.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver.compile; - -import com.brilliance.mda.runtime.annotation.Module; -import com.brilliance.mda.runtime.annotation.Transaction; -import com.brilliance.mda.runtime.mda.driver.MdaScanner; -import com.brilliance.mda.runtime.mda.driver.compile.processor.ModuleAnnotationProcess; -import com.brilliance.mda.runtime.mda.driver.compile.processor.TransAnnotationProcessor; -import com.brilliance.mda.support.td.ModuleInfoManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -@Component -public class EmitterFactory implements InitializingBean { - - private final Logger log = LoggerFactory.getLogger(this.getClass()); - - @Value("${envconfig.emitter.scanPackages:com.ceb.gjjs.mda.manager,com.ceb.gjjs.mda.bo}") - private String scanPackage; - - @Autowired - private MdaScanner scanner; - - public void buildEmitter(String... transPack){ - try { - log.debug("prepare to walk transaction"); - Map<Class<?>, Set<Class<?>>> map = new HashMap<>(); - for (String pack : transPack) { - scanner.doScan(map, pack.trim().replaceAll("\\.", "/"), Module.class, Transaction.class); - } - log.debug("get all modules and transactions"); - Set<Class<?>> moduleSet = map.get(Module.class); - moduleSet.forEach(item -> { - try { - ModuleInfoManager.getModuleInfo(item.getSimpleName()); - ModuleInfoManager.loadModuleInfo(item); - } catch (Exception ignore) { - } - }); - - Set<Class<?>> transSet = map.get(Transaction.class); - transSet.forEach(item->new TransAnnotationProcessor().buildTransEmitter(item,scanner.getBeanDefinitionRegistry())); - ModuleAnnotationProcess.reduceCache(); - TransAnnotationProcessor.getProcessQueue().clear(); - log.debug("walk transaction finished"); - //log.info("注册TableMeta {}个", TableMetaManager.getTableMetaCount()); - log.info("注册ModuleInfo {}个", ModuleInfoManager.getModuleInfoCount()); - log.info("注册Transaction {}个", transSet.size()); - } catch (Exception e) { - log.error("动态Emitter扫描包发生错误", e); - } - } - - @Override - public void afterPropertiesSet() throws Exception { - log.info("动态Emitter扫描包:{}", scanPackage); - String[] scanPackages = scanPackage.split(","); - this.buildEmitter(scanPackages); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/EmitterManager.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/EmitterManager.java deleted file mode 100644 index 2dbb263..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/EmitterManager.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver.compile; - -import com.brilliance.mda.support.td.ModuleInfoManager; -import org.apache.commons.io.Charsets; -import org.apache.commons.io.IOUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.core.io.support.ResourcePatternResolver; - -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class EmitterManager { - - private final static Logger log = LoggerFactory.getLogger(ModuleInfoManager.class); - - private static final ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); - - private static final Map<String, Map<String, String>> initIgnoreMap = new HashMap<>(); - - private static final Map<String, Map<String, String>> defaultIgnoreMap = new HashMap<>(); - - private static final Map<String, Map<String, String>> ruleIgnoreMap = new HashMap<>(); - - private static final Map<String, Map<String, String>> checkIgnoreMap = new HashMap<>(); - - public static void loadEmitterIgnoreInfo(Class<?> aClass) { - try { - String moduleName = aClass.getSimpleName(); - String filename = aClass.getSimpleName() + ".txt"; - Resource[] resources = resourceResolver.getResources("classpath:ignoreRule/" + filename); - // File file = resources[0].getFile(); - InputStream stream2 = resources[0].getInputStream(); - log.info("加载ignoreRule:{}", filename); - List<String> lines = IOUtils.readLines(stream2, Charsets.toCharset(StandardCharsets.UTF_8)); - for (String line : lines) { - String[] fields = line.split("\t"); -// log.info("加载ignoreRule-line:{},fields.length:{}", line, fields.length); - if (fields.length < 2) - continue; - - String target = fields[0].trim(); - String field1 = fields[1].trim(); - String methodExpress = field1; - methodExpress = methodExpress.substring(methodExpress.indexOf("(") + 1); - methodExpress = methodExpress.substring(0, methodExpress.lastIndexOf(")")).trim(); - String[] methodExpresses = methodExpress.split(","); - if (methodExpresses.length < 3) - continue; - - String order = methodExpresses[0].trim(); - String path = methodExpresses[1].trim().replaceAll("\"", ""); - String method = methodExpresses[2].substring(methodExpresses[2].lastIndexOf("::") + 2); - - String expression = String.format("%s#%s#%s#%s", target, path, method, order); - if (field1.startsWith("execCheckItem")) { - log.info("加载ignoreRule.check方法:{}", expression); - Map<String, String> map = checkIgnoreMap.computeIfAbsent(moduleName, k -> new HashMap<>()); - map.put(expression, line); - } else if (field1.startsWith("execRuleItem")) { - Map<String, String> map = ruleIgnoreMap.computeIfAbsent(moduleName, k -> new HashMap<>()); - map.put(expression, line); - } else if (field1.startsWith("execDefaultItem")) { - Map<String, String> map = defaultIgnoreMap.computeIfAbsent(moduleName, k -> new HashMap<>()); - map.put(expression, line); - } else if (field1.startsWith("execInitItem")) { - Map<String, String> map = initIgnoreMap.computeIfAbsent(moduleName, k -> new HashMap<>()); - map.put(expression, line); - } - } - } catch (FileNotFoundException ignore) { - log.warn("[这是提示信息,不影响运行]从resources/ignoreRule下查找文件失败。{}",ignore.getMessage()); - } catch (Exception e) { - log.error("从resources/ignoreRule下查找文件失败", e); - throw new IllegalArgumentException(e.getCause()); - } - } - - public static boolean isIgnoreInitMethod(String moduleName, String methodName) { - Map<String, String> ignoreMap = initIgnoreMap.getOrDefault(moduleName, null); - return ignoreMap != null && ignoreMap.containsKey(methodName); - } - - public static boolean isIgnoreCheckMethod(String moduleName, String methodName) { - Map<String, String> ignoreMap = checkIgnoreMap.getOrDefault(moduleName, null); - return ignoreMap != null && ignoreMap.containsKey(methodName); - } - - public static boolean isIgnoreRuleMethod(String moduleName, String methodName) { - Map<String, String> ignoreMap = ruleIgnoreMap.getOrDefault(moduleName, null); - return ignoreMap != null && ignoreMap.containsKey(methodName); - } - - public static boolean isIgnoreDefaultMethod(String moduleName, String methodName) { - Map<String, String> ignoreMap = defaultIgnoreMap.getOrDefault(moduleName, null); - return ignoreMap != null && ignoreMap.containsKey(methodName); - } - - public static String getMethodNameByRule(String target, String path, String method, int order) { - return String.format("%s#%s#%s#%s", target, path, method, order); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/ModelViewer.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/ModelViewer.java deleted file mode 100644 index 99ab9f3..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/ModelViewer.java +++ /dev/null @@ -1,191 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver.compile; - -import com.brilliance.mda.runtime.annotation.Check; -import com.brilliance.mda.runtime.annotation.Default; -import com.brilliance.mda.runtime.annotation.Init; -import com.brilliance.mda.runtime.annotation.Rule; -import com.brilliance.mda.runtime.mda.FieldHolder; -import com.brilliance.mda.runtime.mda.IModule; -import com.brilliance.mda.runtime.mda.IModuleList; -import com.brilliance.mda.runtime.mda.ModuleHolder; -import com.brilliance.mda.runtime.mda.driver.compile.component.FieldInfo; -import com.brilliance.mda.runtime.mda.driver.compile.component.RuleItem; -import com.brilliance.mda.runtime.mda.driver.compile.processor.ModuleAnnotationProcess; -import com.brilliance.mda.runtime.response.ResponseSet; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; - -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; - -@RestController -@RequestMapping("/model/view") -public class ModelViewer { - - private static Map<String, Object> cache = new ConcurrentHashMap<>(); - - @GetMapping("/{modelClass}") - public Object viewModelData(@PathVariable String modelClass) { - //根据交易名获取数据结构列表 - try { - if (cache.containsKey(modelClass)) { - return ResponseSet.simpleSuccess(cache.get(modelClass)); - } - Class modelClazz = Class.forName(modelClass); - Object classDesc = outModelClazz(modelClazz); - cache.put(modelClass, classDesc); - return ResponseSet.simpleSuccess(classDesc); - } catch (Exception e) { - e.printStackTrace(); - } - return ResponseSet.fail("没有找到对应的模型"); - } - - private Map<String, Object> outModelClazz(Class modelClazz) { - List<FieldInfo> fields = new ArrayList<>(); - Map<String, Object> methods = new LinkedHashMap<>(); - List<Method> skipLocals = new ArrayList<>(); - Arrays.stream(modelClazz.getDeclaredFields()).forEach(field -> { - if (Modifier.isStatic(field.getModifiers())) { - return; - } - FieldInfo fieldInfo = new FieldInfo(); - fieldInfo.setName(field.getName()); - fieldInfo.setTypeName(field.getType().getCanonicalName()); - - if (IModuleList.class.isAssignableFrom(field.getType())) { - fieldInfo.setType(2); - fieldInfo.setTypeName(field.getType().getCanonicalName()); - if (field.getGenericType() instanceof ParameterizedTypeImpl) { - //取出泛型 - String typeName = ((ParameterizedTypeImpl) field.getGenericType()).getActualTypeArguments()[0].getTypeName(); - fieldInfo.setTypeName(typeName); - } - } else if (IModule.class == field.getType()) { - fieldInfo.setType(3); - fieldInfo.setTypeName(field.getType().getCanonicalName()); - } else if (IModule.class.isAssignableFrom(field.getType())) { - fieldInfo.setType(1); - fieldInfo.setTypeName(field.getType().getCanonicalName()); - } else if (ModuleHolder.class.isAssignableFrom(field.getType())) { - fieldInfo.setType(3); - fieldInfo.setTypeName(field.getType().getCanonicalName()); - if (field.getGenericType() instanceof ParameterizedTypeImpl) { - //取出泛型 - String typeName = ((ParameterizedTypeImpl) field.getGenericType()).getActualTypeArguments()[0].getTypeName(); - fieldInfo.setTypeName(typeName); - } - } else if (FieldHolder.class.isAssignableFrom(field.getType())) { - fieldInfo.setType(4); - fieldInfo.setTypeName(field.getType().getCanonicalName()); - if (field.getGenericType() instanceof ParameterizedTypeImpl) { - //取出泛型 - String typeName = ((ParameterizedTypeImpl) field.getGenericType()).getActualTypeArguments()[0].getTypeName(); - fieldInfo.setTypeName(typeName); - } - } else { - fieldInfo.setTypeName(field.getType().getCanonicalName()); - } - fields.add(fieldInfo); - //找到get,set 方法 - Method setter = ModuleAnnotationProcess.getSetterMethod(field); - Method getter = ModuleAnnotationProcess.getGetterMethod(field); - if (setter != null) { - skipLocals.add(setter); - } - if (getter != null) { - skipLocals.add(getter); - } - }); - List<Object> initList = new ArrayList<>(); - List<Object> checkList = new ArrayList<>(); - List<Object> localList = new ArrayList<>(); - List<Object> defaultList = new ArrayList<>(); - List<Object> staticList = new ArrayList<>(); - List<Object> ruleList = new ArrayList<>(); - List<Object> globalList = new ArrayList<>(); - - methods.put("initList", initList); - methods.put("localList", localList); - methods.put("checkList", checkList); - methods.put("defaultList", defaultList); - methods.put("staticList", staticList); - methods.put("ruleList", ruleList); - methods.put("globalList", globalList); - - - Arrays.stream(modelClazz.getDeclaredMethods()).forEach(method -> { - String target = null; - String belongPath = ""; - int order = 0; - //屏蔽特殊方法 - if ((method.getName().equals("setArgument") && method.getParameters().length == 0) || method.getName().startsWith("lambda$")) { - return; - } - if (method.isAnnotationPresent(Rule.class)) { - Rule rule = method.getAnnotation(Rule.class); - target = rule.target(); - order = rule.order(); - String[] multiTarget = rule.value(); - if (multiTarget == null || multiTarget.length == 0) { - multiTarget = new String[]{target}; - } - buildRuleItem(ruleList, RuleItem.RULE, multiTarget, method, order); - } else if (method.isAnnotationPresent(Check.class)) { - Check check = method.getAnnotation(Check.class); - target = check.target(); - order = check.order(); - String[] multiTarget = check.value(); - if (multiTarget == null || multiTarget.length == 0) { - multiTarget = new String[]{target}; - } - buildRuleItem(checkList, RuleItem.CHECK, multiTarget, method, order); - } else if (method.isAnnotationPresent(Default.class)) { - Default defaultAno = method.getAnnotation(Default.class); - target = defaultAno.target(); - order = defaultAno.order(); - String[] multiTarget = defaultAno.value(); - if (multiTarget == null || multiTarget.length == 0) { - multiTarget = new String[]{target}; - } - buildRuleItem(defaultList, RuleItem.DEFAULT, multiTarget, method, order); - } else if (method.isAnnotationPresent(Init.class)) { - Init init = method.getAnnotation(Init.class); - order = init.order(); - buildRuleItem(initList, RuleItem.INIT, new String[0], method, order); - } else if (Modifier.isStatic(method.getModifiers())) { - buildRuleItem(globalList, RuleItem.GLOBAL, new String[0], method, order); - } else if (!skipLocals.contains(method)) { - buildRuleItem(localList, RuleItem.LOCAL, new String[0], method, order); - } - }); - Map<String, Object> descriptions = new LinkedHashMap<>(); - descriptions.put("fields", fields); - descriptions.put("rules", methods); - return descriptions; - } - - private void buildRuleItem(List<Object> seriesRule, String ruleType, String[] multiTarget, Method method, int order) { - RuleItem ruleItem = new RuleItem(); - ruleItem.setRuleType(ruleType); - ruleItem.setOrder(order); - ruleItem.setMethod(method); - ruleItem.setDotPath(Arrays.stream(multiTarget).reduce(new StringJoiner(","), (s, i) -> s.add(i), (a, b) -> a.add(b.toString())).toString()); - seriesRule.add(ruleItem); - } - - @GetMapping("/all") - public Object viewAllTrans() { - //根据交易名获取数据结构列表 - List<String> rs = ModuleAnnotationProcess.cache.entrySet().stream().filter(entry -> { - return entry.getValue().isTrans(); - }).map(entry -> entry.getKey()).collect(Collectors.toList()); - return ResponseSet.simpleSuccess(rs); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/AbstractAutoCompileEmitter.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/AbstractAutoCompileEmitter.java deleted file mode 100644 index 1da2550..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/AbstractAutoCompileEmitter.java +++ /dev/null @@ -1,216 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver.compile.component; - -import com.brilliance.mda.runtime.annotation.Default; -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.driver.DCR; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.brilliance.mda.runtime.mda.driver.compile.processor.ModuleAnnotationProcess; -import com.brilliance.mda.runtime.mda.impl.AbstractRuleEmitter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.lang.reflect.Method; -import java.util.List; -import java.util.Map; - -public abstract class AbstractAutoCompileEmitter extends AbstractRuleEmitter { - private static Logger log = LoggerFactory.getLogger(AbstractAutoCompileEmitter.class); - - - private boolean executeRuleList(String ruleType,String target,int order){ - return executeRuleList(ruleType,target,order,false); - } - - private boolean executeRuleList(String ruleType,String target,int order,boolean verifyHead){ - String moduleName = getModuleName(); - ModuleRuleContext moduleRuleContext = ModuleAnnotationProcess.cache.get(moduleName); - if(moduleRuleContext == null){ - return false; - } - if(target != null){ - target = getRealPath(target); -// if(target.charAt(0) == '.' || target.charAt(0) == '\\') { -// target = target.substring(1); -// } - MdaEnv.getContext().pushEventPath(target); - } - List<RuleItem> ruleItemList = null; - switch (ruleType){ - case RuleItem.INIT:ruleItemList = moduleRuleContext.getInitList();break; - case RuleItem.RULE:ruleItemList = moduleRuleContext.getEventRule().get(target);break; - case RuleItem.CHECK:ruleItemList = moduleRuleContext.getCheckRule().get(target);break; - case RuleItem.DEFAULT:ruleItemList = moduleRuleContext.getDefaultRule().get(target);break; - } - if(ruleItemList == null){ - return false; - } - //开始执行RuleChain - for (int i = 0; i < ruleItemList.size(); i++) { - RuleItem ruleItem = ruleItemList.get(i); - log.debug("executeRule {}.{}.{}{}",MdaEnv.getContext().getTransName(),ruleItem.getDotPath(),ruleItem.getRuleType(),ruleItem.getOrder()); - //校验函数头,当是复合型的rule声明时,需要第一个target为当前target时才会被ExecuteDefaultRule执行 - if(verifyHead && !verifyMethodHead(this,ruleItem,target,ruleType)){ - continue; - } - try { - switch (ruleItem.getRuleType()) { - case RuleItem.INIT: - execInitItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot())); - break; - case RuleItem.CHECK: - execCheckItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot())); - break; - case RuleItem.DEFAULT: - execDefaultItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot())); - break; - case RuleItem.RULE: - execRuleItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, MdaEnv.getContext().getRoot())); - break; - } - } catch (Exception e) { - log.error("execute Rule Exception",e); - throw e; - } finally { - this.printSlowExecutionLog(); - } - } - this.printSlowExecutionLog(); - return true; - } - public static boolean verifyMethodHead(IRuleEmitter emitter,RuleItem ruleItem, String target, String ruleType){ - if(ruleItem.getMethod() instanceof Method && ruleType.equals(RuleItem.DEFAULT)){ - Method method = (Method) ruleItem.getMethod(); - Default defaultAno = method.getAnnotation(Default.class); - if(defaultAno.value()!=null && defaultAno.value().length > 1){ - String firstTarget = defaultAno.value()[0]; - String path = null;; - if(firstTarget.startsWith(".")){ - path = firstTarget; - }else { - path = ruleItem.getDotPath()+"."+ firstTarget; - } - path = emitter.getRealPath(path); - //复合声明,仅与第一个路径相等时,才触发 - if(!target.equals(path)){ - return false; - } - } - } - return true; - } - public boolean invokeRuleList(String ruleType,String target,int order){ - return invokeRuleList(ruleType,target,order,false); - } - public boolean invokeRuleList(String ruleType,String target,int order,boolean verifyHead){ - IContext ctx = MdaEnv.getContext(); - try { - //ctx.pushEventPath(target); - return executeRuleList(ruleType,target,order,verifyHead); - } catch (Exception e) { - if(e.getCause() instanceof RuleExitException) - throw (RuleExitException) e.getCause(); - else if(e instanceof RuleExitException){ - throw (RuleExitException) e; - }else if(e.getCause() instanceof RulePromptException){ - throw (RulePromptException) e.getCause(); - }else if(e instanceof RulePromptException){ - throw (RulePromptException) e; - } - else if(e.getCause() instanceof RuleExecuteException){ - throw (RuleExecuteException) e.getCause(); - }else if(e instanceof RuleExecuteException){ - throw (RuleExecuteException) e; - } - else - throw new RuntimeException(e); - }finally { - if(!RuleItem.INIT.equals(ruleType)) { - ctx.popEventPath(); - } - } - } - - @Override - public boolean executeInit(int order) { - return invokeRuleList(RuleItem.INIT,null,order); - } - //执行Rule - public boolean executeRule(String target, int order) - { - return invokeRuleList(RuleItem.RULE,target,order); - } - //执行Check - public boolean executeCheck( String target, int order) - { - target = getRealPath(target); - String moduleName = getModuleName(); - ModuleRuleContext moduleRuleContext = ModuleAnnotationProcess.cache.get(moduleName); - if(moduleRuleContext == null){ - return true; - } - for(Map.Entry<String,List<RuleItem>> entry:moduleRuleContext.getCheckRule().entrySet()){ - if(!checkPathMatch(entry.getKey(),target)) - continue; - boolean result = invokeRuleList(RuleItem.CHECK,entry.getKey(),order); - if(!result) { - log.warn(String.format("execute @Check[%s,%d] return false", entry.getKey(), order)); - } - } - return true; - } - //执行Default - public boolean executeDefault( String target, int order) { - boolean result; - try { - result = invokeRuleList(RuleItem.DEFAULT,target,order); - }catch (Exception ex) - { - DCR.emptyDefaultQueue(); - throw new RuleExecuteException("Rule执行异常",ex); - }finally { - } - return result; - } - //执行Post 的default,因为它需要验证复合声明的头 - public boolean executePostDefault(String target){ - return invokeRuleList(RuleItem.DEFAULT,target,-1,true); - } - public String getModuleName(){ - return relatedTransaction().getCanonicalName(); - } - - @Override - public Map<String, Integer> getDefaultQueue() { - Map<String,Integer> defaultQueue = super.getDefaultQueue(); - if(defaultQueue.isEmpty()){ - synchronized (defaultQueue){ - if(defaultQueue.isEmpty()){ - String moduleName = getModuleName(); - ModuleRuleContext moduleRuleContext = ModuleAnnotationProcess.cache.get(moduleName); - //设置默认的DefaultQueue,但要排除ModuleList - if(moduleRuleContext != null){ - moduleRuleContext.getDefaultRule().entrySet().forEach(stringListEntry -> { - if(!(stringListEntry.getValue().size() == 1 - && stringListEntry.getValue().get(0).getMethodName().equals("executeDefault"))) { - defaultQueue.put(stringListEntry.getKey(), 0); - } - }); - } - } - } - } - return defaultQueue; - } - @Override - public boolean executeDefaultAll(){ - String moduleName = getModuleName(); - ModuleRuleContext moduleRuleContext = ModuleAnnotationProcess.cache.get(moduleName); - if(moduleRuleContext == null){ - return false; - } - moduleRuleContext.getDefaultRule().entrySet().forEach(stringListEntry -> { - executeRuleList(RuleItem.DEFAULT,stringListEntry.getKey(),-1); - }); - return true; - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/AbstractAutoCompileScopeEmitter.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/AbstractAutoCompileScopeEmitter.java deleted file mode 100644 index 85168e6..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/AbstractAutoCompileScopeEmitter.java +++ /dev/null @@ -1,177 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver.compile.component; - -import com.brilliance.mda.runtime.mda.IContext; -import com.brilliance.mda.runtime.mda.RuleExecuteException; -import com.brilliance.mda.runtime.mda.RuleExitException; -import com.brilliance.mda.runtime.mda.RulePromptException; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.brilliance.mda.runtime.mda.driver.compile.processor.ModuleAnnotationProcess; -import com.brilliance.mda.runtime.mda.impl.AbstractScopeEmitter; - -import java.util.List; -import java.util.Map; - -import static com.brilliance.mda.runtime.mda.driver.compile.component.AbstractAutoCompileEmitter.verifyMethodHead; - -public abstract class AbstractAutoCompileScopeEmitter extends AbstractScopeEmitter { - - private boolean executeRuleList(String ruleType,String target,int order){ - return executeRuleList(ruleType,target,order,false); - } - - private boolean executeRuleList(String ruleType,String target,int order,boolean verifyHead){ - String moduleName = getModuleName(); - ModuleRuleContext moduleRuleContext = ModuleAnnotationProcess.cache.get(moduleName); - if(moduleRuleContext == null){ - return false; - } - if(target != null){ - target = getRealPath(target); - if(target.charAt(0) == '.' || target.charAt(0) == '\\') { - target = target.substring(1); - } - MdaEnv.getContext().pushEventPath(target); - } - List<RuleItem> ruleItemList = null; - switch (ruleType){ - case RuleItem.INIT:ruleItemList = moduleRuleContext.getInitList();break; - case RuleItem.RULE:ruleItemList = moduleRuleContext.getEventRule().get(target);break; - case RuleItem.CHECK:ruleItemList = moduleRuleContext.getCheckRule().get(target);break; - case RuleItem.DEFAULT:ruleItemList = moduleRuleContext.getDefaultRule().get(target);break; - } - if(ruleItemList == null){ - return false; - } - //开始执行RuleChain - for (int i = 0; i < ruleItemList.size(); i++) { - RuleItem ruleItem = ruleItemList.get(i); - //校验函数头,当是复合型的rule声明时,需要第一个target为当前target时才会被ExecuteDefaultRule执行 - if(verifyHead && !verifyMethodHead(this,ruleItem,target,ruleType)){ - continue; - } - try { - switch (ruleItem.getRuleType()) { - case RuleItem.INIT: - execInitItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, this.getContext())); - break; - case RuleItem.CHECK: - execCheckItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, this.getContext())); - break; - case RuleItem.DEFAULT: - execDefaultItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, this.getContext())); - break; - case RuleItem.RULE: - execRuleItem(ruleItem.getOrder(), ruleItem.getDotPath(), new RuleItemExecutor(ruleItem, this, this.getContext())); - break; - } - } catch (Exception e) { - log.error("execute Rule Exception",e); - throw e; - } finally { - this.printSlowExecutionLog(); - } - } - this.printSlowExecutionLog(); - return true; - } - - public boolean invokeRuleList(String ruleType,String target,int order){ - return invokeRuleList(ruleType,target,order,false); - } - - public boolean invokeRuleList(String ruleType,String target,int order,boolean verifyHead){ - IContext ctx = MdaEnv.getContext(); - try { - ctx.pushEventPath(target); - return executeRuleList(ruleType,target,order,verifyHead); - } catch (Exception e) { - if(e.getCause() instanceof RuleExitException) - throw (RuleExitException) e.getCause(); - else if(e.getCause() instanceof RulePromptException){ - throw (RulePromptException) e.getCause(); - }else if(e.getCause() instanceof RuleExecuteException){ - throw (RuleExecuteException) e.getCause(); - } - else - throw new RuntimeException(e); - }finally { - ctx.popEventPath(); - } - } - - @Override - public boolean executeInit(int order) { - return invokeRuleList(RuleItem.INIT,null,order); - } - - public boolean executeRule(String target, int order) - { - return invokeRuleList(RuleItem.RULE,target,order); - } - //执行check - public boolean executeCheck( String target, int order) - { - return invokeRuleList(RuleItem.CHECK,target,order); - } - //执行default - public boolean executeDefault( String target, int order) { - return invokeRuleList(RuleItem.DEFAULT,target,order); - } - //执行Post 的default,因为它需要验证复合声明的头 - public boolean executePostDefault(String target){ - return invokeRuleList(RuleItem.DEFAULT,target,-1,true); - } - - public String getModuleName(){ - return relatedTransaction().getCanonicalName(); - } - - @Override - public Map<String, Integer> getDefaultQueue() { - Map<String,Integer> defaultQueue = super.getDefaultQueue(); - if(defaultQueue.isEmpty()){ - synchronized (defaultQueue){ - if(defaultQueue.isEmpty()){ - String moduleName = getModuleName(); - ModuleRuleContext moduleRuleContext = ModuleAnnotationProcess.cache.get(moduleName); - //设置默认的DefaultQueue,但要排除ModuleList - if(moduleRuleContext != null){ - moduleRuleContext.getDefaultRule().entrySet().forEach(stringListEntry -> { - if(!(stringListEntry.getValue().size() == 1 - && stringListEntry.getValue().get(0).getMethodName().equals("executeDefault"))) { - defaultQueue.put(stringListEntry.getKey(), 0); - } - }); - } - } - } - } - return defaultQueue; - } - - @Override - public boolean executeDefaultAll(){ - String moduleName = getModuleName(); - ModuleRuleContext moduleRuleContext = ModuleAnnotationProcess.cache.get(moduleName); - if(moduleRuleContext == null){ - return false; - } - moduleRuleContext.getDefaultRule().entrySet().forEach(stringListEntry -> { - executeRuleList(RuleItem.DEFAULT,stringListEntry.getKey(),-1); - }); - return true; - } - - @Override - public boolean executeCheckAll() { - String moduleName = getModuleName(); - ModuleRuleContext moduleRuleContext = ModuleAnnotationProcess.cache.get(moduleName); - if(moduleRuleContext == null){ - return false; - } - moduleRuleContext.getCheckRule().entrySet().forEach(stringListEntry -> { - executeRuleList(RuleItem.CHECK,stringListEntry.getKey(),-1); - }); - return true; - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/DefaultAutoCompileEmitter.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/DefaultAutoCompileEmitter.java deleted file mode 100644 index 643aa50..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/DefaultAutoCompileEmitter.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver.compile.component; - -import com.brilliance.mda.runtime.mda.IModule; -import com.brilliance.mda.runtime.mda.IModuleList; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.brilliance.mda.runtime.mda.driver.compile.processor.ModuleAnnotationProcess; -import lombok.AllArgsConstructor; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -@AllArgsConstructor -public class DefaultAutoCompileEmitter extends AbstractAutoCompileEmitter{ - - private Class transClass; - - - @Override - public Class<?> relatedTransaction() { - return transClass; - } - - public IModule getRoot(){ - return MdaEnv.getContext().getRoot(); - } - - @Override - public List<IModuleList> getAllModuleList() { - String moduleName = getModuleName(); - ModuleRuleContext moduleRuleContext = ModuleAnnotationProcess.cache.get(moduleName); - if(moduleRuleContext == null) - return new ArrayList<>(); - return moduleRuleContext.getModuleList().stream().map(item->{ - return MdaDriver.getModuleList(this.getRoot(),item); - }).collect(Collectors.toList()); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/DefaultAutoCompileScopeEmitter.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/DefaultAutoCompileScopeEmitter.java deleted file mode 100644 index 0b088cc..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/DefaultAutoCompileScopeEmitter.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver.compile.component; - -import com.brilliance.mda.runtime.mda.IModule; -import com.brilliance.mda.runtime.mda.IModuleList; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; -import com.brilliance.mda.runtime.mda.driver.compile.processor.ModuleAnnotationProcess; -import lombok.AllArgsConstructor; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -@AllArgsConstructor -public class DefaultAutoCompileScopeEmitter extends AbstractAutoCompileScopeEmitter{ - - private Class transClass; - - @Override - public Class<?> relatedTransaction() { - return transClass; - } - - public IModule getRoot(){ - return this.getContext(); - } - - @Override - public List<IModuleList> getAllModuleList() { - String moduleName = getModuleName(); - ModuleRuleContext moduleRuleContext = ModuleAnnotationProcess.cache.get(moduleName); - if(moduleRuleContext == null) - return new ArrayList<>(); - return moduleRuleContext.getModuleList().stream().map(item->{ - return MdaDriver.getModuleList(this.getRoot(),item); - }).collect(Collectors.toList()); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/RuleItemExecutor.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/RuleItemExecutor.java deleted file mode 100644 index d92271c..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/RuleItemExecutor.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver.compile.component; - -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; -import com.brilliance.mda.runtime.mda.util.MdaUtils; -import lombok.AllArgsConstructor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -@AllArgsConstructor -public class RuleItemExecutor implements Ruleable<Boolean> { - private static Logger log = LoggerFactory.getLogger(RuleItemExecutor.class); - - private RuleItem ruleItem; - private IRuleEmitter ruleEmitter; - private IModule root; - - public Boolean exec(){ - - IModule module = (IModule) MdaDriver.getBaseObject(root,ruleItem.getDotPath()); - Object rs = null; - if(module instanceof IModuleList && "executeDefault".equals(ruleItem.getMethodName())){ - ((IModuleList)module).executeDefault(); - return true; - }else if(module instanceof IModuleList && "executeInit".equals(ruleItem.getMethodName())){ - ((IModuleList)module).executeInit(); - return true; - } - else if(ruleItem.getMethod() instanceof Method){ - try { - boolean invoke = (boolean) (((Method) ruleItem.getMethod()).invoke(module)); - return invoke; - }catch (RulePromptException e) { - return true; - }catch(IllegalAccessException e){ - - }catch (InvocationTargetException e){ - if(e.getCause() instanceof RuntimeException){ - throw (RuntimeException)e.getCause(); - } - } - return false; - } - else { - rs = MdaUtils.invoke(module, ruleItem.getMethodName()); - } - if(rs == null ){ - return false; - } - return (Boolean)rs; - } - - public RuleItem getRuleItem() { - return ruleItem; - } - - public IRuleEmitter getRuleEmitter() { - return ruleEmitter; - } - - public IModule getRoot() { - return root; - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/RuleableCompile.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/RuleableCompile.java deleted file mode 100644 index 635b33d..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/RuleableCompile.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver.compile.component; - - -import com.brilliance.mda.runtime.mda.IModule; -import com.brilliance.mda.runtime.mda.Ruleable; - -public abstract class RuleableCompile implements Ruleable<Boolean> { - - public RuleableCompile(){ - - } - - @Override - public Boolean exec() { - return false; - } - - public abstract Boolean exec(IModule root); -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/processor/ModuleAnnotationProcess.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/processor/ModuleAnnotationProcess.java deleted file mode 100644 index b83a8a0..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/processor/ModuleAnnotationProcess.java +++ /dev/null @@ -1,359 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver.compile.processor; - -import com.brilliance.mda.runtime.annotation.Check; -import com.brilliance.mda.runtime.annotation.Default; -import com.brilliance.mda.runtime.annotation.Init; -import com.brilliance.mda.runtime.annotation.Rule; -import com.brilliance.mda.runtime.mda.FieldHolder; -import com.brilliance.mda.runtime.mda.IModule; -import com.brilliance.mda.runtime.mda.IModuleList; -import com.brilliance.mda.runtime.mda.ModuleHolder; -import com.brilliance.mda.runtime.mda.driver.compile.component.ModuleRuleContext; -import com.brilliance.mda.runtime.mda.driver.compile.component.RuleItem; -import com.brilliance.mda.runtime.mda.impl.Argument; -import lombok.Data; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.*; - -@Data -public class ModuleAnnotationProcess { - private static Logger logger = LoggerFactory.getLogger(ModuleAnnotationProcess.class); - - public static Map<String, ModuleRuleContext> cache = new HashMap<>(); - - private ModuleRuleContext moduleRuleContext; - private Class<? extends IModule> moduleClass; - private IModule instatnce; - - public ModuleAnnotationProcess() { - - } - - public ModuleAnnotationProcess(IModule instance) { - makeInstance(instance); - } - - /** - * 编译完成后,将cache清理下,节约内存 - */ - public static void reduceCache() { - Map<String, ModuleRuleContext> cacheClone = new HashMap<>(); - cache.entrySet().forEach(entry -> { - ModuleRuleContext moduleRuleContext = entry.getValue(); - if (moduleRuleContext.isUseEmitter()) { - if (moduleRuleContext.getMergedContext() != null) { - moduleRuleContext.setEventRule(moduleRuleContext.getMergedContext().getEventRule()); - moduleRuleContext.setDefaultRule(moduleRuleContext.getMergedContext().getDefaultRule()); - moduleRuleContext.setCheckRule(moduleRuleContext.getMergedContext().getCheckRule()); - moduleRuleContext.setInitList(moduleRuleContext.getMergedContext().getInitList()); - moduleRuleContext.setMergedContext(null); - } - cacheClone.put(entry.getKey(), moduleRuleContext); - } - }); - cache = cacheClone; - } - - /** - * 设置模型实例 - * - * @param instance - */ - public void makeInstance(IModule instance, boolean useEmitter) { - moduleClass = instance.getClass(); - this.instatnce = instance; - moduleRuleContext = new ModuleRuleContext(moduleClass.getCanonicalName(), useEmitter); - } - - public void makeInstance(IModule instance) { - makeInstance(instance, false); - } - - public void dealModule() { - - } - - public void walkModule() { - Arrays.stream(moduleClass.getDeclaredFields()).forEach(this::dealField); - int initSize = this.moduleRuleContext.getInitList().size(); - Arrays.stream(moduleClass.getMethods()).forEach(this::dealMethod); - this.moduleRuleContext.getInitList().subList(initSize, this.moduleRuleContext.getInitList().size()).sort(Comparator.comparingInt(RuleItem::getOrder)); - cache.put(getCacheKey(moduleClass), this.moduleRuleContext); - } - - /** - * 将带有模型Rule注解的方法纳入库中 - * - * @param method - */ - private void dealMethod(Method method) { - //私有方法不生效 - String target = null; - String belongPath = ""; - int order = 0; - if (method.isAnnotationPresent(Rule.class)) { - Rule rule = method.getAnnotation(Rule.class); - target = rule.target(); - order = rule.order(); - String[] multiTarget = rule.value(); - if (multiTarget == null || multiTarget.length == 0) { - multiTarget = new String[]{target}; - } - method.setAccessible(true); - putItemToMap(moduleRuleContext.getEventRule(), RuleItem.RULE, multiTarget, belongPath, method, order); - } else if (method.isAnnotationPresent(Check.class)) { - Check check = method.getAnnotation(Check.class); - target = check.target(); - order = check.order(); - String[] multiTarget = check.value(); - if (multiTarget == null || multiTarget.length == 0) { - multiTarget = new String[]{target}; - } - method.setAccessible(true); - putItemToMap(moduleRuleContext.getCheckRule(), RuleItem.CHECK, multiTarget, belongPath, method, order); - } else if (method.isAnnotationPresent(Default.class)) { - Default defaultAno = method.getAnnotation(Default.class); - target = defaultAno.target(); - order = defaultAno.order(); - String[] multiTarget = defaultAno.value(); - if (multiTarget == null || multiTarget.length == 0) { - multiTarget = new String[]{target}; - } - method.setAccessible(true); - putItemToMap(moduleRuleContext.getDefaultRule(), RuleItem.DEFAULT, multiTarget, belongPath, method, order); - } else if (method.isAnnotationPresent(Init.class)) { - Init init = method.getAnnotation(Init.class); - order = init.order(); - method.setAccessible(true); - putItemInitToList(moduleRuleContext.getInitList(), belongPath, method, order); - } else if (Modifier.isStatic(method.getModifiers())) { - //收集全局方法 - moduleRuleContext.putGlobalMethod(method); - } - } - - /** - * 对字段为模型的,进行递归收集 - * - * @param field 当前字段 - */ - private void dealField(Field field) { - if (IModuleList.class.isAssignableFrom(field.getType())) { - //要记录所属泛型 - moduleRuleContext.getModuleList().add(field.getName()); - //需要注册Emitter - ModuleRuleContext moduleListRuleContext = deepWalkChildField(field); - if (moduleListRuleContext != null && moduleListRuleContext.getInitList().size() > 0) { - putModuleListInitToList(moduleRuleContext.getInitList(), field.getName(), "executeInit", 1000); - } - if (moduleListRuleContext != null && moduleListRuleContext.getDefaultRule().size() > 0) { - putItemToMap(moduleRuleContext.getDefaultRule(), RuleItem.DEFAULT, new String[]{field.getName()}, field.getName(), "executeDefault", 1000); - } - //ModuleList 只合并全局方法,不合并static rule - this.moduleRuleContext.getGlobalMethod().putAll(moduleListRuleContext.getGlobalMethod()); - } else if (IModule.class.isAssignableFrom(field.getType())) { - deepWalkChildField(field); - } else if (ModuleHolder.class.isAssignableFrom(field.getType())) { - - } else if (FieldHolder.class.isAssignableFrom(field.getType())) { - //可能要关联真实路径 - } - } - - /** - * 获取字段的真实名称 - * - * @param field - * @param getterHolder - * @return - */ - private String getFieldName(Field field, Argument<Method> getterHolder) { - String fieldName = field.getName(); - Method getter = getGetterMethod(field); - if (getterHolder != null) { - getterHolder.value = getter; - } - if (getter != null) { - return fieldName; - } - //特殊处理 - if (IModule.class.isAssignableFrom(field.getType()) && fieldName.startsWith("tmp") && fieldName.length() > 3) { - fieldName = fieldName.substring(3); - String getterName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); - try { - getter = field.getDeclaringClass().getMethod(getterName); - IModule module = (IModule) getter.invoke(instatnce); - field.setAccessible(true); - IModule fieldModule = (IModule) field.get(instatnce); - if (module == fieldModule) { -// return module.getName(); - return field.getName(); - } - if (getterHolder != null) { - getterHolder.value = getter; - } - } catch (Exception e) { - logger.error("exception:{}", e); - } - } - return fieldName; - } - - private ModuleRuleContext deepWalkChildField(Field field) { - String cacheKey = getCacheKey(field.getType()); - ModuleRuleContext oneModuleCache = cache.get(cacheKey); - if (oneModuleCache != null) { - //映射一下缓存 - if (!IModuleList.class.isAssignableFrom(field.getType())) { - this.moduleRuleContext.mergeChild(getFieldName(field, null), oneModuleCache); - } else { - - } - return null; - } - //遍历当前子模型 - Argument<Method> methodBox = Argument.box(null); - String fieldName = getFieldName(field, methodBox); - Method getter = methodBox.value; - if (getter != null) { - try { - //深入一层 - IModule subIns = (IModule) getter.invoke(instatnce); - //映射当前module至指定实例路径 - //如果是ModuleList,则需要为其模型构建Emitter - if (subIns instanceof IModuleList) { - IModuleList moduleList = (IModuleList) subIns; - cacheKey = moduleList.getDataClass().getCanonicalName(); - oneModuleCache = cache.get(cacheKey); - if (oneModuleCache == null) { - ModuleAnnotationProcess subProc = new ModuleAnnotationProcess((IModule) moduleList.getDataClass().newInstance()); - subProc.walkModule(); - //cache.put(cacheKey, subProc.moduleRuleContext); - oneModuleCache = subProc.moduleRuleContext; - } - if (oneModuleCache.isUseEmitter() || oneModuleCache.isRuleEmpty()) { - return oneModuleCache; //该ModuleList 已经建立过emitter,或者Rule都是空的,则退出 - } else { - oneModuleCache.setUseEmitter(true); - ModuleListAnnotationProcessor moduleListAnnotationProcessor = new ModuleListAnnotationProcessor(); - moduleListAnnotationProcessor.buildModuleListEmitter(moduleList.getDataClass(), oneModuleCache); - } - return oneModuleCache; - } else { - ModuleAnnotationProcess subProc = new ModuleAnnotationProcess(subIns); - subProc.walkModule(); - //cache.put(cacheKey, subProc.moduleRuleContext); - //合并子模块 - this.moduleRuleContext.mergeChild(fieldName, subProc.moduleRuleContext); - return subProc.moduleRuleContext; - } - } catch (Exception e) { - logger.error("深度遍历模型发生异常:{}", e); - } finally { - } - } - return null; - } - - protected String getCacheKey(Class moduleClass) { - return moduleClass.getCanonicalName(); - } - - /** - * 获取字段的get方法 - */ - public static Method getGetterMethod(Field field) { - String fieldName = field.getName(); - String methodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); - try { - Method method = field.getDeclaringClass().getMethod(methodName); - if (method.getParameters().length == 0) - return method; - } catch (Exception e) { - //找不到get方法就算了,不打异常了 - } - return null; - } - - /** - * 获取字段的set方法 - */ - public static Method getSetterMethod(Field field) { - String fieldName = field.getName(); - String methodName = "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); - try { - Method method = field.getDeclaringClass().getMethod(methodName, field.getType()); - //if(method.getParameters().length == 1) - return method; - } catch (Exception e) { - //找不到set方法就算了,不打异常了 - } - return null; - } - - /** - * 内部调用,叫RuleItem加入到 - * - * @param container - * @param ruleType - * @param targets - * @param belongPath - * @param method String or Method - * @param order - */ - private void putItemToMap(Map container, String ruleType, String[] targets, String belongPath, Object method, int order) { - for (String target : targets) { - RuleItem ruleItem = new RuleItem(); - ruleItem.setRuleType(ruleType); - ruleItem.initGetPath(belongPath); - ruleItem.setEntirePath(target); - ruleItem.setMethod(method); - ruleItem.setOrder(order); - List<RuleItem> ruleItemList = (List<RuleItem>) container.get(target); - if (ruleItemList == null) { - ruleItemList = new ArrayList(); - container.put(target, ruleItemList); - - } - //ruleItem.getBelongClass().push(moduleClass.getCanonicalName()); - ruleItemList.add(ruleItem); - } - } - - private void putItemInitToList(List ruleList, String belongPath, Method method, int order) { - RuleItem ruleItem = new RuleItem(); - String ruleType = RuleItem.INIT; - ruleItem.setRuleType(ruleType); - ruleItem.initGetPath(belongPath); - ruleItem.setMethod(method); - ruleItem.setOrder(order); - //ruleItem.getBelongClass().push(moduleClass.getCanonicalName()); - ruleList.add(ruleItem); - } - - private void putModuleListInitToList(List ruleList, String belongPath, String methodName, int order) { - RuleItem ruleItem = new RuleItem(); - String ruleType = RuleItem.INIT; - ruleItem.setRuleType(ruleType); - ruleItem.initGetPath(belongPath); - ruleItem.setMethod(methodName); - ruleItem.setOrder(order); - ///ruleItem.getBelongClass().push(ModuleList.class.getCanonicalName()); - //ruleItem.getBelongClass().push(moduleClass.getCanonicalName()); - - ruleList.add(ruleItem); - } - - //将收集的static rule合并 - private void putItemToStaticMap(Map<String, RuleItem> staticMap, String belongPath, Method method) { - RuleItem ruleItem = new RuleItem(); - ruleItem.initGetPath(belongPath); - ruleItem.setMethod(method); - staticMap.put(ModuleRuleContext.getMethodKey(method), ruleItem); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/processor/ModuleListAnnotationProcessor.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/processor/ModuleListAnnotationProcessor.java deleted file mode 100644 index 6e16ae8..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/processor/ModuleListAnnotationProcessor.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver.compile.processor; - -import com.brilliance.mda.runtime.mda.IModule; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.brilliance.mda.runtime.mda.driver.MdaScanner; -import com.brilliance.mda.runtime.mda.driver.compile.component.AbstractAutoCompileScopeEmitter; -import com.brilliance.mda.runtime.mda.driver.compile.component.ModuleRuleContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ModuleListAnnotationProcessor extends TransAnnotationProcessor { - private final Logger log = LoggerFactory.getLogger(this.getClass()); - - public ModuleListAnnotationProcessor(){ - super(false); - } - public void buildModuleListEmitter(Class moduleClass, ModuleRuleContext moduleRuleContext){ - try { - //初始化上下文 - init(moduleClass); - this.setBeanDefinitionRegistry(MdaEnv.getBean(MdaScanner.class).getBeanDefinitionRegistry()); - IModule rootIns = (IModule) moduleClass.newInstance(); - this.makeInstance(rootIns,true); - //设置为支持使用emitter了 - moduleRuleContext.setUseEmitter(true); - //设置RuleContext - this.setModuleRuleContext(moduleRuleContext); - //注册Emitter - registerEmitterToBeanFactory(); - //合并上下文 - this.mergeTransRules(); - //rule 排序 - this.getModuleRuleContext().sortRule(); - this.pushToProcessQueue(); - }catch (Exception e){ - e.printStackTrace(); - } - } - - public void mergeTransRules(){ - //scopeEmitter需要设置上下文 - AbstractAutoCompileScopeEmitter abstractAutoCompileScopeEmitter = (AbstractAutoCompileScopeEmitter) MdaEnv.getBean(this.getEmitterKey()); - abstractAutoCompileScopeEmitter.acceptContext(this.getInstatnce()); - super.mergeTransRules(); - abstractAutoCompileScopeEmitter.removeContext(); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/processor/TransAnnotationProcessor.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/processor/TransAnnotationProcessor.java deleted file mode 100644 index 1d2e8e6..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/processor/TransAnnotationProcessor.java +++ /dev/null @@ -1,160 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver.compile.processor; - -import com.brilliance.mda.runtime.annotation.Transaction; -import com.brilliance.mda.runtime.mda.IContext; -import com.brilliance.mda.runtime.mda.IModule; -import com.brilliance.mda.runtime.mda.driver.MdaContext; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.brilliance.mda.runtime.mda.driver.compile.EmitterManager; -import com.brilliance.mda.runtime.mda.driver.compile.component.DefaultAutoCompileEmitter; -import com.brilliance.mda.runtime.mda.driver.compile.component.DefaultAutoCompileScopeEmitter; -import com.brilliance.mda.runtime.mda.driver.compile.component.ModuleRuleContext; -import com.brilliance.mda.runtime.mda.driver.compile.component.RuleItem; -import com.brilliance.mda.runtime.mda.impl.AbstractRuleEmitter; -import lombok.Data; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; - -import java.util.*; - -@Data -public class TransAnnotationProcessor extends ModuleAnnotationProcess { - - private final Logger log = LoggerFactory.getLogger(this.getClass()); - - private static List<TransAnnotationProcessor> transAnnotationProcessorsQueue = new LinkedList<>(); - - private String transName; - private String transNameUpper; - private Class<?> rootClazz; - private BeanDefinitionRegistry beanDefinitionRegistry; - private IModule rootIns; - private boolean isTrans; - public String getEmitterKey(){ - return "emitter2."+ this.transName; - } - - public TransAnnotationProcessor(){ - isTrans = true; - } - - public TransAnnotationProcessor(boolean isTrans){ - this.isTrans = isTrans; - } - - - protected void init(Class<?> rootClass){ - rootClazz = rootClass; - String transName = rootClass.getSimpleName().toLowerCase(); - if(rootClass.isAnnotationPresent(Transaction.class)){ - Transaction trnAno = rootClass.getAnnotation(Transaction.class); - if(trnAno.value()!=null && !trnAno.value().isEmpty()){ - transName = trnAno.value(); - } - } - this.transName = transName; - this.transNameUpper = transName.substring(0,1).toUpperCase()+transName.substring(1); - } - public void buildTransEmitter(Class<?> rootClass, BeanDefinitionRegistry beanDefinitionRegistry) { - try { - //初始化上下文 - init(rootClass); - this.beanDefinitionRegistry = beanDefinitionRegistry; - IModule rootIns = (IModule) rootClass.newInstance(); - IContext ctx = new MdaContext(rootIns); - this.makeInstance(rootIns,true); - //变量模型 - walkModule(); - //注册Emitter - registerEmitterToBeanFactory(); - //合并Rule Path - mergeTransRules(); - this.getModuleRuleContext().sortRule(); - pushToProcessQueue(); - - EmitterManager.loadEmitterIgnoreInfo(rootClass); - }catch (Exception e){ - log.error("遍历模型发生异常:{}",e); - } - } - public void registerEmitterToBeanFactory() { - if(isTrans) { - this.getModuleRuleContext().setTrans(true); - registerBean(this.getEmitterKey(),DefaultAutoCompileEmitter.class); - } - else{ - this.getModuleRuleContext().setTrans(false); - registerBean(this.getEmitterKey(),DefaultAutoCompileScopeEmitter.class); - } - - } - - /** - 注册bean - **/ - private void registerBean( String name, Class<?> beanClass) { - BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(beanClass); - beanDefinitionBuilder.addConstructorArgValue(rootClazz); - BeanDefinition beanDefinition = beanDefinitionBuilder.getRawBeanDefinition(); - beanDefinitionRegistry.registerBeanDefinition(name, beanDefinition); - } - - /** - * 合并当前所有rule的路径 - */ - public void mergeTransRules(){ - //利用Emitter开启rule合并 - AbstractRuleEmitter abstractRuleEmitter = (AbstractRuleEmitter)MdaEnv.getBean(this.getEmitterKey()); - //添加Rule系列函数 - Map<String,List<RuleItem>> eventRuleMap = mergeMapRuleItem(abstractRuleEmitter,this.getModuleRuleContext().getEventRule()); - Map<String,List<RuleItem>> checkRuleMap = mergeMapRuleItem(abstractRuleEmitter,this.getModuleRuleContext().getCheckRule()); - Map<String,List<RuleItem>> defaultRuleMap = mergeMapRuleItem(abstractRuleEmitter,this.getModuleRuleContext().getDefaultRule()); - - if(isTrans) { - //交易下的rule做下合并和排序 - this.getModuleRuleContext().setEventRule(eventRuleMap); - this.getModuleRuleContext().setCheckRule(checkRuleMap); - this.getModuleRuleContext().setDefaultRule(defaultRuleMap); - this.getModuleRuleContext().sortRule(); - }else{ - //支持ModuleList的Module,为其创建一个副本,因为后续交易编译还要使用。 - this.getModuleRuleContext().setUseEmitter(true); - this.getModuleRuleContext().setMergedContext(new ModuleRuleContext(this.getModuleRuleContext().getModuleName(),false)); - this.getModuleRuleContext().getMergedContext().setEventRule(eventRuleMap); - this.getModuleRuleContext().getMergedContext().setCheckRule(checkRuleMap); - this.getModuleRuleContext().getMergedContext().setDefaultRule(defaultRuleMap); - this.getModuleRuleContext().getMergedContext().setInitList(this.getModuleRuleContext().getInitList()); - this.getModuleRuleContext().getMergedContext().sortRule(); - } - } - - /** - * 合并rule map,并返回一个副本 - */ - private Map<String,List<RuleItem>> mergeMapRuleItem(AbstractRuleEmitter abstractRuleEmitter, Map<String,List<RuleItem>> ruleMap){ - Map<String,List<RuleItem>> nRuleMap = new LinkedHashMap<>(); - for(Map.Entry<String,List<RuleItem>> entry: ruleMap.entrySet()){ - String target = entry.getKey(); - List<RuleItem> ruleItemList = entry.getValue(); - target = abstractRuleEmitter.getRealPath(target); - List<RuleItem> nRuleItemList = nRuleMap.get(target); - if(nRuleItemList == null){ - nRuleItemList = new ArrayList<>(); - nRuleMap.put(target,nRuleItemList); - } - nRuleItemList.addAll(ruleItemList); - } - return nRuleMap; - } - - public void pushToProcessQueue(){ - transAnnotationProcessorsQueue.add(this); - } - - public static List<TransAnnotationProcessor> getProcessQueue(){ - return transAnnotationProcessorsQueue; - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractBaseObject.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractBaseObject.java deleted file mode 100644 index f080516..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractBaseObject.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.util.RuleUtils; -import org.apache.poi.poifs.macros.Module; - -import java.util.ArrayList; -import java.util.List; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/15 - */ -public abstract class AbstractBaseObject implements IBaseObject { - protected transient List<IRule> defaultRules = null; - - protected transient IParent parent; - - protected transient long key = -1L; - - protected transient String name; - - protected transient String url; - - protected transient boolean sorted = false; - - protected transient boolean disposed = false; - - public AbstractBaseObject(IParent parent) { - this.parent = parent; - } - - public synchronized void dispose() { - if (this.disposed) - return; - if (this.defaultRules != null) - this.defaultRules.clear(); - this.defaultRules = null; - this.parent = null; - this.name = null; - this.url = null; - this.disposed = true; - try { - finalize(); - } catch (Throwable throwable) {} - } - - public boolean isDisposed() { - return this.disposed; - } - - public abstract void clear(); - - public long getIdAttributeKey() { - return this.key; - } - - public void setIdAttributeKey(long key) { - this.key = key; - } - - public Object setAttribute(String name, Object attribute) { - if (this instanceof IParent) - return ((IParent)this).setAttribute(this, name, attribute); - return this.parent.setAttribute(this, name, attribute); - } - - public Object getAttribute(String name) { - if (this instanceof IParent) - return ((IParent)this).getAttribute(this, name); - if (this.parent == null) - System.out.println(getUrl()); - return this.parent.getAttribute(this, name); - } - - public IModule getParent() { - return (IModule)this.parent; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public String getUrl() { - return this.url; - } - - public void setUrl(String url) { - this.url = url; - } - - public void addDefaultRule(IRule rule) { - if (this.defaultRules == null) - this.defaultRules = new ArrayList<IRule>(); - this.defaultRules.add(rule); - } - - protected void sort() { - this.sorted = true; - RuleUtils.sort(this.defaultRules); - } - - public boolean invokeDefaultRules(IContext ctx) { - if (!this.sorted) - sort(); - return RuleUtils.invoke(this.defaultRules, ctx, null); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractDaoSession.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractDaoSession.java deleted file mode 100644 index d610498..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractDaoSession.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import org.springframework.jdbc.datasource.DataSourceTransactionManager; -import org.springframework.transaction.TransactionDefinition; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.support.DefaultTransactionDefinition; - -public abstract class AbstractDaoSession { - private DataSourceTransactionManager transactionManager; - private ThreadLocal<TransactionStatus> status = new ThreadLocal<TransactionStatus>(); - - public AbstractDaoSession() { - - } - - private DataSourceTransactionManager getTransactionManager() { - if (transactionManager == null) - transactionManager = MdaEnv.getBean(DataSourceTransactionManager.class); - return transactionManager; - } - - public void dbBegin() { - if(isOpenTrans()) //事务为提交,回滚 - this.dbRollback(); - DefaultTransactionDefinition def = new DefaultTransactionDefinition(); - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); - status.set(getTransactionManager().getTransaction(def)); - } - - public void dbCommit() { - if(isOpenTrans()) - { - getTransactionManager().commit(status.get()); - status.remove(); - } - } - - public void dbRollback() { - if(isOpenTrans()) - { - getTransactionManager().rollback(status.get()); - status.remove(); - } - new RuntimeException("业务处理错误,手动rollback"); - } - - public boolean isOpenTrans() { - return status.get() != null; - //return false; - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractModule.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractModule.java deleted file mode 100644 index 96d7eb3..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractModule.java +++ /dev/null @@ -1,225 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.annotation.Module; -import com.brilliance.mda.runtime.mda.IBaseObject; -import com.brilliance.mda.runtime.mda.IDatafield; -import com.brilliance.mda.runtime.mda.IModule; -import com.brilliance.mda.runtime.mda.IModuleRoot; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; -import com.brilliance.mda.runtime.mda.util.MdaUtils; -import com.fasterxml.jackson.annotation.JsonFilter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.util.StringUtils; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.*; - -@JsonFilter("fieldFilter") -@Module -public abstract class AbstractModule implements IModule, IModuleRoot { - - protected Logger logger = LoggerFactory.getLogger(this.getClass().getName()); - - private String _path; - - private String _name; - - private IModule _parent; - - private boolean _entityflg; - - private String serialNum; - - private Map<String, Object> attrMaps = new HashMap<>(); - - public AbstractModule() { - } - - public AbstractModule(String name, IModule parent) { - this._name = name; - this._parent = parent; - String prefix = parent.getPath(); - if (prefix == null || prefix.length() == 0) - this._path = this._name; - else - this._path = prefix + "." + this._name; - this._entityflg = false; - } - - public AbstractModule(String name, IModule parent, boolean isEntity) { - this(name, parent); - this._entityflg = true; - } - - public String getFieldPath(String fieldName) { - try { - IBaseObject baseObj = MdaDriver.getBaseObject(this, fieldName); - if (baseObj == null) - return ""; - return baseObj.getPath(); -// Field field = this.getClass().getDeclaredField(fieldName); -// if(field.getType() == DatafieldImpl.class) //是引用模式的 -// { -// return ((DatafieldImpl)field.get(this)).getPath(); -// } - } catch (Exception e) { - e.printStackTrace(); - } - return ""; -// if(null==this._path || this._path.length() ==0 ) -// return fieldName; -// return this._path +"."+ fieldName; - } - - @JsonIgnore - public String getPath() { - if (this._parent != null && this._parent instanceof ModuleList) { - int idx = ((ModuleList) this._parent).indexOf(this); - String path = this._parent.getPath() + "(" + (idx + 1) + ")"; - return path; - } - - String _name = this._name; - if (_name == null) { - return separator; - } - - IModule _this = this._parent; - StringBuilder sb = new StringBuilder(_name); - while (!(_this.getParent() instanceof ModuleList) && _this.getParent() != null) { - sb.insert(0, _this.getName() + separator); - _this = _this.getParent(); - } - if (_this.getParent() == null) { - return this._path == null ? separator : this._path.toUpperCase(); - } else { - return _this.getPath() + separator + sb.toString().toUpperCase(); - } - } - - @JsonIgnore - public String getName() { - return _name; - } - - @JsonIgnore - public IModule getParent() { - return _parent; - } - - @JsonIgnore - public boolean isEntity() { - return this._entityflg; - } - - @Override - public String getSerialNum() { - return serialNum; - } - - public void setSerialNum(String serialNum) { - this.serialNum = serialNum; - } - - @Override - public void copyValue(IModule src) { - MdaDriver.copyValues(this, src); - } - - @Override - public void copyValues(IModule src) { - MdaDriver.copyValues(this, src); - } - - public void clear() { - MdaDriver.clearModule(this); - } - - /** - * 废弃的方法,不要再使用了 - * - * @return - */ - @Deprecated - @Override - @JsonIgnore - public Collection<IDatafield> getDatafields() { - List<IDatafield> list = new ArrayList<>(); - Field[] fs = this.getClass().getDeclaredFields(); - for (int i = 0; i < fs.length; i++) { - Field field = fs[i]; - if (field.getName().charAt(0) == '_') { - continue; - } - if (field.getType() == DatafieldImpl.class) { - try { - list.add((IDatafield) field.get(this)); - } catch (IllegalAccessException e) { - logger.warn("get field exception", e); - } - } - list.add(new DatafieldImpl(this._parent, field)); - } - return new ArrayList<>(); - } - - /** - * 基于反射实现,尽量不用 - * - * @return 当前模型下所有的子模型,包括ModuleList - */ - @JsonIgnore - public List<IModule> getModules() { - Class clazz = this.getClass(); - ArrayList<IModule> moduleList = new ArrayList<>(); - try { - for (Field field : clazz.getDeclaredFields()) { - String name = field.getName(); //获取 - String getterName = "get" + MdaDriver.firstUpper(name); - try { - Method m = clazz.getMethod(getterName); - if (IModule.class.isAssignableFrom(m.getReturnType())) { - moduleList.add((IModule) m.invoke(this)); - } - } catch (Exception e) { - - } - - } - } catch (Exception e) { - - } - return moduleList; - } - - /** - * todo - * - * @param key - * @return - */ - public IBaseObject get(String key) { - return null; - } - - @Override - public void assignSerialNum() { - if (StringUtils.isEmpty(this.serialNum)) { - this.setSerialNum(MdaUtils.generateSerialNum()); - } - } - - @Override - public Map<String, Object> getAttrMaps() { - return attrMaps; - } - - public void setAttrMaps(Map<String, Object> attrMaps) { - this.attrMaps = attrMaps; - } - - -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractRuleEmitter.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractRuleEmitter.java deleted file mode 100644 index 2da6c62..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractRuleEmitter.java +++ /dev/null @@ -1,492 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.annotation.Check; -import com.brilliance.mda.runtime.annotation.Default; -import com.brilliance.mda.runtime.annotation.Rule; -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.driver.DCR; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.brilliance.mda.runtime.mda.driver.compile.EmitterManager; -import com.brilliance.mda.runtime.mda.driver.compile.component.RuleItemExecutor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.util.StopWatch; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - -public abstract class AbstractRuleEmitter implements IRuleEmitter { - protected Logger log = LoggerFactory.getLogger(this.getClass()); - - private static final long SLOW_EXECUTION_TIME = 100; - protected Map<String, String> eqMap = new ConcurrentHashMap<>(); - protected Map<String, String> argMap = new HashMap<>(); - protected static ThreadLocal<List<String>> slowExecutionListThreadLocal = new ThreadLocal<>(); - private Map<String, Method> ruleMethodMap = new LinkedHashMap<>(); - private Map<String, Method> checkMethodMap = new LinkedHashMap<>(); - private Map<String, Method> defaultMethodMap = new LinkedHashMap<>(); - - private Map<String, Integer> defaultQueue = new LinkedHashMap<>(); - - public void scanMethod() { - Method[] methods = this.getClass().getMethods(); - for (Method m : methods) { - Rule rule = m.getAnnotation(Rule.class); - if (rule != null) { - m.setAccessible(true); - ruleMethodMap.put(rule.target(), m); - } - Check check = m.getAnnotation(Check.class); - if (check != null) { - m.setAccessible(true); - checkMethodMap.put(check.target(), m); - } - Default defaultRule = m.getAnnotation(Default.class); - if (defaultRule != null) { - m.setAccessible(true); - defaultMethodMap.put(defaultRule.target(), m); - } - } - defaultMethodMap.forEach((path, method) -> { - if (!method.getName().startsWith("defaultList")) { - method.setAccessible(true); - defaultQueue.put(path, 0); - } - }); - } - - /** - * 提供子类此map,用于子类计算和获取 - * - * @return - */ - public Map<String, Integer> getDefaultQueue() { - return this.defaultQueue; - } - - public Map<String, Object> getDefaultRuleQue() { - //根据default依赖关系进行依赖排序。 - Map<String, Object> queue = new LinkedHashMap<>(); - queue.putAll(this.getDefaultQueue()); - //收集moduleList里面的交易 - getAllModuleList().forEach(moduleList -> { - IRuleEmitter ruleEmitter = DCR.getModuleListEmitter(moduleList.getDataClass()); - if (ruleEmitter == null) { - return; - } - Map<String, Object> subQueue = new LinkedHashMap<>(); - for (int i = 1; i <= moduleList.size(); i++) { - Map<String, Object> subSubQueueTemp = ruleEmitter.getDefaultRuleQue(); - Map<String, Object> subSubQueue = new LinkedHashMap<>(); - subSubQueue.putAll(subSubQueueTemp); - subQueue.put(String.valueOf(i), subSubQueue); - } - - String moduleListPath = moduleList.getPath().toLowerCase().substring(1).replaceAll("\\\\", "\\."); - queue.put(moduleListPath, subQueue); - }); - return queue; - } - - public void executeDefaultRuleQue() { - Stack<String> keyStack = new Stack<>(); - long begMillis = System.currentTimeMillis(); - Map<String, Object> queue = getDefaultRuleQue(); - log.debug("#####获取默认Queue耗时{}", System.currentTimeMillis() - begMillis); - begMillis = System.currentTimeMillis(); - DCR.executeMergedQueue(getRoot(), this, queue, queue, keyStack); - //Default rule执行中会产生修改,导致重新修改,因此继续执行default - long begMillis2 = System.currentTimeMillis(); - log.debug("#####完整Default执行耗时{}", begMillis2 - begMillis); - if (!(this instanceof AbstractScopeEmitter)) { - DCR.executeQueue(true, this, 0); - log.debug("#####补充执行耗时{}", System.currentTimeMillis() - begMillis2); - } - } - - - protected boolean checkPathMatch(String path, String target) { - int targetLen = target.length(); - return targetLen == 0 || - (path.startsWith(target) && (path.length() == targetLen || path.charAt(targetLen) == '.')); - } - - public String getRealPath(String path) { - if (path == null) return ""; - String realPath = eqMap.get(path); - if (realPath != null) - return realPath; - //计算path - IBaseObject baseObject = MdaDriver.getBaseObject(MdaEnv.getContext().getRoot(), path); - if (baseObject != null) { - //如果得到的是ModuleList,但是其后续路径还有,这种情况应该要 - realPath = baseObject.getPath(); - } else { - int lastIndex = path.lastIndexOf('.'); - if (lastIndex > 0) { - //取父级模型,因为按钮在实际中不存在 - baseObject = MdaDriver.getBaseObject(MdaEnv.getContext().getRoot(), path.substring(0, lastIndex)); - if (baseObject != null && baseObject instanceof IModule) { - realPath = ((IModule) baseObject).getFieldPath(path.substring(lastIndex + 1)); - if (realPath == null || realPath.length() == 0) { - realPath = baseObject.getPath() + "." + path.substring(lastIndex + 1); - } - } - } else { - realPath = path; - } - } - if (realPath == null) - return path; - realPath = realPath.toLowerCase().replaceAll("\\\\", "."); - if (realPath.charAt(0) == '.') - realPath = realPath.substring(1); - eqMap.put(path, realPath); - return realPath; - } - - //计算真实路径 - private String calcAbsolutePath(String path) { - out: - while (true) { - for (Map.Entry<String, String> entry : argMap.entrySet()) { - String apath = entry.getKey(); //原始路径 - if (path.startsWith(apath) && - (path.length() == apath.length() || path.charAt(apath.length()) == '.')) { - path = entry.getValue() + path.substring(apath.length()); //替换了一次, - continue out; //重新校验替换 - } - } - //替换完毕 - return path; - } - } - - public boolean executeRule(String target, int order) { - target = getRealPath(target); - if (target.charAt(0) == '.' || target.charAt(0) == '\\') - target = target.substring(1); - Method m = this.ruleMethodMap.get(target); - if (m != null) { - return invokeMethod(m, target, order); - } - return false; - } - - public boolean executeDefault(String target, int order) { - target = getRealPath(target); - Method m = this.defaultMethodMap.get(target); - if (m != null) { - boolean isDcrEnable = DCR.isEnable(); -// if(isDcrEnable) -// DCR.enNotify(false); - boolean result; - try { - result = invokeMethod(m, target, order); - } catch (Exception ex) { - DCR.emptyDefaultQueue(); - throw new RuleExecuteException("Rule执行异常", ex); - } finally { - //DCR.enNotify(isDcrEnable); - } - return result; - } - return false; - } - - public boolean executeDefaultAfterInit() { - //为了保证准确性,根据TD规律,重复运行3次 - for (int i = 0; i < 1; i++) { - executeDefaultRuleQue(); - } - return true; - } - - public boolean executeDefaultAll() { - for (Map.Entry<String, Method> entry : this.defaultMethodMap.entrySet()) { - invokeMethod(entry.getValue(), entry.getKey(), -1); - } - return true; - } - - // 目前只执行moduleList下模型的check - public boolean executeCheckAll() { - for (IModuleList moduleList : this.getAllModuleList()) { - moduleList.executeCheckAll(); - } - MdaEnv.removeModuleListCheckErrorItem(); - return true; - } - - - public boolean executeCheck(String target, int order) { - target = getRealPath(target); - for (Map.Entry<String, Method> entry : checkMethodMap.entrySet()) { - if (!checkPathMatch(entry.getKey(), target)) - continue; - boolean result = invokeMethod(entry.getValue(), entry.getKey(), order); - if (!result) - log.warn(String.format("execute @Check[%s,%d] return false", entry.getKey(), order)); - } - return true; - } - - private boolean invokeMethod(Method m, String target, int order) { - IContext ctx = MdaEnv.getContext(); - try { - ctx.pushEventPath(target); - boolean result = (Boolean) m.invoke(this, order); - return result; - } catch (IllegalAccessException e) { - log.error("invoke method error", e); - } catch (InvocationTargetException e) { - if (e.getCause() instanceof RuleExitException) - throw (RuleExitException) e.getCause(); - else if (e.getCause() instanceof RulePromptException) { - throw (RulePromptException) e.getCause(); - } else if (e.getCause() instanceof RuleExecuteException) { - throw (RuleExecuteException) e.getCause(); - } else - throw new RuntimeException(e); - } finally { - ctx.popEventPath(); - } - return false; - } - - @Override - public boolean executeRule(String target) { - try { - return executeRule(target, -1); - } catch (RuleExitException e) { - return false; - } catch (RulePromptException e) { - return true; - } catch (RuleExecuteException e) { - throw e; - } catch (Exception ex) { - DCR.emptyDefaultQueue(); - throw new RuleExecuteException("Rule执行异常", ex); - } -// finally { -// AbstractDaoSession daoSession = MdaEnv.getBean(AbstractDaoSession.class); -// if(daoSession.isOpenTrans()) -// { -// log.warn("存在未提交的事务,回滚"); -// daoSession.dbRollback(); -// } -// } - } - - @Override - public boolean executeCheck(String target) { - try { - return executeCheck(target, -1); - } catch (RuleExitException e) { - return false; - } catch (Exception ex) { - DCR.emptyDefaultQueue(); - throw new RuleExecuteException("Check执行异常", ex); - } -// finally { -// AbstractDaoSession daoSession = MdaEnv.getBean(AbstractDaoSession.class); -// if(daoSession.isOpenTrans()) -// { -// log.warn("存在未提交的事务,回滚"); -// daoSession.dbRollback(); -// } -// } - } - - @Override - public boolean executeDefault(String target) { - try { - return executeDefault(target, -1); - } catch (RuleExitException e) { - return false; - } catch (Exception ex) { - DCR.emptyDefaultQueue(); - throw new RuleExecuteException("Default执行异常", ex); - } - } - - @Override - public boolean executeInit() { - try { - Boolean result = executeInit(-1); - return result; - } catch (RuleExitException e) { - e.printStackTrace(); - return false; - } catch (Exception ex) { - DCR.emptyDefaultQueue(); - List<String> rows = MdaEnv.getAuthInfo().getSysStream().getRows(); - if (rows.contains("SPT")) { - Iterator<String> iterator = rows.iterator(); - boolean flag = false; - while (iterator.hasNext()) { - String next = iterator.next(); - if (flag) { - iterator.remove(); - break; - } - if (next.equals("SPT")) { - iterator.remove(); - flag = true; - } - } - } - throw new RuleExecuteException("Init执行异常", ex); - } - } - - public void execInitItem(int order, String path, Ruleable<Boolean> ruleHolder) { - boolean ignore = false; - if (ruleHolder instanceof RuleItemExecutor) { - RuleItemExecutor executor = (RuleItemExecutor) ruleHolder; - IModule root = executor.getRoot(); - String methodName = executor.getRuleItem().getMethodName(); - ignore = EmitterManager.isIgnoreInitMethod(root.getClass().getSimpleName(), EmitterManager.getMethodNameByRule("INIT", path, methodName, order)); - } - if (ignore) { - log.debug("{} ignore init [{}] [{}] ", MdaEnv.getContext().getTransName(), order, path); - } else { - StopWatch stopWatch = new StopWatch("execInitItem"); - stopWatch.start(); - //log.debug("{} init [{}] [{}] ", MdaEnv.getContext().getTransName(),order,path); - MdaEnv.getContext().setConcurrentCallStack(path); - MdaEnv.getContext().setErrorCode(Constants.NO_ERROR); - if (!ruleHolder.exec()) { - stopWatch.stop(); - addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execInitItem", path, order); - throw new RuleExitException(String.format("%s init %d %s exit", MdaEnv.getContext().getTransName(), order, path)); - } - stopWatch.stop(); - addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execInitItem", path, order); - } - } - - public void execRuleItem(int order, String path, Ruleable<Boolean> ruleHolder) { - boolean ignore = false; - String eventPath = MdaEnv.getContext().getEventPath(); - if (ruleHolder instanceof RuleItemExecutor) { - RuleItemExecutor executor = (RuleItemExecutor) ruleHolder; - IModule root = executor.getRoot(); - String methodName = executor.getRuleItem().getMethodName(); - ignore = EmitterManager.isIgnoreRuleMethod(root.getClass().getSimpleName(), EmitterManager.getMethodNameByRule(eventPath, path, methodName, order)); - } - if (ignore) { - log.debug("{} ignore rule [{}] [{}] ", MdaEnv.getContext().getTransName(), order, path); - } else { - StopWatch stopWatch = new StopWatch("execRuleItem"); - stopWatch.start(); - //log.debug("{} rule [{}] [{}]",MdaEnv.getContext().getTransName(),order,eventPath); - MdaEnv.getContext().setErrorCode(Constants.NO_ERROR); - MdaEnv.getContext().setConcurrentCallStack(path); - int oldLength = MdaEnv.getContext().getFieldErrors().size(); - boolean b = ruleHolder.exec(); - if (!b) { - stopWatch.stop(); - addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execRuleItem", path, order); - throw new RuleExitException(String.format("%s rule %d %s exit", MdaEnv.getContext().getTransName(), order, eventPath)); - } - if (MdaEnv.getContext().getFieldErrors().size() > oldLength) { - log.warn("{} rule [{}] [{}] set fieldError", MdaEnv.getContext().getTransName(), order, eventPath); - } - stopWatch.stop(); - addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execRuleItem", path, order); - } - //log.debug("rule [{}] [{}] finished",order,eventPath); - } - - public void execCheckItem(int order, String path, Ruleable<Boolean> ruleHolder) { - boolean ignore = false; - String eventPath = MdaEnv.getContext().getEventPath(); - if (ruleHolder instanceof RuleItemExecutor) { - RuleItemExecutor executor = (RuleItemExecutor) ruleHolder; - IModule root = executor.getRoot(); - String methodName = executor.getRuleItem().getMethodName(); - ignore = EmitterManager.isIgnoreCheckMethod(root.getClass().getSimpleName(), EmitterManager.getMethodNameByRule(eventPath, path, methodName, order)); - } - if (ignore) { - log.debug("{} ignore check [{}] [{}] ", MdaEnv.getContext().getTransName(), order, path); - } else { - StopWatch stopWatch = new StopWatch("execCheckItem"); - stopWatch.start(); - //log.debug("{} check [{}] [{}]",MdaEnv.getContext().getTransName(),order,eventPath); - MdaEnv.getContext().setConcurrentCallStack(path); - MdaEnv.getContext().setErrorCode(Constants.NO_ERROR); - int oldLength = MdaEnv.getContext().getFieldErrors().size(); - if (!ruleHolder.exec()) { - stopWatch.stop(); - addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execCheckItem", path, order); - throw new RuleExitException(String.format("check [%d] [%s] exit", order, eventPath)); - } - if (MdaEnv.getContext().getFieldErrors().size() > oldLength) { - log.warn(String.format("%s check [%d] [%s] set fieldError", MdaEnv.getContext().getTransName(), order, eventPath)); - } - stopWatch.stop(); - addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execCheckItem", path, order); - //log.debug("check [{}] [{}] finished",order,eventPath); - } - } - - public void execDefaultItem(int order, String path, Ruleable<Boolean> ruleHolder) { - boolean ignore = false; - String eventPath = MdaEnv.getContext().getEventPath(); - if (ruleHolder instanceof RuleItemExecutor) { - RuleItemExecutor executor = (RuleItemExecutor) ruleHolder; - IModule root = executor.getRoot(); - String methodName = executor.getRuleItem().getMethodName(); - ignore = EmitterManager.isIgnoreDefaultMethod(root.getClass().getSimpleName(), EmitterManager.getMethodNameByRule(eventPath, path, methodName, order)); - } - if (ignore) { - log.debug("{} ignore default [{}] [{}] ", MdaEnv.getContext().getTransName(), order, path); - } else { - StopWatch stopWatch = new StopWatch("execDefaultItem"); - stopWatch.start(); - //log.debug("{} default [{}] [{}]",MdaEnv.getContext().getTransName(),order,eventPath); - MdaEnv.getContext().setConcurrentCallStack(path); - MdaEnv.getContext().setErrorCode(Constants.NO_ERROR); - if (!ruleHolder.exec()) { - stopWatch.stop(); - addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execDefaultItem", path, order); - throw new RuleExitException(String.format("%s default [%d] [%s] exit", MdaEnv.getContext().getTransName(), order, eventPath)); - } - stopWatch.stop(); - addSlowExecutionLog(stopWatch.getLastTaskTimeMillis(), "execDefaultItem", path, order); - //log.debug("default [{}] [{}] finished",order,eventPath); - } - } - - public List<IModuleList> getAllModuleList() { - return new ArrayList<>(); - } - - private void addSlowExecutionLog(long executeTime, String executeType, String path, int order) { - if (executeTime >= SLOW_EXECUTION_TIME) { - if (slowExecutionListThreadLocal.get() == null) { - slowExecutionListThreadLocal.set(new ArrayList<>()); - } - slowExecutionListThreadLocal.get().add(String.format("%s %s %s 消耗时间%dms", executeType, path, order, executeTime)); - } - } - - protected void printSlowExecutionLog() { - if (slowExecutionListThreadLocal.get() != null && slowExecutionListThreadLocal.get().size() > 0) { - StringBuilder logBuilder = new StringBuilder(); - logBuilder.append(Constants.CRLF); - logBuilder.append("================================================").append(Constants.CRLF); - logBuilder.append(String.format("执行Rule 超过%dms集合:", SLOW_EXECUTION_TIME)).append(Constants.CRLF); - for (String slowExecutionLog : slowExecutionListThreadLocal.get()) { - logBuilder.append(slowExecutionLog).append(Constants.CRLF); - } - logBuilder.append("================================================"); - log.warn(logBuilder.toString()); - slowExecutionListThreadLocal.remove(); - } - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractScopeEmitter.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractScopeEmitter.java deleted file mode 100644 index b84354b..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractScopeEmitter.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.mda.IBaseObject; -import com.brilliance.mda.runtime.mda.IModule; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; - -import java.util.Stack; - -public abstract class AbstractScopeEmitter extends AbstractRuleEmitter{ - private ThreadLocal<Stack<IModule>> scopeContext = new ThreadLocal<>(); - - public void acceptContext(IModule module){ - Stack<IModule> stack = scopeContext.get(); - if(scopeContext.get() == null){ - stack = new Stack<>(); - scopeContext.set(stack); - } - stack.push(module); - } - public void removeContext(){ - Stack<IModule> stack = scopeContext.get(); - if(stack == null){ - return; - } - stack.pop(); - if(stack.empty()){ - scopeContext.remove(); - } - - } - public IModule getContext(){ - Stack<IModule> stack = scopeContext.get(); - if(stack == null){ - return null; - } - return stack.peek(); - } - - @Override - public String getRealPath(String path) - { - if(path==null) return ""; - String realPath = eqMap.get(path); - if(realPath != null) - return realPath; - //计算path - IBaseObject baseObject = MdaDriver.getBaseObject(getContext(),path); - if(baseObject != null ) - realPath = getModuleListFieldAbsolutePath(getContext(),baseObject); - else - { - int lastIndex = path.lastIndexOf('.'); - if(lastIndex > 0) - { - //取父级模型,因为按钮在实际中不存在 - baseObject = MdaDriver.getBaseObject(getContext(),path.substring(0,lastIndex)); - if(baseObject!=null && baseObject instanceof IModule) - { - realPath = ((IModule)baseObject).getFieldPath(path.substring(lastIndex+1)); - if(realPath == null || realPath.length() ==0) - { - realPath = baseObject.getPath()+"."+path.substring(lastIndex+1); - } - } - }else{ - realPath = path; - eqMap.put(path,realPath); - return realPath; - } - } - if(realPath == null) - return path; - realPath = realPath.toLowerCase().replaceAll("\\\\","."); - if(realPath.charAt(0) == '.') - realPath = realPath.substring(1); - String parentPath = getContext().getPath(); - realPath = realPath.substring(parentPath.length()); - eqMap.put(path,realPath); - return realPath; - } - public String getModuleListFieldAbsolutePath(IModule itemModule, IBaseObject baseObject){ - IModule parent = baseObject.getParent(); - StringBuilder sb = new StringBuilder(baseObject.getName()); - while(parent != itemModule){ - sb.insert(0,parent.getName()+"\\"); - parent = parent.getParent(); - } - - if(parent != null) - sb.insert(0,itemModule.getPath()+"\\"); - return sb.toString(); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractTransaction.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractTransaction.java deleted file mode 100644 index ba499ef..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AbstractTransaction.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - - -public abstract class AbstractTransaction extends AbstractModule { - -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AttributeValue.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AttributeValue.java deleted file mode 100644 index 290c5ab..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/AttributeValue.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.util.RuleUtils; - -import java.util.*; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/11 - */ - -public class AttributeValue<E> extends SimpleValue<E> implements IAttribute, IAttributeValue<E> { - protected transient Map<String, Object> attributes = null; - - protected transient List<IRule> checkRules = null; - - protected transient List<IEventRule> eventRules = null; - - public AttributeValue() { - } - - public AttributeValue(E value) { - super(value); - } - - public AttributeValue(E value, Class clazz) { - super(value, clazz); - } - - public Object setAttribute(String name, Object attribute) { - if (attribute == null) - return (this.attributes == null) ? null : this.attributes.remove(name); - if (this.attributes == null) - this.attributes = new HashMap<String, Object>(); - return this.attributes.put(name, attribute); - } - - public Object getAttribute(String name) { - if (this.attributes == null) - return null; - return this.attributes.get(name); - } - - public Set getAttributeNameSet() { - if (this.attributes == null) - return Collections.EMPTY_SET; - return this.attributes.keySet(); - } - - public void addCheckRule(IRule rule) { - if (this.checkRules == null) - this.checkRules = new ArrayList<IRule>(); - this.checkRules.add(rule); - } - - public void addEventRule(IEventRule rule) { - if (this.eventRules == null) - this.eventRules = new ArrayList<IEventRule>(); - this.eventRules.add(rule); - } - - public boolean invokeEventRules(IContext ctx, EventType type, Object data, int... orders) { - return (this.eventRules == null) ? true : RuleUtils.invoke(this.eventRules, ctx, new Event(this, type, data), orders); - } - - public boolean invokeCheckRules(IContext ctx) { - return (this.checkRules == null) ? true : RuleUtils.invoke(this.checkRules, ctx, this); - } -} - diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/DatafieldImpl.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/DatafieldImpl.java deleted file mode 100644 index 8da9b57..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/DatafieldImpl.java +++ /dev/null @@ -1,138 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.mda.FieldHolder; -import com.brilliance.mda.runtime.mda.IDatafield; -import com.brilliance.mda.runtime.mda.IModule; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -public class DatafieldImpl<T> implements IDatafield<T> { - - private IModule parent; - private String name; - private Field field; - private Method setter; - private Method getter; - private String path; - - public DatafieldImpl(IModule parent, Field field) - { - this.parent = parent; - this.name = field.getName(); - this.field = field; - initField(); - } - public DatafieldImpl(IModule parent, String fieldName) - { - this.parent = parent; - this.name = fieldName; - try{ - this.field = parent.getClass().getDeclaredField(fieldName); - }catch (Exception e) - { - e.printStackTrace(); - } - initField(); - } - - private void initField() - { - field.setAccessible(true); - if(field.getType() == FieldHolder.class) - { - try{ - FieldHolder holder = (FieldHolder) field.get(parent); - this.path = holder.getPath(); - }catch (Exception e) - { - - } - } - else{ - String prefix = parent.getPath(); - if(prefix == null || prefix.length() ==0) - this.path = this.name; - else - this.path = prefix + "." + this.name; - } - try { - String gettStr = "get"+firstUpper(this.name); - this.getter = parent.getClass().getMethod(gettStr); - }catch (Exception e){} - try { - String settStr = "set" + firstUpper(this.name); - if(this.getter!=null) - this.setter = parent.getClass().getMethod(settStr,this.getter.getReturnType()); - else if(this.field != null) - this.setter = parent.getClass().getMethod(settStr,this.field.getType()); - }catch (Exception e){} - - } - public IModule getParent() { - return parent; - } - public String getName() { - return name; - } - @SuppressWarnings("unchecked") - public T getValue() { - try { - if(this.getter != null) - return (T)this.getter.invoke(parent); - } catch (Exception e) - { - - } - return null; - } - public void setValue(T value) { - try { - if(this.setter != null) - setter.invoke(parent,value); - } catch (Exception e) { - e.printStackTrace(); - } - } - @Override - public String getPath() { - return this.path; - } - public void clear(){ - if(this.setter != null) - { - Class<?>[] clazz = this.setter.getParameterTypes(); - if(clazz.length ==1) - { - Object obj = MdaDriver.zero(clazz[0]); - try { - this.setter.invoke(parent,obj); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - } - private String firstUpper(String str) - { - if(str.length()<=1) - return str.toUpperCase(); - return str.substring(0,1).toUpperCase()+str.substring(1); - } - public Class<T> getDataType() - { - return (Class<T>)getter.getReturnType(); - } - - @Override - public void setAttribute(Object k, Object v) { - - } - - @Override - public Object getAttribute(Object k) { - return null; - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/ModuleList.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/ModuleList.java deleted file mode 100644 index e1dadb0..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/ModuleList.java +++ /dev/null @@ -1,300 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.mda.IBaseObject; -import com.brilliance.mda.runtime.mda.IDatafield; -import com.brilliance.mda.runtime.mda.IModule; -import com.brilliance.mda.runtime.mda.IModuleList; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.fasterxml.jackson.annotation.JsonFilter; -import com.fasterxml.jackson.annotation.JsonIgnore; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -@JsonFilter("fieldFilter") -public class ModuleList<T extends IModule> extends ArrayList<T> implements IModuleList<T> { - /** - * - */ - private static final long serialVersionUID = 7746471631508303843L; - - private Map<String, Object> attrMaps = new HashMap<>(); - - private IModule _parent; - private String _name; - private String _path; - private int fullDbSize; - private Class<T> dataClass; - private static Field parentField; - private String moduleType; - - static { - try { - parentField = AbstractModule.class.getDeclaredField("_parent"); - parentField.setAccessible(true); - } catch (Exception e) { - } - } - - public ModuleList() { - } - - public ModuleList(String name, IModule parent, Class<T> dataClass) { - this._parent = parent; - this._name = name; - String prefix = parent.getPath(); - if (prefix == null || prefix.length() == 0 || prefix.equals(separator)) - this._path = separator + this._name; - else - this._path = prefix + separator + this._name; - this.dataClass = dataClass; - this.moduleType = dataClass.getSimpleName().toLowerCase(); - } - - public ModuleList(String name, IModule parent, int initSize, Class<T> dataClass) { - this(name, parent, dataClass); - initData(initSize); - } - - private void initData(int initSize) { - try { - for (int i = 0; i < initSize; i++) { - T module = dataClass.newInstance(); - this.addElement(module); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void clear() { - super.clear(); - this.fullDbSize = -1; - } - - @JsonIgnore - public IModule getParent() { - return _parent; - } - - @JsonIgnore - public String getName() { - return _name; - } - - @JsonIgnore - @Override - public String getPath() { - return this._path.toUpperCase(); - } - - //数据库总体数据量 - @JsonIgnore - public int getFullDbSize() { - return this.fullDbSize; - } - - //获取类型数据 - @JsonIgnore - public Class<T> getDataClass() { - return this.dataClass; - } - - @JsonIgnore - public int fullSize() { - return this.size(); - } - - public void removeAll() { - this.clear(); - } - - /** - * 废弃的方法,不建议使用 - * - * @param args IDatafield Argument 两项参数 - */ - @Override - public T add(Object... args) { - - if (args == null || args.length == 0) return null; - T bean = null; - try { - bean = this.getDataClass().newInstance(); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - - for (Object obj : args) { - if (obj instanceof Argument) { - Argument arg = (Argument) obj; - setFieldValue(arg.getFieldName(), arg.getValue(), bean); - - } else if (obj instanceof IDatafield) { - IDatafield df = (IDatafield) obj; - setFieldValue(df.getName(), df.getValue(), bean); - } - } - this.add(bean); - updateParentField(bean); - return bean; - } - - private void updateParentField(IModule item) { - try { - parentField.set(item, this); - } catch (Exception e) { - } - } - - @Override - public void addElement(T em) { - em.assignSerialNum(); - super.add(em); - updateParentField(em); - } - - @Override - public void addElement(int idx, T em) { - em.assignSerialNum(); - super.add(idx - 1, em); - updateParentField(em); - } - - @JsonIgnore - public T getElement(int idx) { - return super.get(idx--); - } - - private void setFieldValue(String name, Object value, T bean) { - try { - Field f = this.getDataClass().getDeclaredField(name); - f.setAccessible(true); - f.set(bean, value); - } catch (Exception e) { - e.printStackTrace(); - return; - } - } - - public void copyValues(IModuleList list) { - if (list.getDataClass() != this.getDataClass()) - return; - this.clear(); - this.addAll(list); - } - - private AbstractScopeEmitter getEmitter() { - String emitterName = AbstractScopeEmitter.EMITTER_PRE + moduleType; - AbstractScopeEmitter emitter = (AbstractScopeEmitter) MdaEnv.getBean(emitterName); - return emitter; - } - - @Override - public boolean executeInit() { - AbstractScopeEmitter emitter = getEmitter(); - if (emitter == null) { - return true; - } - for (int i = 1; i <= this.size(); i++) { - emitter.acceptContext(this.getElement(i)); - try { - emitter.executeInit(); - } catch (Exception e) { - e.printStackTrace(); - } - } - emitter.removeContext(); - return true; - } - - @Override - public boolean executeInit(int idx) { - AbstractScopeEmitter emitter = getEmitter(); - if (emitter == null) { - return true; - } - emitter.acceptContext(this.getElement(idx)); - emitter.executeInit(); - emitter.removeContext(); - return true; - } - - @Override - public void executeDefault(String... paths) { - AbstractScopeEmitter emitter = getEmitter(); - if (emitter == null) { - return; - } - for (int i = 1; i <= this.size(); i++) { - emitter.acceptContext(this.getElement(i)); - if (paths.length == 0) { - emitter.executeDefaultAll(); - } else { - for (String path : paths) { - emitter.executeDefault(path); - } - } - } - emitter.removeContext(); - } - - @Override - public void executeDefault(int idx, String... paths) { - AbstractScopeEmitter emitter = getEmitter(); - if (emitter == null) { - return; - } - emitter.acceptContext(this.getElement(idx)); - if (paths.length == 0) { - emitter.executeDefaultAfterInit(); - } else { - for (String path : paths) { - emitter.executeDefault(path); - } - } - emitter.removeContext(); - } - - @Override - public void executeCheckAll() { - AbstractScopeEmitter emitter = getEmitter(); - if (emitter == null) { - return; - } - String prefix = this._path; - if (prefix.charAt(0) == '\\') { - prefix = prefix.substring(1); - } - prefix = prefix.replace("\\", ".").toLowerCase(); - for (int i = 1; i <= this.size(); i++) { - emitter.acceptContext(this.getElement(i)); - MdaEnv.setModuleListCheckItem(prefix + "." + (i - 1)); - emitter.executeCheckAll(); - } - emitter.removeContext(); - } - - - @Override - public String getFieldPath(String fieldName) { - return null; - } - - @Override - public IBaseObject get(String paramString) { - return null; - } - - @Override - public Map<String, Object> getAttrMaps() { - return attrMaps; - } - - public void setAttrMaps(Map<String, Object> attrMaps) { - this.attrMaps = attrMaps; - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/PanelImpl.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/PanelImpl.java deleted file mode 100644 index b93a242..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/PanelImpl.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.util.RuleUtils; - -import java.util.ArrayList; -import java.util.List; - -public class PanelImpl extends AbstractBaseObject implements IPanel { - protected final transient List<IEventRule> eventRules = new ArrayList<IEventRule>(); - - protected transient Object window; - - private String titleI18nKey; - - public PanelImpl(IParent parent, String name, String titleI18nKey) { - super(parent); - this.name = name; - this.titleI18nKey = titleI18nKey; - } - - public synchronized void dispose() { - this.eventRules.clear(); - this.window = null; - super.dispose(); - } - - @Override - public String getPath() { - return this.name; - } - - @Override - public void clear() { - } - - @Override - public String getLanguage() { - return null; - } - - public IModule getModule() { - return (IModule) this.parent; - } - - public String getTitleI18nKey() { - return this.titleI18nKey; - } - - public void setWindow(Object window) { - this.window = window; - } - - public Object getWindow() { - return this.window; - } - - public void addEventRule(IEventRule rule) { - this.eventRules.add(rule); - } - - - protected void sort() { - super.sort(); - RuleUtils.sort2(this.eventRules); - } - - public boolean invokeEventRules(IContext ctx, Event event) { - if (!this.sorted) - sort(); - return RuleUtils.invoke(this.eventRules, ctx, event, new int[0]); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/SimpleValue.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/SimpleValue.java deleted file mode 100644 index 5435eba..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/SimpleValue.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.mda.IValue; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/11 - */ -public class SimpleValue<E> implements IValue<E> { - E value; - - Class clazz; - - public SimpleValue() { - this.clazz = Object.class; - } - - public SimpleValue(E value, Class clazz) { - this.value = value; - this.clazz = clazz; - } - - public SimpleValue(Class clazz) { - this(null, clazz); - } - - public SimpleValue(E value) { - this(value, (value == null) ? Object.class : value.getClass()); - } - - public E setValue(E value) { - this.value = value; - return this.value; - } - - public E getValue() { - return this.value; - } - - public Class getDataType() { - return this.clazz; - } - - public int compareTo(IValue<E> o) { - if (o == null) - return 1; - E nValue = (E)o.getValue(); - if (this.value == null || nValue == null) - return (this.value == null) ? -1 : 1; - return this.value.toString().compareTo(nValue.toString()); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/StreamGrid.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/StreamGrid.java deleted file mode 100644 index 9e21b77..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/StreamGrid.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.mda.IAttributeValue; -import com.brilliance.mda.runtime.mda.IDatafield; -import com.brilliance.mda.runtime.mda.IValue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/15 - */ -public class StreamGrid extends ArrayList<IValue[]> { - static IAttributeValue[] EMPTY = new IAttributeValue[0]; - - IAttributeValue[] headers; - - List<IAttributeValue[]> extHeaders; - - int index = -1; - - IDatafield datafield; - - public IAttributeValue[] getHeaders() { - if (this.headers == null) - return EMPTY; - return this.headers; - } - - public void setHeaders(IAttributeValue[] headers) { - this.headers = headers; - } - - public List<IAttributeValue[]> getExtHeaders() { - if (this.extHeaders == null) - return Collections.EMPTY_LIST; - return this.extHeaders; - } - - public void setExtHeaders(List<IAttributeValue[]> extHeaders) { - this.extHeaders = extHeaders; - } - - public int getIndex() { - if (this.index >= size()) - setIndex(-1); - return this.index; - } - - public void setIndex(int index) { - if (index >= size() || index < 0) - index = -1; - this.index = index; - } - - public IDatafield getDatafield() { - return this.datafield; - } - - public void setDatafield(IDatafield datafield) { - this.datafield = datafield; - } - - public void clear() { - this.datafield = null; - this.index = -1; - super.clear(); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/StreamProxy.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/StreamProxy.java deleted file mode 100644 index 7973668..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/impl/StreamProxy.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.mda.IStream; - -import java.io.InputStream; -import java.io.OutputStream; - -/** - * IStream 代理类 - */ -public class StreamProxy extends DataGrid implements IStream { - private IStream source; - - public StreamProxy() { - - } - - public StreamProxy(IStream source) { - this.source = source; - } - - public void setSource(IStream source) { - this.source = source; - } - - @Override - public InputStream getInputStream() { - if (source != null) - return source.getInputStream(); - return null; - } - - @Override - public OutputStream getOutputStream() { - if (source != null) - return source.getOutputStream(); - return null; - } - - @Override - public void close() { - if (source != null) - source.close(); - } - - @Override - public boolean isEmpty() { - if (source != null) - return source.isEmpty(); - return false; - } - - @Override - public void setType(String type) { - if (source != null) - source.setType(type); - } - - @Override - public String getType() { - if (source != null) - return source.getType(); - return null; - } - - @Override - public void setName(String name) { - if (source != null) - source.setName(name); - } - - @Override - public String getName() { - if (source != null) - return source.getName(); - return null; - } - - @Override - public String setValue(String value) { - if (source != null) - return source.setValue(value); - return value; - } - - @Override - public String getValue() { - if (source != null) - return source.getValue(); - return null; - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/listener/EndListener.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/listener/EndListener.java deleted file mode 100644 index 8fd6bb6..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/listener/EndListener.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.brilliance.mda.runtime.mda.listener; - -import org.springframework.context.ApplicationListener; -import org.springframework.context.event.ContextClosedEvent; - -/** - * 关闭监听 - * @author fukai - * - */ -public class EndListener implements ApplicationListener<ContextClosedEvent>{ - - @Override - public void onApplicationEvent(ContextClosedEvent event) { - - } - -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/listener/StartListener.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/listener/StartListener.java deleted file mode 100644 index 3ac10cc..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/listener/StartListener.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.brilliance.mda.runtime.mda.listener; - -import com.brilliance.mda.runtime.mda.IDaoSession; -import com.brilliance.mda.runtime.mda.IRuleEmitter; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; -import org.apache.ibatis.annotations.Mapper; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationListener; -import org.springframework.context.event.ContextRefreshedEvent; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -public class StartListener implements ApplicationListener<ContextRefreshedEvent>{ - - @Override - public void onApplicationEvent(ContextRefreshedEvent event) { - ApplicationContext context = event.getApplicationContext(); - //EnvConfig config = context.getBean(EnvConfig.class); - //引入全局pplication context - //String packagePath = config.getTransPackage().replaceAll("\\.", "/"); - //扫描所有的交易 - //scanModule(context,packagePath); - //扫描提供给MdaContext调用的Dao - scanDao(context); - //扫描事件触发器 - //scanEmitter(context); - } - - -// public void scanModule(ApplicationContext context,String packagePath){ -// MdaScanner scanner = context.getBean(MdaScanner.class); -// try { -// Set<Class<?>> clsSet = scanner.doScan(packagePath,Transaction.class); -// //MdaDynamicGenerator.createRuleEmitter(clsSet); -// MdaDriver.createVoSetterAndGetter(clsSet); -// //MdaDynamicGenerator.createVoSetterAndGetter(clsSet); -// } catch (ClassNotFoundException | IOException e) { -// e.printStackTrace(); -// } -// } - - public void scanDao(ApplicationContext context){ - Map<String,Object> beans = context.getBeansWithAnnotation(Mapper.class); - IDaoSession daoProxy = context.getBean(IDaoSession.class); - - DaoCyc: - for(Map.Entry<String, Object> entry : beans.entrySet()) - { - Object dao = entry.getValue(); - Class<?>[] interfaces = dao.getClass().getInterfaces(); - - if(interfaces == null) - continue; - for(Class<?> inf : interfaces) - { - Type[] types = inf.getGenericInterfaces(); - if(types == null) - continue; - for(Type type:types) - { - if(!(type instanceof ParameterizedType)) - continue; - Type[] paramTypes = ((ParameterizedType)type).getActualTypeArguments(); - if(paramTypes != null) - { - String clazzName = paramTypes[0].getTypeName(); - try{ - Class<?> clazz = Class.forName(clazzName); - //System.out.print(paramTypes[0].getTypeName()+"->"+inf); - daoProxy.putDao(clazz, dao); - }catch(Exception e) - {} - continue DaoCyc; - } - } - - } - } - } - public void scanEmitter(ApplicationContext context) - { - Map<String, IRuleEmitter> emitterMap = context.getBeansOfType(IRuleEmitter.class); - Set<Class<?>> clsSet = new HashSet<>(); - for(Map.Entry<String, IRuleEmitter> entry:emitterMap.entrySet()) - { - //EmitterFactory.getDefault().putRuleEmmiter(entry.getValue()); - Class<?> transactionClass = entry.getValue().relatedTransaction(); - clsSet.add(transactionClass); - } - MdaDriver.createVoSetterAndGetter(clsSet); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/ArchiveUtils.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/ArchiveUtils.java deleted file mode 100644 index 5896888..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/ArchiveUtils.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.brilliance.mda.runtime.mda.util; - -import org.apache.commons.compress.archivers.ArchiveEntry; -import org.apache.commons.compress.archivers.ArchiveOutputStream; -import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; -import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; -import org.apache.commons.io.IOUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.*; -import java.util.List; - -public class ArchiveUtils { - private static final Logger log = LoggerFactory.getLogger(ArchiveUtils.class); - - private static void archive(File file, ArchiveOutputStream aos, String entryName) - throws IOException { - if (file.isDirectory()) { - File[] files = file.listFiles(); - if (files.length < 1) { - aos.putArchiveEntry(aos.createArchiveEntry(file, entryName)); - aos.closeArchiveEntry(); - } - for (File _file : files) - archive(_file, aos, entryName + "/" + _file.getName()); - } else { - aos.putArchiveEntry(aos.createArchiveEntry(file, entryName)); - FileInputStream fis = new FileInputStream(file); - IOUtils.copyLarge(fis, aos); - fis.close(); - aos.closeArchiveEntry(); - } - } - - public static void archive(OutputStream os, String[] fileNames, String baseDirectoryName) { - ZipArchiveOutputStream zos = null; - try { - zos = new ZipArchiveOutputStream(os); - File baseDirectory = baseDirectoryName == null ? null : new File(baseDirectoryName); - for (String fileName : fileNames) - archive(baseDirectory == null ? new File(fileName) : new File(baseDirectory, fileName), zos, fileName); - } catch (Exception e) { - log.error("Archive to zip package error.", e); - } - MdaUtils.closeQuietly(zos); - } - - public static void archive(OutputStream os, List<String> fileNames, File baseDirectory) { - ZipArchiveOutputStream zos = null; - try { - zos = new ZipArchiveOutputStream(os); - for (String fileName : fileNames) - archive(baseDirectory == null ? new File(fileName) : new File(baseDirectory, fileName), zos, fileName); - } catch (Exception e) { - log.error("Archive to zip package error.", e); - } - MdaUtils.closeQuietly(zos); - } - - public static boolean extract(InputStream is, String entryName, OutputStream os) { - boolean flag = false; - ZipArchiveInputStream zis = null; - try { - zis = new ZipArchiveInputStream(is); - do { - ArchiveEntry entry = zis.getNextEntry(); - if (entry == null) - break; - if ((entryName == null) || (!entryName.equals(entry.getName()))) - continue; - flag = true; - IOUtils.copyLarge(zis, os, 0L, entry.getSize()); - } - while (!flag); - } catch (Exception e) { - log.error("Extract file form zip package error.", e); - } - MdaUtils.closeQuietly(zis); - return flag; - } - - -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Codetables.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Codetables.java deleted file mode 100644 index a4a304c..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Codetables.java +++ /dev/null @@ -1,170 +0,0 @@ -package com.brilliance.mda.runtime.mda.util; - -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.brilliance.mda.runtime.mda.impl.StreamImpl; -import com.brilliance.mda.support.service.CodetableService; -import com.brilliance.mda.support.td.ModuleInfoManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.ClassPathResource; -import org.springframework.util.CollectionUtils; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -public class Codetables { - - private static final Logger log = LoggerFactory.getLogger(Codetables.class); - //码表路径 - static String codeTableFilePath = "codeTable"; - static Map<String, List<CodetableItem>> staticCodeTableCache = new ConcurrentHashMap<>(); - - public static List<CodetableItem> getCodetable(String codeName) { - return null; - } - - public static String getCodetableLabelOfTd(String key, String codetable, String language) { - String label = ""; - List<CodetableItem> codeTable = getCodeTable(codetable, language); - if (!CollectionUtils.isEmpty(codeTable)) { - for (CodetableItem codetableItem : codeTable) { - if (key.equalsIgnoreCase(codetableItem.getValue())) { - label = codetableItem.getLabel(); - break; - } - } - } - return label; - } - - public static String getCodeTableKeyOfTd(String txt, String codetable, String language) { - String key = ""; - List<CodetableItem> codeTable = getCodeTable(codetable, language); - if (!CollectionUtils.isEmpty(codeTable)) { - for (CodetableItem codetableItem : codeTable) { - if (txt.equals(codetableItem.getLabel())) { - key = codetableItem.getValue(); - } - } - } - return key; - } - - public static void setTblText(String key, String table, String language, String value) { - File file = new File(codeTableFilePath, table + "_" + language + ".ctl"); - if (file.exists()) { - String codetable = "<?xml version=\"1.0\" encoding = \"UTF-8\" standalone=\"no\"?>\n<codetable>\n"; - codetable += "<item> description=\"description\" lable=\"" + value + "\" value=\"" + key + "\"/>\n"; - codetable += "</codetable>"; - try { - FileWriter fileWriter = new FileWriter(file); - fileWriter.write(codetable); - fileWriter.flush(); - fileWriter.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - public static IStream getTblKeyList(String codetable, String language) { - IStream keylst = new StreamImpl(); - List<CodetableItem> codeTable = getCodeTable(codetable, language); - if (!CollectionUtils.isEmpty(codeTable)) { - for (CodetableItem codetableItem : codeTable) { - keylst.addLine(codetableItem.getValue()); - } - } - return keylst; - } -// public static IStream getTblKeyList(String table, String language) { -// return getTblKeyList(table, language); -// } - - - public static List<CodetableItem> getCodeTable(String codeName, String lang) { - List codetable = new ArrayList<>(); - - if (codeName.indexOf(":") > 0) { - String arr[] = codeName.split(":"); - Map<String, Object> fieldInfo = ModuleInfoManager.getModuleFieldInfo(arr[0].trim().toLowerCase(), arr[1].trim().toLowerCase()); - if (fieldInfo == null) - return codetable; - codeName = (String) fieldInfo.get("codetable"); - if (MdaUtils.isEmpty(codeName)) - return codetable; - } else { - //尝试从组件中加载 - CodetableService codetableService = MdaEnv.getBean(CodetableService.class); - List<CodetableItem> dbCodeTable = codetableService.selectList(codeName.toUpperCase(), lang); - if (dbCodeTable != null && !dbCodeTable.isEmpty()) - return dbCodeTable; - } - - String fileName = codeTableFilePath + "/"; - if ("CN".equals(lang)) { - fileName = fileName + codeName.toLowerCase() + "_zh_CN.ctl"; - } else { - fileName = fileName + codeName.toLowerCase() + "_en_US.ctl"; - } - //Cache判断 - List<CodetableItem> tempCodeTableList = staticCodeTableCache.get(fileName); - if (tempCodeTableList != null) { - return tempCodeTableList; - } - //判断结束 - log.info("filePath:{}", fileName); - //if(file.exists()){ - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - try { - DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); - InputStream ins = new ClassPathResource(fileName).getInputStream(); - if (ins == null) { - return codetable; - } - Document parse = documentBuilder.parse(ins); - Element documentElement = parse.getDocumentElement(); - NodeList item = documentElement.getElementsByTagName("item"); - for (int i = 0; i < item.getLength(); i++) { - Element item1 = (Element) item.item(i); - codetable.add(new CodetableItem(item1.getAttribute("label"), item1.getAttribute("value"))); - } - - } catch (Exception e) { - log.error(e.getMessage()); - e.printStackTrace(); - } - - //缓存放入 - staticCodeTableCache.put(fileName, codetable); - return codetable; - } - - //private static String ATTR_CODE_VALUES="ATTR_CODE_VALUES"; - public static void setCodeValues(String key, IStream stream) { - } - - public static void setCodeValues(IDatafield<Object> datafield, IStream values) { - //MdaEnv.getContext().setAttribute(datafield.getParent(),datafield.getName(),ATTR_CODE_VALUES,stream); - setCodeValues(datafield.getParent(), datafield.getName(), values); - } - - public static void setCodeValues(IModule parent, String prop, IStream values) { - //拦截做values专项处理 - Systems.setValuesToContextSet(parent, prop, values); - MdaEnv.getContext().setAttribute(parent, prop, Constants.ATTR_CODE_VALUES, values); - } - -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Datas.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Datas.java deleted file mode 100644 index c65d359..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Datas.java +++ /dev/null @@ -1,458 +0,0 @@ -package com.brilliance.mda.runtime.mda.util; - -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.brilliance.mda.runtime.mda.impl.DatafieldImpl; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.math.BigDecimal; -import java.util.*; - -import static com.brilliance.mda.runtime.mda.Constants.NO_ERROR; -import static com.brilliance.mda.runtime.mda.Constants.NULLSTR; - -public class Datas { - - private static final Logger log = LoggerFactory.getLogger(Datas.class); - - public static String DEFAULT_SECTION = "DEFAULT"; - public static String LAST_LOAD_CONTENT = "LAST_LOAD_CONTENT"; - - - public static void saveData(IModule module, IStream os) { -// ObjectMapper mapper = new ObjectMapper(); -// try{ -//// mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); -//// mapper.writeValue(os.getOutputStream(),module); -// String data = mapper.writeValueAsString(module); -// saveData(); -// } -// catch (Exception e) -// { -// log.error("模型序列化异常",e); -// } - saveData(module, os, ""); - } - - public static <T extends IModule> void saveData(IModuleList<T> list, IStream os) { - ObjectMapper mapper = Modules.getObjectMapper(); - try { - mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); - mapper.writeValue(os.getOutputStream(), list); - } catch (Exception e) { - log.error("模型序列化异常", e); - } - } - - public static void saveData(IModule module, IStream stream, String section, String prefix) { -// TODO - /** - * 1、 V20 - * 2、 S+section - * 3、F+tllldddn +全路径名 = dataValue(DV,Dx,De,DL) +值 - * 4、MC +nnnnn +moduleList name - */ - - if (MdaUtils.isEmpty(section) && prefix.equals("")) { - section = "DEFAULT"; - } else { - section = prefix; - } - String tempValue = Modules.module2Data(module); - for (int i = 1; i <= stream.countLines(); i++) { - if (stream.getLine(i).equals(section)) { - if (i == stream.countLines()) - stream.addLine(tempValue); - else - stream.setLine(i + 1, tempValue); - return; - } - } - //写入区块 - stream.addLine(section); - stream.addLine(tempValue); - } - - public static void saveData(IBaseObject moduleOrList, IStream stream, String section) { - if (MdaUtils.isEmpty(section)) - section = "DEFAULT"; - String tempValue = Modules.module2Data(moduleOrList); - for (int i = 1; i <= stream.countLines(); i++) { - if (stream.getLine(i).equals(section)) { - if (i == stream.countLines()) - stream.addLine(tempValue); - else - stream.setLine(i + 1, tempValue); - return; - } - } - //写入区块 - stream.addLine(section); - stream.addLine(tempValue); - } - - public static void loadData(IModule module, IStream stream, String section) { - if (MdaUtils.isEmpty(section)) - section = "DEFAULT"; - for (int i = 1; i <= stream.countLines(); i++) { - if (stream.getLine(i).equals(section) && i < stream.countLines()) { - String dataString = stream.getLine(i + 1); - IModule tempModule = (IModule) Modules.data2Module(module.getClass(), dataString); - if (tempModule != null) - module.copyValues(tempModule); - } - } - MdaEnv.getContext().setErrorCode(NO_ERROR); - } - - - public static <T> IDatafield<T> getField(String target) { - return getContentField(target); - } - - public static <T> IDatafield<T> getField(IModule module, String target) { - if (target != null && target.startsWith("\\")) { - return getContentField(MdaEnv.getContext().getRoot(), target); - } - return getContentField(module, target); - } - - public static void setFieldValue(IDatafield field, String value) { - field.setValue(value); - } - - public static <T> void setFieldValue(String fieldTarget, T value) { - IDatafield<T> field = getContentField(fieldTarget); - if (field == null) return; - if (field.getDataType() == IStream.class) { -// if (value instanceof String) { -// IStream stm = new StreamImpl(); -// stm.setRows(streamStrSplit((String) value)); -// ((IDatafield<IStream>) field).setValue(stm); -// return; -// } - } - //TODO 应该为设置码表,并不是设置值 - //field.setValue(value); - - - } - - public static <T> void setFieldValue(IModule parent, String fieldTarget, T value) { - IDatafield<T> field = getContentField(parent, fieldTarget); - field.setValue(value); - } - - public static <T> IDatafield<T> getContentField(String target) { - return MdaDriver.getDatafield(target); - } - - public static <T> IDatafield<T> getContentField(IModule parent, String target) { - return MdaDriver.getDatafield(parent, target); - } - - public static void setFieldValue(IStream stream, String str) { - if (str == null) return; - String[] args = null; - if (str.indexOf("\r\n") != -1) { - str = Strings.trimEnd(str, "\r\n"); - args = str.split("\r\n"); - } else if (str.indexOf("\n") != -1) { - str = Strings.trimEnd(str, "\n"); - args = str.split("\n"); - } else { - args = new String[]{str}; - } - stream.setRows(Arrays.asList(args)); - List<String> rows = stream.getRows(); - } - - - public static <T> void setContentNumeric(String target, T val) { - IDatafield<T> datafield = getContentField(target); - if (datafield == null) - return; - Class<T> dataType = datafield.getDataType(); - if (dataType == long.class && val instanceof BigDecimal) { - BigDecimal val1 = (BigDecimal) val; - datafield.setValue((T) Long.valueOf(val1.longValue())); - } else { - datafield.setValue(val); - } - } - - public static <T> void setContentNumeric(IModule _this, String target, T val) { - if (!target.startsWith("\\") && _this != null) { - target = _this.getPath() + "\\" + target; - } - setContentNumeric(target, val); - } - - public static BigDecimal getContentNumeric(String target) { - // IDatafield datafield = getContentField(target); - // if (datafield == null) - // return BigDecimal.ZERO; - // if(datafield.getValue() instanceof Integer) - // return new BigDecimal(datafield.getValue().toString()); - // return (BigDecimal) datafield.getValue(); - - IBaseObject baseObject = MdaDriver.getBaseObject(null, target); - if (baseObject == null) { - return BigDecimal.ZERO; - } - if (baseObject instanceof IDatafield) { - IDatafield datafield = (IDatafield) baseObject; - if (datafield.getValue() instanceof Number) { - return new BigDecimal(datafield.getValue().toString()); - } - return (BigDecimal) datafield.getValue(); - } - MdaEnv.getContext().setErrorCode(27); - return BigDecimal.ZERO; - } - - public static BigDecimal getContentNumeric(IModule _this, String target) { - if (!target.startsWith("\\") && _this != null) { - target = _this.getPath() + "\\" + target; - } - return getContentNumeric(target); - } - - public static String getContent(String target) { - IDatafield datafield = getContentField(target); - if (datafield == null) { - MdaEnv.getContext().setErrorCode(Constants.NO_SUCH_FIELD); - return NULLSTR; - } - MdaEnv.getContext().setErrorCode(Constants.NO_ERROR); - if (datafield.getValue() == null) - return NULLSTR; - return datafield.getValue().toString(); - } - - public static String getContent(IModule _this, String target) { - if (!target.startsWith("\\") && _this != null) { - String path = _this.getPath(); - target = path.equals("\\") ? "\\" + target : path + "\\" + target; - } - return getContent(target); - } - - public static void setContentText(String target, String value) { - IDatafield<String> datafield = getContentField(target); - if (datafield == null) { - return; - } - datafield.setValue(value); - } - - public static void setContentText(IModule _this, String target, String value) { - if (!target.startsWith("\\") && _this != null) { - IDatafield<String> datafield = MdaDriver.getDatafield(_this, target); - if (datafield == null) { - return; - } - datafield.setValue(value); - return; - } - setContentText(target, value); - } - - public static void setContentDate(String target, Date value) { - IDatafield<Date> datafield = getContentField(target); - if (datafield == null) - return; - datafield.setValue(value); - } - - public static void setContentDate(IModule _this, String target, Date value) { - if (!target.startsWith("\\") && _this != null) { - IDatafield<Date> datafield = MdaDriver.getDatafield(_this, target); - if (datafield == null) { - return; - } - datafield.setValue(value); - return; - } - setContentDate(target, value); - } - - public static Date getContentDate(String target) { - IDatafield<Date> datafield = getContentField(target); - if (datafield == null) - return null; - return datafield.getValue(); - } - - public static Date getContentDate(IModule _this, String target) { - if (!target.startsWith("\\") && _this != null) { - target = _this.getPath() + "\\" + target; - } - return getContentDate(target); - } - - public static void setContentDateTime(String fieldname, Date datetime) { - setContentDate(fieldname, datetime); - } - - public static void setContentDateTime(IModule _this, String fieldname, Date datetime) { - if (!fieldname.startsWith("\\") && _this != null) { - fieldname = _this.getPath() + "\\" + fieldname; - } - setContentDateTime(fieldname, datetime); - } - - public static Date getContentDateTime(String field) { - return getContentDate(field); - } - - public static Date getContentDateTime(IModule _this, String field) { - return getContentDate(_this, field); - } - - public static void setContentStream(String fieldname, IStream stream) { - stream.setName(fieldname); - } - - public static void getContentStream(IStream stream, String fieldname) { - IDatafield<Object> contentField = getContentField(fieldname); - try { - Streams.streamSet(stream, (IStream) contentField.getValue()); - } catch (Exception e) { - //设置错误码,但是具体应该设置为什么文档上没写,暂时不设置 - //TODO - log.error("返回类型不对", e); - } - } - - public static void getContentStream(IDatafield datafield, String fieldname) { - if (datafield == null) { - return; - } - datafield.setValue(fieldname); - } - - public static void setContentStream(IModule _this, String fieldname, IStream stream) { - if (!fieldname.startsWith("\\") && _this != null) { - fieldname = _this.getPath() + "\\" + fieldname; - } - setContentStream(fieldname, stream); - } - - public static void getContentStream(IModule _this, IStream stream, String fieldname) { - if (!fieldname.startsWith("\\") && _this != null) { - fieldname = _this.getPath() + "\\" + fieldname; - } - getContentStream(stream, fieldname); - } - - public static void getContentStream(IModule _this, IDatafield datafield, String fieldname) { - if (!fieldname.startsWith("\\") && _this != null) { - fieldname = _this.getPath() + "\\" + fieldname; - } - getContentStream(datafield, fieldname); - } - - - public static List<String> findStreamSectionValue(IStream stream, String section) { - List<String> valueList = new ArrayList<>(); - for (int i = 0; i < stream.getRows().size(); i++) { - if (stream.getRows().get(i).indexOf(section) >= 0 && i + 1 < stream.getRows().size()) { - valueList.add(stream.getRows().get(i + 1)); - break; - } - } - return valueList; - } - - - public static Date loadContentDate() { - Object val = MdaEnv.getContext().restoreData(LAST_LOAD_CONTENT); - return (Date) val; - } - - public static Date loadContentDateTime() { - return loadContentDate(); - } - - public static BigDecimal loadContentNumeric() { - Object val = MdaEnv.getContext().restoreData(LAST_LOAD_CONTENT); - - return (BigDecimal) val; - } - - public static void getDataInfoStream(IStream info, IStream data) { - getDataInfoStream(info, data, "DEFAULT"); - } - - public static void getDataInfoStream(IStream info, IStream data, String section) { - if (MdaUtils.isEmpty(section)) { - section = "DEFAULT"; - } - for (int i = 0; i < data.getRows().size(); i++) { -// if(section.equals(data.getRows().get(i)) && i+1<data.getRows().size()) -// data.addLine(data.getRows().get(i+1)); - if (data.getRows().get(i).indexOf(section) < 0 && i + 1 < data.getRows().size() && data.getRows().get(i).indexOf("DN ") == 0) { - String line = data.getRows().get(i).substring(3); - info.addLine(line.split(" ")[0]); - } - } - } - - public static <T extends IModule> void loadContentStream(IStream stm) { - Object val = MdaEnv.getContext().restoreData(LAST_LOAD_CONTENT); - if (val instanceof Map) { - Map map = (Map) val; - List<String> rows = (List<String>) map.get("rows"); - stm.getRows().addAll(rows); - } - } - - public static void ddeSetTopic(String str) { - } - - public static boolean ddeTestTopic(String trigger, String sysmod) { - return false; - } - - public static void ddeSend(String trigger, String ddeTopic, IStream argStr) { - } - - //TODO - public static void getDataInfoCompare(IModule mod, IStream data, String section, IStream addfldnam, IStream dif) { - List<IModule> moduleList = mod.getModules(); - List<String> rows = data.getAttribute(section) == null ? null : ((IStream) data.getAttribute(section)).getRows(); - List<String> l1 = new ArrayList<>(); - List<String> l2 = new ArrayList<>(); - for (IModule iModule : moduleList) { - if (null != rows && !rows.contains(iModule.getName())) { - l1.add(iModule.getName()); - } - } - if (null != rows) { - for (String row : rows) { - if (!moduleList.contains(row)) { - l2.add(row); - } - } - } - addfldnam.setRows(l1); - dif.setRows(l2); - } - - - //基于字段路径返回相应值 - public static Object basePath2Content(String path) { - DatafieldImpl datafield = MdaDriver.getDatafield(path); - if (datafield == null) { - return null; - } - return datafield.getValue(); - } - -} - diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Files.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Files.java deleted file mode 100644 index 9cd8403..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Files.java +++ /dev/null @@ -1,459 +0,0 @@ -package com.brilliance.mda.runtime.mda.util; - -import com.brilliance.mda.runtime.mda.IBaseObject; -import com.brilliance.mda.runtime.mda.IStream; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.brilliance.mda.runtime.response.ResponseSet; -import org.apache.commons.codec.digest.DigestUtils; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.filefilter.DirectoryFileFilter; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.poifs.filesystem.OfficeXmlFileException; -import org.apache.poi.ss.usermodel.*; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.*; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static com.brilliance.mda.runtime.mda.Constants.NULLSTR; - - -public class Files { - - private static final Logger log = LoggerFactory.getLogger(Files.class); - private final static String rootPath = "/DATA/DISPLAY/"; - public static final String separator = File.separator; - - public static ResponseSet<Object> fileOutput(String trninr) { - FileInputStream fis = null; - InputStreamReader isr = null; - BufferedReader br = null; - String str = ""; - String messageStr = ""; - try { - fis = new FileInputStream(MdaEnv.getRootPath() + rootPath + trninr.substring(0, 4) + "/" + trninr + ".DSP"); - isr = new InputStreamReader(fis); - br = new BufferedReader(isr); - while ((str = br.readLine()) != null) { - messageStr += str; - } - } catch (FileNotFoundException e) { - System.out.println("找不到指定文件"); - e.printStackTrace(); - } catch (IOException e) { - System.out.println("读取文件失败"); - e.printStackTrace(); - } finally { - try { - if (null != br) { - br.close(); - } - if (null != isr) { - isr.close(); - } - if (null != fis) { - fis.close(); - } - - } catch (IOException e) { - e.printStackTrace(); - } - } - return new ResponseSet(messageStr); - } - - public static File mkdirs(String fileName) { - if (fileName == null) return null; - File file = new File(fileName); - if (!file.getParentFile().exists()) - file.getParentFile().mkdirs(); - return file; - } - - - public static boolean fileMkdirs(String filePath) { - return new File(filePath).mkdirs(); - } - - public static String fileName(String fileName) { - return FilenameUtils.getName(fileName); - } - - public static String fileBaseName(String fileName) { - return FilenameUtils.getBaseName(fileName); - } - - public static String fileExtension(String fileName) { - return FilenameUtils.getExtension(fileName); - } - - public static long fileSize(String fileName) { - return new File(fileName).length(); - } - - public static String fileMD5Value(String fileName) { - try { - return DigestUtils.md5Hex(new FileInputStream(fileName)); - } catch (Exception e) { - log.error("Get MD5 error.", e); - } - return null; - } - - public static final List<String> loadLines(String fileName, String encoding) { - try { - FileInputStream fis = new FileInputStream(fileName); - List list = IOUtils.readLines(fis, encoding); - fis.close(); - return list; - } catch (Exception e) { - log.error("Read lines error.", e); - } - return Collections.EMPTY_LIST; - } - - public static final void saveLines(List<String> lines, String lineEnding, String fileName, String encoding) { - try { - IOUtils.writeLines(lines, "", new FileOutputStream(fileName), encoding); - } catch (Exception e) { - log.error("Save lines error.", e); - } - } - - public static final void saveContent(String content, String fileName, String encoding) { - try { - IOUtils.write(content, new FileOutputStream(fileName), encoding); - } catch (Exception e) { - log.error("Load content error.", e); - } - } - - public static final String[] loadExcelSheetNames(IStream s) { - Workbook wb = getWorkbook(s); - if (wb == null) - return null; - int count = wb.getNumberOfSheets(); - String[] sheetNames = new String[count]; - for (int i = 0; i < count; i++) - sheetNames[i] = wb.getSheetName(i); - resetQuietly(s); - return sheetNames; - } - - private static final Workbook getWorkbook(IStream s) { - Workbook wb = null; - try { - wb = new HSSFWorkbook(s.getInputStream()); - } catch (OfficeXmlFileException _e) { - try { - resetQuietly(s); - wb = new XSSFWorkbook(s.getInputStream()); - } catch (IOException e) { - log.warn("load excel error.", e); - } - } catch (IOException e) { - log.warn("load excel error.", e); - } - resetQuietly(s); - return wb; - } - - private static final void resetQuietly(IStream s) { - try { - s.getInputStream().reset(); - } catch (IOException localIOException) { - } - } - - public static final int loadExcel(List<String[]> list, IStream s, int sheetIndex, int rowOffset, int rowMax, int columnOffset, int columnCount) { - Workbook wb = getWorkbook(s); - if (wb == null) - return -1; - if ((sheetIndex < 0) || (sheetIndex >= wb.getNumberOfSheets())) { - log.warn("load excel sheet with a illegal index."); - return -3; - } - Sheet sheet = wb == null ? null : wb.getSheetAt(sheetIndex); - if (sheet == null) { - log.warn("load excel sheet error."); - return -2; - } - - int rows = rowMax > 0 ? Math.min(rowMax, sheet.getLastRowNum() - rowOffset) : sheet.getLastRowNum() - rowOffset; - if (columnCount > 0) { - for (int i = 0; i <= rows; i++) { - Row row = sheet.getRow(i + rowOffset); - String[] values = new String[columnCount]; - for (int j = 0; j < columnCount; j++) { - if (row == null) { - values[j] = ""; - } else { - Cell cell = row.getCell(j + columnOffset); - values[j] = (cell != null ? getCellValue(cell, cell.getCellTypeEnum()) : ""); - } - } - list.add(values); - } - } - return rows; - } - - private static final String getCellValue(Cell cell, CellType type) { - switch (type) { - case FORMULA: - return getCellValue(cell, cell.getCachedFormulaResultTypeEnum()); - case ERROR: - return cell.getStringCellValue(); - case BOOLEAN: - int df = cell.getCellStyle().getDataFormat(); - - if ((df == 20) || (df == 32)) - return MdaUtils.timeFormat.format(cell.getDateCellValue()); - if ((DateUtil.isInternalDateFormat(df)) || (df == 31) || (df == 57) || (df == 58) || (DateUtil.isCellDateFormatted(cell))) - return MdaUtils.dateFormat.format(cell.getDateCellValue()); - return MdaUtils.format.format(Double.valueOf(cell.getNumericCellValue())); - } - return cell.toString(); - } - - private static final int unloadExcel(Object value, Row row, int cellNum) { - Cell cell = row.createCell(cellNum); - if ((value != null) && ((value instanceof Number))) { - cell.setCellType(CellType.NUMERIC); - cell.setCellValue(((Number) value).doubleValue()); - } else { - cell.setCellType(CellType.STRING); - if ((value == null) || ((value instanceof String))) - cell.setCellValue((String) value); - else - cell.setCellValue(value.toString()); - } - return cellNum + 1; - } - - private static final void unloadExcel(List list, Sheet sheet) { - int rowNum = 0; - for (Iterator localIterator1 = list.iterator(); localIterator1.hasNext(); ) { - Object values = localIterator1.next(); - - Row row = sheet.createRow(rowNum); - int cellNum = 0; - if ((values instanceof Iterable)) { - for (Iterator localIterator2 = ((Iterable) values).iterator(); localIterator2.hasNext(); ) { - Object value = localIterator2.next(); - cellNum = unloadExcel(value, row, cellNum); - } - } else if ((values instanceof Object[])) { - for (Object value : (Object[]) values) - cellNum = unloadExcel(value, row, cellNum); - } - rowNum++; - } - } - - public static final void unloadExcel(List[] lists, String[] sheetNames, IStream s, boolean flag) { - Workbook wb = flag ? new XSSFWorkbook() : new HSSFWorkbook(); - OutputStream os = null; - try { - for (int i = 0; i < lists.length; i++) { - List list = lists[i]; - String sheetname = sheetNames[i]; - Sheet sheet = MdaUtils.isEmpty(sheetname) ? wb.createSheet() : wb.createSheet(sheetname); - unloadExcel(list, sheet); - } - os = s.getOutputStream(); - wb.write(os); - os.flush(); - } catch (IOException e) { - log.error("unload Excel error.", e); - } finally { - MdaUtils.closeQuietly(os); - MdaUtils.closeQuietly(wb); - } - } - - public static final void unloadExcel(List list, IStream s, boolean flag) { - unloadExcel(new List[]{list}, new String[1], s, flag); - } - - public static final void forceDelete(File path) - throws IOException { - IOException exception = null; - for (int i = 0; i < 10; ) { - try { - FileUtils.forceDelete(path); - return; - } catch (IOException e) { - exception = e; - try { - Thread.sleep(1000L); - } catch (Exception localException) { - } - i++; - } - - } - - throw exception; - } - - public static String fileCreate(String filename) { - File file = new File(filename); - File parentFolder = file.getParentFile(); - String reg = "#{1,}"; - Matcher m = Pattern.compile(reg).matcher(filename); - if (m.find()) { - int beg = m.start(); - int end = m.end(); - for (int i = beg; i <= end; i++) { - if (filename.indexOf(beg) != '#') { - MdaEnv.getContext().setErrorCode(75); - } - } - int len = end - beg; - if (!parentFolder.exists()) { - parentFolder.mkdirs(); - String nfilename = filename.substring(0, beg) + String.format("%0" + len + "d", 0) + filename.substring(end); - file.delete(); - File nfile = new File(nfilename); - try { - nfile.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - } - return nfilename; - } - int maxNum = -1; - File[] fileList = parentFolder.listFiles(); - String path2 = file.getAbsolutePath(); - for (File file1 : fileList) { - if (file1.isDirectory()) - continue; - String path1 = file1.getAbsolutePath(); - //判断长度相等 - //判断前后是否一致 - if (path1.length() == path2.length() - && path1.substring(0, beg).equals(path2.substring(0, beg)) - && path1.substring(end).equals(path2.substring(end))) { - //取出中间字符,判断是否符合纯数字 - String temp = path1.substring(beg, end); - int i = 0; - for (i = 0; i < temp.length(); i++) { - if (!Character.isDigit(temp.charAt(i))) { - break; - } - } - //与maxNum比较与赋值 - if (i == temp.length()) { - int num = Integer.parseInt(temp); - if ((temp + 1 + NULLSTR).length() > len) { //99...99格式 - MdaEnv.getContext().setErrorCode(76); - } - maxNum = Math.max(maxNum, num); - } - } - } - String numstr = String.format("%0" + len + "d", maxNum + 1); - String nfilename = filename.substring(0, beg) + numstr + filename.substring(end); - File nfile = new File(nfilename); - //文件重新创建 - try { - nfile.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - } - return nfilename; - } else { - if (!parentFolder.exists()) - parentFolder.mkdirs(); - if (file.exists()) - file.delete(); - try { - file.createNewFile(); - } catch (IOException e) { - MdaEnv.getContext().setErrorCode(10); - return null; - } - return filename; - } - } - - //TODO 补充 - public static String fileCreate(String filename, String val) { - String reg = "#{1,}"; - Matcher m = Pattern.compile(reg).matcher(filename); - if (m.find()) { - int beg = m.start(); - int end = m.end(); - for (int i = beg; i <= end; i++) { - if (filename.indexOf(beg) != '#') { - MdaEnv.getContext().setErrorCode(75); - } - } - if (!filename.substring(0, beg).equals(val.substring(0, beg))) { - MdaEnv.getContext().setErrorCode(75); - } - String numstr = val.substring(beg, end); - int num = Integer.parseInt(numstr); - num++; - numstr = String.format("%0" + m.group().length() + "d", num); - String nfilename = filename.substring(0, beg) + numstr + filename.substring(end); - File file = new File(nfilename); - File parentFolder = file.getParentFile(); - if (!parentFolder.exists()) - parentFolder.mkdirs(); - if (file.exists()) - file.delete(); - try { - if (!file.createNewFile()) { - MdaEnv.getContext().setErrorCode(10); - } - } catch (IOException e) { - return null; - } - return nfilename; - } else { - File file = new File(filename); - if (file.exists()) { - MdaEnv.getContext().setErrorCode(12); - } - } - return null; - } - - - public static List<String> listFiles(String path, String[] extensions) { - List list = new ArrayList(); - try { - for (File file : FileUtils.listFiles(new File(path), extensions, false)) - list.add(file.getAbsolutePath()); - } catch (Exception e) { - log.error(e.getMessage()); - } - return list; - } - - public static List<String> listDirectories(String path) { - List list = new ArrayList(); - try { - for (File file : new File(path).listFiles((FileFilter) DirectoryFileFilter.DIRECTORY)) - list.add(file.getAbsolutePath()); - } catch (Exception e) { - log.error(e.getMessage()); - } - return list; - } - - public static String getPath(IBaseObject baseObject) { - return baseObject.getPath(); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/MdaUtils.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/MdaUtils.java deleted file mode 100644 index 3404403..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/MdaUtils.java +++ /dev/null @@ -1,1337 +0,0 @@ -package com.brilliance.mda.runtime.mda.util; - -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.driver.I18NImpl; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.brilliance.mda.runtime.mda.impl.Argument; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import oracle.sql.TIMESTAMP; -import org.apache.commons.beanutils.MethodUtils; -import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.codec.digest.DigestUtils; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.filefilter.DirectoryFileFilter; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.poifs.filesystem.OfficeXmlFileException; -import org.apache.poi.ss.usermodel.*; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.*; -import java.math.BigDecimal; -import java.net.URLEncoder; -import java.nio.charset.Charset; -import java.sql.Timestamp; -import java.text.DecimalFormat; -import java.text.Format; -import java.text.MessageFormat; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.concurrent.Semaphore; - -public class MdaUtils { - - private static final Logger log = LoggerFactory.getLogger(MdaUtils.class); - - static final Format format = new DecimalFormat("#.######"); - static final Format dateFormat = new SimpleDateFormat("yyyy/MM/dd"); - static final Format timeFormat = new SimpleDateFormat("HH:mm"); - public static boolean autoConvert = false; - - - static final Map<String, Semaphore> mutexMap = new HashMap(); - - static final HashMap<String, Properties> pMap = new HashMap(); - - public static synchronized void close() { - pMap.clear(); - } - - private static synchronized Properties getProperties(String name) - throws FileNotFoundException, IOException { - Properties properties = (Properties) pMap.get(name); - if (properties == null) { - properties = new Properties(); - properties.load(new FileInputStream(new File(name))); - pMap.put(name, properties); - } - return properties; - } - - public static String getPropertyValue(String fileName, String key) { - try { - return getProperties(fileName).getProperty(key); - } catch (Exception e) { - log.error(e.getMessage()); - } - return null; - } - - public static void setPropertyValue(String fileName, String key, String value) { - try { - Properties properties = getProperties(fileName); - properties.setProperty(key, value); - properties.store(new FileOutputStream(mkdirs(fileName)), null); - } catch (Exception e) { - log.error(e.getMessage()); - } - } - - private static File mkdirs(String fileName) { - File file = new File(fileName); - if (!file.getParentFile().exists()) - file.getParentFile().mkdirs(); - return file; - } - - public static boolean fileCopy(String sourceFileName, String targetFileName) { - try { - File sourceFile = new File(sourceFileName); - File targetFile = new File(targetFileName); - if (targetFile.exists()) { - if (sourceFile.isDirectory()) - FileUtils.copyDirectoryToDirectory(sourceFile, targetFile); - else if (targetFile.isDirectory()) - FileUtils.copyFileToDirectory(sourceFile, targetFile); - else { - FileUtils.copyFile(sourceFile, targetFile); - } - - } else if (sourceFile.isDirectory()) { - targetFile.mkdirs(); - FileUtils.copyDirectory(sourceFile, targetFile); - } else { - FileUtils.copyFile(new File(sourceFileName), mkdirs(targetFileName)); - } - return true; - } catch (Exception e) { - log.error("fileCopy error", e); - } - return false; - } - - public static boolean fileDelete(String fileName) { - try { - FileUtils.forceDelete(new File(fileName)); - return true; - } catch (Exception e) { - log.error("fileDelete error", e); - } - return false; - } - - public static boolean fileMove(String sourcefileNameOrPath, String targetFileOrPathName) { - try { - File sourceFile = new File(sourcefileNameOrPath); - File targetFile = new File(targetFileOrPathName); - if (targetFile.exists()) { - if (sourceFile.isDirectory()) - FileUtils.moveDirectoryToDirectory(sourceFile, targetFile, false); - else if (targetFile.isDirectory()) - FileUtils.moveFileToDirectory(sourceFile, targetFile, false); - else { - FileUtils.moveFile(sourceFile, targetFile); - } - - } else if (sourceFile.isDirectory()) - FileUtils.moveDirectoryToDirectory(sourceFile, targetFile, true); - else { - FileUtils.moveFile(sourceFile, targetFile); - } - return true; - } catch (Exception e) { - log.error("fileMove error", e); - } - return false; - } - - public static boolean fileMkdirs(String filePath) { - return new File(filePath).mkdirs(); - } - - public static String fileName(String fileName) { - return FilenameUtils.getName(fileName); - } - - public static String fileBaseName(String fileName) { - return FilenameUtils.getBaseName(fileName); - } - - public static String fileExtension(String fileName) { - return FilenameUtils.getExtension(fileName); - } - - public static boolean fileExists(String fileName) { - return new File(fileName).exists(); - } - - public static long fileSize(String fileName) { - return new File(fileName).length(); - } - - public static Date fileDate(String fileName) { - return new Date(new File(fileName).lastModified()); - } - - public static String fileMD5Value(String fileName) { - try { - return DigestUtils.md5Hex(new FileInputStream(fileName)); - } catch (Exception e) { - log.error("Get MD5 error.", e); - } - return null; - } - - public static void fileArchive(String zipFileName, String[] fileNames, String baseDirectoryName) { - try { - ArchiveUtils.archive(new FileOutputStream(zipFileName), fileNames, baseDirectoryName); - } catch (Exception e) { - log.error("Archive file error.", e); - } - } - - public static void fileArchive(IStream zipStream, String[] fileNames, String baseDirectoryName) { - try { - ArchiveUtils.archive(zipStream.getOutputStream(), fileNames, baseDirectoryName); - } catch (Exception e) { - log.error("Archive file error.", e); - } - } - - public static boolean fileExtract(String zipFileName, String entryName, String outputFileName) { - try { - return ArchiveUtils.extract(new FileInputStream(zipFileName), entryName, new FileOutputStream(outputFileName)); - } catch (Exception e) { - log.error("Extract file error.", e); - } - return false; - } - - public static boolean fileExtract(IStream zipStream, String entryName, IStream outputStream) { - try { - return ArchiveUtils.extract(zipStream.getInputStream(), entryName, outputStream.getOutputStream()); - } catch (Exception e) { - log.error("Extract file error.", e); - } - return false; - } - - public static void streamSave(IStream stream, String fileName) { - try { - File file = mkdirs(fileName); - copy(stream.getInputStream(), new FileOutputStream(file)); - stream.close(); -// if (clusterUsed) -// clusterSendFile(file); - } catch (Exception e) { - log.error("streamSave error.", e); - } - } - - public static void streamLoad(IStream stream, String fileName) { - try { - stream.close(); - - copy(new FileInputStream(new File(fileName)), stream.getOutputStream()); - } catch (Exception e) { - log.error("streamLoad error.", e); - } - } - - public static void streamClear(IStream stream) { - stream.close(); - } - - public static final void copy(InputStream is, OutputStream os) - throws IOException { - try { - IOUtils.copy(is, os); - } finally { - closeQuietly(is); - closeQuietly(os); - } - } - - public static final void copy(Reader reader, OutputStream os, Charset charset) - throws IOException { - try { - IOUtils.copy(reader, os, charset); - } finally { - closeQuietly(reader); - closeQuietly(os); - } - } - - public static final void closeQuietly(Closeable closeable) { - try { - if (closeable != null) - closeable.close(); - } catch (Exception localException) { - } - } - - public static final String decode(byte[] data, DecodeType type) { - switch (type) { - case DECODE_MD5: - return DigestUtils.md5Hex(data); - case DECODE_SHA: - return DigestUtils.sha1Hex(data); - case DECODE_SHA256: - return DigestUtils.sha256Hex(data); - case DECODE_SHA384: - return DigestUtils.sha384Hex(data); - case DECODE_SHA512: - return DigestUtils.sha512Hex(data); - case DECODE_BASE64: - return Base64.encodeBase64String(data); - } - return new String(data); - } - - public static final String toString(Object object) { - if ((object == null) || ((object instanceof String))) - return (String) object; - try { - if ((object instanceof IStream)) - return IOUtils.toString(((IStream) object).getInputStream(), Charset.defaultCharset()); - if ((object instanceof IDatafield)) - return toString(((IDatafield) object).getValue()); - return object.toString(); - } catch (Exception e) { - } - return null; - } - - public static final int parseInt(Object value) { - if (value == null) - return 0; - try { - if ((value instanceof IDatafield)) - return parseInt(((IDatafield) value).getValue()); - if ((value instanceof String)) - return Integer.parseInt((String) value); - return Integer.parseInt(value.toString()); - } catch (Exception e) { - } - return 0; - } - - public static final BigDecimal parseDecimal(Object value) { - if (value == null) - return BigDecimal.ZERO; - try { - if ((value instanceof IDatafield)) - return parseDecimal(((IDatafield) value).getValue()); - if ((value instanceof String)) - return new BigDecimal((String) value); - return new BigDecimal(value.toString()); - } catch (Exception e) { - } - return BigDecimal.ZERO; - } - - public static final Boolean parseBoolean(Object value, Boolean defaultValue) { - if (value == null) - return defaultValue; - try { - if ((value instanceof IDatafield)) - return parseBoolean(((IDatafield) value).getValue(), defaultValue); - if ((value instanceof Boolean)) - return (Boolean) value; - return Boolean.valueOf(Boolean.parseBoolean(value.toString())); - } catch (Exception e) { - } - return defaultValue; - } - - public static final Date parseDate(Object value, String pattern) { - if (value == null) - return null; - try { - if ((value instanceof IDatafield)) - return parseDate(((IDatafield) value).getValue(), pattern); - String v = (value instanceof String) ? (String) value : value.toString(); - SimpleDateFormat format = new SimpleDateFormat(pattern); - return format.parse(v); - } catch (Exception e) { - } - return null; - } - - public static final String getI18nStr(String name, String key) { - return "/" + name + "/" + key + "/"; - } - - public static void sleep(long millis) { - try { - Thread.sleep(millis); - } catch (Exception localException) { - } - } - - public static int diff(Date date1, Date date2) { - return date1.compareTo(date2); - } - - public static Date add(Date date, int days) { - return add(date, 5, days); - } - - public static Date add(Date date, int type, int value) { - Calendar c = Calendar.getInstance(); - c.setTime(date); - c.add(type, value); - return c.getTime(); - } - - public static Date today() { - return new Date(); - } - - public static String format(Object object, String pattern) { - if (object == null) - return null; - if ((object instanceof IDatafield)) - return format(((IDatafield) object).getValue(), pattern); - if (pattern.startsWith("%")) - return String.format(pattern, new Object[]{object}); - if ((object instanceof Number)) - return new DecimalFormat(pattern).format(object); - if ((object instanceof Date)) - return new SimpleDateFormat(pattern).format(object); - return new MessageFormat(pattern).format(object); - } - - public static boolean isEmpty(Object object) { - if (object == null) - return true; - if ((object instanceof String)) - return "".equals(((String) object).trim()); - if ((object instanceof StringBuffer)) - return isEmpty(((StringBuffer) object).toString()); -// if ((object instanceof IModule)) -// return ((IModule)object).isEmpty(); - if ((object instanceof IStream)) - return ((IStream) object).isEmpty(); - if ((object instanceof IDatafield)) - return isEmpty(((IDatafield) object).getValue()); - if ((object instanceof Number)) - return ((Number) object).doubleValue() == 0.0D; - if ((object instanceof Collection)) - return ((Collection) object).isEmpty(); - if ((object instanceof Map)) - return ((Map) object).isEmpty(); - if ((object instanceof Argument)) - return isEmpty(((Argument) object).getValue()); - return false; - } - - public static boolean exists(Object object, String methodName, Object... args) { - return exists(object, methodName, null, args); - } - - public static boolean exists(Object object, String methodName, Class[] classes, Object[] args) { - if (classes == null) { - classes = new Class[args.length]; - for (int i = 0; i < args.length; i++) - classes[i] = args[i].getClass(); - } - try { - if ((object instanceof String)) - return MethodUtils.getAccessibleMethod(Class.forName((String) object), methodName, classes) != null; - return MethodUtils.getAccessibleMethod(object.getClass(), methodName, classes) != null; - } catch (Exception e) { - } - return false; - } - - public static Object invoke(Object object, String methodName, Object... args) { - return invoke(object, methodName, null, args); - } - - public static Object invoke(Object object, String methodName, Class[] classes, Object[] args) { - try { - if (classes == null) { - classes = new Class[args.length]; - for (int i = 0; i < args.length; i++) - classes[i] = args[i].getClass(); - } - if ((object instanceof String)) - return MethodUtils.invokeStaticMethod(Class.forName((String) object), methodName, args, classes); - return MethodUtils.invokeMethod(object, methodName, args, classes); - } catch (Exception e) { - log.info("invoke errr.", e); - } - return null; - } - - public static Object getProperty(Object object, String propertyName) { - try { - return PropertyUtils.getProperty(object, propertyName); - } catch (Exception e) { - log.info("getProperty", e); - } - return null; - } - - public static void setProperty(Object object, String propertyName, Object value) { - try { -// if ((object instanceof IModule)) -// ((IDatafield)((IModule)object).get(propertyName)).setValue(value); -// else - PropertyUtils.setProperty(object, propertyName, value); - } catch (Exception e) { - log.info("setProperty", e); - } - } - - public static String catPath(String path, String subPath) { - return new File(new File(path), subPath).getAbsolutePath(); - } - - public static List<String> listFiles(String path, String[] extensions) { - List list = new ArrayList(); - try { - for (File file : FileUtils.listFiles(new File(path), extensions, false)) - list.add(file.getAbsolutePath()); - } catch (Exception e) { - log.error(e.getMessage()); - } - return list; - } - - public static List<String> listDirectories(String path) { - List list = new ArrayList(); - try { - for (File file : new File(path).listFiles((FileFilter) DirectoryFileFilter.DIRECTORY)) - list.add(file.getAbsolutePath()); - } catch (Exception e) { - log.error(e.getMessage()); - } - return list; - } - - public static boolean clear(Object object) { - if (object == null) - return true; - if ((object instanceof IBaseObject)) - ((IBaseObject) object).clear(); - else if ((object instanceof Collection)) - ((Collection) object).clear(); - else if ((object instanceof Map)) - ((Map) object).clear(); - else if ((object instanceof IStream)) - ((IStream) object).close(); - else if ((object instanceof IDatafield)) { - if (!clear(((IDatafield) object).getValue())) - ((IDatafield) object).setValue(null); - } else if ((object instanceof IModule)) { - if (!clear(((IDatafield) object).getValue())) - MdaDriver.clearModule((IModule) object); - } else - return false; - return true; - } - - public static Date sqlDate(Date date, OpType type) { - Calendar c = Calendar.getInstance(); - c.setTime(date); - switch (type) { - case DESC: - case GE: - c.set(11, 23); - c.set(12, 59); - c.set(13, 59); - c.set(14, 999); - if (type == OpType.LT) - return new Timestamp(c.getTime().getTime()); - return new Date(c.getTime().getTime()); - case BETWEEN: - case EQ: - c.set(11, 0); - c.set(12, 0); - c.set(13, 0); - c.set(14, 0); - if (type == OpType.GT) - return new Timestamp(c.getTime().getTime()); - return new Date(c.getTime().getTime()); - } - return date; - } - - public static final List<String> loadLines(String fileName, String encoding) { - try { - FileInputStream fis = new FileInputStream(fileName); - List list = IOUtils.readLines(fis, encoding); - fis.close(); - return list; - } catch (Exception e) { - log.error("Read lines error.", e); - } - return Collections.EMPTY_LIST; - } - - public static final void saveLines(List<String> lines, String lineEnding, String fileName, String encoding) { - try { - IOUtils.writeLines(lines, "", new FileOutputStream(fileName), encoding); - } catch (Exception e) { - log.error("Save lines error.", e); - } - } - - public static final String loadContent(String fileName, String encoding) { - try { - FileInputStream fis = new FileInputStream(fileName); - String content = IOUtils.toString(fis, encoding); - fis.close(); - return content; - } catch (Exception e) { - log.error("Load content error.", e); - } - return null; - } - - public static final void saveContent(String content, String fileName, String encoding) { - try { - IOUtils.write(content, new FileOutputStream(fileName), encoding); - } catch (Exception e) { - log.error("Load content error.", e); - } - } - - private static final void resetQuietly(IStream s) { - try { - s.getInputStream().reset(); - } catch (IOException localIOException) { - } - } - - private static final Workbook getWorkbook(IStream s) { - Workbook wb = null; - try { - wb = new HSSFWorkbook(s.getInputStream()); - } catch (OfficeXmlFileException _) { - try { - resetQuietly(s); - wb = new XSSFWorkbook(s.getInputStream()); - } catch (IOException e) { - log.warn("load excel error.", e); - } - } catch (IOException e) { - log.warn("load excel error.", e); - } - resetQuietly(s); - return wb; - } - - public static final String[] loadExcelSheetNames(IStream s) { - Workbook wb = getWorkbook(s); - if (wb == null) - return null; - int count = wb.getNumberOfSheets(); - String[] sheetNames = new String[count]; - for (int i = 0; i < count; i++) - sheetNames[i] = wb.getSheetName(i); - resetQuietly(s); - return sheetNames; - } - - public static final int loadExcel(List<String[]> list, IStream s, int sheetIndex, int rowOffset, int rowMax, int columnOffset, int columnCount) { - Workbook wb = getWorkbook(s); - if (wb == null) - return -1; - if ((sheetIndex < 0) || (sheetIndex >= wb.getNumberOfSheets())) { - log.warn("load excel sheet with a illegal index."); - return -3; - } - Sheet sheet = wb == null ? null : wb.getSheetAt(sheetIndex); - if (sheet == null) { - log.warn("load excel sheet error."); - return -2; - } - - int rows = rowMax > 0 ? Math.min(rowMax, sheet.getLastRowNum() - rowOffset) : sheet.getLastRowNum() - rowOffset; - if (columnCount > 0) { - for (int i = 0; i <= rows; i++) { - Row row = sheet.getRow(i + rowOffset); - String[] values = new String[columnCount]; - for (int j = 0; j < columnCount; j++) { - if (row == null) { - values[j] = ""; - } else { - Cell cell = row.getCell(j + columnOffset); - values[j] = (cell != null ? getCellValue(cell, cell.getCellTypeEnum()) : ""); - } - } - list.add(values); - } - } - return rows; - } - - private static final String getCellValue(Cell cell, CellType type) { - switch (type) { - case FORMULA: - return getCellValue(cell, cell.getCachedFormulaResultTypeEnum()); - case ERROR: - return cell.getStringCellValue(); - case BOOLEAN: - int df = cell.getCellStyle().getDataFormat(); - - if ((df == 20) || (df == 32)) - return timeFormat.format(cell.getDateCellValue()); - if ((DateUtil.isInternalDateFormat(df)) || (df == 31) || (df == 57) || (df == 58) || (DateUtil.isCellDateFormatted(cell))) - return dateFormat.format(cell.getDateCellValue()); - return format.format(Double.valueOf(cell.getNumericCellValue())); - } - return cell.toString(); - } - - private static final int unloadExcel(Object value, Row row, int cellNum) { - Cell cell = row.createCell(cellNum); - if ((value != null) && ((value instanceof Number))) { - cell.setCellType(CellType.NUMERIC); - cell.setCellValue(((Number) value).doubleValue()); - } else { - cell.setCellType(CellType.STRING); - if ((value == null) || ((value instanceof String))) - cell.setCellValue((String) value); - else - cell.setCellValue(value.toString()); - } - return cellNum + 1; - } - - private static final void unloadExcel(List list, Sheet sheet) { - int rowNum = 0; - for (Iterator localIterator1 = list.iterator(); localIterator1.hasNext(); ) { - Object values = localIterator1.next(); - - Row row = sheet.createRow(rowNum); - int cellNum = 0; - if ((values instanceof Iterable)) { - for (Iterator localIterator2 = ((Iterable) values).iterator(); localIterator2.hasNext(); ) { - Object value = localIterator2.next(); - cellNum = unloadExcel(value, row, cellNum); - } - } else if ((values instanceof Object[])) { - for (Object value : (Object[]) values) - cellNum = unloadExcel(value, row, cellNum); - } - rowNum++; - } - } - - public static final void unloadExcel(List[] lists, String[] sheetNames, IStream s, boolean flag) { - Workbook wb = flag ? new XSSFWorkbook() : new HSSFWorkbook(); - OutputStream os = null; - try { - for (int i = 0; i < lists.length; i++) { - List list = lists[i]; - String sheetname = sheetNames[i]; - Sheet sheet = isEmpty(sheetname) ? wb.createSheet() : wb.createSheet(sheetname); - unloadExcel(list, sheet); - } - os = s.getOutputStream(); - wb.write(os); - os.flush(); - } catch (IOException e) { - log.error("unload Excel error.", e); - } finally { - closeQuietly(os); - closeQuietly(wb); - } - } - - public static final void unloadExcel(List list, IStream s, boolean flag) { - unloadExcel(new List[]{list}, new String[1], s, flag); - } - - public static final void generate(String templateFileName, String fileName, String exportType, Map params, Object data) { -// FileOutputStream fos = null; -// try { -// fos = new FileOutputStream(fileName); -// ReportUtils.generate(templateFileName, fos, exportType, params, data); -// } catch (Exception e) { -// log.error("Generate report error.", e); -// } finally { -// closeQuietly(fos); -// } - } - - public static final void generate(String templateFileName, IStream is, String exportType, Map params, Object data) { -// try { -// ReportUtils.generate(templateFileName, is.getOutputStream(), exportType, params, data); -// } catch (Exception e) { -// log.error("Generate report error.", e); -// } - } - - - public static final synchronized void createMutex(String name, int size) { - Semaphore semaphore = (Semaphore) mutexMap.get(name); - if (semaphore == null) { - semaphore = new Semaphore(size); - mutexMap.put(name, semaphore); - } - } - - public static final void releaseMutex(String name) { - Semaphore semaphore = (Semaphore) mutexMap.get(name); - if (semaphore != null) - semaphore.release(); - } - - public static final void acquireMutex(String name) { - Semaphore semaphore = (Semaphore) mutexMap.get(name); - if (semaphore != null) { - try { - semaphore.acquire(); - } catch (Exception e) { - log.info("acquireMutex '" + name + "' error.", e); - } - } - } - - public static final void forceDelete(File path) - throws IOException { - IOException exception = null; - for (int i = 0; i < 10; ) { - try { - FileUtils.forceDelete(path); - return; - } catch (IOException e) { - exception = e; - try { - Thread.sleep(1000L); - } catch (Exception localException) { - } - i++; - } - - } - - throw exception; - } - - public static final int getFormatLength(String format, int length) { - int index = format.indexOf('.'); - String str = ""; - if (index < 0) { - for (int i = 0; i < length; i++) - str = str + "1"; - } else { - int bits = format.length() - index; - for (int i = 0; i < length - bits + 1; i++) - str = str + "1"; - str = str + ("".equals(str) ? "0." : "."); - for (int i = 0; i < bits; i++) - str = str + "1"; - } - str = new DecimalFormat(format).format(new BigDecimal(str)); - return str.length(); - } - - public static final String combineStyle(String oldStyle, String style) { - if (isEmpty(oldStyle)) - return style; - if (isEmpty(style)) - return oldStyle; - return combineStyle(new StringBuffer(oldStyle), style).toString(); - } - - public static final StringBuffer combineStyle(StringBuffer oldStyle, String style) { - if (isEmpty(oldStyle)) - return oldStyle.append(style); - if (isEmpty(style)) { - return oldStyle; - } - oldStyle.insert(0, style + ";"); - String[] attributes = oldStyle.toString().split("\\;"); - oldStyle = new StringBuffer(); - List list = new ArrayList(); - for (String attribute : attributes) { - String[] pairs = attribute.split("\\:"); - if (pairs.length != 2) - continue; - String name = pairs[0].trim(); - if (list.contains(name)) - continue; - list.add(name); - oldStyle.append(name).append(":").append(pairs[1]).append(";"); - } - - return oldStyle; - } - - public static final String getWebType(IStream stream) { - String type = stream.getType(); - return isEmpty(type) ? "pdf" : type; - } - - public static final String getWebFileName(String browserType, IStream stream) { - try { - String name = stream.getName(); - if (isEmpty(name)) - name = "default." + getWebType(stream); - if (!autoConvert) - return name; - log.debug("Type of browser is:\t" + browserType); - if ((isEmpty(browserType)) || (browserType.contains("MSIE"))) - return URLEncoder.encode(name, "UTF-8"); - return new String(name.getBytes(), "ISO8859-1"); - } catch (Exception e) { - } - return "default." + getWebType(stream); - } - - public static boolean equals(String value1, String value2) { - if (value1 == null) - return value2 == null; - return value1.equals(value2); - } - - public static void exitRule() { - throw new RuleExitException("终止当前Rule"); - } - - public static List<CodetableItem> getCodetable(String codeName) { - return null; - } - - public static String encryptPassword(String srcPassword) { - return new String(DigestUtils.sha1(DigestUtils.md5(srcPassword))); - } - - public static void saveData(IModule module, IStream os) { - ObjectMapper mapper = new ObjectMapper(); - try { - mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); - mapper.writeValue(os.getOutputStream(), module); - } catch (Exception e) { - log.error("模型序列化异常", e); - } - } - - public static String getCodetableLabel(String codetable, String toString) { - return null; - } - - public static String getPath(IBaseObject baseObject) { - return baseObject.getPath(); - } - - public static void loadData(IModule module, IStream stream) { - ObjectMapper mapper = new ObjectMapper(); - try { - module.copyValues(mapper.readValue(stream.getInputStream(), module.getClass())); - } catch (Exception e) { - log.error("模型反序列化异常", e); - } - } - - public static String toJson(Object dataMap) { - ObjectMapper mapper = new ObjectMapper(); - try { - return mapper.writeValueAsString(dataMap); - } catch (Exception e) { - log.error("转换JSON异常", e); - } - return ""; - } - - public static <T> T fromJson(String json, Class<T> clazz) { - ObjectMapper mapper = new ObjectMapper(); - return mapper.convertValue(json, clazz); - } - - public static String covCnAmt(BigDecimal amt) { - try { - if (amt == null) - return ""; - String strAmt = amt.setScale(2, 4).toString(); - String[] number = {"壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"}; - String[] radices = {"仟", "", "拾", "佰"}; - String[] bigRadices = {"", "万", "亿", "万亿", "亿亿"}; - int idx = strAmt.indexOf("."); - String sInt = strAmt.substring(0, idx); - String sFlt = strAmt.substring(idx + 1); - String cn = ""; - int zeroC = 0; - int len = sInt.length(); - for (int i = 0; i < len; i++) { - if (sInt.charAt(i) == '0') { - zeroC++; - } else { - if (zeroC > 0) { - cn = String.valueOf(cn) + "零"; - zeroC = 0; - } - cn = String.valueOf(cn) + number[sInt.charAt(i) - 49]; - cn = String.valueOf(cn) + radices[(len - i) % 4]; - } - if ((len - i) % 4 == 1 && zeroC < 4) - cn = String.valueOf(cn) + bigRadices[(len - i) / 4]; - } - cn = String.valueOf(cn) + "元"; - if (sFlt.equals("00")) { - cn = String.valueOf(cn) + "整"; - } else { - if (!sFlt.substring(0, 1).equals("0")) { - cn = String.valueOf(cn) + number[sFlt.charAt(0) - 49] + "角"; - } else { - cn = String.valueOf(cn) + "零"; - } - if (!sFlt.substring(1, 2).equals("0")) - cn = String.valueOf(cn) + number[sFlt.charAt(1) - 49] + "分"; - } - log.debug("cn===" + cn); - return cn; - } catch (Exception e) { - log.error("covCnAmt error", e); - return ""; - } - } - - static String covEnAmt(BigDecimal amt) { - if (amt == null) - return ""; - String strAmt = amt.setScale(2, 4).toString(); - String[] words1 = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; - String[] words4 = {"hundred", "thousand", "million", "billion", "trillion"}; - int idx = strAmt.indexOf("."); - String sInt = strAmt.substring(0, idx); - String sFlt = strAmt.substring(idx + 1); - int lenZ = sInt.length(); - if (lenZ > 15) - return ""; - String en = ""; - if (lenZ > 12) { - String str = sInt.substring(0, lenZ - 9); - if (!"000".equals(str)) - en = String.valueOf(en) + convertdhundred(str) + " " + words4[4] + " "; - sInt = sInt.substring(lenZ - 9); - lenZ = sInt.length(); - } - if (lenZ > 9) { - String str = sInt.substring(0, lenZ - 9); - if (!"000".equals(str)) - en = String.valueOf(en) + convertdhundred(str) + " " + words4[3] + " "; - sInt = sInt.substring(lenZ - 9); - lenZ = sInt.length(); - } - if (lenZ > 6) { - String str = sInt.substring(0, lenZ - 6); - if (!"000".equals(str)) - en = String.valueOf(en) + convertdhundred(str) + " " + words4[2] + " "; - sInt = sInt.substring(lenZ - 6); - lenZ = sInt.length(); - } - if (lenZ > 3) { - String str = sInt.substring(0, lenZ - 3); - if (!"000".equals(str)) - en = String.valueOf(en) + convertdhundred(str) + " " + words4[1] + " "; - sInt = sInt.substring(lenZ - 3); - lenZ = sInt.length(); - } - String s = sInt; - if (!"000".equals(s)) - en = String.valueOf(en) + convertdhundred(s); - int lenF = sFlt.length(); - if (lenF > 0) { - String w2 = " "; - boolean allZero = true; - for (int i = 0; i < lenF; i++) { - int n = sFlt.charAt(i) - 48; - w2 = String.valueOf(w2) + words1[n] + " "; - if (n > 0) - allZero = false; - } - if (!"0".equals(s)) { - w2 = " and cents " + convertdhundred(sFlt); - } else { - w2 = " cents " + convertdhundred(sFlt); - } - if (!allZero) { - en = String.valueOf(en) + w2; - } else { - en = String.valueOf(en) + " only "; - } - } else { - en = String.valueOf(en) + " only "; - } - return en; - } - - static String convertdhundred(String s) { - String[] words1 = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; - String[] words2 = {"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", - "eighteen", "nineteen"}; - String[] words3 = {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"}; - String[] words4 = {"hundred", "thousand", "million", "billion"}; - char c1 = '0'; - char c2 = '0'; - char c3 = '0'; - if (s.length() > 2) { - c1 = s.charAt(0); - c2 = s.charAt(1); - c3 = s.charAt(2); - } else if (s.length() > 1) { - c1 = '0'; - c2 = s.charAt(0); - c3 = s.charAt(1); - } else if (s.length() > 0) { - c1 = '0'; - c2 = '0'; - c3 = s.charAt(0); - } - int n1 = c1 - 48; - int n2 = c2 - 48; - int n3 = c3 - 48; - String word = ""; - if (n1 > 0) - word = String.valueOf(word) + words1[n1] + " " + words4[0] + " "; - if (n1 != 0 && n2 == 0 && n3 != 0) - word = String.valueOf(word) + " and "; - if (n2 == 1) { - word = String.valueOf(word) + words2[n3] + " "; - } else if (n2 > 1) { - word = String.valueOf(word) + words3[n2] + " "; - if (n3 > 0) - word = String.valueOf(word) + words1[n3]; - } else if (n3 > 0) { - word = String.valueOf(word) + words1[n3]; - } - return word.trim(); - } - - private static I18n i18N = new I18NImpl(); - - public static String getI18NString(String moduleName, String key) { - Locale locale = MdaEnv.getLocale(); - - String desp = i18N.getString(locale, moduleName, key); - if (Strings.isEmpty(desp) || desp.startsWith("???")) { - if (locale == Locale.SIMPLIFIED_CHINESE) - desp = i18N.getString(Locale.US, moduleName, key); - else if (locale == Locale.US) - desp = i18N.getString(Locale.SIMPLIFIED_CHINESE, moduleName, key); - } - return desp; - } - - - public static boolean prompt(Object... o) { - return true; - } - - public static String generateSerialNum() { - return UUID.randomUUID().toString(); - } - - public static int compareTo(Object o1, Object o2) { - if (o1 instanceof Boolean) { - int var1 = o1.equals(Boolean.TRUE) ? 1 : 0; - return compareTo(var1, o2); - } - if (o2 instanceof Boolean) { - int var2 = o2.equals(Boolean.TRUE) ? 1 : 0; - return compareTo(o1, var2); - } - - //拆箱展开 - if (o1 instanceof Argument) { - o1 = ((Argument) o1).value; - } - //拆箱展开2 - if (o2 instanceof Argument) { - o2 = ((Argument) o2).value; - } - if (o1 == null && o2 == null) return 0; - if (o1 == null) { - if ("".equals(o2)) { - return 0; - } - return 1; - } - if (o2 == null) { - if ("".equals(o1)) { - return 0; - } - return -1; - } - //先做空判断,使 " " == "" - if (o1 instanceof String && o2 instanceof String) { - if (isEmpty(((String) o1).trim()) && isEmpty(((String) o2).trim())) - return 0; - return (((String) o1).trim()).compareTo(((String) o2).trim()); - } - - if (o1 instanceof String) - return (((String) o1).trim()).compareTo((String) o2); - else if (o1 instanceof Number && o2 instanceof Number) { - double i1 = ((Number) o1).doubleValue(); - double i2 = ((Number) o2).doubleValue(); - if (i1 > i2) - return 1; - else if (i1 == i2) - return 0; - else - return -1; - } else if (o1 instanceof BigDecimal && o2 instanceof Number) { - BigDecimal o2decimal = null; - if (o2 instanceof Double) { - o2decimal = new BigDecimal(Double.toString((Double) o2)); - } else if (o2 instanceof Long) { - o2decimal = new BigDecimal(Long.toString((Long) o2)); - } else if (o2 instanceof Float) { - o2decimal = new BigDecimal(Float.toString((Float) o2)); - } else - o2decimal = new BigDecimal(o2.toString()); - - return ((BigDecimal) o1).compareTo(o2decimal); - } else if (o1 instanceof Number && o2 instanceof BigDecimal) { - return -compareTo(o2, o1); - } else if (o1 instanceof BigDecimal && o2 instanceof BigDecimal) { - return (((BigDecimal) o1).compareTo((BigDecimal) o2)); - } else if (o1 instanceof TIMESTAMP && o2 instanceof TIMESTAMP) { - try { - return compareTo(((TIMESTAMP) o1).timestampValue(), ((TIMESTAMP) o2).timestampValue()); - } catch (Exception throwables) { - throw new IllegalArgumentException("不支持的比较类型!"); - } - } else if (o1 instanceof Date) - return (((Date) o1).compareTo((Date) o2)); - else if (o1 instanceof Byte) - return (((Byte) o1).compareTo((Byte) o2)); - else if (o1 instanceof Character) - return (((Character) o1).compareTo((Character) o2)); - else if (o1 instanceof Short) - return (((Short) o1).compareTo((Short) o2)); - else if (o1 instanceof Long) - return (((Long) o1).compareTo((Long) o2)); - else if (o1 instanceof Float) - return (((Float) o1).compareTo((Float) o2)); - else if (o1 instanceof Double) - return (((Double) o1).compareTo((Double) o2)); - else if (o1 instanceof IStream && o2 instanceof IStream) { - IStream is1 = (IStream) o1; - IStream is2 = (IStream) o2; - if (is1.getRows().size() == 0 && is2.getRows().size() == 0) - return 0; - if (is1.getRows().size() > is2.getRows().size()) - return 1; - else if (is1.getRows().size() < is2.getRows().size()) - return -1; - else { - for (int i = 0; i < is1.getRows().size(); i++) { - int diff = is1.getRows().get(i).compareTo(is2.getRows().get(i)); - if (diff != 0) - return diff; - } - return 0; - } - } else { - throw new IllegalArgumentException("不支持的比较类型!"); - } - } - - - /** - * @param name - * @param key - * @return - */ - public static String getI18nValue(String name, String key) { - return getI18NString(name, key); - } - - - /** - * todo - * - * @param path - * @return - */ - public static List<String> listFiles(String path) { - return null; - } - - /** - * todo - * - * @return - */ - public static String getDatasourceName() { - return ""; - } - - /** - * todo - * - * @return - */ - public static boolean isBackground() { - IContext ctx = MdaEnv.getContext(); - // ctx.getGui().isBackground() - return false; - } - - - /** - * todo - */ - public static void returnToFirst() { - IContext ctx = MdaEnv.getContext(); - // ctx.getGui().chain(Constants.FIRST); - } - - /** - * todo - * - * @return - */ - public static boolean isReturnCall() { - IContext ctx = MdaEnv.getContext(); - //ctx.getSession().isReturnCall() - return false; - } - - /** - * todo - */ - public static Object invokeEx(Object... o) { - IContext ctx = MdaEnv.getContext(); - // ctx.getSupport().invoke - return null; - } - - /** - * todo - * - * @param o - */ - public static void setValues(Object... o) { - - } - - /** - * todo - */ - public static void showMainPanel() { - } - - /** - * todo - */ - public static void resetModified(Object... o) { - } - - -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Modules.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Modules.java deleted file mode 100644 index 2df15e7..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Modules.java +++ /dev/null @@ -1,585 +0,0 @@ -package com.brilliance.mda.runtime.mda.util; - -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.driver.DCR; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.brilliance.mda.runtime.mda.driver.compile.component.AbstractAutoCompileEmitter; -import com.brilliance.mda.runtime.mda.driver.compile.component.AbstractAutoCompileScopeEmitter; -import com.brilliance.mda.runtime.mda.impl.AbstractScopeEmitter; -import com.brilliance.mda.runtime.mda.impl.Argument; -import com.brilliance.mda.runtime.mda.impl.ModuleList; -import com.brilliance.mda.support.td.ModuleInfoManager; -import com.brilliance.mda.support.td.TDFieldInfo; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; -import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; -import org.apache.commons.beanutils.MethodUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.core.io.support.ResourcePatternResolver; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; -import java.lang.reflect.ParameterizedType; -import java.math.BigDecimal; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static com.brilliance.mda.runtime.mda.Constants.*; - -public class Modules { - - private static final Logger log = LoggerFactory.getLogger(Modules.class); - - private static final Map<String, Method> staticPostMethodCache = new ConcurrentHashMap<>(); - private static final Map<String, Method> casecadeMethodCache = new ConcurrentHashMap<>(); - public static List<Class<?>> staticPostArea = new ArrayList<>(); - private static Method EMPTY_METHOD; - //暂时仅用于:为了实现invokeExpress,获取util目录下所有class - private static String utilPath = "com.brilliance.mda.runtime.mda.util"; - - static { - try { - staticPostArea.add(Platform_class); - //staticPostArea.add(Dynamic_class); - staticPostArea.addAll(getClasses(utilPath)); - EMPTY_METHOD = Modules.class.getMethod("clearPostQueue"); - } catch (ClassNotFoundException e) { - log.error(e.getMessage()); - } catch (IOException e) { - log.error(e.getMessage()); - } catch (NoSuchMethodException e) { - log.error(e.getMessage()); - } - } - - public static ObjectMapper getObjectMapper() { - ObjectMapper objectMapper = new ObjectMapper(); - SimpleFilterProvider filterProvider = new SimpleFilterProvider(); - // 在存盘的时候,不需要过滤字段,故 serializeAllExcept 不传参数 - SimpleBeanPropertyFilter fieldFilter = SimpleBeanPropertyFilter.serializeAllExcept(); - filterProvider.addFilter("fieldFilter", fieldFilter); - objectMapper.setFilterProvider(filterProvider); - return objectMapper; - } - - public static String module2Data(IBaseObject moduleOrList) { - ObjectMapper mapper = getObjectMapper(); - try { - String dataString = mapper.writeValueAsString(moduleOrList); - return dataString; - } catch (Exception e) { - - } - return null; - } - - public static Object data2Module(Class clazz, String dataString) { - ObjectMapper mapper = new ObjectMapper(); - try { - boolean isEnableNotify = DCR.isEnable(); - if (isEnableNotify) - DCR.enNotify(false); - Object obj = mapper.readValue(dataString, clazz); - if (isEnableNotify) - DCR.enNotify(true); - return obj; - } catch (Exception e) { - - } - return null; - } - - //ExecuteDefault - public static void postDefaultRule(IModule module, String field) { - if (field != null) { - if (module.getParent() instanceof IModuleList) { - //modulelist的儿子模型 - AbstractScopeEmitter scopeEmitter = DCR.getModuleListEmitter(((IModuleList) module.getParent()).getDataClass()); - scopeEmitter.acceptContext(module); - if (scopeEmitter instanceof AbstractAutoCompileScopeEmitter) { - ((AbstractAutoCompileScopeEmitter) scopeEmitter).executePostDefault(field); - } else { - scopeEmitter.executeDefault(field); - } - scopeEmitter.removeContext(); - } else { - String fieldPath = module.getFieldPath(field); - int leftCommas = fieldPath.indexOf('('); - if (leftCommas > -1) { - //modulelist的孙子模型 - int rightCommas = fieldPath.indexOf(leftCommas, ')'); - String relativePath = fieldPath.substring(rightCommas + 1); - //String moduleListPath = fieldPath.substring(0, leftCommas); - IModule parent = module.getParent(); - IModule scopeModule = module; - while (parent != null && !(parent instanceof IModuleList)) { - scopeModule = parent; - parent = parent.getParent(); - } - AbstractScopeEmitter scopeEmitter = DCR.getModuleListEmitter(((IModuleList) parent).getDataClass()); - scopeEmitter.acceptContext(scopeModule); - if (scopeEmitter instanceof AbstractAutoCompileScopeEmitter) { - ((AbstractAutoCompileScopeEmitter) scopeEmitter).executePostDefault(relativePath); - } else { - scopeEmitter.executeDefault(relativePath); - } - scopeEmitter.removeContext(); - } else { - if (MdaEnv.getContext().getEmitter() instanceof AbstractAutoCompileEmitter) { - ((AbstractAutoCompileEmitter) MdaEnv.getContext().getEmitter()).executePostDefault(fieldPath); - } else { - MdaEnv.getContext().getEmitter().executeDefault(fieldPath); - } - } - } - } else - MdaEnv.getContext().getEmitter().executeDefault(module.getPath()); - - } - - - public static void postDefaultRule(IModule t) { - postDefaultRule(t, null); - } - - - public static void executePostQueue() { - LinkedList<Map> linkedList = (LinkedList<Map>) MdaEnv.getContext().restoreData(tdContextPOSTQUEUE); - if (linkedList == null || linkedList.size() == 0) { - return; - } - // 在执行invokeExpress rule时候有可能还往队列里方,所以需要循环调用直到为空 - //建立计数器,防止无限循环 - int count = linkedList.size() + 15; - while (!linkedList.isEmpty() && linkedList.size() != 0) { - // 排序,先加入队列并且延迟数小的先执行 - count--; - if (count == 0) { - //队列一直有数,超过15次,不干了 - linkedList.clear(); - log.error("无限循环队列执行!!"); - break; - } - linkedList.sort((a, b) -> { - double delayA = (Double) a.get("delay"); - long putTimeA = (long) a.get("putTime"); - double delayB = (Double) b.get("delay"); - long putTimeB = (long) b.get("putTime"); - long delayAMillisecond = new BigDecimal(delayA).multiply(new BigDecimal(1000)).longValue(); - long delayBMillisecond = new BigDecimal(delayB).multiply(new BigDecimal(1000)).longValue(); - long timeTotalA = putTimeA + delayAMillisecond; - long timeTotalB = putTimeB + delayBMillisecond; - return Long.compare(timeTotalA, timeTotalB); - }); - // 采用pop方式拿取,按照顺序执行一个pop一个 - Map item = linkedList.pop(); - IModule module = (IModule) item.get("module"); - String rule = (String) item.get("rule"); - Double delay = (Double) item.get("delay"); - invokeExpress(module, rule, -1); - } - } - - public static void clearPostQueue() { - LinkedList<Map> linkedList = (LinkedList<Map>) MdaEnv.getContext().restoreData(tdContextPOSTQUEUE); - if (linkedList == null) { - return; - } - linkedList.clear(); - } - - //Post - public static void invokeExpress(IModule _this, String rule, double delay) { - if (rule == null || rule.length() == 0) { - return; - } - rule = rule.trim(); - LinkedList<Map> linkedList = (LinkedList<Map>) MdaEnv.getContext().restoreData(tdContextPOSTQUEUE); - if (linkedList == null) { - linkedList = new LinkedList<>(); - MdaEnv.getContext().storeData(tdContextPOSTQUEUE, linkedList); - } - if (delay >= 0) { - //>=0的情况,进入队列,不在当前Rule里面执行 - Map<String, Object> map = new HashMap<>(); - map.put("module", _this); - map.put("rule", rule); - map.put("delay", delay); - // 加入队列时间 - map.put("putTime", System.currentTimeMillis()); - linkedList.add(map); - return; - } - try { - //Rule分三段,belong,function,expressionList - String segItem = "\\w[\\w\\d]*"; - // 最复杂路径 \SETMOD\SETGLG\SETGLL(1).SETSUMS1 与checkStatement保持一致 - String pathReg = String.format("(\\\\)|([\\\\]?%s((\\\\%s)|(\\(\\d+\\)))*)", segItem, segItem); - String belongReg = String.format("(?<belong>%s)", pathReg); - String functionReg = "(?<func>\\w+)"; - String argsReg = "(?<args>.*)"; - String entireReg = String.format("(%s\\s*\\.\\s*)?%s\\s*(\\(%s\\))?", belongReg, functionReg, argsReg); - //System.out.println(entireReg); - Matcher m = Pattern.compile(entireReg).matcher(rule); - if (!m.find() || m.start() != 0) { - //TODO 错误,设置错误码 - MdaEnv.getContext().setErrorCode(-999); - return; - // String[] exprArr = getExpressions(expressionList); - } - String belong = m.group("belong"); - String function = m.group("func"); - String argsStr = m.group("args"); - - String[] args = Strings.splitArgumentsString(argsStr); - - if (belong != null) { - belong = belong.toLowerCase(); - IModule subModule = null; - if (belong.startsWith("\\")) - subModule = MdaDriver.getModule(belong); - else - subModule = MdaDriver.getModule(_this, belong); - //MdaDriver.getModule(belong); - if (subModule == null) { - MdaEnv.getContext().setErrorCode(999); - return; - } - Method method = findModuleMethod(_this, subModule.getClass(), function, args); - if (method != null) { - invokeExpressMethod(_this, subModule, method, args); - MdaEnv.getContext().setErrorCode(NO_ERROR); - return; - } - MdaEnv.getContext().setErrorCode(130); - } else { - //全局函数搜索 - Method method = searchStaticFunction(_this, function, args); - if (method != null) { - invokeExpressMethod(_this, null, method, args); //执行静态方法,Class传null - MdaEnv.getContext().setErrorCode(NO_ERROR); - return; - } - //先从当前模型找 - if (_this != null) { - method = findModuleMethod(_this, _this.getClass(), function, args); - if (method != null) { - invokeExpressMethod(_this, _this, method, args); - MdaEnv.getContext().setErrorCode(NO_ERROR); - return; - } - } - MdaEnv.getContext().setErrorCode(130); - //全局查找 - /*Argument moduleArg = new Argument(); - method = findCasecadeMethod(MdaEnv.getContext().getRoot(), _this, moduleArg, function, args); - if (method != null) { - IModule subModule = (IModule) moduleArg.value; - try { - invokeExpressMethod(_this, subModule, method, args); - MdaEnv.getContext().setErrorCode(NO_ERROR); - }catch (Exception e){ - MdaEnv.getContext().setErrorCode(130); - log.warn("执行非交易下的module中的方法!!!"); - } - return; - }else{ - MdaEnv.getContext().setErrorCode(130); - }*/ - } - log.debug("express cannot be executed:{}", rule); - } catch (RuleExecuteException re) { - throw re; - } catch (Exception e) { - //表达式执行失败 - //设置错误码 - log.error("表达式执行失败 : " + e.getMessage()); - MdaEnv.getContext().setErrorCode(999); - } - } - - private static List<Class<?>> getClasses(String packageName) - throws ClassNotFoundException, IOException { - // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - // assert classLoader != null; - // String path = packageName.replace('.', '/'); - // Enumeration<URL> resources = classLoader.getResources(path); - // List<File> dirs = new ArrayList<File>(); - // while (resources.hasMoreElements()) { - // URL resource = resources.nextElement(); - // dirs.add(new File(resource.getFile())); - // } - // ArrayList<Class> classes = new ArrayList<Class>(); - // for (File directory : dirs) { - // classes.addAll(findClasses(directory, packageName)); - // } - // return classes.toArray(new Class[classes.size()]); - - ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); - Resource[] resolverResources = resourceResolver.getResources(utilPath.replace(".", Files.separator) + "/**/*"); - List<Class<?>> classes = new ArrayList<>(); - for (Resource resource : resolverResources) { - String filename = resource.getFilename(); - if (filename.endsWith(".class")) { - classes.add(Class.forName(packageName + '.' + filename.substring(0, filename.length() - 6))); - } - } - return classes; - } - - private static List<Class> findClasses(File directory, String packageName) throws ClassNotFoundException { - List<Class> classes = new ArrayList<Class>(); - if (!directory.exists()) { - return classes; - } - File[] files = directory.listFiles(); - for (File file : files) { - if (file.isDirectory()) { - assert !file.getName().contains("."); - classes.addAll(findClasses(file, packageName + "." + file.getName())); - } else if (file.getName().endsWith(".class")) { - classes.add(Class.forName(packageName + '.' + file.getName().substring(0, file.getName().length() - 6))); - } - } - return classes; - } - //util目录下所有class的静态数组 -// public static Class[] utilClass = new Class[]{Archives.class, Caches.class, Databases.class, Datas.class, Dates.class, -// Decimals.class, Files.class, Formats.class, Grids.class, Inis.class, MdaUtils.class, MdaUtilsEx.class, Modules.class, -// Numerics.class, Reflects.class, Reports.class, Streams.class, Strings.class, Systems.class}; - - - private static void invokeExpressMethod(IModule _this, Object target, Method method, String[] args) throws InvocationTargetException, IllegalAccessException { - List argsList = new ArrayList(); - collectArguments(_this, method, args, argsList); - log.debug("invoke method:{} , args:{}", target, argsList); - method.invoke(target, argsList.toArray()); - //将使用到Argument的参数调用之后,赋值到被引用字段,专门应对给拼接的表达式里面带PATH的情况 - for (Object arg : argsList) { - if (arg instanceof Argument) { - Argument argument = (Argument) arg; - if (argument.attachField != null && argument.attachField instanceof IDatafield) { - ((IDatafield) argument.attachField).setValue(argument.value); - } - } - } - } - - public static Method findMethod(IModule _this, Class clazz, String methodName, String[] args) { - Method[] methods = clazz.getMethods(); - int argsLength = args == null ? 0 : args.length; - for (Method method : methods) { - if (method.getParameters().length != argsLength) - continue; - if (!method.getName().equalsIgnoreCase(methodName)) - continue; - //TODO 检验参数 - return method; - } - return null; - } - - public static Method findCasecadeMethod(IModule root, IModule _this, Argument outModule, String methodName, String[] args) { - String cacheKey = String.format("%s#%s#%s#%d", root == null ? "null" : root.getClass().getName(), - _this == null ? "null" : _this.getClass().getName(), methodName, args == null ? 0 : args.length); - if (casecadeMethodCache.containsKey(cacheKey)) { - return casecadeMethodCache.get(cacheKey); - } - Queue<IModule> stack = new LinkedList<>(); - stack.add(root); - Set<Class<?>> visited = new HashSet<>(); - while (!stack.isEmpty()) { - IModule module = stack.poll(); - Class<?> clazz = module.getClass(); - Method method = findModuleMethod(_this, clazz, methodName, args); - if (method != null) { - outModule.value = module; - casecadeMethodCache.put(cacheKey, method); - return method; - } - Map<String, TDFieldInfo> tdModules = ModuleInfoManager.getTDModules(clazz); - if (null != tdModules) { - for (TDFieldInfo fieldInfo : tdModules.values()) { - if (visited.contains(fieldInfo.getFieldType())) //已经访问过 - continue; - - try { - Method m = fieldInfo.getGetter(); - if (m != null) { - IModule subModule = (IModule) m.invoke(module); - stack.add(subModule); - } - visited.add(fieldInfo.getFieldType()); - } catch (Exception e) { - - } - } - } - } - return null; - } - - private static boolean collectArguments(IModule _this, Method m, String[] arr, List<Object> argsList) { - Parameter[] paramClazz = m.getParameters(); - if (arr == null) { - return paramClazz.length == 0; - } - if (paramClazz.length != arr.length) - return false; - - for (int i = 0; i < arr.length; i++) { - String item = arr[i]; - item = item.trim(); - - // MdaDriver.getBaseObject(null, "\\TRNMOD\\TRNDOC\\DOCEOT") - - //字符串 - if (paramClazz[i].getType().equals(Argument.class)) { - Class clazz = (Class) ((ParameterizedType) paramClazz[i].getParameterizedType()).getActualTypeArguments()[0]; - Argument argument = new Argument("", null); - Object val = wrapperValue(_this, item, clazz, argument); - argument.value = val; - argsList.add(argument); - } else { - Object val = wrapperValue(_this, item, paramClazz[i].getType(), null); - - argsList.add(val); - } - } - return true; - } - - private static Object wrapperValue(IModule _this, String val, Class basicClass, Argument argument) { - if ((val.charAt(0) == '"' && val.charAt(val.length() - 1) == '"') - || (val.charAt(1) == '\'' && val.charAt(val.length() - 1) == '\'')) - return val.substring(1, val.length() - 1); - if (basicClass.equals(BigDecimal.class)) - return new BigDecimal(val); - if (basicClass.equals(int.class) || basicClass.equals(Integer.class)) - return Integer.parseInt(val); - //path 路径,尝试从上下文中获取 - String path = val.toLowerCase(); - if (path.startsWith("\\")) { - IBaseObject baseObject = MdaDriver.getBaseObject(null, path); - if (argument != null) { - argument.attachField = baseObject; - } - if (baseObject instanceof IDatafield) - return ((IDatafield) baseObject).getValue(); - else - return baseObject; - } else { - //相对路径 - IBaseObject baseObject = MdaDriver.getBaseObject(_this, path); - if (argument != null) { - argument.attachField = baseObject; - } else { - //有可能是个空参数函数 - Method method = searchStaticFunction(_this, val, null); - if (method != null) { - try { - Object methodResult = method.invoke(null); - return methodResult; - } catch (Exception e) { - log.warn(e.getMessage()); - return null; - } - } - } - if (baseObject instanceof IDatafield) - return ((IDatafield) baseObject).getValue(); - else - return baseObject; - } - } - - private static Method searchStaticFunction(IModule _this, String methodName, String[] args) { - int argLength = 0; - if (args != null) { - argLength = args.length; - } - String key = methodName.toLowerCase() + "#" + argLength; - //先从缓存中查找 - Method method = staticPostMethodCache.get(key); - if (method != null) { - if (method == EMPTY_METHOD) { - //有缓存,但是EMPTY_METHOD代表找过为空 - return null; - } - return method; - } - for (Class<?> aClass : staticPostArea) { - method = findMethod(_this, aClass, methodName, args); - if (method != null) { - staticPostMethodCache.put(key, method); - return method; - } - } - //未找到,置为EMPTY_METHOD,避免频繁查找 - staticPostMethodCache.put(key, EMPTY_METHOD); - return null; - } - - public static Method findModuleMethod(IModule _this, Class clazz, String methodName, String[] args) { - int argsLength = args == null ? 0 : args.length; - Map<String, Method> methodMap = ModuleInfoManager.getAllPublicLowerCaseMethods(clazz); - if (null != methodMap) { - return methodMap.getOrDefault(methodName.toLowerCase() + "#" + argsLength, null); - } else { - return findMethod(_this, clazz, methodName, args); - } - } - - public static void postDefaultRule(IModule module, String field, boolean isModuleListItem) { - if (!isModuleListItem) { - postDefaultRule(module, field); - return; - } - AbstractScopeEmitter scopeEmitter = DCR.getModuleListEmitter(module.getClass()); - scopeEmitter.acceptContext(module); - if (scopeEmitter == null) { - return; - } - scopeEmitter.executeDefault(field); - } - - public static void invokeExpress(IModule _this, String path) { - invokeExpress(_this, path, -1); - } - - public static boolean exists(Object object, String methodName, Object... args) { - return exists(object, methodName, null, args); - } - - public static boolean exists(Object object, String methodName, Class[] classes, Object[] args) { - if (classes == null) { - classes = new Class[args.length]; - for (int i = 0; i < args.length; i++) - classes[i] = args[i].getClass(); - } - try { - if ((object instanceof String)) - return MethodUtils.getAccessibleMethod(Class.forName((String) object), methodName, classes) != null; - return MethodUtils.getAccessibleMethod(object.getClass(), methodName, classes) != null; - } catch (Exception e) { - } - return false; - } - - public static int Row(IModule _this) { - while (!(_this.getParent() instanceof ModuleList) && _this.getParent() != null) { - _this = _this.getParent(); - } - ModuleList parent = (ModuleList) _this.getParent(); - return parent.indexOf(_this) + 1; - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Reflects.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Reflects.java deleted file mode 100644 index 1e94cce..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Reflects.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.brilliance.mda.runtime.mda.util; - -import lombok.extern.slf4j.Slf4j; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -@Slf4j -public abstract class Reflects { - - public static <T> T fieldGet(Object obj, String name){ - try { - Field field = obj.getClass().getDeclaredField(name); - field.setAccessible(true); - Object result = field.get(obj); - return (T)result; - } catch (NoSuchFieldException | IllegalAccessException e) { - log.warn(String.format("get object %s[%s]属性值异常!",obj.toString(),name)); - return null; - } - } - - public static void fieldSet(Object obj, String name,Object val){ - try { - Field field = obj.getClass().getDeclaredField(name); - field.setAccessible(true); - field.set(obj,val); - } catch (NoSuchFieldException | IllegalAccessException e) { - log.warn(String.format("get object %s[%s]属性值异常!",obj.toString(),name)); - } - } - - public static Method getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) { - try { - return clazz.getMethod(methodName, parameterTypes); - } catch (Exception ignore) { - - } - return null; - } - - -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/RuleUtils.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/RuleUtils.java deleted file mode 100644 index 7f7cbbe..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/RuleUtils.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.brilliance.mda.runtime.mda.util; - -import com.brilliance.mda.runtime.mda.*; - -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -public class RuleUtils { - - static Comparator<IRule> c = new Comparator<IRule>() { - public int compare(IRule rule1, IRule rule2) { - return rule1.getOrder() - rule2.getOrder(); - } - }; - - static Comparator<IEventRule> c2 = new Comparator<IEventRule>() { - public int compare(IEventRule rule1, IEventRule rule2) { - if (rule1.getType().equals(rule2.getType())) - return rule1.getOrder() - rule2.getOrder(); - return rule1.getType().compareTo(rule2.getType()); - } - }; - - public static final void sort(List<IRule> rules) { - if (rules != null) - Collections.sort(rules, c); - } - - public static final InheritableThreadLocal<IContext> ctx = new InheritableThreadLocal<IContext>(); - - public static final boolean invoke(List<IRule> rules, IContext ctx, IAttributeValue av) { - if (rules == null) - return true; - boolean continued = true; - RuleUtils.ctx.set(ctx); - for (int i = 0; continued && i < rules.size(); i++) { - try { - continued = ((IRule) rules.get(i)).invoke(ctx, av); - } catch (Throwable e) { - if (!(e instanceof ExitEventException)) - continued = false; - } - } - return continued; - } - - public static final void sort2(List<IEventRule> rules) { - if (rules != null) - Collections.sort(rules, c2); - } - - public static final boolean invoke(List<IEventRule> rules, IContext ctx, Event event, int... orders) { - if (rules == null) - return true; - boolean continued = true; - RuleUtils.ctx.set(ctx); - boolean checkMinOrder = (orders != null && orders.length > 0); - boolean checkMaxOrder = (orders != null && orders.length > 1); - int minOrder = checkMinOrder ? orders[0] : 0; - int maxOrder = checkMaxOrder ? orders[1] : 0; - for (IEventRule rule : rules) { - if (rule.getType() == EventType.DEFAULT || rule.getType() == event.getType()) { - if ((checkMinOrder && rule.getOrder() < minOrder) || (checkMaxOrder && rule.getOrder() > maxOrder)) - continue; - try { - continued = rule.invoke(ctx, event); - } catch (Throwable e) { - if (!(e instanceof ExitEventException)) - continued = false; - } - if (!continued) - break; - } - } - return continued; - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Streams.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Streams.java deleted file mode 100644 index 0814888..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Streams.java +++ /dev/null @@ -1,295 +0,0 @@ -package com.brilliance.mda.runtime.mda.util; - -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.brilliance.mda.runtime.mda.impl.StreamImpl; -import com.brilliance.mda.runtime.request.SelectedParams; -import org.apache.commons.io.IOUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static com.brilliance.mda.runtime.mda.Constants.CR; - -public class Streams { - - private static final Logger log = LoggerFactory.getLogger(Streams.class); - - public static final void copy(InputStream is, OutputStream os) - throws IOException { - try { - IOUtils.copy(is, os); - } finally { - MdaUtils.closeQuietly(is); - MdaUtils.closeQuietly(os); - } - } - - public static final void copy(Reader reader, OutputStream os, Charset charset) - throws IOException { - try { - IOUtils.copy(reader, os, charset); - } finally { - MdaUtils.closeQuietly(reader); - MdaUtils.closeQuietly(os); - } - } - - //TODO - public static int streamCount(IStream stream) { - if (stream == null) return 0; - - return stream.countLines(); - } - - public static int streamSearch(IStream stream, String line) { - if (stream == null) return 0; - return stream.searchLine(line); - } - - public static String streamGetLine(IStream stream, int idx) { - return stream.getLine(idx); - } - - public static void streamSet(IStream src, Object dist) { - if (dist instanceof IStream) { - streamSetByIStream(src, (IStream) dist); - } else if (dist instanceof String) { - streamSetByString(src, (String) dist); - } - } - - public static void streamSetByIStream(IStream src, IStream dist) { - src.clearLines(); - dist.getRows().forEach(src::addLine); - } - - public static void streamSetByString(IStream src, String str) { - if (str == null || str.trim().isEmpty()) { - MdaUtils.clear(src); - return; - } - src.clearLines(); - String[] lines = str.split("[\\n]|\\r\\n"); - Arrays.stream(lines).forEach(line -> src.addLine(line)); - } - - public static void streamSet(IStream src, String str, int len) { - if (str == null || str.trim().isEmpty()) { - MdaUtils.clear(src); - return; - } - src.clearLines(); - String[] lines = str.split("[\\n]|\\r\\n"); - Arrays.stream(lines).forEach(line -> { - int begPos = 0; - while (begPos + len < line.length()) { - src.addLine(line.substring(begPos, begPos + len)); - begPos += len; - } - if (begPos < line.length()) { - src.addLine(line.substring(begPos)); - } - }); - } - - public static void streamSet(IStream src, String str, double len) { - streamSet(src, str, (int) len); - } - - public static void streamInsert(IStream stream, int idx, String line) { - if (stream == null) return; - stream.insertLine(idx, line); - } - - public static void streamDelete(IStream stream, int idx) { - stream.deleteLine(idx); - } - - - public static void streamClear(IStream stream) { - if (stream != null) { - //stream.close(); - stream.clearLines(); - } - } - - public static void getAttributeStream(IStream out, IStream dist, String attr) { - if (dist == null) { - return; - } - IStream tmp = dist.getAttribute(attr); - if (tmp == null || tmp.countLines() == 0) { - out.clearLines(); - return; - } - out.setRows(tmp.getRows()); - } - - public static void setAttributeStream(IStream dist, String attr, IStream value) { - dist.setAttribute(attr, value); - } - - public static void setSelectedLine(IStream stm, int idx) { - SelectedParams.setSelectedLine(stm, idx); - } - - public static int getSelectedLine(IStream stm) { - return SelectedParams.getSelectedLine(stm); - } - - public static void setSelectedRow(IModuleList<? extends IModule> list, int index) { - SelectedParams.setSelectedRow(list, index); - } - - public static int getSelectedRow(IModuleList<? extends IModule> list) { - return SelectedParams.getSelectedRow(list); - } - - public static int getSelectedRowIndex(IModuleList<? extends IModule> list) { - return getSelectedRow(list); - } - - public static String streamGetAdditional(IStream stm, String s1, String s2) { - switch (s1) { - case "ANNOTATION_TEXT": - break; - case "ANNOTATION_CLASS": - break; - case "ANNOTATION_HINT": - break; - case "ANNOTATION_USER": - break; - case "ANNOTATION_TIMESTAMP": - break; - case "ANNOTATION_COUNT": - break; - case "CHARDATA": - if (s2.equals("")) { - return stm.getValue(); - } - break; - case "RANGETEXT": - break; - case "SELRANGE": - break; - } - - return null; - } - - public static void streamSetAdditional(IStream stm, String insert, String insPos, String txt) { - } - - public static boolean streamPrint(IStream logstr) { - return true; - } - - public static List<String> streamStrSplit(String str) { - List<String> lines = new ArrayList<String>(); - if (str == null || str.length() == 0) - return lines; - if (str.indexOf("\r\n") == -1) - lines.add(str); - else { - lines.addAll(Arrays.asList(str.split("\r\n"))); - lines.remove(lines.size() - 1); - } - return lines; - } - - //前台方法空实现 - public static String promptStream(IStream stream, String caption, String values) { - MdaEnv.setGridData(caption, values, stream); - throw new RulePromptException("Propmt out"); - } - - public static void promptIModule(List<IModule> list) { - Class<? extends IModule> clazz = list.get(0).getClass(); - List<String> columnList = new ArrayList<>(); - IStream stm1 = new StreamImpl(); - String column = ""; - int i = 1; - for (Field declaredField : clazz.getDeclaredFields()) { - column = column + (i - 1) + " " + i + " \"" + declaredField.getName().toUpperCase() + "\"410" + CR; - columnList.add(declaredField.getName()); - i++; - } - for (int index = 0; index < list.size(); index++) { - IModule iModule1 = list.get(index); - Class<? extends IModule> clazzIModule = iModule1.getClass(); - StringBuilder stringBuilder = new StringBuilder(); - try { - for (String columnName : columnList) { - String getMethodName = "get" + columnName.substring(0, 1).toUpperCase() + columnName.substring(1); - Method m = clazzIModule.getMethod(getMethodName); - String vul = (String) m.invoke(iModule1); - stringBuilder.append(vul + "\t"); - } - } catch (Exception e) { - - } - Streams.streamInsert(stm1, index, stringBuilder.toString()); - - } - MdaEnv.setGridData(clazz.getSimpleName(), column, stm1); - throw new RulePromptException("Propmt out"); - } - - public static String promptStream(IStream stgStm, String grdHea, String grdVal, int parseInt, int parseInt1) { - Integer que = SelectedParams.getNomalSelected(); - if (que == 0) { - MdaEnv.setGridData(grdHea, grdVal, stgStm); - throw new RulePromptException("Propmt out"); - } - return stgStm.getLine(que); - } - - - /** - * 执行面函面板rule,并将面函模板内容保存至stream - * TODO 根据i的值实现不同类型的模板转换。 - * - * @param stream - * @param panel - * @param i - */ - public static void saveTextStream(IStream stream, IPanel panel, int i) { - MdaEnv.getContext().postRule(panel); - IDatafield<String> field = MdaDriver.getDatafield(panel.getPath() + "blk"); - if (field != null && Strings.notEmpty(field.getValue())) { - stream.addLine(field.getValue()); - } - } - - public static void saveTextStream(IStream stream, IPanel panel) { - } - - /** - * 将stream中的面函模板赋值给面板panel - * - * @param stm - * @param panel - * @param i - */ - public static void loadTextStream(IStream stm, IPanel panel, int i) { - String blkName = panel.getName() + "blk"; - IModule model = panel.getParent(); - if (model == null) { - model = MdaEnv.getContext().getRoot(); - } - Reflects.fieldSet(model, blkName, stm.getValue()); - } - -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Strings.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Strings.java deleted file mode 100644 index 1711773..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Strings.java +++ /dev/null @@ -1,316 +0,0 @@ -package com.brilliance.mda.runtime.mda.util; - -import com.brilliance.mda.runtime.mda.IDatafield; -import com.brilliance.mda.runtime.mda.IStream; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.math.BigDecimal; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.regex.Matcher; - -import static com.brilliance.mda.runtime.mda.Constants.NO_NAN; -import static com.brilliance.mda.runtime.mda.Constants.NULLSTR; - -public abstract class Strings { - - private static final Logger log = LoggerFactory.getLogger(Strings.class); - - public static boolean isEmpty(Object obj){ - return !notEmpty(obj); - } - - public static boolean notEmpty(Object obj){ - return obj !=null && !"".equals(obj.toString()); - } - - public static Integer toInt(Object obj){ - if(obj instanceof Integer){ - return (Integer) obj; - } - return notEmpty(obj) ? Integer.valueOf(obj.toString()) : null; - } - - - public static String rpad(String str,int len,char c){ - StringBuilder builder = new StringBuilder(); - for (int i = 0 ;i < str.length() ;i++) { - builder.append(str.charAt(i)); - } - for (int i = builder.length(); i < len; i++) { - builder.append(c); - } - return builder.toString(); - } - - public static String lpad(String str,int len,char c){ - StringBuilder builder = new StringBuilder(); - for (int i = 0 ;i < len-str.length() ; i++) { - builder.append(c); - } - for (int i=len-str.length(),j=0; i <len; i++,j++) { - builder.append(str.charAt(j)); - } - return builder.toString(); - } - - - public static String getLine(IStream stream, double idx) { - return getLine(stream, (int)idx); - } - public static String getLine(String block, int line) { - if(isEmpty(block)) - return NULLSTR; - String[] arr = block.split("[\\r\\n]{1,2}"); - if(line<= arr.length) - return arr[line-1]; - return NULLSTR; - } - public static String getLine(String block, double line) { - return getLine(block, (int)line); - } - - public static String trimEnd(String str, String endStr) { - if (str.endsWith(endStr)) { - return str.substring(0, str.lastIndexOf(endStr)); - } - return str; - } - - public static String leftTrim(String str) { - int pos = 0; - for (int i=0; i < str.length(); i++) { - if (str.charAt(i) != ' ') - { - pos = i; - break; - } - } - if (pos == 0) return str; - if (pos + 1 == str.length()) - return NULLSTR; - return str.substring(pos); - } - - public static String trim(Object obj) { - return obj == null ? NULLSTR : obj.toString().trim(); - } - - public static String toUpper(String text) { - return text == null ? NULLSTR : text.toUpperCase(); - } - - public static String toLower(String text) { - return text == null ? NULLSTR : text.toLowerCase(); - } - - - /** - * 使用GBK编码表进行字符串的截取,一个英文字符对应码表一个正数,一个汉字对应两个负数 - **/ - public static String cutStringByByte(String str, int start ,int len) - throws IOException { - byte[] buf = str.getBytes("gbk"); - int count = 0; - for (int x = len - 1; x >= start; x--) { - if (buf[x] < 0) { - count++; - } else { - break; - } - } - if (count % 2 == 0) { - return new String(buf, 0, len, "gbk"); - } else { - return new String(buf, 0, len - 1, "gbk"); - } - } - - - //从消息系统中检索消息,参数M是要检索消息的标识符。如果所检索的消息文本中包含有“$n”,那么可选参数就给“$n”赋值。 - public static String getText(String format, Object... args) { - return formatText(format, args); - } - - public static String formatText(String format, Object... args) { - if (format == null) return NULLSTR; - if (args == null || args.length == 0) - return format; - for (int i = 0; i < args.length; i++) { - String key = "\\$" + (i + 1); - String arg = args[i] == null ? "null" : args[i].toString(); - arg = Matcher.quoteReplacement(arg); - format = format.replaceAll(key, arg); - } - return format; - } - - - //前台方法空实现 - public static String convertBlock(String block, int convtype, int lines, int linelength) { - return block; - } - - public static String convertBlock(String block, int convtype, int lines) { - return block; - } - - public static String convertBlock(String argBlock, int i) { - switch (i) { - case 0: - break; - case 11: - argBlock.replace("<", "<"); - argBlock.replace(">", ">"); - argBlock.replace("&", "&"); - break; - case 21: - break; - default: - break; - } - return argBlock; - } - - public static String[] splitArgumentsString(String argsString) { - if (argsString == null) - return null; - List<String> argList = new ArrayList<>(); - boolean strflag = false; //是否处于字符串中 - boolean charflag = false; - int segPos = 0; - for (int i = 0; i < argsString.length(); i++) { - char c = argsString.charAt(i); - if(c == '"'){ - if(!charflag){ - strflag = !strflag; - } - } - else if(c == '\''){ - if(!strflag) { - charflag = !charflag; - } - } - else if(c == '\\'){ //转义符号 - //字符串模式下忽略下一个字符 - if(strflag || charflag) { - i++; - } - } - else if(c == ','){ - if(!strflag && !charflag){ - argList.add(argsString.substring(segPos,i)); - segPos = i+1; - } - } - //末尾一个 - if(i == argsString.length() - 1){ - argList.add(argsString.substring(segPos)); - } - } - return argList.toArray(new String[0]); - } - - public static void setLine(String block, int i, String s2) { - } - - public static int searchBlock(String valCur, String inCur) { - return valCur.indexOf(inCur) + 1; - } - - - public static final int parseInt(Object value) { - try { - if(isEmpty(value)){ - return 0; - } - if ((value instanceof IDatafield)) - return parseInt(((IDatafield) value).getValue()); - if ((value instanceof String)) - return new BigDecimal(((String) value).trim()).intValue(); - if (value instanceof BigDecimal) - return ((BigDecimal)value).intValue(); - return new BigDecimal(value.toString()).intValue(); - } catch (Exception e) { - log.warn(String.format("value:[%s] not a int",value),e); - MdaEnv.getContext().setErrorCode(NO_NAN); - } - return 0; - } - - public static final BigDecimal parseDecimal(Object value) { - - try { - if ((value instanceof IDatafield)) - return parseDecimal(((IDatafield) value).getValue()); - if ((value instanceof String)){ - if(isEmpty(value)){ - return BigDecimal.ZERO; - } - return new BigDecimal((String) value); - } - - return new BigDecimal(value.toString()); - } catch (Exception e) { - log.error(String.format("value:[%s] not a number",value),e); - MdaEnv.getContext().setErrorCode(NO_NAN); - } - return BigDecimal.ZERO; - } - - public static final Boolean parseBoolean(Object value, Boolean defaultValue) { - if (value == null) - return defaultValue; - try { - if ((value instanceof IDatafield)) - return parseBoolean(((IDatafield) value).getValue(), defaultValue); - if ((value instanceof Boolean)) - return (Boolean) value; - return Boolean.valueOf(Boolean.parseBoolean(value.toString())); - } catch (Exception e) { - } - return defaultValue; - } - - public static final Date parseDate(String val) { - if (val == null || val.length() == 0){ - return null; - } - if (val.indexOf("/") >= 0){ - String[] split = val.split("/"); - if (split.length >= 3){ - val = split[2] + "-" + split[1] + "-" + split[0]; - }else{ - return null; - } - } - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - Date date = null; - try { - date = simpleDateFormat.parse(val); - } catch (ParseException e) { - e.printStackTrace(); - } - return date; - } - - public static final Date parseDate(Object value, String pattern) { - if (value == null) - return null; - try { - if ((value instanceof IDatafield)) - return parseDate(((IDatafield) value).getValue(), pattern); - String v = (value instanceof String) ? (String) value : value.toString(); - SimpleDateFormat format = new SimpleDateFormat(pattern); - return format.parse(v); - } catch (Exception e) { - } - return null; - } -} \ No newline at end of file diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Systems.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Systems.java deleted file mode 100644 index 6b99e30..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/mda/util/Systems.java +++ /dev/null @@ -1,1031 +0,0 @@ -package com.brilliance.mda.runtime.mda.util; - -import com.brilliance.mda.runtime.annotation.RelPath; -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.brilliance.mda.runtime.mda.driver.compile.component.ModuleRuleContext; -import com.brilliance.mda.runtime.mda.driver.compile.processor.ModuleAnnotationProcess; -import com.brilliance.mda.runtime.mda.impl.Argument; -import com.brilliance.mda.runtime.mda.impl.DatafieldImpl; -import com.brilliance.mda.runtime.mda.impl.ModuleList; -import com.brilliance.mda.runtime.mda.impl.StreamImpl; -import com.brilliance.mda.support.td.ModuleInfoManager; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.codec.digest.DigestUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.SystemUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.math.BigDecimal; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static com.brilliance.mda.runtime.mda.Constants.*; -import static com.brilliance.mda.runtime.mda.driver.MdaDriver.getBaseObject; - -public class Systems { - - private static final Logger log = LoggerFactory.getLogger(Systems.class); - - public static void setAttribute(IDatafield field, String ATTR, Object val) { - setAttribute(field.getParent(), field.getName(), ATTR, val); - } - - public static int getAttribute(IDatafield field, String ATTR) { - return getAttribute(field.getParent(), field.getName(), ATTR); - } - - public static int getAttribute(IModule parent, String prop, String ATTR) { - Object val = getAttributeValue(parent, prop, ATTR); - if (val == null) - return 0; - if (val instanceof Integer) - return (Integer) val; - if (val instanceof Boolean) { - return (Boolean) val ? 1 : 0; - } - if (val instanceof String) { - if ("Visible".equals(val) || "Enabled".equals(val)) { - return 1; - } - } - return 0; - } - - public static <T> T getAttributeValue(IModule parent, String prop, String ATTR) { - if (parent == null) { - MdaEnv.getContext().setErrorCode(-1); - } - if (ATTR == null) { - MdaEnv.getContext().setErrorCode(-2); - } - if ("".equals(ATTR)) { - MdaEnv.getContext().setErrorCode(102); - } - if (tdAttrName.equals(ATTR)) - return (T) prop.toUpperCase(); - if (tdAttrFullName.equals(ATTR)) { - String fieldPath = parent.getFieldPath(prop); - return (T) fieldPath; - } - if (tdAttrVisible.equals(ATTR)) { - return (T) (Systems.isVisible(parent, prop) ? "Visible" : "Invisible"); - } - if (tdAttrEnabled.equals(ATTR)) { - return (T) (Systems.isEnabled(parent, prop) ? "Enabled" : "Disabled"); - } - if (tdAttrDecpos.equals(ATTR)) { - //TODO - } - if (tdAttrLines.equals(ATTR)) { - return (T) new Integer(100); - } - if (tdAttrLength.equals(ATTR)) { - return (T) new Integer(100); - } - if (tdAttrDatatype.equals(ATTR)) { - IDatafield datafield = MdaDriver.getDatafield(parent, prop); - if (datafield != null) { - Class<T> dataType = (Class<T>) datafield.getDataType(); - if (dataType == String.class) { - return (T) new Integer(1); - } else if (dataType == BigDecimal.class || dataType == Long.class || dataType == Integer.class) { - return (T) new Integer(2); - } else if (dataType == Date.class) { - return (T) new Integer(4); - } else if (dataType == IStream.class) { - return (T) new Integer(7); - } else if (dataType == long.class) { - return (T) new Integer(2); - } - } else {// 默认返回字符串类型 - return (T) new Integer(1); - } - } - if (tdAttrViewtype.equals(ATTR)) { - //TODO - } - if (tdAttrFieldViewtype.equals(ATTR)) { - //TODO - } - if (tdAttrModified.equals(ATTR)) { - Object attribute = MdaEnv.getContext().getAttribute(parent, prop, ATTR); - if (attribute == null) { - return (T) Integer.valueOf(0); - } - return (T) attribute; - } - if (tdAttrCalendar.equals(ATTR)) { - IDatafield datafield = MdaDriver.getDatafield(parent, prop); - if (!(datafield.getValue() instanceof Date)) { - MdaEnv.getContext().setErrorCode(171); - } - if (MdaEnv.getContext().getAttribute(parent, prop, ATTR) == null) { - return (T) NULLSTR; - } - } - if (tdAttrCodetable.equals(ATTR)) { - Map<String, Object> itemInfo = ModuleInfoManager.getModuleFieldInfo(parent.getClass().getSimpleName().toLowerCase(), prop); - return (T) itemInfo.get("codetable"); - } - if (tdAttrCurrency.equals(ATTR)) { - IDatafield datafield = MdaDriver.getDatafield(parent, prop); - if (datafield != null) { - Class<T> dataType = (Class<T>) datafield.getDataType(); - if (!(dataType == BigDecimal.class || dataType == Long.class || dataType == Integer.class)) { - MdaEnv.getContext().setErrorCode(171); - } - } - if (MdaEnv.getContext().getAttribute(parent, prop, ATTR) == null) { - return (T) NULLSTR; - } - } - if (tdAttrInfo.equals(ATTR)) { - //TODO - } - if (tdAttrContent.equals(ATTR)) { - IDatafield datafield = MdaDriver.getDatafield(parent, prop); - if (datafield != null) { - return (T) datafield.getValue(); - } - } - if (tdAttrFirstValue.equals(ATTR)) { - String list = getAttributeValue(parent, prop, tdAttrKeyList); - if (list != null) { - String[] split = list.split("\r\n"); - return (T) split[0]; - } - } - if (tdAttrKeyList.equals(ATTR)) { - //TODO - List<CodetableItem> codeTable = Codetables.getCodeTable(prop, Systems.getLang()); - StringBuilder sb = new StringBuilder(); - if (!codeTable.isEmpty()) { - for (CodetableItem item : codeTable) { - sb.append(item.getValue() + "\r\n"); - } - return (T) sb.toString(); - } - } - if (tdAttrCodeValues.equals(ATTR)) { - //TODO - } - return MdaEnv.getContext().getAttribute(parent, prop, ATTR); - } - - public static void setAttribute(IModule parent, String prop, String ATTR, Object val) { - MdaEnv.getContext().setAttribute(parent, prop, ATTR, val); - } - - public static void setAttributeText(IModule parent, String prop, String ATTR, Object val) { - MdaEnv.getContext().setAttribute(parent, prop, ATTR, val); - } - - public static void setAttributeText(Date date, String prop, String ATTR) { - if (null != date) { - MdaEnv.getContext().setAttribute(null, date.toString(), prop, ATTR); - } - } - - public static void setValues(IModule parent, String prop, IStream values) { - setValuesToContextSet(parent, prop, values); - MdaEnv.getContext().setAttribute(parent, prop, AttrType.VALUES.name(), values); - } - - public static void setValuesToContextSet(IModule parent, String prop, IStream values) { - //拦截做values专项处理 - String key = null; - if (MdaEnv.getContext().getRoot() == parent) { - key = prop; - } else { - key = parent.getPath().replaceAll("\\\\", "\\.") + "." + prop; - key = key.substring(1).toLowerCase(); - } - if (values != null && !(key.endsWith("sdamod.dadrcv") || key.endsWith("sdamod.dadsnd")) && hasField(MdaEnv.getContext().getVo(), key.replaceAll("\\.", "_"))) { - MdaEnv.getContext().getValuesSet().put(key, new CodeEntity(key, values.getRows(), false)); - } - } - - public static void setValues(IModule parent, String prop, String values) { - IStream stream = new StreamImpl(); - Streams.streamSet(stream, values); - setValues(parent, prop, stream); - } - - public static void setValues(IDatafield datafield, IStream values) { - setValues(datafield.getParent(), datafield.getName(), values); - } - - public static void setValues(IDatafield datafield, String values) { - setValues(datafield.getParent(), datafield.getName(), values); - } - - public static IStream getValues(IModule parent, String prop) { - Object attribute = MdaEnv.getContext().getAttribute(parent, prop, AttrType.VALUES.name()); - if (attribute instanceof IStream) { - return (IStream) attribute; - } else if (attribute instanceof Map) { - Map map = (Map) attribute; - List<String> rows = (List<String>) map.get("rows"); - IStream result = new StreamImpl(); - result.getRows().addAll(rows); - return result; - } - return (IStream) attribute; - } - - public static IStream getValues(IDatafield datafield) { - //If no framefields exist for datafield, the positive (critical) error code 111 is set. - if (MdaUtils.isEmpty(datafield.getParent())) { - MdaEnv.getContext().setErrorCode(Constants.tdDataParentIsNull); - return new StreamImpl(); - } - IStream stream = getValues(datafield.getParent(), datafield.getName()); - if (stream == null) - stream = new StreamImpl(); - return stream; - } - - public static void setModified(IDatafield field) { - setModified(field.getParent(), field.getName()); - } - - public static void setModified(IModule parent, String prop) { - MdaEnv.getContext().setAttribute(parent, prop, AttrType.MODIFIED.name(), Boolean.TRUE); - } - - public static void resetModified(IModule module) { - resetModified(module.getParent(), module.getName()); - } - - public static void resetModified(IDatafield field) { - resetModified(field.getParent(), field.getName()); - } - - public static void resetModified(IModule parent, String prop) { - MdaEnv.getContext().setAttribute(parent, prop, AttrType.MODIFIED.name(), Boolean.FALSE); - } - - public static void resetModified(IStream stream) { - stream.setAttribute(AttrType.MODIFIED.name(), Boolean.FALSE); - } - - public static boolean checkModuleHasModified(IModule module) { - if (module == null) { - return false; - } - Map<String, Object> attrMaps = module.getAttrMaps(); - for (String s : attrMaps.keySet()) { - if (s.endsWith("MODIFIED") || s.endsWith("modified")) { - return true; - } - } - Field[] declaredFields = module.getClass().getDeclaredFields(); - for (Field field : declaredFields) { - if ("_parent".equals(field.getName())) { - continue; - } - if (IModule.class.isAssignableFrom(field.getType())) { - try { - field.setAccessible(true); - IModule o = (IModule) field.get(module); - if (checkModuleHasModified(o)) { - return true; - } - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - } - return false; - } - - public static boolean checkIsFieldHolder(IModule root, String prop) { - Field[] declaredFields = root.getClass().getDeclaredFields(); - for (Field declaredField : declaredFields) { - if (prop.equals(declaredField.getName())) { - return declaredField.getType().isAssignableFrom(FieldHolder.class); - } - } - return false; - } - - public static boolean isModified(IModule parent, String prop) { - if ("".equals(prop)) { - return checkModuleHasModified(parent); - } - if (checkIsFieldHolder(parent, prop)) { - IBaseObject baseObject = getBaseObject(parent, prop); - try { - DatafieldImpl datafield = (DatafieldImpl) baseObject; - Field field = datafield.getClass().getDeclaredField("field"); - Field parentField = datafield.getClass().getDeclaredField("parent"); - field.setAccessible(true); - parentField.setAccessible(true); - FieldHolder fieldHolder = (FieldHolder) ((Field) field.get(datafield)).get(parentField.get(datafield)); - String holderPath = fieldHolder.getPath(); - if (StringUtils.isBlank(holderPath)) { - return false; - } - if (holderPath.contains("\\")) {//modle ,且有parent时 - int indexOf = holderPath.lastIndexOf("\\"); - IModule m = (IModule) getBaseObject(null, holderPath.substring(0, indexOf)); - if (m != null) { - return isModified(m, holderPath.substring(indexOf + 1)); - } - } else { - return isModified(MdaEnv.getContext().getRoot(), holderPath); - } - //原代码:return isModified((IDatafield) getBaseObject(null, baseObject.getPath())); - } catch (NoSuchFieldException | IllegalAccessException e) { - e.printStackTrace(); - } - //( ((DatafieldImpl) baseObject).field.get(((DatafieldImpl) baseObject).parent)).getPath() - } - Object obj = MdaEnv.getContext().getAttribute(parent, prop, AttrType.MODIFIED.name()); - if (obj == null) { - return false; - } - if (obj instanceof Integer) { - return (Integer) obj != 0; - } - return obj == null ? false : (Boolean) obj; - } - - public static boolean isModified(IDatafield field) { - return isModified(field.getParent(), field.getName()); - } - - public static void resetEnabled(IDatafield field) { - resetEnabled(field.getParent(), field.getName()); - } - - public static void resetEnabled(IModule parent, String prop) { - MdaEnv.getContext().setAttribute(parent, prop, AttrType.ENABLED.name(), Boolean.FALSE); - } - - public static void setEnabled(IDatafield field) { - setEnabled(field.getParent(), field.getName()); - } - - public static void setEnabled(IModule parent, String prop) { - MdaEnv.getContext().setAttribute(parent, prop, AttrType.ENABLED.name(), Boolean.TRUE); - } - - public static void setEnabled(IModule parent, String... props) { - for (String prop : props) { - MdaEnv.getContext().setAttribute(parent, prop, AttrType.ENABLED.name(), Boolean.TRUE); - } - } - - public static void resetEnabled(IModule parent, String... props) { - for (String prop : props) { - MdaEnv.getContext().setAttribute(parent, prop, AttrType.ENABLED.name(), Boolean.FALSE); - } - } - - public static boolean isEnabled(IModule parent, String prop) { - - if (!isPanel(parent, prop) && !hasField(MdaEnv.getContext().getVo(), getVoFieldName(parent, prop))) { - return false; - } - - Object obj = MdaEnv.getContext().getAttribute(parent, prop, AttrType.ENABLED.name()); - if (obj == null) { - Map<String, Object> infoMap = ModuleInfoManager.getModuleFieldInfo(parent.getClass().getSimpleName().toLowerCase(), prop); - if (infoMap != null && Boolean.FALSE.equals(infoMap.getOrDefault("enabled", true))) { - MdaEnv.getContext().setErrorCode(Constants.tdDataTypeNil); - return false; - } - //不用随便添加错误码 - //MdaEnv.getContext().setErrorCode(111); - } - return obj == null ? true : (Boolean) obj; - } - - public static boolean isEnabled(IDatafield field) { - //If no framefield exist for the field, the function returns FALSE and error code 111 is set. - if (MdaUtils.isEmpty(field.getParent())) { - MdaEnv.getContext().setErrorCode(Constants.tdDataParentIsNull); - return false; - } - return isEnabled(field.getParent(), field.getName()); - } - - public static boolean isPanel(IModule parent, String prop) { - IBaseObject baseObject = getBaseObject(parent, prop); - return baseObject instanceof IPanel || baseObject instanceof IControl; - } - - public static void resetVisible(IModule parent, String prop) { - MdaEnv.getContext().setAttribute(parent, prop, AttrType.VISIABLE.name(), Boolean.FALSE); - } - - public static void resetVisible(IModuleList parent, String prop) { - //MdaEnv.getContext().setAttribute(parent, prop,AttrType.VISIABLE.name(),Boolean.FALSE); - } - - public static void resetVisible(IPanel panel) { - } - - public static void resetVisible(IDatafield panel) { - } - - public static void setVisible(IPanel panel) { - if (panel == null) { - return; - } - setVisible(panel.getParent(), panel.getName()); - } - - public static void setVisible(IModule parent, String prop) { - if (parent == null) { - return; - } - MdaEnv.getContext().setAttribute(parent, prop, AttrType.VISIABLE.name(), Boolean.TRUE); - } - - public static void setVisible(IModuleList parent, String prop) { - //MdaEnv.getContext().setAttribute(parent, prop,AttrType.VISIABLE.name(),Boolean.TRUE); - } - - public static <T> void setVisible(IDatafield<T> value) { - setVisible(value.getParent(), value.getName()); - } - - public static boolean isVisible(IModule parent, String prop) { - if (!isPanel(parent, prop) && !hasField(MdaEnv.getContext().getVo(), getVoFieldName(parent, prop))) { - return false; - } - Object obj = MdaEnv.getContext().getAttribute(parent, prop, AttrType.VISIABLE.name()); - if (obj == null) { - Map<String, Object> infoMap = ModuleInfoManager.getModuleFieldInfo(parent.getClass().getSimpleName().toLowerCase(), prop); - if (infoMap != null) { - if (Boolean.FALSE.equals(infoMap.get("visible"))) { - return false; - } - } - //MdaEnv.getContext().setErrorCode(111); - } - return obj == null ? true : (Boolean) obj; - } - - private static Map<String, String> voFieldsMap = new ConcurrentHashMap<>(); - - public static boolean hasField(Object vo, String field) { - String prefix = vo.getClass().getName() + "_"; - int idx = field.indexOf('('); - if (idx > -1) { - field = field.substring(0, idx); - } - if (!voFieldsMap.containsKey(prefix)) { - Arrays.stream(vo.getClass().getDeclaredFields()).forEach( - e -> { - String fieldName = e.getName(); - if (e.isAnnotationPresent(RelPath.class)) { - RelPath relPath = e.getAnnotation(RelPath.class); - if (!MdaUtils.isEmpty((relPath.value()))) { - fieldName = relPath.value().replaceAll("\\.", "_"); - } - } - voFieldsMap.put(prefix + fieldName, "1"); - } - ); - voFieldsMap.put(prefix, "1"); - } - return voFieldsMap.containsKey(prefix + field); - } - - - //默认返回1(yes) - public static int promptYesNo(String message) { - return 1; - } - - public static int promptYesNo(String s, String rtnTxt) { - return 1; - } - - public static int promptYesNo(String s, int a, int b, String rtnTxt) { - return 1; - } - - public static void setEnabled(IPanel panel) { - } - - public static void resetEnabled(IPanel panel) { - } - - public static String signature(String str, int i) { - return macGen(str, i); - } - - public static String macGen(String text, int startval) { - String data = startval + text; - String s = DigestUtils.sha1Hex(DigestUtils.md5(data)).substring(0, 8); - return s; - } - - public static String macGen(IStream str, int startval) { - - String data = str.getRows().stream().reduce("", (acc, item) -> acc + item); - return macGen(data, startval); - } - - public static <T> T cast(Class<T> clazz, Object value) { - if (value == null) { - MdaEnv.getContext().setErrorCode(789); - return null; - } else if (clazz != value.getClass()) { - MdaEnv.getContext().setErrorCode(789); - return null; - } - MdaEnv.getContext().setErrorCode(NO_ERROR); - return (T) value; - } - - public static void logText(String filename, String text) { - if (filename == null || text == null) return; - File f = new File(filename); - if (f.isDirectory()) - throw new IllegalArgumentException("filename必须是一个文件!"); - if (!f.getParentFile().exists()) - f.getParentFile().mkdirs(); - - BufferedWriter out = null; - try { - if (!f.exists()) { - f.createNewFile(); - } - out = new BufferedWriter(new FileWriter(f)); - out.append(text); - } catch (IOException e) { - throw new IllegalArgumentException(e.getMessage()); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - } - - public static void setContext(String key, Object... obj) { - if (key == null) return; - MdaEnv.setSessionContext(key, obj); - } - - public static String getContext(String key) { - if (key == null) return NULLSTR; - if (tdContextCALLSTACK.equalsIgnoreCase(key)) { - return MdaEnv.getContext().getConcurrentCallStack(); - } - if (tdContextDBDRIVERNAME.equals(key)) - return "ORACLE"; - if (tdContextPOSTQUEUE.equals(key)) { - LinkedList<Map> linkedList = (LinkedList<Map>) MdaEnv.getContext().restoreData(tdContextPOSTQUEUE); - if (linkedList == null) - return NULLSTR; - Optional<String> result = linkedList.stream().map(m -> m.get("rule").toString().toUpperCase()).reduce((a, b) -> a + "\n" + b); - if (result.isPresent()) - return result.get(); - return NULLSTR; - } - if (tdContextDBSERVICENAME.equals(key)) { - return "DSN=sstfcebnew;UID=sstfcebnew;PWD=<protected>;DBQ=SSTF;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;BTD=F;BNF=F;BAM=IfAllSuccessful;NUM=NLS;DPM=F;MTS=T;MDI=F;CSR=F;FWC=F;FBS=64000;TLO=O;MLD=0;ODA=F;"; - } - if (tdContextLANGUAGE.equals(key)) - return getLang(); - - if (tdContextLASTUSERACTIONTIME.equals(key)) { //返回上一次操作的毫秒级时间日期 - //每次请求时会添加一个时间进入。 - } - if (tdContextFORM.equals(key))//返回上一次操作的毫秒级时间日期 - return new Date().toString(); - Object obj = MdaEnv.getSessionContextValue(key); - return obj == null ? NULLSTR : obj.toString(); - } - - public static String getContext(String key, String str) { - if (key == null) key = NULLSTR; - if (str == null) str = NULLSTR; - return MdaEnv.getSessionContextValue(key + ":" + str); - } - - public static void getContextStream(IStream stm, String str) { - } - - public static void status(String format, Object... obj) { - String message = Strings.getText(format, obj); - log.info(message); - } - - public static boolean checkStatement(IModule _this, String rule) { - try { - //Rule分三段,belong,function,expressionList - rule = rule.trim(); - int eqAssign = rule.indexOf("="); - if (eqAssign > 0) - rule = rule.substring(eqAssign + 1).trim(); - String segItem = "\\w[\\w\\d]*"; - // 最复杂路径 \SETMOD\SETGLG\SETGLL(1).SETSUMS1 与invokeExpress保持一致 - String pathReg = String.format("(\\\\)|([\\\\]?%s((\\\\%s)|(\\(\\d+\\)))*)", segItem, segItem); - String belongReg = String.format("(?<belong>%s)", pathReg); - String functionReg = "(?<func>\\w+)"; - String argsReg = "(?<args>.*)"; - String entireReg = String.format("(%s\\s*\\.\\s*)?%s\\s*(\\(%s\\))?", belongReg, functionReg, argsReg); - //System.out.println(entireReg); - Matcher m = Pattern.compile(entireReg).matcher(rule); - if (!m.find() || m.start() != 0) { - return false; - } - String belong = m.group("belong"); - String function = m.group("func"); - String argsStr = m.group("args"); - - String[] args = Strings.splitArgumentsString(argsStr); - - if (belong != null) { - belong = belong.toLowerCase(); - IModule subModule = null; - if (belong.startsWith("\\")) - subModule = MdaDriver.getModule(belong); - else - subModule = MdaDriver.getModule(_this, belong); - //MdaDriver.getModule(belong); - if (subModule == null) { - return false; - } - Method method = Modules.findMethod(_this, subModule.getClass(), function, args); - if (method != null) { - //invokeExpressMethod(_this, subModule, method, args); - return true; - } - } else { - - //全局函数搜索 - Method method = Modules.findMethod(_this, Platform_class, function, args); - if (method != null && isMethodInContext(true, method)) { - //invokeExpressMethod(_this, null, method, args); - return true; - } -// method = Modules.findMethod(_this, Dynamic_class, function, args); -// if (method != null && isMethodInContext(false, method)) { -// //invokeExpressMethod(_this, null, method, args); -// return true; -// } - //先从当前模型找 - if (_this != null) { - method = Modules.findMethod(_this, _this.getClass(), function, args); - if (method != null) { - //invokeExpressMethod(_this, _this, method, args); - return true; - } - } - //全局查找 - Argument moduleArg = new Argument(); - method = Modules.findCasecadeMethod(MdaEnv.getContext().getRoot(), _this, moduleArg, function, args); - if (method != null) { - - return true; - } - } - } catch (Exception e) { - //e.printStackTrace(); - //表达式执行失败 - //设置错误码 - e.printStackTrace(); - } - return false; - } - - public static boolean isMethodInContext(boolean globalOrStatic, Method m) { - String methodKey = ModuleRuleContext.getMethodKey(m); - ModuleRuleContext moduleRuleContext = ModuleAnnotationProcess.cache.get(MdaEnv.getContext().getEmitter().getModuleName()); - if (globalOrStatic) { - return moduleRuleContext.getGlobalMethod().containsKey(methodKey); - } else { - return moduleRuleContext.getStaticMethod().containsKey(methodKey); - } - } - - public static String getAttributeText(IDatafield field, String ATTR) { - return getAttributeValue(field.getParent(), field.getName(), ATTR); - } - - public static String getAttributeText(IModule parent, String prop, String ATTR) { - return getAttributeValue(parent, prop, ATTR); - } - - public static String expandEnv(String str) { - if (str == null || str.length() == 0 || str.indexOf("%") < 0) { - return str; - } - StringBuilder sb = new StringBuilder(); - StringBuilder temp = new StringBuilder(); - char[] s = str.toCharArray(); - int j = 0; - for (int i = 0; i < s.length; ) { - if (s[i] != '%') { - sb.append(s[i]); - i++; - } else { - j = i + 1; - while (j < s.length && s[j] != '%') { - temp.append(s[j]); - j++; - } - sb.append(System.getenv().get(temp.toString())); - temp.setLength(0); - i = j + 1; - } - } - return sb.toString(); - } - - - public static void ReInit() { - } - - public static String getAdditional(IDatafield argFld) { - return ""; - } - - //前台方法空实现 - public static void postDelete(String queLin) { - } - - //前台方法空实现 - public static void setTitle(String str) { - } - - public static int sockOpen(String socketseve, String socketport) { - return 0; - } - - public static void sockCall(int fd, IStream inStream, IStream outStream) { - } - - public static void sockClose(int fd) { - } - - public static IPanel getPanel(String str) { - - IBaseObject baseObject = getBaseObject(null, str); - if (!(baseObject instanceof IPanel)) { - MdaEnv.getContext().setErrorCode(Constants.NO_SUCH_FIELD); - return null; - } - return (IPanel) baseObject; - } - - public static void winExec(String dest) { - } - - public static void winExec(String dest, boolean bool) { - } - - public static void winExec(String dest, boolean bool, int no) { - } - - //前台方法空实现 - public static void pause(int code) { - //空实现 - } - - public static void pause(BigDecimal code) { - //空实现 - } - - - //前台方法空实现 - public static void popupTitledFrame(Object o, String title) { - if (o instanceof IPanel) { - String path = ((IPanel) o).getPath(); - log.debug("执行{}-Panel:{} rule", title, path); - MdaEnv.getContext().postRule(((IPanel) o)); - } - } - - public static void popupTitledFrame(Object o, String title, boolean b) { - popupTitledFrame(o, title); - } - - public static void setActivePanel(IPanel panel) { - } - - public static void setActivePanel(IPanel panel, boolean b) { - } - - //前台方法空实现 - //SaveDisplay - public static void saveDisplayToStream(IStream stream) { - Object requestVo = MdaEnv.getContext().restoreData(IContext.DISPLAY_KEY); - ObjectMapper objectMapper = Modules.getObjectMapper(); - try { - //写入到流中 - String jsonVo = objectMapper.writeValueAsString(requestVo); - stream.addLine(jsonVo); - } catch (Exception e) { - log.error("快照写入错误:{}", e); - } - } - - //前台方法空实现 - //SetStyle - public static void setTDStyle(Object... objects) { - } - - //前台方法空实现 - public static void shellExec(String destfile, String download) { - } - - //前台方法空实现 - public static <T> void setFocusField(IDatafield<T> field) { - } - - //前台方法空实现 - public static <T> void setFocusField(String extKey) { - } - - public static void recalc() { - } - - public static void recalc(IModuleList list) { - } - - public static void recalc(IModule grp) { - } - - public static void recalc(String selusr) { - } - - public static void recalc(IStream selusr) { - } - - public static void recalc(IDatafield datafield) { - } - - public static void recalc(String flt, String selusg, String selusr, String selusgset) { - } - - public static void recalc(BigDecimal src) { - } - - //前台方法空实现 - public static void showNotifyMessage(int num, String s) { - } - - public static void showNotifyMessage(double num, String s) { - } - - public static void showDisplay(String str) { - } - - public static void showDisplay(IStream image) { - } - - public static void showDisplay(IStream ascin, String title) { - } - - public static void redisplay() { - } - - public static void redisplay(String msg) { - } - - public static void redisplay(IModule module) { - } - - //前台方法空实现 - public static void setDescription(IPanel p, String s) { - } - - public static void setDescription(String target, String s) { - } - - public static void setDescription(IDatafield p, String s) { - } - - public static String getDescription(IDatafield d) { - return NULLSTR; - } - - public static String getDescription(IPanel errPan, int i) { - return NULLSTR; - } - - //前台方法空实现 - public static void stopVideo() { - } - - public static void startVideo() { - } - - //前台方法空实现 - public static void showHelpText(String getFocusFieldPos, String hlp) { - } - - //前台方法空实现 - public static final String lineFeed = "\r\n"; - public static final String langList = "EN" + lineFeed + "IT" + lineFeed + "FR" + "CN" + lineFeed + "DE" + lineFeed + "SP" + lineFeed + "VN" + lineFeed + "TH"; - - public static String getPanelInfo(IPanel pan, String attr) { - if (pan == null) { - return NULLSTR; - } - if (tdPanelName.equals(attr)) { - return getPanelInfo(pan, 1); - } - if (tdPanelFullName.equals(attr)) { - return getPanelInfo(pan, 2); - } - return NULLSTR; - } - - public static String getPanelInfo(IPanel pan, int attr) { - if (pan == null) { - return NULLSTR; - } - switch (attr) { - case 1: - return pan.getName(); - case 2: - return pan.getPath(); - case 3: - //TODO - break; - case 4: - //TODO - break; - case 5: - return getLang(); - case 6: - //返回该面板支持的语种,暂时返回所有可支持的语种 - return langList; - case 7: - //TODO - break; - case 8: - //TODO - break; - case 9: - //TODO - break; - case 10: - //TODO - break; - case 11: - //TODO - break; - } - return NULLSTR; - } - - //前台方法空实现 - public static void showAboutPicture(String s) { - } - - public static void setIcon(String icoName) { - // Association association = new Association(); - // association.setIconFileName(icoName); - } - - public static String getVoFieldName(IModule parent, String prop) { - StringBuffer buf = new StringBuffer(prop); - IModule m = parent; - while (m != MdaEnv.getContext().getRoot() && m != null) { - if (m instanceof ModuleList) { - buf.setLength(0); - } else { - buf.insert(0, m.getName() + "_"); - } - m = m.getParent(); - } - if (buf.charAt(buf.length() - 1) == '_') { - buf.deleteCharAt(buf.length() - 1); - } - return buf.toString(); - } - - public static boolean isUnix() { - return SystemUtils.IS_OS_UNIX; - } - - public static String getLang() { - return MdaEnv.getLang(); - } - -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/request/CheckedParams.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/request/CheckedParams.java deleted file mode 100644 index e25ab42..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/request/CheckedParams.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.brilliance.mda.runtime.request; - -import com.brilliance.mda.runtime.mda.IBaseObject; -import com.brilliance.mda.runtime.mda.IDatafield; -import com.brilliance.mda.runtime.mda.IStream; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; -import com.brilliance.mda.runtime.mda.impl.StreamImpl; - -import java.util.List; - -import static com.brilliance.mda.runtime.mda.Constants.tdAttrChecked; -import static com.brilliance.mda.runtime.mda.Constants.tdAttrCheckedIdx; - -public class CheckedParams { - - public static final String CHK_IDS ="chkIds"; - public static final String CHK_DST="chkDst"; - - public static void checkedParamsInit(BaseVO req) { - List<Integer> chkIds = null; - String chkDst = null; - if(req.getParams().containsKey(CHK_IDS)){ - chkIds = (List<Integer>) req.getParams().get(CHK_IDS); - } - if(req.getParams().containsKey(CHK_DST)){ - chkDst = (String)req.getParams().get(CHK_DST); - } - if(chkDst == null){ - return ; - } - IBaseObject dist = MdaDriver.getBaseObject(null,chkDst); - if(dist == null){ - return ; - } - if(dist instanceof IDatafield){ - Object val = ((IDatafield)dist).getValue(); - if(!(val instanceof IStream)){ - return; - } - IStream distStm = (IStream)val; - IStream selStm = new StreamImpl(); - IStream selIdsStrem = new StreamImpl(); - for (int i = 0; i <chkIds.size(); i++) { - selStm.addLine(distStm.getLine(chkIds.get(i))); - selIdsStrem.addLine(String.valueOf(chkIds.get(i))); - } - distStm.setAttribute(tdAttrChecked,selStm); - distStm.setAttribute(tdAttrCheckedIdx,selIdsStrem); - } - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/request/SelectedParams.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/request/SelectedParams.java deleted file mode 100644 index 4ed42cc..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/request/SelectedParams.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.brilliance.mda.runtime.request; - -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.brilliance.mda.runtime.mda.impl.StreamImpl; -import com.brilliance.mda.runtime.mda.util.Strings; -import com.brilliance.mda.runtime.mda.util.Systems; - -import java.util.List; - -import static com.brilliance.mda.runtime.mda.Constants.*; - -public class SelectedParams { - - public static final String SEL_IDS ="selIds"; - public static final String SEL_DST="selDst"; - public static final String SEL_BTN_ID="selBtnId"; - - public static final String ButtonIndex = "ButtonIndex"; - public static final String ButtonId = "ButtonId"; - - - public static void selectedParamsInit(BaseVO req){ - List<Integer> selIds = null; - String selDst = null; - if(req.getParams().containsKey(SEL_IDS)){ - selIds = (List<Integer>) req.getParams().get(SEL_IDS); - } - if(req.getParams().containsKey(SEL_DST)){ - selDst = (String)req.getParams().get(SEL_DST); - } - - if(selIds == null || selIds.size() == 0){ - return ; - } - int tdSel = selIds.get(0); - if(Strings.isEmpty(selDst)){ - setNomalSelected(tdSel); - return; - } - IBaseObject dist = MdaDriver.getBaseObject(null,selDst); - if(dist == null){ - return ; - } - - if(dist instanceof IModuleList){ - setSelectedRow((IModuleList)dist,tdSel); - return; - } - if(dist instanceof IDatafield){ - Object val = ((IDatafield)dist).getValue(); - if(!(val instanceof IStream)){ - return; - } - IStream distStm = (IStream)val; - IStream selStm = new StreamImpl(); - IStream selIdsStrem = new StreamImpl(); - for (int i = 0; i <selIds.size(); i++) { - selStm.addLine(distStm.getLine(selIds.get(i))); - selIdsStrem.addLine(String.valueOf(selIds.get(i))); - } - distStm.setAttribute(tdAttrSelected,selStm); - distStm.setAttribute(tdAttrSelectedIdx,selIdsStrem); - - Systems.setAttribute(dist.getParent(),dist.getName(),ButtonIndex,selIds.get(0)); - String selBtnId = ""; - if(req.getParams().containsKey(SEL_BTN_ID)){ - selBtnId = (String) req.getParams().get(SEL_BTN_ID); - Systems.setAttribute(dist.getParent(),dist.getName(),ButtonId,selBtnId); - } - } - } - - public static String buildSelKey(Object obj,String ATTR){ - return obj.toString()+ATTR; - } - - public static void setSelectedLine(IStream stm,int idx){ - IStream selected = MdaEnv.getContext().getParam(buildSelKey(stm,tdAttrSelectedIdx)); - if(selected == null){ - selected = new StreamImpl(); - stm.setAttribute(tdAttrSelectedIdx,selected); - }else{ - selected.getRows().clear(); - } - selected.getRows().add(String.valueOf(idx)); - } - public static int getSelectedLine(IStream stream){ - IStream selected = stream.getAttribute(tdAttrSelectedIdx); -// IStream selected = MdaEnv.getContext().getParam(buildSelKey(stream,tdAttrSelectedIdx)); - if(selected == null || selected.isEmpty()){ - return 0; - } - return Integer.valueOf(selected.getRows().get(0)); - } - - public static void setSelectedRow(IModuleList<? extends IModule> list, int index) { - MdaEnv.getContext().setAttribute(list,"SELECT_INDEX","index",index); - } - - public static int getSelectedRow(IModuleList<? extends IModule> list) { - Integer idx = (Integer) MdaEnv.getContext().getAttribute(list,"SELECT_INDEX","index"); - return idx == null?0:idx; - } - - public static int getSelectedRowIndex(IModuleList<? extends IModule> list) { - return getSelectedRow(list); - } - - public static void setNomalSelected(int index){ - MdaEnv.getContext().setParam("SELECTED_INDEX_NOMAL",index); - } - public static Integer getNomalSelected(){ - Integer idx = MdaEnv.getContext().getParam("SELECTED_INDEX_NOMAL"); - if(idx == null){ - return 0; - } - return idx; - } - -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/response/ResponseSet.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/response/ResponseSet.java deleted file mode 100644 index e541135..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/runtime/response/ResponseSet.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.brilliance.mda.runtime.response; - -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import com.brilliance.mda.runtime.mda.IContext; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; - -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown = true) -public class ResponseSet<T> { - - /** - * 成功代码 - */ - public static final String CODE_SUCCESS="AAAAAA"; - public static final String MSG_SUCESS="操作成功!"; - - private String respCode; - private String respMsg; - private Map<String,String> fieldErrors; - private Map<String, List<String>> codeSet; - private Object data; - - public ResponseSet(IContext ctx, Object t){ - this.respCode = CODE_SUCCESS; - this.respMsg = MSG_SUCESS; - this.data = t; - fieldErrors = cloneFieldErrorsFromContext(ctx); - this.codeSet = getValuesSet(ctx); - ctx.visitValues(); - MdaDriver.setValueToVO(ctx, this.data); - } - private Map<String, List<String>> getValuesSet(IContext ctx){ - Map<String, List<String>> valuesSet = new LinkedHashMap<>(); - ctx.getValuesSet().forEach((key, codeEntity)->{ - if(!codeEntity.visited){ - valuesSet.put(key,codeEntity.values); - } - }); - return valuesSet; - } - - private Map<String,String> cloneFieldErrorsFromContext(IContext ctx){ - if(ctx == null){ - return null; - } - Map<String,String> fieldErrors = ctx.getFieldErrors(); - Map<String,String> fieldErrorsClone = new LinkedHashMap<>(); - fieldErrorsClone.putAll(fieldErrors); - fieldErrors.clear(); - return fieldErrorsClone; - } - - public ResponseSet(Object t){ - this.respCode = CODE_SUCCESS; - this.respMsg = MSG_SUCESS; - if(MdaEnv.getContext()!=null) { - fieldErrors = cloneFieldErrorsFromContext(MdaEnv.getContext()); - this.codeSet = getValuesSet(MdaEnv.getContext()); - MdaEnv.getContext().visitValues(); - } - this.data = t; - } - - public ResponseSet(String errCode,String errMsg){ - this.respCode = errCode; - this.respMsg = errMsg; - if(MdaEnv.getContext()!=null) { - fieldErrors = cloneFieldErrorsFromContext(MdaEnv.getContext()); - this.codeSet = getValuesSet(MdaEnv.getContext()); - MdaEnv.getContext().visitValues(); - } - } - - // public ResponseSet(String errCode,String errMsg,Map<String,String> fieldErrors){ -// this(errCode,errMsg); -// this.fieldErrors = fieldErrors; -// } - public ResponseSet(String errCode,String errMsg,T t){ - this(errCode,errMsg); - this.data = t; - if(t!=null) { - MdaDriver.setValueToVO(MdaEnv.getContext(), this.data); - } - } - public Object getData() { - return data; - } - public void setData(Object data) { - this.data = data; - } - - public String getRespCode() { - return respCode; - } - - public void setRespCode(String respCode) { - this.respCode = respCode; - } - - public String getRespMsg() { - return respMsg; - } - - public void setRespMsg(String respMsg) { - this.respMsg = respMsg; - } - - public Map<String, String> getFieldErrors() { - return fieldErrors; - } - - public void setFieldErrors(Map<String, String> fieldErrors) { - this.fieldErrors = fieldErrors; - } - - public Map<String, List<String>> getCodeSet() { - return codeSet; - } - - public void setCodeSet(Map<String, List<String>> codeSet) { - this.codeSet = codeSet; - } - - static class BooleanResult{ - boolean result; - public BooleanResult(boolean result){ - this.result = result; - } - } - static final String FAIL_CODE = "999999"; - public static ResponseSet fail(String message) { - ResponseSet responseSet = new ResponseSet(FAIL_CODE,message); - return responseSet; - } - public static ResponseSet simpleSuccess(Object data){ - return new ResponseSet(data); - } - -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/cache/CacheConfiguration.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/cache/CacheConfiguration.java deleted file mode 100644 index f0085f0..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/cache/CacheConfiguration.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.brilliance.mda.support.cache; - -import com.brilliance.mda.runtime.mda.IAuthInfo; -import com.brilliance.mda.runtime.mda.IContext; -import com.brilliance.mda.support.cache.impl.GuavaCache; -import com.brilliance.mda.support.cache.impl.RedisCache; -import com.brilliance.mda.support.cache.serializer.ICacheSerializer; -import com.brilliance.mda.support.cache.serializer.ICacheSerializerEnum; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; -import org.springframework.data.redis.serializer.StringRedisSerializer; - -import javax.annotation.Resource; - -@Configuration -public class CacheConfiguration { - - private static final Logger logger = LoggerFactory.getLogger(CacheConfiguration.class); - - @Resource - private RedisTemplate<String, Object> redisTemplate; - - @Value("${envconfig.cache.serializer:kryo}") - private String cacheSerializerType; - @Value("${envconfig.cache.expireAfterAccess:300}") - private long expireAfterAccess; - - @Bean("ctxCache") - @ConditionalOnProperty(prefix = "envconfig.cache", name = "type", havingValue = "guava", matchIfMissing = true) - public ICache<String, IContext> getGuavaCtxCache() { - //2h timeout - logger.info("使用Guava作为Context缓存"); - return new GuavaCache<>("CtxCache", expireAfterAccess); - } - - @Bean("ctxCache") - @ConditionalOnProperty(prefix = "envconfig.cache", name = "type", havingValue = "redis") - public ICache<String, IContext> getRedisCtxCache() { - //2h timeout - ICacheSerializer cacheSerializer = getCacheSerializer(); - logger.info("使用Redis作为Context缓存,序列化处理器:{}", cacheSerializer.getName()); - this.redisTemplate.setKeySerializer(new StringRedisSerializer()); - this.redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer()); - return new RedisCache<>("CtxCache", redisTemplate, cacheSerializer, expireAfterAccess); - } - - @Bean("ctxCacheSerializer") - public ICacheSerializer getCacheSerializer() { - return ICacheSerializerEnum.getSerializer(cacheSerializerType); - } - - @Bean("authCache") - @ConditionalOnProperty(prefix = "envconfig.cache", name = "type", havingValue = "guava", matchIfMissing = true) - public ICache<String, IAuthInfo> getGuavaAuthCache() { - return new GuavaCache<>("AuthCache", expireAfterAccess); - } - - @Bean("authCache") - @ConditionalOnProperty(prefix = "envconfig.cache", name = "type", havingValue = "redis") - public ICache<String, IAuthInfo> getRedisAuthCache() { - ICacheSerializer cacheSerializer = getCacheSerializer(); - logger.info("使用Redis作为Auth缓存,序列化处理器:{}", cacheSerializer.getName()); - this.redisTemplate.setKeySerializer(new StringRedisSerializer()); - this.redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer()); - return new RedisCache<>("AuthCache", redisTemplate, cacheSerializer, expireAfterAccess); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/cache/impl/GuavaCache.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/cache/impl/GuavaCache.java deleted file mode 100644 index 54069f4..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/cache/impl/GuavaCache.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.brilliance.mda.support.cache.impl; - -import com.brilliance.mda.support.cache.ICache; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.time.Duration; -import java.util.UUID; - -public class GuavaCache<V> implements ICache<String, V> { - - private final Logger logger = LoggerFactory.getLogger(GuavaCache.class); - - private final LoadingCache<String, V> cache; - private String cacheName; - - public GuavaCache(String cacheName, long seconds) { - this.cacheName = cacheName; - cache = CacheBuilder.newBuilder() - .expireAfterAccess(Duration.ofSeconds(seconds)) - .build(new CacheLoader<String, V>() { - @Override - public V load(String s) throws Exception { - return null; - } - }); - } - - @Override - public String store(V v) { - String key = generateKey(); - cache.put(key, v); - return key; - } - - @Override - public void store(String key, V v) { - cache.put(key, v); - } - - @Override - public V get(String k) { - try { - return cache.get(k); - } catch (Exception e) { - logger.warn("Acquire {} cache failed", cacheName); - } - return null; - } - - @Override - public void remove(String k) { - cache.invalidate(k); - } - - @Override - public String generateKey() { - return UUID.randomUUID().toString(); - } - - @Override - public void cleanup() { - logger.info("{} clean up start.size:{}",this.cacheName,cache.size()); - this.cache.cleanUp(); - logger.info("{} clean up over.size:{}",this.cacheName,cache.size()); - } - - @Override - public boolean contains(String key) { - return this.get(key) != null; - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/cache/impl/RedisCache.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/cache/impl/RedisCache.java deleted file mode 100644 index 4617c70..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/cache/impl/RedisCache.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.brilliance.mda.support.cache.impl; - -import com.brilliance.mda.runtime.mda.RuleExecuteException; -import com.brilliance.mda.support.cache.ICache; -import com.brilliance.mda.support.cache.serializer.ICacheSerializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.data.redis.core.RedisTemplate; - -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -public class RedisCache<V> implements ICache<String, V> { - - private final Logger logger = LoggerFactory.getLogger(RedisCache.class); - - private String cacheName; - - private RedisTemplate<String, Object> redisTemplate; - - private ICacheSerializer serializer; - - private long expireTime; - - public RedisCache(String cacheName, RedisTemplate<String, Object> redisTemplate, ICacheSerializer serializer, long expireTime) { - this.cacheName = cacheName; - this.redisTemplate = redisTemplate; - this.serializer = serializer; - this.expireTime = expireTime; - } - - @Override - public String store(V v) { - String key = generateKey(); - this.store(key, v); - return key; - } - - @Override - public void store(String key, V v) { - try { - long time1 = System.currentTimeMillis(); - byte[] bytes = serializer.writeToByteArray(v); - if(bytes == null){ - logger.debug("{}使用{}序列化 Key:{},Length:{},Timing:{}ms",cacheName,serializer.getName(),key,0,System.currentTimeMillis() - time1); - return; - } - logger.debug("{}使用{}序列化 Key:{},Length:{},Timing:{}ms",cacheName,serializer.getName(),key,bytes.length,System.currentTimeMillis() - time1); - - time1 = System.currentTimeMillis(); - redisTemplate.opsForValue().set(key, bytes, expireTime, TimeUnit.SECONDS); - logger.debug("{}写入redis Key:{},Length:{},Timing:{}ms",cacheName,key,bytes.length,System.currentTimeMillis() - time1); - - } catch (Exception e) { - logger.error(cacheName+"使用"+serializer.getName() + "序列化保存缓存失败", e); - } - } - - @Override - @SuppressWarnings("unchecked") - public V get(String s) { - try { - if (null == s) { - logger.error("RedisCache get with null key"); - return null; - } - long time1 = System.currentTimeMillis(); - byte[] bytes = (byte[]) redisTemplate.opsForValue().get(s); - if (null == bytes){ - logger.debug("从redis读取Key:{},Length:{},Timing:{}ms",s,0,System.currentTimeMillis() - time1); - return null; - } - long time2 = System.currentTimeMillis(); - logger.debug("从redis读取Key:{},Length:{},Timing:{}ms",s,bytes.length,System.currentTimeMillis() - time1 ); - V v = serializer.readFromByteArray(bytes); - - logger.debug("{}使用{}反序列化Key:{},Length:{},Timing:{} ms", cacheName,serializer.getName(),s,bytes.length, System.currentTimeMillis() - time2); - - return v; - } catch (Exception e) { - logger.error(serializer.getName() + "反序列化失败", e); - if(e instanceof RuleExecuteException){ - throw e; - }else{ - throw new RuleExecuteException(serializer.getName() + "反序列化失败",e); - } - } - } - - @Override - public void remove(String s) { - redisTemplate.delete(s); - } - - @Override - public String generateKey() { - return cacheName + "-" + UUID.randomUUID(); - } - - @Override - public void keeplive(String key) { - if(key == null){ - return; - } - redisTemplate.expire(key,expireTime,TimeUnit.SECONDS); - } - - @Override - public void cleanup() { - logger.info("RedisCache not clean up ."); - } - - @Override - public boolean contains(String key) { - return redisTemplate.hasKey(key); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/cache/serializer/ICacheSerializerEnum.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/cache/serializer/ICacheSerializerEnum.java deleted file mode 100644 index 4cb3cf1..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/cache/serializer/ICacheSerializerEnum.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.brilliance.mda.support.cache.serializer; - - -import com.brilliance.mda.support.cache.serializer.impl.KryoSerializer; - -public enum ICacheSerializerEnum { - - Kryo("kryo", new KryoSerializer()); - - private String key; - - private ICacheSerializer serializer; - - ICacheSerializerEnum(String key, ICacheSerializer serializer) { - this.key = key; - this.serializer = serializer; - } - - public static ICacheSerializer getSerializer(String key) { - for (ICacheSerializerEnum e : ICacheSerializerEnum.values()) { - if (e.key.equals(key)) - return e.getSerializer(); - } - return ICacheSerializerEnum.values()[0].getSerializer(); - } - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public ICacheSerializer getSerializer() { - return serializer; - } - - public void setSerializer(ICacheSerializer serializer) { - this.serializer = serializer; - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/cache/serializer/impl/KryoSerializer.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/cache/serializer/impl/KryoSerializer.java deleted file mode 100644 index 28e15e9..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/cache/serializer/impl/KryoSerializer.java +++ /dev/null @@ -1,191 +0,0 @@ -package com.brilliance.mda.support.cache.serializer.impl; - -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.brilliance.mda.runtime.mda.impl.AbstractModule; -import com.brilliance.mda.runtime.mda.impl.ModuleList; -import com.brilliance.mda.support.cache.serializer.ICacheSerializer; -import com.esotericsoftware.kryo.kryo5.Kryo; -import com.esotericsoftware.kryo.kryo5.io.Input; -import com.esotericsoftware.kryo.kryo5.io.Output; -import com.esotericsoftware.kryo.kryo5.objenesis.strategy.StdInstantiatorStrategy; -import com.esotericsoftware.kryo.kryo5.util.DefaultInstantiatorStrategy; -import com.esotericsoftware.kryo.kryo5.util.Pool; -import com.google.common.io.Files; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.lang.reflect.*; -import java.nio.charset.StandardCharsets; -import java.util.concurrent.atomic.AtomicInteger; - -public class KryoSerializer implements ICacheSerializer { - - private static final Logger logger = LoggerFactory.getLogger(KryoSerializer.class); - - private static final String NAME = "Kryo"; - - private static final String DEFAULT_ENCODING = StandardCharsets.UTF_8.toString(); - - private static final int bufferSize = 8192; - - private static volatile Pool<Output> outputPool = new Pool<Output>(true, false, 50) { - @Override - protected Output create() { - return new Output(bufferSize, -1); - } - }; - - private static volatile Pool<Kryo> kryoPool = new Pool<Kryo>(true, false, 50) { - @Override - protected Kryo create() { - Kryo kryo = new Kryo(); - kryo.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); - kryo.setReferences(true); - kryo.setRegistrationRequired(false); - return kryo; - } - }; - - @Override - public String getName() { - return NAME; - } - - @Override - public <T> byte[] writeToByteArray(T obj) { - Output output = null; - Kryo kryo = null; - try { - output = outputPool.obtain(); - kryo = kryoPool.obtain(); - kryo.writeClassAndObject(output, obj); - byte[] buff = output.toBytes(); - return buff; - } catch (Exception e) { - logger.error("Kryo序列化失败", e); - throw new RuleExecuteException("kryo 序列化异常!", e); - } finally { - if (kryo != null) { - kryoPool.free(kryo); - } - if (output != null) { - outputPool.free(output); - } - } - } - - static AtomicInteger count = new AtomicInteger(0); - - @Override - @SuppressWarnings("unchecked") - public <T> T readFromByteArray(byte[] bytes) { - Input input = new Input(bytes); - Kryo kryo = null; - try { - kryo = kryoPool.obtain(); - long time2 = System.currentTimeMillis(); - T t = (T) kryo.readClassAndObject(input); - if (t instanceof IContext) { - IContext context = (IContext) t; - IModule root = context.getRoot(); - context.setEmitter(MdaEnv.getBean(IRuleEmitter.EMITTER_PRE + root.getClass().getSimpleName().toLowerCase(), IRuleEmitter.class)); - moduleSetting(root); - logger.debug("bytes to module timing:{}ms", System.currentTimeMillis() - time2); - } - return t; - } catch (Exception e) { - logger.error("Kryo反序列化失败", e); - int i = count.incrementAndGet(); - try { - File file = new File(MdaEnv.getRootPath(), "kryo_ex_" + i + ".ky"); - Files.write(bytes, file); - } catch (Exception ex) { - logger.warn("", ex); - } - throw new RuleExecuteException("kryo反序列化异常!", e); - } finally { - if (kryo != null) { - kryoPool.free(kryo); - } - } - } - - private void moduleSetting(IModule module) { - invokeSetArgumentMethod(module); - Field[] fields = module.getClass().getDeclaredFields(); - for (Field field : fields) { - field.setAccessible(true); - if (Modifier.isStatic(field.getModifiers())) { - continue; - } - Class<?> clazz = field.getType(); - try { - Object o = field.get(module); - if (null == o) continue; - - if (AbstractModule.class.isAssignableFrom(clazz)) { - moduleSetting((IModule) o); - } else if (ModuleList.class.isAssignableFrom(clazz)) { - fillModuleList(module, field, (ModuleList<?>) o); - } - } catch (IllegalAccessException ignored) { - - } - } - } - - private void invokeSetArgumentMethod(IModule module) { - try { - Method method = module.getClass().getMethod("setArgument"); - method.invoke(module); - } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException ignored) { - - } - } - - private void fillModuleList(IModule parentModule, Field field, ModuleList<?> moduleList) { - try { - Class<? extends ModuleList> moduleListClass = moduleList.getClass(); - Field parentField = moduleListClass.getDeclaredField("_parent"); - Field nameField = moduleListClass.getDeclaredField("_name"); - Field pathField = moduleListClass.getDeclaredField("_path"); - Field dataClassField = moduleListClass.getDeclaredField("dataClass"); - Field moduleTypeField = moduleListClass.getDeclaredField("moduleType"); - - parentField.setAccessible(true); - nameField.setAccessible(true); - pathField.setAccessible(true); - dataClassField.setAccessible(true); - moduleTypeField.setAccessible(true); - - parentField.set(moduleList, parentModule); - nameField.set(moduleList, field.getName()); - - String prefix = parentModule.getPath(); - if (prefix == null || prefix.length() == 0 || prefix.equals(IBaseObject.separator)) { - pathField.set(moduleList, IBaseObject.separator + field.getName()); - } else { - pathField.set(moduleList, prefix + IBaseObject.separator + field.getName()); - } - - Type type = field.getGenericType(); - if (type instanceof ParameterizedType) { - ParameterizedType t = (ParameterizedType) type; - Type[] actualTypeArguments = t.getActualTypeArguments(); - if (null != actualTypeArguments && actualTypeArguments.length > 0) { - Class<?> aClass = (Class<?>) actualTypeArguments[0]; - dataClassField.set(moduleList, aClass); - moduleTypeField.set(moduleList, aClass.getSimpleName().toLowerCase()); - } - } - - for (IModule module : moduleList) { - moduleSetting(module); - } - } catch (NoSuchFieldException | IllegalAccessException ignored) { - - } - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/jaxrs/ApplicationAware.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/jaxrs/ApplicationAware.java deleted file mode 100644 index 1b27c44..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/jaxrs/ApplicationAware.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.brilliance.mda.support.jaxrs; - -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanFactoryPostProcessor; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.stereotype.Component; - -@Component -public class ApplicationAware implements BeanFactoryPostProcessor, ApplicationContextAware { - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - //MdaEnv.appContext = applicationContext; - } - - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException { - MdaEnv.beanFactory = configurableListableBeanFactory; - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/service/AbstractRouteService.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/service/AbstractRouteService.java deleted file mode 100644 index f43e77c..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/service/AbstractRouteService.java +++ /dev/null @@ -1,489 +0,0 @@ -package com.brilliance.mda.support.service; - -import com.brilliance.mda.runtime.mda.*; -import com.brilliance.mda.runtime.mda.driver.DCR; -import com.brilliance.mda.runtime.mda.driver.MdaContext; -import com.brilliance.mda.runtime.mda.driver.MdaDriver; -import com.brilliance.mda.runtime.mda.driver.MdaEnv; -import com.brilliance.mda.runtime.mda.impl.AbstractScopeEmitter; -import com.brilliance.mda.runtime.mda.impl.Argument; -import com.brilliance.mda.runtime.mda.util.Modules; -import com.brilliance.mda.runtime.request.BaseVO; -import com.brilliance.mda.runtime.request.CheckedParams; -import com.brilliance.mda.runtime.request.SelectedParams; -import com.brilliance.mda.runtime.response.ResponseSet; -import com.brilliance.mda.support.cache.ICache; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StopWatch; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.Map; - -public abstract class AbstractRouteService<V extends BaseVO> { - - Logger logger = LoggerFactory.getLogger(this.getClass()); - private Class<V> vClass; - - public final static String SAVE_PATH = "mtabut.sav"; - public final static String CONFIRM_PATH = "mtabut.usrcon"; - public final static String PEN_PATH = "mtabut.pen"; - public final static String CHEK_PATH = "mtabut.chk"; - - - @SuppressWarnings("unchecked") - public AbstractRouteService() { - Type t = this.getClass().getGenericSuperclass(); - if (t instanceof ParameterizedType) { - Type[] ts = ((ParameterizedType) t).getActualTypeArguments(); - vClass = (Class<V>) ts[0]; - } - } - - public String getServiceName() { - Service service = this.getClass().getAnnotation(Service.class); - if (service == null) { - return null; - } - return service.value(); - } - - public IRuleEmitter getEmitter() { - return getEmitter(getServiceName()); - } - - public IRuleEmitter getEmitterByPath(Argument<String> path) { - int rightCommasIdx = path.value.lastIndexOf(")"); - if (rightCommasIdx > 0) { - String modueInsPath = path.value.substring(0, rightCommasIdx + 1); - IModule module = MdaDriver.getModule(null, modueInsPath); - AbstractScopeEmitter scopeEmitter = DCR.getModuleListEmitter(module.getClass()); - scopeEmitter.acceptContext(module); - path.value = path.value.substring(rightCommasIdx + 2); - return scopeEmitter; - } else { - return getEmitter(getServiceName()); - } - } - - public IRuleEmitter getEmitter(String name) { - IRuleEmitter emitter = MdaEnv.getBean(IRuleEmitter.EMITTER_PRE + name, IRuleEmitter.class); - return emitter; - } - - public IModule createModule() { - - try { - return (IModule) getEmitter().relatedTransaction().newInstance(); - } catch (Exception e) { - logger.error("module create error ! ", e); - } - return null; - } - - public V createVO() { - try { - return vClass.newInstance(); - } catch (Exception e) { - logger.error("vo create error ! ", e); - } - return null; - } - - public ResponseSet<V> init(V req) { - StopWatch stopWatch = new StopWatch("init"); - stopWatch.start("getParams"); - Map<String, Object> params = null; - if (req != null) { - params = req.getParams(); - if (req.getParams().containsKey("trn")) { - return new ResponseSet<V>(req); - } - } - stopWatch.stop(); - - stopWatch.start("chain"); - chain(params); - stopWatch.stop(); - - stopWatch.start("initTrans"); - initTrans(req); - stopWatch.stop(); - - stopWatch.start("storeCache"); - IContext ctx = MdaEnv.getContext(); - ICache<String, IContext> cache = MdaEnv.getBean(ICache.CTX_CACHE, ICache.class); - // String key = cache.store(ctx); - stopWatch.stop(); - - stopWatch.start("createVO"); - V vo = createVO(); - vo.setPageId(cache.generateKey()); - ctx.setVo(vo); - stopWatch.stop(); - - logger.info(stopWatch.prettyPrint()); - return new ResponseSet<>(ctx, vo); - } - - public ResponseSet<V> checkAll(V req) { - return executeRule(req, CHEK_PATH); - } - - @Transactional - public ResponseSet<V> saveData(V req) { - return executeRule(req, SAVE_PATH); - } - - @Transactional - public ResponseSet<V> confirmData(V req) { - return executeRule(req, CONFIRM_PATH); - } - - @Transactional - public ResponseSet<V> pending(V req) { - return executeRule(req, PEN_PATH); - - } - - public ResponseSet<V> executeCheck(V req, String... rulePathArr) { - try { - StopWatch stopWatch = new StopWatch("executeCheck:" + StringUtils.join(rulePathArr, ',')); - stopWatch.start("enterTransaction"); - enterTransaction(req); - stopWatch.stop(); - - IContext ctx = MdaEnv.getContext(); - synchronized (ctx) { - stopWatch.start("setValueFromVO"); - setValueFromVO(req); - stopWatch.stop(); - - stopWatch.start("executeStepWithCheckList"); - executeStepWithCheckList(rulePathArr); - stopWatch.stop(); - - stopWatch.start("afterExecute"); - boolean result = ctx.getFieldErrors().size() <= 0; - afterExecute(rulePathArr); - stopWatch.stop(); - - logger.info(stopWatch.prettyPrint()); - return new ResponseSet<V>(ctx, req); - - //return new ResponseSet<V>(ctx.getErrorNo(), ctx.getMessage(), ctx.getFieldErrors()); - } - } catch (Exception e) { - throw new RuleExecuteException(e.getMessage(), e); - } finally { - DCR.emptyDefaultQueue(); - } - } - - public boolean isStdErrorNo(String errorNo) { - if (errorNo != null && errorNo.matches("E\\d{4}")) { - return true; - } - return false; - } - - public ResponseSet<V> executeRule(V req, String... rulePathArr) { - try { - StopWatch stopWatch = new StopWatch("executeRule:" + StringUtils.join(rulePathArr, ',')); - stopWatch.start("enterTransaction"); - enterTransaction(req); - stopWatch.stop(); - - IContext ctx = MdaEnv.getContext(); - synchronized (ctx) { - stopWatch.start("setValueFromVO"); - setValueFromVO(req); - stopWatch.stop(); - - stopWatch.start("executeStepWithRuleList"); - boolean[] step = executeStepWithRuleList(rulePathArr); - stopWatch.stop(); - - // checkAll时对ModuleList进行check - if (rulePathArr.length == 1 && CHEK_PATH.equals(rulePathArr[0])) { - stopWatch.start("executeCheckAll"); - ctx.getEmitter().executeCheckAll(); - stopWatch.stop(); - } - boolean result = step[step.length - 1]; - if (!result) { - logger.warn("{} execute return false", rulePathArr); - } - - stopWatch.start("afterExecute"); - afterExecute(rulePathArr); - stopWatch.stop(); - - logger.info(stopWatch.prettyPrint()); - // 机构选择、联行信息 - Map<String, Object> gridData = MdaEnv.getGridData(); - if (gridData != null && rulePathArr.length == 1) { - return new ResponseSet<V>(ctx, gridData); - } - if (!isStdErrorNo(ctx.getErrorNo())) - return new ResponseSet<V>(ctx, req); - //返回标准错误码消息 - return new ResponseSet<V>(ctx.getErrorNo(), ctx.getErrorMessage(), req); - //return new ResponseSet<V>(ctx.getErrorNo(), ctx.getErrorMessage(), ctx.getFieldErrors()); - } - } catch (Exception e) { - throw new RuleExecuteException(e.getMessage(), e); -// return new ResponseSet<V>() - } finally { - DCR.emptyDefaultQueue(); - } - } - - /** - * 执行defaultRule - */ - public ResponseSet<V> executeDefault(V req, String... rulePathArr) { - try { - StopWatch stopWatch = new StopWatch("executeDefault:" + StringUtils.join(rulePathArr, ',')); - stopWatch.start("enterTransaction"); - enterTransaction(req); - stopWatch.stop(); - - IContext ctx = MdaEnv.getContext(); - synchronized (ctx) { - stopWatch.start("setValueFromVO"); - setValueFromVO(req); - stopWatch.stop(); - - stopWatch.start("executeStepWithDefaultList"); - executeStepWithDefaultList(rulePathArr); - stopWatch.stop(); - - stopWatch.start("afterExecute"); - afterExecute(rulePathArr); - stopWatch.stop(); - - logger.info(stopWatch.prettyPrint()); - return new ResponseSet<V>(ctx, req); - } - } catch (Exception e) { - throw new RuleExecuteException(e.getMessage(), e); - } finally { - DCR.emptyDefaultQueue(); - } - } - - /** - * 执行Notify - */ - public ResponseSet<V> executeNotify(V req) { - try { - StopWatch stopWatch = new StopWatch("executeNotify"); - stopWatch.start("enterTransaction"); - enterTransaction(req); - stopWatch.stop(); - - IContext ctx = MdaEnv.getContext(); - synchronized (ctx) { - stopWatch.start("enterTransaction"); - setValueFromVO(req); - stopWatch.stop(); - //执行Default - stopWatch.start("executeQueue"); - DCR.executeQueue(); - stopWatch.stop(); - - stopWatch.start("executeAndClearPostQueue"); - executeAndClearPostQueue(); - stopWatch.stop(); - - //执行Default - stopWatch.start("executeQueue"); - DCR.executeQueue(); - stopWatch.stop(); - - stopWatch.start("afterExecute"); - afterExecute(); - stopWatch.stop(); - - logger.info(stopWatch.prettyPrint()); - return new ResponseSet<V>(ctx, req); - } - } catch (Exception e) { - throw new RuleExecuteException(e.getMessage(), e); - } finally { - DCR.emptyDefaultQueue(); - } - } - - /** - * 初始化步骤 - */ - public void initTrans(V req) { - StopWatch watch = new StopWatch("initTrans"); - IContext ctx = MdaEnv.getContext(); - IRuleEmitter emitter = getEmitter(); - if (req != null) { - ctx.setVo(req); - } - //将认证信息(usr、usg、ety)放入sysStream - //后台自动交易可能没有这个授权信息,先这样判断 - IAuthInfo authInfo = MdaEnv.getAuthInfo(); - if (null != authInfo) { - authInfo.recoveryAuthInfo(); - } - //一阶段,构造与初始化 -// DCR.emptyDefaultQueue(); - watch.start("executeInit"); - emitter.executeInit(); // 执行初始 - watch.stop(); - DCR.enNotify(true); - watch.start("executeDefaultAfterInit"); - emitter.executeDefaultAfterInit(); - watch.stop(); - watch.start("executeAndClearPostQueue"); - executeAndClearPostQueue(); - watch.stop(); - - logger.info(watch.prettyPrint()); - //执行Default - DCR.executeQueue(); - } - - /** - * 切换到交易 - */ - public void chain(Map<String, Object> params) { - IRuleEmitter emitter = getEmitter(); - IModule m = createModule(); - IContext ctx = new MdaContext(emitter, m); - ctx.resetParams(params); - } - - /** - * 赋值步骤 - */ - public void setVoToTransaction(BaseVO req) { - IContext ctx = MdaEnv.getContext(); - MdaDriver.setValueFromVO(ctx, req); - executeAndClearPostQueue(); - } - - /** - * 执行Rule列表 - */ - public boolean[] executeStepWithRuleList(String... ruleList) { - boolean[] result = new boolean[ruleList.length]; - for (int i = 0; i < ruleList.length; i++) { -// DCR.emptyDefaultQueue(); - String path = ruleList[i]; - Argument<String> pathBox = Argument.box(path); - result[i] = getEmitterByPath(pathBox).executeRule(pathBox.value); - //todo 判断是否列表数据,例如机构选择,如果是则不执行后续的default, - Map<String, Object> gridData = MdaEnv.getGridData(); - if (gridData != null && ruleList.length == 1) { - break; - } - //执行Default - DCR.executeQueue(); - executeAndClearPostQueue(); - //执行Default - DCR.executeQueue(); - } - return result; - } - - /** - * 执行Check列表 - */ - public boolean[] executeStepWithCheckList(String... ruleList) { - boolean[] result = new boolean[ruleList.length]; - for (int i = 0; i < ruleList.length; i++) { -// DCR.emptyDefaultQueue(); - String path = ruleList[i]; - Argument<String> pathBox = Argument.box(path); - result[i] = getEmitterByPath(pathBox).executeCheck(pathBox.value); - //执行Default - DCR.executeQueue(); - executeAndClearPostQueue(); - //执行Default - DCR.executeQueue(); - } - return result; - } - - /** - * 执行Default列表 - */ - public boolean[] executeStepWithDefaultList(String... ruleList) { - boolean[] result = new boolean[ruleList.length]; - for (int i = 0; i < ruleList.length; i++) { -// DCR.emptyDefaultQueue(); - String path = ruleList[i]; - Argument<String> pathBox = Argument.box(path); - result[i] = getEmitterByPath(pathBox).executeDefault(pathBox.value); - //执行Default - DCR.executeQueue(); - executeAndClearPostQueue(); - //执行Default - DCR.executeQueue(); - } - return result; - } - - - protected void executeAndClearPostQueue() { - Modules.executePostQueue(); - Modules.clearPostQueue(); - } - - - public boolean beforeExecute() { - return true; - } - - public boolean afterExecute(String... rulePathArr) { - return true; - } - - public boolean enterTransaction(V req) { - if (req != null) { - String pageId = req.getPageId(); - ICache<String, IContext> cache = MdaEnv.getBean(ICache.CTX_CACHE, ICache.class); - IContext ctx = cache.get(pageId); - if (ctx == null) { - Map<String, Object> params = req.getParams(); - chain(params); - initTrans(req); - ctx = MdaEnv.getContext(); - ctx.storeData(IContext.DISPLAY_KEY, req); - // String key = cache.store(ctx); - req.setPageId(cache.generateKey()); - } else { - // wgc - //ctx.clearData(); - ctx.resetParams(req.getParams()); - ctx.setVo(req); - ctx.getFieldErrors().clear(); - ctx.storeData(IContext.DISPLAY_KEY, req); - MdaEnv.setContext(ctx); - } - - } - return true; - } - - public void setValueFromVO(V req) { - DCR.enNotify(true); - setVoToTransaction(req); - SelectedParams.selectedParamsInit(req); - CheckedParams.checkedParamsInit(req); - //执行Default Queue -// DCR.executeQueue(false); - beforeExecute(); - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/service/CodetableService.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/service/CodetableService.java deleted file mode 100644 index f993a83..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/service/CodetableService.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.brilliance.mda.support.service; - -import com.brilliance.mda.runtime.mda.CodetableItem; - -import java.util.List; - -public interface CodetableService { - - List<CodetableItem> selectList(String tbl, String lang); -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/td/ModuleInfoManager.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/td/ModuleInfoManager.java deleted file mode 100644 index 11380da..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/td/ModuleInfoManager.java +++ /dev/null @@ -1,261 +0,0 @@ -package com.brilliance.mda.support.td; - - -import com.brilliance.mda.runtime.mda.FieldHolder; -import com.brilliance.mda.runtime.mda.IPanel; -import com.brilliance.mda.runtime.mda.IStream; -import com.brilliance.mda.runtime.mda.ModuleHolder; -import com.brilliance.mda.runtime.mda.impl.AbstractModule; -import com.brilliance.mda.runtime.mda.impl.ModuleList; -import com.brilliance.mda.runtime.mda.util.Reflects; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.io.IOUtils; -import org.dom4j.Document; -import org.dom4j.Element; -import org.dom4j.io.SAXReader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.core.io.support.ResourcePatternResolver; -import org.springframework.util.StringUtils; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - -public class ModuleInfoManager { - - private static Logger log = LoggerFactory.getLogger(ModuleInfoManager.class); - - //缓存模型信息 - private static final Map<String, Map<String, Map<String, Object>>> cache = new ConcurrentHashMap<>(); - //缓存 字段名->字段会触发的 - private static final Map<String, Map<String, List<String>>> defaultRule = new HashMap<>(); - //缓存 defaultRule->依赖的字段 - private static final Map<String, Map<String, List<String>>> dependencies = new HashMap<>(); - //文件存放目录 - private static final String path = "moduleInfo/"; - private static final String rulePattern = "classpath*:defaultRule/*"; - private static Map<Class<?>, TDModuleInfo> moduleInfoCacheMap = new HashMap<>(); - - static { - ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); - try { - Resource[] resources = resourceResolver.getResources(rulePattern); - for (Resource dp : resources) { - try { - Document document = new SAXReader().read(dp.getInputStream()); - Iterator<Element> iterator = document.getRootElement().elementIterator(); //获取根元素下的迭代器 - Map<String, List<String>> defaultRuleMap = new HashMap<>(); - Map<String, List<String>> dependencyMap = new HashMap<>(); - while (iterator.hasNext()) { - Element next = iterator.next(); //Rule元素 - Iterator<Element> elementIterator = next.elementIterator(); - Element element = elementIterator.next(); //target元素 - String defaultRule = element.getText(); - List<String> dependency = new ArrayList<>(); - while (elementIterator.hasNext()) { - String path = elementIterator.next().getText(); - //defaultRuleMap 添加元素 - List<String> list = defaultRuleMap.get(path); - if (list == null) { - List<String> rules = new ArrayList<>(); - rules.add(defaultRule); - defaultRuleMap.put(path, rules); - } else { - list.add(defaultRule); - } - //dependencyMap 添加元素 - dependency.add(path); - } - dependencyMap.put(defaultRule, dependency); - } - String transaction = dp.getFilename().replace(".xml", ""); - dependencies.put(transaction, dependencyMap); - defaultRule.put(transaction, defaultRuleMap); - } catch (Exception e) { - log.error("解析defaultRule配置异常", e); - } - } - } catch (IOException e) { - log.error("解析defaultRule配置异常", e); - } - } - - /** - * @param transaction 交易名 - * @param path 路径名 - * @return 对应的default rule - */ - public static List<String> getDefaultRule(String transaction, String path) { - if (path.charAt(0) == '\\') - path = path.substring(1); - path = path.toLowerCase(Locale.ROOT).replace("\\", "."); - Map<String, List<String>> transDefaultSet = defaultRule.get(transaction.toLowerCase(Locale.ROOT)); - if (transDefaultSet == null) { - return null; - } - return transDefaultSet.get(path); - } - - public static Map<String, List<String>> getDefaultRule(String transaction) { - return defaultRule.get(transaction.toLowerCase(Locale.ROOT)); - } - - public static Map<String, Map<String, List<String>>> getDefaultRule() { - return defaultRule; - } - - /** - * @param transaction 交易名 - * @param target 路径名 - * @return 对应的依赖 - */ - public static List<String> getDependency(String transaction, String target) { - if (target.charAt(0) == '\\') - target = target.substring(1); - target = target.toLowerCase(Locale.ROOT).replace("\\", "."); - return dependencies.get(transaction.toLowerCase(Locale.ROOT)).get(target); - } - - public static Map<String, List<String>> getDependency(String transaction) { - return dependencies.get(transaction.toLowerCase(Locale.ROOT)); - } - - public static Map<String, Map<String, List<String>>> getDependency() { - return dependencies; - } - - /** - * 传入模型名称,从resources/moduleInfo下查找文件 - * - * @param moduleName 模型名称 - * @return 模型对应的map - */ - public static Map<String, Map<String, Object>> getModuleInfo(String moduleName) { - if (!StringUtils.hasLength(moduleName)) - throw new NullPointerException("模型名不能为空"); - if (cache.containsKey(moduleName)) - return cache.get(moduleName); - try (InputStream stream = new ClassPathResource(path + moduleName + ".info").getInputStream()) { - Map map = new ObjectMapper().readValue(IOUtils.toString(stream, StandardCharsets.UTF_8), Map.class); - cache.put(moduleName, map); - return map; - } catch (IOException e) { - throw new IllegalArgumentException(e.getCause()); - } - } - - /** - * 传入模型名称,和字段名称 从resources/moduleInfo下查找文件,并在文件中查找对应字段<br/> - * 返回的map中key包含{type, viewLine, viewType, dataType, length, line, codeTable} - * - * @param moduleName 模型名称 - * @param fieldName 模型中的字段名称 - * @return 模型moduleName#fileName字段对应的map集合 - */ - public static Map<String, Object> getModuleFieldInfo(String moduleName, String fieldName) { - Map<String, Map<String, Object>> moduleInfo = getModuleInfo(moduleName); - if (moduleInfo == null) - throw new IllegalArgumentException("模型名错误或模型文件不存在"); - if (!StringUtils.hasLength(fieldName)) - throw new IllegalArgumentException("字段名称参数名不能为空"); - return moduleInfo.get(fieldName); - } - - public static int getModuleInfoCount() { - return cache.size(); - } - - public static void loadModuleInfo(Class<?> moduleClass) { - Method[] methods = moduleClass.getMethods(); - //防止同名函数,要用List - Map<String, List<Method>> tdMethods = new HashMap<>(); - Map<String, List<Method>> allPublicMethods = new HashMap<>(); - Map<String, Method> allPublicLowerCaseMethods = new HashMap<>(); - for (Method method : methods) { - List<Method> methodList = allPublicMethods.computeIfAbsent(method.getName(), k -> new ArrayList<>()); - methodList.add(method); - - allPublicLowerCaseMethods.put(method.getName().toLowerCase() + "#" + method.getParameterCount(), method); - - methodList = tdMethods.computeIfAbsent(method.getName(), k -> new ArrayList<Method>()); - methodList.add(method); - } - - //IModule字段集合 - Map<String, TDFieldInfo> tdModules = new HashMap<>(); - //IModuleList字段集合 - Map<String, TDFieldInfo> tdModuleLists = new HashMap<>(); - //简单字段集合 - Map<String, TDFieldInfo> tdPrimitiveFields = new HashMap<>(); - //IStream字段集合 - Map<String, TDFieldInfo> tdStreamFields = new HashMap<>(); - //IPanel字段集合 - Map<String, TDFieldInfo> tdPanelFields = new HashMap<>(); - //ModuleHolder字段集合 - Map<String, TDFieldInfo> tdModuleHolderFields = new HashMap<>(); - //FieldHolder字段集合 - Map<String, TDFieldInfo> tdFieldHolderFields = new HashMap<>(); - - Field[] fields = moduleClass.getDeclaredFields(); - for (Field field : fields) { - String fieldName = field.getName(); - String getMethodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); - String setMethodName = getMethodName.replaceFirst("get", "set"); - Method getMethod = Reflects.getMethod(moduleClass, getMethodName); - Method setMethod = Reflects.getMethod(moduleClass, setMethodName, field.getType()); - if (AbstractModule.class.isAssignableFrom(field.getType())) { - tdModules.put(field.getName(), new TDFieldInfo(field.getName(), field.getType(), field, getMethod, setMethod)); - } else if (ModuleList.class.isAssignableFrom(field.getType())) { - Class<?> actualType = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; - tdModuleLists.put(field.getName(), new TDFieldInfo(field.getName(), actualType, field, getMethod, setMethod)); - } else if (IStream.class.isAssignableFrom(field.getType())) { - tdStreamFields.put(field.getName(), new TDFieldInfo(field.getName(), field.getType(), field, getMethod, setMethod)); - } else if (IPanel.class.isAssignableFrom(field.getType())) { - tdPanelFields.put(field.getName(), new TDFieldInfo(field.getName(), field.getType(), field, getMethod, setMethod)); - } else if (ModuleHolder.class.isAssignableFrom(field.getType())) { - tdModuleHolderFields.put(field.getName(), new TDFieldInfo(field.getName(), field.getType(), field, getMethod, setMethod)); - } else if (FieldHolder.class.isAssignableFrom(field.getType())) { - tdFieldHolderFields.put(field.getName(), new TDFieldInfo(field.getName(), field.getType(), field, getMethod, setMethod)); - } else { - tdPrimitiveFields.put(field.getName(), new TDFieldInfo(field.getName(), field.getType(), field, getMethod, setMethod)); - } - } - - moduleInfoCacheMap.put(moduleClass, new TDModuleInfo(moduleClass.getSimpleName(), - moduleClass, tdMethods, allPublicMethods, allPublicLowerCaseMethods, tdModules, tdModuleLists, tdPrimitiveFields, - tdStreamFields, tdPanelFields, tdModuleHolderFields, tdFieldHolderFields)); - } - - public static TDModuleInfo getTDModuleInfo(Class<?> moduleClass) { - return moduleInfoCacheMap.getOrDefault(moduleClass, null); - } - - public static Map<String, List<Method>> getTDMethods(Class<?> moduleClass) { - TDModuleInfo moduleInfo = getTDModuleInfo(moduleClass); - return moduleInfo != null ? moduleInfo.getTdMethods() : null; - } - - public static Map<String, List<Method>> getAllPublicMethods(Class<?> moduleClass) { - TDModuleInfo moduleInfo = getTDModuleInfo(moduleClass); - return moduleInfo != null ? moduleInfo.getAllPublicMethods() : null; - } - - public static Map<String, Method> getAllPublicLowerCaseMethods(Class<?> moduleClass) { - TDModuleInfo moduleInfo = getTDModuleInfo(moduleClass); - return moduleInfo != null ? moduleInfo.getAllPublicLowerCaseMethods() : null; - } - - public static Map<String, TDFieldInfo> getTDModules(Class<?> moduleClass) { - TDModuleInfo moduleInfo = getTDModuleInfo(moduleClass); - return moduleInfo != null ? moduleInfo.getTdModules() : null; - } -} diff --git a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/td/TDAuthInfo.java b/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/td/TDAuthInfo.java deleted file mode 100644 index cdaaec8..0000000 --- a/gjjs-bd-runtime/src/main/java/com/brilliance/mda/support/td/TDAuthInfo.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.brilliance.mda.support.td; - -import com.brilliance.mda.runtime.mda.IAuthInfo; -import com.brilliance.mda.runtime.mda.IStream; -import com.brilliance.mda.runtime.mda.impl.StreamImpl; - -import java.util.List; - -public class TDAuthInfo implements IAuthInfo { - private String userId; - private IStream sysStream; - private IStream ddsStream; - private IStream keepAuthInfo; - - public TDAuthInfo(){} - - public TDAuthInfo(String userId) { - this.userId = userId; - sysStream = new StreamImpl(); - ddsStream = new StreamImpl(); - keepAuthInfo = new StreamImpl(); - } - - @Override - public String getUserId() { - return userId; - } - - @Override - public IStream getSysStream() { - return sysStream; - } - - @Override - public IStream getDdsStream() { - return ddsStream; - } - - public IStream getKeepAuthInfo() { - return keepAuthInfo; - } - - public void recoveryAuthInfo(){ - List<String> keyRows = this.getKeepAuthInfo().getRows(); - List<String> sysRows = this.getSysStream().getRows(); - for(int i=0;i< keyRows.size();i+=2){ - String key = keyRows.get(i); - String value = keyRows.get(i+1); - int idx = sysRows.indexOf(key); - if(idx>=0){ - sysRows.set(idx+1,value); - } - else{ - sysRows.add(key); - sysRows.add(value); - } - } - } -} diff --git a/gjjs-mda/pom.xml b/gjjs-mda/pom.xml deleted file mode 100644 index 86430fa..0000000 --- a/gjjs-mda/pom.xml +++ /dev/null @@ -1,93 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <parent> - <artifactId>gjjs-bd-common</artifactId> - <groupId>com.brilliance</groupId> - <version>0.0.1</version> - </parent> - <modelVersion>4.0.0</modelVersion> - - <artifactId>gjjs-mda</artifactId> - - <properties> - <maven.compiler.source>8</maven.compiler.source> - <maven.compiler.target>8</maven.compiler.target> - </properties> - <dependencies> - <dependency> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - </dependency> - <dependency> - <groupId>com.alibaba</groupId> - <artifactId>druid-spring-boot-starter</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-aop</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>com.sun</groupId> - <artifactId>tools</artifactId> - <version>1.8</version> - <scope>system</scope> - <systemPath>${basedir}/../lib/tools.jar</systemPath> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.1</version> - <configuration> - <source>${java.version}</source> - <target>${java.version}</target> - </configuration> - <executions> - <execution> - <id>default-compile</id> - <configuration> - <compilerArgument>-proc:none</compilerArgument> - <includes> - <include>com/brilliance/annotation/processor/*.java</include> - <include>com/brilliance/annotation/processor/enhance/*.java</include> - </includes> - </configuration> - </execution> - <execution> - <id>compile-project</id> - <phase>compile</phase> - <goals> - <goal>compile</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <version>2.19.1</version> - <configuration> - <skipTests>true</skipTests> <!--默认关掉单元测试 --> - </configuration> - </plugin> - </plugins> - </build> -</project> \ No newline at end of file diff --git a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/AnnotationEnhanceUtils.java b/gjjs-mda/src/main/java/com/brilliance/annotation/processor/AnnotationEnhanceUtils.java deleted file mode 100644 index 4c9a8a5..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/AnnotationEnhanceUtils.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.brilliance.annotation.processor; - -import com.sun.tools.javac.tree.JCTree; - -import java.util.List; - -public class AnnotationEnhanceUtils { - - public static String findAnnotationArguments(List<JCTree.JCExpression> args, String key) { - return findAnnotationArguments(args, key, null); - } - - public static String findAnnotationArguments(List<JCTree.JCExpression> args, String key, String defaultValue) { - String value = defaultValue; - if (null != args && args.size() > 0) { - for (JCTree.JCExpression jcExpression : args) { - if (jcExpression instanceof JCTree.JCAssign) { - JCTree.JCAssign jcAssign = (JCTree.JCAssign) jcExpression; - if (key.equals(jcAssign.lhs.toString())) { - value = jcAssign.rhs.toString(); - break; - } - } - } - } - return value; - } - - public static int findAnnotationArgumentsInt(List<JCTree.JCExpression> args, String key, int defaultValue) { - String value = findAnnotationArguments(args, key, null); - if (null == value || "".equals(value)) { - return defaultValue; - } - try { - return Integer.parseInt(value); - } catch (Exception e) { - return defaultValue; - } - } - - protected static boolean findAnnotationArgumentsBoolean(List<JCTree.JCExpression> args, String key, Boolean defaultValue) { - String value = findAnnotationArguments(args, key, null); - if (null == value || "".equals(value)) { - return true; - } - try { - return Boolean.valueOf(value); - } catch (Exception e) { - return defaultValue; - } - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/BaseProcessor.java b/gjjs-mda/src/main/java/com/brilliance/annotation/processor/BaseProcessor.java deleted file mode 100644 index e290cf2..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/BaseProcessor.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.brilliance.annotation.processor; - -import com.sun.source.util.Trees; -import com.sun.tools.javac.processing.JavacProcessingEnvironment; -import com.sun.tools.javac.tree.TreeMaker; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.Name; -import com.sun.tools.javac.util.Names; - -import javax.annotation.processing.AbstractProcessor; -import javax.annotation.processing.Messager; -import javax.annotation.processing.ProcessingEnvironment; -import javax.tools.Diagnostic; - -public abstract class BaseProcessor extends AbstractProcessor { - - /** - * 用于在编译器打印消息的组件 - */ - Messager messager; - - /** - * 语法树 - */ - Trees trees; - - /** - * 用来构造语法树节点 - */ - TreeMaker treeMaker; - - /** - * 用于创建标识符的对象 - */ - Name.Table names; - - @Override - public synchronized void init(ProcessingEnvironment processingEnvironment) { - super.init(processingEnvironment); - messager = processingEnvironment.getMessager(); - trees = Trees.instance(processingEnvironment); - Context context = ((JavacProcessingEnvironment) processingEnvironment).getContext(); - treeMaker = TreeMaker.instance(context); - names = Names.instance(context).table; - messager.printMessage(Diagnostic.Kind.NOTE, "父类BaseProcessor执行init()方法"); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/ModuleAnnotationTranslator.java b/gjjs-mda/src/main/java/com/brilliance/annotation/processor/ModuleAnnotationTranslator.java deleted file mode 100644 index ad58262..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/ModuleAnnotationTranslator.java +++ /dev/null @@ -1,175 +0,0 @@ -package com.brilliance.annotation.processor; - -import com.brilliance.annotation.processor.enhance.AbstractAnnotationEnhance; -import com.brilliance.annotation.processor.enhance.impl.*; -import com.brilliance.mda.runtime.annotation.BDGetter; -import com.brilliance.mda.runtime.annotation.Module; -import com.brilliance.mda.runtime.annotation.TDGetter; -import com.brilliance.mda.runtime.annotation.TDSetter; -import com.sun.source.tree.Tree; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.tree.TreeMaker; -import com.sun.tools.javac.tree.TreeTranslator; -import com.sun.tools.javac.util.Name; - -import javax.annotation.processing.Messager; -import javax.lang.model.element.Modifier; -import javax.tools.Diagnostic; -import java.util.List; -import java.util.Set; - -public class ModuleAnnotationTranslator extends TreeTranslator { - - private Name.Table names; - - private TreeMaker treeMaker; - - private Name moduleName; - - private Messager messager; - - public ModuleAnnotationTranslator(Name.Table names, TreeMaker treeMaker, Name moduleName, Messager messager) { - this.names = names; - this.treeMaker = treeMaker; - this.moduleName = moduleName; - this.messager = messager; - } - - @Override - public void visitClassDef(JCTree.JCClassDecl jcClassDecl) { - if ("AbstractModule".equals(moduleName.toString())) { - messager.printMessage(Diagnostic.Kind.NOTE, "AbstractModule 不会被增强."); - return; - } - if (jcClassDecl.name == moduleName) { - jcClassDecl.defs - .stream().filter(it -> it.getKind() == Tree.Kind.VARIABLE) - .map(it -> (JCTree.JCVariableDecl) it) - .forEach(it -> { - JCTree.JCModifiers modifiers = it.getModifiers(); - List<JCTree.JCAnnotation> annotations = modifiers.getAnnotations(); - for (JCTree.JCAnnotation annotation : annotations) { - AbstractAnnotationEnhance annotationEnhance = getAnnotationEnhance(annotation); - if (annotationEnhance != null) { - processAnnotationEnhance(annotationEnhance, annotation, jcClassDecl, it); - } - } - if (needGenerateMethod(annotations, TDSetter.class.getName()) && isValidField(it)) { - AbstractAnnotationEnhance annotationEnhance = new ModuleSetterEnhance(); - processAnnotationEnhance(annotationEnhance, null, jcClassDecl, it); - } - if (needGenerateMethod(annotations, TDGetter.class.getName()) && isValidField(it)) { - AbstractAnnotationEnhance annotationEnhance = new ModuleGetterEnhance(); - processAnnotationEnhance(annotationEnhance, null, jcClassDecl, it); - } - if (needGenerateMethod(annotations, BDGetter.class.getName()) && isValidField(it)) { - AbstractAnnotationEnhance annotationEnhance = new ModuleGetterEnhance(); - processAnnotationEnhance(annotationEnhance, null, jcClassDecl, it); - } - }); - } - super.visitClassDef(jcClassDecl); - } - - - /** - * 注解增强处理方法 - * 1.先找到对应的注解增强实现类 - * 2.生成方法名 - * 3.找到是否存在该方法 - * 4.构造方法体 - * - * @param annotationEnhance - * @param annotation - * @param jcClassDecl - * @param it - */ - private void processAnnotationEnhance(AbstractAnnotationEnhance annotationEnhance, JCTree.JCAnnotation annotation, JCTree.JCClassDecl jcClassDecl, JCTree.JCVariableDecl it) { - annotationEnhance.setNames(names); - annotationEnhance.setTreeMaker(treeMaker); - String methodName = annotationEnhance.getMethodName(it); - JCTree.JCMethodDecl methodDecl = annotationEnhance.findJCMethodDecl(jcClassDecl, it, methodName); - if (null == methodDecl) { - messager.printMessage(Diagnostic.Kind.NOTE, "正在增强:" + jcClassDecl.name.toString() + "." + methodName); - List<JCTree.JCExpression> args = annotation == null ? null : annotation.getArguments(); - JCTree.JCMethodDecl setterMethod = annotationEnhance.createJCMethodDecl(jcClassDecl, it, methodName, args); - if (setterMethod != null) { - messager.printMessage(Diagnostic.Kind.NOTE, "已增强:" + jcClassDecl.name.toString() + "." + methodName); - jcClassDecl.defs = jcClassDecl.defs.append(setterMethod); - } - } else { - messager.printMessage(Diagnostic.Kind.NOTE, jcClassDecl.name.toString() + "." + methodName + "已经存在,跳过增强"); - } - } - - /** - * 是否存在注解(@param annotationName) - * - * @param annotations - * @param annotationName - * @return - */ - private boolean includeAnnotation(List<JCTree.JCAnnotation> annotations, String annotationName) { - for (JCTree.JCAnnotation annotation : annotations) { - if (annotation.annotationType.type.toString().equals(annotationName)) { - return true; - } - } - return false; - } - - /** - * 根据注解找到对应的实现类 - * - * @param annotation - * @return - */ - private AbstractAnnotationEnhance getAnnotationEnhance(JCTree.JCAnnotation annotation) { - if (annotation.annotationType.type.toString().equals(TDSetter.class.getName())) { - return new TDSetterEnhance(); - } else if (annotation.annotationType.type.toString().equals(TDGetter.class.getName())) { - return new TDGetterEnhance(); - } else if (annotation.annotationType.type.toString().equals(BDGetter.class.getName())) { - return new BDGetterEnhance(); - } else { - return null; - } - } - - /** - * 字段如果是 final 或者static 修饰的, 不生产getset方法 - * - * @param it - * @return - */ - private boolean isValidField(JCTree.JCVariableDecl it) { - Set<Modifier> flagSets = it.getModifiers().getFlags(); - return (!flagSets.contains(Modifier.STATIC) - && !flagSets.contains(Modifier.FINAL)); - } - - /** - * 是否需要生成对应的getter 或者 setter 方法 - * 1. module getter setter - * 2. 是否已经存在TDSetter TDGetter - * - * @param annotations - * @param annotationName - * @return - */ - private boolean needGenerateMethod(List<JCTree.JCAnnotation> annotations, String annotationName) { - boolean flag = true; - String key = ""; - if (annotationName.lastIndexOf(".") > -1) { - key = annotationName.substring(annotationName.lastIndexOf(".") + 3).toLowerCase(); - } else { - key = annotationName.substring(2).toLowerCase(); - } - for (JCTree.JCAnnotation annotation : annotations) { - if (annotation.annotationType.type.toString().equals(Module.class.getName())) { - flag = AnnotationEnhanceUtils.findAnnotationArgumentsBoolean(annotation.getArguments(), key, Boolean.TRUE); - } - } - return flag && !includeAnnotation(annotations, annotationName); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/ModuleProcessor.java b/gjjs-mda/src/main/java/com/brilliance/annotation/processor/ModuleProcessor.java deleted file mode 100644 index 1826406..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/ModuleProcessor.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.brilliance.annotation.processor; - -import com.sun.source.util.TreePath; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.util.Name; - -import javax.annotation.processing.RoundEnvironment; -import javax.annotation.processing.SupportedAnnotationTypes; -import javax.annotation.processing.SupportedSourceVersion; -import javax.lang.model.SourceVersion; -import javax.lang.model.element.TypeElement; -import javax.tools.Diagnostic; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -@SupportedAnnotationTypes("com.brilliance.mda.runtime.annotation.Module") -@SupportedSourceVersion(SourceVersion.RELEASE_8) -public class ModuleProcessor extends BaseProcessor{ - - @Override - public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) { - if (null != set && set.size() > 0) { - messager.printMessage(Diagnostic.Kind.NOTE, "开始编译增强Module"); - TypeElement tmpTypeElement = null; - try { - for (TypeElement annotation : set) { - messager.printMessage(Diagnostic.Kind.NOTE, String.format("正在处理增强:%s", annotation.getSimpleName())); - List<TypeElement> typeElementList = roundEnvironment.getElementsAnnotatedWith(annotation) - .stream().filter(it -> (it instanceof TypeElement)) - .map(it -> (TypeElement) it) - .collect(Collectors.toList()); - - messager.printMessage(Diagnostic.Kind.NOTE, String.format("增强Module数量:%d", typeElementList.size())); - - for (TypeElement it : typeElementList) { - TreePath treePath = trees.getPath(it); - JCTree.JCCompilationUnit cu = (JCTree.JCCompilationUnit) treePath.getCompilationUnit(); - addImport(cu); - JCTree jcTree = (JCTree) trees.getTree(it); - tmpTypeElement = it; - translate(it, jcTree); - } - } - } catch (Exception e) { - messager.printMessage(Diagnostic.Kind.ERROR, "编译增强模型["+tmpTypeElement.getSimpleName().toString()+"]发生错误, 错误原因 : " + e.getMessage()); - } - messager.printMessage(Diagnostic.Kind.NOTE, "结束编译增强"); - } - return true; - } - - private void translate(TypeElement curElement, JCTree curTree) { - treeMaker.pos = curTree.pos; - curTree.accept(new ModuleAnnotationTranslator(names, treeMaker, (Name) curElement.getSimpleName(), messager)); - } - - private void addImport(JCTree.JCCompilationUnit cu) { - addImport(cu, - "com.brilliance.mda.runtime.mda.impl.PanelImpl", - "com.brilliance.mda.runtime.mda.impl.StreamImpl", - "com.brilliance.mda.runtime.mda.impl.ModuleList", - "com.brilliance.mda.runtime.mda.util.MdaUtils", - "java.lang.*"); - } - - private void addImport(JCTree.JCCompilationUnit cu, String... importPackages) { - if (null == importPackages) - return; - - List<JCTree.JCImport> jcImports = cu.defs.stream() - .filter(it -> (it instanceof JCTree.JCImport)) - .map(it -> (JCTree.JCImport) it) - .collect(Collectors.toList()); - - boolean[] exists = new boolean[importPackages.length]; - for (JCTree.JCImport jcImport : jcImports) { - for (int i = 0; i < importPackages.length; i++) { - if (jcImport.toString().equals(importPackages[i])) { - exists[i] = true; - break; - } - } - } - - for (int i = 0; i < exists.length; i++) { - if (!exists[i]) { - JCTree.JCFieldAccess fieldAccess = treeMaker.Select( - treeMaker.Ident(names.fromString(importPackages[i].substring(0, importPackages[i].lastIndexOf(".")))), - names.fromString(importPackages[i].substring(importPackages[i].lastIndexOf(".") + 1))); - cu.defs = cu.defs.append(treeMaker.Import(fieldAccess, false)); - } - } - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/PrimitiveEnums.java b/gjjs-mda/src/main/java/com/brilliance/annotation/processor/PrimitiveEnums.java deleted file mode 100644 index 0496a75..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/PrimitiveEnums.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.brilliance.annotation.processor; - -public enum PrimitiveEnums { - - INT("int", "Integer"), - SHORT("short", "Short"), - FLOAT("float", "Float"), - DOUBLE("double", "Double"), - BYTE("byte", "Byte"), - CHAR("char", "Char"), - BOOLEAN("boolean", "Boolean"), - LONG("long", "Long"); - - private String code; - - private String value; - - PrimitiveEnums(String code, String value) { - this.code = code; - this.value = value; - } - - public static PrimitiveEnums getValues(String code) { - for (PrimitiveEnums e : values()) { - if (e.code.equals(code)) { - return e; - } - } - return null; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/AbstractAnnotationEnhance.java b/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/AbstractAnnotationEnhance.java deleted file mode 100644 index 93a232c..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/AbstractAnnotationEnhance.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.brilliance.annotation.processor.enhance; - -import com.sun.tools.javac.tree.TreeMaker; -import com.sun.tools.javac.util.Name; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -public abstract class AbstractAnnotationEnhance implements AnnotationEnhance{ - - protected Name.Table names; - - protected TreeMaker treeMaker; - - public void setNames(Name.Table names) { - this.names = names; - } - - public void setTreeMaker(TreeMaker treeMaker) { - this.treeMaker = treeMaker; - } - - public static Properties moduleClassNameProperties; - - static { - try { - moduleClassNameProperties = new Properties(); - InputStream inputStream = AbstractAnnotationEnhance.class.getResourceAsStream("/META-INF/moduleClassName.properties"); - moduleClassNameProperties.load(inputStream); - } catch (IOException e) { - - } - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/AnnotationEnhance.java b/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/AnnotationEnhance.java deleted file mode 100644 index bb5acb2..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/AnnotationEnhance.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.brilliance.annotation.processor.enhance; - -import com.sun.tools.javac.tree.JCTree; - -import java.util.List; - -public interface AnnotationEnhance { - - /** - * 得到要增强的方法名称 - * @param variableDecl - * @return - */ - String getMethodName(JCTree.JCVariableDecl variableDecl); - /** - * 找到是否存在已增加的注解方法 - * @param jcClassDecl - * @param variableDecl - * @param methodName - * @return - */ - JCTree.JCMethodDecl findJCMethodDecl(JCTree.JCClassDecl jcClassDecl, JCTree.JCVariableDecl variableDecl, String methodName); - - /** - * 增强注解方法 - * @param jcClassDecl - * @param variableDecl - * @param methodName - * @param args - * @return - */ - JCTree.JCMethodDecl createJCMethodDecl(JCTree.JCClassDecl jcClassDecl, JCTree.JCVariableDecl variableDecl, String methodName, List<JCTree.JCExpression> args); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/impl/BDGetterEnhance.java b/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/impl/BDGetterEnhance.java deleted file mode 100644 index c93bdb6..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/impl/BDGetterEnhance.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.brilliance.annotation.processor.enhance.impl; - -import com.brilliance.annotation.processor.AnnotationEnhanceUtils; -import com.brilliance.annotation.processor.enhance.AbstractAnnotationEnhance; -import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.code.TypeTag; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.util.ListBuffer; - -import java.util.List; -import java.util.stream.Collectors; - -/** - * BDGetter注解增强实现类 - */ -public class BDGetterEnhance extends AbstractAnnotationEnhance { - - @Override - public String getMethodName(JCTree.JCVariableDecl variableDecl) { - String variableName = variableDecl.name.toString(); - return "get" + variableName.substring(0, 1).toUpperCase() + variableName.substring(1); - } - - @Override - public JCTree.JCMethodDecl findJCMethodDecl(JCTree.JCClassDecl jcClassDecl, JCTree.JCVariableDecl variableDecl, String methodName) { - List<JCTree.JCMethodDecl> jcMethodDecls = jcClassDecl.defs - .stream().filter(it -> (it instanceof JCTree.JCMethodDecl)) - .map(it -> (JCTree.JCMethodDecl) it) - .collect(Collectors.toList()); - - for (JCTree.JCMethodDecl jcMethodDecl : jcMethodDecls) { - if (jcMethodDecl.name.toString().equals(methodName) - && jcMethodDecl.params.size() == 0 - && jcMethodDecl.restype.type.toString().equals(variableDecl.vartype.type.toString())) { - return jcMethodDecl; - } - } - return null; - } - - @Override - public JCTree.JCMethodDecl createJCMethodDecl(JCTree.JCClassDecl jcClassDecl, JCTree.JCVariableDecl variableDecl, String methodName, List<JCTree.JCExpression> args) { - ListBuffer<JCTree.JCStatement> body = new ListBuffer<>(); - String instance = variableDecl.name.toString(); - if ("tmpint".equals(instance.trim())) { - instance = "int"; - } - - JCTree.JCNewClass jcNewClass = null; - - if (variableDecl.vartype.type.toString().startsWith(moduleClassNameProperties.get("IModuleList") + "<") - || variableDecl.vartype.type.toString().startsWith(moduleClassNameProperties.get("ModuleList") + "<")) { - JCTree.JCTypeApply typeApply = (JCTree.JCTypeApply) variableDecl.vartype; - List<JCTree.JCExpression> argsuments = typeApply.arguments; - String tClass = argsuments.get(0).toString(); - int initSize = AnnotationEnhanceUtils.findAnnotationArgumentsInt(args, "initSize", 0); - - jcNewClass = treeMaker.NewClass(null, - com.sun.tools.javac.util.List.nil(), - treeMaker.TypeApply(treeMaker.Ident(names.fromString("ModuleList")), - com.sun.tools.javac.util.List.nil()), - new ListBuffer<JCTree.JCExpression>() - .append(treeMaker.Literal(variableDecl.name.toString())) - .append(treeMaker.Ident(names.fromString("this"))) - .append(treeMaker.Literal(initSize)) - .append(treeMaker.Select(treeMaker.Ident(names.fromString(tClass)), names.fromString("class"))) - .toList(), - null); - } else if (variableDecl.vartype.type.toString().equals(moduleClassNameProperties.get("IPanel")) - || variableDecl.vartype.type.toString().equals(moduleClassNameProperties.get("PanelImpl"))) { - String i18n = AnnotationEnhanceUtils.findAnnotationArguments(args, "i18n", "").replaceAll("\"", ""); - - jcNewClass = treeMaker.NewClass(null, - com.sun.tools.javac.util.List.nil(), - treeMaker.Ident(names.fromString("PanelImpl")), - new ListBuffer<JCTree.JCExpression>() - .append(treeMaker.Literal(variableDecl.name.toString())) - .append(treeMaker.Apply( - com.sun.tools.javac.util.List.nil(), - treeMaker.Select(treeMaker.Ident(names.fromString("MdaUtils")), names.fromString("getI18NString")), - new ListBuffer<JCTree.JCExpression>() - .append(treeMaker.Ident(names.fromString("this"))) - .append(treeMaker.Literal(TypeTag.CLASS, i18n)) - .toList() - )) - .append(treeMaker.Ident(names.fromString("this"))) - .toList(), - null); - } else if (variableDecl.vartype.type.toString().equals(moduleClassNameProperties.get("IStream")) - || variableDecl.vartype.type.toString().equals(moduleClassNameProperties.get("StreamImpl"))) { - jcNewClass = treeMaker.NewClass(null, - com.sun.tools.javac.util.List.nil(), - treeMaker.Ident(names.fromString("StreamImpl")), - com.sun.tools.javac.util.List.nil(), - null); - } else if ((!variableDecl.vartype.type.isPrimitive() && variableDecl.vartype.type.toString().startsWith("com.ceb"))) { - jcNewClass = treeMaker.NewClass(null, - com.sun.tools.javac.util.List.nil(), - variableDecl.vartype, - new ListBuffer<JCTree.JCExpression>() - .append(treeMaker.Literal(instance)) - .append(treeMaker.Ident(names.fromString("this"))) - .toList(), - null); - } - //当jcNewClass == null 时 生成简单的get方法 - if (null != jcNewClass) { - body.append( - treeMaker.If( - treeMaker.Parens(treeMaker.Binary(JCTree.Tag.EQ, treeMaker.Select(treeMaker.Ident(names.fromString("this")), variableDecl.name), treeMaker.Literal(TypeTag.BOT, "null"))), - treeMaker.Exec(treeMaker.Assign(treeMaker.Select(treeMaker.Ident(names.fromString("this")), variableDecl.name), jcNewClass)), null)); - } - body.append(treeMaker.Return(treeMaker.Select(treeMaker.Ident(names.fromString("this")), variableDecl.name))); - JCTree.JCBlock jcBlock = treeMaker.Block(0, body.toList()); - - return treeMaker.MethodDef( - treeMaker.Modifiers(Flags.PUBLIC), //方法可见性 - names.fromString(methodName), //方法名称 - variableDecl.vartype, //返回值类型 - com.sun.tools.javac.util.List.nil(), //泛型参数列表 - com.sun.tools.javac.util.List.nil(), //参数列表 - com.sun.tools.javac.util.List.nil(), //抛出异常列表 - jcBlock, null); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/impl/ModuleGetterEnhance.java b/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/impl/ModuleGetterEnhance.java deleted file mode 100644 index 60802af..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/impl/ModuleGetterEnhance.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.brilliance.annotation.processor.enhance.impl; - -import com.brilliance.annotation.processor.enhance.AbstractAnnotationEnhance; -import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.util.ListBuffer; - -import java.util.List; -import java.util.stream.Collectors; - -/** - * Module 注解增强类 - * 实现普通的get方法 - */ -public class ModuleGetterEnhance extends AbstractAnnotationEnhance { - - @Override - public String getMethodName(JCTree.JCVariableDecl variableDecl) { - String variableName = variableDecl.name.toString(); - return "get" + variableName.substring(0, 1).toUpperCase() + variableName.substring(1); - } - - @Override - public JCTree.JCMethodDecl findJCMethodDecl(JCTree.JCClassDecl jcClassDecl, JCTree.JCVariableDecl variableDecl, String methodName) { - List<JCTree.JCMethodDecl> jcMethodDecls = jcClassDecl.defs - .stream().filter(it -> (it instanceof JCTree.JCMethodDecl)) - .map(it -> (JCTree.JCMethodDecl) it) - .collect(Collectors.toList()); - - for (JCTree.JCMethodDecl jcMethodDecl : jcMethodDecls) { - if (jcMethodDecl.name.toString().equals(methodName) - && jcMethodDecl.params.size() == 0 - && jcMethodDecl.restype.type.toString().equals(variableDecl.vartype.type.toString())) { - return jcMethodDecl; - } - } - return null; - } - - @Override - public JCTree.JCMethodDecl createJCMethodDecl(JCTree.JCClassDecl jcClassDecl, JCTree.JCVariableDecl variableDecl, String methodName, List<JCTree.JCExpression> args) { - ListBuffer<JCTree.JCStatement> body = new ListBuffer<>(); - body.append(treeMaker.Return(treeMaker.Select(treeMaker.Ident(names.fromString("this")), variableDecl.name))); - JCTree.JCBlock jcBlock = treeMaker.Block(0, body.toList()); - return treeMaker.MethodDef( - treeMaker.Modifiers(Flags.PUBLIC), //方法可见性 - names.fromString(methodName), //方法名称 - variableDecl.vartype, //返回值类型 - com.sun.tools.javac.util.List.nil(), //泛型参数列表 - com.sun.tools.javac.util.List.nil(), //参数列表 - com.sun.tools.javac.util.List.nil(), //抛出异常列表 - jcBlock, null); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/impl/ModuleSetterEnhance.java b/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/impl/ModuleSetterEnhance.java deleted file mode 100644 index fb020d3..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/impl/ModuleSetterEnhance.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.brilliance.annotation.processor.enhance.impl; - -import com.brilliance.annotation.processor.enhance.AbstractAnnotationEnhance; -import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.code.TypeTag; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.util.ListBuffer; - -import java.util.List; -import java.util.stream.Collectors; - -/** - * Module 注解增强类 - * 实现普通的set方法 - */ -public class ModuleSetterEnhance extends AbstractAnnotationEnhance { - @Override - public String getMethodName(JCTree.JCVariableDecl variableDecl) { - String variableName = variableDecl.name.toString(); - return "set" + variableName.substring(0, 1).toUpperCase() + variableName.substring(1); - } - - @Override - public JCTree.JCMethodDecl findJCMethodDecl(JCTree.JCClassDecl jcClassDecl, JCTree.JCVariableDecl variableDecl, String methodName) { - List<JCTree.JCMethodDecl> jcMethodDecls = jcClassDecl.defs - .stream().filter(it -> (it instanceof JCTree.JCMethodDecl)) - .map(it -> (JCTree.JCMethodDecl) it) - .collect(Collectors.toList()); - - for (JCTree.JCMethodDecl jcMethodDecl : jcMethodDecls) { - if (jcMethodDecl.name.toString().equals(methodName) - && jcMethodDecl.params.size() == 1 - && jcMethodDecl.params.get(0).vartype.type.toString().equals(variableDecl.vartype.type.toString())) { - return jcMethodDecl; - } - } - return null; - } - - @Override - public JCTree.JCMethodDecl createJCMethodDecl(JCTree.JCClassDecl jcClassDecl, JCTree.JCVariableDecl variableDecl, String methodName, List<JCTree.JCExpression> args) { - ListBuffer<JCTree.JCStatement> body = new ListBuffer<>(); - //添加语句 " this.xxx = xxx; " - body.append( - treeMaker.Exec( - treeMaker.Assign( - treeMaker.Select( - treeMaker.Ident(names.fromString("this")), - variableDecl.name - ), - treeMaker.Ident(variableDecl) - ) - ) - ); - JCTree.JCBlock jcBlock = treeMaker.Block(0, body.toList()); - - return treeMaker.MethodDef( - treeMaker.Modifiers(Flags.PUBLIC), //方法可见性 - names.fromString(methodName), //方法名称 - treeMaker.TypeIdent(TypeTag.VOID), //方法返回值 - com.sun.tools.javac.util.List.nil(), //泛型参数列表 - new ListBuffer<JCTree.JCVariableDecl>() - .append(treeMaker.VarDef(treeMaker.Modifiers(Flags.PARAMETER), variableDecl.name, variableDecl.vartype, null)) - .toList(), - com.sun.tools.javac.util.List.nil(), //抛出异常列表 - jcBlock, null); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/impl/TDGetterEnhance.java b/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/impl/TDGetterEnhance.java deleted file mode 100644 index 99a2a8a..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/impl/TDGetterEnhance.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.brilliance.annotation.processor.enhance.impl; - -import com.brilliance.annotation.processor.AnnotationEnhanceUtils; -import com.brilliance.annotation.processor.enhance.AbstractAnnotationEnhance; -import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.code.TypeTag; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.util.ListBuffer; - -import java.util.List; -import java.util.stream.Collectors; - -/** - * TDGetter注解增强实现类 - */ -public class TDGetterEnhance extends AbstractAnnotationEnhance { - - @Override - public String getMethodName(JCTree.JCVariableDecl variableDecl) { - String variableName = variableDecl.name.toString(); - return "get" + variableName.substring(0, 1).toUpperCase() + variableName.substring(1); - } - - @Override - public JCTree.JCMethodDecl findJCMethodDecl(JCTree.JCClassDecl jcClassDecl, JCTree.JCVariableDecl variableDecl, String methodName) { - List<JCTree.JCMethodDecl> jcMethodDecls = jcClassDecl.defs - .stream().filter(it -> (it instanceof JCTree.JCMethodDecl)) - .map(it -> (JCTree.JCMethodDecl) it) - .collect(Collectors.toList()); - - for (JCTree.JCMethodDecl jcMethodDecl : jcMethodDecls) { - if (jcMethodDecl.name.toString().equals(methodName) - && jcMethodDecl.params.size() == 0 - && jcMethodDecl.restype.type.toString().equals(variableDecl.vartype.type.toString())) { - return jcMethodDecl; - } - } - return null; - } - - @Override - public JCTree.JCMethodDecl createJCMethodDecl(JCTree.JCClassDecl jcClassDecl, JCTree.JCVariableDecl variableDecl, String methodName, List<JCTree.JCExpression> args) { - ListBuffer<JCTree.JCStatement> body = new ListBuffer<>(); - String instance = variableDecl.name.toString(); - if ("tmpint".equals(instance.trim())) { - instance = "int"; - } - - JCTree.JCNewClass jcNewClass = null; - - if (variableDecl.vartype.type.toString().startsWith(moduleClassNameProperties.get("IModuleList") + "<") - || variableDecl.vartype.type.toString().startsWith(moduleClassNameProperties.get("ModuleList") + "<")) { - JCTree.JCTypeApply typeApply = (JCTree.JCTypeApply) variableDecl.vartype; - List<JCTree.JCExpression> argsuments = typeApply.arguments; - String tClass = argsuments.get(0).toString(); - int initSize = AnnotationEnhanceUtils.findAnnotationArgumentsInt(args, "initSize", 0); - - jcNewClass = treeMaker.NewClass(null, - com.sun.tools.javac.util.List.nil(), - treeMaker.TypeApply(treeMaker.Ident(names.fromString("ModuleList")), - com.sun.tools.javac.util.List.nil()), - new ListBuffer<JCTree.JCExpression>() - .append(treeMaker.Literal(variableDecl.name.toString())) - .append(treeMaker.Ident(names.fromString("this"))) - .append(treeMaker.Literal(initSize)) - .append(treeMaker.Select(treeMaker.Ident(names.fromString(tClass)), names.fromString("class"))) - .toList(), - null); - } else if (variableDecl.vartype.type.toString().equals(moduleClassNameProperties.get("IPanel")) - || variableDecl.vartype.type.toString().equals(moduleClassNameProperties.get("PanelImpl"))) { - String i18n = AnnotationEnhanceUtils.findAnnotationArguments(args, "i18n", "").replaceAll("\"", ""); - - jcNewClass = treeMaker.NewClass(null, - com.sun.tools.javac.util.List.nil(), - treeMaker.Ident(names.fromString("PanelImpl")), - new ListBuffer<JCTree.JCExpression>() - .append(treeMaker.Literal(variableDecl.name.toString())) - .append(treeMaker.Apply( - com.sun.tools.javac.util.List.nil(), - treeMaker.Select(treeMaker.Ident(names.fromString("MdaUtils")), names.fromString("getI18NString")), - new ListBuffer<JCTree.JCExpression>() - .append(treeMaker.Ident(names.fromString("this"))) - .append(treeMaker.Literal(TypeTag.CLASS, i18n)) - .toList() - )) - .append(treeMaker.Ident(names.fromString("this"))) - .toList(), - null); - } else if (variableDecl.vartype.type.toString().equals(moduleClassNameProperties.get("IStream")) - || variableDecl.vartype.type.toString().equals(moduleClassNameProperties.get("StreamImpl"))) { - jcNewClass = treeMaker.NewClass(null, - com.sun.tools.javac.util.List.nil(), - treeMaker.Ident(names.fromString("StreamImpl")), - com.sun.tools.javac.util.List.nil(), - null); - } else if ((!variableDecl.vartype.type.isPrimitive() && variableDecl.vartype.type.toString().startsWith("com.ceb"))) { - jcNewClass = treeMaker.NewClass(null, - com.sun.tools.javac.util.List.nil(), - variableDecl.vartype, - new ListBuffer<JCTree.JCExpression>() - .append(treeMaker.Literal(instance)) - .append(treeMaker.Ident(names.fromString("this"))) - .toList(), - null); - } - //当jcNewClass == null 时 生成简单的get方法 - if (null != jcNewClass) { - body.append( - treeMaker.If( - treeMaker.Parens(treeMaker.Binary(JCTree.Tag.EQ, treeMaker.Select(treeMaker.Ident(names.fromString("this")), variableDecl.name), treeMaker.Literal(TypeTag.BOT, "null"))), - treeMaker.Exec(treeMaker.Assign(treeMaker.Select(treeMaker.Ident(names.fromString("this")), variableDecl.name), jcNewClass)), null)); - } - body.append(treeMaker.Return(treeMaker.Select(treeMaker.Ident(names.fromString("this")), variableDecl.name))); - JCTree.JCBlock jcBlock = treeMaker.Block(0, body.toList()); - - return treeMaker.MethodDef( - treeMaker.Modifiers(Flags.PUBLIC), //方法可见性 - names.fromString(methodName), //方法名称 - variableDecl.vartype, //返回值类型 - com.sun.tools.javac.util.List.nil(), //泛型参数列表 - com.sun.tools.javac.util.List.nil(), //参数列表 - com.sun.tools.javac.util.List.nil(), //抛出异常列表 - jcBlock, null); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/impl/TDSetterEnhance.java b/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/impl/TDSetterEnhance.java deleted file mode 100644 index 8f53d60..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/annotation/processor/enhance/impl/TDSetterEnhance.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.brilliance.annotation.processor.enhance.impl; - -import com.brilliance.annotation.processor.AnnotationEnhanceUtils; -import com.brilliance.annotation.processor.PrimitiveEnums; -import com.brilliance.annotation.processor.enhance.AbstractAnnotationEnhance; -import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.code.TypeTag; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.util.ListBuffer; - -import java.math.BigDecimal; -import java.util.Date; -import java.util.List; -import java.util.stream.Collectors; - -/** - * TDSetter注解增强实现类 - */ -public class TDSetterEnhance extends AbstractAnnotationEnhance { - - @Override - public String getMethodName(JCTree.JCVariableDecl variableDecl) { - String variableName = variableDecl.name.toString(); - return "set" + variableName.substring(0, 1).toUpperCase() + variableName.substring(1); - } - - @Override - public JCTree.JCMethodDecl findJCMethodDecl(JCTree.JCClassDecl jcClassDecl, JCTree.JCVariableDecl variableDecl, String methodName) { - List<JCTree.JCMethodDecl> jcMethodDecls = jcClassDecl.defs - .stream().filter(it -> (it instanceof JCTree.JCMethodDecl)) - .map(it -> (JCTree.JCMethodDecl) it) - .collect(Collectors.toList()); - - for (JCTree.JCMethodDecl jcMethodDecl : jcMethodDecls) { - if (jcMethodDecl.name.toString().equals(methodName) - && jcMethodDecl.params.size() == 1 - && jcMethodDecl.params.get(0).vartype.type.toString().equals(variableDecl.vartype.type.toString())) { - return jcMethodDecl; - } - } - return null; - } - - @Override - public JCTree.JCMethodDecl createJCMethodDecl(JCTree.JCClassDecl jcClassDecl, JCTree.JCVariableDecl variableDecl, String methodName, List<JCTree.JCExpression> args) { - ListBuffer<JCTree.JCStatement> body = new ListBuffer<>(); - boolean isNotifyDefault = AnnotationEnhanceUtils.findAnnotationArguments(args, "notifyDefault", "true").equals("true"); - if (String.class.getName().equals(variableDecl.vartype.type.toString())) { - int maxLength = AnnotationEnhanceUtils.findAnnotationArgumentsInt(args, "max", 0); - body.append(treeMaker.VarDef( - treeMaker.Modifiers(Flags.PARAMETER), - names.fromString("rs"), - treeMaker.TypeApply(treeMaker.Ident(names.fromString("Result")), - new ListBuffer<JCTree.JCExpression>().append(variableDecl.vartype).toList()), - treeMaker.Apply( - com.sun.tools.javac.util.List.nil(), - treeMaker.Select(treeMaker.Ident(names.fromString("this")), names.fromString("compareAndGetStr")), - new ListBuffer<JCTree.JCExpression>() - .append(treeMaker.Literal(variableDecl.name.toString())) - .append(treeMaker.Ident(names.fromString(variableDecl.name.toString()))) - .append(treeMaker.Select(treeMaker.Ident(names.fromString("this")), variableDecl.name)) - .append(treeMaker.Literal(maxLength)) - .toList() - ))); - body.append(treeMaker.Exec( - treeMaker.Assign( - treeMaker.Select(treeMaker.Ident(names.fromString("this")), variableDecl.name), - treeMaker.Select(treeMaker.Ident(names.fromString("rs")), names.fromString("value"))))); - if (isNotifyDefault) { - body.append(treeMaker.Exec( - treeMaker.Apply( - com.sun.tools.javac.util.List.nil(), - treeMaker.Select(treeMaker.Ident(names.fromString("rs")), names.fromString("notifyDefault")), - com.sun.tools.javac.util.List.nil() - ) - )); - } - } else if (BigDecimal.class.getName().equals(variableDecl.vartype.type.toString())) { - int scale = AnnotationEnhanceUtils.findAnnotationArgumentsInt(args, "scale", 2); - body.append(treeMaker.VarDef( - treeMaker.Modifiers(Flags.PARAMETER), - names.fromString("rs"), - treeMaker.TypeApply(treeMaker.Ident(names.fromString("Result")), - new ListBuffer<JCTree.JCExpression>().append(variableDecl.vartype).toList()), - treeMaker.Apply( - com.sun.tools.javac.util.List.nil(), - treeMaker.Select(treeMaker.Ident(names.fromString("this")), names.fromString("compareAndGetDecimal")), - new ListBuffer<JCTree.JCExpression>() - .append(treeMaker.Literal(variableDecl.name.toString())) - .append(treeMaker.Ident(names.fromString(variableDecl.name.toString()))) - .append(treeMaker.Select(treeMaker.Ident(names.fromString("this")), variableDecl.name)) - .append(treeMaker.Literal(scale)) - .toList() - ))); - body.append(treeMaker.Exec( - treeMaker.Assign( - treeMaker.Select(treeMaker.Ident(names.fromString("this")), variableDecl.name), - treeMaker.Select(treeMaker.Ident(names.fromString("rs")), names.fromString("value"))))); - if (isNotifyDefault) { - body.append(treeMaker.Exec( - treeMaker.Apply( - com.sun.tools.javac.util.List.nil(), - treeMaker.Select(treeMaker.Ident(names.fromString("rs")), names.fromString("notifyDefault")), - com.sun.tools.javac.util.List.nil() - ) - )); - } - } else if (Date.class.getName().equals(variableDecl.vartype.type.toString()) - || moduleClassNameProperties.get("IStream").equals(variableDecl.vartype.type.toString()) - || moduleClassNameProperties.get("StreamImpl").equals(variableDecl.vartype.type.toString()) - || variableDecl.vartype.type.isPrimitive()) { - body.append(treeMaker.VarDef( - treeMaker.Modifiers(Flags.PARAMETER), - names.fromString("rs"), - treeMaker.TypeApply(treeMaker.Ident(names.fromString("Result")), - variableDecl.vartype.type.isPrimitive() ? - new ListBuffer<JCTree.JCExpression>().append(treeMaker.Ident(names.fromString(PrimitiveEnums.getValues(variableDecl.vartype.toString()).getValue()))).toList() - : new ListBuffer<JCTree.JCExpression>().append(variableDecl.vartype).toList() - ), - treeMaker.Apply( - com.sun.tools.javac.util.List.nil(), - treeMaker.Select(treeMaker.Ident(names.fromString("this")), names.fromString("compareAndGet")), - new ListBuffer<JCTree.JCExpression>() - .append(treeMaker.Literal(variableDecl.name.toString())) - .append(treeMaker.Ident(names.fromString(variableDecl.name.toString()))) - .append(treeMaker.Select(treeMaker.Ident(names.fromString("this")), variableDecl.name)) - .toList() - ))); - body.append(treeMaker.Exec( - treeMaker.Assign( - treeMaker.Select(treeMaker.Ident(names.fromString("this")), variableDecl.name), - treeMaker.Select(treeMaker.Ident(names.fromString("rs")), names.fromString("value"))))); - if (isNotifyDefault) { - body.append(treeMaker.Exec( - treeMaker.Apply( - com.sun.tools.javac.util.List.nil(), - treeMaker.Select(treeMaker.Ident(names.fromString("rs")), names.fromString("notifyDefault")), - com.sun.tools.javac.util.List.nil() - ) - )); - } - } else { - return null; - } - JCTree.JCBlock jcBlock = treeMaker.Block(0, body.toList()); - - return treeMaker.MethodDef( - treeMaker.Modifiers(Flags.PUBLIC), //方法可见性 - names.fromString(methodName), //方法名称 - treeMaker.TypeIdent(TypeTag.VOID), //方法返回值 - com.sun.tools.javac.util.List.nil(), //泛型参数列表 - new ListBuffer<JCTree.JCVariableDecl>() - .append(treeMaker.VarDef(treeMaker.Modifiers(Flags.PARAMETER), variableDecl.name, variableDecl.vartype, null)) - .toList(), - com.sun.tools.javac.util.List.nil(), //抛出异常列表 - jcBlock, null); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/BDGetter.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/BDGetter.java deleted file mode 100644 index 13b548c..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/BDGetter.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.brilliance.mda.runtime.annotation; - -import java.lang.annotation.*; - -@Documented -@Inherited -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface BDGetter { - -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Check.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Check.java deleted file mode 100644 index 053d862..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Check.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.brilliance.mda.runtime.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -/** - * check函数 - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface Check { - int order() default 100; - String target() default ""; - String[] value() default {}; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Default.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Default.java deleted file mode 100644 index da61a17..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Default.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.brilliance.mda.runtime.annotation; - -import java.lang.annotation.*; - -/** - * default函数 - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface Default { - int order() default 100; - String target() default ""; - String[] value() default {}; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Init.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Init.java deleted file mode 100644 index 1b4d8a6..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Init.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.brilliance.mda.runtime.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * 初始化函数 - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface Init { - int order() default 100; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Module.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Module.java deleted file mode 100644 index caa593e..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Module.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.brilliance.mda.runtime.annotation; - -import java.lang.annotation.*; - -@Inherited -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE, ElementType.FIELD}) -public @interface Module { - - boolean getter() default true; - - boolean setter() default true; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/RelPath.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/RelPath.java deleted file mode 100644 index ee18b64..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/RelPath.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.brilliance.mda.runtime.annotation; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; -import com.brilliance.mda.runtime.mda.DirType; -/** - * 视图映射注解 - * @author fukai - * - */ -@Documented -@Retention(RUNTIME) -@Target({TYPE,FIELD}) -public @interface RelPath { - String value() default ""; //路径 - DirType dir() default DirType.BOTH ; //输入输出方向 - boolean recursion() default false; //是否递归关联 -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Rule.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Rule.java deleted file mode 100644 index f57785e..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Rule.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.brilliance.mda.runtime.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * 事件函数 - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface Rule { - String target() default ""; - int order() default 100; - String[] value() default {}; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Setter.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Setter.java deleted file mode 100644 index bb00b1c..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Setter.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.brilliance.mda.runtime.annotation; - -import java.lang.annotation.*; - -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * 用于引用模型的get函数 - */ -@Documented -@Retention(RUNTIME) -@Target(ElementType.TYPE) -@Repeatable(Setters.class) -public @interface Setter { - String path(); - String value(); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Setters.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Setters.java deleted file mode 100644 index ea3b290..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Setters.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.brilliance.mda.runtime.annotation; - -import java.lang.annotation.*; - -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * 用于引用模型的get函数 - */ -@Documented -@Retention(RUNTIME) -@Target(ElementType.TYPE) -public @interface Setters { - Setter[] value(); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/SimpleType.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/SimpleType.java deleted file mode 100644 index 2765d28..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/SimpleType.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.brilliance.mda.runtime.annotation; - -import java.lang.annotation.*; - -/** - * 标记为已简化处理 - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface SimpleType { - Class type(); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/TDGetter.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/TDGetter.java deleted file mode 100644 index 4dcff99..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/TDGetter.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.brilliance.mda.runtime.annotation; - -import java.lang.annotation.*; - -@Documented -@Inherited -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface TDGetter { - - String i18n() default ""; - - int initSize() default 0; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/TDMethod.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/TDMethod.java deleted file mode 100644 index 66ad597..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/TDMethod.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.brilliance.mda.runtime.annotation; - -import java.lang.annotation.*; - -/** - * 标记为TD的Method - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface TDMethod { - boolean value() default true; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/TDSetter.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/TDSetter.java deleted file mode 100644 index 8fa8125..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/TDSetter.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.brilliance.mda.runtime.annotation; - -import java.lang.annotation.*; - -@Documented -@Inherited -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface TDSetter { - - int max() default 0; - - int scale() default 2; - - boolean notifyDefault() default true; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/TDStatic.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/TDStatic.java deleted file mode 100644 index d55af4a..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/TDStatic.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.brilliance.mda.runtime.annotation; - -import java.lang.annotation.*; - -/** - * 标记为TD的Static方法 - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface TDStatic { - boolean value() default true; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Transaction.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Transaction.java deleted file mode 100644 index a9217a0..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/annotation/Transaction.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.brilliance.mda.runtime.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import com.brilliance.mda.runtime.mda.EmptyVO; - -/** - * 交易注解 - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface Transaction { - String value() default ""; - Class<?> vo() default EmptyVO.class; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/AttrType.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/AttrType.java deleted file mode 100644 index 457f9e2..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/AttrType.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -public enum AttrType { - - ATTRIBUTE, - MODIFIED, - ENABLED, - VALUES, - VISIABLE; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/CodeEntity.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/CodeEntity.java deleted file mode 100644 index e2f701a..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/CodeEntity.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import lombok.AllArgsConstructor; -import lombok.NoArgsConstructor; - -import java.util.List; - -@AllArgsConstructor -@NoArgsConstructor -public class CodeEntity { - public String path; - public List<String> values; - public boolean visited; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/CodetableItem.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/CodetableItem.java deleted file mode 100644 index 877fdf3..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/CodetableItem.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -public class CodetableItem -{ - private String label; - private String value; - private String description; - - public CodetableItem(String label, String value, String description) - { - this.label = label; - this.value = value; - this.description = description; - } - - public CodetableItem(String label, String value) - { - this.label = label; - this.value = value; - } - - public String getLabel() - { - return this.label; - } - - public void setLabel(String label) - { - this.label = label; - } - - public String getValue() - { - return this.value; - } - - public void setValue(String value) - { - this.value = value; - } - - public String getDescription() - { - return this.description; - } - - public void setDescription(String description) - { - this.description = description; - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/Constants.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/Constants.java deleted file mode 100644 index f316420..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/Constants.java +++ /dev/null @@ -1,380 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import com.brilliance.mda.runtime.mda.impl.StreamImpl; -import org.springframework.util.ResourceUtils; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Properties; - -public class Constants { - public static final String NULLSTR = ""; - public static final Date NULLDATE = null; - public static final Date NULLDATETIME = null; - public static final String CRLF = "\r\n"; - public static Date EMPDATE = null; - public static Class<?> Dynamic_class; - public static Class<?> Platform_class; - public static Properties packageInfo; - private static String GLOBAL_PACK_KEY = "global.package"; - static{ - packageInfo = new Properties(); - try { - packageInfo.load(ResourceUtils.getURL("classpath:package-info.properties").openStream()); - String busipack = packageInfo.getProperty(GLOBAL_PACK_KEY,""); - try{ - Dynamic_class = Class.forName(busipack+".Dynamic"); - }catch (Exception e){ - - } - Platform_class = Class.forName(busipack+".Platform"); - EMPDATE = new SimpleDateFormat("yyyyMMdd").parse("19900806"); - }catch (Exception e){ - e.printStackTrace(System.err); - System.exit(-1); - } - } - public static final int NO_SUCH_FIELD = 27; - public static final int NO_ERROR = 0; - public static final int NO_MORE_ROW = 228; - public static final int GLOBAL_CURSOR_NOT_SET=249; - public static final int NO_NAN = -37; - public static final int ARGUMENT_COUNT_ERROR=205; - public static final int ERROR_SQL = 200; - public static final int ERROR_COLUMN = 251; - public static final int ERROR_LOCK = 225; - public static final int ERROR_LOCKED = 226; - public static final int DATE_DAY = 5; - public static final int DATE_HOUR = 11; - public static final int DATE_MINUTE = 12; - public static final int DATE_SECOND = 13; - public static final String TRUE = "X"; - public static final String FALSE = ""; - public static final String CR = "\n"; - public static final String TAB = "\t"; - public static final String CALLER = ""; - public static final String FIRST = "_1st_"; - public static final String LASTTAG = "_tag_"; - public static final OpType EQ = OpType.EQ; - public static final OpType NE = OpType.NE; - public static final OpType GE = OpType.GE; - public static final OpType LE = OpType.LE; - public static final OpType GT = OpType.GT; - public static final OpType LT = OpType.LT; - public static final OpType IN = OpType.IN; - public static final OpType LIKE = OpType.LIKE; - public static final OpType NOTLIKE = OpType.NOTLIKE; - public static final OpType BETWEEN = OpType.BETWEEN; - public static final OpType OR = OpType.OR; - public static final OpType AND = OpType.AND; - public static final OpType NOT = OpType.NOT; - public static final OpType ISNULL = OpType.ISNULL; - public static final OpType ISNOTNULL = OpType.ISNOTNULL; - public static final OpType DESC = OpType.DESC; - public static final OpType ASC = OpType.ASC; - public static final RuleType INIT = RuleType.INIT; - public static final RuleType CHECK = RuleType.CHECK; - public static final RuleType RULE = RuleType.RULE; - public static final DecodeType DECODE_BASE64 = DecodeType.DECODE_BASE64; - public static final DecodeType DECODE_MD5 = DecodeType.DECODE_MD5; - public static final DecodeType DECODE_SHA = DecodeType.DECODE_SHA; - public static final DecodeType DECODE_SHA256 = DecodeType.DECODE_SHA256; - public static final DecodeType DECODE_SHA384 = DecodeType.DECODE_SHA384; - public static final DecodeType DECODE_SHA512 = DecodeType.DECODE_SHA512; - - - public static final String SdbEtyColEntity ="ETYEXTKEY"; - public static final String SdbEtyColEntityGroup ="ETGEXTKEY"; - public static final String DbsTypeInformix ="Informix"; - public static final String DbsTypeDB2 ="DB2"; - public static final String DbsTypeSqlServer ="SqlServer"; - public static final String DbsTypeFirebird ="Firebird"; - public static final String tdAttrKeyList ="KeyList"; - public static final int maxDate =99991231; - - public static final int tdDataTypeNumeric=2; - public static final int tdDataTypeText=1; - public static final int tdDataTypeBlock=3; - public static final int tdDataTypeDate=4; - public static final int tdDataTypeStream=7; - public static final int tdDataTypeDateTime=20; - public static final int tdDataTypeControl=5; - public static final int tdDataTypeNil=25; - public static final int tdDataParentIsNull=111; - public static final int tdDataDateOutOfBoundary=36; - public static final int tdDataDateStreamLineError=117; - public static final int tdViewTypeDateTime=30; - public static final int tdViewTypeButton=6; - public static final int tdViewTypeEdit=0; - public static final int tdViewTypeTime=26; - public static final int tdViewTypeLabel=5; - - public static final int tdStrBase36Encoding = 173; - public static final int tdOdbcLocked = 227; - public static final int tdOdbcHeld = 247; - public static final int tdOdbcNotFound=228; - public static final int tdOdbcNotUnique=-229; - public static final int tdOdbcNotSelected=-230; - public static final int TdOdbcSelectGridEmpty=-231; - public static final int tdCacheNotFound = 166; - public static final int tdOdbcDuplicateKey=229; - public static final int tdOdbcRowNotLocked=242; - public static final int tdOdbcNoTable=0; - - - //getModuleInfoStream - // update by wgc 2021-07-08 from 0 to 2 - public static int tdModuleDatafields = 1; - public static int tdModuleModules = 2; - public static int tdModuleRules = 3; - public static int tdModulePanels = 4; - public static int tdModuleAllDatafields = 5; - public static int tdModuleMenus = 6; - public static int tdModuleVisiblePanels = 7; - public static int tdModuleSearchDatafields = 8; - public static int tdModuleAllModules = 9; - public static int tdModuleDBIndexes = 10; - public static int tdModuleLockFields = 11; - public static int tdModuleAllMethods = 12; - public static int tdModuleAllModifiedFields = 13; - public static int tdModuleModifiedFields = 14; - - // public static int tdModuleModules = 2; - // public static int tdModuleLockFields = 0; - // public static int tdModuleAllModules = 0; - // public static int tdModuleAllModifiedFields = 13 ; - // public static int tdModuleVisiblePanels = 7 ; - // public static int tdModuleAllMethods = 12 ; - // public static int tdModuleDatafields = 1 ; - // public static int tdModulePanels = 199 ; - - - //getModuleInfo - public static final int tdModuleInfoClass = 1; - public static final int tdModuleInfoFullName= 2; - - public static final String tdAttrFullName = "0"; - public static final String tdAttrModified="MODIFIED"; - public static final String tdStringTRUE="TRUE"; - public static final String tdAttrLines="tdAttrLines"; - public static final String tdAttrLength="tdAttrLength"; - public static final String tdAttrContent="tdAttrContent"; - public static final String tdPanelFullName="tdPanelFullName"; - public static final String tdPanelName="tdPanelName"; - public static final String tdAttrConstant="tdAttrConstant"; - public static final String tdAttrEmpty="tdAttrEmpty"; - public static final String tdAttrDatatype="tdAttrDatatype"; - public static final String tdAttrViewtype="tdAttrViewtype"; - public static final String tdAttrCalendar="tdAttrCalendar"; - public static final String tdAttrEnabled="tdAttrEnabled"; - public static final String tdAttrCodeValues="tdAttrCodeValues"; - public static final String tdAttrName="tdAttrName"; - public static final String tdAttrDecpos="tdAttrDecpos"; - public static final String tdAttrFirstValue="tdAttrFirstValue"; - public static final String tdAttrCurrency="tdAttrCurrency"; - public static final String tdAttrFieldViewtype = "tdAttrFieldViewtype"; - public static final String tdAttrInfo = "tdAttrInfo"; - - - - public static final String tdContextAPPLICATIONSTATUS = "tdContextAPPLICATIONSTATUS"; - - public static final String tdUnit="tdUnit"; - public static final String tdUnitmm="tdUnitmm"; - public static final String tdUnitem="tdUnitem"; - public static final String tdPosCurrent="R"; - public static final String tdContextCLIENTSERVER="tdContextCLIENTSERVER"; - public static final String tdStringFALSE="tdStringFALSE"; - public static final String tdContextDBSERVICENAME="tdContextDBSERVICENAME"; - public static final String tdContextLANGUAGE="tdContextLANGUAGE"; - public static final String tdContextPOPUPTRIGGER="tdContextPOPUPTRIGGER"; - public static final String tdContextHTMLBASEURL = "tdContextHTMLBASEURL"; - public static final String tdContextBATCHMODE = "tdContextBATCHMODE"; - public static final String tdContextRETURNCODE = "tdContextRETURNCODE"; - public static final String tdContextDSPGENMODE = "tdContextDSPGENMODE"; - public static final String tdContextSERVERTYPE = "tdContextSERVERTYPE"; - public static final String tdContextLASTEXECRESULT = "tdContextLASTEXECRESULT"; - public static final String tdContextCOMMANDLINE = "tdContextCOMMANDLINE"; - public static final String tdContextPOSTQUEUE = "tdContextPOSTQUEUE"; - public static final String tdContextFILEVERSIONINFO = "tdContextFILEVERSIONINFO"; - public static final String tdContextSERVERPROGVER = "tdContextSERVERPROGVER"; - public static final String tdContextPROFILE = "tdContextPROFILE"; - public static final String tdContextPOPUPPANEL = "tdContextPOPUPPANEL"; - public static final String tdContextPAPERBINS = "tdContextPAPERBINS"; - - public static final String tdContextDEBUGLEVEL_PROF = "tdContextDEBUGLEVEL_PROF"; - public static final String tdContextDEBUGLEVEL_COMM = "tdContextDEBUGLEVEL_COMM"; - public static final String tdContextDEBUGLEVEL_SQL = "tdContextDEBUGLEVEL_SQL"; - public static final String tdContextDEBUGLEVEL_RULES = "tdContextDEBUGLEVEL_RULES"; - public static final String tdContextDEBUGLEVEL_USER = "tdContextDEBUGLEVEL_USER"; - public static final String tdContextDEBUGLEVEL_BUILTIN = "tdContextDEBUGLEVEL_BUILTIN"; - public static final String tdContextDEBUGLEVEL_BASEXEC = "tdContextDEBUGLEVEL_BASEXEC"; - public static final String tdContextDEBUGLEVEL_FLOW = "tdContextDEBUGLEVEL_FLOW"; - public static final String tdContextDEBUGLEVEL_SQLDATA = "tdContextDEBUGLEVEL_SQLDATA"; - public static final String tdContextDEBUGLEVEL_APPLICATION = "tdContextDEBUGLEVEL_APPLICATION"; - public static final String tdContextDEBUGLEVEL_INFO = "tdContextDEBUGLEVEL_INFO"; - - public static final String tdContextDBTransactionInfo = "tdContextDBTransactionInfo"; - //public static final String tdContextTZSYSTEM = "tdContextTZSYSTEM"; - public static final String tdContextTZUSER = "tdContextTZUSER"; - public static final String tdContextTDVCSFILE = "tdContextTDVCSFILE"; - public static final String tdContextSERVERID = "tdContextSERVERID"; - public static final String tdContextDISTRIBUTIONFILE = "tdContextDISTRIBUTIONFILE"; - public static final String tdContextMAXSTEPCOUNT = "tdContextMAXSTEPCOUNT"; - public static final String tdContextSWIFTEMPTYLINE = "tdContextSWIFTEMPTYLINE"; - public static final String tdContextSETTODAY="tdContextSETTODAY"; - public static final String tdContextSAVEDATASKIPEMPTY="SAVEDATASKIPEMPTY"; - - - - public static final String OitDontShow = "OitDontShow"; - public static final String GetLockUID = "GetLockUID"; - public static final String GetLockDate = "GetLockDate"; - public static final double GetLockTime = 0d; - public static final String GetLockDateTime = "GetLockDateTime"; - - public static final String tdContextSESSIONNUMBER = "tdContextSESSIONNUMBER"; - public static final String tdContextSERVERPID = "tdContextSERVERPID"; - public static final String tdContextCLIENTID = "tdContextCLIENTID"; - public static final String tdContextCLIENTPID = "tdContextCLIENTPID"; - public static final String tdContextUSERID = "tdContextUSERID"; - public static final String tdContextDBDRIVERNAME = "tdContextDBDRIVERNAME"; - public static final String tdContextTRIGGER = "tdContextTRIGGER"; - public static final String tdContextCALLSTACK = "CALLSTACK"; - public static final String tdContextLASTUSERACTIONTIME = "tdContextLASTUSERACTIONTIME"; - - public static int tdEventButtonPress=0; - public static int tdEventMouseLeave=1; - public static int tdEventTabLeave=2; - public static int tdEventHotkey=3; - public static int tdEventSelChange=4; - public static int tdEventGridSel=5; - public static int tdEventDragDrop=6; - public static int tdEventDragPrepare=7; - public static int tdEventGridDelete=8; - public static int tdEventGridInsert=9; - public static int tdEventFieldUpdate=10; - public static int tdEventPosted=11; - public static int tdEventPanelClose=12; - public static int tdEventPanelCreate=13; - public static final String tdPnlXML="tdPnlXML"; - - //public static String tdContextTZSYSTEM = "tdContextTZSYSTEM"; - public static String tdContextTZSYSTEM = "TZSYSTEM"; - public static String tdContextAUTHUSERINFO = "TZSYSTEM"; - public static String tdContextEXENAME = "EXENAME"; - - public static final int tdPromptOK=1; //1 - public static final int tdPromptCancel=2; //2 - public static final int tdPromptYes=1; //1 - public static final int tdPromptNo=0; //0 - public static boolean IsDesigner=true; - public static boolean IsAdministrator=false; - - public static final String tdAttrSelectedIdx = "tdAttrSelectedIdx"; - public static final String tdAttrSelected="tdAttrSelected"; - public static final String tdAttrChecked="tdAttrChecked"; - public static final String tdAttrCheckSwift="tdAttrCheckSwift"; - public static final String tdAttrExpandedIdx="tdAttrExpandedIdx"; - public static final String tdAttrCodetable="tdAttrCodetable"; - - public static final int tdViewTypeCombobox=2; - public static final int tdViewTypeDate=7; - public static final int tdViewTypeAmount=8; - public static final int tdViewTypeCheckbox=3; - public static final int tdViewTypeFormatted = 20; - - public static final int SRVTRNNoLock = 0; - public static final int SRVTRNLockOnly = 1; - public static final int SRVTRNUpdate = 2; - - public static final String NtfTypWarning = "5"; - - public static final String PanStaEdit="E"; - public static final String PanStaInquiry="I"; - public static final String PanStaDelete="D"; - public static final String PanStaAdd="A"; - public static final String PanStaHide="H"; - public static final String PanStaShow="S"; - public static final String PanStaLog="L"; - - public static final String SYSWRNTypeFinal="F"; - public static final String SYSWRNTypeWarning="W"; - public static final String SYSWRNTypeInfo="I"; - public static final String SYSWRNTypeStartup="S"; - public static final String SYSWRNTypeStartupInfo="C"; - //public static int tdPromptNo=0; - //public static int tdPromptOK=1; - public static final String SptWaitForIncoming="INC"; - public static final String SptWaitForAutoExec="AUT"; - public static final String SptWaitForRecalculation="EXE"; - public static final String SptAfterSentToRepair="COR"; - public static final String SptAfterRejection="REJ"; - public static final String SptAfterBreak="PEN"; - public static final String SptWaitForProcessing="PUP"; - - public static final String ClientTypeHtml="ClientTypeHtml"; - public static final String ClientTypeAjax="ClientTypeAjax"; - - public static final String TrnmodCancelExitWithPrompt="TrnmodCancelExitWithPrompt"; - public static final String LogmodInfo="LogmodInfo"; - public static final String LogmodWarning="LogmodWarning"; - public static final String LogmodError="LogmodError"; - - public static final String Quote = "\""; - public static final String NtfTypError = "NtfTypError"; - public static final String tdContextDBOpenCursors = "tdContextDBOpenCursors"; - public static final String tdContextSQLCURSOR = "tdContextSQLCURSOR"; - public static final String SptWaitForRelease = "SptWaitForRelease"; - public static final String AppIniFile = "AppIniFile"; - public static final String tdPaperbin1 = "tdPaperbin1"; - public static final String tdPaperbin2 = "tdPaperbin2"; - public static final String TrnmodCancelExitWithoutPrompt = "TrnmodCancelExitWithoutPrompt"; - - public static final String LscRejected="LscRejected"; - public static final String LscPending="LscPending"; - public static final String LscAccepted="LscAccepted"; - - - public static final String tdPageFirst = "tdPageFirst"; - public static final String tdPage = "tdPage"; - - public static final String tdContextCLIENTPROGVER="v505"; - - public static final String ClientTypeFat="F"; - public static final String ClientTypeWin32="W"; - public static final String ClientTypeJava="J"; - - public static final String SptWaitingIncoming="INC"; - public static final String SptWaitingRegistration="SptWaitingRegistration"; - public static final String SptWaitForManExec = "SptWaitForManExec"; - - public static final String tdContextSTARTTRANSACTION="tdContextSTARTTRANSACTION"; - - - public static final String DiaToWrite="DiaToWrite"; - public static final String DiaToReplace="DiaToReplace"; - - public static final String UilSwift = "UilSwift"; - public static final boolean SptIsexeLoaded = false; - -// public static final AttrGetter tdAttrCheckedIdx = new AttrGetter.DefaultAttrGetter(); - public static final String tdAttrCheckedIdx = "tdAttrCheckedIdx"; - public static IStream DDRSTREAM = new StreamImpl(); - - public static String DbsTypeAccess = "DbsTypeAccess"; - public static final String FF = "\r\n<FF/>\r\n"; - public static final String tdPosAbsolute = "tdPosAbsolute"; - public static final String tdPosition = "tdPosition"; - public static final String tdAttrVisible = "tdAttrVisible"; - public static final String OitStopPayment = "2"; - - public static final String tdContextFORM = "tdContextFORM"; - - public static final String tdPnlFrame = "tdPnlFrame"; - public static final String tdPnlDoc = "tdPnlDoc"; - - public static final String ATTR_CODE_VALUES="ATTR_CODE_VALUES"; - /** MX 转 MT 后 XML文件存放的文件夹名 */ - public static final String MX_BAK_DIR="MX"; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/DecodeType.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/DecodeType.java deleted file mode 100644 index ec4ddf9..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/DecodeType.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -public enum DecodeType { - DECODE_BASE64, DECODE_MD5, DECODE_SHA, DECODE_SHA256, DECODE_SHA384, DECODE_SHA512; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/DirType.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/DirType.java deleted file mode 100644 index cfe225d..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/DirType.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -public enum DirType { - IN,OUT,BOTH -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/EmptyVO.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/EmptyVO.java deleted file mode 100644 index c4c7b34..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/EmptyVO.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.brilliance.mda.runtime.mda; -/** - * 标记无VO - * @author fukai - * - */ -public class EmptyVO { - -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/Event.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/Event.java deleted file mode 100644 index 65ce2b0..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/Event.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/11 - */ -public class Event { - public static final int UNSELECTED_INDEX = -1; - - private IAttribute target; - - private EventType type; - - private Object data; - - public Event(IAttribute target, EventType type, Object data) { - this.target = target; - this.type = type; - this.data = data; - } - - public IAttribute getTarget() { - return this.target; - } - - public final EventType getType() { - return this.type; - } - - public final Object getData() { - return this.data; - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/EventType.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/EventType.java deleted file mode 100644 index 9abad7b..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/EventType.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/11 - */ -public enum EventType { - DEFAULT, ON_KEY_PRESS, ON_PULL_DOWN, ON_PULL_UP, ON_CHANGE, ON_CLICK, ON_DBLCLICK, ON_ROW_INSERT, ON_ROW_REMOVE, ON_STREAM_UPLOAD, ON_STREAM_DOWNLOAD, ON_PANEL_SHOW, ON_PANEL_CLOSE, ON_TIMER; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ExitEventException.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ExitEventException.java deleted file mode 100644 index 20da562..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ExitEventException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/11 - */ -public class ExitEventException extends RuntimeException { -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/FieldHolder.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/FieldHolder.java deleted file mode 100644 index 19814d6..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/FieldHolder.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import com.fasterxml.jackson.annotation.JsonIgnoreType; - -@JsonIgnoreType -public interface FieldHolder<T> { - - void setValue(T t); - T getValue(); - String getPath(); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/I18n.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/I18n.java deleted file mode 100644 index 18aa95b..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/I18n.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import java.util.Locale; - -public interface I18n { - public static final String I18N_IDENT = "/"; - - String getString(Locale paramLocale, String paramString1, String paramString2, int paramInt); - - String getString(Locale paramLocale, String paramString1, String paramString2); - - String getString(Locale paramLocale, String paramString, int paramInt); - - String getString(Locale paramLocale, String paramString); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IAttribute.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IAttribute.java deleted file mode 100644 index 9e34232..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IAttribute.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/11 - */ -public interface IAttribute<E> { - public static final String ID = "ID"; - - public static final String DESCRIPTION = "DESCRIPTION"; - - public static final String REQUIRED = "REQUIRED"; - - public static final String VISIBLE = "VISIBLE"; - - public static final String ENABLE = "ENABLE"; - - public static final String MODIFY = "MODIFY"; - - public static final String BYINPUT = "BYINPUT"; - - public static final String CODEVALUES = "CODEVALUES"; - - public static final String FORMAT = "FORMAT"; - - public static final String WIDTH = "WIDTH"; - - public static final String COLSPAN = "COLSPAN"; - - public static final String ROWSPAN = "ROWSPAN"; - - public static final String HEIGHT = "HEIGHT"; - - public static final String LENGTH = "LENGTH"; - - public static final String LINE = "LINE"; - - public static final String VIEWTYPE = "VIEWTYPE"; - - public static final String STYLE = "STYLE"; - - public static final String STYLECLASS = "STYLECLASS"; - - public static final String HINT = "HINT"; - - public static final String ARGS = "ARGS"; - - public static final String SAVEDISPLAY = "SAVEDISPLAY"; - - Object setAttribute(String paramString, Object paramObject); - - Object getAttribute(String paramString); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IAttributeValue.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IAttributeValue.java deleted file mode 100644 index b923879..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IAttributeValue.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/11 - */ -public interface IAttributeValue<E> extends IValue<E>, IAttribute { - void addCheckRule(IRule paramIRule); - - void addEventRule(IEventRule paramIEventRule); - - boolean invokeCheckRules(IContext paramIContext); - - boolean invokeEventRules(IContext paramIContext, EventType paramEventType, Object paramObject, int... paramVarArgs); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IAuthInfo.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IAuthInfo.java deleted file mode 100644 index 7d65e76..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IAuthInfo.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -public interface IAuthInfo { - //获取当前用户登录ID - String getUserId(); - - IStream getSysStream(); - - IStream getDdsStream(); - - IStream getKeepAuthInfo(); - - void recoveryAuthInfo(); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IBaseObject.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IBaseObject.java deleted file mode 100644 index 53cf33b..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IBaseObject.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import java.io.Serializable; - -public interface IBaseObject extends Serializable { - String getName(); - IModule getParent(); - String getPath(); - void clear(); - String separator = "\\"; - default String getDescription(){ - return ""; - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ICallback.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ICallback.java deleted file mode 100644 index a9e8c29..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ICallback.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/15 - */ -public interface ICallback { - Object invoke(Object... paramVarArgs); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IContext.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IContext.java deleted file mode 100644 index 212ea88..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IContext.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import com.brilliance.mda.runtime.mda.impl.EnvConfig; - -import java.io.Serializable; -import java.util.Locale; -import java.util.Map; - -public interface IContext extends Serializable { - - int ErrorHandled = 0,ErrorUnHandled=1; - String DISPLAY_KEY = "DISPLAY_KEY"; - - String getTransName(); - Map<String,Object> getModified(); - Map<String,String> getFieldErrors(); - String getMessage(); - String getErrorNo(); - void setModified(String path, Object value);//Platform.setModified() - void setFieldError(IModule m,String path, String errMsg);//Platform.error() - void setFieldError(IModule m,String path, String format,Object... obj);//Platform.error() - void setFieldError(IBaseObject baseobj, String errMsg);//Platform.error() - void setFieldError(IBaseObject baseobj, String format,Object... obj);//Platform.error() - void setMessage(String errorNo, String message);//Platform.message() - IModule getRoot(); - boolean checkAll(IModule module); - boolean postRule(RuleType ruleType, String target); - boolean postInit(); - boolean postRule(IModule m,String target); - boolean postRule(IModule m,String target,boolean isInModuleList); - boolean postRule(IBaseObject baseObject); - boolean postCheck(String target); - void setParams(Map<String, Object> params); - - Map<String, CodeEntity> getValuesSet(); - void visitValues(); - Map<String,Object> getRetMap(); - IDaoSession getDaoSession() ; - Pagination getPagination(String path); - - void storeCacheData(String key, Object data); - void deleteCacheData(String key); - void clearCacheData(); - Object restoreCacheData(String key); - - EnvConfig getEnvConfig(); - boolean saveDisplay(String fileName); - int getErrorCode(); - void setErrorCode(int errorCode); - void setErrorCode(int errorCode,String message); - void setErrorMessage(String errorMessage); - void setErrorMessage(String format,Object... values); - void setMessage(String format,Object... values); - String getErrorMessage(); - ILocker getLocker(); - - Locale getLocale(); - void setLocale(Locale locale); - - void setEmitter(IRuleEmitter emitter); - IRuleEmitter getEmitter(); - - void logout(); - <T> T getVo(); - void setVo(Object vo); - - <T> void setAttribute(Object parent,String prop,String ATTR,T val); - <T> T getAttribute(Object parent,String prop,String ATTR); - - void mallocPrintBuffer(); - String releasePrintBuffer(); - StringBuilder getCurPrintBuffer(); - PrintSegment getCurPrintSegment(); - - void pushEventPath(String path); - String getEventPath(); - void popEventPath(); - - void setError(IDatafield t); - void setError(String str); - void reraise(); - int getErrorState(); - void resetErrorState(); - void clearEntireError(); - - void setConcurrentCallStack(String path); - String getConcurrentCallStack(); - <T> T absGet(Class<T> clazz); - <T> T absGet(Class<T> clazz,String instName); - - Object restoreData(String key); - void storeData(String key,Object data); - void deleteData(String key); - void clearData(); - - <T> T getParam(String key); - <T> void setParam(String key,T t); - void resetParams(Map<String, Object> params); - - int assignSerialNo(); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IControl.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IControl.java deleted file mode 100644 index b4eded5..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IControl.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import com.fasterxml.jackson.annotation.JsonIgnoreType; - -@JsonIgnoreType -public interface IControl extends IBaseObject { -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IDaoSession.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IDaoSession.java deleted file mode 100644 index 85c58f1..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IDaoSession.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import com.brilliance.mda.runtime.mda.impl.Argument; - -import java.util.Date; - -public interface IDaoSession { - - void dbBegin(); - void dbCommit(); - void dbRollback(); - - void putDao(Class<?> key, Object dao); - int dbCounter(String seqname); - - int dbInsert(IModule modull); - - - int dbUpdate(IModule module,Object v1,String whereCol1); - int dbUpdate(IModule module,Object v1,String whereCol1,Object v2,String whereCol2); - <T extends IModule> int dbUpdate(T module); - - - int dbDelete(IModule module); - int dbDelete(IModule module, Object val, String col); - int dbDelete(IModule module, Object val, String col,Object val2,String col2); - int dbDelete(IModule module, Argument<? extends Object>... args); - - - <T extends IModule> T dbRead(T module, Object... args); - <T extends IModule> T dbRead(T module, Argument... args); - <T extends IModule> T dbReadNoData(T module, Object... args); - - <T extends IModule> T dbReadByArguments(T module, Argument<? extends Object>... args); - <T extends IModule> T dbReadHold(T module, Object... args); - - <T extends IModule> int dbReadSet(IModuleList<T> list, Object... args); - <T extends IModule> int dbReadset(IModuleList<T> list, Object... args); - <T extends IModule> int dbReadSetByArguments(IModuleList<T> list, Argument<? extends Object>... args); - @SuppressWarnings("rawtypes") - <T extends IModule> int dbReadset(IModuleList<T> list,int limitSize, Argument... args); - - <T extends IModule> int dbReadset(IModuleList<T> list, String whereSql); - - <T extends IModule> int dbReadset(IModuleList<T> list, String whereSql,Object[] params); - - <T extends IModule> int dbReadset(IModuleList<T>[] lists, int maxSize, String whereClause, Object[] datas); - void dbReadset(IModuleList[] lists, String whereClause, Object[] datas); - void dbReadset(IModuleList list, int maxSize, String sql); - - - void dbExecuteSQL(IStream stm); - void dbExecuteSQL(IStream sql, IStream retstream); - void dbExecuteSQL(String sql,Object... params); - - void dbFetch(IModule module); - void dbFetchStream(IStream args); - void dbFetchFields(Object... args); - void dbFetchFields(Argument<? extends Object>... arguments); - - void dbCloseCursor(); - String dbSqlDate(Date endDat); - - //TODO 待实现 - void dbFreeAll(); - void setWaitCursor(); - void dbHold(IModule module); - void dbFree(IModule module); - void dbSelect(IModule module, String string, String sql, Object... val); - void DBOpen(IModule module); - void dbSelectCursor(IModule module,String whereSql,Object... params); - - boolean isOpenTrans(); - void dbConnect(); - void dbDisconnect(); - String dbName(); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IDataGrid.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IDataGrid.java deleted file mode 100644 index c1cf1ef..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IDataGrid.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import java.io.File; -import java.io.IOException; -import java.util.List; - -public interface IDataGrid { - - String getLine(int idx); - String deleteLine(int idx); - void sortLines(); - int countLines(); - int searchLine(String line); - void setRows(List<String> list); - List<String> getRows(); - void insertLine(int idx,String line); - void setLine(int idx,String line); - - void clearLines(); - void addLine(String line); - void saveLines(File file)throws IOException; - void loadLines(File file) throws IOException; - boolean isLinesChanged(); - <T> void setAttribute(String attr,T t); - <T> T getAttribute(String attr); - - String defaultColDelimiter = "\t"; - -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IDatafield.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IDatafield.java deleted file mode 100644 index a062afb..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IDatafield.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -public interface IDatafield<T> extends IBaseObject{ - T getValue(); - void setValue(T value); - Class<T> getDataType(); - void setAttribute(Object k,Object v); - Object getAttribute(Object k); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IDisplay.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IDisplay.java deleted file mode 100644 index 973fad9..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IDisplay.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.brilliance.mda.runtime.mda; - - -/** - * 快照保存接口,保存的东西,可以使文件路径/或者是文件保存key。具体实现由实施情况决定。 - * 可以使保存至数据库/保存至NOSQL数据库/保存至文件存储器 - * @author fukai - * - */ -public interface IDisplay { - boolean saveDisplay(String filePathOrKey, String data); - String readDisplay(String filePathOrKey); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IEventRule.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IEventRule.java deleted file mode 100644 index 49a94b7..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IEventRule.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.brilliance.mda.runtime.mda; - - -import java.io.Serializable; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/11 - */ -public interface IEventRule extends Serializable { - int getOrder(); - - EventType getType(); - - boolean invoke(IContext paramIContext, Event paramEvent); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ILocker.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ILocker.java deleted file mode 100644 index 8851cfa..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ILocker.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import java.io.Serializable; - -public interface ILocker { - boolean lock(Serializable key); - boolean lock(Serializable key, int expireflg); - boolean lock(Serializable key, long timeout); - LockInfo lock(String userName,Serializable key); - boolean unlock(Serializable key); - boolean unlock(String lockname, Serializable key); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ILoginContext.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ILoginContext.java deleted file mode 100644 index edae332..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ILoginContext.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -/** - * TODO 认证实现类,实现登录签发Token,认证Token - * @author fukai - * - */ -public interface ILoginContext { - Object login(String id, String pwd); - Object auth(String token); - Object logout(String token); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IModule.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IModule.java deleted file mode 100644 index d3374fd..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IModule.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import java.util.Collection; -import java.util.List; -import java.util.Map; - -public interface IModule extends IBaseObject{ - default boolean isEntity() {return false;}; - String getSerialNum(); - void assignSerialNum(); - void copyValue(IModule src); - void copyValues(IModule src); - Map<String, Object> getAttrMaps(); - default String getFieldPath(String fieldName) {return null;}; - - /** - * 废弃的方法,不要再使用了 - * @return - */ - @Deprecated - default Collection<IDatafield> getDatafields(){return null;}; - - /** - * 基于反射实现的,尽量不要用了 - * @return - */ - @Deprecated - default List<IModule> getModules(){return null;}; - - default String getTableName() - { - return null; - } - - IBaseObject get(String paramString); - -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IModuleAttribute.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IModuleAttribute.java deleted file mode 100644 index 7d09a2e..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IModuleAttribute.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/11 - */ -public interface IModuleAttribute extends IModule { - // void clearIdAttribute(); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IModuleList.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IModuleList.java deleted file mode 100644 index 9ae3537..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IModuleList.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import java.util.List; - -public interface IModuleList<T extends IModule> extends IModule,List<T> { - int getFullDbSize(); - int fullSize(); - Class<T> getDataClass(); - void removeAll(); - - @Override - default String getSerialNum() { - return null; - } - - @Override - default void assignSerialNum() {}; - - /** - * 废弃的方法,不建议使用 - * @param args IDatafield Argument 两项参数 - */ - @Deprecated - T add(Object... args); - - void addElement(T em); - void addElement(int index,T em); - default void copyValues(IModule src){ - - } - default void copyValue(IModule src) - { - copyValues(src); - } - - boolean executeInit(); - boolean executeInit(int idx); - void executeDefault(String... paths); - void executeDefault(int idx,String... paths); - - void executeCheckAll(); -} \ No newline at end of file diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IModuleRoot.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IModuleRoot.java deleted file mode 100644 index 87d7e56..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IModuleRoot.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/11 - */ -public interface IModuleRoot extends IModuleAttribute { - public static final Log log = LogFactory.getLog(IModuleRoot.class); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IPanel.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IPanel.java deleted file mode 100644 index 675de08..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IPanel.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import com.fasterxml.jackson.annotation.JsonIgnoreType; - -@JsonIgnoreType -public interface IPanel extends IBaseObject{ - String getLanguage(); - - IModule getModule(); - - String getTitleI18nKey(); - - void setWindow(Object paramObject); - - Object getWindow(); - - void addEventRule(IEventRule paramIEventRule); - - boolean invokeEventRules(IContext paramIContext, Event paramEvent); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IParent.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IParent.java deleted file mode 100644 index 244293f..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IParent.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/15 - */ -public interface IParent extends IBaseObject { - public static final IParent[] EMPTY = new IParent[0]; - - void addChild(); - - void bindEvents(IContext paramIContext); - - void init(IContext paramIContext); - - void copyValues(IParent paramIParent); - - Object getAttribute(IBaseObject paramIBaseObject, String paramString); - - Object setAttribute(IBaseObject paramIBaseObject, String paramString, Object paramObject); - - void updateSubUrls(int paramInt); - - String getSubUrl(Object paramObject); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IResult.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IResult.java deleted file mode 100644 index 94b9e42..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IResult.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -public interface IResult<E> extends IValue<E> { - String getName(); -} \ No newline at end of file diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IRule.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IRule.java deleted file mode 100644 index 022e8dc..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IRule.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import java.io.Serializable; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/11 - */ -public interface IRule extends Serializable { - int getOrder(); - - boolean invoke(IContext paramIContext, IAttributeValue paramIAttributeValue); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IRuleEmitter.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IRuleEmitter.java deleted file mode 100644 index 6e9e8c8..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IRuleEmitter.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import java.util.List; -import java.util.Map; - -public interface IRuleEmitter { - String EMITTER_PRE = "emitter2."; - boolean executeInit(); - boolean executeInit(int order); - boolean executeRule(String target); - boolean executeCheck(String target); - boolean executeRule(String target,int order); - boolean executeCheck(String target,int order); - boolean executeCheckAll(); - boolean executeDefault(String target); - boolean executeDefault(String target, int order); - boolean executeDefaultAfterInit(); - boolean executeDefaultAll(); -// boolean executeDefaultAfterRule(String target); - Map<String,Object> getDefaultRuleQue(); - - IModule getRoot(); - String getModuleName(); - - Class<?> relatedTransaction(); - String getRealPath(String path); - List<IModuleList> getAllModuleList(); - -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ISqlTemplate.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ISqlTemplate.java deleted file mode 100644 index d63c603..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ISqlTemplate.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import java.util.List; -import java.util.Map; - -public interface ISqlTemplate { - <T> List<T> dbQuery(String statement, Map<String,Object> params); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IState.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IState.java deleted file mode 100644 index 8c33d0b..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IState.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/15 - */ -public interface IState { - boolean getContinued(); - - void sleep(); - - void setStopCallback(IStopCallback paramIStopCallback); - - public static interface IStopCallback { - void stop(); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IStream.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IStream.java deleted file mode 100644 index 4def801..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IStream.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import com.brilliance.mda.support.jakson.serialize.IStreamDeSerialized; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Serializable; - -@JsonDeserialize(using = IStreamDeSerialized.class) -public interface IStream extends IDataGrid,Serializable { - InputStream getInputStream(); - OutputStream getOutputStream(); - void close(); - boolean isEmpty(); - void setType(String type); - String getType(); - void setName(String name); - String getName(); - String setValue(String value); - String getValue(); - boolean isKeepsort(); - void setKeepsort(boolean keepsort); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IValue.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IValue.java deleted file mode 100644 index 83877e4..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/IValue.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/11 - */ -public interface IValue<E> extends Comparable<IValue<E>> { - E setValue(E value); - - E getValue(); - - Class getDataType(); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/LockInfo.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/LockInfo.java deleted file mode 100644 index 532a923..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/LockInfo.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.brilliance.mda.runtime.mda; - - -import java.text.SimpleDateFormat; -import java.util.Date; - -public class LockInfo -{ - public Date date; - public String name; - - public LockInfo(Date date, String name) - { - this.date = date; - this.name = name; - } - - public String toString() - { - return String.format("Lock by %s at %s", new Object[] { this.name, new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(this.date) }); - } -} \ No newline at end of file diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/MessageType.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/MessageType.java deleted file mode 100644 index 8602f76..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/MessageType.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/11 - */ -public enum MessageType { - INFORMATION, ERROR, QUESTION; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ModuleHolder.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ModuleHolder.java deleted file mode 100644 index e87d5e8..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ModuleHolder.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -import com.fasterxml.jackson.annotation.JsonIgnoreType; - -@JsonIgnoreType -@FunctionalInterface -public interface ModuleHolder<T> { - T get(); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ModuleInfoGetter.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ModuleInfoGetter.java deleted file mode 100644 index 056e7c5..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ModuleInfoGetter.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -public interface ModuleInfoGetter { - String get(IModule module); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/OpType.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/OpType.java deleted file mode 100644 index 6713332..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/OpType.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -public enum OpType -{ - EQ, NE, GE, LE, GT, LT, IN, LIKE, NOTLIKE, BETWEEN, OR, AND, NOT, ISNULL, ISNOTNULL, ASC, DESC; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/Pagination.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/Pagination.java deleted file mode 100644 index 8fe75b9..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/Pagination.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -public class Pagination { - public String dir; //排序方向 - public String sortField; //排序字段 - public int pageno; //从0开始计算 - public int total; //总数量 -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/PrintSegment.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/PrintSegment.java deleted file mode 100644 index ebd66dd..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/PrintSegment.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -public class PrintSegment { - private StringBuilder buffer; - private String segname; - - public PrintSegment() - { - buffer = new StringBuilder(); - } - - public StringBuilder getBuffer() { - return buffer; - } - - public void setBuffer(StringBuilder buffer) { - this.buffer = buffer; - } - - public String getSegname() { - return segname; - } - - public void setSegname(String segname) { - this.segname = segname; - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/RuleExecuteException.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/RuleExecuteException.java deleted file mode 100644 index 1ca9d33..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/RuleExecuteException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -public class RuleExecuteException extends RuntimeException { - public RuleExecuteException(String message,Throwable e) - { - super(message,e); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/RuleExitException.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/RuleExitException.java deleted file mode 100644 index 36f120e..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/RuleExitException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -public class RuleExitException extends RuntimeException { - public RuleExitException(String message) - { - super(message); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/RulePromptException.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/RulePromptException.java deleted file mode 100644 index 1c53977..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/RulePromptException.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -/** - * 设置为弹出处理的异常 - */ -public class RulePromptException extends RuntimeException { - public RulePromptException(String message) - { - super(message); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/RuleType.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/RuleType.java deleted file mode 100644 index edfe0e9..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/RuleType.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -public enum RuleType { - RULE("RULE"), - INIT("INIT"), - CHECK("CHECK"); - - private String type; - - private RuleType(String type){ - this.type = type; - } - - public String toString(){ - return this.type; - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/RuleWarnException.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/RuleWarnException.java deleted file mode 100644 index d2d85ac..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/RuleWarnException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -public class RuleWarnException extends RuntimeException{ - public RuleWarnException(String message) - { - super(message); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/Ruleable.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/Ruleable.java deleted file mode 100644 index bb2e84d..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/Ruleable.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -@FunctionalInterface -public interface Ruleable<T> { - T exec(); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ViewType.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ViewType.java deleted file mode 100644 index bc259ed..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/ViewType.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.brilliance.mda.runtime.mda; - -/** - * @Description - * @Author s_guodong - * @Date 2022/11/11 - */ -public enum ViewType { - VIEW_LABEL, VIEW_EDIT, VIEW_DATEBOX, VIEW_DECIMALBOX, VIEW_COMBO, VIEW_CHECK, VIEW_RADIO, VIEW_RADIOS, VIEW_HYPER, VIEW_BUTTON; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/config/Bundle.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/config/Bundle.java deleted file mode 100644 index 0a77005..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/config/Bundle.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.brilliance.mda.runtime.mda.config; - -import java.util.Properties; - -public class Bundle extends Properties { - - private static Bundle bundle = new Bundle(); - - public static Bundle get() { - return bundle; - } - - private static final long serialVersionUID = 1L; - - public boolean getBoolean(String key) { - return getBoolean(key, false); - } - - public boolean getBoolean(String key, boolean defaultValue) { - String temp = getProperty(key); - if (temp == null || temp.length() == 0) { - return defaultValue; - } - return Boolean.parseBoolean(temp); - } - - public double getDouble(String key) { - return getDouble(key, 0); - } - - public double getDouble(String key, double defaultValue) { - String temp = getProperty(key); - if (temp == null || temp.length() == 0) { - return defaultValue; - } - return Double.parseDouble(temp); - } - - public int getInteger(String key) { - return getInteger(key, 0); - } - - public int getInteger(String key, int defaultValue) { - String temp = getProperty(key); - if (temp == null || temp.length() == 0) { - return defaultValue; - } - return Integer.parseInt(temp); - } - - public long getLong(String key) { - return getLong(key, 0); - } - - public long getLong(String key, long defaultValue) { - String temp = getProperty(key); - if (temp == null || temp.length() == 0) { - return defaultValue; - } - return Long.parseLong(temp); - } - - private void addLine(String line) { - if (line == null || line.length() == 0) { - return; - } - int index = line.indexOf("="); - if (index == -1) { - return; - } - String key = line.substring(0, index); - String value = line.substring(index + 1); - key = trim(key); - value = trim(value); - put(key, value); - } - - public Properties loadString(String content) { - if (content == null || content.length() == 0) { - return this; - } - String[] lines = content.split("\n"); - for (String line : lines) { - addLine(line); - } - - return this; - } - - private String trim(String value) { - return value.trim().replace("\r", "").replace("\t", ""); - } - -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/config/IniConfig.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/config/IniConfig.java deleted file mode 100644 index d4c1ce4..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/config/IniConfig.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.brilliance.mda.runtime.mda.config; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.util.StringUtils; - -import java.io.*; -import java.util.HashMap; -import java.util.Map; - -public class IniConfig { - private static Logger logger = LoggerFactory.getLogger(IniConfig.class); - private static Map<String,IniConfig> iniConfigMap = new HashMap<>(); - - public static String getIniConfig(String iniName,String block,String key){ - //返回默认币种 - if(key!=null && (key.equalsIgnoreCase("SysCurrency") - ||key.equalsIgnoreCase("RateBaseCurrency") - ||key.equalsIgnoreCase("CURRENCY"))){ - return "EUR"; - } - //后续需要添加在trade.ini中 - if(iniConfigMap.containsKey(iniName.toUpperCase())) - return iniConfigMap.get(iniName.toUpperCase()).get(block.toUpperCase(),key.toUpperCase()); - return ""; - } - - private Map<String, Map<String,String>> data = new HashMap<>(); - - public String get(String block,String key){ - if(data.containsKey(block)) - return data.get(block).get(key); - return null; - } - - public void set(String block,String key,String value){ - if(!data.containsKey(block)) - data.put(block,new HashMap<>()); - data.get(block).put(key,value); - } - - - public static void loadIni(File file){ - IniConfig config = new IniConfig(); - - try(BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"gb2312"))) { - String str="",block=""; - while ((str = br.readLine()) != null){ - if(StringUtils.isEmpty(str)) - continue; - if(str.indexOf('[')==0){ - if (str.indexOf(']') < 0){ - block = str.substring(1); - }else{ - block = str.substring(1,str.indexOf(']')); - } - block = block.toUpperCase(); - }else if(str.indexOf('=')>-1){ - if (str.indexOf(';') == 0){ - continue; - } - if (str.indexOf(';') > 0){ - str = str.substring(0, str.indexOf(';')); - } - String[] ary = str.trim().split("="); - String val = ""; - if (ary.length >= 2){ - val = ary[1]; - } - config.set(block,ary[0].trim().toUpperCase(),val); - } - } - } catch (Exception e) { - logger.error(String.format("解析INI配置[%s]错误!", file.getAbsolutePath())); - System.exit(-1); - } - iniConfigMap.put(file.getName().toUpperCase(),config); - } - - public static Map<String, IniConfig> getIniConfigMap() { - return iniConfigMap; - } - - public Map<String, Map<String, String>> getData() { - return data; - } -} - diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/MdaScanner.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/MdaScanner.java deleted file mode 100644 index 007a68c..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/MdaScanner.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver; - -import java.io.IOException; -import java.lang.annotation.Annotation; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; - -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; -import org.springframework.context.ResourceLoaderAware; -import org.springframework.core.io.Resource; -import org.springframework.core.io.ResourceLoader; -import org.springframework.core.io.support.ResourcePatternResolver; -import org.springframework.core.io.support.ResourcePatternUtils; -import org.springframework.core.type.classreading.CachingMetadataReaderFactory; -import org.springframework.core.type.classreading.MetadataReader; -import org.springframework.core.type.classreading.MetadataReaderFactory; -import org.springframework.stereotype.Component; - -/** - * 扫描包路径的交易类 - * @author fukai - * - */ -@Component -@Data -@Slf4j -public class MdaScanner implements ResourceLoaderAware, BeanDefinitionRegistryPostProcessor { - - private ResourceLoader resourceLoader; - - private BeanDefinitionRegistry beanDefinitionRegistry; - - @Override - public void setResourceLoader(ResourceLoader resourceLoader) { - this.resourceLoader = resourceLoader; - } - - @Override - public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException { - this.beanDefinitionRegistry = beanDefinitionRegistry; - } - /** - * - * @param packagePath 类路径,以"/"斜线分隔 - * @return 该包下的添加了该注解的类 - * @throws IOException - * @throws ClassNotFoundException - */ - public Set<Class<?>> doScan(String packagePath,Class<? extends Annotation> anoclazz) throws IOException, ClassNotFoundException - { - HashSet<Class<?>> set = new HashSet<Class<?>>(); - ResourcePatternResolver resolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader); - MetadataReaderFactory metaReader = new CachingMetadataReaderFactory(resourceLoader); - String path = "classpath*:"+packagePath+"/**/*.class"; - log.info("MdaScanner doScan:{}", path); - Resource[] resources = resolver.getResources(path); - - for (Resource r : resources) { - if(!r.isReadable()) - continue; - MetadataReader reader = metaReader.getMetadataReader(r); - if(!reader.getClassMetadata().isConcrete()) // 当类型不是抽象类或接口在添加到集合 - continue; - - String className = reader.getClassMetadata().getClassName(); - Class<?> clazz = Class.forName(className); - if(clazz.isAnnotationPresent(anoclazz)) - { - set.add(clazz); - } - } - return set; - } - - public Map<Class<?>, Set<Class<?>>> doScan(Map<Class<?>, Set<Class<?>>> map, String packagePath, Class<? extends Annotation>... annotationClasses) throws IOException, ClassNotFoundException { - ResourcePatternResolver resolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader); - MetadataReaderFactory metaReader = new CachingMetadataReaderFactory(resourceLoader); - String path = "classpath*:" + packagePath + "/**/*.class"; - log.info("MdaScanner doScan:{}", path); - Resource[] resources = resolver.getResources(path); - - for (Resource r : resources) { - if (!r.isReadable()) - continue; - MetadataReader reader = metaReader.getMetadataReader(r); - if (!reader.getClassMetadata().isConcrete()) // 当类型不是抽象类或接口在添加到集合 - continue; - String className = reader.getClassMetadata().getClassName(); - Class<?> clazz = Class.forName(className); - for (Class<? extends Annotation> annotationClass : annotationClasses) { - if (clazz.isAnnotationPresent(annotationClass)) { - Set<Class<?>> set = map.computeIfAbsent(annotationClass, k -> new LinkedHashSet<>()); - set.add(Class.forName(className)); - } - } - } - return map; - } - - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException { - - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/NamesMapper.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/NamesMapper.java deleted file mode 100644 index 13e321d..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/NamesMapper.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver; - -import java.util.HashMap; -import java.util.Map; -/** - * - * @author fukai - * 扫描vo类、配置目录,实现VO长短类名检测 - */ -public class NamesMapper { - private static Map<String,Alias> trnAlias = new HashMap<String,Alias>(); - - public static Alias genTransAlias(String trnName) - { - Alias alias = trnAlias.get(trnName); - if(alias == null) - { - alias = new Alias(trnName); - trnAlias.put(trnName, alias); - } - return alias; - } - public static Alias getAlias(String trnName){ - return trnAlias.get(trnName); - } - - public static class Alias{ - private Map<String,String> pathAliasMap = new HashMap<String,String>(); - private Map<String,String> revertMap = new HashMap<String,String>(); - - private String trnName; - public Alias(String trnName) - { - this.trnName = trnName; - } - - public Map<String, String> getPathAliasMap() { - return pathAliasMap; - } - - public void setPathAliasMap(Map<String, String> pathAliasMap) { - this.pathAliasMap = pathAliasMap; - } - - public Map<String, String> getRevertMap() { - return revertMap; - } - - public void setRevertMap(Map<String, String> revertMap) { - this.revertMap = revertMap; - } - - public String getRelPath(String alias) { - return this.pathAliasMap.get(alias); - } - public String getPathAlias(String path) - { - return revertMap.get(path); - } - public String getTrnName() { - return trnName; - } - - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/StatusInfoConfig.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/StatusInfoConfig.java deleted file mode 100644 index ff71a63..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/StatusInfoConfig.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver; - -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.Data; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.core.io.support.ResourcePatternResolver; - -import java.io.InputStream; -import java.util.*; - -@Data -public class StatusInfoConfig { - - private static StatusInfoConfig config = null; - - public static Map<String, Map<String, Set<String>>> statusInfoMap = new HashMap<>(); - - private static String location = "classpath:statusInfo/*"; - private static String separator = "."; - - static { - ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); - try { - Resource[] resources = resourceResolver.getResources(location); - for (Resource resource : resources) { - statusInfoMap.put(Objects.requireNonNull(resource.getFilename()).substring(0, resource.getFilename().indexOf(".")), collecSignleTranMap(resource.getInputStream())); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - private static Map<String, Set<String>> collecSignleTranMap(InputStream inputStream)throws Exception{ - ObjectMapper om = new ObjectMapper(); - Map<String,Object> map = om.readValue(inputStream, Map.class); - Map<String, Set<String>> result = new HashMap<>(); - collectMapInfo("", map, result); - return result; - } - - private static void collectMapInfo(String path, Map<String, Object> map, Map<String, Set<String>> result) { - for (Map.Entry<String, Object> entry : map.entrySet()) { - String currPath = path + separator + entry.getKey(); - if (entry.getValue() instanceof List){ - List value = (List) entry.getValue(); - String[] statusInfo_list = new String[]{"visiable", "modified", "enabled"}; - //for (String status : MdaDriver.statusInfo_list) { - for (String status : statusInfo_list) { - if(value.contains(status)){ - if(!result.containsKey(status)){ - result.put(status, new HashSet<>()); - } - result.get(status).add(formatPath(currPath)); - } - } - }else{ - collectMapInfo(currPath, (Map)entry.getValue(), result); - } - } - } - - public static String formatPath(String path){ - if (path.isEmpty()){ - return path; - } - if (separator.equals(path.charAt(0)+"")){ - return path.substring(1); - } - return path; - } - -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/FieldInfo.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/FieldInfo.java deleted file mode 100644 index 6cd5bbe..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/FieldInfo.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver.compile.component; - -import lombok.Data; - -@Data -public class FieldInfo { - private String name; - private int type; // 0 基本类型 1 模型 2 模型List 3 引用模型 4引用字段 - private String typeName; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/ModuleRuleContext.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/ModuleRuleContext.java deleted file mode 100644 index 7c7e6fe..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/ModuleRuleContext.java +++ /dev/null @@ -1,126 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver.compile.component; - -import lombok.Data; - -import java.lang.reflect.Method; -import java.util.*; -import java.util.stream.Collectors; - -@Data -public class ModuleRuleContext { - //RULE编译的层次 - public static int RULE_COMPILE_DEPTH=1; - private Map<String, List<RuleItem>> checkRule = new LinkedHashMap<>(); - private Map<String, List<RuleItem>> eventRule = new LinkedHashMap<>(); - private Map<String, List<RuleItem>> defaultRule = new LinkedHashMap<>(); - private List<RuleItem> initList = new ArrayList<>(); - private List<String> moduleList = new ArrayList<>(); - private Map<String,Method> globalMethod = new HashMap<>(); - private Map<String,RuleItem> staticMethod = new HashMap<>(); - - private String moduleName; - private boolean useEmitter; - private boolean isTrans; - - private ModuleRuleContext mergedContext; - - public ModuleRuleContext(String moduleName){ - this.moduleName = moduleName; - this.useEmitter = false; - } - public ModuleRuleContext(String moduleName,boolean useEmitter){ - this.moduleName = moduleName; - this.useEmitter = useEmitter; - } - - public void mergeChild(String nodePath,ModuleRuleContext nodeContext){ - nodeContext.moduleList.forEach(item->this.moduleList.add(nodePath+"."+item)); - nodeContext.initList.forEach(item->{ - RuleItem newItem = item.clone(); - String belongPath = nodePath+"."+newItem.getDotPath(); - //newItem.getBelongClass().push(this.moduleName); - newItem.initGetPath(belongPath); - this.initList.add(newItem); - }); - mergeRuleMap(nodePath,this.checkRule,nodeContext.checkRule); - mergeRuleMap(nodePath,this.defaultRule,nodeContext.defaultRule); - mergeRuleMap(nodePath,this.eventRule,nodeContext.eventRule); - nodeContext.staticMethod.forEach((key,ruleItem)->{ - RuleItem newItem = ruleItem.clone(); - String belongPath = nodePath+"."+newItem.getDotPath(); - newItem.initGetPath(belongPath); - this.staticMethod.put(key,newItem); - }); - this.globalMethod.putAll(nodeContext.globalMethod); - } - - private void mergeRuleMap(String nodePath,Map<String, List<RuleItem>> dest,Map<String, List<RuleItem>> src){ - src.entrySet().forEach(entry->{ - String key = entry.getKey(); - if(!entry.getValue().isEmpty()){ - RuleItem ruleItem = entry.getValue().get(0); - if(ruleItem.getRuleType().equals("CHECK") && key.endsWith("sdamod.dadsnd")){ - return; - } - } - //顶层交易模块,自动识别去除开始的. -// if(key.charAt(0) == '.' && useEmitter){ -// key = key.substring(1); -// } - if(key.charAt(0) != '.') { - //合并rule路径 - key = nodePath + "." + key; - } - List<RuleItem> ruleItemList = dest.get(key); - if(ruleItemList == null){ - ruleItemList = new ArrayList<>(); - dest.put(key,ruleItemList); - } - List<RuleItem> finalRuleItemList = ruleItemList; - String entirePath = key; - entry.getValue().forEach(item->{ - RuleItem newItem = item.clone(); - String belongPath = nodePath+"."+newItem.getDotPath(); - newItem.initGetPath(belongPath); - newItem.setEntirePath(entirePath); - //newItem.getBelongClass().push(this.moduleName); - finalRuleItemList.add(newItem); - }); - }); - } - - public void sortRule(){ - this.checkRule.values().stream().forEach(list->list.sort(new RuleItem.RuleItemComparator())); - this.eventRule.values().stream().forEach(list->list.sort(new RuleItem.RuleItemComparator())); - this.defaultRule.values().stream().forEach(list->list.sort(new RuleItem.RuleItemComparator())); - List<RuleItem> nInitRule = new ArrayList<>(); - //EnterTransaction - List<RuleItem> tempList = initList.stream().filter(a->a.getOrder()>9000000).sorted(Comparator.comparingInt(RuleItem::getOrder)).collect(Collectors.toList()); - //InitTransaction - List<RuleItem> tempList2 = initList.stream().filter(a->a.getOrder()<9000000 && a.getOrder()>=900000).sorted(Comparator.comparingInt(RuleItem::getOrder)).collect(Collectors.toList()); - //ModuleTransaction - List<RuleItem> tempList3 = initList.stream().filter(a->a.getOrder()<900000).collect(Collectors.toList()); - nInitRule.addAll(tempList); - nInitRule.addAll(tempList3); - nInitRule.addAll(tempList2); - initList = nInitRule; - } - public boolean isRuleEmpty(){ - return checkRule.size() ==0 - && defaultRule.size() == 0 - && eventRule.size() == 0 - && initList.size() == 0; - } - public void putGlobalMethod(Method method){ - String key = getMethodKey(method); - globalMethod.put(key,method); - } - public static String getMethodKey(Method method){ - StringBuilder key = new StringBuilder(method.getName()); - for(Class clazz : method.getParameterTypes()){ - key.append(",").append(clazz.getCanonicalName()); - } - key.append(",").append(method.getReturnType().getCanonicalName()); - return key.toString(); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/RuleItem.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/RuleItem.java deleted file mode 100644 index 274e5b3..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/driver/compile/component/RuleItem.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.brilliance.mda.runtime.mda.driver.compile.component; - -import com.brilliance.mda.runtime.mda.Ruleable; -import com.fasterxml.jackson.annotation.JsonIgnore; -import lombok.Data; - -import java.lang.reflect.Method; -import java.util.Comparator; - -@Data -public class RuleItem { - public static final String INIT = "INIT"; - public static final String RULE = "RULE"; - public static final String CHECK = "CHECK"; - public static final String DEFAULT = "DEFAULT"; - public static final String STATIC = "STATIC"; - public static final String LOCAL = "LOCAL"; - public static final String GLOBAL = "GLOBAL"; - - public static final String LIST = "LIST"; - -// private String methodName; - //String or Method - @JsonIgnore - private Object method; - private int order; - @JsonIgnore - private String getPath; - private String dotPath; - @JsonIgnore - private String entirePath; - @JsonIgnore - private int depth; - @JsonIgnore - private String ruleType; - @JsonIgnore - private String module; - @JsonIgnore - private String transName; - @JsonIgnore - private Ruleable<Boolean> ruleableIns; - //private Stack<String> belongClass = new Stack<>(); - - public void initGetPath(String dotPath) - { - - if(dotPath.endsWith(".")){ - dotPath = dotPath.substring(0,dotPath.length()-1); - } - - this.dotPath = dotPath; - if(dotPath.length() == 0) - { - this.getPath = ""; - this.depth = 0; - return ; - } - String[] pathArr = dotPath.split("\\."); - this.depth = pathArr.length; -// StringBuilder sb = new StringBuilder(); -// for(String item:pathArr) -// { -// sb.append(".get"); -// sb.append(firstUpper(item)); -// sb.append("()"); -// } -// getPath = sb.toString(); - } - private String firstUpper(String s){ - if(s.length() == 1) - return s.toUpperCase(); - return s.substring(0,1).toUpperCase()+s.substring(1); - } - public static class RuleItemComparator implements Comparator<RuleItem> { - @Override - public int compare(RuleItem o1, RuleItem o2) { - if(o1.getOrder() > o2.getOrder()) - return 1; - else if(o1.getOrder() < o2.getOrder()) - return -1; - //TD的Rule执行顺序,由上到下,由里到外 - if(o1.getDepth() > o2.getDepth()) - return -1; - else if(o1.getDepth() < o2.getDepth()) - return 1; - return 0; - } - } - - public String getTransName() { - return transName; - } - - public void setTransName(String transName) { - this.transName = transName; - } - - public RuleItem clone(){ - RuleItem clone = new RuleItem(); -// clone.methodName = this.methodName; - clone.order = this.order; - clone.getPath = this.getPath; - clone.dotPath = this.dotPath; - clone.entirePath = this.entirePath; - clone.depth = this.depth; - clone.ruleType = this.ruleType; - clone.module = this.module; - clone.transName = this.transName; - clone.method = this.method; -// Stack<String> belongClassStack = new Stack<>(); -// belongClassStack.addAll(this.belongClass); -// clone.belongClass = belongClassStack; - return clone; - } - public String getMethodName(){ - if(method instanceof Method) - return ((Method)method).getName(); - return (String)method; - } -} \ No newline at end of file diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/impl/Argument.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/impl/Argument.java deleted file mode 100644 index 17a91d4..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/impl/Argument.java +++ /dev/null @@ -1,184 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.mda.IResult; -import com.brilliance.mda.runtime.mda.OpType; - -public class Argument<E> implements IResult { - public String fieldName; - public OpType opType; - public E value; - public Object attachField; - - public Argument() { - - } - - public Argument(String fieldName) { - this.fieldName = fieldName; - } - - public Argument(String fieldName, OpType opType, E value) { - this.fieldName = fieldName; - this.opType = opType; - this.value = value; - } - - public Argument(String fieldName, OpType opType) { - this.fieldName = fieldName; - this.opType = opType; - this.value = null; - } - - public Argument(String fieldName, E value) { - this(fieldName, OpType.EQ, value); - } - - public Argument(OpType opType, E value) { - this(null, opType, value); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Argument or(Argument arg1, Argument arg2) { - return new Argument(OpType.OR, new Argument[]{arg1, arg2}); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Argument and(Argument arg1, Argument arg2) { - return new Argument(OpType.AND, new Argument[]{arg1, arg2}); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Argument not(Argument argument) { - return new Argument(OpType.NOT, argument); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Argument in(String column, Object[] values) { - return new Argument(column, OpType.IN, values); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Argument between(String column, Object value1, Object value2) { - return new Argument(column, OpType.BETWEEN, new Object[]{value1, value2}); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Argument eq(String column, Object value) { - return new Argument(column, value); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Argument gt(String column, Object value) { - return new Argument(column, OpType.GT, value); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Argument ge(String column, Object value) { - return new Argument(column, OpType.GE, value); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Argument lt(String column, Object value) { - return new Argument(column, OpType.LT, value); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Argument le(String column, Object value) { - return new Argument(column, OpType.LE, value); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Argument isNotNull(String column) { - return new Argument(column, OpType.ISNOTNULL); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Argument isNull(String column) { - return new Argument(column, OpType.ISNULL); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Argument like(String column, Object value) { - return new Argument(column, OpType.LIKE, value); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Argument notLike(String column, Object value) { - return new Argument(column, OpType.NOTLIKE, value); - } - - @SuppressWarnings({"rawtypes"}) - public Argument and(Argument argument) { - return this.opType == null ? argument : and(this, argument); - } - - @SuppressWarnings({"rawtypes"}) - public Argument and(String fieldName, Object value) { - return and(fieldName, OpType.EQ, value); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public Argument and(String fieldName, OpType opType) { - return and(new Argument(fieldName, opType)); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public Argument and(String fieldName, OpType opType, Object value) { - return and(new Argument(fieldName, opType, value)); - } - - @SuppressWarnings({"rawtypes"}) - public Argument or(Argument argument) { - return this.opType == null ? argument : or(this, argument); - } - - @SuppressWarnings({"rawtypes"}) - public Argument or(String fieldName, Object value) { - return or(fieldName, OpType.EQ, value); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public Argument or(String fieldName, OpType opType) { - return or(new Argument(fieldName, opType)); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - public Argument or(String fieldName, OpType opType, Object value) { - return or(new Argument(fieldName, opType, value)); - } - - - @Override - public Object setValue(Object value) { - this.value = (E) value; - return value; - } - - @Override - public E getValue() { - return value; - } - - @Override - public Class getDataType() { - return this.getClass(); - } - - public String getFieldName() { - return this.fieldName; - } - - @Override - public String getName() { - return this.fieldName; - } - - @Override - public int compareTo(Object o) { - return 0; - } - - public static <T> Argument<T> box(T value){ - return new Argument<T>("",value); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/impl/DataGrid.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/impl/DataGrid.java deleted file mode 100644 index 4381d2f..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/impl/DataGrid.java +++ /dev/null @@ -1,183 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.mda.IDataGrid; -import com.fasterxml.jackson.annotation.JsonIgnore; - -import java.io.*; -import java.util.*; - -public class DataGrid implements IDataGrid, Serializable { - - protected List<String> rows = new ArrayList<>(); - protected List<String> initRows = new ArrayList<>(); - protected Map<String,Object> attrs = new HashMap<>(); - - private boolean keepsort; - - @Override - public void insertLine(int idx, String line) { - if (idx <= 0 || idx > rows.size()) { - rows.add(line); - return; - } - if(line != null) - rows.add(--idx,line); - } - - @JsonIgnore - public String getLine(int idx) { - if(idx == 0) idx =1; - idx--; - if(idx >= rows.size()) - return ""; - return rows.get(idx); - } - - @JsonIgnore - @Override - public String deleteLine(int idx) { - if(idx == 0) idx =1; - return rows.remove(--idx); - } - - @Override - public void sortLines() { - Collections.sort(rows); - } - - @Override - public int countLines() { - return rows.size(); - } - @JsonIgnore - @Override - public int searchLine(String line) { - if(line ==null) return 0; - for (int i = 0; i <rows.size() ; i++) { - if(rows.get(i) == null) continue; - - if(!keepsort && rows.get(i).toLowerCase().startsWith(line.toLowerCase())){ - return i+1; - } - if(keepsort && rows.get(i).startsWith(line)){ - return i+1; - } - } - return 0; - } - - @Override - public void setRows(List<String> list) { - this.rows.clear(); - rows.addAll(list); - } - - @Override - public List<String> getRows() { - return rows; - } - - @Override - public void clearLines() { - this.rows.clear(); - } - - @Override - public void addLine(String line) { - if(line != null) - this.rows.add(line); - } - - @JsonIgnore - public void setLine(int idx, String line) { - if(idx == 0) idx =1; - if(line == null){ - return; - } - //String[] lines = line.split("[\\r\\n]{1,2}"); - String[] lines = new String[]{line}; - //计算替换区间 - int endIdx = idx +lines.length; - for(int n=this.rows.size()+1;n<endIdx;n++){ - this.rows.add(""); - } - - for(int n=idx;n<endIdx;n++){ - this.rows.set(n-1,lines[n-idx]); - } - } - - @JsonIgnore - public void loadLines(File file)throws IOException { - BufferedReader br = null; - rows.clear(); - try{ - br = new BufferedReader(new FileReader(file)); - String str = null; - while((str = br.readLine())!=null){ - rows.add(str); - } - }catch (IOException e){ - rows.clear(); - throw e; - }finally { - if(br != null){ - br.close(); - } - } - } - - @JsonIgnore - public void saveLines(File file)throws IOException{ - BufferedWriter br = null; - try{ - if(!file.exists()){ - file.createNewFile(); - } - br = new BufferedWriter(new FileWriter(file)); - for (String s : rows) { - br.write(s); - br.newLine(); - } - }catch (Exception e){ - rows.clear(); - throw new RuntimeException(e); - } - finally { - if(br != null){ - br.close(); - } - } - } - - @JsonIgnore - public boolean isLinesChanged(){ - if(rows.size() != initRows.size()) - return true; - for (int i = 0; i < initRows.size(); i++) { - if(!initRows.get(i).equals(rows.get(i))){ - return true; - } - } - return false; - } - - @JsonIgnore - public <T> void setAttribute(String attr,T stream){ - this.attrs.put(attr,stream); - } - - @JsonIgnore - public <T> T getAttribute(String attr){ - return (T)this.attrs.get(attr); - } - - public boolean isKeepsort() { - return keepsort; - } - - public void setKeepsort(boolean keepsort) { - this.keepsort = keepsort; - } - -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/impl/EnvConfig.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/impl/EnvConfig.java deleted file mode 100644 index f155d60..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/impl/EnvConfig.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.mda.config.IniConfig; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; - -import javax.annotation.PostConstruct; -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -/** - * 放置环境参数 - */ -@Configuration -public class EnvConfig { - - private static Logger logger = LoggerFactory.getLogger(EnvConfig.class); - private static Map<String,Object> config = new HashMap<>(); - - @Value("${envConfig.rootPath}") - private String rootPath; - - public String getRootPath() { - return rootPath; - } - - public void setRootPath(String rootPath) { - this.rootPath = rootPath; - } - - @PostConstruct - public void init(){ - File dir = new File(rootPath); - if(!dir.exists()){ - dir.mkdirs(); - }else { - recursionFile(dir); - } - config.put("rootPath",rootPath); - - } - - public void recursionFile(File file){ - if(file.isFile()){ - parse(file); - return; - } - for (File f: file.listFiles()) { - recursionFile(f); - } - } - - public void parse(File file){ - String lowerFileName = file.getName().toLowerCase(); - if(lowerFileName.endsWith(".ini") || lowerFileName.endsWith(".dof")){ - IniConfig.loadIni(file); - } - } - - -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/impl/FieldConstantHolder.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/impl/FieldConstantHolder.java deleted file mode 100644 index 2310535..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/impl/FieldConstantHolder.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.mda.FieldHolder; - -public class FieldConstantHolder<T> implements FieldHolder<T> { - private T constantValue; - public FieldConstantHolder(T constantValue){ - this.constantValue = constantValue; - } - - public FieldConstantHolder(){ - this(null); - } - - public void setValue(T o) { - this.constantValue = o; - } - - - public T getValue() { - return this.constantValue; - } - - @Override - public String getPath() { - return null; - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/impl/StreamImpl.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/impl/StreamImpl.java deleted file mode 100644 index 80f76f6..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/impl/StreamImpl.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.brilliance.mda.runtime.mda.impl; - -import com.brilliance.mda.runtime.mda.IStream; -import com.fasterxml.jackson.annotation.JsonIgnore; - -import java.io.*; -import java.util.Arrays; - -public class StreamImpl extends DataGrid implements IStream,Serializable { - - transient ByteArrayOutputStream bos = new ByteArrayOutputStream(); - private String name; - private String type; - private String value; - - - @JsonIgnore - public InputStream getInputStream() - { - return new ByteArrayInputStream(this.bos.toByteArray()); - } - - @JsonIgnore - public OutputStream getOutputStream() - { - return this.bos; - } - public boolean isEmpty() - { - for (String row : getRows()) { - if (!row.trim().isEmpty()){ - return false; - } - } - return true; - } - - @JsonIgnore - public String getValue() - { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < rows.size(); i++) { - sb.append(rows.get(i)); - if(i<rows.size() - 1) - sb.append("\r\n"); - } - return sb.toString(); - } - - @JsonIgnore - public Class getDataType() - { - return String.class; - } - - @JsonIgnore - public String getName() - { - return this.name; - } - - @JsonIgnore - public void setName(String name) - { - this.name = name; - } - @JsonIgnore - public String getType() - { - return this.type; - } - @JsonIgnore - public void setType(String type) - { - this.type = type; - } - - public long size() - { - return this.bos.size(); - } - - public void close() - { - this.bos.reset(); - this.clearLines(); - } - - public String setValue(String value) - { - this.value = value; - if(value != null && value.length() > 0){ - Arrays.stream(value.split("\r\n")).forEach(rows::add); - } - return value; - } - - public String toString(){ - return this.getValue(); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/util/ApplicationContextHolder.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/util/ApplicationContextHolder.java deleted file mode 100644 index a7a95da..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/mda/util/ApplicationContextHolder.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.brilliance.mda.runtime.mda.util; - - -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.stereotype.Component; - -import java.util.Optional; - -@Component -public class ApplicationContextHolder implements ApplicationContextAware { - - private static ApplicationContext context; - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - context = applicationContext; - } - - - public static <T> Optional<T> getBean(Class<T> type){ - if(context == null){ - return Optional.empty(); - } - return Optional.of(context.getBean(type)); - } - - public static <T> Optional<T> getBean(String name,Class<T> type){ - if(context == null){ - return Optional.empty(); - } - return Optional.of(context.getBean(name,type)); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/request/BaseVO.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/request/BaseVO.java deleted file mode 100644 index 13f376a..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/request/BaseVO.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.brilliance.mda.runtime.request; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class BaseVO { - - protected Map<String,Object> params = new HashMap<>(); - protected List changes; - protected String pageId; - - /**新增,用于记录码表,使快照上的码值能正确显示**/ - protected Map<String, List<String>> valuesSet; - - - public Map<String, Object> getParams() { - return params; - } - public void setParams(Map<String, Object> params) { - this.params = params; - } - public List getChanges() { - return changes; - } - public void setChanges(List changes) { - this.changes = changes; - } - protected Map<String, Map<String, Object>> statusInfo = new HashMap<>(); - - public String getPageId() { - return pageId; - } - - public void setPageId(String pageId) { - this.pageId = pageId; - } - - public Map<String, Map<String, Object>> getStatusInfo() { - return statusInfo; - } - - public Map<String, List<String>> getValuesSet() { - return valuesSet; - } - - public void setValuesSet(Map<String, List<String>> valuesSet) { - this.valuesSet = valuesSet; - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/request/RequestSet.java b/gjjs-mda/src/main/java/com/brilliance/mda/runtime/request/RequestSet.java deleted file mode 100644 index a003e9f..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/runtime/request/RequestSet.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.brilliance.mda.runtime.request; - -public class RequestSet<T> { - - private T data; - private String changes; - - public Object getData(){ - return this.data; - } - - public void setData(T data) { - this.data = data; - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/support/cache/ICache.java b/gjjs-mda/src/main/java/com/brilliance/mda/support/cache/ICache.java deleted file mode 100644 index f89d5fa..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/support/cache/ICache.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.brilliance.mda.support.cache; - -public interface ICache<K, V> { - K store(V v); - default void store(String key,V v){ - - } - V get(K k); - void remove(K k); - String generateKey(); - - default void keeplive(K key){ - get(key); - } - - default void cleanup(){ - - }; - - default boolean contains(K key){ - return false; - }; - - String CTX_CACHE="ctxCache"; - - String AUTH_CACHE="authCache"; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/support/cache/serializer/ICacheSerializer.java b/gjjs-mda/src/main/java/com/brilliance/mda/support/cache/serializer/ICacheSerializer.java deleted file mode 100644 index 1e67182..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/support/cache/serializer/ICacheSerializer.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.brilliance.mda.support.cache.serializer; - -public interface ICacheSerializer { - - String getName(); - - <T> byte[] writeToByteArray(T obj); - - <T> T readFromByteArray(byte[] bytes); -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/support/jakson/serialize/BigDecimalSerializeRate.java b/gjjs-mda/src/main/java/com/brilliance/mda/support/jakson/serialize/BigDecimalSerializeRate.java deleted file mode 100644 index a7ec15d..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/support/jakson/serialize/BigDecimalSerializeRate.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.brilliance.mda.support.jakson.serialize; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.BeanProperty; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.ser.ContextualSerializer; - -import java.io.IOException; -import java.math.BigDecimal; - -public class BigDecimalSerializeRate extends JsonSerializer<BigDecimal> implements ContextualSerializer { - public BigDecimalSerializeRate(){ - - } - private int decimal; - public BigDecimalSerializeRate(int decimal){ - this.decimal = decimal; - } - - @Override - public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializers) throws IOException { - if(null != value ) { - gen.writeString(value.setScale(decimal, BigDecimal.ROUND_HALF_UP).toPlainString()); - }else { - gen.writeString(""); - } - } - - @Override - public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) - throws JsonMappingException { - int decimal = 0; - DecimalLength ann=null; - - if (property !=null) { - ann = property.getAnnotation(DecimalLength.class); - } - - if (ann != null) { - decimal = ann.value(); - } - return new BigDecimalSerializeRate(decimal); - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/support/jakson/serialize/DateDeSerialized.java b/gjjs-mda/src/main/java/com/brilliance/mda/support/jakson/serialize/DateDeSerialized.java deleted file mode 100644 index 6411e20..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/support/jakson/serialize/DateDeSerialized.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.brilliance.mda.support.jakson.serialize; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; - -import java.io.IOException; - -public class DateDeSerialized extends JsonDeserializer { - - @Override - public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { - - String source = p.getText().trim(); - - return source.equals("NULL") || source.equals("null") ? null : source; - } - -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/support/jakson/serialize/DecimalLength.java b/gjjs-mda/src/main/java/com/brilliance/mda/support/jakson/serialize/DecimalLength.java deleted file mode 100644 index b105461..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/support/jakson/serialize/DecimalLength.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.brilliance.mda.support.jakson.serialize; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Inherited -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface DecimalLength { - public int value() default 0; -} - diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/support/jakson/serialize/IStreamDeSerialized.java b/gjjs-mda/src/main/java/com/brilliance/mda/support/jakson/serialize/IStreamDeSerialized.java deleted file mode 100644 index bfe995c..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/support/jakson/serialize/IStreamDeSerialized.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.brilliance.mda.support.jakson.serialize; - -import com.brilliance.mda.runtime.mda.IStream; -import com.brilliance.mda.runtime.mda.impl.StreamImpl; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.ObjectCodec; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.deser.std.StdDeserializer; - -import java.io.IOException; -import java.util.List; - -public class IStreamDeSerialized extends StdDeserializer<IStream> { - public IStreamDeSerialized() { - this(null); - } - protected IStreamDeSerialized(Class<?> vc) { - super(vc); - } - - @Override - public IStream deserialize(JsonParser jp, DeserializationContext ctxt) - throws IOException, JsonProcessingException { - ObjectCodec codec = jp.getCodec(); - JsonNode node = codec.readTree(jp); - //IStream目前统一用StreamImpl构造,后续新增类型时,再逐步补充 - StreamImpl stream = new StreamImpl(); - if(node.has("rows")) - { - JsonNode s = node.get("rows"); - List<String> tempRows = codec.treeToValue(s,List.class); - stream.getRows().addAll(tempRows); - } - return stream; - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/support/td/AreaType.java b/gjjs-mda/src/main/java/com/brilliance/mda/support/td/AreaType.java deleted file mode 100644 index c47fffa..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/support/td/AreaType.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.brilliance.mda.support.td; - -public enum AreaType { - HEAD("header"), - BODY("body"), - FOOTER("fotter"); - private String value; - private AreaType(String val){ - this.value = val; - } -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/support/td/TDFieldInfo.java b/gjjs-mda/src/main/java/com/brilliance/mda/support/td/TDFieldInfo.java deleted file mode 100644 index 7f01b4f..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/support/td/TDFieldInfo.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.brilliance.mda.support.td; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class TDFieldInfo { - - private String fieldName; - - private Class<?> fieldType; - - private Field field; - - private Method getter; - - private Method setter; -} diff --git a/gjjs-mda/src/main/java/com/brilliance/mda/support/td/TDModuleInfo.java b/gjjs-mda/src/main/java/com/brilliance/mda/support/td/TDModuleInfo.java deleted file mode 100644 index 1ebdc14..0000000 --- a/gjjs-mda/src/main/java/com/brilliance/mda/support/td/TDModuleInfo.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.brilliance.mda.support.td; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.lang.reflect.Method; -import java.util.List; -import java.util.Map; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class TDModuleInfo { - - private String moduleName; - - private Class<?> moduleClass; - - private Map<String, List<Method>> tdMethods; - - private Map<String, List<Method>> allPublicMethods; - - private Map<String, Method> allPublicLowerCaseMethods; - - private Map<String, TDFieldInfo> tdModules; - - private Map<String, TDFieldInfo> tdModuleLists; - - private Map<String, TDFieldInfo> tdPrimitiveFields; - - private Map<String, TDFieldInfo> tdStreamFields; - - private Map<String, TDFieldInfo> tdPanelFields; - - private Map<String, TDFieldInfo> tdModuleHolderFields; - - private Map<String, TDFieldInfo> tdFieldHolderFields; -} diff --git a/gjjs-mda/src/main/resources/META-INF/moduleClassName.properties b/gjjs-mda/src/main/resources/META-INF/moduleClassName.properties deleted file mode 100644 index cd2e845..0000000 --- a/gjjs-mda/src/main/resources/META-INF/moduleClassName.properties +++ /dev/null @@ -1,6 +0,0 @@ -IModuleList=com.brilliance.mda.runtime.mda.IModuleList -IPanel=com.brilliance.mda.runtime.mda.IPanel -IStream=com.brilliance.mda.runtime.mda.IStream -ModuleList=com.brilliance.mda.runtime.mda.impl.ModuleList -PanelImpl=com.brilliance.mda.runtime.mda.impl.PanelImpl -StreamImpl=com.brilliance.mda.runtime.mda.impl.StreamImpl \ No newline at end of file diff --git a/gjjs-mda/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/gjjs-mda/src/main/resources/META-INF/services/javax.annotation.processing.Processor deleted file mode 100644 index fc021f9..0000000 --- a/gjjs-mda/src/main/resources/META-INF/services/javax.annotation.processing.Processor +++ /dev/null @@ -1 +0,0 @@ -com.brilliance.annotation.processor.ModuleProcessor \ No newline at end of file diff --git a/pom.xml b/pom.xml index f14df99..b34624e 100644 --- a/pom.xml +++ b/pom.xml @@ -9,10 +9,8 @@ <version>2.2.10.RELEASE</version> </parent> <modules> - <module>gjjs-mda</module> <module>gjjs-bd-business</module> <module>gjjs-bd-mybatis-support</module> - <module>gjjs-bd-runtime</module> </modules> <groupId>com.brilliance</groupId> @@ -250,4 +248,16 @@ </plugin> </plugins> </build> + + + <repositories> + <repository> + <id>brilliance-virtual</id> + <name>brilliance-virtual</name> + <url>http://114.115.138.98:9620/artifactory/brilliance-virtual/</url> + <releases> + <enabled>true</enabled> + </releases> + </repository> + </repositories> </project>