浏览代码

新增mock工程

konghl 4 年之前
父节点
当前提交
4b9cfc964f
共有 28 个文件被更改,包括 1884 次插入0 次删除
  1. 37 0
      ebc-mock-service/.gitignore
  2. 189 0
      ebc-mock-service/pom.xml
  3. 59 0
      ebc-mock-service/src/main/assembly/package.xml
  4. 33 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/MockApp.java
  5. 11 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/constants/MockConstant.java
  6. 56 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/controller/MockController.java
  7. 15 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/model/Data.java
  8. 30 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/model/DataPoint.java
  9. 18 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/model/EBCData.java
  10. 71 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/model/MockScenarioData.java
  11. 25 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/repository/MockScenarioDataRepository.java
  12. 70 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/service/impl/MockManageServiceImpl.java
  13. 234 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/service/impl/MockProcessImpl.java
  14. 30 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/service/interfaces/MockManageService.java
  15. 12 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/service/interfaces/MockProcess.java
  16. 48 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/utils/HexStringUtil.java
  17. 92 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/utils/KafkaProducerConfig.java
  18. 19 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/utils/MessageUtil.java
  19. 19 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/utils/SecurityConfigSEVEN.java
  20. 197 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/utils/makedata/MakeBeidouData.java
  21. 46 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/IpuTcpLongConnectClient.java
  22. 287 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/TcpLongConnectClient.java
  23. 77 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/TcpLongConnectClientHandler.java
  24. 27 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/message/DefaultMessageGeneration.java
  25. 19 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/message/IMessageGeneration.java
  26. 74 0
      ebc-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/message/MessageGenerationManager.java
  27. 55 0
      ebc-mock-service/src/main/resources/application.properties
  28. 34 0
      ebc-mock-service/src/test/resources/application.properties

+ 37 - 0
ebc-mock-service/.gitignore

@ -0,0 +1,37 @@
1
### Java template
2
# Compiled class file
3
*.class
4
5
# Log file
6
*.log
7
8
# BlueJ files
9
*.ctxt
10
11
# Mobile Tools for Java (J2ME)
12
.mtj.tmp/
13
14
# Package Files #
15
*.jar
16
*.war
17
*.ear
18
*.zip
19
*.tar.gz
20
*.rar
21
22
#eclipse
23
/.settings
24
/.classpath
25
/.project
26
27
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
28
hs_err_pid*
29
30
*.iml
31
.idea
32
target/
33
logs/
34
.DS_Store
35
36
37

+ 189 - 0
ebc-mock-service/pom.xml

@ -0,0 +1,189 @@
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0"
3
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
    <parent>
6
        <artifactId>components</artifactId>
7
        <groupId>com.ai.bss</groupId>
8
        <version>2.1.5-SNAPSHOT</version>
9
    </parent>
10
    <modelVersion>4.0.0</modelVersion>
11
12
    <artifactId>ebc-mock-service</artifactId>
13
14
    <name>ebc-mock-service</name>
15
16
    <dependencies>
17
        <dependency>
18
            <groupId>com.ai.abc</groupId>
19
            <artifactId>persistence-mysql8</artifactId>
20
            <version>2.1.5-SNAPSHOT</version>
21
            <exclusions>
22
                <exclusion>
23
                    <groupId>org.springframework.boot</groupId>
24
                    <artifactId>spring-boot-starter-security</artifactId>
25
                </exclusion>
26
            </exclusions>
27
        </dependency>
28
29
        <dependency>
30
            <groupId>com.ai.bss</groupId>
31
            <artifactId>components-common</artifactId>
32
            <version>2.1.5-SNAPSHOT</version>
33
            <scope>compile</scope>
34
        </dependency>
35
36
        <dependency>
37
            <groupId>com.ai.bss</groupId>
38
            <artifactId>infrastructure</artifactId>
39
            <version>2.1.5-SNAPSHOT</version>
40
            <scope>compile</scope>
41
        </dependency>
42
43
        <dependency>
44
            <groupId>org.springframework.kafka</groupId>
45
            <artifactId>spring-kafka</artifactId>
46
            <version>2.2.9.RELEASE</version>
47
        </dependency>
48
49
        <dependency>
50
            <groupId>org.springframework.boot</groupId>
51
            <artifactId>spring-boot-starter-test</artifactId>
52
            <version>${spring-boot.version}</version>
53
            <type>pom</type>
54
            <scope>test</scope>
55
        </dependency>
56
57
        <dependency>
58
            <groupId>com.ai.ipu</groupId>
59
            <artifactId>ipu-basic</artifactId>
60
            <version>3.1-SNAPSHOT</version>
61
            <exclusions>
62
                <exclusion>
63
                    <groupId>log4j</groupId>
64
                    <artifactId>log4j</artifactId>
65
                </exclusion>
66
                <exclusion>
67
                    <groupId>org.apache.logging</groupId>
68
                    <artifactId>log4j</artifactId>
69
                </exclusion>
70
                <exclusion>
71
                    <groupId>org.slf4j</groupId>
72
                    <artifactId>slf4j</artifactId>
73
                </exclusion>
74
            </exclusions>
75
        </dependency>
76
        <dependency>
77
            <groupId>com.ai.ipu</groupId>
78
            <artifactId>ipu-common</artifactId>
79
            <version>3.1-SNAPSHOT</version>
80
            <exclusions>
81
                <exclusion>
82
                    <groupId>org.apache.logging.log4j</groupId>
83
                    <artifactId>log4j-slf4j-impl</artifactId>
84
                </exclusion>
85
                <exclusion>
86
                    <groupId>dom4j</groupId>
87
                    <artifactId>dom4j</artifactId>
88
                </exclusion>
89
            </exclusions>
90
        </dependency>
91
92
    </dependencies>
93
94
95
    <build>
96
97
        <resources>
98
            <resource>
99
                <directory>src/main/resources</directory>
100
            </resource>
101
        </resources>
102
103
        <plugins>
104
105
            <!-- The configuration of maven-jar-plugin -->
106
            <plugin>
107
                <groupId>org.apache.maven.plugins</groupId>
108
                <artifactId>maven-jar-plugin</artifactId>
109
                <version>2.4</version>
110
                <!-- The configuration of the plugin -->
111
                <configuration>
112
                    <!-- Configuration of the archiver -->
113
                    <archive>
114
                        <!--生成的jar中,不要包含pom.xml和pom.properties这两个文件-->
115
                        <addMavenDescriptor>false</addMavenDescriptor>
116
117
                        <!-- Manifest specific configuration -->
118
                        <manifest>
119
                            <!--是否要把第三方jar放到manifest的classpath中-->
120
                            <addClasspath>true</addClasspath>
121
                            <!--生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/-->
122
                            <classpathPrefix>lib/</classpathPrefix>
123
                            <!--应用的main class-->
124
                            <mainClass>com.ai.bss.mock.MockApp</mainClass>
125
                        </manifest>
126
                        <manifestEntries>
127
                            <Class-Path>./config/</Class-Path>
128
                        </manifestEntries>
129
                    </archive>
130
                    <!--过滤掉不希望包含在jar中的文件-->
131
                    <excludes>
132
                        <exclude>**/*.properties</exclude>
133
                        <exclude>**/*.xml</exclude>
134
                    </excludes>
135
                </configuration>
136
            </plugin>
137
138
            <plugin>
139
                <groupId>org.apache.maven.plugins</groupId>
140
                <artifactId>maven-dependency-plugin</artifactId>
141
                <version>2.10</version>
142
                <executions>
143
                    <execution>
144
                        <id>copy-dependencies</id>
145
                        <phase>package</phase>
146
                        <goals>
147
                            <goal>copy-dependencies</goal>
148
                        </goals>
149
                        <configuration>
150
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
151
                        </configuration>
152
                    </execution>
153
                </executions>
154
            </plugin>
155
156
            <!-- The configuration of maven-assembly-plugin -->
157
            <plugin>
158
                <groupId>org.apache.maven.plugins</groupId>
159
                <artifactId>maven-assembly-plugin</artifactId>
160
                <version>2.4</version>
161
                <!-- The configuration of the plugin -->
162
                <configuration>
163
                    <!-- Specifies the configuration file of the assembly plugin -->
164
                    <descriptors>
165
                        <descriptor>src/main/assembly/package.xml</descriptor>
166
                    </descriptors>
167
                </configuration>
168
                <executions>
169
                    <execution>
170
                        <id>make-assembly</id>
171
                        <phase>package</phase>
172
                        <goals>
173
                            <goal>single</goal>
174
                        </goals>
175
                    </execution>
176
                </executions>
177
            </plugin>
178
179
            <plugin>
180
                <groupId>org.apache.maven.plugins</groupId>
181
                <artifactId>maven-surefire-plugin</artifactId>
182
                <configuration>
183
                    <skip>true</skip>
184
                </configuration>
185
            </plugin>
186
        </plugins>
187
188
    </build>
189
</project>

+ 59 - 0
ebc-mock-service/src/main/assembly/package.xml

@ -0,0 +1,59 @@
1
<assembly>
2
    <id>bin</id>
3
    <!-- 最终打包成一个用于发布的zip文件 -->
4
    <formats>
5
        <format>zip</format>
6
    </formats>
7
8
    <!-- Adds dependencies to zip package under lib directory -->
9
    <dependencySets>
10
        <dependencySet>
11
            <!-- 不使用项目的artifact,第三方jar不要解压,打包进zip文件的lib目录 -->
12
            <useProjectArtifact>false</useProjectArtifact>
13
            <outputDirectory>lib</outputDirectory>
14
            <unpack>false</unpack>
15
            <scope>runtime</scope>
16
        </dependencySet>
17
    </dependencySets>
18
19
    <fileSets>
20
        <!-- 把项目相关的说明文件,打包进zip文件的根目录 -->
21
        <fileSet>
22
            <directory>${project.basedir}</directory>
23
            <outputDirectory>/</outputDirectory>
24
        <includes>
25
            <include>README*</include>
26
            <include>LICENSE*</include>
27
            <include>NOTICE*</include>
28
        </includes>
29
    </fileSet>
30
31
        <!-- 把项目的配置文件,打包进zip文件的config目录 -->
32
        <fileSet>
33
            <directory>src/main/resources</directory>
34
            <outputDirectory>/config</outputDirectory>
35
            <includes>
36
                <include>**/*.properties</include>
37
                <include>**/*.xml</include>
38
            </includes>
39
        </fileSet>
40
41
        <!-- 把项目的脚本文件目录( src/main/scripts )中的启动脚本文件,打包进zip文件的跟目录 -->
42
        <fileSet>
43
            <directory>${project.build.scriptSourceDirectory}</directory>
44
            <outputDirectory></outputDirectory>
45
            <includes>
46
                <include>startup.*</include>
47
            </includes>
48
        </fileSet>
49
50
        <!-- 把项目自己编译出来的jar文件,打包进zip文件的根目录 -->
51
        <fileSet>
52
            <directory>${project.build.directory}</directory>
53
            <outputDirectory></outputDirectory>
54
            <includes>
55
                <include>*.jar</include>
56
            </includes>
57
        </fileSet>
58
    </fileSets>
59
</assembly>

+ 33 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/MockApp.java

@ -0,0 +1,33 @@
1
package com.ai.bss.mock;
2
3
import com.ai.bss.mock.utils.tcp.IpuTcpLongConnectClient;
4
import org.springframework.boot.SpringApplication;
5
import org.springframework.boot.autoconfigure.SpringBootApplication;
6
import org.springframework.boot.autoconfigure.domain.EntityScan;
7
import org.springframework.context.annotation.ComponentScan;
8
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
9
import org.springframework.scheduling.annotation.EnableAsync;
10
11
/**
12
 * @author zhangfeng
13
 */
14
15
@EnableJpaRepositories(basePackages = "com.ai.bss")
16
@EntityScan(basePackages = {"com.ai.bss","com.ai.abc"})
17
@ComponentScan(basePackages = {"com.ai.bss","com.ai.abc","com.ai.ipu"})
18
@EnableAsync
19
@SpringBootApplication
20
21
public class MockApp {
22
    private static final String HOST = "47.105.130.83";
23
    private static final int PORT = 8042;
24
25
    public static void main(String[] args) throws Exception {
26
27
//        IpuTcpLongConnectClient.getInstance(HOST, PORT).test();
28
29
        SpringApplication.run(MockApp.class, args);
30
31
32
    }
33
}

+ 11 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/constants/MockConstant.java

@ -0,0 +1,11 @@
1
package com.ai.bss.mock.constants;
2
3
import java.util.HashMap;
4
import java.util.Map;
5
6
public class MockConstant {
7
    public static Map MACK_STATUS = new HashMap();
8
9
10
    public static final String SPLIT_DASH = "-";
11
}

+ 56 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/controller/MockController.java

@ -0,0 +1,56 @@
1
package com.ai.bss.mock.controller;
2
3
4
import com.ai.bss.mock.constants.MockConstant;
5
import com.ai.bss.mock.service.interfaces.MockManageService;
6
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.stereotype.Controller;
10
import org.springframework.web.bind.annotation.RequestMapping;
11
import org.springframework.web.bind.annotation.RequestParam;
12
import org.springframework.web.bind.annotation.ResponseBody;
13
14
import java.util.Map;
15
16
/**
17
 * mock
18
 */
19
@Controller
20
@RequestMapping("/mock")
21
public class MockController {
22
23
    @Autowired
24
    MockManageService mockManageService;
25
26
    Logger logger = LoggerFactory.getLogger(MockController.class);
27
28
    /**
29
     * 查询mock执行状态
30
     */
31
    @ResponseBody
32
    @RequestMapping("/getMockStatus")
33
    public Map getMockStatus(){
34
        return mockManageService.findMockStatusByScenarioId();
35
    }
36
37
    /**
38
     * 查询历史轨迹查询
39
     */
40
    @ResponseBody
41
    @RequestMapping("/startMackData")
42
    public Object startMackData(@RequestParam Long sId,@RequestParam Long f,@RequestParam(required = false) String topic0 ,@RequestParam(required = false) String topic1 ) {
43
        return mockManageService.startMackData(sId,f,topic0,topic1);
44
    }
45
46
    /**
47
     * 查询历史轨迹查询
48
     */
49
    @ResponseBody
50
    @RequestMapping("/stopMackData")
51
    public Object stopMackData(@RequestParam Long sId){
52
        return mockManageService.stopMackData(sId);
53
    }
54
55
56
}

+ 15 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/model/Data.java

@ -0,0 +1,15 @@
1
package com.ai.bss.mock.model;
2
3
4
import lombok.Getter;
5
import lombok.Setter;
6
7
@Getter
8
@Setter
9
public class Data {
10
11
    private String unit;
12
    private String name;
13
    private String description;
14
    private String value;
15
}

+ 30 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/model/DataPoint.java

@ -0,0 +1,30 @@
1
package com.ai.bss.mock.model;
2
3
import lombok.Getter;
4
import lombok.Setter;
5
6
@Getter
7
@Setter
8
public class DataPoint {
9
    
10
    private String dataPointId;
11
    private String dataPointValue;
12
    private String detailInfo;
13
    private String eventSpecId;
14
    private String eventSpecName;
15
    private String eventTime;
16
    private String eventTimeStr;
17
    private String eventTypeName;
18
    private String messageTopic;
19
    private String messageTypeId;
20
    private String resourceId;
21
    private String resourceName;
22
    private String resourceSpecId;
23
    private String specName;
24
    private String subcriberPush;
25
    private String subscriberDataType;
26
    private String terminalEventId;
27
    private String pushTopic;
28
29
    private long orderNo;
30
}

+ 18 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/model/EBCData.java

@ -0,0 +1,18 @@
1
package com.ai.bss.mock.model;
2
3
4
import lombok.Getter;
5
import lombok.Setter;
6
7
@Getter
8
@Setter
9
public class EBCData {
10
11
    private Data orientation;
12
    private Data businessState;
13
    private Data latitude;
14
    private Data speed;
15
    private Data msgDate;
16
    private Data longitude;
17
    private Data alarmType;
18
}

+ 71 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/model/MockScenarioData.java

@ -0,0 +1,71 @@
1
package com.ai.bss.mock.model;
2
3
import lombok.Getter;
4
import lombok.NoArgsConstructor;
5
import lombok.Setter;
6
import org.hibernate.annotations.SQLDelete;
7
import org.hibernate.annotations.Where;
8
9
import javax.persistence.*;
10
import java.io.Serializable;
11
import java.sql.Timestamp;
12
13
14
@Entity
15
@Table( name="mock_scenario_data")
16
@NoArgsConstructor
17
@Getter
18
@Setter
19
public class MockScenarioData implements Serializable {
20
21
22
    @Id
23
    @GeneratedValue(strategy = GenerationType.AUTO)
24
    @Column(name="ID")
25
    private long id;
26
27
    //场景ID
28
    @Column(name="SCENARIO_ID")
29
    private long scenarioId;
30
31
    //场景ID
32
    @Column(name="DEVICE_ID")
33
    private String deviceId;
34
35
    //执行顺序
36
    @Column(name="ORDER_NO")
37
    private long orderNo;
38
39
    //经度
40
    @Column(name="LONGITUDE")
41
    private String longitude;
42
43
    //纬度
44
    @Column(name="LATITUDE")
45
    private String latitude;
46
47
    //速度
48
    @Column(name="SPEED")
49
    private String speed;
50
51
    //方位
52
    @Column(name="ORIENTATION")
53
    private String orientation;
54
55
    //时间
56
    @Column(name="TIME")
57
    private String time;
58
59
    //类型(0 定位;1 自动报警;2手动报警;4离线)
60
    @Column(name="TYPE")
61
    private String type;
62
63
    //类型(0 定位;1 自动报警;2手动报警;4离线)
64
    @Column(name="TOPIC")
65
    private String topic;
66
67
    //模拟数据-扩展json格式
68
    @Column(name="MOCK_DATA")
69
    private String mock_data;
70
71
}

+ 25 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/repository/MockScenarioDataRepository.java

@ -0,0 +1,25 @@
1
package com.ai.bss.mock.repository;
2
3
import com.ai.bss.mock.model.MockScenarioData;
4
import org.springframework.data.jpa.repository.JpaRepository;
5
import org.springframework.data.jpa.repository.Modifying;
6
import org.springframework.data.jpa.repository.Query;
7
import org.springframework.data.repository.query.Param;
8
import org.springframework.stereotype.Repository;
9
10
import java.io.Serializable;
11
import java.util.List;
12
13
@Repository
14
public interface MockScenarioDataRepository extends JpaRepository<MockScenarioData, Serializable> {
15
16
    List<MockScenarioData> findByScenarioIdOrderByOrderNo(Long scenarioId);
17
18
    @Modifying
19
    @Query(value = "select DISTINCT order_no from mock_scenario_data where scenario_id = :scenarioId order by order_no\n", nativeQuery = true)
20
    List<Long> findByOrderNoByScenarioId(@Param("scenarioId") Long scenarioId);
21
22
    
23
24
25
}

+ 70 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/service/impl/MockManageServiceImpl.java

@ -0,0 +1,70 @@
1
package com.ai.bss.mock.service.impl;
2
3
import com.ai.bss.mock.constants.MockConstant;
4
import com.ai.bss.mock.model.MockScenarioData;
5
import com.ai.bss.mock.repository.MockScenarioDataRepository;
6
import com.ai.bss.mock.service.interfaces.MockManageService;
7
import com.ai.bss.mock.service.interfaces.MockProcess;
8
import lombok.extern.slf4j.Slf4j;
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.stereotype.Service;
11
12
import java.util.ArrayList;
13
import java.util.HashMap;
14
import java.util.List;
15
import java.util.Map;
16
17
@Slf4j
18
@Service
19
public class MockManageServiceImpl implements MockManageService {
20
21
22
    @Autowired
23
    private MockScenarioDataRepository mockScenarioDataRepository;
24
    @Autowired
25
    private MockProcess mockProcess;
26
27
//    @Value("${kafka.producer.servers:Empty}")
28
    private static String kafkaServers = "47.105.160.21:9090";
29
30
    @Override
31
    public Map findMockStatusByScenarioId()  {
32
        List<Long> result = new ArrayList(MockConstant.MACK_STATUS.keySet());
33
        Map  tempmap = new HashMap();
34
        for(Long sid:result){
35
            tempmap.put(sid,"场景 "+sid+" 执行中...");
36
        }
37
        return tempmap;
38
    }
39
    @Override
40
    public String  startMackData(Long sId,  Long frequency,String topic0,String topic1)  {
41
        //        验证场景是否正在执行
42
        if(MockConstant.MACK_STATUS.get(sId)!=null){
43
            return "场景" + sId + " 正在执行,请耐心等待...";
44
        }
45
        //根据场景ID从数据库中查询模拟数据
46
        List<MockScenarioData>  mockScenarioDataList = mockScenarioDataRepository.findByScenarioIdOrderByOrderNo(sId);
47
48
        List<Long> orderNoList = mockScenarioDataRepository.findByOrderNoByScenarioId(sId);
49
        if(mockScenarioDataList==null || mockScenarioDataList.size()==0){
50
            return "场景" + sId + " 没有配置模拟 ,请在数据库中添加数据再执行...";
51
        }
52
        //记录场景执行状态
53
        MockConstant.MACK_STATUS.put(sId,frequency);
54
        //异步执行模拟场景 通过IOT-DMP连接服务模拟
55
//        mockProcess.processMock(sId,mockScenarioDataList,frequency);
56
57
        //异步执行模拟场景  直接模拟最终数据发送到kafka
58
        mockProcess.processMockKafka(sId,mockScenarioDataList,orderNoList,frequency,topic0, topic1);
59
60
        return "场景" + sId + " 开始执行...";
61
    }
62
63
64
    @Override
65
    public String  stopMackData(Long sId){
66
        MockConstant.MACK_STATUS.remove(sId);
67
        return "场景" + sId + " 终止执行...";
68
    }
69
70
}

+ 234 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/service/impl/MockProcessImpl.java

@ -0,0 +1,234 @@
1
package com.ai.bss.mock.service.impl;
2
3
import com.ai.bss.mock.constants.MockConstant;
4
import com.ai.bss.mock.model.Data;
5
import com.ai.bss.mock.model.DataPoint;
6
import com.ai.bss.mock.model.EBCData;
7
import com.ai.bss.mock.model.MockScenarioData;
8
import com.ai.bss.mock.service.interfaces.MockProcess;
9
import com.ai.bss.mock.utils.KafkaProducerConfig;
10
import com.ai.bss.mock.utils.tcp.IpuTcpLongConnectClient;
11
import com.alibaba.fastjson.JSONObject;
12
import lombok.extern.slf4j.Slf4j;
13
import org.springframework.context.annotation.Configuration;
14
import org.springframework.kafka.core.KafkaTemplate;
15
import org.springframework.scheduling.annotation.Async;
16
import org.springframework.stereotype.Service;
17
import org.springframework.util.StringUtils;
18
19
import java.util.ArrayList;
20
import java.util.HashMap;
21
import java.util.List;
22
import java.util.Map;
23
import java.util.concurrent.TimeUnit;
24
25
26
@Slf4j
27
@Configuration
28
@Service
29
public class MockProcessImpl implements MockProcess {
30
//    EBC设备tcp连接服务地址
31
    private static final String HOST = "47.105.130.83";
32
    private static final int PORT = 8042;
33
34
35
//    @Value("${kafka.producer.servers:Empty}")
36
//    private static String kafkaServers;
37
    private static String kafkaServers = "47.105.160.21:9090";
38
39
40
    @Async
41
    @Override
42
    public void processMock(Long sId,List<MockScenarioData> mockScenarioDataList, Long frequency){
43
        try {
44
            IpuTcpLongConnectClient.getInstance(HOST, PORT).sendMockData(sId,mockScenarioDataList, frequency);
45
46
            MockConstant.MACK_STATUS.remove(sId);
47
        }catch (Exception e){
48
            e.printStackTrace();
49
        }
50
    }
51
52
53
    @Async
54
    @Override
55
    public void processMockKafka(Long sId,List<MockScenarioData> mockScenarioDataList,List<Long> orderNoList, Long frequency,String topic0,String topic1){
56
        List<DataPoint> dataPointList =  parseDataPoint(mockScenarioDataList,topic0,topic1);
57
58
        try {
59
            for (Long orderNo : orderNoList) {
60
                for (DataPoint dataPoint : dataPointList) {
61
                    if (dataPoint.getOrderNo() == orderNo) {
62
                        sendKafkaDataPoint(dataPoint);
63
                    }
64
                }
65
66
                TimeUnit.MILLISECONDS.sleep(frequency * 1000);
67
            }
68
69
70
            MockConstant.MACK_STATUS.remove(sId);
71
        }catch (Exception e){
72
            e.printStackTrace();
73
        }
74
    }
75
76
77
    private List<DataPoint> parseDataPoint(List<MockScenarioData> mockScenarioDataList,String topic0,String topic1){
78
        List<DataPoint> dataPointList = new ArrayList<>();
79
        DataPoint dataPoint = new DataPoint();
80
81
        EBCData ebcData = new EBCData();
82
83
        Data data = new Data();
84
85
        if(mockScenarioDataList!=null){
86
            for(MockScenarioData mockScenarioData:mockScenarioDataList){
87
                dataPoint = new DataPoint();
88
                ebcData = new EBCData();
89
                dataPoint.setResourceId(mockScenarioData.getDeviceId());
90
                dataPoint.setResourceName(mockScenarioData.getDeviceId());
91
                dataPoint.setOrderNo(mockScenarioData.getOrderNo());
92
                if(mockScenarioData.getType().equals("0")){
93
                    dataPoint.setEventSpecName("定位");
94
                    dataPoint.setMessageTopic("DW");
95
                    dataPoint.setPushTopic(topic0);
96
                    if(StringUtils.isEmpty(dataPoint.getPushTopic())) {
97
                        dataPoint.setPushTopic(mockScenarioData.getTopic() == null ? "Topic_IoT_DeviceLocation" : mockScenarioData.getTopic());
98
                    }
99
                    if(mockScenarioData.getTime()!=null){
100
                        data = new Data();
101
                        data.setName("msgDate");
102
                        data.setDescription("报告时间");
103
                        data.setValue(mockScenarioData.getTime());
104
                        ebcData.setMsgDate(data);
105
                    }
106
                }else{
107
                    dataPoint.setEventSpecName("报警类型");
108
                    dataPoint.setMessageTopic("BJ");
109
110
                    dataPoint.setPushTopic(topic1);
111
                    if(StringUtils.isEmpty(dataPoint.getPushTopic())) {
112
                        dataPoint.setPushTopic(mockScenarioData.getTopic() == null ? "Topic_IoT_IndividualAlarm" : mockScenarioData.getTopic());
113
                    }
114
115
                    data = new Data();
116
                    data.setName("alarmType");
117
                    data.setDescription("报警类型");
118
                    data.setValue(mockScenarioData.getType());
119
                    ebcData.setAlarmType(data);
120
121
                    if(mockScenarioData.getTime()!=null){
122
                        data = new Data();
123
                        data.setName("msgDate");
124
                        data.setDescription("报警时间");
125
                        data.setValue(mockScenarioData.getTime());
126
                        ebcData.setMsgDate(data);
127
                    }
128
                }
129
130
131
                if(mockScenarioData.getLatitude()!=null){
132
                    data = new Data();
133
                    data.setName("latitude");
134
                    data.setDescription("纬度");
135
                    data.setValue(mockScenarioData.getLatitude());
136
                    data.setUnit("度");
137
                    ebcData.setLatitude(data);
138
                }
139
                if(mockScenarioData.getLongitude()!=null){
140
                    data = new Data();
141
                    data.setName("longitude");
142
                    data.setDescription("经度");
143
                    data.setValue(mockScenarioData.getLongitude());
144
                    data.setUnit("度");
145
                    ebcData.setLongitude(data);
146
                }
147
                if(mockScenarioData.getSpeed()!=null){
148
                    data = new Data();
149
                    data.setName("speed");
150
                    data.setDescription("速度");
151
                    data.setValue(mockScenarioData.getSpeed());
152
                    data.setUnit("米/秒");
153
                    ebcData.setSpeed(data);
154
                }
155
                if(mockScenarioData.getOrientation()!=null){
156
                    data = new Data();
157
                    data.setName("orientation");
158
                    data.setDescription("方位");
159
                    data.setValue(mockScenarioData.getOrientation());
160
                    data.setUnit("度");
161
                    ebcData.setOrientation(data);
162
                }
163
                dataPoint.setDataPointValue(JSONObject.toJSONString(ebcData));
164
                dataPointList.add(dataPoint);
165
            }
166
        }
167
        return dataPointList;
168
169
170
    }
171
172
    private Map<String, KafkaTemplate> kafkaTemplateMap = new HashMap<>();
173
174
175
    private boolean sendKafkamsg(List<DataPoint> dataPointList,Long frequency){
176
//        String kafkaServers = "";
177
        KafkaTemplate kafkaTemplate = kafkaTemplateMap.get(kafkaServers);
178
        if(kafkaTemplate == null){
179
            //new 实例
180
            KafkaProducerConfig kafkaProducerConfig = new KafkaProducerConfig(kafkaServers);
181
            kafkaTemplate = kafkaProducerConfig.kafkaTemplate();
182
            kafkaTemplateMap.put(kafkaServers,kafkaTemplate);
183
        }
184
        try {
185
            for(DataPoint dataPoint:dataPointList){
186
                Object result = kafkaTemplate.send(dataPoint.getPushTopic(), JSONObject.toJSONString(dataPoint)).get();
187
//                Object result = KafkaProducerConfig.sendForKafka(dataPoint.getPushTopic(), JSONObject.toJSONString(dataPoint));
188
                kafkaTemplate.flush();
189
                log.debug("It's successful send msg to Kafka:" + kafkaServers + "服务器地址以及topic:" + dataPoint.getPushTopic() + " 内容:" + JSONObject.toJSONString(dataPoint) + " 结果" + result);
190
191
                TimeUnit.MILLISECONDS.sleep(frequency*1000);
192
193
            }
194
        } catch (InterruptedException e) {
195
            e.printStackTrace();
196
            return false;
197
        } catch (Exception e) {
198
            e.printStackTrace();
199
            log.error(e.getMessage());
200
            return false;
201
        }
202
203
        return true;
204
    }
205
206
    private boolean sendKafkaDataPoint(DataPoint dataPoint){
207
//        String kafkaServers = "";
208
        KafkaTemplate kafkaTemplate = kafkaTemplateMap.get(kafkaServers);
209
        if(kafkaTemplate == null){
210
            //new 实例
211
            KafkaProducerConfig kafkaProducerConfig = new KafkaProducerConfig(kafkaServers);
212
            kafkaTemplate = kafkaProducerConfig.kafkaTemplate();
213
            kafkaTemplateMap.put(kafkaServers,kafkaTemplate);
214
        }
215
        try {
216
//            for(DataPoint dataPoint:dataPointList){
217
            Object result = kafkaTemplate.send(dataPoint.getPushTopic(), JSONObject.toJSONString(dataPoint)).get();
218
            kafkaTemplate.flush();
219
220
//                TimeUnit.MILLISECONDS.sleep(frequency*1000);
221
            log.debug("It's successful send msg to Kafka:" + kafkaServers + "服务器地址以及topic:" + dataPoint.getPushTopic() + " 内容:" + JSONObject.toJSONString(dataPoint) + " 结果" + result);
222
//            }
223
        } catch (InterruptedException e) {
224
            e.printStackTrace();
225
            return false;
226
        } catch (Exception e) {
227
            e.printStackTrace();
228
            log.error(e.getMessage());
229
            return false;
230
        }
231
232
        return true;
233
    }
234
}

+ 30 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/service/interfaces/MockManageService.java

@ -0,0 +1,30 @@
1
package com.ai.bss.mock.service.interfaces;
2
3
import com.ai.bss.mock.model.MockScenarioData;
4
5
import java.util.List;
6
import java.util.Map;
7
8
public interface MockManageService {
9
10
    /**
11
     * 查询当前正在 的场景
12
     * @return
13
     */
14
    Map findMockStatusByScenarioId();
15
16
    /**
17
     * 开始执行模拟数据
18
     * @param sId
19
     * @param f
20
     * @return
21
     */
22
    String  startMackData(Long sId,  Long f,String topic0,String topic1) ;
23
24
    /**
25
     * 停止执行模拟数据
26
     * @param sId
27
     * @return
28
     */
29
    String  stopMackData(Long sId);
30
}

+ 12 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/service/interfaces/MockProcess.java

@ -0,0 +1,12 @@
1
package com.ai.bss.mock.service.interfaces;
2
3
import com.ai.bss.mock.model.MockScenarioData;
4
5
import java.util.List;
6
7
public interface MockProcess {
8
    void processMock(Long sId,List<MockScenarioData> mockScenarioDataList, Long frequency);
9
10
11
    void processMockKafka(Long sId,List<MockScenarioData> mockScenarioDataList,List<Long> orderNoList, Long frequency,String topic0,String topic1);
12
}

+ 48 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/utils/HexStringUtil.java

@ -0,0 +1,48 @@
1
package com.ai.bss.mock.utils;
2
3
/**
4
 * 16进制转换工具类
5
 * */
6
public class HexStringUtil {
7
8
	/**
9
	 * 将16进制字符串转换为byte[]
10
	 */
11
	public static byte[] decodeHextoByte(String str) {
12
		if (str == null || str.trim().equals("")) {
13
			return new byte[0];
14
		}
15
		byte[] bytes = new byte[str.length() / 2];
16
		for (int i = 0; i < str.length() / 2; i++) {
17
			String subStr = str.substring(i * 2, i * 2 + 2);
18
			bytes[i] = (byte) Integer.parseInt(subStr, 16);
19
		}
20
		return bytes;
21
	}
22
23
	/**
24
	 * 将byte转换为16进制字符串
25
	 * @param b
26
	 * @return
27
	 */
28
	public static String decodeBytetoHexString(byte b) {
29
		return Integer.toHexString(b & 0xff);
30
	}
31
32
	/**
33
	 * 将byte数组转换为16进制字符串
34
	 * @param bs
35
	 * @return
36
	 */
37
	public static String decodeByteArraytoHexString(byte[] bs) {
38
		StringBuilder builder = new StringBuilder();
39
		for (int i = 0; i < bs.length; i++) {
40
			if (bs[i]<0x10 && bs[i]>=0) {
41
				builder.append("0");
42
			}
43
			builder.append(decodeBytetoHexString(bs[i]));
44
		}
45
		return builder.toString();
46
	}
47
48
}

+ 92 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/utils/KafkaProducerConfig.java

@ -0,0 +1,92 @@
1
package com.ai.bss.mock.utils;
2
3
import lombok.NoArgsConstructor;
4
import lombok.extern.slf4j.Slf4j;
5
import org.apache.kafka.clients.producer.ProducerConfig;
6
import org.apache.kafka.common.serialization.StringSerializer;
7
import org.springframework.beans.factory.annotation.Value;
8
import org.springframework.context.annotation.Bean;
9
import org.springframework.context.annotation.Configuration;
10
import org.springframework.kafka.annotation.EnableKafka;
11
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
12
import org.springframework.kafka.core.KafkaTemplate;
13
import org.springframework.kafka.core.ProducerFactory;
14
15
import java.util.HashMap;
16
import java.util.Map;
17
18
@Slf4j
19
@Configuration
20
@EnableKafka
21
@NoArgsConstructor
22
public class KafkaProducerConfig {
23
24
    @Value("${kafka.producer.servers:Empty}")
25
    private static String servers;
26
    @Value("${kafka.producer.retries:0}")
27
    private  int retries;
28
    @Value("${kafka.producer.batch.size:4096}")
29
    private  int batchSize;
30
    @Value("${kafka.producer.linger:1}")
31
    private  int linger;
32
    @Value("${kafka.producer.buffer.memory:40960}")
33
    private  int bufferMemory;
34
35
    private  int maxBlockTime = 60000;
36
37
    public KafkaProducerConfig(String inputServers){
38
        servers = inputServers;
39
        this.retries = 0;
40
        this.batchSize = 4096;
41
        this.linger = 1;
42
        this.bufferMemory = 40960;
43
        this.maxBlockTime = 6000;
44
45
    }
46
47
    public Map<String, Object> producerConfigs() {
48
        Map<String, Object> props = new HashMap<>();
49
        props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, servers);
50
        props.put(ProducerConfig.RETRIES_CONFIG, retries);
51
        props.put(ProducerConfig.BATCH_SIZE_CONFIG, batchSize);
52
        props.put(ProducerConfig.LINGER_MS_CONFIG, linger);
53
        props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, bufferMemory);
54
        props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
55
        props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
56
        props.put(ProducerConfig.MAX_BLOCK_MS_CONFIG,maxBlockTime);
57
        return props;
58
    }
59
60
    public ProducerFactory<String, String> producerFactory() {
61
        return new DefaultKafkaProducerFactory<>(producerConfigs());
62
    }
63
64
    @Bean
65
    public KafkaTemplate<String, String> kafkaTemplate() {
66
        return new KafkaTemplate<String, String>(producerFactory());
67
    }
68
//
69
    /**
70
     * 推送消息到订阅的KAFKA服务器地址以及topic
71
     * @param kafkaTopic  订阅的kafka topic
72
     * @param content  消息内容
73
     * @return
74
     */
75
    public static Boolean sendForKafka(String kafkaTopic,String content) {
76
        KafkaProducerConfig kafkaProducerConfig = new KafkaProducerConfig(servers);
77
        KafkaTemplate kafkaTemplate =  kafkaProducerConfig.kafkaTemplate();
78
79
80
        try {
81
            Object result = kafkaTemplate.send(kafkaTopic,content ).get();
82
            kafkaTemplate.flush();
83
        } catch (InterruptedException e) {
84
            log.error(e.getMessage());
85
            return false;
86
        } catch (Exception e) {
87
            log.error(e.getMessage());
88
            return false;
89
        }
90
        return true;
91
    }
92
}

+ 19 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/utils/MessageUtil.java

@ -0,0 +1,19 @@
1
package com.ai.bss.mock.utils;
2
3
4
public class MessageUtil {
5
    private MessageUtil() {
6
    }
7
8
    public static String getMessageKeyWord(String strContent) {
9
        return null;//  CommonConfig.hasBase64Flag() ? JSON.parseObject(new String(Base64.getDecoder().decode(strContent), StandardCharsets.UTF_8)).getString(CommonConfig.getMessageKeyWord()) : JSON.parseObject(strContent).getString(CommonConfig.getMessageKeyWord());
10
    }
11
12
    public static String getDecodeContent(String strContentEncode) {
13
        return null;//  CommonConfig.hasBase64Flag() ? new String(Base64.getDecoder().decode(strContentEncode), StandardCharsets.UTF_8) : strContentEncode;
14
    }
15
16
    public static String getEncodeContent(String strContent) {
17
        return null;// CommonConfig.hasBase64Flag() ? new String(Base64.getEncoder().encode(strContent.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8) : strContent;
18
    }
19
}

+ 19 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/utils/SecurityConfigSEVEN.java

@ -0,0 +1,19 @@
1
package com.ai.bss.mock.utils;
2
3
import org.springframework.context.annotation.Configuration;
4
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
5
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
6
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
7
8
@Configuration
9
@EnableWebSecurity
10
public class SecurityConfigSEVEN extends WebSecurityConfigurerAdapter {
11
12
    @Override
13
    protected void configure(HttpSecurity http) throws Exception {
14
        //super.configure(http);
15
        //配置不需要登陆验证
16
        http.authorizeRequests().anyRequest().permitAll().and().logout().permitAll();
17
    }
18
}
19

+ 197 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/utils/makedata/MakeBeidouData.java

@ -0,0 +1,197 @@
1
package com.ai.bss.mock.utils.makedata;
2
3
import com.ai.bss.mock.utils.HexStringUtil;
4
5
import java.math.BigDecimal;
6
import java.text.SimpleDateFormat;
7
import java.util.Calendar;
8
9
10
public class MakeBeidouData {
11
	/**
12
	 * 
13
	 * @param deviceId 设备ID
14
	 * @param type 类型(0 定位;1 自动报警;2手动报警;4离线)
15
	 * @param longitudeDouble 经度
16
	 * @param latitudeDouble 纬度
17
	 * @param dateString 时间
18
	 * @return
19
	 */
20
	public static String makeOneBeidouData(String deviceId, String type, String longitudeDouble, String latitudeDouble,String dateString) {
21
		return makeOneBeidouData(Integer.parseInt(deviceId), Integer.parseInt(type), Double.parseDouble(longitudeDouble), Double.parseDouble(latitudeDouble), dateString);
22
	}
23
	
24
	/**
25
	 * 
26
	 * @param deviceId 设备ID
27
	 * @param type 类型(0 定位;1 自动报警;2手动报警;4离线)
28
	 * @param longitudeDouble 经度
29
	 * @param latitudeDouble 纬度
30
	 * @param dateString 时间
31
	 * @return
32
	 */
33
	public static String makeOneBeidouData(int deviceId, int type, double longitudeDouble, double latitudeDouble,String dateString) {
34
		//时间
35
		String time = getHexDate(dateString);
36
		
37
		//经度
38
		String longitude="45"+getHexCoord(longitudeDouble);
39
		
40
		//纬度
41
		String latitude="4e"+getHexCoord(latitudeDouble);
42
		
43
		int speed = 0; // 速度
44
		int orientation = 0; // 方位
45
46
		StringBuilder sb = new StringBuilder();
47
		sb.append("2454585858002a02426c60").append(getHex(deviceId, 6)).append("000000b000");
48
		switch (type) {
49
		case 0:
50
			// 定位
51
			sb.append("b0").append(time).append(longitude).append(latitude);
52
			sb.append(getHex(speed)).append(getHex(orientation));
53
			sb.append("87");// 业务状态
54
			break;
55
		case 1:
56
			// 自动报警
57
			sb.append("a2").append(time).append("01").append(longitude).append(latitude);
58
			sb.append(getHex(speed)).append(getHex(orientation));
59
			break;
60
		case 2:
61
			// 手动报警
62
			sb.append("a2").append(time).append("02").append(longitude).append(latitude);
63
			sb.append(getHex(speed)).append(getHex(orientation));
64
			break;
65
		case 4:
66
			// 离线
67
			sb.append("a2").append(time).append("04").append(longitude).append(latitude);
68
			sb.append(getHex(speed)).append(getHex(orientation));
69
			break;
70
		default:
71
			break;
72
		}
73
74
		sb.append(xorCheck(sb.toString().substring(36)));
75
		sb.append("00");
76
		sb.append(xorCheck(sb.toString()));
77
78
		return sb.toString();
79
	}
80
81
	private static String getHexDate(String dateString) {
82
		try {
83
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
84
			 Calendar date = Calendar.getInstance();
85
			 date.setTime(sdf.parse(dateString));
86
		     String time = getHex(date.get(Calendar.YEAR) - 2000) + getHex(date.get(Calendar.MONTH) + 1) 
87
		        + getHex( date.get(Calendar.DAY_OF_MONTH)) + getHex(date.get(Calendar.HOUR_OF_DAY)) 
88
		        + getHex(date.get(Calendar.MINUTE)) + getHex(date.get(Calendar.SECOND));
89
		     return time;
90
		} catch (Exception e) {
91
			System.out.println(e.getMessage());
92
		}
93
		return "";
94
	}
95
	
96
	private static String getHexCoord(double data) {
97
		BigDecimal b1=new BigDecimal(String.valueOf(data));
98
		
99
		BigDecimal degreeBigDecimal=b1.setScale(0, BigDecimal.ROUND_DOWN);
100
		int degree=degreeBigDecimal.intValue();
101
		
102
		b1=b1.subtract(degreeBigDecimal).multiply(new BigDecimal("60"));
103
		BigDecimal minutesBigDecimal=b1.setScale(0, BigDecimal.ROUND_DOWN);
104
		int minutes=minutesBigDecimal.intValue();
105
		
106
		b1=b1.subtract(minutesBigDecimal).multiply(new BigDecimal("60"));
107
		BigDecimal secondBigDecimal=b1.setScale(0, BigDecimal.ROUND_DOWN);
108
		int second=secondBigDecimal.intValue();
109
		
110
		b1=b1.subtract(secondBigDecimal).multiply(new BigDecimal("10"));
111
		BigDecimal littleSecondBigDecimal=b1.setScale(0, BigDecimal.ROUND_HALF_UP);
112
		int littleSecond=littleSecondBigDecimal.intValue();
113
		
114
		String value=getHex(degree)+getHex(minutes)+getHex(second)+getHex(littleSecond);
115
		return value;
116
	}
117
	
118
	private static  String xorCheck(String data) {
119
		byte[] value = HexStringUtil.decodeHextoByte(data);
120
		byte result = 0;
121
		for (int i = 0; i < value.length; i++) {
122
			result ^= value[i];
123
		}
124
		return HexStringUtil.decodeBytetoHexString(result);
125
	}
126
127
	private static  String getHex(int data) {
128
		return getHex(data, 2);
129
	}
130
131
	private static  String getHex(int data, int len) {
132
		String result = Integer.toString(data, 16);
133
		if (result.length() < len) {
134
			StringBuilder sb = new StringBuilder();
135
			for (int i = 0; i < len - result.length(); i++) {
136
				sb.append("0");
137
			}
138
			sb.append(result);
139
			result = sb.toString();
140
		}
141
		return result;
142
	}
143
	
144
	
145
	public void test1111() {
146
		int deviceId = 318414; // 设备id
147
		int type = 4; // 0 定位;1 自动报警;2手动报警;4离线
148
		int year = 2020; // 年
149
		int month = 10; // 月
150
		int day = 16; // 日
151
		int hour = 10; // 时
152
		int minute = 50; // 分
153
		int second = 42; // 秒
154
		String longitude = "45762e0f00"; // 经度
155
		String latitude = "4e200e1608"; // 纬度
156
		int speed = 0; // 速度
157
		int orientation = 0; // 方位
158
		
159
		String time = getHex(year - 2000) + getHex(month) + getHex(day) + getHex(hour) + getHex(minute)
160
				+ getHex(second);
161
162
		StringBuilder sb = new StringBuilder();
163
		sb.append("2454585858002a02426c60").append(getHex(deviceId, 6)).append("000000b000");
164
		switch (type) {
165
		case 0:
166
			// 定位
167
			sb.append("b0").append(time).append(longitude).append(latitude);
168
			sb.append(getHex(speed)).append(getHex(orientation));
169
			sb.append("87");// 业务状态
170
			break;
171
		case 1:
172
			// 自动报警
173
			sb.append("a2").append(time).append("01").append(longitude).append(latitude);
174
			sb.append(getHex(speed)).append(getHex(orientation));
175
			break;
176
		case 2:
177
			// 手动报警
178
			sb.append("a2").append(time).append("02").append(longitude).append(latitude);
179
			sb.append(getHex(speed)).append(getHex(orientation));
180
			break;
181
		case 4:
182
			// 离线
183
			sb.append("a2").append(time).append("04").append(longitude).append(latitude);
184
			sb.append(getHex(speed)).append(getHex(orientation));
185
			break;
186
		default:
187
			break;
188
		}
189
190
		sb.append(xorCheck(sb.toString().substring(36)));
191
		sb.append("00");
192
		sb.append(xorCheck(sb.toString()));
193
194
		System.out.println(sb.toString());
195
	}
196
	
197
}

+ 46 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/IpuTcpLongConnectClient.java

@ -0,0 +1,46 @@
1
package com.ai.bss.mock.utils.tcp;
2
3
import com.ai.bss.mock.model.MockScenarioData;
4
import com.ai.bss.mock.utils.tcp.message.MessageGenerationManager;
5
6
import java.util.List;
7
8
/**
9
 * Ipu Tcp长连接测试
10
 *
11
 * @author lilb3@asiainfo.com
12
 * @since 2020-06-23
13
 **/
14
@SuppressWarnings("unused")
15
public class IpuTcpLongConnectClient {
16
    private static IpuTcpLongConnectClient ipuClient;
17
    private TcpLongConnectClient nettyClient;
18
19
    private IpuTcpLongConnectClient() {
20
21
    }
22
23
    public static IpuTcpLongConnectClient getInstance(String host, int serverPort) {
24
        if (ipuClient == null) {
25
            ipuClient = new IpuTcpLongConnectClient();
26
            ipuClient.nettyClient = new TcpLongConnectClient(host, serverPort, MessageGenerationManager.getMessage());
27
        }
28
        return ipuClient;
29
    }
30
31
    /**
32
     * Tcp长连接方式发送消息
33
     * @throws Exception 
34
     */
35
    public void test() throws Exception {
36
        nettyClient.test();
37
    }
38
39
    /**
40
     * Tcp长连接方式发送消息
41
     * @throws Exception
42
     */
43
    public void sendMockData(Long sId,List<MockScenarioData> mockScenarioDataList,Long frequency) throws Exception {
44
        nettyClient.sendMockData(sId,mockScenarioDataList,frequency);
45
    }
46
}

+ 287 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/TcpLongConnectClient.java

@ -0,0 +1,287 @@
1
package com.ai.bss.mock.utils.tcp;
2
3
import com.ai.bss.mock.constants.MockConstant;
4
import com.ai.bss.mock.model.MockScenarioData;
5
import com.ai.bss.mock.utils.HexStringUtil;
6
import com.ai.bss.mock.utils.makedata.MakeBeidouData;
7
import com.ai.ipu.common.date.TimeUtil;
8
import com.alibaba.fastjson.JSONObject;
9
import io.netty.bootstrap.Bootstrap;
10
import io.netty.buffer.Unpooled;
11
import io.netty.channel.*;
12
import io.netty.channel.nio.NioEventLoopGroup;
13
import io.netty.channel.socket.SocketChannel;
14
import io.netty.channel.socket.nio.NioSocketChannel;
15
import lombok.extern.slf4j.Slf4j;
16
import org.springframework.util.StringUtils;
17
18
import java.io.BufferedReader;
19
import java.io.InputStreamReader;
20
import java.util.List;
21
import java.util.concurrent.ScheduledExecutorService;
22
import java.util.concurrent.TimeUnit;
23
24
/**
25
 * Tcp长连接客户端
26
 *
27
 * @author lilb3@asiainfo.com
28
 * @since 2019-10-16
29
 **/
30
@Slf4j
31
class TcpLongConnectClient {
32
//	private static final ILogger LOGGER = IpuLoggerFactory.createLogger(TcpLongConnectClient.class);
33
	// private static final int PERIOD = 1;
34
	static final long PER_SLEEP_TIME = 2000L;
35
	// private static final int SEND_TIMES = 6;
36
	private final String host;
37
	private final int port;
38
	private final String message;
39
	private Channel channel;
40
	private ChannelFuture channelFuture;
41
	private Bootstrap bootstrap;
42
43
	TcpLongConnectClient(String host, int port, String message) {
44
		this.host = host;
45
		this.port = port;
46
		this.message = message;
47
	}
48
49
	/**
50
	 * 抽取出该方法 (断线重连时使用)
51
	 *
52
	 * @throws InterruptedException 异常
53
	 */
54
	void doConnect() throws InterruptedException {
55
		channelFuture = bootstrap.connect(host, port).sync();
56
		channel = channelFuture.channel();
57
	}
58
59
	public void test() throws Exception {
60
		EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
61
		bootstrap = new Bootstrap();
62
		bootstrap.group(eventLoopGroup);
63
		bootstrap.channel(NioSocketChannel.class);
64
		bootstrap.option(ChannelOption.SO_REUSEADDR, true);
65
		ScheduledExecutorService scheduledExecutorService;
66
		TcpLongConnectClient tcpLongConnectClient = this;
67
		bootstrap.handler(new ChannelInitializer<SocketChannel>() {
68
			@Override
69
			protected void initChannel(SocketChannel socketChannel) {
70
				// 消息最大长度:1*1024*1024=1M表示单条消息的最大长度
71
				// int maxFrameLength = 1*1024*1024;
72
				// netty基于分割符的自带解码器,根据提供的分隔符解析报文,这里是0x7e;
73
				// 解码器在查找分隔符的时候,达到该长度还没找到的话会抛异常
74
				// 设置分隔符为分号(###)
75
				// socketChannel.pipeline().addLast(new DelimiterBasedFrameDecoder(maxFrameLength,
76
				// Unpooled.copiedBuffer(TCP_DELIMITER.getBytes(StandardCharsets.UTF_8))));
77
				socketChannel.pipeline().addLast(new TcpLongConnectClientHandler(tcpLongConnectClient));
78
			}
79
		});
80
81
		// 连接Tcp服务器
82
		int count=1;
83
		try {
84
			doConnect();
85
86
			if (channelFuture.isSuccess()) {
87
88
				String sendMessage = null;
89
				String deviceId=null;
90
				String type=null; //类型(0 定位;1 自动报警;2手动报警;4离线) 
91
				String longitudeDouble=null;
92
				String latitudeDouble=null; 
93
				String dateString=null;
94
				while (count<50) {
95
					try {
96
					System.out.println("请输入第"+count+"条数据(设备ID,类型,经度,纬度,时间):");
97
					
98
					//建立从控制台输入的类  
99
					BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
100
					
101
					// 循环读取每行数据
102
					//while(true) {
103
					String parameters = stdin.readLine().trim();
104
					
105
					if (parameters==null||"".equals(parameters)) {
106
						continue;
107
						//break;
108
						
109
					}else if ("0".equals(parameters)) {
110
						//断开
111
						break;
112
						
113
					}else if ("1".equals(parameters)&&sendMessage!=null) {
114
						//重复发送
115
						dateString=TimeUtil.getSysTime();
116
						sendMessage = MakeBeidouData.makeOneBeidouData(deviceId, type, longitudeDouble, latitudeDouble, dateString);
117
						
118
					}else {
119
						String[] params=parameters.split(",");
120
						if (params.length==5) {//设备ID,类型,经度,纬度,时间
121
							deviceId=params[0].trim();
122
							type=params[1].trim();
123
							longitudeDouble=params[2].trim();
124
							latitudeDouble=params[3].trim();
125
							dateString=params[4].trim();
126
							sendMessage = MakeBeidouData.makeOneBeidouData(deviceId, type, longitudeDouble, latitudeDouble, dateString);
127
						}else if(params.length==4){//设备ID,类型,经度,纬度
128
							deviceId=params[0].trim();
129
							type=params[1].trim();
130
							longitudeDouble=params[2].trim();
131
							latitudeDouble=params[3].trim();
132
							dateString=TimeUtil.getSysTime();
133
							sendMessage = MakeBeidouData.makeOneBeidouData(deviceId, type, longitudeDouble, latitudeDouble, dateString);
134
						}else if(params.length==3){//类型,经度,纬度
135
							type=params[0].trim();
136
							longitudeDouble=params[1].trim();
137
							latitudeDouble=params[2].trim();
138
							dateString=TimeUtil.getSysTime();
139
							sendMessage = MakeBeidouData.makeOneBeidouData(deviceId, "0", longitudeDouble, latitudeDouble, dateString);
140
						}else if(params.length==2){//经度,纬度
141
							longitudeDouble=params[0].trim();
142
							latitudeDouble=params[1].trim();
143
							dateString=TimeUtil.getSysTime();
144
							sendMessage = MakeBeidouData.makeOneBeidouData(deviceId, "0", longitudeDouble, latitudeDouble, dateString);
145
						}else if(params.length==1&&parameters.startsWith("2454585858")){
146
							sendMessage = parameters;
147
						}else {
148
//							LOGGER.debug("输入错误");
149
							continue;
150
						}
151
					}
152
						
153
						String typeZh="";//类型(0 定位;1 自动报警;2手动报警;4离线) 
154
						switch (type) {
155
						case "0":
156
							typeZh="定位";
157
							break;
158
						case "1":
159
							typeZh="自动报警";
160
							break;
161
						case "2":
162
							typeZh="手动报警";
163
							break;
164
						case "4":
165
							typeZh="离线";
166
							break;
167
						default:
168
							break;
169
						}
170
					
171
						log.debug("设备("+deviceId+")的["+typeZh+"]数据: 经度="+longitudeDouble+",纬度="+latitudeDouble+",时间="+dateString);
172
						log.debug(String.format(count + ":Send Message: %s", sendMessage));
173
						//LOGGER.debug("send data:" + Arrays.toString(HexStringUtil.decodeHextoByte(sendMessage)));
174
175
						channel.writeAndFlush(Unpooled.copiedBuffer(HexStringUtil.decodeHextoByte(sendMessage)));
176
						count++;
177
						
178
						//TimeUnit.MILLISECONDS.sleep(PER_SLEEP_TIME);
179
					//}
180
					}catch (Exception e) {
181
						log.debug("输入错误,请重新输入");
182
					}
183
				}
184
			}
185
		} finally {
186
			try {
187
				if (null != channel) {
188
					channel.disconnect();
189
				}
190
			} catch (Exception e) {
191
				log.error("出现错误,连接断开");
192
			}
193
		}
194
		log.info("发送成功,共发送"+count+"条数据");
195
	}
196
	public void sendMockData(Long sId,List<MockScenarioData> mockScenarioDataList,Long frequency) throws Exception {
197
		EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
198
		bootstrap = new Bootstrap();
199
		bootstrap.group(eventLoopGroup);
200
		bootstrap.channel(NioSocketChannel.class);
201
		bootstrap.option(ChannelOption.SO_REUSEADDR, true);
202
		ScheduledExecutorService scheduledExecutorService;
203
		TcpLongConnectClient tcpLongConnectClient = this;
204
		bootstrap.handler(new ChannelInitializer<SocketChannel>() {
205
			@Override
206
			protected void initChannel(SocketChannel socketChannel) {
207
				// 消息最大长度:1*1024*1024=1M表示单条消息的最大长度
208
				// int maxFrameLength = 1*1024*1024;
209
				// netty基于分割符的自带解码器,根据提供的分隔符解析报文,这里是0x7e;
210
				// 解码器在查找分隔符的时候,达到该长度还没找到的话会抛异常
211
				// 设置分隔符为分号(###)
212
				// socketChannel.pipeline().addLast(new DelimiterBasedFrameDecoder(maxFrameLength,
213
				// Unpooled.copiedBuffer(TCP_DELIMITER.getBytes(StandardCharsets.UTF_8))));
214
				socketChannel.pipeline().addLast(new TcpLongConnectClientHandler(tcpLongConnectClient));
215
			}
216
		});
217
218
		// 连接Tcp服务器
219
		int count=0;
220
		try {
221
			doConnect();
222
			if (channelFuture.isSuccess()) {
223
				String sendMessage = null;
224
				String deviceId=null;
225
				String type=null; //类型(0 定位;1 自动报警;2手动报警;4离线)
226
				String longitudeDouble=null;
227
				String latitudeDouble=null;
228
				String dateString=null;
229
				for(MockScenarioData mockScenarioData:mockScenarioDataList) {
230
					if(MockConstant.MACK_STATUS.get(sId)==null){
231
						break;
232
					}
233
234
					type = mockScenarioData.getType();
235
					deviceId = mockScenarioData.getDeviceId();
236
					longitudeDouble = mockScenarioData.getLongitude();
237
					latitudeDouble = mockScenarioData.getLatitude();
238
					dateString = mockScenarioData.getTime();
239
					if (StringUtils.isEmpty(mockScenarioData.getTime())){
240
						dateString = TimeUtil.getSysTime();
241
					}
242
					try {
243
						System.out.println("data:" + JSONObject.toJSONString(mockScenarioData));
244
					log.debug("data:" + JSONObject.toJSONString(mockScenarioData));
245
						sendMessage = MakeBeidouData.makeOneBeidouData(deviceId, type, longitudeDouble, latitudeDouble, dateString);
246
						String typeZh="";//类型(0 定位;1 自动报警;2手动报警;4离线)
247
						switch (type) {
248
						case "0":
249
							typeZh="定位";
250
							break;
251
						case "1":
252
							typeZh="自动报警";
253
							break;
254
						case "2":
255
							typeZh="手动报警";
256
							break;
257
						case "4":
258
							typeZh="离线";
259
							break;
260
						default:
261
							break;
262
						}
263
264
						System.out.println("设备("+deviceId+")的["+typeZh+"]数据: 经度="+longitudeDouble+",纬度="+latitudeDouble+",时间="+dateString);
265
						System.out.println(String.format(count + ":Send Message: %s", sendMessage));
266
						channel.writeAndFlush(Unpooled.copiedBuffer(HexStringUtil.decodeHextoByte(sendMessage)));
267
						count++;
268
269
						TimeUnit.MILLISECONDS.sleep(frequency*1000);
270
					}catch (Exception e) {
271
						e.printStackTrace();
272
						log.error("数据错误,请重新输入");
273
					}
274
				}
275
			}
276
		} finally {
277
			try {
278
				if (null != channel) {
279
					channel.disconnect();
280
				}
281
			} catch (Exception e) {
282
				log.error("出现错误,连接断开");
283
			}
284
		}
285
		log.info("发送成功,共发送"+count+"条数据");
286
	}
287
}

+ 77 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/TcpLongConnectClientHandler.java

@ -0,0 +1,77 @@
1
package com.ai.bss.mock.utils.tcp;
2
3
import com.ai.bss.mock.utils.MessageUtil;
4
import com.ai.ipu.basic.log.ILogger;
5
import com.ai.ipu.basic.log.IpuLoggerFactory;
6
import io.netty.buffer.ByteBuf;
7
import io.netty.channel.ChannelHandlerContext;
8
import io.netty.channel.ChannelInboundHandlerAdapter;
9
import io.netty.handler.timeout.IdleStateEvent;
10
import lombok.extern.slf4j.Slf4j;
11
12
import java.nio.charset.StandardCharsets;
13
14
/**
15
 * Tcp长连接客户端处理类
16
 *
17
 * @author lilb3@asiainfo.com
18
 * @since 2020-04-09
19
 **/
20
@Slf4j
21
class TcpLongConnectClientHandler extends ChannelInboundHandlerAdapter {
22
//    private static final ILogger LOGGER = IpuLoggerFactory.createLogger(TcpLongConnectClientHandler.class);
23
    private static final long SLEEP_TIME = 10 * 1000L;
24
    private final TcpLongConnectClient tcpLongConnectClient;
25
26
    TcpLongConnectClientHandler(TcpLongConnectClient tcpLongConnectClient) {
27
        this.tcpLongConnectClient = tcpLongConnectClient;
28
    }
29
30
    @Override
31
    public void channelActive(ChannelHandlerContext ctx) {
32
        log.info("TCP长连接客户端接入成功");
33
    }
34
35
    @Override
36
    public void channelInactive(ChannelHandlerContext ctx) {
37
    	log.debug("连接断开");
38
    	System.out.println("连接断开");
39
		/*LOGGER.debug("连接断开,10s之后尝试重新连接服务器。");
40
		try {
41
		    TimeUnit.MILLISECONDS.sleep(SLEEP_TIME);
42
		} catch (InterruptedException e) {
43
		    LOGGER.error(e.getMessage(), e);
44
		    Thread.currentThread().interrupt();
45
		}
46
		try {
47
		    tcpLongConnectClient.doConnect();
48
		} catch (InterruptedException e) {
49
		    LOGGER.error(e.getMessage(), e);
50
		    Thread.currentThread().interrupt();
51
		}*/
52
    }
53
54
    @Override
55
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
56
        ByteBuf byteBuf = (ByteBuf) msg;
57
        byte[] content = new byte[byteBuf.readableBytes()];
58
        byteBuf.readBytes(content);
59
        String strContentEncode = new String(content, StandardCharsets.UTF_8);
60
//            String strContentDecode = MessageUtil.getDecodeContent(strContentEncode);
61
        log.debug(String.format("长连接TCP客户端收到的信息: %s", strContentEncode));
62
    }
63
64
    @Override
65
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
66
        log.error("客户端捕获到异常。", cause);
67
    }
68
69
    @Override
70
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
71
        if (evt instanceof IdleStateEvent) {
72
            //如果规定时内没有读写时间,则触发一个消息
73
            //ctx.writeAndFlush((CommonConfig.getTcpHeartBeat() + TCP_DELIMITER).getBytes(StandardCharsets.UTF_8));
74
        	
75
        }
76
    }
77
}

+ 27 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/message/DefaultMessageGeneration.java

@ -0,0 +1,27 @@
1
package com.ai.bss.mock.utils.tcp.message;
2
3
import com.ai.bss.mock.utils.MessageUtil;
4
import com.alibaba.fastjson.JSONObject;
5
6
/**
7
 * 消息测试
8
 *
9
 * @author lilb3@asiainfo.com
10
 * @since 2020-03-30
11
 **/
12
public class DefaultMessageGeneration implements IMessageGeneration {
13
    private static final String IMEI = "imeiTest";
14
15
    private static String getMessage0(String topic) {
16
        JSONObject jsonObject = new JSONObject();
17
        jsonObject.put("topic", topic);
18
        jsonObject.put("imei", IMEI);
19
        jsonObject.put("sendTime", System.currentTimeMillis() + "");
20
        return jsonObject.toString();
21
    }
22
23
    @Override
24
    public String getMessage(String topic) {
25
        return MessageUtil.getEncodeContent(getMessage0(topic));
26
    }
27
}

+ 19 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/message/IMessageGeneration.java

@ -0,0 +1,19 @@
1
package com.ai.bss.mock.utils.tcp.message;
2
3
/**
4
 * 消息发送接口
5
 *
6
 * @author lilb3@asiainfo.com
7
 * @since 2020-06-22
8
 **/
9
@SuppressWarnings("unused")
10
public interface IMessageGeneration {
11
12
    /**
13
     * 获取测试消息
14
     *
15
     * @param topic 消息主题
16
     * @return 测试消息
17
     */
18
    String getMessage(String topic);
19
}

+ 74 - 0
ebc-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/message/MessageGenerationManager.java

@ -0,0 +1,74 @@
1
package com.ai.bss.mock.utils.tcp.message;
2
3
import com.ai.bss.mock.constants.MockConstant;
4
import com.ai.ipu.basic.instance.InstanceManager;
5
6
import java.util.HashMap;
7
import java.util.Map;
8
9
10
/**
11
 * 增加message默认处理类,分离消息消费逻辑
12
 *
13
 * @author lilb3@asiainfo.com
14
 * @since 2020-06-22
15
 **/
16
@SuppressWarnings("unused")
17
public class MessageGenerationManager {
18
//    private static final ILogger LOGGER = IpuLoggerFactory.createLogger(MessageGenerationManager.class);
19
    private static final String SPLIT_DASH = MockConstant.SPLIT_DASH;
20
    private static final Map<String, IMessageGeneration> INSTANCES = new HashMap<>();
21
    private static IMessageGeneration defaultMessageGeneration;
22
23
    private MessageGenerationManager() {
24
        throw new RuntimeException("MessageGenerationManager无法被实例化");
25
    }
26
27
    @SuppressWarnings("unchecked")
28
    private static IMessageGeneration createMessageGeneration(String className) throws Exception {
29
        IMessageGeneration messageGeneration = INSTANCES.get(className);
30
        if (messageGeneration == null) {
31
            synchronized (INSTANCES) {
32
                if (INSTANCES.get(className) == null) {
33
                    Class<?> clazz = Class.forName(className);
34
                    messageGeneration = InstanceManager.createBean((Class<IMessageGeneration>) clazz);
35
                    INSTANCES.put(className, messageGeneration);
36
                }
37
            }
38
        }
39
        return INSTANCES.get(className);
40
    }
41
42
//    public static <Type> Type createBean(Class<Type> clazz) throws Exception {
43
//        return createBean(clazz, true);
44
//    }
45
46
    private static IMessageGeneration getDefaultMessageGeneration() {
47
        if (defaultMessageGeneration == null) {
48
            defaultMessageGeneration = new DefaultMessageGeneration();
49
        }
50
        return defaultMessageGeneration;
51
    }
52
53
    public static void setDefaultMessageGeneration(IMessageGeneration defaultMessageGeneration) {
54
        MessageGenerationManager.defaultMessageGeneration = defaultMessageGeneration;
55
    }
56
57
    public static String getMessage() {
58
    	//String topic = CommonConfig.getTopics()[new Random().nextInt(CommonConfig.getTopics().length)];
59
        String topic = "networkPacket";
60
        return getMessage(topic);
61
    }
62
63
    public static String getMessage(String topic) {
64
        try {
65
            IMessageGeneration messageGeneration = MessageGenerationManager.getDefaultMessageGeneration();;
66
            if (messageGeneration != null) {
67
                return messageGeneration.getMessage(topic);
68
            }
69
        } catch (Exception e) {
70
//            LOGGER.error("Test Message生成异常", e);
71
        }
72
        return "";
73
    }
74
}

+ 55 - 0
ebc-mock-service/src/main/resources/application.properties

@ -0,0 +1,55 @@
1
spring.application.name=WorkTaskSpec
2
server.port=8086
3
4
# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
5
#spring.datasource.url=jdbc:mysql://localhost:3306/cmp
6
#spring.datasource.url=jdbc:mysql://10.19.14.28:3306/work_order?useUnicode=true&ampcharacterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
7
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
8
#spring.datasource.username=aibp
9
#spring.datasource.password=Aibp@123
10
#spring.datasource.url=jdbc:mysql://10.11.20.120:3306/common_frm?useUnicode=true&ampcharacterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
11
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
12
#spring.datasource.username=comon_frm
13
#spring.datasource.password=1qaz@WSX
14
spring.datasource.url=jdbc:mysql://47.105.160.21:3309/dmp?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
15
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
16
spring.datasource.username=cmp
17
spring.datasource.password=cmp@123
18
19
# JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
20
#spring.jpa.database=default
21
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
22
spring.jpa.hibernate.ddl-auto=update
23
spring.jpa.show-sql=true
24
spring.jpa.properties.hibernate.format_sql=true
25
spring.jpa.properties.hibernate.generate_statistics=false
26
spring.main.allow-bean-definition-overriding=true
27
28
# CACHE
29
#spring.cache.type=ehcache
30
#spring.cache.ehcache.config=ehcache.xml
31
32
# LOGGING
33
logging.level.com.ai=info
34
logging.level.org.springframework.data=info
35
36
37
38
39
#============== kafka ===================
40
kafka.consumer.zookeeper.connect=47.105.160.21:2100
41
kafka.consumer.servers=47.105.160.21:9090
42
kafka.consumer.enable.auto.commit=true
43
kafka.consumer.session.timeout=6000
44
kafka.consumer.auto.commit.interval=100
45
kafka.consumer.auto.offset.reset=latest
46
kafka.consumer.topic=productMessage
47
kafka.consumer.group.id=productMessage
48
kafka.consumer.concurrency=10
49
50
kafka.producer.servers=47.105.160.21:9090
51
kafka.producer.retries=0
52
kafka.producer.batch.size=4096
53
kafka.producer.linger=1
54
kafka.producer.buffer.memory=40960
55
kafka.producer.topic=67message

+ 34 - 0
ebc-mock-service/src/test/resources/application.properties

@ -0,0 +1,34 @@
1
spring.application.name=WorkTaskSpec
2
server.port=8086
3
4
# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
5
#spring.datasource.url=jdbc:mysql://localhost:3306/cmp
6
#spring.datasource.url=jdbc:mysql://10.19.14.28:3306/work_order?useUnicode=true&ampcharacterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
7
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
8
#spring.datasource.username=aibp
9
#spring.datasource.password=Aibp@123
10
#spring.datasource.url=jdbc:mysql://10.11.20.120:3306/common_frm?useUnicode=true&ampcharacterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
11
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
12
#spring.datasource.username=comon_frm
13
#spring.datasource.password=1qaz@WSX
14
spring.datasource.url=jdbc:mysql://10.19.90.34:3307/energy?useUnicode=true&ampcharacterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
15
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
16
spring.datasource.username=ebc
17
spring.datasource.password=ebc@123
18
19
# JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
20
#spring.jpa.database=default
21
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
22
spring.jpa.hibernate.ddl-auto=update
23
spring.jpa.show-sql=true
24
spring.jpa.properties.hibernate.format_sql=true
25
spring.jpa.properties.hibernate.generate_statistics=false
26
spring.main.allow-bean-definition-overriding=true
27
28
# CACHE
29
#spring.cache.type=ehcache
30
#spring.cache.ehcache.config=ehcache.xml
31
32
# LOGGING
33
logging.level.com.ai=info
34
logging.level.org.springframework.data=info