Commit 989070a501d6afec7d96f0e390bf18c3ae0f2cff

Authored by 王通
0 parents

1.init commit

pom.xml 0 → 100644
  1 +++ a/pom.xml
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4 + <modelVersion>4.0.0</modelVersion>
  5 + <parent>
  6 + <groupId>org.springframework.boot</groupId>
  7 + <artifactId>spring-boot-starter-parent</artifactId>
  8 + <version>2.2.2.RELEASE</version>
  9 + <relativePath/> <!-- lookup parent from repository -->
  10 + </parent>
  11 + <groupId>com.bsth</groupId>
  12 + <artifactId>control4cloud</artifactId>
  13 + <packaging>jar</packaging>
  14 + <version>0.0.1-SNAPSHOT</version>
  15 + <name>control4cloud</name>
  16 + <description>control4cloud</description>
  17 +
  18 + <dependencies>
  19 + <dependency>
  20 + <groupId>org.springframework.boot</groupId>
  21 + <artifactId>spring-boot-starter-web</artifactId>
  22 + </dependency>
  23 +
  24 + <dependency>
  25 + <groupId>mysql</groupId>
  26 + <artifactId>mysql-connector-java</artifactId>
  27 + <scope>runtime</scope>
  28 + </dependency>
  29 +
  30 + <dependency>
  31 + <groupId>org.springframework.boot</groupId>
  32 + <artifactId>spring-boot-starter-test</artifactId>
  33 + <scope>test</scope>
  34 + <exclusions>
  35 + <exclusion>
  36 + <groupId>org.junit.vintage</groupId>
  37 + <artifactId>junit-vintage-engine</artifactId>
  38 + </exclusion>
  39 + </exclusions>
  40 + </dependency>
  41 +
  42 + <dependency>
  43 + <groupId>org.springframework.boot</groupId>
  44 + <artifactId>spring-boot-starter-jdbc</artifactId>
  45 + </dependency>
  46 +
  47 + <dependency>
  48 + <groupId>joda-time</groupId>
  49 + <artifactId>joda-time</artifactId>
  50 + </dependency>
  51 + </dependencies>
  52 +
  53 + <build>
  54 + <plugins>
  55 + <plugin>
  56 + <groupId>org.springframework.boot</groupId>
  57 + <artifactId>spring-boot-maven-plugin</artifactId>
  58 + </plugin>
  59 + </plugins>
  60 + </build>
  61 +
  62 +</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 +
  6 +/**
  7 + * @author Hill
  8 + */
  9 +@SpringBootApplication
  10 +public class Application {
  11 +
  12 + public static void main(String[] args) {
  13 + SpringApplication.run(Application.class, args);
  14 + }
  15 +}
src/main/java/com/bsth/utils/CallBack.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/utils/CallBack.java
  1 +package com.bsth.utils;
  2 +
  3 +import java.util.List;
  4 +import java.util.Map;
  5 +
  6 +/**
  7 + * @author hill
  8 + * @date
  9 + */
  10 +public interface CallBack {
  11 +
  12 + public void success(byte[] bytes, Map<String, List<String>> header);
  13 +
  14 + public void failed();
  15 +
  16 +}
src/main/java/com/bsth/utils/HttpUtils.java 0 → 100644
  1 +++ a/src/main/java/com/bsth/utils/HttpUtils.java
  1 +package com.bsth.utils;
  2 +
  3 +import org.apache.tomcat.util.http.fileupload.IOUtils;
  4 +import org.slf4j.Logger;
  5 +import org.slf4j.LoggerFactory;
  6 +
  7 +import java.io.ByteArrayOutputStream;
  8 +import java.io.IOException;
  9 +import java.io.InputStream;
  10 +import java.io.OutputStream;
  11 +import java.net.HttpURLConnection;
  12 +import java.net.URL;
  13 +import java.util.HashMap;
  14 +import java.util.List;
  15 +import java.util.Map;
  16 +
  17 +/**
  18 + * @author hill
  19 + * @date
  20 + */
  21 +public class HttpUtils {
  22 +
  23 + private final static Logger log = LoggerFactory.getLogger(HttpUtils.class);
  24 +
  25 + public static void request(String url) {
  26 + request(url, new CallBack() {
  27 + @Override
  28 + public void success(byte[] bytes, Map<String, List<String>> header) {
  29 +
  30 + }
  31 +
  32 + @Override
  33 + public void failed() {
  34 +
  35 + }
  36 + });
  37 + }
  38 +
  39 + public static void request(String url, CallBack cb) {
  40 + request(url, cb, "GET");
  41 + }
  42 +
  43 + public static void request(String url, CallBack cb, String method) {
  44 + request(url, cb, method, new HashMap<>());
  45 + }
  46 +
  47 + public static void request(String url, CallBack cb, String method, Map<String, String> header) {
  48 + request(url, cb, method, header, new HashMap<>());
  49 + }
  50 +
  51 + public static void request(String url, CallBack cb, String method, Map<String, String> header, Map<String, Object> param) {
  52 + InputStream in = null;
  53 + OutputStream out = null;
  54 + HttpURLConnection con = null;
  55 + long start = System.currentTimeMillis();
  56 + try {
  57 + con = (HttpURLConnection)new URL(url).openConnection();
  58 + con.setRequestMethod(method);
  59 + con.setRequestProperty("keep-alive", "true");
  60 + con.setRequestProperty("accept", "application/json");
  61 + con.setRequestProperty("content-type", "application/json");
  62 + con.setDoInput(true);
  63 + con.setDoOutput(true);
  64 + con.setReadTimeout(5000);
  65 + con.setConnectTimeout(5000);
  66 +
  67 + if (header.size() > 0) {
  68 + for (Map.Entry<String, String> entry : header.entrySet()) {
  69 + con.setRequestProperty(entry.getKey(), entry.getValue());
  70 + }
  71 + }
  72 +
  73 + if (param.size() > 0) {
  74 + out = con.getOutputStream();
  75 + StringBuilder sb = new StringBuilder();
  76 + for (Map.Entry<String, Object> entry : param.entrySet()) {
  77 + sb.append("&").append(entry.getKey()).append("=").append(entry.getValue());
  78 + }
  79 + out.write(sb.substring(1).getBytes("UTF-8"));
  80 + out.flush();
  81 + }
  82 +
  83 + in = con.getInputStream();
  84 + ByteArrayOutputStream bout = new ByteArrayOutputStream();
  85 + IOUtils.copy(in, bout); bout.close();
  86 + if (con.getResponseCode() == 200) {
  87 + cb.success(bout.toByteArray(), con.getHeaderFields());
  88 + } else {
  89 + log.info(new String(bout.toByteArray()));
  90 + cb.failed();
  91 + }
  92 + } catch (IOException e) {
  93 + // TODO Auto-generated catch block
  94 + log.error("cost:" + (System.currentTimeMillis() - start));
  95 + log.error("HttpUtils.request异常", e);
  96 + cb.failed();
  97 + } catch (Exception e) {
  98 + log.error("处理异常", e);
  99 + } finally {
  100 + con.disconnect();
  101 + try {
  102 + if (in != null) in.close();
  103 + if (out != null) out.close();
  104 + } catch (IOException e) {
  105 + // TODO Auto-generated catch block
  106 + e.printStackTrace();
  107 + }
  108 + }
  109 + }
  110 +}
src/main/resources/app.properties 0 → 100644
  1 +++ a/src/main/resources/app.properties
src/main/resources/application-dev.yml 0 → 100644
  1 +++ a/src/main/resources/application-dev.yml
  1 +server:
  2 + port: 10010
  3 +
  4 +management:
  5 + port: 9001
  6 + address: 127.0.0.1
  7 + security:
  8 + enabled: false
  9 + context-path: /manage
  10 +
  11 +#DATASOURCE
  12 +spring:
  13 + datasource:
  14 + driver-class-name: com.mysql.jdbc.Driver
  15 + url: jdbc:mysql://192.168.168.241/pd_control?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8
  16 + username: root
  17 + password: root2jsp
  18 + max-active: 100
  19 + max-idle: 8
  20 + min-idle: 8
  21 + initial-size: 5
  22 + test-on-borrow: true
  23 + test-on-connect: true
  24 + test-on-return: true
  25 + test-while-idle: true
  26 + validation-query: select 1
  27 +## gateway real data
  28 +http:
  29 + gps:
  30 + real:
  31 + url: http://114.80.178.12:18080/transport_server/rtgps/
0 \ No newline at end of file 32 \ No newline at end of file
src/main/resources/application-prod.yml 0 → 100644
  1 +++ a/src/main/resources/application-prod.yml
  1 +server:
  2 + port: 29088
  3 +
  4 +management:
  5 + port: 9001
  6 + address: 127.0.0.1
  7 + security:
  8 + enabled: false
  9 + context-path: /manage
  10 +
  11 +#DATASOURCE
  12 +spring:
  13 + datasource:
  14 + driver-class-name: com.mysql.jdbc.Driver
  15 + url: jdbc:mysql://10.10.200.121/control?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8
  16 + username: root
  17 + password: root2jsp
  18 + max-active: 100
  19 + max-idle: 8
  20 + min-idle: 8
  21 + initial-size: 5
  22 + test-on-borrow: true
  23 + test-on-connect: true
  24 + test-on-return: true
  25 + test-while-idle: true
  26 + validation-query: select 1
  27 +## gateway real data
  28 +http:
  29 + gps:
  30 + real:
  31 + url: http://10.10.200.79:8080/transport_server/rtgps/
0 \ No newline at end of file 32 \ No newline at end of file
src/main/resources/application.yml 0 → 100644
  1 +++ a/src/main/resources/application.yml
  1 +spring:
  2 + profiles:
  3 + active: dev
  4 + view:
  5 + suffix: .html
  6 +server:
  7 + session-timeout: -1
  8 +security:
  9 + basic:
  10 + enabled: false
  11 + compression:
  12 + enabled: true
  13 + mime-types: application/json,application/xml,text/html,text/xml,text/plain,text/javascript,text/css,application/javascript
  14 +hibernate:
  15 + jdbc:
  16 + batch_size: 50
  17 +
  18 +# \u4E0A\u4F20\u6587\u4EF6\u5927\u5C0F\u9650\u5236\u914D\u7F6E
  19 +# File size limit
  20 +multipart:
  21 + maxFileSize: -1
  22 +# Total request size for a multipart/form-data
  23 + maxRequestSize: -1
0 \ No newline at end of file 24 \ 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 +<!-- scan="true" 当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true。 -->
  3 +<!-- scanPeriod="30 seconds" 设置每30秒自动扫描,若没有指定具体单位则以milliseconds为标准(单位:milliseconds, seconds, minutes or hours) -->
  4 +<!-- debug="false"当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。-->
  5 +<configuration scan="true" scanPeriod="30 seconds">
  6 + <property name="LOG_BASE" value="D:/control4cloud_logs" />
  7 + <!-- 控制台输出 -->
  8 + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
  9 + <encoder>
  10 + <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
  11 + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level-%msg%n</pattern>
  12 + </encoder>
  13 + </appender>
  14 +
  15 + <!-- 主日志文件 -->
  16 + <appender name="FILE"
  17 + class="ch.qos.logback.core.rolling.RollingFileAppender">
  18 + <file>${LOG_BASE}/main/main.log</file>
  19 + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  20 + <fileNamePattern>${LOG_BASE}/main/main-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  21 + <timeBasedFileNamingAndTriggeringPolicy
  22 + class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
  23 + <maxFileSize>100MB</maxFileSize>
  24 + </timeBasedFileNamingAndTriggeringPolicy>
  25 + </rollingPolicy>
  26 + <encoder>
  27 + <pattern>%msg%n</pattern>
  28 + </encoder>
  29 +
  30 + <layout class="ch.qos.logback.classic.PatternLayout">
  31 + <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
  32 + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level-%msg%n
  33 + </pattern>
  34 + </layout>
  35 + </appender>
  36 +
  37 + <!-- 日志输出级别 -->
  38 + <root level="info">
  39 + <appender-ref ref="FILE" />
  40 + <appender-ref ref="STDOUT" />
  41 + </root>
  42 +
  43 +</configuration>
0 \ No newline at end of file 44 \ No newline at end of file