Commit d2274741be65df6b77a79fe850da1b065e295b0a

Authored by 潘钊
0 parents

init...

Showing 40 changed files with 3206 additions and 0 deletions
.gitignore 0 → 100644
  1 +++ a/.gitignore
  1 +.classpath
  2 +.project
  3 +.springBeans
  4 +.settings/*
  5 +/target/*
  6 +node_modules/
  7 +test_junitReport/
  8 +test_coverage/
  9 +.idea
  10 +.DS_Store
  11 +*.iml
  12 +tmp
  13 +
  14 +# git忽略空文件夹,按照惯例,空文件夹下放置.gitkeep文件避免文件夹被忽略不上传。
  15 +!.gitkeep
  16 +/target/
... ...
README.md 0 → 100644
  1 +++ a/README.md
  1 +
  2 +GPS客户端,调度系统用!!!!
0 3 \ No newline at end of file
... ...
pom.xml 0 → 100644
  1 +++ a/pom.xml
  1 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3 +
  4 + <modelVersion>4.0.0</modelVersion>
  5 + <groupId>com.bsth</groupId>
  6 + <artifactId>control_gps_client</artifactId>
  7 + <version>0.0.1-SNAPSHOT</version>
  8 + <packaging>jar</packaging>
  9 +
  10 + <parent>
  11 + <groupId>org.springframework.boot</groupId>
  12 + <artifactId>spring-boot-starter-parent</artifactId>
  13 + <version>1.5.2.RELEASE</version>
  14 + </parent>
  15 +
  16 + <dependencies>
  17 +
  18 + <dependency>
  19 + <groupId>org.springframework.boot</groupId>
  20 + <artifactId>spring-boot-starter-web</artifactId>
  21 + </dependency>
  22 +
  23 + <dependency>
  24 + <groupId>org.springframework.boot</groupId>
  25 + <artifactId>spring-boot-starter-tomcat</artifactId>
  26 + <scope>provided</scope>
  27 + </dependency>
  28 +
  29 + <dependency>
  30 + <groupId>org.springframework.boot</groupId>
  31 + <artifactId>spring-boot-starter-aop</artifactId>
  32 + </dependency>
  33 +
  34 + <dependency>
  35 + <groupId>org.springframework</groupId>
  36 + <artifactId>spring-context-support</artifactId>
  37 + </dependency>
  38 +
  39 + <dependency>
  40 + <groupId>joda-time</groupId>
  41 + <artifactId>joda-time</artifactId>
  42 + </dependency>
  43 + <dependency>
  44 + <groupId>com.alibaba</groupId>
  45 + <artifactId>fastjson</artifactId>
  46 + <version>1.2.4</version>
  47 + </dependency>
  48 +
  49 + <dependency>
  50 + <groupId>org.apache.httpcomponents</groupId>
  51 + <artifactId>httpclient</artifactId>
  52 + </dependency>
  53 +
  54 + <dependency>
  55 + <groupId>commons-dbcp</groupId>
  56 + <artifactId>commons-dbcp</artifactId>
  57 + </dependency>
  58 + <dependency>
  59 + <groupId>commons-lang</groupId>
  60 + <artifactId>commons-lang</artifactId>
  61 + <version>2.6</version>
  62 + </dependency>
  63 + <dependency>
  64 + <groupId>org.apache.commons</groupId>
  65 + <artifactId>commons-lang3</artifactId>
  66 + <version>3.4</version>
  67 + </dependency>
  68 + <dependency>
  69 + <groupId>commons-io</groupId>
  70 + <artifactId>commons-io</artifactId>
  71 + <version>2.4</version>
  72 + </dependency>
  73 + <dependency>
  74 + <groupId>org.codehaus.janino</groupId>
  75 + <artifactId>janino</artifactId>
  76 + </dependency>
  77 +
  78 + <dependency>
  79 + <groupId>org.apache.poi</groupId>
  80 + <artifactId>poi</artifactId>
  81 + <version>3.13</version>
  82 + </dependency>
  83 +
  84 + <dependency>
  85 + <groupId>com.google.guava</groupId>
  86 + <artifactId>guava</artifactId>
  87 + <version>19.0</version>
  88 + </dependency>
  89 +
  90 + <dependency>
  91 + <groupId>org.apache.mina</groupId>
  92 + <artifactId>mina-core</artifactId>
  93 + <version>2.0.13</version>
  94 + </dependency>
  95 +
  96 + </dependencies>
  97 +
  98 + <build>
  99 + <plugins>
  100 + <plugin>
  101 + <artifactId>maven-compiler-plugin</artifactId>
  102 + <version>2.3.2</version><!--$NO-MVN-MAN-VER$ -->
  103 + <configuration>
  104 + <source>1.7</source>
  105 + <target>1.7</target>
  106 + </configuration>
  107 + </plugin>
  108 + <plugin>
  109 + <artifactId>maven-war-plugin</artifactId>
  110 + <version>2.2</version><!--$NO-MVN-MAN-VER$ -->
  111 + <configuration>
  112 + <failOnMissingWebXml>false</failOnMissingWebXml>
  113 + </configuration>
  114 + </plugin>
  115 + <plugin>
  116 + <groupId>org.springframework.boot</groupId>
  117 + <artifactId>spring-boot-maven-plugin</artifactId>
  118 + </plugin>
  119 + </plugins>
  120 + <resources>
  121 + <resource>
  122 + <directory>src/main/resources</directory>
  123 + <filtering>false</filtering>
  124 + </resource>
  125 + </resources>
  126 + </build>
  127 + <repositories>
  128 + <repository>
  129 + <id>spring-snapshots</id>
  130 + <url>http://repo.spring.io/snapshot</url>
  131 + <snapshots>
  132 + <enabled>true</enabled>
  133 + </snapshots>
  134 + </repository>
  135 + <repository>
  136 + <id>spring-milestones</id>
  137 + <url>http://repo.spring.io/milestone</url>
  138 + </repository>
  139 + </repositories>
  140 + <pluginRepositories>
  141 + <pluginRepository>
  142 + <id>spring-snapshots</id>
  143 + <url>http://repo.spring.io/snapshot</url>
  144 + </pluginRepository>
  145 + <pluginRepository>
  146 + <id>spring-milestones</id>
  147 + <url>http://repo.spring.io/milestone</url>
  148 + </pluginRepository>
  149 + </pluginRepositories>
  150 +
  151 + <properties>
  152 + <start-class>com.bsth.Application</start-class>
  153 + </properties>
  154 +</project>
... ...
src/main/java/com/bsth/Application.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/Application.java
  1 +package com.bsth;
  2 +
  3 +import org.springframework.boot.SpringApplication;
  4 +import org.springframework.boot.autoconfigure.SpringBootApplication;
  5 +import org.springframework.boot.builder.SpringApplicationBuilder;
  6 +import org.springframework.boot.web.support.SpringBootServletInitializer;
  7 +
  8 +import java.util.concurrent.Executors;
  9 +import java.util.concurrent.ScheduledExecutorService;
  10 +
  11 +@SpringBootApplication
  12 +public class Application extends SpringBootServletInitializer {
  13 +
  14 + public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(7);
  15 +
  16 + @Override
  17 + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
  18 + return application.sources(Application.class);
  19 + }
  20 +
  21 + public static void main(String[] args) throws Exception {
  22 + SpringApplication.run(Application.class, args);
  23 + }
  24 +
  25 +}
0 26 \ No newline at end of file
... ...
src/main/java/com/bsth/WebAppConfiguration.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/WebAppConfiguration.java
  1 +package com.bsth;
  2 +
  3 +import org.springframework.context.annotation.Bean;
  4 +import org.springframework.context.annotation.ComponentScan;
  5 +import org.springframework.context.annotation.Configuration;
  6 +import org.springframework.web.filter.CharacterEncodingFilter;
  7 +import org.springframework.web.filter.HttpPutFormContentFilter;
  8 +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  9 +
  10 +import javax.servlet.Filter;
  11 +
  12 +@Configuration
  13 +@ComponentScan
  14 +public class WebAppConfiguration extends WebMvcConfigurerAdapter {
  15 +
  16 + /**
  17 + * @Title: httpPutFormContentFilter
  18 + * @Description: TODO(弥补浏览器不支持PUT/DELETE,对携带 _method 参数的请求进行转换)
  19 + */
  20 + @Bean
  21 + public Filter httpPutFormContentFilter() {
  22 + return new HttpPutFormContentFilter();
  23 + }
  24 +
  25 + /**
  26 + * @Title: characterEncodingFilter
  27 + * @Description: TODO(编码过滤器)
  28 + */
  29 + @Bean
  30 + public Filter characterEncodingFilter(){
  31 + return new CharacterEncodingFilter("UTF-8");
  32 + }
  33 +}
... ...
src/main/java/com/bsth/client/ClientApp.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/ClientApp.java
  1 +package com.bsth.client;
  2 +
  3 +import com.bsth.data.gpsdata.client.pd.codec.PdMessageCodecFactory;
  4 +import com.bsth.data.gpsdata.client.pd.handler.PdClientHandler;
  5 +import com.bsth.data.gpsdata.client.pd.protocol.Pd_31_0;
  6 +import com.bsth.data.gpsdata.client.pf.codec.PfMessageCodecFactory;
  7 +import com.bsth.data.gpsdata.client.pf.handler.PfClientHandler;
  8 +import com.bsth.util.ConfigUtil;
  9 +import org.apache.mina.core.future.ConnectFuture;
  10 +import org.apache.mina.core.future.WriteFuture;
  11 +import org.apache.mina.core.session.IdleStatus;
  12 +import org.apache.mina.core.session.IoSession;
  13 +import org.apache.mina.core.session.IoSessionConfig;
  14 +import org.apache.mina.filter.codec.ProtocolCodecFilter;
  15 +import org.apache.mina.filter.logging.LogLevel;
  16 +import org.apache.mina.filter.logging.LoggingFilter;
  17 +import org.apache.mina.transport.socket.nio.NioSocketConnector;
  18 +import org.slf4j.Logger;
  19 +import org.slf4j.LoggerFactory;
  20 +import org.springframework.beans.factory.annotation.Autowired;
  21 +import org.springframework.stereotype.Component;
  22 +
  23 +import java.net.InetSocketAddress;
  24 +import java.util.concurrent.*;
  25 +
  26 +/**
  27 + * Created by panzhao on 2017/5/4.
  28 + */
  29 +@Component
  30 +public class ClientApp {
  31 +
  32 + private static NioSocketConnector pdDataConnector;
  33 + private static NioSocketConnector pfDataConnector;
  34 +
  35 + @Autowired
  36 + private PdClientHandler pdClient;
  37 + @Autowired
  38 + private PfClientHandler pfClient;
  39 + @Autowired
  40 + GpsBeforeBuffer gpsBeforeBuffer;
  41 +
  42 + static Logger logger = LoggerFactory.getLogger(ClientApp.class);
  43 + private static ExecutorService exec;
  44 +
  45 + private ScheduledExecutorService sexec;
  46 +
  47 + public static boolean dconnect(String device) {
  48 + boolean flag = false;
  49 + try {
  50 + ConnectFuture con = pdDataConnector.connect(new InetSocketAddress(ConfigUtil.get("gps.server.pd"), Integer.parseInt(ConfigUtil.get("gps.port.pd"))));
  51 + con.awaitUninterruptibly();
  52 + IoSession session = con.getSession();
  53 + session.setAttribute("deviceId", device);
  54 + com.bsth.data.gpsdata.client.pd.protocol.PdMessage msg = new com.bsth.data.gpsdata.client.pd.protocol.PdMessage();
  55 + Pd_31_0 body = new Pd_31_0();
  56 + body.setFunCode((short)0x15);
  57 + body.setLineId(0);
  58 + body.setDeviceId(device);
  59 + msg.setMessageBody(body);
  60 + msg.setVersion((short)1);
  61 + msg.setSerialNo((short)1);
  62 + msg.setCommandType((short)0x31);
  63 + byte[] bytes = msg.write();
  64 + WriteFuture write = session.write(bytes);
  65 + write.awaitUninterruptibly();
  66 + flag = true;
  67 +
  68 + logger.info("dconnect...");
  69 + pdSession = session;
  70 + //SessionManager.getInstance().register(device, session);
  71 + } catch (Exception e) {
  72 + e.printStackTrace();
  73 + }
  74 + return flag;
  75 + }
  76 +
  77 + public static void pdconnect(final String device) {
  78 + exec.submit(new Runnable() {
  79 +
  80 + @Override
  81 + public void run() {
  82 + // TODO Auto-generated method stub
  83 + long now = System.currentTimeMillis();
  84 + boolean flag = false;
  85 + while (!flag) {
  86 + flag = dconnect(device);
  87 + }
  88 + System.out.println("设备编号:" + device + "重连, cost time: " + (System.currentTimeMillis() - now));
  89 + }
  90 + });
  91 + }
  92 +
  93 + public static void pfconnect(final String device) {
  94 + exec.submit(new Runnable() {
  95 +
  96 + @Override
  97 + public void run() {
  98 + // TODO Auto-generated method stub
  99 + long now = System.currentTimeMillis();
  100 + boolean flag = false;
  101 + while (!flag) {
  102 + flag = fconnect(device);
  103 + }
  104 + System.out.println("重连, cost time: " + (System.currentTimeMillis() - now));
  105 + }
  106 + });
  107 + }
  108 +
  109 + public static void pdreconn(){
  110 + pdconnect(ConfigUtil.get("forward.device.name"));
  111 + }
  112 +
  113 + public static void pfreconn(){
  114 + pfconnect(ConfigUtil.get("forward.device.name"));
  115 + }
  116 +
  117 + public void destroy(){
  118 + try {
  119 + logger.warn("socket client destroy!!!");
  120 + exec.shutdownNow();
  121 + sexec.shutdownNow();
  122 +
  123 + pdDataConnector.dispose(true);
  124 + pfDataConnector.dispose(true);
  125 + } catch (Exception e) {
  126 + logger.error("", e);
  127 + }
  128 + }
  129 +
  130 +
  131 + public static void pdClose(){
  132 + pdSession.closeNow();
  133 + }
  134 +
  135 + public static void pfClose(){
  136 + pfSession.closeNow();
  137 + }
  138 +
  139 + public static boolean fconnect(String device) {
  140 + boolean flag = false;
  141 + try {
  142 + ConnectFuture con = pfDataConnector.connect(new InetSocketAddress(ConfigUtil.get("gps.server.pf"), Integer.parseInt(ConfigUtil.get("gps.port.pf"))));
  143 + con.awaitUninterruptibly();
  144 + IoSession session = con.getSession();
  145 + session.setAttribute("deviceId", device);
  146 + flag = true;
  147 +
  148 + logger.info("fconnect...");
  149 + pfSession = session;
  150 + } catch (Exception e) {
  151 + e.printStackTrace();
  152 + }
  153 + return flag;
  154 + }
  155 +
  156 + public void init() {
  157 + logger.warn("socket client init...");
  158 + exec = Executors.newFixedThreadPool(50);
  159 + sexec = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
  160 + @Override
  161 + public Thread newThread(Runnable r) {
  162 + // TODO Auto-generated method stub
  163 + Thread t = new Thread(r);
  164 + t.setName("SessionCheckExecutor");
  165 + return t;
  166 + }
  167 + });
  168 + sexec.scheduleAtFixedRate(new SessionChecker(), 1, 1, TimeUnit.MINUTES);
  169 + /*******************************浦东********************************/
  170 + pdDataConnector = new NioSocketConnector();
  171 +
  172 + LoggingFilter log = new LoggingFilter();
  173 + log.setMessageReceivedLogLevel(LogLevel.DEBUG);
  174 + pdDataConnector.getFilterChain().addLast("logger", log);
  175 +
  176 + pdDataConnector.getFilterChain().addLast("codec",
  177 + new ProtocolCodecFilter(new PdMessageCodecFactory()));
  178 +
  179 + IoSessionConfig config = pdDataConnector.getSessionConfig();
  180 +
  181 + config.setReadBufferSize(4096);
  182 + config.setWriteTimeout(10000);
  183 + config.setWriterIdleTime(60000);
  184 +
  185 + config.setIdleTime(IdleStatus.BOTH_IDLE, 60);
  186 +
  187 + pdDataConnector.setHandler(pdClient);
  188 +
  189 + pdconnect(ConfigUtil.get("forward.device.name"));
  190 + /*******************************浦东转发********************************/
  191 + pfDataConnector = new NioSocketConnector();
  192 +
  193 + LoggingFilter log1 = new LoggingFilter();
  194 + log1.setMessageReceivedLogLevel(LogLevel.DEBUG);
  195 + pfDataConnector.getFilterChain().addLast("logger", log1);
  196 +
  197 + pfDataConnector.getFilterChain().addLast("codec",
  198 + new ProtocolCodecFilter(new PfMessageCodecFactory()));
  199 +
  200 + IoSessionConfig config1 = pfDataConnector.getSessionConfig();
  201 +
  202 + config1.setReadBufferSize(4096);
  203 + config1.setWriteTimeout(10000);
  204 + config1.setWriterIdleTime(60000);
  205 +
  206 + config1.setIdleTime(IdleStatus.BOTH_IDLE, 60);
  207 +
  208 + pfDataConnector.setHandler(pfClient);
  209 + pfconnect(ConfigUtil.get("forward.device.name"));
  210 + }
  211 +
  212 +
  213 + static IoSession pdSession;
  214 + static IoSession pfSession;
  215 + final class SessionChecker implements Runnable {
  216 +
  217 + @Override
  218 + public void run() {
  219 + // TODO Auto-generated method stub
  220 + try {
  221 +
  222 + if(!pdSession.isActive()){
  223 + logger.warn("浦东设备注销");
  224 + ClientApp.pdreconn();
  225 + }
  226 +
  227 + if(!pfSession.isActive()){
  228 + logger.warn("浦东转发设备注销");
  229 + ClientApp.pfreconn();
  230 + }
  231 + } catch (Exception e) {
  232 + logger.error("SessionChecker异常", e);
  233 + }
  234 + }
  235 + }
  236 +}
0 237 \ No newline at end of file
... ...
src/main/java/com/bsth/client/GpsBeforeBuffer.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/GpsBeforeBuffer.java
  1 +package com.bsth.client;
  2 +
  3 +import com.bsth.Application;
  4 +import com.bsth.data.BasicData;
  5 +import com.bsth.data.gpsdata.GpsEntity;
  6 +import com.bsth.data.gpsdata.arrival.GpsRealAnalyse;
  7 +import com.bsth.data.gpsdata.client.pd.protocol.BasicInfo;
  8 +import org.apache.commons.lang3.StringUtils;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.stereotype.Component;
  13 +
  14 +import java.util.ArrayList;
  15 +import java.util.LinkedList;
  16 +import java.util.List;
  17 +import java.util.concurrent.TimeUnit;
  18 +
  19 +/**
  20 + * 从 socket client 到 .. 的缓冲
  21 + * Created by panzhao on 2017/5/4.
  22 + */
  23 +@Component
  24 +public class GpsBeforeBuffer {
  25 +
  26 + static LinkedList<GpsEntity> linkedList = new LinkedList<>();
  27 +
  28 + @Autowired
  29 + GpsHandleThread gpsHandleThread;
  30 +
  31 + public void put(BasicInfo basicInfo){
  32 + //放弃补发数据
  33 + byte cacheData = getCacheState(basicInfo.getServiceState());
  34 + if(cacheData == 1)
  35 + return;
  36 + GpsEntity gps = new GpsEntity();
  37 +
  38 + gps.setDeviceId(basicInfo.getDeviceId());
  39 + gps.setTimestamp(basicInfo.getTimestamp());
  40 + gps.setLat(basicInfo.getLat());
  41 + gps.setLon(basicInfo.getLon());
  42 + gps.setDirection((float)basicInfo.getDirection() / 10);
  43 + gps.setValid(basicInfo.getGpsValid());
  44 + gps.setCompanyCode(basicInfo.getCompanyCode());
  45 + gps.setStopNo(basicInfo.getStopNo());
  46 + gps.setUpDown(basicInfo.getUpOrDown());
  47 + gps.setSpeed((float)basicInfo.getSpeedGps() / 10);
  48 + gps.setLineId(String.valueOf(basicInfo.getLineId()));
  49 + gps.setState((int) getService(basicInfo.getServiceState()));
  50 + //没有设备号
  51 + if (StringUtils.isBlank(gps.getDeviceId()))
  52 + return;
  53 +
  54 + String nbbm = BasicData.deviceId2NbbmMap.get(gps.getDeviceId());
  55 + if (StringUtils.isBlank(nbbm))
  56 + gps.setIncomplete(true);
  57 + else
  58 + gps.setNbbm(nbbm);
  59 +
  60 + linkedList.addLast(gps);
  61 + }
  62 +
  63 + public byte getCacheState(long serviceState) {
  64 + return (byte)(((serviceState & 0x00100000) == 0x00100000) ? 1 : 0);
  65 + }
  66 +
  67 + public void init(){
  68 + Application.mainServices.scheduleWithFixedDelay(gpsHandleThread, 20 * 1000, 500, TimeUnit.MILLISECONDS);
  69 + }
  70 +
  71 + static int idleCount = 0;
  72 + @Component
  73 + public static class GpsHandleThread extends Thread{
  74 +
  75 + List<GpsEntity> list;
  76 +
  77 + @Autowired
  78 + GpsRealAnalyse gpsRealAnalyse;
  79 +
  80 + @Autowired
  81 + ClientApp clientApp;
  82 +
  83 + Logger log = LoggerFactory.getLogger(this.getClass());
  84 +
  85 + @Override
  86 + public void run() {
  87 + list = new ArrayList<>(200);
  88 +
  89 + GpsEntity gps;
  90 + for(int i = 0; i < 4000; i ++){
  91 + gps = linkedList.poll();
  92 + if(gps == null)
  93 + break;
  94 + list.add(gps);
  95 + }
  96 +
  97 + if(list.size() == 0){
  98 + idleCount ++;
  99 + //连续40次没有数据,重建socket连接
  100 + if(idleCount == 40){
  101 + log.info("idleCount == 40");
  102 + idleCount = 0;
  103 + clientApp.destroy();
  104 + clientApp.init();
  105 + }
  106 + }
  107 + gpsRealAnalyse.analyse(list);
  108 + }
  109 + }
  110 +
  111 + /**
  112 + * 获取运营状态
  113 + *
  114 + * @return -1无效 0运营 1未运营
  115 + */
  116 + public static byte getService(long serviceState) {
  117 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000)
  118 + return -1;
  119 + return (byte) (((serviceState & 0x02000000) == 0x02000000) ? 1 : 0);
  120 + }
  121 +}
0 122 \ No newline at end of file
... ...
src/main/java/com/bsth/client/common/ExceptionUtil.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/common/ExceptionUtil.java
  1 +package com.bsth.client.common;
  2 +
  3 +public class ExceptionUtil {
  4 +
  5 + public static String getTrace(Throwable e) {
  6 + StringBuilder sb = new StringBuilder();
  7 + sb.append(e.toString());
  8 + for (StackTraceElement ste : e.getStackTrace()) {
  9 + sb.append(ste).append("\r\n");
  10 + }
  11 + return sb.toString();
  12 + }
  13 +}
... ...
src/main/java/com/bsth/client/common/Protocol2BizUtil.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/common/Protocol2BizUtil.java
  1 +package com.bsth.client.common;
  2 +
  3 +//import com.bsth.data.gpsdata.socket_client_001.pd.protocol.BasicInfo;
  4 +//import com.bsth.data.gpsdata.socket_client_001.pf.protocol.PfMessage;
  5 +//import com.bsth.data.gpsdata.socket_client_001.pf.protocol.Pf_1_0;
  6 +
  7 +import com.bsth.data.gpsdata.client.pd.protocol.BasicInfo;
  8 +import com.bsth.data.gpsdata.client.pf.protocol.PfMessage;
  9 +import com.bsth.data.gpsdata.client.pf.protocol.Pf_1_0;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +
  13 +public class Protocol2BizUtil {
  14 +
  15 + private final static Logger log = LoggerFactory.getLogger(Protocol2BizUtil.class);
  16 +
  17 + /**
  18 + * 从协议数据中获得基本数据
  19 + */
  20 + public static BasicInfo getBasicInfoFromMsg(PfMessage msg) {
  21 + if (msg == null) return null;
  22 + BasicInfo info = null;
  23 + if (msg.getCommandType() == 0x01) {
  24 + Pf_1_0 pf_1_0 = (Pf_1_0)msg.getMessageBody();
  25 + info = new BasicInfo();
  26 + info.setLineId(pf_1_0.getXldm());
  27 + info.setDeviceId(pf_1_0.getMtd());
  28 + info.setDriverEmpNo(Integer.parseInt(pf_1_0.getDriver().trim()));
  29 + info.setCarparkNo(pf_1_0.getTccbh());
  30 + info.setStopNo(pf_1_0.getZdbh());
  31 + double lon = pf_1_0.getLon()/1000000, lat = pf_1_0.getLat()/1000000;
  32 + info.setCarLon(((long)lon) * 1000000 + (long)((lon - (long)lon) * 600000));
  33 + info.setCarLat(((int)lat) * 1000000 + (int)((lat - (int)lat) * 600000));
  34 + info.setTimestamp(pf_1_0.getFssj().getTime());
  35 + info.setSpeedGps((short)pf_1_0.getSpeed());
  36 + info.setSpeedSensor((short)(pf_1_0.getSpeed()));
  37 + info.setDirection((short)(pf_1_0.getFx()));
  38 + info.setServiceState(0);
  39 + info.setService(pf_1_0.getYyzt() == 0 ? true : false);
  40 + info.setUpOrDown(pf_1_0.getSxxzt() == 0 ? true : false);
  41 +
  42 + info.setLon(Float.parseFloat(String.valueOf(lon)));
  43 + info.setLat(Float.parseFloat(String.valueOf(lat)));
  44 + }
  45 +
  46 + return info;
  47 + }
  48 +}
... ...
src/main/java/com/bsth/client/common/ThreadLocalDateUtil.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/common/ThreadLocalDateUtil.java
  1 +package com.bsth.client.common;
  2 +
  3 +import java.text.DateFormat;
  4 +import java.text.ParseException;
  5 +import java.text.SimpleDateFormat;
  6 +import java.util.Date;
  7 +
  8 +public class ThreadLocalDateUtil {
  9 + private static final String date_format = "yyyyMMddHHmmss";
  10 + private static ThreadLocal<DateFormat> threadLocal = new ThreadLocal<DateFormat>();
  11 +
  12 + public static DateFormat getDateFormat()
  13 + {
  14 + DateFormat df = threadLocal.get();
  15 + if(df==null){
  16 + df = new SimpleDateFormat(date_format);
  17 + threadLocal.set(df);
  18 + }
  19 + return df;
  20 + }
  21 +
  22 + public static String formatDate(Date date) throws ParseException {
  23 + return getDateFormat().format(date);
  24 + }
  25 +
  26 + public static Date parse(String strDate) throws ParseException {
  27 + return getDateFormat().parse(strDate);
  28 + }
  29 +}
... ...
src/main/java/com/bsth/client/msg/IMessage.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/msg/IMessage.java
  1 +package com.bsth.client.msg;
  2 +
  3 +public interface IMessage extends IMessageIO {
  4 +
  5 + public IMessageBody getMessageBody();
  6 +}
... ...
src/main/java/com/bsth/client/msg/IMessageBody.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/msg/IMessageBody.java
  1 +package com.bsth.client.msg;
  2 +
  3 +public interface IMessageBody extends IMessageIO {
  4 +
  5 + public String getDeviceId();
  6 +
  7 + public long getTimestamp();
  8 +}
... ...
src/main/java/com/bsth/client/msg/IMessageIO.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/msg/IMessageIO.java
  1 +package com.bsth.client.msg;
  2 +
  3 +public interface IMessageIO {
  4 +
  5 + public void read(byte[] bytes);
  6 +
  7 + public byte[] write();
  8 +}
... ...
src/main/java/com/bsth/client/pd/codec/MessageDecoder.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pd/codec/MessageDecoder.java
  1 +package com.bsth.client.pd.codec;
  2 +
  3 +import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
  4 +import com.bsth.data.gpsdata.client.pd.protocol.PdMessage;
  5 +import org.apache.mina.core.buffer.IoBuffer;
  6 +import org.apache.mina.core.session.IoSession;
  7 +import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
  8 +import org.apache.mina.filter.codec.ProtocolDecoderOutput;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +
  12 +
  13 +public class MessageDecoder extends CumulativeProtocolDecoder {
  14 +
  15 + Logger log = LoggerFactory.getLogger(MessageDecoder.class);
  16 +
  17 + @Override
  18 + protected boolean doDecode(IoSession session, IoBuffer in,
  19 + ProtocolDecoderOutput out) throws Exception {
  20 + // TODO Auto-generated method stub
  21 + while (in.remaining() > 3) {
  22 + in.mark();
  23 + byte head1 = in.get(), head2 = in.get(), lenh = in.get(), lenl = in.get();
  24 + int len = ((lenh & 0xff) << 8) + (lenl & 0xff);
  25 + if ((head1 & 0xff) == 0xfa && (head2 & 0xff) == 0xf5) {
  26 + if (in.remaining() > len) {
  27 + try {
  28 + byte[] bytes = new byte[len + 1];
  29 + in.get(bytes);
  30 + PdMessage msg = new PdMessage();
  31 + msg.read(bytes);
  32 + out.write(msg);
  33 +
  34 + //日志纪录
  35 + log.info("pd client receive: " + ConvertUtil.bytesToHexString(bytes));
  36 + }catch (Exception e){
  37 + log.error("pd message decoder:", e);
  38 + }
  39 + } else {
  40 + in.reset();
  41 + return false;
  42 + }
  43 + }
  44 + }
  45 + return false;
  46 + }
  47 +
  48 + /*private static String toHexString(byte[] bytes) {
  49 + StringBuilder sb = new StringBuilder();
  50 + for (byte b : bytes) {
  51 + sb.append(Integer.toHexString(b & 0xff) + "|");
  52 + }
  53 + return sb.toString();
  54 + }*/
  55 +}
... ...
src/main/java/com/bsth/client/pd/codec/MessageEncoder.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pd/codec/MessageEncoder.java
  1 +package com.bsth.client.pd.codec;
  2 +
  3 +import org.apache.mina.core.buffer.IoBuffer;
  4 +import org.apache.mina.core.session.IoSession;
  5 +import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
  6 +import org.apache.mina.filter.codec.ProtocolEncoderOutput;
  7 +
  8 +
  9 +public class MessageEncoder extends ProtocolEncoderAdapter {
  10 +
  11 + @Override
  12 + public void encode(IoSession session, Object message,
  13 + ProtocolEncoderOutput out) throws Exception {
  14 + // TODO Auto-generated method stub
  15 + IoBuffer buf = IoBuffer.allocate(1024).setAutoExpand(true);
  16 + buf.put((byte[])message);
  17 + buf.flip();
  18 + out.write(buf);
  19 + /*if ("true".equals(ConfigUtil.getProperty("protocoldown", "true"))) {
  20 + DownProtocolDataService.getInstance().write((byte[])message);
  21 + }*/
  22 + }
  23 +
  24 +}
... ...
src/main/java/com/bsth/client/pd/codec/PdMessageCodecFactory.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pd/codec/PdMessageCodecFactory.java
  1 +package com.bsth.client.pd.codec;
  2 +
  3 +import org.apache.mina.core.session.IoSession;
  4 +import org.apache.mina.filter.codec.ProtocolCodecFactory;
  5 +import org.apache.mina.filter.codec.ProtocolDecoder;
  6 +import org.apache.mina.filter.codec.ProtocolEncoder;
  7 +
  8 +public class PdMessageCodecFactory implements ProtocolCodecFactory {
  9 +
  10 + private ProtocolEncoder encoder;
  11 + private ProtocolDecoder decoder;
  12 +
  13 + public PdMessageCodecFactory() {
  14 + encoder = new MessageEncoder();
  15 + decoder = new MessageDecoder();
  16 + }
  17 +
  18 + @Override
  19 + public ProtocolEncoder getEncoder(IoSession session) throws Exception {
  20 + // TODO Auto-generated method stub
  21 + return encoder;
  22 + }
  23 +
  24 + @Override
  25 + public ProtocolDecoder getDecoder(IoSession session) throws Exception {
  26 + // TODO Auto-generated method stub
  27 + return decoder;
  28 + }
  29 +
  30 +}
... ...
src/main/java/com/bsth/client/pd/common/ConvertUtil.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pd/common/ConvertUtil.java
  1 +package com.bsth.client.pd.common;
  2 +
  3 +import com.bsth.data.gpsdata.client.common.ThreadLocalDateUtil;
  4 +import org.slf4j.Logger;
  5 +import org.slf4j.LoggerFactory;
  6 +
  7 +import java.text.ParseException;
  8 +import java.util.Arrays;
  9 +import java.util.Calendar;
  10 +import java.util.Date;
  11 +
  12 +
  13 +public class ConvertUtil {
  14 +
  15 + private final static Logger log = LoggerFactory.getLogger(ConvertUtil.class);
  16 +
  17 + public static int bcd2int(byte[] bytes, int start, int len) {
  18 + if (len > 4 || len == 0)
  19 + throw new IllegalArgumentException("bcd2int 字节数不符合要求");
  20 + String temp = "";
  21 + for (int i = 0;i < len;i++) {
  22 + int val = bytes[start + i] & 0xff;
  23 + if (val < 10) temp += 0;
  24 + temp += Integer.toHexString(val);
  25 + }
  26 + return Integer.parseInt(temp);
  27 + }
  28 +
  29 + public static byte[] int2bcd(int val, int len) {
  30 + if (len > 4 || len == 0)
  31 + throw new IllegalArgumentException("int2bcd 字节数不符合要求");
  32 + byte[] result = new byte[len];
  33 + for (int i = len - 1;i > -1;i--) {
  34 + result[i] = (byte)Integer.parseInt(val%100 + "", 16);
  35 + val = val/100;
  36 + }
  37 + return result;
  38 + }
  39 +
  40 + public static long bcd2long(byte[] bytes, int start, int len) {
  41 + if (len > 8 || len == 0)
  42 + throw new IllegalArgumentException("bcd2long 字节数不符合要求");
  43 + String temp = "";
  44 + for (int i = 0;i < len;i++) {
  45 + int val = bytes[start + i] & 0xff;
  46 + if (val < 10) temp += 0;
  47 + temp += Integer.toHexString(val);
  48 + }
  49 + return Long.parseLong(temp);
  50 + }
  51 +
  52 + public static byte[] long2bcd(long val, int len) {
  53 + if (len > 8 || len == 0)
  54 + throw new IllegalArgumentException("long2bcd 字节数不符合要求");
  55 + byte[] result = new byte[len];
  56 + for (int i = len - 1;i > -1;i--) {
  57 + result[i] = (byte)Integer.parseInt(val%100 + "", 16);
  58 + val = val/100;
  59 + }
  60 + return result;
  61 + }
  62 +
  63 + public static String ascii2string(byte[] bytes, int start, int len) {
  64 + return new String(Arrays.copyOfRange(bytes, start, start + len));
  65 + }
  66 +
  67 + public static byte[] string2ascii(String val, int len) {
  68 + byte[] result = new byte[len];
  69 + byte[] bytes = val.getBytes();
  70 + if (bytes.length > len && len != 0)
  71 + throw new IllegalArgumentException("string2ascii 参数不符合要求");
  72 + if (len != 0)
  73 + for (int i = 0, l = bytes.length;i < l;i++) result[i] = bytes[i];
  74 + else return bytes;
  75 + return result;
  76 + }
  77 +
  78 + public static long bcd2timestamp(byte[] bytes, int start) {
  79 + String temp = "20";
  80 + for (int i = 0;i < 6;i++) {
  81 + int val = bytes[start + i] & 0xff;
  82 + if (val < 10) temp += 0;
  83 + temp += Integer.toHexString(val);
  84 + }
  85 + Date date = null;
  86 + try {
  87 + date = ThreadLocalDateUtil.parse(temp);
  88 + } catch (ParseException e) {
  89 + log.error("协议中时间数据异常:" + temp);
  90 + }
  91 + if (date != null) return date.getTime();
  92 + return -1;
  93 + }
  94 +
  95 + public static byte[] timestamp2bcd(long val) {
  96 + byte[] result = new byte[6];
  97 + Calendar c = Calendar.getInstance();
  98 + c.setTime(new Date(val));
  99 + result[0] = (byte)(Integer.parseInt(c.get(Calendar.YEAR)%100 + "", 16));
  100 + result[1] = (byte)(Integer.parseInt(c.get(Calendar.MONTH) + 1 + "", 16));
  101 + result[2] = (byte)Integer.parseInt(c.get(Calendar.DAY_OF_MONTH) + "", 16);
  102 + result[3] = (byte)Integer.parseInt(c.get(Calendar.HOUR_OF_DAY) + "", 16);
  103 + result[4] = (byte)Integer.parseInt(c.get(Calendar.MINUTE) + "", 16);
  104 + result[5] = (byte)Integer.parseInt(c.get(Calendar.SECOND) + "", 16);
  105 + return result;
  106 + }
  107 +
  108 + public static byte[] int2hex(int val, int len) {
  109 + if (len < 1)
  110 + throw new IllegalArgumentException("int2hex len 参数不符合要求");
  111 + byte[] result = new byte[len];
  112 + for (int i = 0;i < len;i++) {
  113 + result[len - 1 - i] = (byte)(val%100);
  114 + val = val/100;
  115 + }
  116 +
  117 + return result;
  118 + }
  119 +
  120 + public static int bytes2int(byte[] bytes, int start, int len) {
  121 + int val = 0;
  122 + for (int i = 0; i < len; i++) {
  123 + int shift = (len - 1 - i) * 8;
  124 + val += (bytes[start + i] & 0x0000FF) << shift;
  125 + }
  126 +
  127 + return val;
  128 + }
  129 +
  130 + /* Convert byte[] to hex string.这里我们可以将byte转换成int,然后利用Integer.toHexString(int)来转换成16进制字符串。
  131 + * @param src byte[] data
  132 +* @return hex string
  133 +*/
  134 + public static String bytesToHexString(byte[] src){
  135 + StringBuilder stringBuilder = new StringBuilder("");
  136 + if (src == null || src.length <= 0) {
  137 + return null;
  138 + }
  139 + for (int i = 0; i < src.length; i++) {
  140 + int v = src[i] & 0xFF;
  141 + String hv = Integer.toHexString(v);
  142 + if (hv.length() < 2) {
  143 + stringBuilder.append(0);
  144 + }
  145 + stringBuilder.append(hv);
  146 + }
  147 + return stringBuilder.toString();
  148 + }
  149 +}
... ...
src/main/java/com/bsth/client/pd/handler/PdClientHandler.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pd/handler/PdClientHandler.java
  1 +package com.bsth.client.pd.handler;
  2 +
  3 +import com.bsth.data.gpsdata.client.GpsBeforeBuffer;
  4 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  5 +import com.bsth.data.gpsdata.client.pd.protocol.PdMessage;
  6 +import com.bsth.data.gpsdata.client.pd.protocol.Pd_41_0;
  7 +import com.bsth.data.gpsdata.client.pd.protocol.Pd_42_0;
  8 +import org.apache.mina.core.service.IoHandlerAdapter;
  9 +import org.apache.mina.core.session.IdleStatus;
  10 +import org.apache.mina.core.session.IoSession;
  11 +import org.apache.mina.transport.socket.SocketSessionConfig;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.stereotype.Service;
  16 +
  17 +import java.io.IOException;
  18 +
  19 +
  20 +@Service
  21 +public class PdClientHandler extends IoHandlerAdapter{
  22 +
  23 + private final static Logger log = LoggerFactory.getLogger(PdClientHandler.class);
  24 +
  25 + @Autowired
  26 + GpsBeforeBuffer gpsBeforeBuffer;
  27 +
  28 + @Override
  29 + public void sessionCreated(IoSession session) throws Exception {
  30 + SocketSessionConfig cfg = (SocketSessionConfig) session.getConfig();
  31 + cfg.setSoLinger(0);
  32 + }
  33 +
  34 + @Override
  35 + public void sessionOpened(IoSession session) throws Exception {
  36 +
  37 + }
  38 +
  39 + @Override
  40 + public void sessionClosed(IoSession session) throws Exception {
  41 + String deviceId = (String)session.getAttribute("deviceId");
  42 + if (deviceId != null) {
  43 + //SessionManager.getInstance().unregister(deviceId);
  44 + log.info("连网关设备编号:" + deviceId + "断开连接");
  45 + log.warn(deviceId + "网关设备注销");
  46 +
  47 + //ClientApp.dconnect(deviceId);
  48 + } else {
  49 + log.info("连网关设备编号:" + deviceId + "断开连接");
  50 + }
  51 + }
  52 +
  53 + @Override
  54 + public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
  55 + log.warn("pd sessionIdle");
  56 + session.closeNow();
  57 + }
  58 +
  59 + @Override
  60 + public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
  61 + if (cause instanceof IOException) session.closeNow();
  62 + log.error("PdClientHandler异常:", cause);
  63 + }
  64 +
  65 + @Override
  66 + public void messageReceived(IoSession session, Object message) throws Exception {
  67 + PdMessage msg = (PdMessage)message;
  68 + IMessageBody body = msg.getMessageBody();
  69 + if (body != null) {
  70 + //String deviceId = body.getDeviceId();
  71 + if (0x31 == msg.getCommandType()) {
  72 + //IoSession regSession = SessionManager.getInstance().getSession(deviceId);
  73 + //if (regSession != null) regSession.closeNow();
  74 + //SessionManager.getInstance().register(deviceId, session);
  75 + log.debug("设备编号:" + body.getDeviceId() + "建立连接");
  76 + }
  77 + else if(0x41 == msg.getCommandType()){
  78 + Pd_41_0 pd41 = (Pd_41_0)msg.getMessageBody();
  79 + gpsBeforeBuffer.put(pd41.getInfo());
  80 + }
  81 + else if(0x42 == msg.getCommandType()){
  82 + Pd_42_0 pd42 = (Pd_42_0)msg.getMessageBody();
  83 + gpsBeforeBuffer.put(pd42.getInfo());
  84 + }
  85 + }
  86 + }
  87 +
  88 + @Override
  89 + public void messageSent(IoSession session, Object message) throws Exception {
  90 +
  91 + }
  92 +}
... ...
src/main/java/com/bsth/client/pd/protocol/BasicInfo.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pd/protocol/BasicInfo.java
  1 +package com.bsth.client.pd.protocol;
  2 +
  3 +
  4 +import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
  5 +
  6 +import java.nio.ByteBuffer;
  7 +import java.util.Date;
  8 +
  9 +
  10 +public class BasicInfo {
  11 +
  12 + private int cityCode;
  13 + private short industryCode;
  14 + private short companyCode;
  15 + private String deviceId;
  16 + private int lineId;
  17 + private int driverEmpNo;
  18 + private short carparkSerialNo;
  19 + private String carparkNo;
  20 + private short stopSerialNo;
  21 + private String stopNo;
  22 + // 经度 bcd 5 0121245333表示经度为121度24.5333分
  23 + private long carLon;
  24 + // 维度
  25 + private int carLat;
  26 + private long timestamp;
  27 + // 速度(传感器)bcd 2 保留一位小数 km/h
  28 + private short speedSensor;
  29 + // 速度(gps)bcd 2 保留一位小数 km/h
  30 + private short speedGps;
  31 + // 方向 bcd 2 0-359.5 保留一位小数
  32 + private short direction;
  33 + // 车内温度 bcd 2 第一字节为符号 00为正 01为负 后一字节为温度
  34 + private short inTemp;
  35 + // 营运状态 hex 4高位在前
  36 + // 第一字节位 7 GPS有/无效|6 场外/内|5 起终点站外/内|4 上/下行|3 已知/未知|2站外/站内|1 营运/非营运|0 在线路上/不在
  37 + // 7=1时其它位无效|0=1时3,4,5无效 第二字节6,7无效|3=1时2,4无效 第二字节6,7无效
  38 + // 第二字节位 7 非/标杆点|6 非/中途校时点|5 点/熄火|4 实时/缓存数据|3 门开/关|2 预留|1 非/包车|0预留
  39 + // 1=1时 第一字节0-6无效 6,7无效
  40 + // 后两个字节保留
  41 + private long serviceState;
  42 + // 调控状态
  43 + private long controlState;
  44 + // 累计里程 km 保留两位小数
  45 + private int totalMiles;
  46 + // 水温
  47 + private byte waterTemp;
  48 + // 油耗 (第一个字节 + 第二个字节/10)升/百公里
  49 + private int oilConsumption;
  50 + // 发动机转速 100转/秒
  51 + private int engineSpeed;
  52 + private float lon;
  53 + private float lat;
  54 +
  55 + private boolean inOutStopFlag = false;
  56 +
  57 + public void read(byte[] bytes, int idx) {
  58 + // TODO Auto-generated method stub
  59 + ByteBuffer buf = ByteBuffer.wrap(bytes);
  60 + cityCode = ConvertUtil.bcd2int(bytes, idx, 3); idx += 3;
  61 + industryCode = (short)(bytes[idx] & 0xff); idx++;
  62 + companyCode = (short)(bytes[idx] & 0xff); idx++;
  63 + deviceId = ConvertUtil.ascii2string(bytes, idx, 8); idx += 8;
  64 + lineId = ConvertUtil.bcd2int(bytes, idx, 3); idx += 3;
  65 + driverEmpNo = ConvertUtil.bcd2int(bytes, idx, 4); idx +=4;
  66 + carparkSerialNo = (short)(bytes[idx] & 0xff); idx++;
  67 + carparkNo = ConvertUtil.ascii2string(bytes, idx, 8); idx += 8;
  68 + stopSerialNo = (short)(bytes[idx] & 0xff); idx++;
  69 + stopNo = ConvertUtil.ascii2string(bytes, idx, 8).trim(); idx += 8;
  70 + carLon = ConvertUtil.bcd2long(bytes, idx, 5); lon = (int)(carLon/1000000) + carLon%1000000/600000f; idx += 5;
  71 + carLat = ConvertUtil.bcd2int(bytes, idx, 4); lat = carLat/1000000 + carLat%1000000/600000f; idx += 4;
  72 + timestamp = ConvertUtil.bcd2timestamp(bytes, idx); idx += 6;
  73 + speedSensor = (short)ConvertUtil.bcd2int(bytes, idx, 2); idx += 2;
  74 + speedGps = (short)ConvertUtil.bcd2int(bytes, idx, 2); idx += 2;
  75 + direction = (short)(ConvertUtil.bcd2int(bytes, idx, 2)); idx += 2;
  76 + inTemp = (short)ConvertUtil.bcd2int(bytes, idx, 2); idx += 2;
  77 + serviceState = buf.getInt(idx) & 0xffffffff; idx += 4;
  78 + controlState = buf.getInt(idx) & 0xffffffff; idx += 4;
  79 + totalMiles = ConvertUtil.bcd2int(bytes, idx, 4); idx += 4;
  80 + waterTemp = bytes[idx]; idx++;
  81 + oilConsumption = ConvertUtil.bcd2int(bytes, idx, 4); idx += 4;
  82 + engineSpeed = buf.getShort(idx) & 0xffff; idx += 2;
  83 + }
  84 +
  85 + public byte[] write() {
  86 + ByteBuffer buf = ByteBuffer.allocate(80);
  87 + buf.put(ConvertUtil.int2bcd(cityCode, 3));
  88 + buf.put((byte)industryCode);
  89 + buf.put((byte)companyCode);
  90 + buf.put(ConvertUtil.string2ascii(deviceId, 8));
  91 + buf.put(ConvertUtil.int2bcd(lineId, 3));
  92 + buf.put(ConvertUtil.int2bcd(driverEmpNo, 4));
  93 + buf.put((byte)carparkSerialNo);
  94 + buf.put(ConvertUtil.string2ascii(carparkNo, 8));
  95 + buf.put((byte)stopSerialNo);
  96 + buf.put(ConvertUtil.string2ascii(stopNo, 8));
  97 + buf.put(ConvertUtil.long2bcd(carLon, 5));
  98 + buf.put(ConvertUtil.long2bcd(carLat, 4));
  99 + buf.put(ConvertUtil.timestamp2bcd(timestamp));
  100 + buf.put(ConvertUtil.int2bcd(speedSensor, 2));
  101 + buf.put(ConvertUtil.int2bcd(speedGps, 2));
  102 + buf.put(ConvertUtil.int2bcd(direction, 2));
  103 + buf.put(ConvertUtil.int2bcd(inTemp, 2));
  104 + buf.putInt((int)serviceState);
  105 + buf.putInt((int)controlState);
  106 + buf.put(ConvertUtil.int2bcd(totalMiles, 4));
  107 + buf.put(waterTemp);
  108 + buf.put(ConvertUtil.int2bcd(oilConsumption, 2));
  109 + buf.putShort((short)engineSpeed);
  110 +
  111 + return buf.array();
  112 + }
  113 +
  114 + public String getDeviceId() {
  115 + // TODO Auto-generated method stub
  116 + return deviceId;
  117 + }
  118 +
  119 + public int getCityCode() {
  120 + return cityCode;
  121 + }
  122 +
  123 + public short getIndustryCode() {
  124 + return industryCode;
  125 + }
  126 +
  127 + public short getCompanyCode() {
  128 + return companyCode;
  129 + }
  130 +
  131 + public int getLineId() {
  132 + return lineId;
  133 + }
  134 +
  135 + public int getDriverEmpNo() {
  136 + return driverEmpNo;
  137 + }
  138 +
  139 + public short getCarparkSerialNo() {
  140 + return carparkSerialNo;
  141 + }
  142 +
  143 + public String getCarparkNo() {
  144 + return carparkNo;
  145 + }
  146 +
  147 + public short getStopSerialNo() {
  148 + return stopSerialNo;
  149 + }
  150 +
  151 + public String getStopNo() {
  152 + return stopNo;
  153 + }
  154 +
  155 + public long getCarLon() {
  156 + return carLon;
  157 + }
  158 +
  159 + public int getCarLat() {
  160 + return carLat;
  161 + }
  162 +
  163 + public long getTimestamp() {
  164 + return timestamp;
  165 + }
  166 +
  167 + public short getSpeedSensor() {
  168 + return speedSensor;
  169 + }
  170 +
  171 + public short getSpeedGps() {
  172 + return speedGps;
  173 + }
  174 +
  175 + public short getDirection() {
  176 + return direction;
  177 + }
  178 +
  179 + public short getInTemp() {
  180 + return inTemp;
  181 + }
  182 +
  183 + public long getServiceState() {
  184 + return serviceState;
  185 + }
  186 +
  187 + public long getControlState() {
  188 + return controlState;
  189 + }
  190 +
  191 + public int getTotalMiles() {
  192 + return totalMiles;
  193 + }
  194 +
  195 + public byte getWaterTemp() {
  196 + return waterTemp;
  197 + }
  198 +
  199 + public int getOilConsumption() {
  200 + return oilConsumption;
  201 + }
  202 +
  203 + public int getEngineSpeed() {
  204 + return engineSpeed;
  205 + }
  206 +
  207 + public float getLon() {
  208 + return lon;
  209 + }
  210 +
  211 + public void setLon(float lon) {
  212 + this.lon = lon;
  213 + }
  214 +
  215 + public float getLat() {
  216 + return lat;
  217 + }
  218 +
  219 + public void setLat(float lat) {
  220 + this.lat = lat;
  221 + }
  222 +
  223 + public void setStopNo(String stopNo) {
  224 + this.stopNo = stopNo;
  225 + }
  226 +
  227 + public byte getGpsValid() {
  228 + return (byte)(((serviceState & 0x80000000) == 0x80000000) ? 1 : 0);
  229 + }
  230 +
  231 + /**
  232 + * 获取车辆在场外/内
  233 + * @return -1无效 0场外1场内
  234 + */
  235 + public byte getInOrOutCarpark() {
  236 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
  237 + || (serviceState & 0x01000000) == 0x01000000) return -1;
  238 + return (byte)(((serviceState & 0x40000000) == 0x40000000) ? 1 : 0);
  239 + }
  240 +
  241 + public void setInOrOutCarpark(boolean inOutFlag) {
  242 + if (inOutFlag) serviceState |= 0x40000000;
  243 + else serviceState &= 0xbfffffff;
  244 + }
  245 +
  246 + /**
  247 + * 获取车辆在起终点站外/内
  248 + * @return -1无效 0起终点站外1起终点站内
  249 + */
  250 + public byte getInOrOutStartEnd() {
  251 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
  252 + || (serviceState & 0x01000000) == 0x01000000) return -1;
  253 + return (byte)(((serviceState & 0x20000000) == 0x20000000) ? 1 : 0);
  254 + }
  255 +
  256 + /**
  257 + * 获取车辆线路上下行
  258 + * @return -1无效 0上行 1下行
  259 + */
  260 + public byte getUpOrDown() {
  261 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
  262 + || (serviceState & 0x01000000) == 0x01000000
  263 + || (serviceState & 0x08000000) == 0x08000000) return -1;
  264 + return (byte)(((serviceState & 0x10000000) == 0x10000000) ? 1 : 0);
  265 + }
  266 +
  267 + public void setUpOrDown(boolean upOrDown) {
  268 + if (!upOrDown) serviceState |= 0x10000000;
  269 + else serviceState &= 0xefffffff;
  270 + }
  271 +
  272 + /**
  273 + * 获取车辆在站外/内
  274 + * @return -1无效 0站外 1站内
  275 + */
  276 + public byte getInOrOutStop() {
  277 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
  278 + || (serviceState & 0x01000000) == 0x01000000
  279 + || (serviceState & 0x08000000) == 0x08000000) return -1;
  280 + return (byte)(((serviceState & 0x04000000) == 0x04000000) ? 1 : 0);
  281 + }
  282 +
  283 + public void setInOrOutStop(boolean isInOrOutStop) {
  284 + inOutStopFlag = true;
  285 + if (isInOrOutStop) serviceState |= 0x04000000;
  286 + else serviceState &= 0xfbffffff;
  287 + }
  288 +
  289 + /**
  290 + * 获取运营状态
  291 + * @return -1无效 0运营 1未运营
  292 + */
  293 + public byte getService() {
  294 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000) return -1;
  295 + return (byte)(((serviceState & 0x02000000) == 0x02000000) ? 1 : 0);
  296 + }
  297 +
  298 + public void setService(boolean service) {
  299 + if (!service) serviceState |= 0x02000000;
  300 + else serviceState &= 0xfdffffff;
  301 + }
  302 +
  303 + /**
  304 + * 获得车辆状态
  305 + * @return 0点火 1熄火
  306 + */
  307 + public byte getVehicleState() {
  308 + return (byte)(((serviceState & 0x00200000) == 0x00200000) ? 1 : 0);
  309 + }
  310 +
  311 + public void setInOutStopFlag(boolean inOutStopFlag) {
  312 + this.inOutStopFlag = inOutStopFlag;
  313 + }
  314 +
  315 + public boolean getInOutStopFlag() {
  316 + return inOutStopFlag;
  317 + }
  318 +
  319 + public String toString() {
  320 + Date d = new Date();d.setTime(timestamp);
  321 + StringBuilder sb = new StringBuilder();
  322 + sb.append("城市代码:").append(cityCode)
  323 + .append("行业代码:").append(industryCode)
  324 + .append("公司代码:").append(companyCode)
  325 + .append("设备号:").append(deviceId)
  326 + .append("线路编号:").append(lineId)
  327 + .append("驾驶员工号:").append(driverEmpNo)
  328 + .append("停车场序列号:").append(carparkSerialNo)
  329 + .append("停车场编号:").append(carparkNo)
  330 + .append("站点序列号").append(stopSerialNo)
  331 + .append("站点编号:").append(stopNo)
  332 + .append("经度:").append(carLon)
  333 + .append("维度:").append(carLat)
  334 + .append("时间戳:").append(d)
  335 + .append("速度(传感器):").append(speedSensor)
  336 + .append("速度(gps)").append(speedGps)
  337 + .append("方向:").append(direction)
  338 + .append("车内温度:").append(inTemp)
  339 + .append("营运状态:").append(serviceState)
  340 + .append("调控状态:").append(controlState)
  341 + .append("总里程:").append(totalMiles)
  342 + .append("水温:").append(waterTemp)
  343 + .append("油耗:").append(oilConsumption)
  344 + .append("发动机速度:").append(engineSpeed);
  345 +
  346 + return sb.toString();
  347 + }
  348 + /* ----------------------------------------------------- */
  349 +
  350 + public void setCityCode(int cityCode) {
  351 + this.cityCode = cityCode;
  352 + }
  353 +
  354 + public void setIndustryCode(short industryCode) {
  355 + this.industryCode = industryCode;
  356 + }
  357 +
  358 + public void setCompanyCode(short companyCode) {
  359 + this.companyCode = companyCode;
  360 + }
  361 +
  362 + public void setDeviceId(String deviceId) {
  363 + this.deviceId = deviceId;
  364 + }
  365 +
  366 + public void setLineId(int lineId) {
  367 + this.lineId = lineId;
  368 + }
  369 +
  370 + public void setDriverEmpNo(int driverEmpNo) {
  371 + this.driverEmpNo = driverEmpNo;
  372 + }
  373 +
  374 + public void setCarparkSerialNo(short carparkSerialNo) {
  375 + this.carparkSerialNo = carparkSerialNo;
  376 + }
  377 +
  378 + public void setCarparkNo(String carparkNo) {
  379 + this.carparkNo = carparkNo;
  380 + }
  381 +
  382 + public void setStopSerialNo(short stopSerialNo) {
  383 + this.stopSerialNo = stopSerialNo;
  384 + }
  385 +
  386 + public void setCarLon(long carLon) {
  387 + this.carLon = carLon;
  388 + }
  389 +
  390 + public void setCarLat(int carLat) {
  391 + this.carLat = carLat;
  392 + }
  393 +
  394 + public void setTimestamp(long timestamp) {
  395 + this.timestamp = timestamp;
  396 + }
  397 +
  398 + public void setSpeedSensor(short speedSensor) {
  399 + this.speedSensor = speedSensor;
  400 + }
  401 +
  402 + public void setSpeedGps(short speedGps) {
  403 + this.speedGps = speedGps;
  404 + }
  405 +
  406 + public void setDirection(short direction) {
  407 + this.direction = direction;
  408 + }
  409 +
  410 + public void setInTemp(short inTemp) {
  411 + this.inTemp = inTemp;
  412 + }
  413 +
  414 + public void setServiceState(long serviceState) {
  415 + this.serviceState = serviceState;
  416 + }
  417 +
  418 + public void setControlState(long controlState) {
  419 + this.controlState = controlState;
  420 + }
  421 +
  422 + public void setTotalMiles(int totalMiles) {
  423 + this.totalMiles = totalMiles;
  424 + }
  425 +
  426 + public void setWaterTemp(byte waterTemp) {
  427 + this.waterTemp = waterTemp;
  428 + }
  429 +
  430 + public void setOilConsumption(int oilConsumption) {
  431 + this.oilConsumption = oilConsumption;
  432 + }
  433 +
  434 + public void setEngineSpeed(int engineSpeed) {
  435 + this.engineSpeed = engineSpeed;
  436 + }
  437 +}
... ...
src/main/java/com/bsth/client/pd/protocol/PdFactory.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pd/protocol/PdFactory.java
  1 +package com.bsth.client.pd.protocol;
  2 +
  3 +
  4 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  5 +
  6 +public class PdFactory {
  7 +
  8 + public static IMessageBody create(int commandType, byte[] data) {
  9 + String pkgName = PdFactory.class.getPackage().getName();
  10 + IMessageBody body = null;
  11 + try {
  12 + Class<?> cls = Class.forName(pkgName + ".Pd_" + Integer.toHexString(commandType).toUpperCase() + "_0");
  13 + body = (IMessageBody)cls.newInstance();
  14 + body.read(data);
  15 + } catch (ClassNotFoundException e) {
  16 + // TODO Auto-generated catch block
  17 + //e.printStackTrace();
  18 + } catch (InstantiationException e) {
  19 + // TODO Auto-generated catch block
  20 + e.printStackTrace();
  21 + } catch (IllegalAccessException e) {
  22 + // TODO Auto-generated catch block
  23 + e.printStackTrace();
  24 + }
  25 + return body;
  26 + }
  27 +}
... ...
src/main/java/com/bsth/client/pd/protocol/PdMessage.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pd/protocol/PdMessage.java
  1 +package com.bsth.client.pd.protocol;
  2 +
  3 +
  4 +import com.bsth.data.gpsdata.client.msg.IMessage;
  5 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  6 +
  7 +import java.nio.ByteBuffer;
  8 +import java.util.Arrays;
  9 +
  10 +public class PdMessage implements IMessage {
  11 +
  12 + private short version;
  13 + private short serialNo;
  14 + private short commandType;
  15 + private IMessageBody messageBody;
  16 + private byte checkSum;
  17 +
  18 + public short getVersion() {
  19 + return version;
  20 + }
  21 +
  22 + public void setVersion(short version) {
  23 + this.version = version;
  24 + }
  25 +
  26 + public short getSerialNo() {
  27 + return serialNo;
  28 + }
  29 +
  30 + public void setSerialNo(short serialNo) {
  31 + this.serialNo = serialNo;
  32 + }
  33 +
  34 + public short getCommandType() {
  35 + return commandType;
  36 + }
  37 +
  38 + public void setCommandType(short commandType) {
  39 + this.commandType = commandType;
  40 + }
  41 +
  42 + public IMessageBody getMessageBody() {
  43 + return messageBody;
  44 + }
  45 +
  46 + public void setMessageBody(IMessageBody messageBody) {
  47 + this.messageBody = messageBody;
  48 + }
  49 +
  50 + public byte getCheckSum() {
  51 + return checkSum;
  52 + }
  53 +
  54 + public void setCheckSum(byte checkSum) {
  55 + this.checkSum = checkSum;
  56 + }
  57 +
  58 + public void read(byte[] data) {
  59 + int idx = 0, len = data.length;
  60 + version = (short)(data[idx] & 0xff); idx++;
  61 + serialNo = (short)(data[idx] & 0xff); idx++;
  62 + commandType = (short)(data[idx] & 0xff); idx++;
  63 + byte[] temp = Arrays.copyOfRange(data, idx, len - 1);
  64 + checkSum = data[len - 1];
  65 + byte sum = 0;
  66 + for (int i = 0;i < len - 1;i++) {
  67 + sum += data[i];
  68 + }
  69 + if (sum == checkSum) {
  70 + messageBody = PdFactory.create(commandType, temp);
  71 + }
  72 + }
  73 +
  74 + public byte[] write() {
  75 + byte[] bytes = messageBody.write();
  76 + ByteBuffer buf = ByteBuffer.allocate(bytes.length + 8);
  77 + buf.put(new byte[] { (byte)0xfa, (byte)0xf5 });
  78 + buf.putShort((short)(bytes.length + 3));
  79 + buf.put((byte)version);
  80 + buf.put((byte)serialNo);
  81 + buf.put((byte)commandType);
  82 + buf.put(bytes);
  83 + checkSum = 0;
  84 + checkSum += (byte)version;
  85 + checkSum += (byte)serialNo;
  86 + checkSum += (byte)commandType;
  87 + for (byte b : bytes) {
  88 + checkSum += b;
  89 + }
  90 + buf.put(checkSum);
  91 + return buf.array();
  92 + }
  93 +
  94 + public String toString() {
  95 + StringBuilder sb = new StringBuilder();
  96 + sb.append("报文版本号:").append(version)
  97 + .append("报文序列号:").append(serialNo)
  98 + .append("报文命令字:0x").append(Integer.toHexString(commandType))
  99 + .append("报文主体:(").append(messageBody).append(")")
  100 + .append("报文校验和:").append(checkSum);
  101 +
  102 + return sb.toString();
  103 + }
  104 +}
... ...
src/main/java/com/bsth/client/pd/protocol/Pd_31_0.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pd/protocol/Pd_31_0.java
  1 +package com.bsth.client.pd.protocol;
  2 +
  3 +
  4 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  5 +import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
  6 +
  7 +import java.nio.ByteBuffer;
  8 +import java.util.Date;
  9 +
  10 +
  11 +public class Pd_31_0 implements IMessageBody {
  12 +
  13 + // bcd 1
  14 + private short funCode;
  15 + // bcd 3
  16 + private int lineId;
  17 + // ascii 8
  18 + private String deviceId;
  19 + // bcd 6 yyMMddhhmmss
  20 + private long timestamp;
  21 + // hex 8
  22 + private String reserved;
  23 +
  24 + @Override
  25 + public void read(byte[] bytes) {
  26 + // TODO Auto-generated method stub
  27 + int idx = 0;
  28 + funCode = (short)(bytes[idx] & 0xff);idx++;
  29 + lineId = ConvertUtil.bcd2int(bytes, idx, 3);idx += 3;
  30 + deviceId = ConvertUtil.ascii2string(bytes, idx, 8);idx += 8;
  31 + timestamp = ConvertUtil.bcd2timestamp(bytes, idx);idx += 6;
  32 + reserved = ConvertUtil.ascii2string(bytes, idx, 8);idx += 8;
  33 + }
  34 +
  35 + @Override
  36 + public byte[] write() {
  37 + // TODO Auto-generated method stub
  38 + ByteBuffer buf = ByteBuffer.allocate(26);
  39 + buf.put((byte)funCode);
  40 + buf.put(ConvertUtil.int2bcd(lineId, 3));
  41 + buf.put(deviceId.getBytes());
  42 + buf.put(ConvertUtil.timestamp2bcd(timestamp));
  43 + buf.put(new byte[]{0,0,0,0,0,0,0,0});
  44 + return buf.array();
  45 + }
  46 +
  47 + public short getFunCode() {
  48 + return funCode;
  49 + }
  50 +
  51 + public int getLineId() {
  52 + return lineId;
  53 + }
  54 +
  55 + public String getDeviceId() {
  56 + return deviceId;
  57 + }
  58 +
  59 + public long getTimestamp() {
  60 + return timestamp;
  61 + }
  62 +
  63 + public String getReserved() {
  64 + return reserved;
  65 + }
  66 +
  67 + public void setFunCode(short funCode) {
  68 + this.funCode = funCode;
  69 + }
  70 +
  71 + public void setLineId(int lineId) {
  72 + this.lineId = lineId;
  73 + }
  74 +
  75 + public void setDeviceId(String deviceId) {
  76 + this.deviceId = deviceId;
  77 + }
  78 +
  79 + public void setTimeStamp(long timestamp) {
  80 + this.timestamp = timestamp;
  81 + }
  82 +
  83 + public void setReserved(String reserved) {
  84 + this.reserved = reserved;
  85 + }
  86 +
  87 + public String toString() {
  88 + Date d = new Date();
  89 + d.setTime(timestamp);
  90 + StringBuilder sb = new StringBuilder();
  91 + sb.append("功能号:").append(Integer.toHexString(funCode))
  92 + .append("线路编号:").append(lineId)
  93 + .append("设备编号:").append(deviceId)
  94 + .append("时间戳:").append(d);
  95 + return sb.toString();
  96 + }
  97 +}
... ...
src/main/java/com/bsth/client/pd/protocol/Pd_41_0.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pd/protocol/Pd_41_0.java
  1 +package com.bsth.client.pd.protocol;
  2 +
  3 +
  4 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  5 +import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
  6 +
  7 +import java.nio.ByteBuffer;
  8 +
  9 +
  10 +public class Pd_41_0 implements IMessageBody {
  11 +
  12 + private BasicInfo info;
  13 + private short leaveStopDis;
  14 +
  15 + public BasicInfo getInfo() {
  16 + return info;
  17 + }
  18 +
  19 + public void setInfo(BasicInfo info) {
  20 + this.info = info;
  21 + }
  22 +
  23 + public short getLeaveStopDis() {
  24 + return leaveStopDis;
  25 + }
  26 +
  27 + public void setLeaveStopDis(short leaveStopDis) {
  28 + this.leaveStopDis = leaveStopDis;
  29 + }
  30 +
  31 + @Override
  32 + public void read(byte[] bytes) {
  33 + // TODO Auto-generated method stub
  34 + int idx = 0;
  35 + info = new BasicInfo();
  36 + info.read(bytes, idx); idx += 80;
  37 + leaveStopDis = (short) ConvertUtil.bcd2int(bytes, idx, 2); idx += 2;
  38 + }
  39 +
  40 + @Override
  41 + public byte[] write() {
  42 + // TODO Auto-generated method stub
  43 + ByteBuffer buf = ByteBuffer.allocate(82);
  44 + buf.put(info.write());
  45 + buf.put(ConvertUtil.int2bcd(leaveStopDis, 2));
  46 +
  47 + return buf.array();
  48 + }
  49 +
  50 + @Override
  51 + public String getDeviceId() {
  52 + // TODO Auto-generated method stub
  53 + return info.getDeviceId();
  54 + }
  55 +
  56 + public String toString() {
  57 + StringBuilder sb = new StringBuilder();
  58 + sb.append("基本数据:").append(info.toString())
  59 + .append("离站距离:").append(leaveStopDis);
  60 +
  61 + return sb.toString();
  62 + }
  63 +
  64 + @Override
  65 + public long getTimestamp() {
  66 + // TODO Auto-generated method stub
  67 + return info.getTimestamp();
  68 + }
  69 +}
... ...
src/main/java/com/bsth/client/pd/protocol/Pd_42_0.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pd/protocol/Pd_42_0.java
  1 +package com.bsth.client.pd.protocol;
  2 +
  3 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  4 +import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
  5 +
  6 +import java.nio.ByteBuffer;
  7 +
  8 +public class Pd_42_0 implements IMessageBody {
  9 +
  10 + private BasicInfo info;
  11 + // 站间里程 保留两位小数 km
  12 + private short stopBetMiles;
  13 + private short frontDoorUp;
  14 + private short frontDoorDown;
  15 + private short backDoorUp;
  16 + private short backDoorDown;
  17 + // 本站留车人数
  18 + private int stay;
  19 + // 本站刷卡次数
  20 + private short cardCount;
  21 + // 本站刷卡金额
  22 + private int cardMoney;
  23 + // 免费刷卡次数
  24 + private short freeCardCount;
  25 + // 免费刷卡金额
  26 + private int freeCardMoney;
  27 + // 总刷卡次数
  28 + private int totalCardCount;
  29 + // 总数卡金额
  30 + private long totalCardMoney;
  31 + // 总免费刷卡次数
  32 + private int totalFreeCardCount;
  33 + // 总免费刷卡金额
  34 + private long totalFreeCardMoney;
  35 + // 客流站号
  36 + private short passengerStopNo;
  37 +
  38 + @Override
  39 + public void read(byte[] bytes) {
  40 + // TODO Auto-generated method stub
  41 + ByteBuffer buf = ByteBuffer.wrap(bytes);
  42 + int idx = 0;
  43 + info = new BasicInfo();
  44 + info.read(bytes, idx); idx += 80;
  45 + stopBetMiles = (short) ConvertUtil.bcd2int(bytes, idx, 2); idx += 2;
  46 + frontDoorUp = (short)(buf.get(idx) & 0xff); idx++;
  47 + frontDoorDown = (short)(buf.get(idx) & 0xff); idx++;
  48 + backDoorUp = (short)(buf.get(idx) & 0xff); idx++;
  49 + backDoorDown = (short)(buf.get(idx) & 0xff); idx++;
  50 + stay = buf.getShort(idx) & 0xffff; idx += 2;
  51 + cardCount = (short)(buf.get(idx) & 0xff); idx++;
  52 + cardMoney = buf.getShort(idx) & 0xffff; idx += 2;
  53 + freeCardCount = (short)(buf.get(idx) & 0xff); idx++;
  54 + freeCardMoney = buf.getShort(idx) & 0xffff; idx += 2;
  55 + totalCardCount = buf.getShort(idx) & 0xffff; idx += 2;
  56 + totalCardMoney = buf.getInt(idx) & 0xffffffffl; idx += 4;
  57 + totalFreeCardCount = buf.getShort(idx) & 0xffff; idx += 2;
  58 + totalFreeCardMoney = buf.getInt(idx) & 0xffffffffl; idx += 4;
  59 + passengerStopNo = (short)(buf.get(idx) & 0xff); idx++;
  60 + }
  61 +
  62 + @Override
  63 + public byte[] write() {
  64 + // TODO Auto-generated method stub
  65 + ByteBuffer buf = ByteBuffer.allocate(107);
  66 + buf.put(info.write());
  67 + buf.put(ConvertUtil.int2bcd(stopBetMiles, 2));
  68 + buf.put((byte)frontDoorUp);
  69 + buf.put((byte)frontDoorDown);
  70 + buf.put((byte)backDoorUp);
  71 + buf.put((byte)backDoorDown);
  72 + buf.putShort((short)stay);
  73 + buf.put((byte)cardCount);
  74 + buf.putShort((short)cardMoney);
  75 + buf.put((byte)freeCardCount);
  76 + buf.putShort((short)freeCardMoney);
  77 + buf.putShort((short)totalCardCount);
  78 + buf.putInt((int)totalCardMoney);
  79 + buf.putShort((short)totalFreeCardCount);
  80 + buf.putInt((int)totalFreeCardMoney);
  81 + buf.put((byte)passengerStopNo);
  82 +
  83 + return buf.array();
  84 + }
  85 +
  86 + @Override
  87 + public String getDeviceId() {
  88 + // TODO Auto-generated method stub
  89 + return info.getDeviceId();
  90 + }
  91 +
  92 + public BasicInfo getInfo() {
  93 + return info;
  94 + }
  95 +
  96 + public short getStopBetMiles() {
  97 + return stopBetMiles;
  98 + }
  99 +
  100 + public short getFrontDoorUp() {
  101 + return frontDoorUp;
  102 + }
  103 +
  104 + public short getFrontDoorDown() {
  105 + return frontDoorDown;
  106 + }
  107 +
  108 + public short getBackDoorUp() {
  109 + return backDoorUp;
  110 + }
  111 +
  112 + public short getBackDoorDown() {
  113 + return backDoorDown;
  114 + }
  115 +
  116 + public int getStay() {
  117 + return stay;
  118 + }
  119 +
  120 + public short getCardCount() {
  121 + return cardCount;
  122 + }
  123 +
  124 + public int getCardMoney() {
  125 + return cardMoney;
  126 + }
  127 +
  128 + public short getFreeCardCount() {
  129 + return freeCardCount;
  130 + }
  131 +
  132 + public int getFreeCardMoney() {
  133 + return freeCardMoney;
  134 + }
  135 +
  136 + public int getTotalCardCount() {
  137 + return totalCardCount;
  138 + }
  139 +
  140 + public long getTotalCardMoney() {
  141 + return totalCardMoney;
  142 + }
  143 +
  144 + public int getTotalFreeCardCount() {
  145 + return totalFreeCardCount;
  146 + }
  147 +
  148 + public long getTotalFreeCardMoney() {
  149 + return totalFreeCardMoney;
  150 + }
  151 +
  152 + public short getPassengerStopNo() {
  153 + return passengerStopNo;
  154 + }
  155 +
  156 + public String toString() {
  157 + StringBuilder sb = new StringBuilder();
  158 + sb.append("基本数据:").append(info.toString())
  159 + .append("站间距离:").append(stopBetMiles)
  160 + .append("前门上客:").append(frontDoorUp)
  161 + .append("前门下客:").append(frontDoorDown)
  162 + .append("后门上客:").append(backDoorUp)
  163 + .append("后门下客:").append(backDoorDown)
  164 + .append("本站留车人数:").append(stay)
  165 + .append("本站刷卡次数:").append(cardCount)
  166 + .append("本站刷卡金额:").append(cardMoney)
  167 + .append("免费刷卡次数:").append(freeCardCount)
  168 + .append("免费刷卡金额:").append(freeCardMoney)
  169 + .append("总刷卡次数:").append(totalCardCount)
  170 + .append("总数卡金额:").append(totalCardMoney)
  171 + .append("总免费刷卡次数:").append(totalFreeCardCount)
  172 + .append("总免费刷卡金额:").append(totalFreeCardMoney)
  173 + .append("客流站号:").append(passengerStopNo);
  174 +
  175 + return sb.toString();
  176 + }
  177 +
  178 + @Override
  179 + public long getTimestamp() {
  180 + // TODO Auto-generated method stub
  181 + return info.getTimestamp();
  182 + }
  183 +}
... ...
src/main/java/com/bsth/client/pf/codec/MessageDecoder.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pf/codec/MessageDecoder.java
  1 +package com.bsth.client.pf.codec;
  2 +
  3 +import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
  4 +import com.bsth.data.gpsdata.client.pf.protocol.PfMessage;
  5 +import org.apache.mina.core.buffer.IoBuffer;
  6 +import org.apache.mina.core.session.IoSession;
  7 +import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
  8 +import org.apache.mina.filter.codec.ProtocolDecoderOutput;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +
  12 +
  13 +public class MessageDecoder extends CumulativeProtocolDecoder {
  14 +
  15 + Logger log = LoggerFactory.getLogger(MessageDecoder.class);
  16 +
  17 + @Override
  18 + protected boolean doDecode(IoSession session, IoBuffer in,
  19 + ProtocolDecoderOutput out) throws Exception {
  20 + // TODO Auto-generated method stub
  21 + while (in.remaining() > 3) {
  22 + in.mark();
  23 + byte head1 = in.get(), head2 = in.get(), lenh = in.get(), lenl = in.get();
  24 + int len = ((lenh & 0xff) << 8) + (lenl & 0xff);
  25 + if ((head1 & 0xff) == 0xfa && (head2 & 0xff) == 0xf5) {
  26 + if (in.remaining() > len) {
  27 + try {
  28 + byte[] bytes = new byte[len + 1];
  29 + in.get(bytes);
  30 + PfMessage msg = new PfMessage();
  31 + msg.read(bytes);
  32 +
  33 + //日志纪录
  34 + log.info("pf client receive: " + ConvertUtil.bytesToHexString(bytes));
  35 + out.write(msg);
  36 + }catch (Exception e){
  37 + log.error("pf message decoder:", e);
  38 + }
  39 + } else {
  40 + in.reset();
  41 + return false;
  42 + }
  43 + }
  44 + }
  45 + return false;
  46 + }
  47 +
  48 + /*private static String toHexString(byte[] bytes) {
  49 + StringBuilder sb = new StringBuilder();
  50 + for (byte b : bytes) {
  51 + sb.append(Integer.toHexString(b & 0xff) + "|");
  52 + }
  53 + return sb.toString();
  54 + }*/
  55 +}
... ...
src/main/java/com/bsth/client/pf/codec/MessageEncoder.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pf/codec/MessageEncoder.java
  1 +package com.bsth.client.pf.codec;
  2 +
  3 +import org.apache.mina.core.buffer.IoBuffer;
  4 +import org.apache.mina.core.session.IoSession;
  5 +import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
  6 +import org.apache.mina.filter.codec.ProtocolEncoderOutput;
  7 +
  8 +public class MessageEncoder extends ProtocolEncoderAdapter {
  9 +
  10 + @Override
  11 + public void encode(IoSession session, Object message,
  12 + ProtocolEncoderOutput out) throws Exception {
  13 + // TODO Auto-generated method stub
  14 + IoBuffer buf = IoBuffer.allocate(1024).setAutoExpand(true);
  15 + buf.put((byte[])message);
  16 + buf.flip();
  17 + out.write(buf);
  18 + }
  19 +
  20 +}
... ...
src/main/java/com/bsth/client/pf/codec/PfMessageCodecFactory.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pf/codec/PfMessageCodecFactory.java
  1 +package com.bsth.client.pf.codec;
  2 +
  3 +import org.apache.mina.core.session.IoSession;
  4 +import org.apache.mina.filter.codec.ProtocolCodecFactory;
  5 +import org.apache.mina.filter.codec.ProtocolDecoder;
  6 +import org.apache.mina.filter.codec.ProtocolEncoder;
  7 +
  8 +public class PfMessageCodecFactory implements ProtocolCodecFactory {
  9 +
  10 + private ProtocolEncoder encoder;
  11 + private ProtocolDecoder decoder;
  12 +
  13 + public PfMessageCodecFactory() {
  14 + encoder = new MessageEncoder();
  15 + decoder = new MessageDecoder();
  16 + }
  17 +
  18 + @Override
  19 + public ProtocolEncoder getEncoder(IoSession session) throws Exception {
  20 + // TODO Auto-generated method stub
  21 + return encoder;
  22 + }
  23 +
  24 + @Override
  25 + public ProtocolDecoder getDecoder(IoSession session) throws Exception {
  26 + // TODO Auto-generated method stub
  27 + return decoder;
  28 + }
  29 +
  30 +}
... ...
src/main/java/com/bsth/client/pf/common/ConvertUtil.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pf/common/ConvertUtil.java
  1 +package com.bsth.client.pf.common;
  2 +
  3 +import com.bsth.data.gpsdata.client.common.ThreadLocalDateUtil;
  4 +import org.slf4j.Logger;
  5 +import org.slf4j.LoggerFactory;
  6 +
  7 +import java.text.ParseException;
  8 +import java.util.Arrays;
  9 +import java.util.Calendar;
  10 +import java.util.Date;
  11 +
  12 +
  13 +public class ConvertUtil {
  14 +
  15 + private final static Logger log = LoggerFactory.getLogger(ConvertUtil.class);
  16 +
  17 + public static int bcd2int(byte[] bytes, int start, int len) {
  18 + if (len > 4 || len == 0)
  19 + throw new IllegalArgumentException("bcd2int 字节数不符合要求");
  20 + String temp = "";
  21 + for (int i = 0;i < len;i++) {
  22 + int val = bytes[start + i] & 0xff;
  23 + if (val < 10) temp += 0;
  24 + temp += Integer.toHexString(val);
  25 + }
  26 + return Integer.parseInt(temp);
  27 + }
  28 +
  29 + public static byte[] int2bcd(int val, int len) {
  30 + if (len > 4 || len == 0)
  31 + throw new IllegalArgumentException("int2bcd 字节数不符合要求");
  32 + byte[] result = new byte[len];
  33 + for (int i = len - 1;i > -1;i--) {
  34 + result[i] = (byte)Integer.parseInt(val%100 + "", 16);
  35 + val = val/100;
  36 + }
  37 + return result;
  38 + }
  39 +
  40 + public static long bcd2long(byte[] bytes, int start, int len) {
  41 + if (len > 8 || len == 0)
  42 + throw new IllegalArgumentException("bcd2long 字节数不符合要求");
  43 + String temp = "";
  44 + for (int i = 0;i < len;i++) {
  45 + int val = bytes[start + i] & 0xff;
  46 + if (val < 10) temp += 0;
  47 + temp += Integer.toHexString(val);
  48 + }
  49 + return Long.parseLong(temp);
  50 + }
  51 +
  52 + public static byte[] long2bcd(long val, int len) {
  53 + if (len > 8 || len == 0)
  54 + throw new IllegalArgumentException("long2bcd 字节数不符合要求");
  55 + byte[] result = new byte[len];
  56 + for (int i = len - 1;i > -1;i--) {
  57 + result[i] = (byte)Integer.parseInt(val%100 + "", 16);
  58 + val = val/100;
  59 + }
  60 + return result;
  61 + }
  62 +
  63 + public static String ascii2string(byte[] bytes, int start, int len) {
  64 + return new String(Arrays.copyOfRange(bytes, start, start + len));
  65 + }
  66 +
  67 + public static byte[] string2ascii(String val, int len) {
  68 + byte[] result = new byte[len];
  69 + byte[] bytes = val.getBytes();
  70 + if (bytes.length > len && len != 0)
  71 + throw new IllegalArgumentException("string2ascii 参数不符合要求");
  72 + if (len != 0)
  73 + for (int i = 0, l = bytes.length;i < l;i++) result[i] = bytes[i];
  74 + else return bytes;
  75 + return result;
  76 + }
  77 +
  78 + public static long bcd2timestamp(byte[] bytes, int start) {
  79 + String temp = "20";
  80 + for (int i = 0;i < 6;i++) {
  81 + int val = bytes[start + i] & 0xff;
  82 + if (val < 10) temp += 0;
  83 + temp += Integer.toHexString(val);
  84 + }
  85 + Date date = null;
  86 + try {
  87 + date = ThreadLocalDateUtil.parse(temp);
  88 + } catch (ParseException e) {
  89 + log.error("协议中时间数据异常:" + temp);
  90 + }
  91 + if (date != null) return date.getTime();
  92 + return -1;
  93 + }
  94 +
  95 + public static byte[] timestamp2bcd(long val) {
  96 + byte[] result = new byte[6];
  97 + Calendar c = Calendar.getInstance();
  98 + c.setTime(new Date(val));
  99 + result[0] = (byte)(Integer.parseInt(c.get(Calendar.YEAR)%100 + "", 16));
  100 + result[1] = (byte)(Integer.parseInt(c.get(Calendar.MONTH) + 1 + "", 16));
  101 + result[2] = (byte)Integer.parseInt(c.get(Calendar.DAY_OF_MONTH) + "", 16);
  102 + result[3] = (byte)Integer.parseInt(c.get(Calendar.HOUR_OF_DAY) + "", 16);
  103 + result[4] = (byte)Integer.parseInt(c.get(Calendar.MINUTE) + "", 16);
  104 + result[5] = (byte)Integer.parseInt(c.get(Calendar.SECOND) + "", 16);
  105 + return result;
  106 + }
  107 +
  108 + public static byte[] int2hex(int val, int len) {
  109 + if (len < 1)
  110 + throw new IllegalArgumentException("int2hex len 参数不符合要求");
  111 + byte[] result = new byte[len];
  112 + for (int i = 0;i < len;i++) {
  113 + result[len - 1 - i] = (byte)(val%100);
  114 + val = val/100;
  115 + }
  116 +
  117 + return result;
  118 + }
  119 +}
... ...
src/main/java/com/bsth/client/pf/handler/PfClientHandler.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pf/handler/PfClientHandler.java
  1 +package com.bsth.client.pf.handler;
  2 +
  3 +import com.bsth.data.gpsdata.client.GpsBeforeBuffer;
  4 +import com.bsth.data.gpsdata.client.common.Protocol2BizUtil;
  5 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  6 +import com.bsth.data.gpsdata.client.pd.protocol.BasicInfo;
  7 +import com.bsth.data.gpsdata.client.pf.protocol.PfMessage;
  8 +import org.apache.mina.core.service.IoHandlerAdapter;
  9 +import org.apache.mina.core.session.IdleStatus;
  10 +import org.apache.mina.core.session.IoSession;
  11 +import org.slf4j.Logger;
  12 +import org.slf4j.LoggerFactory;
  13 +import org.springframework.beans.factory.annotation.Autowired;
  14 +import org.springframework.stereotype.Service;
  15 +
  16 +import java.io.IOException;
  17 +
  18 +@Service
  19 +public class PfClientHandler extends IoHandlerAdapter{
  20 +
  21 + private final static Logger log = LoggerFactory.getLogger(PfClientHandler.class);
  22 +
  23 + //@Autowired
  24 + //private MessageProcessor processor;
  25 +
  26 + @Autowired
  27 + GpsBeforeBuffer gpsBeforeBuffer;
  28 +
  29 + @Override
  30 + public void sessionCreated(IoSession session) throws Exception {
  31 +
  32 + }
  33 +
  34 + @Override
  35 + public void sessionOpened(IoSession session) throws Exception {
  36 +
  37 + }
  38 +
  39 + @Override
  40 + public void sessionClosed(IoSession session) throws Exception {
  41 + String deviceId = (String)session.getAttribute("deviceId");
  42 + if (deviceId != null) {
  43 + //SessionManager.getInstance().unregister(deviceId);
  44 + log.info("连老网关设备编号:" + deviceId + "断开连接");
  45 + log.warn(deviceId + "老网关设备注销");
  46 + //ClientApp.fconnect(deviceId);
  47 + }
  48 + }
  49 +
  50 + @Override
  51 + public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
  52 + log.warn("pf sessionIdle");
  53 + session.closeNow();
  54 + }
  55 +
  56 + @Override
  57 + public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
  58 + if (cause instanceof IOException) session.closeNow();
  59 + log.error("PfClientHandler exceptionCaught", cause);
  60 + }
  61 +
  62 + @Override
  63 + public void messageReceived(IoSession session, Object message) throws Exception {
  64 + PfMessage msg = (PfMessage)message;
  65 + IMessageBody body = msg.getMessageBody();
  66 + if (body != null) {
  67 + String deviceId = body.getDeviceId();
  68 + if (0x1 == msg.getCommandType()) {
  69 + log.debug("设备编号:" + body.getDeviceId() + "建立连接");
  70 + }
  71 +
  72 + BasicInfo info = Protocol2BizUtil.getBasicInfoFromMsg(msg);
  73 + gpsBeforeBuffer.put(info);
  74 + }
  75 +
  76 + }
  77 +
  78 + @Override
  79 + public void messageSent(IoSession session, Object message) throws Exception {
  80 +
  81 + }
  82 +}
... ...
src/main/java/com/bsth/client/pf/protocol/PfFactory.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pf/protocol/PfFactory.java
  1 +package com.bsth.client.pf.protocol;
  2 +
  3 +
  4 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  5 +
  6 +public class PfFactory {
  7 +
  8 + public static IMessageBody create(int commandType, byte[] data) {
  9 + String pkgName = PfFactory.class.getPackage().getName();
  10 + IMessageBody body = null;
  11 + try {
  12 + Class<?> cls = Class.forName(pkgName + ".Pf_" + Integer.toHexString(commandType).toUpperCase() + "_0");
  13 + body = (IMessageBody)cls.newInstance();
  14 + body.read(data);
  15 + } catch (ClassNotFoundException e) {
  16 + // TODO Auto-generated catch block
  17 + //e.printStackTrace();
  18 + } catch (InstantiationException e) {
  19 + // TODO Auto-generated catch block
  20 + e.printStackTrace();
  21 + } catch (IllegalAccessException e) {
  22 + // TODO Auto-generated catch block
  23 + e.printStackTrace();
  24 + }
  25 + return body;
  26 + }
  27 +}
... ...
src/main/java/com/bsth/client/pf/protocol/PfMessage.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pf/protocol/PfMessage.java
  1 +package com.bsth.client.pf.protocol;
  2 +
  3 +import com.bsth.data.gpsdata.client.msg.IMessage;
  4 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  5 +
  6 +import java.util.Arrays;
  7 +
  8 +public class PfMessage implements IMessage {
  9 +
  10 + private short version;
  11 + private short serialNo;
  12 + private short commandType;
  13 + private IMessageBody messageBody;
  14 + private byte checkSum;
  15 +
  16 + public short getVersion() {
  17 + return version;
  18 + }
  19 +
  20 + public void setVersion(short version) {
  21 + this.version = version;
  22 + }
  23 +
  24 + public short getSerialNo() {
  25 + return serialNo;
  26 + }
  27 +
  28 + public void setSerialNo(short serialNo) {
  29 + this.serialNo = serialNo;
  30 + }
  31 +
  32 + public short getCommandType() {
  33 + return commandType;
  34 + }
  35 +
  36 + public void setCommandType(short commandType) {
  37 + this.commandType = commandType;
  38 + }
  39 +
  40 + public IMessageBody getMessageBody() {
  41 + return messageBody;
  42 + }
  43 +
  44 + public void setMessageBody(IMessageBody messageBody) {
  45 + this.messageBody = messageBody;
  46 + }
  47 +
  48 + public byte getCheckSum() {
  49 + return checkSum;
  50 + }
  51 +
  52 + public void setCheckSum(byte checkSum) {
  53 + this.checkSum = checkSum;
  54 + }
  55 +
  56 + public void read(byte[] data) {
  57 + int idx = 0, len = data.length;
  58 + //version = (short)(data[idx] & 0xff); idx++;
  59 + //serialNo = (short)(data[idx] & 0xff); idx++;
  60 + commandType = (short)(data[idx] & 0xff); idx++;
  61 + byte[] temp = Arrays.copyOfRange(data, idx, len - 1);
  62 + checkSum = data[len - 1];
  63 + if (0xff == (checkSum & 0xff)) {
  64 + try {
  65 + messageBody = PfFactory.create(commandType, temp);
  66 + } catch (Exception e) {
  67 +
  68 + }
  69 + }
  70 + }
  71 +
  72 + public byte[] write() {
  73 + return null;
  74 + }
  75 +
  76 + public String toString() {
  77 + StringBuilder sb = new StringBuilder();
  78 + //sb.append("报文版本号:").append(version)
  79 + //.append("报文序列号:").append(serialNo)
  80 + sb.append("报文命令字:0x").append(Integer.toHexString(commandType))
  81 + .append("报文主体:(").append(messageBody).append(")")
  82 + .append("报文校验和:").append(checkSum);
  83 +
  84 + return sb.toString();
  85 + }
  86 +}
... ...
src/main/java/com/bsth/client/pf/protocol/Pf_1_0.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/client/pf/protocol/Pf_1_0.java
  1 +package com.bsth.client.pf.protocol;
  2 +
  3 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  4 +import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
  5 +
  6 +import java.nio.ByteBuffer;
  7 +import java.util.Date;
  8 +
  9 +
  10 +public class Pf_1_0 implements IMessageBody {
  11 +
  12 + /** 1、车载终端识别码-byte[8] */
  13 + private String mtd;
  14 + /** 2、司机工号-byte[8] */
  15 + private String driver;
  16 + /** 3、包车状态-byte[1] */
  17 + private int bczt;
  18 + /** 4、线路状态-byte[1] */
  19 + private int xlzt;
  20 + /** 5、线路代码-byte[6] */
  21 + private int xldm;
  22 + /** 6、营运状态-byte[1] */
  23 + private int yyzt;
  24 + /** 7、进出站状态-byte[1] */
  25 + private int jczzt;
  26 + /** 8、站点编号-byte[8] */
  27 + private String zdbh;
  28 + /** 9、进出停车场状态(0:厂内,1:厂外,2:未知)-byte[1] */
  29 + private int jctcczt;
  30 + /** 10、停车场编号-byte[8] */
  31 + private String tccbh;
  32 + /** 11、路段编码-byte[12] */
  33 + private String ldbh;
  34 + /** 12、上下行状态-byte[1] */
  35 + private int sxxzt;
  36 + /** 13、速度-byte[1] */
  37 + private int speed;
  38 + /** 14、初始异常状态-byte[1] */
  39 + private int csyczt;
  40 + /** 15、结束异常状态-byte[1] */
  41 + private int jsyczt;
  42 + /** 16、车辆位置经度(纠偏后)-byte[4] */
  43 + private double lon;
  44 + /** 17、车辆位置维度(纠偏后)-byte[4] */
  45 + private double lat;
  46 + /** 18、方向-byte[2] */
  47 + private int fx;
  48 + /** 19、发送时间-byte[4] */
  49 + private Date fssj;
  50 + /** 20、离下站距离-byte[2] */
  51 + private int lxzjl;
  52 + /** 21、本站留车人数-byte[2] */
  53 + private int bzlcrs;
  54 + /** 22、车辆位置经度(未纠偏)-byte[4] */
  55 + private double lon_old;
  56 + /** 23、车辆位置经度(未纠偏)-byte[4] */
  57 + private double lat_old;
  58 + /** 24、城建X坐标 */
  59 + private double x;
  60 + /** 25、城建Y坐标 */
  61 + private double y;
  62 +
  63 + public String getMtd() {
  64 + return mtd;
  65 + }
  66 +
  67 + public void setMtd(String mtd) {
  68 + this.mtd = mtd;
  69 + }
  70 +
  71 + public String getDriver() {
  72 + return driver;
  73 + }
  74 +
  75 + public void setDriver(String driver) {
  76 + this.driver = driver;
  77 + }
  78 +
  79 + public int getBczt() {
  80 + return bczt;
  81 + }
  82 +
  83 + public void setBczt(int bczt) {
  84 + this.bczt = bczt;
  85 + }
  86 +
  87 + public int getXlzt() {
  88 + return xlzt;
  89 + }
  90 +
  91 + public void setXlzt(int xlzt) {
  92 + this.xlzt = xlzt;
  93 + }
  94 +
  95 + public int getXldm() {
  96 + return xldm;
  97 + }
  98 +
  99 + public void setXldm(int xldm) {
  100 + this.xldm = xldm;
  101 + }
  102 +
  103 + public int getYyzt() {
  104 + return yyzt;
  105 + }
  106 +
  107 + public void setYyzt(int yyzt) {
  108 + this.yyzt = yyzt;
  109 + }
  110 +
  111 + public int getJczzt() {
  112 + return jczzt;
  113 + }
  114 +
  115 + public void setJczzt(int jczzt) {
  116 + this.jczzt = jczzt;
  117 + }
  118 +
  119 + public String getZdbh() {
  120 + return zdbh;
  121 + }
  122 +
  123 + public void setZdbh(String zdbh) {
  124 + this.zdbh = zdbh;
  125 + }
  126 +
  127 + public int getJctcczt() {
  128 + return jctcczt;
  129 + }
  130 +
  131 + public void setJctcczt(int jctcczt) {
  132 + this.jctcczt = jctcczt;
  133 + }
  134 +
  135 + public String getTccbh() {
  136 + return tccbh;
  137 + }
  138 +
  139 + public void setTccbh(String tccbh) {
  140 + this.tccbh = tccbh;
  141 + }
  142 +
  143 + public String getLdbh() {
  144 + return ldbh;
  145 + }
  146 +
  147 + public void setLdbh(String ldbh) {
  148 + this.ldbh = ldbh;
  149 + }
  150 +
  151 + public int getSxxzt() {
  152 + return sxxzt;
  153 + }
  154 +
  155 + public void setSxxzt(int sxxzt) {
  156 + this.sxxzt = sxxzt;
  157 + }
  158 +
  159 + public int getSpeed() {
  160 + return speed;
  161 + }
  162 +
  163 + public void setSpeed(int speed) {
  164 + this.speed = speed;
  165 + }
  166 +
  167 + public int getCsyczt() {
  168 + return csyczt;
  169 + }
  170 +
  171 + public void setCsyczt(int csyczt) {
  172 + this.csyczt = csyczt;
  173 + }
  174 +
  175 + public int getJsyczt() {
  176 + return jsyczt;
  177 + }
  178 +
  179 + public void setJsyczt(int jsyczt) {
  180 + this.jsyczt = jsyczt;
  181 + }
  182 +
  183 + public double getLon() {
  184 + return lon;
  185 + }
  186 +
  187 + public void setLon(double lon) {
  188 + this.lon = lon;
  189 + }
  190 +
  191 + public double getLat() {
  192 + return lat;
  193 + }
  194 +
  195 + public void setLat(double lat) {
  196 + this.lat = lat;
  197 + }
  198 +
  199 + public int getFx() {
  200 + return fx;
  201 + }
  202 +
  203 + public void setFx(int fx) {
  204 + this.fx = fx;
  205 + }
  206 +
  207 + public Date getFssj() {
  208 + return fssj;
  209 + }
  210 +
  211 + public void setFssj(Date fssj) {
  212 + this.fssj = fssj;
  213 + }
  214 +
  215 + public int getLxzjl() {
  216 + return lxzjl;
  217 + }
  218 +
  219 + public void setLxzjl(int lxzjl) {
  220 + this.lxzjl = lxzjl;
  221 + }
  222 +
  223 + public int getBzlcrs() {
  224 + return bzlcrs;
  225 + }
  226 +
  227 + public void setBzlcrs(int bzlcrs) {
  228 + this.bzlcrs = bzlcrs;
  229 + }
  230 +
  231 + public double getLon_old() {
  232 + return lon_old;
  233 + }
  234 +
  235 + public void setLon_old(double lon_old) {
  236 + this.lon_old = lon_old;
  237 + }
  238 +
  239 + public double getLat_old() {
  240 + return lat_old;
  241 + }
  242 +
  243 + public void setLat_old(double lat_old) {
  244 + this.lat_old = lat_old;
  245 + }
  246 +
  247 + public double getX() {
  248 + return x;
  249 + }
  250 +
  251 + public void setX(double x) {
  252 + this.x = x;
  253 + }
  254 +
  255 + public double getY() {
  256 + return y;
  257 + }
  258 +
  259 + public void setY(double y) {
  260 + this.y = y;
  261 + }
  262 +
  263 + public byte[] write() {
  264 + return null;
  265 + }
  266 +
  267 + @Override
  268 + public void read(byte[] bytes) {
  269 + // TODO Auto-generated method stub
  270 + int idx = 0;
  271 + ByteBuffer buf = ByteBuffer.wrap(bytes);
  272 + mtd = ConvertUtil.ascii2string(bytes, idx, 8); idx += 8;
  273 + driver = ConvertUtil.ascii2string(bytes, idx, 8); idx += 8;
  274 + bczt = buf.get(idx); idx++;
  275 + xlzt = buf.get(idx); idx++;
  276 + xldm = Integer.parseInt(ConvertUtil.ascii2string(bytes, idx, 6).trim()); idx += 6;
  277 + yyzt = buf.get(idx); idx++;
  278 + jczzt = buf.get(idx); idx++;
  279 + zdbh = ConvertUtil.ascii2string(bytes, idx, 8).trim(); idx += 8;
  280 + jctcczt = buf.get(idx); idx++;
  281 + tccbh = ConvertUtil.ascii2string(bytes, idx, 8); idx += 8;
  282 + ldbh = ConvertUtil.ascii2string(bytes, idx, 12).trim(); idx += 12;
  283 + sxxzt = buf.get(idx); idx++;
  284 + speed = buf.get(idx)*10; idx++;
  285 + csyczt = buf.get(idx); idx++;
  286 + jsyczt = buf.get(idx); idx++;
  287 + byte flagx = buf.get(idx); idx++;
  288 + if (flagx == 0) x = ConvertUtil.bytes2int(bytes, idx, 3)/100.0;
  289 + else x = -ConvertUtil.bytes2int(bytes, idx, 3)/100.0;
  290 + idx += 3;
  291 + byte flagy = buf.get(idx); idx++;
  292 + if (flagy == 0) y = ConvertUtil.bytes2int(bytes, idx, 3)/100.0;
  293 + else y = -ConvertUtil.bytes2int(bytes, idx, 3)/100.0;
  294 + idx += 3;
  295 + fx = buf.getShort(idx)*(short)10; idx += 2;
  296 + fssj = new Date(ConvertUtil.bytes2int(bytes, idx, 4) * 1000L); idx += 4;
  297 + lxzjl = buf.getShort(idx); idx += 2;
  298 + bzlcrs = buf.getShort(idx); idx += 2;
  299 + lon = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4;
  300 + lat = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4;
  301 + }
  302 +
  303 + @Override
  304 + public String getDeviceId() {
  305 + // TODO Auto-generated method stub
  306 + return mtd;
  307 + }
  308 +
  309 + @Override
  310 + public long getTimestamp() {
  311 + // TODO Auto-generated method stub
  312 + return 0;
  313 + }
  314 +}
... ...
src/main/java/com/bsth/util/Arith.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/util/Arith.java
  1 +package com.bsth.util;
  2 +
  3 +import java.math.BigDecimal;
  4 +
  5 +/**
  6 + * 进行BigDecimal对象的加减乘除,四舍五入等运算的工具类
  7 + * @author ameyume
  8 + *
  9 + */
  10 +public class Arith {
  11 +
  12 + /**
  13 + * 由于Java的简单类型不能够精确的对浮点数进行运算,这个工具类提供精
  14 + * 确的浮点数运算,包括加减乘除和四舍五入。
  15 + */
  16 + //默认除法运算精度
  17 + private static final int DEF_DIV_SCALE = 10;
  18 +
  19 + //这个类不能实例化
  20 + private Arith(){
  21 + }
  22 +
  23 + /**
  24 + * 提供精确的加法运算。
  25 + * @param v1 被加数
  26 + * @param v2 加数
  27 + * @return 两个参数的和
  28 + */
  29 + public static double add(Object v1,Object v2){
  30 + BigDecimal b1 = new BigDecimal(String.valueOf(v1));
  31 + BigDecimal b2 = new BigDecimal(String.valueOf(v2));
  32 + return b1.add(b2).doubleValue();
  33 + }
  34 +
  35 + /**
  36 + * 提供精确的减法运算。
  37 + * @param v1 被减数
  38 + * @param v2 减数
  39 + * @return 两个参数的差
  40 + */
  41 + public static double sub(Object v1,Object v2){
  42 + BigDecimal b1 = new BigDecimal(String.valueOf(v1));
  43 + BigDecimal b2 = new BigDecimal(String.valueOf(v2));
  44 + return b1.subtract(b2).doubleValue();
  45 + }
  46 +
  47 + /**
  48 + * 提供精确的乘法运算。
  49 + * @param v1 被乘数
  50 + * @param v2 乘数
  51 + * @return 两个参数的积
  52 + */
  53 + public static double mul(Object v1,Object v2){
  54 + BigDecimal b1 = new BigDecimal(String.valueOf(v1));
  55 + BigDecimal b2 = new BigDecimal(String.valueOf(v2));
  56 + return b1.multiply(b2).doubleValue();
  57 + }
  58 +
  59 + /**
  60 + * 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到
  61 + * 小数点以后10位,以后的数字四舍五入。
  62 + * @param v1 被除数
  63 + * @param v2 除数
  64 + * @return 两个参数的商
  65 + */
  66 + public static double div(Object v1,Object v2){
  67 + return div(v1,v2,DEF_DIV_SCALE);
  68 + }
  69 +
  70 + /**
  71 + * 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指
  72 + * 定精度,以后的数字四舍五入。
  73 + * @param v1 被除数
  74 + * @param v2 除数
  75 + * @param scale 表示表示需要精确到小数点以后几位。
  76 + * @return 两个参数的商
  77 + */
  78 + public static double div(Object v1,Object v2,int scale){
  79 + if(scale<0){
  80 + throw new IllegalArgumentException(
  81 + "The scale must be a positive integer or zero");
  82 + }
  83 + BigDecimal b1 = new BigDecimal(String.valueOf(v1));
  84 + BigDecimal b2 = new BigDecimal(String.valueOf(v2));
  85 + return b1.divide(b2,scale,BigDecimal.ROUND_HALF_UP).doubleValue();
  86 + }
  87 +
  88 + /**
  89 + * 提供精确的小数位四舍五入处理。
  90 + * @param v 需要四舍五入的数字
  91 + * @param scale 小数点后保留几位
  92 + * @return 四舍五入后的结果
  93 + */
  94 + public static double round(Object v,int scale){
  95 + if(scale<0){
  96 + throw new IllegalArgumentException(
  97 + "The scale must be a positive integer or zero");
  98 + }
  99 + BigDecimal b = new BigDecimal(String.valueOf(v));
  100 + BigDecimal one = new BigDecimal("1");
  101 + return b.divide(one,scale,BigDecimal.ROUND_HALF_UP).doubleValue();
  102 + }
  103 +
  104 + /**
  105 + * 提供精确的类型转换(Float)
  106 + * @param v 需要被转换的数字
  107 + * @return 返回转换结果
  108 + */
  109 + public static float convertsToFloat(double v){
  110 + BigDecimal b = new BigDecimal(v);
  111 + return b.floatValue();
  112 + }
  113 +
  114 + /**
  115 + * 提供精确的类型转换(Int)不进行四舍五入
  116 + * @param v 需要被转换的数字
  117 + * @return 返回转换结果
  118 + */
  119 + public static int convertsToInt(double v){
  120 + BigDecimal b = new BigDecimal(v);
  121 + return b.intValue();
  122 + }
  123 +
  124 + /**
  125 + * 提供精确的类型转换(Long)
  126 + * @param v 需要被转换的数字
  127 + * @return 返回转换结果
  128 + */
  129 + public static long convertsToLong(double v){
  130 + BigDecimal b = new BigDecimal(v);
  131 + return b.longValue();
  132 + }
  133 +
  134 + /**
  135 + * 返回两个数中大的一个值
  136 + * @param v1 需要被对比的第一个数
  137 + * @param v2 需要被对比的第二个数
  138 + * @return 返回两个数中大的一个值
  139 + */
  140 + public static double returnMax(double v1,double v2){
  141 + BigDecimal b1 = new BigDecimal(v1);
  142 + BigDecimal b2 = new BigDecimal(v2);
  143 + return b1.max(b2).doubleValue();
  144 + }
  145 +
  146 + /**
  147 + * 返回两个数中小的一个值
  148 + * @param v1 需要被对比的第一个数
  149 + * @param v2 需要被对比的第二个数
  150 + * @return 返回两个数中小的一个值
  151 + */
  152 + public static double returnMin(double v1,double v2){
  153 + BigDecimal b1 = new BigDecimal(v1);
  154 + BigDecimal b2 = new BigDecimal(v2);
  155 + return b1.min(b2).doubleValue();
  156 + }
  157 +
  158 + /**
  159 + * 精确对比两个数字
  160 + * @param v1 需要被对比的第一个数
  161 + * @param v2 需要被对比的第二个数
  162 + * @return 如果两个数一样则返回0,如果第一个数比第二个数大则返回1,反之返回-1
  163 + */
  164 + public static int compareTo(double v1,double v2){
  165 + BigDecimal b1 = new BigDecimal(v1);
  166 + BigDecimal b2 = new BigDecimal(v2);
  167 + return b1.compareTo(b2);
  168 + }
  169 +
  170 +}
0 171 \ No newline at end of file
... ...
src/main/java/com/bsth/util/ConfigUtil.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/util/ConfigUtil.java
  1 +package com.bsth.util;
  2 +
  3 +public class ConfigUtil {
  4 +
  5 + static Tools tools;
  6 +
  7 + static{
  8 + tools = new Tools("application.properties");
  9 + String active = tools.getValue("spring.profiles.active");
  10 + tools = new Tools("application-"+active+".properties");
  11 + }
  12 +
  13 + public static String get(String key){
  14 + return tools.getValue(key);
  15 + }
  16 +}
... ...
src/main/java/com/bsth/util/Tools.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/util/Tools.java
  1 +package com.bsth.util;
  2 +
  3 +import java.io.IOException;
  4 +import java.util.Properties;
  5 +
  6 +public class Tools {
  7 + private static Properties p = new Properties();
  8 + private static String f;
  9 + public Tools(String file){
  10 + f = file;
  11 + try {
  12 + p.load(Tools.class.getClassLoader().getResourceAsStream(f));
  13 + } catch (IOException e) {
  14 + e.printStackTrace();
  15 + }
  16 + }
  17 +
  18 + /**
  19 + * 根据key得到value的值
  20 + */
  21 + public String getValue(String key)
  22 + {
  23 + return p.getProperty(key);
  24 + }
  25 +}
... ...
src/main/resources/application.properties 0 → 100644
  1 +++ a/src/main/resources/application.properties
  1 +server.port=12580
  2 +management.port= 9001
  3 +management.address= 127.0.0.1
... ...
src/main/resources/banner.txt 0 → 100644
  1 +++ a/src/main/resources/banner.txt
  1 + ____ _____ _______ _ _
  2 + | _ \ / ____| |__ __| | | | |
  3 + | |_) | | (___ | | | |__| |
  4 + | _ < \___ \ | | | __ |
  5 + | |_) | ____) | | | | | | |
  6 + |____/ |_____/ |_| |_| |_|
  7 +
  8 +Running Spring Boot ${spring-boot.version}
0 9 \ No newline at end of file
... ...
src/main/resources/logback.xml 0 → 100644
  1 +++ a/src/main/resources/logback.xml
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/2002/xmlspec/dtd/2.10/xmlspec.dtd"> -->
  3 +<configuration>
  4 +
  5 + <property name="LOG_BASE" value="D:/gps_client_logs" />
  6 + <!--<property name="LOG_BASE" value="/u04/gps_client_logs" />-->
  7 + <!-- 控制台输出 -->
  8 + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
  9 +
  10 + <layout class="ch.qos.logback.classic.PatternLayout">
  11 + <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
  12 + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level-%msg%n
  13 + </pattern>
  14 + </layout>
  15 + </appender>
  16 +
  17 + <!-- 浦东网关 -->
  18 + <appender name="PD_FILE"
  19 + class="ch.qos.logback.core.rolling.RollingFileAppender">
  20 + <file>${LOG_BASE}/pd/data.log</file>
  21 + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  22 + <fileNamePattern>${LOG_BASE}/pd/data-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  23 + <timeBasedFileNamingAndTriggeringPolicy
  24 + class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
  25 + <maxFileSize>500MB</maxFileSize>
  26 + </timeBasedFileNamingAndTriggeringPolicy>
  27 + </rollingPolicy>
  28 + <encoder>
  29 + <pattern>%msg%n</pattern>
  30 + </encoder>
  31 +
  32 + <layout class="ch.qos.logback.classic.PatternLayout">
  33 + <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
  34 + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level-%msg%n
  35 + </pattern>
  36 + </layout>
  37 + </appender>
  38 +
  39 + <!-- 浦东转发 -->
  40 + <appender name="PF_FILE"
  41 + class="ch.qos.logback.core.rolling.RollingFileAppender">
  42 + <file>${LOG_BASE}/pf/data.log</file>
  43 + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  44 + <fileNamePattern>${LOG_BASE}/pf/data-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  45 + <timeBasedFileNamingAndTriggeringPolicy
  46 + class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
  47 + <maxFileSize>500MB</maxFileSize>
  48 + </timeBasedFileNamingAndTriggeringPolicy>
  49 + </rollingPolicy>
  50 + <encoder>
  51 + <pattern>%msg%n</pattern>
  52 + </encoder>
  53 +
  54 + <layout class="ch.qos.logback.classic.PatternLayout">
  55 + <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
  56 + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level-%msg%n
  57 + </pattern>
  58 + </layout>
  59 + </appender>
  60 +
  61 +
  62 + <!-- 日志输出级别 -->
  63 + <root level="info">
  64 + <appender-ref ref="STDOUT" />
  65 + <appender-ref ref="FILE" />
  66 + </root>
  67 +</configuration>
0 68 \ No newline at end of file
... ...
src/main/resources/static/favicon.ico 0 → 100644
No preview for this file type
src/main/resources/static/index.html 0 → 100644
  1 +++ a/src/main/resources/static/index.html
  1 +<!DOCTYPE html>
  2 +<html>
  3 +<head>
  4 + <title>调度系统营运数据接口</title>
  5 + <meta charset="utf-8">
  6 + <meta http-equiv="Expires" content="0">
  7 + <meta http-equiv="Pragma" content="no-cache">
  8 + <meta http-equiv="Cache-control" content="no-cache">
  9 + <meta http-equiv="Cache" content="no-cache">
  10 + <link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.2.0/css/bootstrap.min.css">
  11 + <link rel="stylesheet" href="/simple_switch/simple.switch.three.css">
  12 + <style>
  13 + .table-wrap {
  14 + height: 500px;
  15 + overflow: auto;
  16 + }
  17 +
  18 + #line2SysListTable .Switch_FlatRadius .SwitchLine:before {
  19 + content: "老系统";
  20 + }
  21 +
  22 + #line2SysListTable .Switch_FlatRadius .SwitchLine:after {
  23 + content: "新系统";
  24 + }
  25 +
  26 + #line2SysListTable .Switch_FlatRadius {
  27 + width: 118px;
  28 + }
  29 +
  30 + #line2SysListTable .Switch_FlatRadius .SwitchButton {
  31 + width: 52px;
  32 + }
  33 +
  34 + #line2SysListTable .Switch_FlatRadius .SwitchButton:before {
  35 + left: 18px;
  36 + }
  37 +
  38 + #line2SysListTable .Switch_FlatRadius .SwitchButton:after {
  39 + left: 30px;
  40 + }
  41 +
  42 + #line2SysListTable .Switch_FlatRadius.On .SwitchButton {
  43 + left: 60px;
  44 + }
  45 + </style>
  46 +</head>
  47 +
  48 +<body>
  49 +
  50 +<div class="row" style="margin: 15px;">
  51 + <div class="col-md-12 well">
  52 + <h4>Available SOAP services: <a href="/webservice" target="_blank">/webservice</a></h4>
  53 + <h4>WSDL: <a href="/webservice/CompanyService?wsdl" target="_blank">/webservice/CompanyService?wsdl</a></h4>
  54 + </div>
  55 +
  56 + <div class="col-lg-4 col-md-6 col-sm-12">
  57 + <div class="bs-example" data-example-id="panel-without-body-with-table">
  58 + <div class="panel panel-default">
  59 + <!-- Default panel contents -->
  60 + <div class="panel-heading">线路清单</div>
  61 + <div class="panel-body">
  62 + <p style="color: #ff2727;">
  63 + 屏蔽新老系统的底层数据差异,对外提供统一的数据输出
  64 + </p>
  65 + <p>
  66 + 1、使用员工号查询数据时,系统将参考 “线路人员配置” 以确定人员所在线路。
  67 + </p>
  68 + <p>
  69 + 2、使用公司编码查询数据时,系统将参考 “线路基础信息” 里的公司编码。
  70 + </p>
  71 + </div>
  72 + <div class="table-wrap">
  73 + <table class="table" id="line2SysListTable">
  74 + <thead>
  75 + <tr>
  76 + <th>线路编码</th>
  77 + <th>线路名称</th>
  78 + <th>数据来源</th>
  79 + </tr>
  80 + </thead>
  81 + <tbody>
  82 + </tbody>
  83 + </table>
  84 + </div>
  85 + </div>
  86 + </div>
  87 + </div>
  88 +
  89 + <div class="col-lg-8 col-md-6 col-sm-12">
  90 + <div class="bs-example">
  91 + <div class="panel panel-default">
  92 + <div class="panel-heading">接口调试工具</div>
  93 + <div style="padding: 15px;margin-top: 15px;">
  94 + <form class="form-inline">
  95 + <div class="form-group">
  96 + <label>函数</label>
  97 + <select class="form-control">
  98 + <option value="returnCCInfo">returnCCInfo(获取出场班次信息)</option>
  99 + <option value="returnJCInfo">returnJCInfo(获取进场班次信息)</option>
  100 + </select>
  101 + </div>
  102 + &nbsp;
  103 + <div class="form-group">
  104 + <label>公司编码</label>
  105 + <select class="form-control">
  106 + <option value="55">55(上南)</option>
  107 + <option value="22">22(金高)</option>
  108 + <option value="05">05(杨高)</option>
  109 + <option value="26">26(南汇)</option>
  110 + </select>
  111 + </div>
  112 + &nbsp;
  113 + <div class="form-group">
  114 + <label>日期</label>
  115 + <input type="date" class="form-control" style="width: 150px;" required>
  116 + </div>
  117 + <button type="submit" class="btn btn-primary">获取数据</button>
  118 +
  119 + <textarea class="form-control" rows="25" style="width: 100%;margin-top: 25px;"></textarea>
  120 + </form>
  121 +
  122 + </div>
  123 + </div>
  124 + </div>
  125 + </div>
  126 +</div>
  127 +
  128 +<script id="line2sys-table-list-temp" type="text/html">
  129 + {{each list as obj i}}
  130 + <tr data-id="{{obj.lineCode}}" data-name="{{obj.lineName}}" {{if obj.new}}class="warning" {{/if}} >
  131 + <td>{{obj.lineCode}}</td>
  132 + <td>{{obj.lineName}}</td>
  133 + <td>
  134 + <input type="checkbox" {{if obj.new}}checked{{/if}} />
  135 + </td>
  136 + </tr>
  137 + {{/each}}
  138 +</script>
  139 +
  140 +<script src="http://apps.bdimg.com/libs/jquery/1.8.3/jquery.min.js"></script>
  141 +<script src="http://apps.bdimg.com/libs/bootstrap/3.2.0/js/bootstrap.min.js"></script>
  142 +<script src="/assets/js/template.js"></script>
  143 +<script src="/simple_switch/simple.switch.min.js"></script>
  144 +
  145 +<script>
  146 +
  147 + //线路清单
  148 + !function () {
  149 + var f = arguments.callee;
  150 + $.get('/line2System/all', function (list) {
  151 + list.sort(function (a, b) {
  152 + return b.new - a.new;
  153 + });
  154 + var htmlStr = template('line2sys-table-list-temp', {list: list});
  155 + $('#line2SysListTable tbody').html(htmlStr);
  156 +
  157 + $('input[type=checkbox]').simpleSwitch({
  158 + "theme": "FlatRadius"
  159 + });
  160 +
  161 + $('input[type=checkbox]').on('change', function () {
  162 + var $tr = $(this).parents('tr');
  163 + var data = {
  164 + lineCode: $tr.data('id'),
  165 + lineName: $tr.data('name'),
  166 + new: this.checked
  167 + }
  168 +
  169 + $.post('/line2System/update', data, function (rs) {
  170 + var $tr = $('#line2SysListTable tr[data-id=' + rs.lineCode + ']');
  171 + $tr.attr('class', rs.new ? 'warning' : '');
  172 + });
  173 + });
  174 + });
  175 + }();
  176 +
  177 +</script>
  178 +</body>
  179 +</html>
0 180 \ No newline at end of file
... ...