pipIrr-platform/pipIrr-common/pom.xml
@@ -148,6 +148,13 @@ <artifactId>jna-platform</artifactId> <version>5.12.1</version> </dependency> <!-- ç±»åå° --> <dependency> <groupId>org.reflections</groupId> <artifactId>reflections</artifactId> <version>0.10.2</version> </dependency> <!-- Hutoolæ¯ä¸ä¸ªå°èå ¨çJavaå·¥å ·ç±»åº(https://github.com/dromara/hutool) --> <dependency> pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/AnnotationScan.java
@@ -1,13 +1,13 @@ package com.dy.common.mw.protocol; import java.net.URI; import java.net.URL; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Set; import com.dy.common.util.ClassScan; import com.dy.common.util.NumUtil; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.reflections.Reflections; /** * æ«æï¼ @@ -19,14 +19,16 @@ */ @SuppressWarnings("unused") public class AnnotationScan { private static String scanRootPackage = "com.dy.common.mw.protocol." ; private static final Logger log = LogManager.getLogger(AnnotationScan.class); private static String scanRootPackage = "com.dy.common.mw.protocol" ; private static AnnotationScan instance ; private AnnotationScan(){ } /** * å¾å°å¯ä¸å®ä¾ï¼ * å¹¶å¨çæå¯ä¸å®ä¾æ¶ï¼æ«ææ³¨è§£ç±» @@ -40,148 +42,135 @@ } return instance ; } /** * æ«æåºæ³¨è§£çç±» * @throws ClassNotFoundException å¼å¸¸ * @throws Exception å¼å¸¸ */ private void scanEndpointAnnotations() throws Exception{ ClassLoader load = this.getClass().getClassLoader() ; if(!scanRootPackage.endsWith(".")){ scanRootPackage += "." ; } URL url = AnnotationScan.class.getResource("/" + scanRootPackage.replace('.', '/')); if(url != null){ String urlStr = url.toString() ; if(urlStr != null){ URI uri = new URI(url.toString()); private void scanEndpointAnnotations() throws Exception { Reflections reflections = new Reflections(scanRootPackage); // æå®å å Set<Class<?>> driverClasses = reflections.getTypesAnnotatedWith(AnnotationDriver.class); if (driverClasses != null && driverClasses.size() > 0) { String protocolName; int priority; int onLineDataMinLength; int headMinLength; List<String> classNames = new ClassScan().searchClassFromUrl(new URI[]{uri}, scanRootPackage) ; if(classNames != null && classNames.size() > 0){ String protocolName ; int priority; int onLineDataMinLength; int headMinLength ; HashMap<String, AnnotationDriverVo> driverMap = ProtocolCache.getDriverMap(); HashMap<String, AnnotationPrefixedDataAvailableVo> prefixedDataAvailableMap = ProtocolCache.getPrefixedDataAvailableMap(); HashMap<String, AnnotationOnLineVo> onLineMap = ProtocolCache.getOnLineMap(); HashMap<String, AnnotationDriverVo> driverMap = ProtocolCache.getDriverMap() ; HashMap<String, AnnotationPrefixedDataAvailableVo> prefixedDataAvailableMap = ProtocolCache.getPrefixedDataAvailableMap() ; HashMap<String, AnnotationOnLineVo> onLineMap = ProtocolCache.getOnLineMap() ; for(String cName : classNames){ String className = cName.substring(0, cName.lastIndexOf('.')) ; Class<?> clazz = load.loadClass(className) ; if(clazz.isAnnotationPresent(AnnotationDriver.class)){ AnnotationDriver ann = clazz.getAnnotation(AnnotationDriver.class) ; if(ann != null){ if(ann.enable()){ protocolName = ann.name() ; if(!(protocolName.trim().equals(""))){ if(driverMap.containsKey(protocolName)){ throw new Exception("严éé误ï¼å议驱å¨åç§°" + protocolName + "åºç°äºé夿³¨è§£ï¼") ; } driverMap.put(protocolName, new AnnotationDriverVo(clazz)) ; }else{ throw new Exception("严éé误ï¼å议驱å¨å称注解å¼ä¸ºç©ºå符串") ; } } for (Class<?> clazz : driverClasses) { AnnotationDriver ann = clazz.getAnnotation(AnnotationDriver.class); if (ann != null) { if (ann.enable()) { protocolName = ann.name(); if (!(protocolName.trim().equals(""))) { if (driverMap.containsKey(protocolName)) { throw new Exception("严éé误ï¼å议驱å¨(åç§°)" + protocolName + "åºç°äºé夿³¨è§£ï¼"); } driverMap.put(protocolName, new AnnotationDriverVo(clazz)); } else { throw new Exception("严éé误ï¼å议驱å¨å称注解å¼ä¸ºç©ºå符串"); } } } } Set<Class<?>> prefixedClass = reflections.getTypesAnnotatedWith(AnnotationPrefixedDataAvailable.class); for (Class<?> clazz : prefixedClass) { AnnotationPrefixedDataAvailable ann = clazz.getAnnotation(AnnotationPrefixedDataAvailable.class); if (ann != null) { if (ann.enable()) { protocolName = ann.protocolName(); if (!(protocolName.trim().equals(""))) { if (prefixedDataAvailableMap.containsKey(protocolName)) { throw new Exception("严ééè¯¯ï¼ ä¸è¡æ°æ®å®æ´æ§æ£æ¥æé å议驱å¨" + protocolName + "åºç°äºé夿³¨è§£ï¼"); } } else { throw new Exception("严éé误ï¼ä¸è¡æ°æ®å®æ´æ§æ£æ¥æé åè®®é©±å¨æ³¨è§£å¼ä¸ºç©ºå符串"); } priority = ann.priority(); if (priority == 0) { throw new Exception("严ééè¯¯ï¼ ä¸è¡æ°æ®å®æ´æ§æ£æ¥æé ä¼å 级注解ä¸è½ä¸º0"); } if (isRepeatPrefixedDataAvailablePriority(priority, prefixedDataAvailableMap)) { throw new Exception("严ééè¯¯ï¼ ä¸è¡æ°æ®å®æ´æ§æ£æ¥æé ä¼å 级注解(priority)æ°å¼" + priority + "éå¤"); } if(clazz.isAnnotationPresent(AnnotationPrefixedDataAvailable.class)){ AnnotationPrefixedDataAvailable ann = clazz.getAnnotation(AnnotationPrefixedDataAvailable.class) ; if(ann != null){ if(ann.enable()){ protocolName = ann.protocolName() ; if(!(protocolName.trim().equals(""))){ if(prefixedDataAvailableMap.containsKey(protocolName)){ throw new Exception("严ééè¯¯ï¼ ä¸è¡æ°æ®å®æ´æ§æ£æ¥æé å议驱å¨" + protocolName + "åºç°äºé夿³¨è§£ï¼") ; } }else{ throw new Exception("严éé误ï¼ä¸è¡æ°æ®å®æ´æ§æ£æ¥æé åè®®é©±å¨æ³¨è§£å¼ä¸ºç©ºå符串") ; } priority = ann.priority() ; if(priority == 0){ throw new Exception("严ééè¯¯ï¼ ä¸è¡æ°æ®å®æ´æ§æ£æ¥æé ä¼å 级注解ä¸è½ä¸º0") ; } if(isRepeatPrefixedDataAvailablePriority(priority, prefixedDataAvailableMap)){ throw new Exception("严ééè¯¯ï¼ ä¸è¡æ°æ®å®æ´æ§æ£æ¥æé ä¼å 级注解(priority)æ°å¼" + priority + "éå¤") ; } onLineDataMinLength = ann.onLineDataMinLength() ; onLineDataMinLength = ann.onLineDataMinLength(); /*æ°è±¡å议为0 if(onLineDataMinLength == 0){ throw new Exception("严ééè¯¯ï¼ ä¸è¡æ°æ®å®æ´æ§æ£æ¥æé ä¸çº¿æ°æ®æå°é¿åº¦æ³¨è§£ä¸è½ä¸º0") ; } */ headMinLength = ann.headMinLength() ; headMinLength = ann.headMinLength(); /*æ°è±¡å议为0 if(headMinLength == 0){ throw new Exception("严ééè¯¯ï¼ ä¸è¡æ°æ®å®æ´æ§æ£æ¥æé 䏿¥æ°æ®ç头鍿å°é¿åº¦æ³¨è§£ä¸è½ä¸º0") ; } */ prefixedDataAvailableMap.put(protocolName, new AnnotationPrefixedDataAvailableVo(clazz, protocolName, priority, onLineDataMinLength, headMinLength, ProtocolConstant.errorMaxLength)) ; } } } if(clazz.isAnnotationPresent(AnnotationOnLine.class)){ AnnotationOnLine ann = clazz.getAnnotation(AnnotationOnLine.class) ; if(ann != null){ if(ann.enable()){ protocolName = ann.protocolName() ; if(!(protocolName.trim().equals(""))){ if(onLineMap.containsKey(protocolName)){ throw new Exception("严ééè¯¯ï¼ ä¸çº¿æ°æ®åææé å议驱å¨" + protocolName + "åºç°äºé夿³¨è§£ï¼") ; } }else{ throw new Exception("严éé误ï¼ä¸çº¿æ°æ®åææé åè®®é©±å¨æ³¨è§£å¼ä¸ºç©ºå符串") ; } priority = ann.priority() ; if(priority == 0){ throw new Exception("严ééè¯¯ï¼ ä¸çº¿æ°æ®åææé ä¼å 级注解ä¸è½ä¸º0") ; } if(isRepeatOnLinePriority(priority, onLineMap)){ throw new Exception("严ééè¯¯ï¼ ä¸çº¿æ°æ®åææé ä¼å 级注解(priority)æ°å¼" + priority + "éå¤") ; } onLineMap.put(protocolName, new AnnotationOnLineVo(clazz, protocolName, priority)) ; } } } prefixedDataAvailableMap.put(protocolName, new AnnotationPrefixedDataAvailableVo(clazz, protocolName, priority, onLineDataMinLength, headMinLength, ProtocolConstant.errorMaxLength)); } String error = this.hasErrorInDriver(driverMap) ; if(error != null){ throw new Exception(error) ; }else{ error = this.hasErrorInPrefixedDataAvailable(driverMap, prefixedDataAvailableMap) ; if(error != null){ throw new Exception(error) ; }else{ error = this.hasErrorInOnLine(driverMap, onLineMap) ; if(error != null){ throw new Exception(error) ; } } } }else{ throw new Exception("严ééè¯¯ï¼ æ«æåè®®ç¸å ³æ³¨è§£æå¾å°ç±»åéåä¸ºç©ºï¼æ«ææ ¹è·¯å¾æ¯" + scanRootPackage) ; } } Set<Class<?>> onLineClass = reflections.getTypesAnnotatedWith(AnnotationOnLine.class); for (Class<?> clazz : onLineClass) { AnnotationOnLine ann = clazz.getAnnotation(AnnotationOnLine.class); if (ann != null) { if (ann.enable()) { protocolName = ann.protocolName(); if (!(protocolName.trim().equals(""))) { if (onLineMap.containsKey(protocolName)) { throw new Exception("严ééè¯¯ï¼ ä¸çº¿æ°æ®åææé å议驱å¨" + protocolName + "åºç°äºé夿³¨è§£ï¼"); } } else { throw new Exception("严éé误ï¼ä¸çº¿æ°æ®åææé åè®®é©±å¨æ³¨è§£å¼ä¸ºç©ºå符串"); } priority = ann.priority(); if (priority == 0) { throw new Exception("严ééè¯¯ï¼ ä¸çº¿æ°æ®åææé ä¼å 级注解ä¸è½ä¸º0"); } if (isRepeatOnLinePriority(priority, onLineMap)) { throw new Exception("严ééè¯¯ï¼ ä¸çº¿æ°æ®åææé ä¼å 级注解(priority)æ°å¼" + priority + "éå¤"); } onLineMap.put(protocolName, new AnnotationOnLineVo(clazz, protocolName, priority)); } } } //è¿è¡éªè¯ String error = this.hasErrorInDriver(driverMap); if (error != null) { throw new Exception(error); } else { error = this.hasErrorInPrefixedDataAvailable(driverMap, prefixedDataAvailableMap); if (error != null) { throw new Exception(error); } else { error = this.hasErrorInOnLine(driverMap, onLineMap); if (error != null) { throw new Exception(error); } } } } else { throw new Exception("严ééè¯¯ï¼ æ«æåè®®ç¸å ³æ³¨è§£æå¾å°ç±»åéåä¸ºç©ºï¼æ«ææ ¹è·¯å¾æ¯" + scanRootPackage); } } /** * æ£æ¥ä¼å 级éå¤ * @param priority ä¼å 级 * @return ç»æ */ private boolean isRepeatPrefixedDataAvailablePriority(int priority, HashMap<String, AnnotationPrefixedDataAvailableVo> prefixedDataAvailableMap){ Collection<AnnotationPrefixedDataAvailableVo> col = prefixedDataAvailableMap.values(); Collection<AnnotationPrefixedDataAvailableVo> col = prefixedDataAvailableMap.values(); for(AnnotationPrefixedDataAvailableVo vo : col){ if(vo.priority == priority){ return true ; @@ -195,7 +184,7 @@ * @return ç»æ */ private boolean isRepeatOnLinePriority(int priority, HashMap<String, AnnotationOnLineVo> onLineMap){ Collection<AnnotationOnLineVo> col = onLineMap.values(); Collection<AnnotationOnLineVo> col = onLineMap.values(); for(AnnotationOnLineVo vo : col){ if(vo.priority == priority){ return true ; @@ -203,7 +192,7 @@ } return false ; } private String hasErrorInDriver(HashMap<String, AnnotationDriverVo> driverMap){ if(driverMap.size() == 0){ return "严ééè¯¯ï¼æªæ³¨è§£ä»»ä½å议驱å¨" ; @@ -211,23 +200,23 @@ return null ; } private String hasErrorInPrefixedDataAvailable(HashMap<String, AnnotationDriverVo> driverMap, HashMap<String, AnnotationPrefixedDataAvailableVo> prefixedDataAvailableMap){ Collection<AnnotationPrefixedDataAvailableVo> col = prefixedDataAvailableMap.values(); private String hasErrorInPrefixedDataAvailable(HashMap<String, AnnotationDriverVo> driverMap, HashMap<String, AnnotationPrefixedDataAvailableVo> prefixedDataAvailableMap){ Collection<AnnotationPrefixedDataAvailableVo> col = prefixedDataAvailableMap.values(); for(AnnotationPrefixedDataAvailableVo vo : col){ if(!driverMap.containsKey(vo.protocolName)){ return "严éé误ï¼ä¸è¡æ°æ®å®æ´æ§æ£æ¥æé 驱å¨åç§°(" + vo.protocolName + ")å¨å议驱å¨ä¸æªé ç½®" ; } } int[] prioritys = new int[prefixedDataAvailableMap.size()] ; int count = 0 ; col = prefixedDataAvailableMap.values(); col = prefixedDataAvailableMap.values(); for(AnnotationPrefixedDataAvailableVo vo : col){ prioritys[count++] = vo.priority ; } NumUtil.sort(prioritys, true) ; int firstPriority = prioritys[0] ; if(ProtocolConstant.firstPriority != firstPriority){ return "严éé误ï¼ä¸è¡æ°æ®å®æ´æ§æ£æ¥æé ä¼å çº§å¿ é¡»ä» " + ProtocolConstant.firstPriority + " å¼å§" ; @@ -246,24 +235,24 @@ } return null ; } private String hasErrorInOnLine(HashMap<String, AnnotationDriverVo> driverMap, HashMap<String, AnnotationOnLineVo> onLineMap){ Collection<AnnotationOnLineVo> col = onLineMap.values(); HashMap<String, AnnotationOnLineVo> onLineMap){ Collection<AnnotationOnLineVo> col = onLineMap.values(); for(AnnotationOnLineVo vo : col){ if(!driverMap.containsKey(vo.protocolName)){ return "严éé误ï¼ä¸çº¿æ°æ®åææé 驱å¨åç§°(" + vo.protocolName + ")å¨å议驱å¨ä¸æªé ç½®" ; } } int[] prioritys = new int[onLineMap.size()] ; int count = 0 ; col = onLineMap.values(); col = onLineMap.values(); for(AnnotationOnLineVo vo : col){ prioritys[count++] = vo.priority ; } NumUtil.sort(prioritys, true) ; int firstPriority = prioritys[0] ; if(ProtocolConstant.firstPriority != firstPriority){ return "严éé误ï¼ä¸çº¿æ°æ®åææé ä¼å çº§å¿ é¡»ä» " + ProtocolConstant.firstPriority + " å¼å§" ; pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/Driver.java
@@ -1,10 +1,9 @@ package com.dy.common.mw.protocol; import java.net.URI; import java.util.HashMap; import java.util.List; import java.util.Set; import com.dy.common.util.ClassScan; import org.reflections.Reflections; public abstract class Driver { @@ -21,7 +20,6 @@ * @throws Exception å¼å¸¸ */ public abstract void scanAnnotationCode() throws Exception ; /** * æ«æè¯å«åè½ç 注解类 * @param driver é©±å¨ @@ -31,72 +29,73 @@ * @throws Exception å¼å¸¸ */ @SuppressWarnings("unchecked") protected void doScanAnnotationCode(Driver driver, String protocolName, URI uri, String scanRootPackage) throws Exception{ ClassLoader load = driver.getClass().getClassLoader() ; List<String> classNames = new ClassScan().searchClassFromUrl(new URI[]{uri}, scanRootPackage) ; if(classNames != null && classNames.size() > 0){ String code ; String[] codes ; for(String cName : classNames){ String className = cName.substring(0, cName.lastIndexOf('.')) ; Class<?> clazz = load.loadClass(className) ; Class<CodeParse> codeParseClazz ; if(clazz.isAnnotationPresent(AnnotationCodeUp.class)){ AnnotationCodeUp ann = clazz.getAnnotation(AnnotationCodeUp.class) ; if(ann != null){ codeParseClazz = (Class<CodeParse>)clazz ; codes = ann.ifAny() ; if(codes.length > 0){ for(String cd: codes){ cd = cd.trim() ; if(!(cd.trim().equals(""))){ if(driver.upCode2Classes.containsKey(cd)){ throw new Exception("严éé误ï¼åè®®" + protocolName + "çä¸è¡æ°æ®åè½ç " + cd + "åºç°äºé夿³¨è§£ï¼") ; } driver.upCode2Classes.put(cd, codeParseClazz) ; protected void doScanAnnotationCode(Driver driver, String protocolName, String scanRootPackage) throws Exception{ Reflections reflections = new Reflections(scanRootPackage); // æå®å å String code ; String[] codes ; Class<CodeParse> codeParseClazz ; Set<Class<?>> codeUpClasses = reflections.getTypesAnnotatedWith(AnnotationCodeUp.class); if (codeUpClasses != null && codeUpClasses.size() > 0) { for (Class<?> clazz : codeUpClasses) { AnnotationCodeUp ann = clazz.getAnnotation(AnnotationCodeUp.class) ; if(ann != null){ codeParseClazz = (Class<CodeParse>)clazz ; codes = ann.ifAny() ; if(codes.length > 0){ for(String cd: codes){ cd = cd.trim() ; if(!(cd.trim().equals(""))){ if(driver.upCode2Classes.containsKey(cd)){ throw new Exception("严éé误ï¼åè®®" + protocolName + "çä¸è¡æ°æ®åè½ç " + cd + "åºç°äºé夿³¨è§£ï¼") ; } driver.upCode2Classes.put(cd, codeParseClazz) ; } }else{ code = ann.value().trim() ; if(!(code.equals(""))){ if(driver.upCode2Classes.containsKey(code)){ throw new Exception("严éé误ï¼åè®®" + protocolName + "çä¸è¡æ°æ®åè½ç " + code + "åºç°äºé夿³¨è§£ï¼") ; } driver.upCode2Classes.put(code, codeParseClazz) ; } }else{ code = ann.value().trim() ; if(!(code.equals(""))){ if(driver.upCode2Classes.containsKey(code)){ throw new Exception("严éé误ï¼åè®®" + protocolName + "çä¸è¡æ°æ®åè½ç " + code + "åºç°äºé夿³¨è§£ï¼") ; } driver.upCode2Classes.put(code, codeParseClazz) ; } } } if(clazz.isAnnotationPresent(AnnotationCodeDown.class)){ AnnotationCodeDown ann = clazz.getAnnotation(AnnotationCodeDown.class) ; if(ann != null){ codeParseClazz = (Class<CodeParse>)clazz ; codes = ann.ifAny() ; if(codes.length > 0){ for(String cd: codes){ cd = cd.trim() ; if(!(cd.trim().equals(""))){ if(driver.downCode2Class.containsKey(cd)){ throw new Exception("严éé误ï¼å议驱å¨" + protocolName + "çä¸è¡æ°æ®åè½ç " + cd + "åºç°äºé夿³¨è§£ï¼") ; } driver.downCode2Class.put(cd, codeParseClazz) ; } } Set<Class<?>> codeDownClasses = reflections.getTypesAnnotatedWith(AnnotationCodeDown.class); if (codeDownClasses != null && codeDownClasses.size() > 0) { for (Class<?> clazz : codeDownClasses) { AnnotationCodeDown ann = clazz.getAnnotation(AnnotationCodeDown.class) ; if(ann != null){ codeParseClazz = (Class<CodeParse>)clazz ; codes = ann.ifAny() ; if(codes.length > 0){ for(String cd: codes){ cd = cd.trim() ; if(!(cd.trim().equals(""))){ if(driver.downCode2Class.containsKey(cd)){ throw new Exception("严éé误ï¼å议驱å¨" + protocolName + "çä¸è¡æ°æ®åè½ç " + cd + "åºç°äºé夿³¨è§£ï¼") ; } driver.downCode2Class.put(cd, codeParseClazz) ; } }else{ code = ann.value() ; if(!(code.trim().equals(""))){ if(driver.downCode2Class.containsKey(code)){ throw new Exception("严éé误ï¼å议驱å¨" + protocolName + "çä¸è¡æ°æ®åè½ç " + code + "åºç°äºé夿³¨è§£ï¼") ; } driver.downCode2Class.put(code, codeParseClazz) ; } }else{ code = ann.value() ; if(!(code.trim().equals(""))){ if(driver.downCode2Class.containsKey(code)){ throw new Exception("严éé误ï¼å议驱å¨" + protocolName + "çä¸è¡æ°æ®åè½ç " + code + "åºç°äºé夿³¨è§£ï¼") ; } driver.downCode2Class.put(code, codeParseClazz) ; } } } } } } /** * å线ç¨åä¾Driver模å¼ä¸è¿è¡ * å¾å°ä¸è¡æ°æ®åè½ç å¤çç±»CodeParse对象 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/DriverV1_0_1.java
@@ -9,7 +9,7 @@ @AnnotationDriver(enable = true, name= ProtocolConstantV206V1_0_0.protocolName) public class DriverV1_0_1 extends Driver { private static String scanRootPackage = "com.dy.common.mw.protocol.p206V1_0_0." ; private static String scanRootPackage = "com.dy.common.mw.protocol.p206V1_0_0" ; //å¨Driver䏿¯åä¾ï¼éDriverçåä¾å¯¹è±¡å¨å线ç¨ä¸è¿è¡ private ParseParamsForUpV1_0_1 upCpParams ; @@ -29,12 +29,7 @@ */ @Override public void scanAnnotationCode() throws Exception{ if(!scanRootPackage.endsWith(".")){ scanRootPackage += "." ; } URL url = this.getClass().getResource("/" + scanRootPackage.replace('.', '/')); URI uri = new URI(url.toString()); super.doScanAnnotationCode(this, ProtocolConstantV206V1_0_0.protocolName, uri, scanRootPackage) ; super.doScanAnnotationCode(this, ProtocolConstantV206V1_0_0.protocolName, scanRootPackage) ; } /** pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V202404/DriverV202404.java
@@ -1,6 +1,7 @@ package com.dy.common.mw.protocol.p206V202404; import com.dy.common.mw.protocol.*; import com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0; import com.dy.common.util.DateTime; import java.net.URI; @@ -9,7 +10,7 @@ @AnnotationDriver(name= ProtocolConstantV206V202404.protocolName) public class DriverV202404 extends Driver { private static String scanRootPackage = "com.dy.common.mw.protocol.p206V202404." ; private static String scanRootPackage = "com.dy.common.mw.protocol.p206V202404" ; //å¨Driver䏿¯åä¾ï¼éDriverçåä¾å¯¹è±¡å¨å线ç¨ä¸è¿è¡ private ParseParamsForUpV202404 upCpParams ; @@ -29,12 +30,7 @@ */ @Override public void scanAnnotationCode() throws Exception{ if(!scanRootPackage.endsWith(".")){ scanRootPackage += "." ; } URL url = this.getClass().getResource("/" + scanRootPackage.replace('.', '/')); URI uri = new URI(url.toString()); super.doScanAnnotationCode(this, ProtocolConstantV206V202404.protocolName, uri, scanRootPackage) ; super.doScanAnnotationCode(this, ProtocolConstantV206V1_0_0.protocolName, scanRootPackage) ; } /** pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ClassScan.java
File was deleted pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ConfigXml.java
@@ -1,516 +1,495 @@ package com.dy.common.util; import java.io.FileWriter; import java.net.URL; import java.util.List; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.input.SAXBuilder; import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; @SuppressWarnings("unused") import java.io.FileWriter; import java.net.URL; import java.util.List; /** * @Author: liurunyu * @Date: 2024/8/21 15:27 * @Description */ public class ConfigXml { /** * å建Document对象 * @param clazz åèç±» * @param filePath é ç½®æä»¶è·¯å¾ * @return è¿åç»æ è¿åç»æè¿å doc对象 * @throws Exception æåºå¼å¸¸ æåºå¼å¸¸ */ public Document createDom(Class<?> clazz, String filePath) throws Exception { if(clazz == null){ throw new Exception("class对象为空!"); } if(filePath == null || filePath.equals("")){ throw new Exception("é ç½®æä»¶è·¯å¾å称为空!"); } if(!filePath.startsWith("/")){ filePath = "/" + filePath ; } URL configFileURL = clazz.getResource(filePath); if (configFileURL == null) { throw new Exception("没æå¾å°" + filePath + "é ç½®!"); } return this.createDom(configFileURL) ; } /** * å建Document对象 * @param configFileURL é ç½®æä»¶è·¯å¾ * @return è¿åç»æ è¿åç»æè¿å doc对象 * @throws Exception æåºå¼å¸¸ æåºå¼å¸¸ */ public Document createDom(URL configFileURL) throws Exception { if (configFileURL == null) { throw new Exception("没æå¾å°é ç½®æä»¶!", null); } Document doc; try { SAXBuilder sb = new SAXBuilder(); doc = sb.build(configFileURL); if (doc == null) { throw new Exception("没æçæé ç½®æä»¶çDOM对象!", null); } } catch (Exception e) { throw new Exception("çæé ç½®æä»¶çDOM对象失败!", e); } return doc; } /** * ä¿åxmlæä»¶ * @param clazz åèç±» * @param doc doc对象 doc对象 * @param filePath é ç½®æä»¶è·¯å¾ * @throws Exception æåºå¼å¸¸ æåºå¼å¸¸ */ public void saveXML(Class<?> clazz, Document doc, String filePath) throws Exception { if(doc == null){ throw new Exception("Document对象为空!"); } if(filePath == null || filePath.equals("")){ throw new Exception("é ç½®æä»¶è·¯å¾å称为空!"); } if(!filePath.startsWith("/")){ filePath = "/" + filePath ; } // å°doc对象è¾åºå°æä»¶ FileWriter writer = null ; try { // å建xmlæä»¶è¾åºæµ XMLOutputter xmlopt = new XMLOutputter(); // å建æä»¶è¾åºæµ URL configFileURL = clazz.getResource(filePath); if (configFileURL == null) { throw new Exception("没æå¾å°" + filePath + "é ç½®!"); } writer = new FileWriter(configFileURL.getPath()); // æå®ææ¡£æ ¼å¼ Format fm = Format.getPrettyFormat(); fm.setEncoding("UTF-8"); xmlopt.setFormat(fm); // å°docåå ¥å°æå®çæä»¶ä¸ xmlopt.output(doc, writer); } catch (Exception e) { throw new Exception("ä¿åxmlæä»¶å¤±è´¥!", e); } finally { if(writer != null){ writer.close(); } } } /** * æ£æ¥å ç´ æ¯å¦åå¨ * @param doc doc对象 * @param elementName å ç´ åç§° * @return è¿åç»æ è¿åç»æ */ public Element getElement(Document doc, String elementName){ if(doc == null){ return null ; } if(elementName == null){ return null ; } elementName = elementName.trim() ; if(elementName.equals("")){ return null ; } return this.get_element(doc, elementName) ; } /** * æ£æ¥å ç´ æ¯å¦åå¨ * @param doc doc对象 * @param elementName å ç´ åç§° * @return è¿åç»æ è¿åç»æ */ public boolean existElement(Document doc, String elementName){ if(doc == null){ return false ; } if(elementName == null){ return false ; } elementName = elementName.trim() ; if(elementName.equals("")){ return false ; } Element e = this.get_element(doc, elementName) ; return e != null; } /** * å建Document对象 * @param configFileURL é ç½®æä»¶è·¯å¾ * @return è¿åç»æ è¿åç»æè¿å doc对象 * @throws Exception æåºå¼å¸¸ æåºå¼å¸¸ */ protected Document doCreateDom(URL configFileURL) throws Exception { if (configFileURL == null) { throw new Exception("没æå¾å°é ç½®æä»¶!", null); } Document doc; try { SAXBuilder sb = new SAXBuilder(); doc = sb.build(configFileURL); if (doc == null) { throw new Exception("没æçæé ç½®æä»¶çDOM对象!", null); } } catch (Exception e) { throw new Exception("çæé ç½®æä»¶çDOM对象失败!", e); } return doc; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çå¸å°å¼ * @param doc doc对象 * @param elementName å ç´ åç§° * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public boolean getSetAttrBoolean(Document doc, String elementName, String attrName, String attPropertyNameFix, String setValue) throws Exception{ String txt = this.getSetAttrTxt(doc, elementName, attrName, attPropertyNameFix, false, setValue) ; return txt.equalsIgnoreCase("true"); } /** * ä¿åxmlæä»¶ * @param clazz åèç±» * @param doc doc对象 doc对象 * @param filePath é ç½®æä»¶è·¯å¾ * @throws Exception æåºå¼å¸¸ æåºå¼å¸¸ */ public void saveXML(Class<?> clazz, Document doc, String filePath) throws Exception { if(doc == null){ throw new Exception("Document对象为空!"); } if(filePath == null || filePath.equals("")){ throw new Exception("é ç½®æä»¶è·¯å¾å称为空!"); } if(!filePath.startsWith("/")){ filePath = "/" + filePath ; } // å°doc对象è¾åºå°æä»¶ FileWriter writer = null ; try { // å建xmlæä»¶è¾åºæµ XMLOutputter xmlopt = new XMLOutputter(); // å建æä»¶è¾åºæµ URL configFileURL = clazz.getResource(filePath); if (configFileURL == null) { throw new Exception("没æå¾å°" + filePath + "é ç½®!"); } writer = new FileWriter(configFileURL.getPath()); // æå®ææ¡£æ ¼å¼ Format fm = Format.getPrettyFormat(); fm.setEncoding("UTF-8"); xmlopt.setFormat(fm); // å°docåå ¥å°æå®çæä»¶ä¸ xmlopt.output(doc, writer); } catch (Exception e) { throw new Exception("ä¿åxmlæä»¶å¤±è´¥!", e); } finally { if(writer != null){ writer.close(); } } } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çå¸å°å¼ * @param e å ç´ å¯¹è±¡ * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public boolean getSetAttrBoolean(Element e, String attrName, String attPropertyNameFix, String setValue) throws Exception{ String txt = this.getSetAttrTxt(e, attrName, attPropertyNameFix, false, setValue) ; return txt.equalsIgnoreCase("true"); } /** * æ£æ¥å ç´ æ¯å¦åå¨ * @param doc doc对象 * @param elementName å ç´ åç§° * @return è¿åç»æ è¿åç»æ */ public Element getElement(Document doc, String elementName){ if(doc == null){ return null ; } if(elementName == null){ return null ; } elementName = elementName.trim() ; if(elementName.equals("")){ return null ; } return this.get_element(doc, elementName) ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çåç¬¦ä¸²å¼ * @param doc doc对象 * @param elementName å ç´ åç§° * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param canBlank æ¯å¦å¯ä¸ºç©º * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public String getSetAttrTxt(Document doc, String elementName, String attrName, String attPropertyNameFix, Boolean canBlank, String setValue) throws Exception{ Element e = this.check_and_get_element(doc, elementName); return this.getSetAttrTxt(e, attrName, attPropertyNameFix, canBlank, setValue) ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çåç¬¦ä¸²å¼ * @param e å ç´ å¯¹è±¡ * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param canBlank æ¯å¦å¯ä¸ºç©º * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public String getSetAttrTxt(Element e, String attrName, String attPropertyNameFix, Boolean canBlank, String setValue) throws Exception{ String txt = this.check_get_set_Attribute(e, e.getName(), attrName, attPropertyNameFix, setValue) ; if(!canBlank){ if(txt.trim().equals("")){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼ä¸ºç©ºå符串!"); } } return txt.trim() ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çæ£æ´æ°å¼ * @param doc doc对象 * @param elementName å ç´ åç§° * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param min æå°å¼ * @param max æå¤§å¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public Integer getSetAttrPlusInt(Document doc, String elementName, String attrName, String attPropertyNameFix, Integer min, Integer max, String setValue) throws Exception{ Element e = this.check_and_get_element(doc, elementName); return this.getSetAttrPlusInt(e, attrName, attPropertyNameFix, min, max, setValue) ; } /** * æ£æ¥å ç´ æ¯å¦åå¨ * @param doc doc对象 * @param elementName å ç´ åç§° * @return è¿åç»æ è¿åç»æ */ public boolean existElement(Document doc, String elementName){ if(doc == null){ return false ; } if(elementName == null){ return false ; } elementName = elementName.trim() ; if(elementName.equals("")){ return false ; } Element e = this.get_element(doc, elementName) ; return e != null; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çæ£æ´æ°å¼ * @param e å ç´ å¯¹è±¡ * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param min æå°å¼ * @param max æå¤§å¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public Integer getSetAttrPlusInt(Element e, String attrName, String attPropertyNameFix, Integer min, Integer max, String setValue) throws Exception{ int v ; String txt = this.check_get_set_Attribute(e, e.getName(), attrName, attPropertyNameFix, setValue) ; if(!NumUtil.isPlusIntNumber(txt)){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼ä¸æ¯æ£æ´æ°!"); } v = Integer.parseInt(txt); if(min != null && v < min){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼å°äº" + min + "!"); } if(max != null && v > max){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼å¤§äº" + max + "!"); } return v ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çæ´æ°å¼ * @param doc doc对象 * @param elementName å ç´ åç§° * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param min æå°å¼ * @param max æå¤§å¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public Integer getSetAttrInt(Document doc, String elementName, String attrName, String attPropertyNameFix, Integer min, Integer max, String setValue) throws Exception{ Element e = this.check_and_get_element(doc, elementName); return this.getSetAttrInt(e, attrName, attPropertyNameFix, min, max, setValue) ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çæ´æ°å¼ * @param e å ç´ å¯¹è±¡ * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param min æå°å¼ * @param max æå¤§å¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public Integer getSetAttrInt(Element e, String attrName, String attPropertyNameFix, Integer min, Integer max, String setValue) throws Exception{ int v ; String txt = this.check_get_set_Attribute(e, e.getName(), attrName, attPropertyNameFix, setValue) ; if(!NumUtil.isIntNumber(txt)){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼ä¸æ¯æ£æ´æ°!"); } v = Integer.parseInt(txt) ; if(min != null && v < min){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼å°äº" + min + "!"); } if(max != null && v > max){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼å¤§äº" + max + "!"); } return v ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çæµ®ç¹æ°å¼ * @param doc doc对象 * @param elementName å ç´ åç§° * @param attrName 屿§åç§° * @param min æå°å¼ * @param max æå¤§å¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public Double getSetAttrPlusDouble(Document doc, String elementName, String attrName, String attPropertyNameFix, Double min, Double max, String setValue) throws Exception{ Element e = this.check_and_get_element(doc, elementName); return this.getSetAttrPlusDouble(e, attrName, attPropertyNameFix, min, max, setValue) ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çæ£æµ®ç¹æ°å¼ * @param e å ç´ å¯¹è±¡ * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param min æå°å¼ * @param max æå¤§å¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public Double getSetAttrPlusDouble(Element e, String attrName, String attPropertyNameFix, Double min, Double max, String setValue) throws Exception{ double v ; String txt = this.check_get_set_Attribute(e, e.getName(), attrName, attPropertyNameFix, setValue) ; if(!NumUtil.isPlusDoubleNumber(txt)){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼ä¸æ¯æ£æµ®ç¹æ°!"); } v = Double.parseDouble(txt) ; if(min != null && v < min){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼å°äº" + min + "!"); } if(max != null && v > max){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼å¤§äº" + max + "!"); } return v ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çæµ®ç¹æ°å¼ * @param doc doc对象 * @param elementName å ç´ åç§° * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param min æå°å¼ * @param max æå¤§å¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public Double getSetAttrDouble(Document doc, String elementName, String attrName, String attPropertyNameFix, Double min, Double max, String setValue) throws Exception{ Element e = this.check_and_get_element(doc, elementName); return this.getSetAttrDouble(e, attrName, attPropertyNameFix, min, max, setValue) ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çæµ®ç¹æ°å¼ * @param e å ç´ å¯¹è±¡ * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param min æå°å¼ * @param max æå¤§å¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public Double getSetAttrDouble(Element e, String attrName, String attPropertyNameFix, Double min, Double max, String setValue) throws Exception{ double v ; String txt = this.check_get_set_Attribute(e, e.getName(), attrName, attPropertyNameFix, setValue) ; if(!NumUtil.isDoubleNumber(txt)){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼ä¸æ¯æ£æµ®ç¹æ°!"); } v = Double.parseDouble(txt) ; if(min != null && v < min){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼å°äº" + min + "!"); } if(max != null && v > max){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼å¤§äº" + max + "!"); } return v ; } /** * å¾å°å ç´ * @param doc doc对象 * @param elementName å ç´ åç§° å ç´ åï¼å½¢å¦"config.base.test" * @return è¿åç»æ */ private Element get_element(Document doc, String elementName){ Element e = null ; Element root ; String nm ; String[] eNames = elementName.split("\\.") ; if(eNames.length > 0){ root = doc.getRootElement() ; nm = root.getName() ; if(nm.equals(eNames[0].trim())){ if(eNames.length == 1){ e = root ; }else{ e = this.get_next_element(root, eNames, 1) ; } } } return e ; } /** * å¾å°åå ç´ * @param base ä¸çº§å ç´ å¯¹è±¡ * @param eNames å ç´ åç§° * @param index æ°ç»ä¸æ * @return è¿åç»æ */ private Element get_next_element(Element base, String[] eNames, int index){ Element e = null ; String nm ; List<Element> list = base.getChildren() ; if(list != null && list.size() >0){ for(Element el: list){ nm = el.getName() ; if(nm.equals(eNames[index].trim())){ if(eNames.length == index + 1){ e = el ; }else{ e = this.get_next_element(el, eNames, index + 1) ; } break ; } } } return e ; } /** * æ£æ¥å¹¶è·å ç´ * @param doc doc对象 * @param elementName å ç´ åç§° * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ private Element check_and_get_element(Document doc, String elementName)throws Exception{ if(doc == null){ throw new Exception("é ç½®æä»¶çDOM对象为空!"); } if(elementName == null){ throw new Exception("å ç´ å为空!"); } elementName = elementName.trim() ; if(elementName.equals("")){ throw new Exception("å ç´ å为空!"); } Element e = this.get_element(doc, elementName) ; if(e == null){ throw new Exception("æªå¾å°å称为" + elementName + "çå ç´ !"); } return e ; } /** * æ£æ¥å¹¶è·å¾å¹¶è®¾ç½®å±æ§å¼ * @param e å ç´ å¯¹è±¡ * @param elementName å ç´ åç§° * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ private String check_get_set_Attribute(Element e, String elementName, String attrName, String attPropertyNameFix, String setValue)throws Exception{ if(attrName == null){ throw new Exception("屿§å为空!"); } attrName = attrName.trim() ; if(attrName.equals("")){ throw new Exception("屿§å为空!"); } String txt = this.get_set_AttributTxt(e, attrName, attPropertyNameFix, setValue) ; if(txt == null){ throw new Exception("æªå¾å°å ç´ " + elementName + "ç屿§" + attrName + "çå¼!"); } return txt ; } /** * å¾å°å¹¶è®¾ç½®å±æ§é ç½®å¼ * @param e å ç´ å¯¹è±¡ * @param attName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ */ private String get_set_AttributTxt(Element e, String attName, String attPropertyNameFix, String setValue){ String txt = null ; if(e != null && attName != null){ attName = attName.trim() ; if(!attName.equals("")){ txt = e.getAttributeValue(attName) ; if(setValue != null){ e.setAttribute(attName, setValue) ; } } } if(txt != null && txt.startsWith("${") && txt.endsWith("}")){ txt = txt.substring(2, txt.length() - 1) ; if(attPropertyNameFix != null){ txt = txt + attPropertyNameFix ; } txt = ConfigProperties.getConfig(txt) ; } return txt ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çå¸å°å¼ * @param doc doc对象 * @param elementName å ç´ åç§° * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public boolean getSetAttrBoolean(Document doc, String elementName, String attrName, String attPropertyNameFix, String setValue) throws Exception{ String txt = this.getSetAttrTxt(doc, elementName, attrName, attPropertyNameFix, false, setValue) ; return txt.equalsIgnoreCase("true"); } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çå¸å°å¼ * @param e å ç´ å¯¹è±¡ * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public boolean getSetAttrBoolean(Element e, String attrName, String attPropertyNameFix, String setValue) throws Exception{ String txt = this.getSetAttrTxt(e, attrName, attPropertyNameFix, false, setValue) ; return txt.equalsIgnoreCase("true"); } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çåç¬¦ä¸²å¼ * @param doc doc对象 * @param elementName å ç´ åç§° * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param canBlank æ¯å¦å¯ä¸ºç©º * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public String getSetAttrTxt(Document doc, String elementName, String attrName, String attPropertyNameFix, Boolean canBlank, String setValue) throws Exception{ Element e = this.check_and_get_element(doc, elementName); return this.getSetAttrTxt(e, attrName, attPropertyNameFix, canBlank, setValue) ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çåç¬¦ä¸²å¼ * @param e å ç´ å¯¹è±¡ * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param canBlank æ¯å¦å¯ä¸ºç©º * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public String getSetAttrTxt(Element e, String attrName, String attPropertyNameFix, Boolean canBlank, String setValue) throws Exception{ String txt = this.check_get_set_Attribute(e, e.getName(), attrName, attPropertyNameFix, setValue) ; if(!canBlank){ if(txt.trim().equals("")){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼ä¸ºç©ºå符串!"); } } return txt.trim() ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çæ£æ´æ°å¼ * @param doc doc对象 * @param elementName å ç´ åç§° * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param min æå°å¼ * @param max æå¤§å¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public Integer getSetAttrPlusInt(Document doc, String elementName, String attrName, String attPropertyNameFix, Integer min, Integer max, String setValue) throws Exception{ Element e = this.check_and_get_element(doc, elementName); return this.getSetAttrPlusInt(e, attrName, attPropertyNameFix, min, max, setValue) ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çæ£æ´æ°å¼ * @param e å ç´ å¯¹è±¡ * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param min æå°å¼ * @param max æå¤§å¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public Integer getSetAttrPlusInt(Element e, String attrName, String attPropertyNameFix, Integer min, Integer max, String setValue) throws Exception{ int v ; String txt = this.check_get_set_Attribute(e, e.getName(), attrName, attPropertyNameFix, setValue) ; if(!NumUtil.isPlusIntNumber(txt)){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼ä¸æ¯æ£æ´æ°!"); } v = Integer.parseInt(txt); if(min != null && v < min){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼å°äº" + min + "!"); } if(max != null && v > max){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼å¤§äº" + max + "!"); } return v ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çæ´æ°å¼ * @param doc doc对象 * @param elementName å ç´ åç§° * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param min æå°å¼ * @param max æå¤§å¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public Integer getSetAttrInt(Document doc, String elementName, String attrName, String attPropertyNameFix, Integer min, Integer max, String setValue) throws Exception{ Element e = this.check_and_get_element(doc, elementName); return this.getSetAttrInt(e, attrName, attPropertyNameFix, min, max, setValue) ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çæ´æ°å¼ * @param e å ç´ å¯¹è±¡ * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param min æå°å¼ * @param max æå¤§å¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public Integer getSetAttrInt(Element e, String attrName, String attPropertyNameFix, Integer min, Integer max, String setValue) throws Exception{ int v ; String txt = this.check_get_set_Attribute(e, e.getName(), attrName, attPropertyNameFix, setValue) ; if(!NumUtil.isIntNumber(txt)){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼ä¸æ¯æ£æ´æ°!"); } v = Integer.parseInt(txt) ; if(min != null && v < min){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼å°äº" + min + "!"); } if(max != null && v > max){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼å¤§äº" + max + "!"); } return v ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çæµ®ç¹æ°å¼ * @param doc doc对象 * @param elementName å ç´ åç§° * @param attrName 屿§åç§° * @param min æå°å¼ * @param max æå¤§å¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public Double getSetAttrPlusDouble(Document doc, String elementName, String attrName, String attPropertyNameFix, Double min, Double max, String setValue) throws Exception{ Element e = this.check_and_get_element(doc, elementName); return this.getSetAttrPlusDouble(e, attrName, attPropertyNameFix, min, max, setValue) ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çæ£æµ®ç¹æ°å¼ * @param e å ç´ å¯¹è±¡ * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param min æå°å¼ * @param max æå¤§å¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public Double getSetAttrPlusDouble(Element e, String attrName, String attPropertyNameFix, Double min, Double max, String setValue) throws Exception{ double v ; String txt = this.check_get_set_Attribute(e, e.getName(), attrName, attPropertyNameFix, setValue) ; if(!NumUtil.isPlusDoubleNumber(txt)){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼ä¸æ¯æ£æµ®ç¹æ°!"); } v = Double.parseDouble(txt) ; if(min != null && v < min){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼å°äº" + min + "!"); } if(max != null && v > max){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼å¤§äº" + max + "!"); } return v ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çæµ®ç¹æ°å¼ * @param doc doc对象 * @param elementName å ç´ åç§° * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param min æå°å¼ * @param max æå¤§å¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public Double getSetAttrDouble(Document doc, String elementName, String attrName, String attPropertyNameFix, Double min, Double max, String setValue) throws Exception{ Element e = this.check_and_get_element(doc, elementName); return this.getSetAttrDouble(e, attrName, attPropertyNameFix, min, max, setValue) ; } /** * å¾å°å¹¶è®¾ç½®å ç´ ç屿§çæµ®ç¹æ°å¼ * @param e å ç´ å¯¹è±¡ * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param min æå°å¼ * @param max æå¤§å¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ public Double getSetAttrDouble(Element e, String attrName, String attPropertyNameFix, Double min, Double max, String setValue) throws Exception{ double v ; String txt = this.check_get_set_Attribute(e, e.getName(), attrName, attPropertyNameFix, setValue) ; if(!NumUtil.isDoubleNumber(txt)){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼ä¸æ¯æ£æµ®ç¹æ°!"); } v = Double.parseDouble(txt) ; if(min != null && v < min){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼å°äº" + min + "!"); } if(max != null && v > max){ throw new Exception("å ç´ " + e.getName() + "ç屿§" + attrName + "çå¼å¤§äº" + max + "!"); } return v ; } /** * å¾å°å ç´ * @param doc doc对象 * @param elementName å ç´ åç§° å ç´ åï¼å½¢å¦"config.base.test" * @return è¿åç»æ */ private Element get_element(Document doc, String elementName){ Element e = null ; Element root ; String nm ; String[] eNames = elementName.split("\\.") ; if(eNames.length > 0){ root = doc.getRootElement() ; nm = root.getName() ; if(nm.equals(eNames[0].trim())){ if(eNames.length == 1){ e = root ; }else{ e = this.get_next_element(root, eNames, 1) ; } } } return e ; } /** * å¾å°åå ç´ * @param base ä¸çº§å ç´ å¯¹è±¡ * @param eNames å ç´ åç§° * @param index æ°ç»ä¸æ * @return è¿åç»æ */ private Element get_next_element(Element base, String[] eNames, int index){ Element e = null ; String nm ; List<Element> list = base.getChildren() ; if(list != null && list.size() >0){ for(Element el: list){ nm = el.getName() ; if(nm.equals(eNames[index].trim())){ if(eNames.length == index + 1){ e = el ; }else{ e = this.get_next_element(el, eNames, index + 1) ; } break ; } } } return e ; } /** * æ£æ¥å¹¶è·å ç´ * @param doc doc对象 * @param elementName å ç´ åç§° * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ private Element check_and_get_element(Document doc, String elementName)throws Exception{ if(doc == null){ throw new Exception("é ç½®æä»¶çDOM对象为空!"); } if(elementName == null){ throw new Exception("å ç´ å为空!"); } elementName = elementName.trim() ; if(elementName.equals("")){ throw new Exception("å ç´ å为空!"); } Element e = this.get_element(doc, elementName) ; if(e == null){ throw new Exception("æªå¾å°å称为" + elementName + "çå ç´ !"); } return e ; } /** * æ£æ¥å¹¶è·å¾å¹¶è®¾ç½®å±æ§å¼ * @param e å ç´ å¯¹è±¡ * @param elementName å ç´ åç§° * @param attrName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @return è¿åç»æ * @throws Exception æåºå¼å¸¸ */ private String check_get_set_Attribute(Element e, String elementName, String attrName, String attPropertyNameFix, String setValue)throws Exception{ if(attrName == null){ throw new Exception("屿§å为空!"); } attrName = attrName.trim() ; if(attrName.equals("")){ throw new Exception("屿§å为空!"); } String txt = this.get_set_AttributTxt(e, attrName, attPropertyNameFix, setValue) ; if(txt == null){ throw new Exception("æªå¾å°å ç´ " + elementName + "ç屿§" + attrName + "çå¼!"); } return txt ; } /** * å¾å°å¹¶è®¾ç½®å±æ§é ç½®å¼ * @param e å ç´ å¯¹è±¡ * @param attName 屿§åç§° * @param attPropertyNameFix 屿§åç§°åç¼ * @param setValue åæ¶è®¾ç½®å¼ * @return è¿åç»æ */ private String get_set_AttributTxt(Element e, String attName, String attPropertyNameFix, String setValue){ String txt = null ; if(e != null && attName != null){ attName = attName.trim() ; if(!attName.equals("")){ txt = e.getAttributeValue(attName) ; if(setValue != null){ e.setAttribute(attName, setValue) ; } } } if(txt != null && txt.startsWith("${") && txt.endsWith("}")){ txt = txt.substring(2, txt.length() - 1) ; if(attPropertyNameFix != null){ txt = txt + attPropertyNameFix ; } txt = ConfigProperties.getConfig(txt) ; } return txt ; } } pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ConfigXml4Springboot.java
New file @@ -0,0 +1,36 @@ package com.dy.common.util; import java.net.URL; import org.jdom2.Document; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; @SuppressWarnings("unused") public class ConfigXml4Springboot extends ConfigXml { /** * å¨SpringBootç¯å¢ä¸åºç¨ * @param resourceLoader * @param fileName * @return * @throws Exception */ public Document createDom(ResourceLoader resourceLoader, String fileName) throws Exception { if(resourceLoader == null){ throw new Exception("resourceLoader对象为空!"); } if(fileName == null || fileName.equals("")){ throw new Exception("é ç½®æä»¶è·¯å¾å称为空!"); } while(fileName.startsWith("/") || fileName.startsWith("\\")){ fileName = fileName.substring(1) ; } Resource resource = resourceLoader.getResource("classpath:" + fileName); URL configFileURL = resource.getURL() ; if (configFileURL == null) { throw new Exception("没æå¾å°" + fileName + "é ç½®!"); } return super.doCreateDom(configFileURL) ; } } pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ConfigXmlNoSpringboot.java
New file @@ -0,0 +1,33 @@ package com.dy.common.util; import java.net.URL; import org.jdom2.Document; @SuppressWarnings("unused") public class ConfigXmlNoSpringboot extends ConfigXml { /** * å¨éSpringBootç¯å¢ä¸åºç¨ * å建Document对象 * @param clazz åèç±» * @param filePath é ç½®æä»¶è·¯å¾ * @return è¿åç»æ è¿åç»æè¿å doc对象 * @throws Exception æåºå¼å¸¸ æåºå¼å¸¸ */ public Document createDom(Class<?> clazz, String filePath) throws Exception { if(clazz == null){ throw new Exception("class对象为空!"); } if(filePath == null || filePath.equals("")){ throw new Exception("é ç½®æä»¶è·¯å¾å称为空!"); } if(!filePath.startsWith("/")){ filePath = "/" + filePath ; } URL configFileURL = clazz.getResource(filePath); if (configFileURL == null) { throw new Exception("没æå¾å°" + filePath + "é ç½®!"); } return super.doCreateDom(configFileURL) ; } } pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/OrgListenerSupport.java
@@ -1,10 +1,8 @@ package com.dy.pipIrrGlobal.util; import com.dy.common.util.ConfigXml; import com.dy.common.util.ConfigXml4Springboot; import org.jdom2.Document; import org.springframework.boot.context.event.ApplicationReadyEvent; import java.net.URL; import org.springframework.core.io.ResourceLoader; /** * @Author: liurunyu @@ -17,18 +15,17 @@ * å®å§å */ @SuppressWarnings("unused ") protected void init() { this.init(null); protected void init(ResourceLoader resourceLoader) { this.doInit(resourceLoader); } /** * å®å§å */ @SuppressWarnings("unused ") protected void init(ApplicationReadyEvent event) { protected void doInit(ResourceLoader resourceLoader) { try { URL configFileURL = OrgListenerSupport.class.getResource("/init-config.xml"); ConfigXml configXml = new ConfigXml(); Document doc = configXml.createDom(configFileURL); ConfigXml4Springboot configXml = new ConfigXml4Springboot() ; Document doc = configXml.createDom(resourceLoader, "init-config.xml") ; this.doInit(configXml, doc); } catch (Exception e) { System.out.println("ç³»ç»å¯å¨æ¶ï¼åå§åé ç½®åºé !"); @@ -36,16 +33,19 @@ e.printStackTrace(); } } private void doInit(ConfigXml configXml, Document doc) throws Exception { private void doInit(ConfigXml4Springboot configXml, Document doc) throws Exception { if (configXml != null && doc != null) { for (int num = 1; num <= 10000; num++) { if (configXml.existElement(doc, "config.orgs.org" + num)) { String orgTag = configXml.getSetAttrTxt(doc, "config.orgs.org" + num, "tag", null, false, null); String orgName = configXml.getSetAttrTxt(doc, "config.orgs.org" + num, "name", null, false, null); Org.OrgVo vo = new Org().new OrgVo() ; vo.tag = orgTag ; vo.name = orgName ; Org.OrgList.add(vo) ; Boolean enable = configXml.getSetAttrBoolean(doc, "config.orgs.org" + num, "enable", null, null); if(enable != null && enable.booleanValue()){ Org.OrgVo vo = new Org().new OrgVo() ; vo.tag = orgTag ; vo.name = orgName ; Org.OrgList.add(vo) ; } }else{ break ; } pipIrr-platform/pipIrr-global/src/main/resources/init-config.xml
@@ -1,8 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> <config> <orgs> <!-- å¤ä¸ªç»ç»ï¼ç¨ç¼å·åºåï¼ç¼å·ä»1å¼å§ --> <org1 tag="ym" name="å è°"> <!-- å¤ä¸ªç»ç»ï¼ç¨ç¼å·åºåï¼ç¼å·ä»1å¼å§ï¼enable表示æ¯å¦å¯ç¨ --> <org1 tag="ym" name="å è°" enable="true"> <districts> <province name="äºåç" num="53" level="0"> <city name="æ¥éå½æèªæ²»å·" num="23" level="1"> @@ -29,7 +29,7 @@ <item5 typeName="绿åç¨æ°´"/> </waterTypes> </org1> <org2 tag="pj" name="çè§"> <org2 tag="pj" name="çè§" enable="false"> <districts> <province name="äºåç" num="53" level="0"> <city name="丽æ±å¸" num="23" level="1"> pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/pom.xml
@@ -159,6 +159,14 @@ <artifactId>jna-platform</artifactId> <version>5.12.1</version> </dependency> <!-- ç±»åå° --> <dependency> <groupId>org.reflections</groupId> <artifactId>reflections</artifactId> <version>0.10.2</version> </dependency> <!-- æµè¯ --> <dependency> <groupId>org.springframework.boot</groupId> pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/Server.java
@@ -22,17 +22,19 @@ import com.dy.rtuMw.resource.ResourceUnit; import com.dy.rtuMw.resource.ResourceUnitConfigVo; import com.dy.common.springUtil.SpringContextUtil; import com.dy.common.util.ConfigXml; import com.dy.common.util.ConfigXml4Springboot; import com.dy.common.util.IDLongGenerator; import org.jdom2.Document; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.ResourceLoader; import org.springframework.stereotype.Component; @Component public class Server { private ConfigXml conf = null ; private ConfigXml4Springboot conf = null ; private Document doc = null ; private boolean showStartInfo = false ; @@ -42,6 +44,9 @@ private String HttpSvPort ; @Value("${server.servlet.context-path}") private String HttpSvPath ; @Autowired protected ResourceLoader resourceLoader ; private List<UnitInterface> units = new ArrayList<UnitInterface>() ; @@ -78,8 +83,8 @@ try { //ConfigProperties.init(this.getClass().getResourceAsStream("/config/config.properties"), false); this.conf = new ConfigXml() ; this.doc = this.conf.createDom(this.getClass(), "config.xml") ; this.conf = new ConfigXml4Springboot() ; this.doc = this.conf.createDom(this.resourceLoader, "config.xml") ; //////////////// //æå¡ é ç½® this.showStartInfo = this.conf.getSetAttrBoolean(this.doc, "config.server", "showStartInfo", null, null) ; @@ -325,6 +330,7 @@ ///////////////// //RTUä¸è¡æ°æ®å¤ç模å RtuDataUnitConfigVo rducVo = new RtuDataUnitConfigVo(); rducVo.resourceLoader = this.resourceLoader ; AdapterImp_RtuDataUnit rducAdap = new AdapterImp_RtuDataUnit(); rducAdap.setConfig(rducVo); RtuDataUnit rducUnit = RtuDataUnit.getInstance(); pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/rtuData/RtuDataUnit.java
@@ -34,7 +34,7 @@ */ @Override public void start(UnitStartedCallbackInterface callback) throws Exception { TaskPool.setTaskTreeCofig(new TreeParse().parseConfig()); TaskPool.setTaskTreeCofig(new TreeParse().parseConfig(confVo.resourceLoader)); callback.call(null) ; System.out.println("RTUæ°æ®å¤ç模åæåå¯å¨"); } pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/rtuData/RtuDataUnitConfigVo.java
@@ -1,5 +1,7 @@ package com.dy.rtuMw.server.rtuData; public class RtuDataUnitConfigVo { import org.springframework.core.io.ResourceLoader; public class RtuDataUnitConfigVo { public ResourceLoader resourceLoader ; } pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/rtuData/TreeParse.java
@@ -7,7 +7,8 @@ import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.input.SAXBuilder; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; public class TreeParse { public List<String> ids ; @@ -26,7 +27,6 @@ /** * è§£æå¤çå¨é ç½® * @return */ protected TreeConfig parseConfig() { try { ClassLoader classLoader = ClassLoader.getSystemClassLoader(); @@ -39,6 +39,24 @@ return null; } } */ /** * è§£æå¤çå¨é ç½® * @return */ protected TreeConfig parseConfig(ResourceLoader resourceLoader) { try { Resource resource = resourceLoader.getResource("classpath:RtuDataDealTree.xml"); URL configFileURL = resource.getURL() ; return this.parse(this.createDom(configFileURL)) ; } catch (Exception e) { System.out.println("ç³»ç»å¯å¨æ¶ï¼åå§ä¸è¡æ°æ®å¤çä»»å¡é ç½®åºé !"); System.out.println(e.getMessage()); e.printStackTrace(); return null; } } /** * pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/resources/config.xml
@@ -9,7 +9,7 @@ onlyOneProtocolï¼å¨æ¯æå¤éä¿¡åè®®æ¶ï¼åªæRTUä¸çº¿äºï¼æè½è¯å«åºè¯¥RTUå®é ç¨çéä¿¡åè®®ï¼è¿èç¨æ¤å议解æä¸è¡æ°æ®åæé ä¸è¡å½ä»¤ã 妿RTUæªæ¾ä¸çº¿ï¼éä¿¡ä¸é´ä»¶å¯å¨å该RTUæªæ¾ä¸çº¿ï¼ï¼é£ä¹å¨åå®åéä¸è¡å½ä»¤æ¶ï¼ä¸è½å¤æåºå ¶éç¨çåè®®ï¼ä¹ä¸è½æé å½ä»¤ï¼å°¤å ¶æ¯ä½åèæ åµä¸ï¼ä¸ä¸çº¿æ¯æ£å¸¸ç°è±¡ã å½åªæä¸ä¸ªåè®®æ åµä¸ï¼å¨RTUæªæ¾ä¸çº¿æ¶ï¼ä¹è½ç¨æ¤åè®®æé å½ä»¤å¹¶ç¼å䏿¥ï¼å°¤å ¶éåä½åèæ åµã onlyOneProtocol=true: éä¿¡ä¸é´ä»¶å½ååªæä¸ä¸ªåè®® onlyOneProtocol=true: éä¿¡ä¸é´ä»¶å½ååªæä¸ä¸ªåè®® downComandMaxResendTimes: ä¸è¡å½ä»¤å 许åéçæå¤§æ¬¡æ°Xï¼å³å 许éåX-1 commandSendInterval: é对ä¸ä¸ªRTUï¼ä¸åå½ä»¤çæ¶é´é´é(ç§) cachWaitResultTimeout: å½ä»¤å·²ç»åéè¾¾æå¤§æ¬¡æ°ï¼ä»æªæ¶å°å½ä»¤ç»æï¼éè¦å¨ç¼åç»§ç»çå¾ ï¼å ¶çå¾ æå¤§æ¶é¿(ç§)ï¼æ¬ç³»ç»RTUï¼å¯¹äºå¼å ³æ³µå½ä»¤ï¼å ¶å æ§è¡å¼å ³æ³µæ¥ï¼ç¶ååè¿è¡å½ä»¤åºçï¼æä»¥æ¤å¼ è¦å¤§ä¸äº @@ -40,7 +40,8 @@ sendDingDingAlarmMsInterval="60" /> <!-- <!-- 2024-08-22 ææ¶ä¸ç¨ centerAddr: ä¸å¿å°åï¼å½åï¼centerAddræªç¨å° synchroRtuClock: æ¯å¦å¯¹RTUæ ¡æ¶ synchroRtuClockTimepiecesï¼å½RTU䏿å¡å¨æ¶éç¸å·®ä¸å®æ¯«ç§ï¼é ç½®æä»¶æ¯ç§éï¼åï¼è¿è¡æ ¡æ¶ @@ -107,7 +108,8 @@ /> <!-- <!-- 2024-08-22 ææ¶ä¸ç¨ portï¼rmiæå¡ç«¯å£å· contextï¼rmiæå¡ä¸ä¸æ --> pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/Server.java
@@ -11,10 +11,11 @@ import com.dy.common.mw.UnitInterface; import com.dy.common.mw.support.SupportUnit; import com.dy.common.mw.support.SupportUnitConfigVo; import com.dy.common.util.ConfigXml; import com.dy.common.util.ConfigXmlNoSpringboot; public class Server { private ConfigXml conf = null ; private ConfigXmlNoSpringboot conf = null ; private Document doc = null ; private boolean showStartInfo = false ; @@ -27,7 +28,7 @@ Server sv = new Server(); Long start = System.currentTimeMillis() ; try { sv.conf = new ConfigXml() ; sv.conf = new ConfigXmlNoSpringboot() ; sv.doc = sv.conf.createDom(sv.getClass(), "/config.xml") ; //////////////// //æå¡ é ç½® pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/˵Ã÷.txt
New file @@ -0,0 +1 @@ æ¬æ¨¡åæ¯æ¹éååæµè¯ç客æ·ç«¯ï¼æ¨¡æå¤ä¸ªæµæ§å¨ä¸æ¥æ°æ®ï¼åæå¡ç«¯ï¼pipIrr-mwTest-serverï¼æ§å¶ã pipIrr-platform/pipIrr-mw/pipIrr-mwTest-server/src/main/java/com/dy/testServer/Server.java
@@ -12,12 +12,12 @@ import com.dy.common.mw.UnitStartedCallbackInterface; import com.dy.common.mw.channel.rmi.RmiConfigVo; import com.dy.common.mw.channel.rmi.RmiUnit; import com.dy.common.util.ConfigXml; import com.dy.common.util.NumUtil; import com.dy.common.util.ConfigXmlNoSpringboot; public class Server{ private ConfigXml conf = null ; private ConfigXmlNoSpringboot conf = null ; private Document doc = null ; private boolean showStartInfo = false ; @@ -39,7 +39,7 @@ Server sv = new Server(); long start = System.currentTimeMillis() ; try { sv.conf = new ConfigXml() ; sv.conf = new ConfigXmlNoSpringboot() ; sv.doc = sv.conf.createDom(sv.getClass(), "config.xml") ; //////////////// //æå¡ é ç½® pipIrr-platform/pipIrr-mw/pipIrr-mwTest-server/˵Ã÷.txt
New file @@ -0,0 +1 @@ æ¬æ¨¡åæ¯æ¹éååæµè¯çæå¡ç«¯ï¼ä¸ºå®¢æ·ç«¯ï¼pipIrr-mwTest-clientï¼åé æµæ§å¨ï¼RTUï¼æ°éåæµæ§å¨ï¼RTUï¼å°åï¼å¹¶æ§å¶å®¢æ·å¯å¨ï¼æ¥æ¶å®¢æ·ç«¯æ°æ®ã pipIrr-platform/pipIrr-web/pipIrr-mwTest-rtu/src/main/java/com/dy/pipIrrMwTestRtu/Server.java
@@ -1,10 +1,12 @@ package com.dy.pipIrrMwTestRtu; import com.dy.common.mw.UnitInterface; import com.dy.common.util.ConfigXml; import com.dy.common.util.ConfigXml4Springboot; import com.dy.pipIrrMwTestRtu.tcpClient.TcpClUnit; import com.dy.pipIrrMwTestRtu.tcpClient.TcpClUnitConfigVo; import org.jdom2.Document; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ResourceLoader; import org.springframework.stereotype.Component; import java.util.ArrayList; @@ -18,8 +20,10 @@ @Component public class Server { @Autowired protected ResourceLoader resourceLoader ; private ConfigXml conf = null ; private ConfigXml4Springboot conf = null ; private Document doc = null ; private boolean showStartInfo = false ; @@ -41,8 +45,8 @@ try { //ConfigProperties.init(this.getClass().getResourceAsStream("/config/config.properties"), false); this.conf = new ConfigXml() ; this.doc = this.conf.createDom(this.getClass(), "config.xml") ; this.conf = new ConfigXml4Springboot() ; this.doc = this.conf.createDom(resourceLoader, "config.xml") ; //////////////// //æå¡ é ç½® this.showStartInfo = this.conf.getSetAttrBoolean(this.doc, "config.server", "showStartInfo", null, null) ; pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/resources/application.yml
@@ -1,6 +1,6 @@ spring: profiles: include: global, database, database-ym, database-pj, database-sp include: global, database, database-ym, database-pj #actutorçwebç«¯å£ management: pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/util/InitListener.java
@@ -3,7 +3,7 @@ import com.dy.common.multiDataSource.DataSourceContext; import com.dy.common.mybatis.envm.Deleted; import com.dy.common.mybatis.envm.Disabled; import com.dy.common.util.ConfigXml; import com.dy.common.util.ConfigXml4Springboot; import com.dy.common.util.MD5; import com.dy.pipIrrGlobal.daoBa.BaDistrictMapper; import com.dy.pipIrrGlobal.daoBa.BaSettingsMapper; @@ -20,10 +20,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.ApplicationListener; import org.springframework.core.io.ResourceLoader; import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; import java.net.URL; /** * çå¬å¨ï¼å®ç°åè½ï¼å¨ç³»ç»å¯å¨æ¶åå§åï¼åæ°æ®åºä¸æå ¥æ°æ® @@ -34,11 +33,18 @@ @Component public class InitListener implements ApplicationListener<ApplicationReadyEvent> { protected ResourceLoader resourceLoader ; private BaDistrictMapper distriDao ; private BaUserMapper userDao ; private SePaymentMethodMapper paymentMethodDao ; private BaSettingsMapper settingsDao ; private SeWaterTypeMapper waterTypeDao ; @Autowired public void setResourceLoader(ResourceLoader resourceLoader){ this.resourceLoader = resourceLoader ; } @Autowired public void setDistriDao(BaDistrictMapper distriDao){ @@ -88,9 +94,8 @@ @SuppressWarnings("unused ") private void init(ApplicationReadyEvent event){ try { URL configFileURL = InitListener.class.getResource("/init-config.xml" ); ConfigXml configXml = new ConfigXml() ; Document doc = configXml.createDom(configFileURL) ; ConfigXml4Springboot configXml = new ConfigXml4Springboot() ; Document doc = configXml.createDom(this.resourceLoader, "init-config.xml") ; this.doInit(configXml, doc); } catch (Exception e) { System.out.println("ç³»ç»å¯å¨æ¶ï¼åå§åé ç½®åºé !"); @@ -98,76 +103,79 @@ e.printStackTrace(); } } private void doInit(ConfigXml configXml, Document doc) throws Exception{ private void doInit(ConfigXml4Springboot configXml, Document doc) throws Exception{ if(configXml != null && doc != null){ for(int num = 1; num <= 10000; num++){ if(configXml.existElement(doc, "config.orgs.org" + num)){ String orgTag = configXml.getSetAttrTxt(doc, "config.orgs.org" + num,"tag", null, false, null) ; //è®¾ç½®æ°æ®æº DataSourceContext.set(orgTag); if(!this.existDistricts()){ if(configXml.existElement(doc, "config.orgs.org" + num + ".districts.province")){ String distriName = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".districts.province","name", null, false, null) ; String distriNum = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".districts.province","num", null, false, null) ; Integer distriLevel = configXml.getSetAttrPlusInt(doc, "config.orgs.org" + num + ".districts.province","level", null, 0, 99,null) ; Long supperId = this.saveDistrict(null, distriName, distriNum, distriLevel); if(supperId != null && configXml.existElement(doc, "config.orgs.org" + num + ".districts.province.city")){ distriName = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".districts.province.city","name", null, false, null) ; distriNum = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".districts.province.city","num", null, false, null) ; distriLevel = configXml.getSetAttrPlusInt(doc, "config.orgs.org" + num + ".districts.province.city","level", null, 1, 99,null) ; supperId = this.saveDistrict(supperId, distriName, distriNum, distriLevel); if(supperId != null && configXml.existElement(doc, "config.orgs.org" + num + ".districts.province.city.country")) { distriName = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".districts.province.city.country", "name", null, false, null); distriNum = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".districts.province.city.country", "num", null, false, null); distriLevel = configXml.getSetAttrPlusInt(doc, "config.orgs.org" + num + ".districts.province.city.country", "level", null, 1, 99, null); this.saveDistrict(supperId, distriName, distriNum, distriLevel); Boolean enable = configXml.getSetAttrBoolean(doc, "config.orgs.org" + num, "enable", null, null); if(enable != null && enable.booleanValue()){ //è®¾ç½®æ°æ®æº DataSourceContext.set(orgTag); if(!this.existDistricts()){ if(configXml.existElement(doc, "config.orgs.org" + num + ".districts.province")){ String distriName = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".districts.province","name", null, false, null) ; String distriNum = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".districts.province","num", null, false, null) ; Integer distriLevel = configXml.getSetAttrPlusInt(doc, "config.orgs.org" + num + ".districts.province","level", null, 0, 99,null) ; Long supperId = this.saveDistrict(null, distriName, distriNum, distriLevel); if(supperId != null && configXml.existElement(doc, "config.orgs.org" + num + ".districts.province.city")){ distriName = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".districts.province.city","name", null, false, null) ; distriNum = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".districts.province.city","num", null, false, null) ; distriLevel = configXml.getSetAttrPlusInt(doc, "config.orgs.org" + num + ".districts.province.city","level", null, 1, 99,null) ; supperId = this.saveDistrict(supperId, distriName, distriNum, distriLevel); if(supperId != null && configXml.existElement(doc, "config.orgs.org" + num + ".districts.province.city.country")) { distriName = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".districts.province.city.country", "name", null, false, null); distriNum = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".districts.province.city.country", "num", null, false, null); distriLevel = configXml.getSetAttrPlusInt(doc, "config.orgs.org" + num + ".districts.province.city.country", "level", null, 1, 99, null); this.saveDistrict(supperId, distriName, distriNum, distriLevel); } } } } } if(!this.existUsers()){ if(configXml.existElement(doc, "config.orgs.org" + num + ".user")){ String name = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".user","name", null, false, null) ; String phone = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".user","phone", null, false, null) ; String password = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".user","password", null, false, null) ; Integer supperAdmin = configXml.getSetAttrPlusInt(doc, "config.orgs.org" + num + ".user","supperAdmin", null, 0, 1,null) ; this.saveUser(orgTag, name, phone, password, supperAdmin); if(!this.existUsers()){ if(configXml.existElement(doc, "config.orgs.org" + num + ".user")){ String name = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".user","name", null, false, null) ; String phone = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".user","phone", null, false, null) ; String password = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".user","password", null, false, null) ; Integer supperAdmin = configXml.getSetAttrPlusInt(doc, "config.orgs.org" + num + ".user","supperAdmin", null, 0, 1,null) ; this.saveUser(orgTag, name, phone, password, supperAdmin); } } } if(!this.existPayments()){ if(configXml.existElement(doc, "config.orgs.org" + num + ".payments")){ for(int i = 1 ; i < 10000; i++){ if(configXml.existElement(doc, "config.orgs.org" + num + ".payments.item" + i)){ String name = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".payments.item" + i,"name", null, false, null) ; this.savePayment(orgTag, name); }else{ break ; if(!this.existPayments()){ if(configXml.existElement(doc, "config.orgs.org" + num + ".payments")){ for(int i = 1 ; i < 10000; i++){ if(configXml.existElement(doc, "config.orgs.org" + num + ".payments.item" + i)){ String name = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".payments.item" + i,"name", null, false, null) ; this.savePayment(orgTag, name); }else{ break ; } } } } } if(!this.existSettings()){ if(configXml.existElement(doc, "config.orgs.org" + num + ".settings")){ for(int i = 1 ; i < 10000; i++){ if(configXml.existElement(doc, "config.orgs.org" + num + ".settings.item" + i)){ String item_name = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".settings.item" + i,"item_name", null, false, null) ; String item_value = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".settings.item" + i,"item_value", null, false, null) ; String remarks = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".settings.item" + i,"remarks", null, false, null) ; this.saveSettings(orgTag, item_name, item_value, remarks); }else{ break ; if(!this.existSettings()){ if(configXml.existElement(doc, "config.orgs.org" + num + ".settings")){ for(int i = 1 ; i < 10000; i++){ if(configXml.existElement(doc, "config.orgs.org" + num + ".settings.item" + i)){ String item_name = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".settings.item" + i,"item_name", null, false, null) ; String item_value = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".settings.item" + i,"item_value", null, false, null) ; String remarks = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".settings.item" + i,"remarks", null, false, null) ; this.saveSettings(orgTag, item_name, item_value, remarks); }else{ break ; } } } } } if(!this.existWaterTypes()){ if(configXml.existElement(doc, "config.orgs.org" + num + ".waterTypes")){ for(int i = 1 ; i < 10000; i++){ if(configXml.existElement(doc, "config.orgs.org" + num + ".waterTypes.item" + i)){ String typeName = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".waterTypes.item" + i,"typeName", null, false, null) ; this.saveWaterType(orgTag, typeName); }else{ break ; if(!this.existWaterTypes()){ if(configXml.existElement(doc, "config.orgs.org" + num + ".waterTypes")){ for(int i = 1 ; i < 10000; i++){ if(configXml.existElement(doc, "config.orgs.org" + num + ".waterTypes.item" + i)){ String typeName = configXml.getSetAttrTxt(doc, "config.orgs.org" + num + ".waterTypes.item" + i,"typeName", null, false, null) ; this.saveWaterType(orgTag, typeName); }else{ break ; } } } } pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/resources/application.yml
@@ -1,6 +1,6 @@ spring: profiles: include: global, database, database-ym, database-pj, database-sp include: global, database, database-ym, database-pj #actutorçwebç«¯å£ management: pipIrr-platform/pipIrr-web/pipIrr-web-operation/src/main/resources/application.yml
@@ -1,6 +1,6 @@ spring: profiles: include: global, database, database-ym, database-pj, database-sp include: global, database, database-ym, database-pj #actutorçwebç«¯å£ management: pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/resources/application.yml
@@ -1,6 +1,6 @@ spring: profiles: include: global, database, database-ym, database-pj, database-sp include: global, database, database-ym, database-pj #actutorçwebç«¯å£ management: pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/resources/application.yml
@@ -1,6 +1,6 @@ spring: profiles: include: global, database, database-ym, database-pj, database-sp include: global, database, database-ym, database-pj #actutorçwebç«¯å£ management: pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/resources/application.yml
@@ -1,6 +1,6 @@ spring: profiles: include: global, database, database-ym, database-pj, database-sp include: global, database, database-ym, database-pj #actutorçwebç«¯å£ management: pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/util/SsoListener.java
@@ -1,12 +1,17 @@ package com.dy.sso.util; import com.dy.pipIrrGlobal.util.OrgListenerSupport; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.ApplicationListener; import org.springframework.core.io.ResourceLoader; import org.springframework.stereotype.Component; @Component public class SsoListener extends OrgListenerSupport implements ApplicationListener<ApplicationReadyEvent> { @Autowired protected ResourceLoader resourceLoader ; @Override @@ -18,7 +23,7 @@ e.printStackTrace(); } finally { //åå§åæºæ super.init(); super.init(resourceLoader); } } pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/resources/application.yml
@@ -1,6 +1,6 @@ spring: profiles: include: global, database, database-ym, database-pj, database-sp include: global, database, database-ym, database-pj #actutorçwebç«¯å£ management: pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/util/OrgListener.java
@@ -1,12 +1,17 @@ package com.dy.pipIrrStatistics.util; import com.dy.pipIrrGlobal.util.OrgListenerSupport; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.ApplicationListener; import org.springframework.core.io.ResourceLoader; import org.springframework.stereotype.Component; @Component public class OrgListener extends OrgListenerSupport implements ApplicationListener<ApplicationReadyEvent> { @Autowired protected ResourceLoader resourceLoader ; @Override public void onApplicationEvent(ApplicationReadyEvent event) { @@ -16,7 +21,7 @@ } catch (InterruptedException e) { e.printStackTrace(); } finally { super.init(); super.init(resourceLoader); } } } pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/resources/application.yml
@@ -1,6 +1,6 @@ spring: profiles: include: global, database, database-ym, database-pj, database-sp include: global, database, database-ym, database-pj #actutorçwebç«¯å£ management: pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/resources/application.yml
@@ -1,6 +1,6 @@ spring: profiles: include: global, database, database-ym, database-pj, database-sp include: global, database, database-ym, database-pj #actutorçwebç«¯å£ management: