1、完善代码和application.yml配置文件,去掉不用的引入文件;
2、init-config.xml配置中增加属性 enable,相应解析类也增加了解析与判断;
3、凡是有Server的应用,加载资源方式改为用springboot的工具类加载;
4、通信协议相关的扫描注解功能实现改为采用reflections-0.10.2,以实现可以在jar包情况下能够扫描类(.class)注解。
| | |
| | | <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> |
| | |
| | | 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; |
| | | |
| | | /** |
| | | * æ«æï¼ |
| | |
| | | @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 ; |
| | | |
| | |
| | | * @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()); |
| | | |
| | | List<String> classNames = new ClassScan().searchClassFromUrl(new URI[]{uri}, scanRootPackage) ; |
| | | if(classNames != null && classNames.size() > 0){ |
| | | Reflections reflections = new Reflections(scanRootPackage); // æå®å
å |
| | | Set<Class<?>> driverClasses = reflections.getTypesAnnotatedWith(AnnotationDriver.class); |
| | | if (driverClasses != null && driverClasses.size() > 0) { |
| | | String protocolName ; |
| | | int priority; |
| | | int onLineDataMinLength; |
| | |
| | | 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)){ |
| | | 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 + "åºç°äºé夿³¨è§£ï¼") ; |
| | | throw new Exception("严éé误ï¼å议驱å¨(åç§°)" + protocolName + "åºç°äºé夿³¨è§£ï¼"); |
| | | } |
| | | driverMap.put(protocolName, new AnnotationDriverVo(clazz)) ; |
| | | }else{ |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | if(clazz.isAnnotationPresent(AnnotationPrefixedDataAvailable.class)){ |
| | | Set<Class<?>> prefixedClass = reflections.getTypesAnnotatedWith(AnnotationPrefixedDataAvailable.class); |
| | | for (Class<?> clazz : prefixedClass) { |
| | | AnnotationPrefixedDataAvailable ann = clazz.getAnnotation(AnnotationPrefixedDataAvailable.class) ; |
| | | if(ann != null){ |
| | | if(ann.enable()){ |
| | |
| | | } |
| | | } |
| | | |
| | | if(clazz.isAnnotationPresent(AnnotationOnLine.class)){ |
| | | Set<Class<?>> onLineClass = reflections.getTypesAnnotatedWith(AnnotationOnLine.class); |
| | | for (Class<?> clazz : onLineClass) { |
| | | AnnotationOnLine ann = clazz.getAnnotation(AnnotationOnLine.class) ; |
| | | if(ann != null){ |
| | | if(ann.enable()){ |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //è¿è¡éªè¯ |
| | | String error = this.hasErrorInDriver(driverMap) ; |
| | | if(error != null){ |
| | | throw new Exception(error) ; |
| | |
| | | throw new Exception("严ééè¯¯ï¼ æ«æåè®®ç¸å
³æ³¨è§£æå¾å°ç±»åéåä¸ºç©ºï¼æ«ææ ¹è·¯å¾æ¯" + scanRootPackage) ; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ£æ¥ä¼å
级éå¤ |
| | | * @param priority ä¼å
级 |
| | |
| | | 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 { |
| | |
| | | * @throws Exception å¼å¸¸ |
| | | */ |
| | | public abstract void scanAnnotationCode() throws Exception ; |
| | | |
| | | /** |
| | | * æ«æè¯å«åè½ç 注解类 |
| | | * @param driver é©±å¨ |
| | |
| | | * @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){ |
| | | protected void doScanAnnotationCode(Driver driver, String protocolName, String scanRootPackage) throws Exception{ |
| | | Reflections reflections = new Reflections(scanRootPackage); // æå®å
å |
| | | 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)){ |
| | | |
| | | 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 ; |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if(clazz.isAnnotationPresent(AnnotationCodeDown.class)){ |
| | | 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 ; |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å线ç¨åä¾Driver模å¼ä¸è¿è¡ |
| | | * å¾å°ä¸è¡æ°æ®åè½ç å¤çç±»CodeParse对象 |
| | |
| | | @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 ; |
| | |
| | | */ |
| | | @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) ; |
| | | } |
| | | |
| | | /** |
| | |
| | | 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; |
| | |
| | | @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 ; |
| | |
| | | */ |
| | | @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) ; |
| | | } |
| | | |
| | | /** |
| | |
| | | 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") |
| | | public class ConfigXml { |
| | | |
| | | import java.io.FileWriter; |
| | | import java.net.URL; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * å建Document对象 |
| | | * @param clazz åèç±» |
| | | * @param filePath é
ç½®æä»¶è·¯å¾ |
| | | * @return è¿åç»æ è¿åç»æè¿å doc对象 |
| | | * @throws Exception æåºå¼å¸¸ æåºå¼å¸¸ |
| | | * @Author: liurunyu |
| | | * @Date: 2024/8/21 15:27 |
| | | * @Description |
| | | */ |
| | | 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) ; |
| | | } |
| | | public class ConfigXml { |
| | | |
| | | /** |
| | | * å建Document对象 |
| | |
| | | * @return è¿åç»æ è¿åç»æè¿å doc对象 |
| | | * @throws Exception æåºå¼å¸¸ æåºå¼å¸¸ |
| | | */ |
| | | public Document createDom(URL configFileURL) throws Exception { |
| | | protected Document doCreateDom(URL configFileURL) throws Exception { |
| | | if (configFileURL == null) { |
| | | throw new Exception("没æå¾å°é
ç½®æä»¶!", null); |
| | | } |
New file |
| | |
| | | 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) ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | 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) ; |
| | | } |
| | | |
| | | } |
| | |
| | | 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 |
| | |
| | | * å®å§å |
| | | */ |
| | | @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("ç³»ç»å¯å¨æ¶ï¼åå§åé
ç½®åºé !"); |
| | |
| | | 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); |
| | | 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 ; |
| | | } |
| | |
| | | <?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"> |
| | |
| | | <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"> |
| | |
| | | <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> |
| | |
| | | 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 ; |
| | | |
| | |
| | | private String HttpSvPort ; |
| | | @Value("${server.servlet.context-path}") |
| | | private String HttpSvPath ; |
| | | |
| | | @Autowired |
| | | protected ResourceLoader resourceLoader ; |
| | | |
| | | private List<UnitInterface> units = new ArrayList<UnitInterface>() ; |
| | | |
| | |
| | | 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) ; |
| | |
| | | ///////////////// |
| | | //RTUä¸è¡æ°æ®å¤ç模å |
| | | RtuDataUnitConfigVo rducVo = new RtuDataUnitConfigVo(); |
| | | rducVo.resourceLoader = this.resourceLoader ; |
| | | AdapterImp_RtuDataUnit rducAdap = new AdapterImp_RtuDataUnit(); |
| | | rducAdap.setConfig(rducVo); |
| | | RtuDataUnit rducUnit = RtuDataUnit.getInstance(); |
| | |
| | | */ |
| | | @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æ°æ®å¤ç模åæåå¯å¨"); |
| | | } |
| | |
| | | package com.dy.rtuMw.server.rtuData; |
| | | |
| | | public class RtuDataUnitConfigVo { |
| | | import org.springframework.core.io.ResourceLoader; |
| | | |
| | | public class RtuDataUnitConfigVo { |
| | | public ResourceLoader resourceLoader ; |
| | | } |
| | |
| | | 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 ; |
| | |
| | | /** |
| | | * è§£æå¤çå¨é
ç½® |
| | | * @return |
| | | */ |
| | | protected TreeConfig parseConfig() { |
| | | try { |
| | | ClassLoader classLoader = ClassLoader.getSystemClassLoader(); |
| | |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * |
| | |
| | | /> |
| | | |
| | | <!-- |
| | | 2024-08-22 ææ¶ä¸ç¨ |
| | | centerAddr: ä¸å¿å°åï¼å½åï¼centerAddræªç¨å° |
| | | synchroRtuClock: æ¯å¦å¯¹RTUæ ¡æ¶ |
| | | synchroRtuClockTimepiecesï¼å½RTU䏿å¡å¨æ¶éç¸å·®ä¸å®æ¯«ç§ï¼é
ç½®æä»¶æ¯ç§éï¼åï¼è¿è¡æ ¡æ¶ |
| | |
| | | |
| | | |
| | | <!-- |
| | | 2024-08-22 ææ¶ä¸ç¨ |
| | | portï¼rmiæå¡ç«¯å£å· |
| | | contextï¼rmiæå¡ä¸ä¸æ |
| | | --> |
| | |
| | | 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 ; |
| | | |
| | |
| | | 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") ; |
| | | //////////////// |
| | | //æå¡ é
ç½® |
New file |
| | |
| | | æ¬æ¨¡åæ¯æ¹éååæµè¯ç客æ·ç«¯ï¼æ¨¡æå¤ä¸ªæµæ§å¨ä¸æ¥æ°æ®ï¼åæå¡ç«¯ï¼pipIrr-mwTest-serverï¼æ§å¶ã |
| | |
| | | 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 ; |
| | | |
| | |
| | | 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") ; |
| | | //////////////// |
| | | //æå¡ é
ç½® |
New file |
| | |
| | | æ¬æ¨¡åæ¯æ¹éååæµè¯çæå¡ç«¯ï¼ä¸ºå®¢æ·ç«¯ï¼pipIrr-mwTest-clientï¼åé
æµæ§å¨ï¼RTUï¼æ°éåæµæ§å¨ï¼RTUï¼å°åï¼å¹¶æ§å¶å®¢æ·å¯å¨ï¼æ¥æ¶å®¢æ·ç«¯æ°æ®ã |
| | |
| | | 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; |
| | |
| | | |
| | | @Component |
| | | public class Server { |
| | | @Autowired |
| | | protected ResourceLoader resourceLoader ; |
| | | |
| | | private ConfigXml conf = null ; |
| | | private ConfigXml4Springboot conf = null ; |
| | | private Document doc = null ; |
| | | private boolean showStartInfo = false ; |
| | | |
| | |
| | | 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) ; |
| | |
| | | spring: |
| | | profiles: |
| | | include: global, database, database-ym, database-pj, database-sp |
| | | include: global, database, database-ym, database-pj |
| | | |
| | | #actutorçwebç«¯å£ |
| | | management: |
| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | | /** |
| | | * çå¬å¨ï¼å®ç°åè½ï¼å¨ç³»ç»å¯å¨æ¶åå§åï¼åæ°æ®åºä¸æå
¥æ°æ® |
| | |
| | | @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){ |
| | |
| | | @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("ç³»ç»å¯å¨æ¶ï¼åå§åé
ç½®åºé !"); |
| | |
| | | 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) ; |
| | | Boolean enable = configXml.getSetAttrBoolean(doc, "config.orgs.org" + num, "enable", null, null); |
| | | if(enable != null && enable.booleanValue()){ |
| | | //è®¾ç½®æ°æ®æº |
| | | DataSourceContext.set(orgTag); |
| | | if(!this.existDistricts()){ |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }else{ |
| | | break ; |
| | | } |
| | |
| | | spring: |
| | | profiles: |
| | | include: global, database, database-ym, database-pj, database-sp |
| | | include: global, database, database-ym, database-pj |
| | | |
| | | #actutorçwebç«¯å£ |
| | | management: |
| | |
| | | spring: |
| | | profiles: |
| | | include: global, database, database-ym, database-pj, database-sp |
| | | include: global, database, database-ym, database-pj |
| | | |
| | | #actutorçwebç«¯å£ |
| | | management: |
| | |
| | | spring: |
| | | profiles: |
| | | include: global, database, database-ym, database-pj, database-sp |
| | | include: global, database, database-ym, database-pj |
| | | |
| | | #actutorçwebç«¯å£ |
| | | management: |
| | |
| | | spring: |
| | | profiles: |
| | | include: global, database, database-ym, database-pj, database-sp |
| | | include: global, database, database-ym, database-pj |
| | | |
| | | #actutorçwebç«¯å£ |
| | | management: |
| | |
| | | spring: |
| | | profiles: |
| | | include: global, database, database-ym, database-pj, database-sp |
| | | include: global, database, database-ym, database-pj |
| | | |
| | | #actutorçwebç«¯å£ |
| | | management: |
| | |
| | | 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 |
| | |
| | | e.printStackTrace(); |
| | | } finally { |
| | | //åå§åæºæ |
| | | super.init(); |
| | | super.init(resourceLoader); |
| | | } |
| | | } |
| | | |
| | |
| | | spring: |
| | | profiles: |
| | | include: global, database, database-ym, database-pj, database-sp |
| | | include: global, database, database-ym, database-pj |
| | | |
| | | #actutorçwebç«¯å£ |
| | | management: |
| | |
| | | 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) { |
| | |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | super.init(); |
| | | super.init(resourceLoader); |
| | | } |
| | | } |
| | | } |
| | |
| | | spring: |
| | | profiles: |
| | | include: global, database, database-ym, database-pj, database-sp |
| | | include: global, database, database-ym, database-pj |
| | | |
| | | #actutorçwebç«¯å£ |
| | | management: |
| | |
| | | spring: |
| | | profiles: |
| | | include: global, database, database-ym, database-pj, database-sp |
| | | include: global, database, database-ym, database-pj |
| | | |
| | | #actutorçwebç«¯å£ |
| | | management: |