| package com.dy.pipirrComCreator; | 
|   | 
| import com.dy.common.mw.protocol.p206V1.ProtocolConstantV206V1; | 
| import com.dy.common.util.NumUtil; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.boot.CommandLineRunner; | 
| import org.springframework.boot.WebApplicationType; | 
| import org.springframework.boot.autoconfigure.SpringBootApplication; | 
| import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | 
| import org.springframework.boot.builder.SpringApplicationBuilder; | 
| import org.springframework.context.annotation.ComponentScan; | 
| import org.springframework.context.annotation.FilterType; | 
|   | 
| @Slf4j | 
| @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) //禁止启动数据库连接池 | 
| @ComponentScan(basePackages = {"com.dy.common", "com.dy.pipIrrGlobal", "com.dy.pipirrComCreator"}, | 
|         excludeFilters = { | 
|                 @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = { | 
|                         com.dy.common.apiDoc.SpringApiConfig.class, //一种排除类的方式 | 
|                         com.dy.pipIrrGlobal.config.DingTalk.class | 
|                 }), | 
|                 @ComponentScan.Filter(type = FilterType.REGEX, pattern = { | 
|                         //二种排除类的方式,写正则表达式,需要对目标类的完全限定名完全匹配,否则不生效 | 
|                         "com.dy.common.aop..*", | 
|                         "com.dy.common.apiDoc..*", | 
|                         "com.dy.common.multiDataSource..*", | 
|                         "com.dy.common.singleDataSource..*", | 
|                         "com.dy.common.mybatis..*", | 
|                         "com.dy.common.webFilter..*", | 
|                         "com.dy.common.webListener..*", | 
|                         "com.dy.pipIrrGlobal.config..*", | 
|                         "com.dy.pipIrrGlobal.webCtrls..*" | 
|                 }) | 
|         } | 
| ) | 
| public class PipIrrComCreatorApplication implements CommandLineRunner { | 
|   | 
|   | 
|     /** | 
|      * 参数0:协议名称(当前只支持p206V1) | 
|      * 参数1:协议版本号(当前只支持1) | 
|      * 参数2:rtu地址 | 
|      * 参数3:IC卡地址 | 
|      * 参数4:IC卡编号 | 
|      * @param args | 
|      */ | 
|     public static void main(String[] args) { | 
|         int index = 0 ; | 
|         parseArg0(args, index++) ; | 
|         parseArg1(args, index++) ; | 
|         parseArg2(args, index++) ; | 
|         parseArg3(args, index++) ; | 
|         parseArg4(args, index++) ; | 
|   | 
|         new SpringApplicationBuilder(PipIrrComCreatorApplication.class) | 
|                 .web(WebApplicationType.NONE)//不启动web服务 | 
|                 .run(args); | 
|     } | 
|   | 
|   | 
|     private static void parseArg0(String[] args, int index){ | 
|         if(args != null | 
|                 && args.length > index | 
|                 && args[index] != null | 
|                 && !args[index].trim().equals("")){ | 
|             ServerProperties.protocolName = args[index] ;//协议名称 | 
|             log.info("参数" + (index + 1) + ":" + ServerProperties.protocolName); | 
|         } | 
|         if(ServerProperties.protocolName == null || ServerProperties.protocolName.trim().equals("")){ | 
|             ServerProperties.protocolName = ProtocolConstantV206V1.protocolName ; | 
|             ServerProperties.protocolVersion = ProtocolConstantV206V1.protocolVer ; | 
|         } | 
|     } | 
|   | 
|     private static void parseArg1(String[] args, int index){ | 
|         if(args != null | 
|                 && args.length > index | 
|                 && args[index] != null | 
|                 && !args[index].trim().equals("")){ | 
|             if(ServerProperties.protocolVersion == -1){ | 
|                 if(NumUtil.isPlusIntNumber(args[index].trim())){ | 
|                     ServerProperties.protocolVersion = Short.parseShort(args[index].trim()) ;//协议版本号 | 
|                 } | 
|             } | 
|             log.info("参数" + (index + 1) + ":" + args[index].trim()); | 
|         }else{ | 
|             if(ServerProperties.protocolVersion == -1){ | 
|                 ServerProperties.protocolVersion = ProtocolConstantV206V1.protocolVer ; | 
|             } | 
|         } | 
|     } | 
|     private static void parseArg2(String[] args, int index){ | 
|         if(args != null | 
|                 && args.length > index | 
|                 && args[index] != null | 
|                 && !args[index].trim().equals("")){ | 
|             ServerProperties.rtuAddr = args[index] ;//本模拟器模拟RTU地址 | 
|             log.info("参数" + (index + 1) + ":" + ServerProperties.rtuAddr); | 
|         } | 
|         if(ServerProperties.rtuAddr == null){ | 
|             ServerProperties.rtuAddr = "37142501020100218" ; | 
|         } | 
|     } | 
|     private static void parseArg3(String[] args, int index){ | 
|         if(args != null | 
|                 && args.length > index | 
|                 && args[index] != null | 
|                 && !args[index].trim().equals("")){ | 
|             ServerProperties.icCardAddr = args[index] ;//IC卡地址 | 
|             log.info("参数" + (index + 1) + ":" + ServerProperties.icCardAddr); | 
|         } | 
|         if(ServerProperties.icCardAddr == null){ | 
|             ServerProperties.icCardAddr = "C49A340D" ; | 
|         } | 
|     } | 
|     private static void parseArg4(String[] args, int index){ | 
|         if(args != null | 
|                 && args.length > index | 
|                 && args[index] != null | 
|                 && !args[index].trim().equals("")){ | 
|             ServerProperties.icCardNo = args[index] ;//IC卡编号 | 
|             log.info("参数" + (index + 1) + ":" + ServerProperties.icCardNo); | 
|         } | 
|         if(ServerProperties.icCardNo == null){ | 
|             ServerProperties.icCardNo = "37142501020100257" ; | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * Spring容器启动完成后,执行下面方法 | 
|      * @param args 参数 | 
|      * @throws Exception 异常 | 
|      */ | 
|     @Override | 
|     public void run(String... args) throws Exception { | 
|         try{ | 
|             //等待一下 | 
|             Thread.sleep(500L); | 
|         }catch (Exception e){ | 
|             e.printStackTrace(); | 
|         } | 
|         finally { | 
|             this.startMwSv() ; | 
|         } | 
|     } | 
|   | 
|     private void startMwSv(){ | 
|         if(sv != null){ | 
|             try { | 
|                 sv.startServer(); | 
|             }catch (Exception e){ | 
|                 e.printStackTrace(); | 
|             } | 
|         } | 
|     } | 
|   | 
|   | 
|     private Server sv ; | 
|   | 
|     @Autowired | 
|     public void setSv(Server sv){ | 
|         this.sv = sv ; | 
|     } | 
|   | 
| } |