瀏覽代碼

Merge branch 'master' of http://10.1.235.20:3000/asiainfo/ebc

wangchao 4 年之前
父節點
當前提交
c99c4d5c5d
共有 30 個文件被更改,包括 1546 次插入13 次删除
  1. 37 0
      indoor-mock-service/.gitignore
  2. 189 0
      indoor-mock-service/pom.xml
  3. 59 0
      indoor-mock-service/src/main/assembly/package.xml
  4. 25 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/IndoorMockApp.java
  5. 9 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/constants/MockConstant.java
  6. 56 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/controller/MockController.java
  7. 15 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/model/Data.java
  8. 30 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/model/DataPoint.java
  9. 18 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/model/EBCData.java
  10. 107 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/model/LocationBean.java
  11. 71 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/model/MockScenarioData.java
  12. 22 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/repository/MockScenarioDataRepository.java
  13. 111 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/service/impl/MockManageServiceImpl.java
  14. 136 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/service/impl/MockProcessImpl.java
  15. 27 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/service/interfaces/MockManageService.java
  16. 14 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/service/interfaces/MockProcess.java
  17. 48 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/utils/HexStringUtil.java
  18. 113 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/utils/KafkaProducerConfig.java
  19. 19 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/utils/MessageUtil.java
  20. 19 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/utils/SecurityConfigSEVEN.java
  21. 31 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/utils/makedata/MakeBluetoothData.java
  22. 56 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/IpuTcpLongConnectClient.java
  23. 42 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/TcpLongConnectClient.java
  24. 73 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/TcpLongConnectClientHandler.java
  25. 27 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/message/DefaultMessageGeneration.java
  26. 19 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/message/IMessageGeneration.java
  27. 73 0
      indoor-mock-service/src/main/java/com/ai/bss/mock/utils/tcp/message/MessageGenerationManager.java
  28. 59 0
      indoor-mock-service/src/main/resources/application.properties
  29. 34 0
      indoor-mock-service/src/test/resources/application.properties
  30. 7 13
      indoor-service/src/main/java/com/ai/bss/location/util/DateUtil.java

+ 37 - 0
indoor-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
indoor-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>indoor-mock-service</artifactId>
13
14
    <name>indoor-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.IndoorMockApp</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
indoor-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>

+ 25 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/IndoorMockApp.java

@ -0,0 +1,25 @@
1
package com.ai.bss.mock;
2
3
import org.springframework.boot.SpringApplication;
4
import org.springframework.boot.autoconfigure.SpringBootApplication;
5
import org.springframework.boot.autoconfigure.domain.EntityScan;
6
import org.springframework.context.annotation.ComponentScan;
7
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
8
import org.springframework.scheduling.annotation.EnableAsync;
9
10
/**
11
 * @author wangdong
12
 */
13
14
@EnableJpaRepositories(basePackages = "com.ai.bss")
15
@EntityScan(basePackages = {"com.ai.bss","com.ai.abc"})
16
@ComponentScan(basePackages = {"com.ai.bss","com.ai.abc","com.ai.ipu"})
17
@EnableAsync
18
@SpringBootApplication
19
20
public class IndoorMockApp {
21
22
    public static void main(String[] args) throws Exception {
23
        SpringApplication.run(IndoorMockApp.class, args);
24
    }
25
}

+ 9 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/constants/MockConstant.java

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

+ 56 - 0
indoor-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 java.util.Map;
5
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 com.ai.bss.mock.service.interfaces.MockManageService;
15
16
/**
17
 * mock
18
 */
19
@Controller
20
@RequestMapping("/mock")
21
public class MockController {
22
23
    @Autowired
24
    private MockManageService mockManageService;
25
26
    private static final 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
indoor-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
indoor-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
indoor-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
}

+ 107 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/model/LocationBean.java

@ -0,0 +1,107 @@
1
package com.ai.bss.mock.model;
2
3
import java.io.Serializable;
4
import java.sql.Timestamp;
5
6
/**
7
 * created on 2016年8月25日
8
 *
9
 * 定位结果bean
10
 *
11
 * @author  megagao
12
 * @version  0.0.1
13
 */
14
public class LocationBean implements Serializable {
15
16
	private static final long serialVersionUID = 1L;
17
18
	/*员工id*/
19
	private String mac;
20
21
	/*楼层*/
22
	private Integer floor;
23
24
	/*x轴坐标*/
25
	private Double xAxis;
26
27
	/*y轴坐标*/
28
	private Double yAxis;
29
30
	/*z轴坐标*/
31
	private Double zAxis;
32
33
	/*时间戳*/
34
	private Timestamp timeStamp;
35
36
	public LocationBean(String mac, int floor, double xAxis, double yAxis, Timestamp timeStamp) {
37
		this.mac = mac;
38
		this.floor = floor;
39
		this.xAxis = xAxis;
40
		this.yAxis = yAxis;
41
		this.zAxis = 0d;
42
		this.timeStamp = timeStamp;
43
	}
44
45
	public LocationBean() {
46
		this.floor = 0;
47
		this.xAxis = 0d;
48
		this.yAxis = 0d;
49
		this.zAxis = 0d;
50
		this.timeStamp = new Timestamp(System.currentTimeMillis());
51
	}
52
53
	public Integer getFloor() {
54
		return floor;
55
	}
56
57
	public void setFloor(Integer floor) {
58
		this.floor = floor;
59
	}
60
61
	public String getMac() {
62
		return mac;
63
	}
64
65
	public void setMac(String mac) {
66
		this.mac = mac;
67
	}
68
69
	public Double getxAxis() {
70
		return xAxis;
71
	}
72
73
	public void setxAxis(Double xAxis) {
74
		this.xAxis = xAxis;
75
	}
76
77
	public Double getyAxis() {
78
		return yAxis;
79
	}
80
81
	public void setyAxis(Double yAxis) {
82
		this.yAxis = yAxis;
83
	}
84
85
	public Double getzAxis() {
86
		return zAxis;
87
	}
88
89
	public void setzAxis(Double zAxis) {
90
		this.zAxis = zAxis;
91
	}
92
93
	public Timestamp getTimeStamp() {
94
		return timeStamp;
95
	}
96
97
	public void setTimeStamp(Timestamp timeStamp) {
98
		this.timeStamp = timeStamp;
99
	}
100
101
	@Override
102
	public String toString() {
103
		return "LocationBean [mac=" + mac + ", floor=" + floor + ", xAxis=" + xAxis + ", yAxis=" + yAxis + ", zAxis="
104
				+ zAxis + ", timeStamp=" + timeStamp + "]";
105
	}
106
107
}

+ 71 - 0
indoor-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
}

+ 22 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/repository/MockScenarioDataRepository.java

@ -0,0 +1,22 @@
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
}

+ 111 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/service/impl/MockManageServiceImpl.java

@ -0,0 +1,111 @@
1
package com.ai.bss.mock.service.impl;
2
3
import java.sql.Timestamp;
4
import java.util.ArrayList;
5
import java.util.HashMap;
6
import java.util.List;
7
import java.util.Map;
8
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.stereotype.Service;
11
import org.springframework.util.CollectionUtils;
12
13
import com.ai.bss.mock.model.LocationBean;
14
import com.ai.bss.mock.model.MockScenarioData;
15
import com.ai.bss.mock.repository.MockScenarioDataRepository;
16
import com.ai.bss.mock.service.interfaces.MockManageService;
17
import com.ai.bss.mock.service.interfaces.MockProcess;
18
19
import lombok.extern.slf4j.Slf4j;
20
21
@Slf4j
22
@Service
23
public class MockManageServiceImpl implements MockManageService {
24
25
	protected static Map MACK_STATUS = new HashMap();
26
	
27
    @Autowired
28
    private MockScenarioDataRepository mockScenarioDataRepository;
29
    @Autowired
30
    private MockProcess mockProcess;
31
32
//    @Value("${kafka.producer.servers:Empty}")
33
    private static String kafkaServers = "47.105.160.21:9090";
34
35
    @Override
36
    public Map findMockStatusByScenarioId()  {
37
        List<Long> result = new ArrayList(MACK_STATUS.keySet());
38
        Map  tempmap = new HashMap();
39
        for(Long sid:result){
40
            tempmap.put(sid,"场景 "+sid+" 执行中...");
41
        }
42
        return tempmap;
43
    }
44
    @Override
45
    public String  startMackData(Long sId,  Long frequency,String topic0,String topic1)  {
46
        //        验证场景是否正在执行
47
        if(MACK_STATUS.get(sId)!=null){
48
            return "场景" + sId + " 正在执行,请耐心等待...";
49
        }
50
        //根据场景ID从数据库中查询模拟数据
51
        List<MockScenarioData>  mockScenarioDataList = mockScenarioDataRepository.findByScenarioIdOrderByOrderNo(sId);
52
53
        List<Long> orderNoList = mockScenarioDataRepository.findByOrderNoByScenarioId(sId);
54
        if(CollectionUtils.isEmpty(mockScenarioDataList) || CollectionUtils.isEmpty(orderNoList)){
55
            return "场景" + sId + " 没有配置模拟 ,请在数据库中添加数据再执行...";
56
        }
57
        
58
        //记录场景执行状态
59
        MACK_STATUS.put(sId,frequency);
60
        //异步执行模拟场景 通过IOT-DMP连接服务模拟
61
//        mockProcess.processMock(sId,mockScenarioDataList,frequency);
62
63
        Map<Long, List<LocationBean>> dataMap=getMapListData(mockScenarioDataList);
64
        
65
        //异步执行模拟场景  直接模拟最终数据发送到kafka
66
        mockProcess.processMockKafka(sId,dataMap,orderNoList,frequency,topic0, topic1);
67
68
        return "场景" + sId + " 开始执行...";
69
    }
70
71
72
    @Override
73
    public String  stopMackData(Long sId){
74
        MACK_STATUS.remove(sId);
75
        return "场景" + sId + " 终止执行...";
76
    }
77
78
    /**
79
          * 按orderNo分组
80
     * @param mockScenarioDataList
81
     * @return
82
     */
83
    private Map<Long, List<LocationBean>> getMapListData(List<MockScenarioData> mockScenarioDataList) {
84
    	Map<Long, List<LocationBean>> map=new HashMap<Long, List<LocationBean>>();
85
    	
86
    	for (MockScenarioData mockScenarioData : mockScenarioDataList) {
87
    		LocationBean locationBean=new LocationBean();
88
        	locationBean.setFloor(1);
89
        	locationBean.setMac(mockScenarioData.getDeviceId());
90
        	locationBean.setxAxis(Double.valueOf(mockScenarioData.getLongitude()));
91
        	locationBean.setyAxis(Double.valueOf(mockScenarioData.getLatitude()));
92
        	locationBean.setzAxis(0d);
93
        	locationBean.setTimeStamp(new Timestamp(System.currentTimeMillis()));
94
    		
95
        	
96
    		long orderNo=mockScenarioData.getOrderNo();
97
    		
98
    		List<LocationBean> list=map.get(orderNo);
99
    		if (list==null) {
100
    			list=new ArrayList<LocationBean>();
101
    			list.add(locationBean);
102
    			map.put(orderNo, list);
103
			}else {
104
				list.add(locationBean);
105
			}
106
		}
107
    	
108
    	return map;
109
    }
110
    
111
}

+ 136 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/service/impl/MockProcessImpl.java

@ -0,0 +1,136 @@
1
package com.ai.bss.mock.service.impl;
2
3
import java.sql.Timestamp;
4
import java.util.ArrayList;
5
import java.util.Date;
6
import java.util.HashMap;
7
import java.util.List;
8
import java.util.Map;
9
import java.util.concurrent.ExecutorService;
10
import java.util.concurrent.Executors;
11
import java.util.concurrent.TimeUnit;
12
13
import org.slf4j.Logger;
14
import org.slf4j.LoggerFactory;
15
import org.springframework.beans.factory.annotation.Value;
16
import org.springframework.kafka.core.KafkaTemplate;
17
import org.springframework.scheduling.annotation.Async;
18
import org.springframework.stereotype.Service;
19
import org.springframework.util.StringUtils;
20
21
import com.ai.bss.mock.model.Data;
22
import com.ai.bss.mock.model.DataPoint;
23
import com.ai.bss.mock.model.EBCData;
24
import com.ai.bss.mock.model.LocationBean;
25
import com.ai.bss.mock.model.MockScenarioData;
26
import com.ai.bss.mock.service.interfaces.MockProcess;
27
import com.ai.bss.mock.utils.KafkaProducerConfig;
28
import com.ai.bss.mock.utils.tcp.IpuTcpLongConnectClient;
29
import com.ailk.common.data.impl.DataMap;
30
import com.alibaba.fastjson.JSON;
31
import com.alibaba.fastjson.JSONObject;
32
33
import lombok.extern.slf4j.Slf4j;
34
35
36
@Slf4j
37
@Service
38
public class MockProcessImpl implements MockProcess {
39
	private static final Logger logger = LoggerFactory.getLogger(MockProcessImpl.class);
40
41
//    EBC设备tcp连接服务地址
42
    private static final String HOST = "47.105.130.83";
43
    private static final int PORT = 8042;
44
45
    private static String kafkaServers = "47.105.160.21:9091";
46
47
    @Value("${kafka.producer.servers}")
48
    private static String servers;
49
    
50
    @Value("${kafka.producer.topic}")
51
    private String topic;
52
53
    @Async
54
    @Override
55
    public void processMock(Long sId,List<MockScenarioData> mockScenarioDataList, Long frequency){
56
        try {
57
            IpuTcpLongConnectClient.getInstance(HOST, PORT).sendMockData(sId,mockScenarioDataList, frequency);
58
59
            MockManageServiceImpl.MACK_STATUS.remove(sId);
60
        }catch (Exception e){
61
        	logger.error("processMock is error:"+e.getMessage());
62
            //e.printStackTrace();
63
        }
64
    }
65
66
    //线程池
67
    private ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
68
    
69
    @Async
70
    @Override
71
    public void processMockKafka(Long sId,Map<Long, List<LocationBean>> dataMap,List<Long> orderNoList, Long frequency,String topic0,String topic1){
72
    	String clientId="XBG_AC67B2C23CFC";
73
		String userName="abc";
74
		topic="uploadInfoTest";
75
		
76
    	try {
77
            for (Long orderNo : orderNoList) {
78
            	List<LocationBean> dataList=dataMap.get(orderNo);
79
            	
80
            	for (LocationBean locationBean : dataList) {
81
            		cachedThreadPool.execute(new Runnable() {
82
            			@Override
83
            			public void run() {
84
            				String msg=JSON.toJSONString(locationBean);
85
                   		 
86
                    		System.out.println("推送消息:"+msg);
87
                    		 
88
                        	sendKafkaDataPoint(clientId, userName, topic, msg);
89
            			}
90
            		});
91
				}
92
93
                TimeUnit.MILLISECONDS.sleep(frequency * 1000);
94
            }
95
96
97
            MockManageServiceImpl.MACK_STATUS.remove(sId);
98
        }catch (Exception e){
99
        	logger.error("processMockKafka is error:"+e.getMessage());
100
        }
101
    }
102
103
    private Map<String, KafkaTemplate> kafkaTemplateMap = new HashMap<>();
104
105
    private void sendKafkaDataPoint(String deviceId, String userName, String topic, String msg) {
106
		KafkaTemplate kafkaTemplate = kafkaTemplateMap.get(kafkaServers);
107
		if (kafkaTemplate == null) {
108
			// new 实例
109
			KafkaProducerConfig kafkaProducerConfig = new KafkaProducerConfig(kafkaServers);
110
			kafkaTemplate = kafkaProducerConfig.kafkaTemplate();
111
			kafkaTemplateMap.put(kafkaServers, kafkaTemplate);
112
		}
113
		
114
		if (kafkaTemplate == null) {
115
			log.error("kafkaTemplate is null");
116
			return;
117
		}
118
		
119
		DataMap dataMap = new DataMap();
120
		dataMap.put("resourceId", deviceId);
121
		dataMap.put("productKey", userName);
122
		dataMap.put("detailInfo", msg);
123
		dataMap.put("eventTime", System.currentTimeMillis());
124
		try {
125
			String msgStr=JSON.toJSONString(dataMap);
126
			log.info("发送kafka消息:topic=" + topic + ", msg=" + msgStr );
127
			kafkaTemplate.send(topic, deviceId, msgStr);
128
			
129
			kafkaTemplate.flush();
130
			log.info("发送kafka消息成功");
131
		} catch (Exception e) {
132
			log.error(topic + " send error");
133
		}
134
	}
135
    
136
}

+ 27 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/service/interfaces/MockManageService.java

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

+ 14 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/service/interfaces/MockProcess.java

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

+ 48 - 0
indoor-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
}

+ 113 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/utils/KafkaProducerConfig.java

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

+ 19 - 0
indoor-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
indoor-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

+ 31 - 0
indoor-mock-service/src/main/java/com/ai/bss/mock/utils/makedata/MakeBluetoothData.java

@ -0,0 +1,31 @@
1
package com.ai.bss.mock.utils.makedata;
2
3
import java.sql.Timestamp;
4
5
import com.ai.bss.mock.model.LocationBean;
6
import com.alibaba.fastjson.JSON;
7
8
public class MakeBluetoothData {
9
10
	/**
11
	 * 经纬度坐标单位为米
12
	 * @param xAxis
13
	 * @param yAxis
14
	 */
15
	public static String sendBluetoothKafka(double xAxis,double yAxis) {
16
		String clientId="XBG_AC67B2C23CFC";
17
		 String userName="abc";
18
		
19
		 String mac="d3e656a4573d";
20
		 
21
		 Integer floor=1;
22
		 Timestamp timeStamp=new Timestamp(System.currentTimeMillis());
23
		 LocationBean location=new LocationBean(mac, floor, xAxis, yAxis, timeStamp);
24
		 
25
		 String msg=JSON.toJSONString(location);
26
		 
27
		 System.out.println(msg);
28
		 
29
		 return msg;
30
	}
31
}

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

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

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

@ -0,0 +1,42 @@
1
package com.ai.bss.mock.utils.tcp;
2
3
import io.netty.bootstrap.Bootstrap;
4
import io.netty.channel.Channel;
5
import io.netty.channel.ChannelFuture;
6
import lombok.extern.slf4j.Slf4j;
7
8
/**
9
 * Tcp长连接客户端
10
 *
11
 * @author lilb3@asiainfo.com
12
 * @since 2019-10-16
13
 **/
14
@Slf4j
15
class TcpLongConnectClient {
16
	// private static final int PERIOD = 1;
17
	static final long PER_SLEEP_TIME = 2000L;
18
	// private static final int SEND_TIMES = 6;
19
	private final String host;
20
	private final int port;
21
	private final String message;
22
	private Channel channel;
23
	private ChannelFuture channelFuture;
24
	private Bootstrap bootstrap;
25
26
	TcpLongConnectClient(String host, int port, String message) {
27
		this.host = host;
28
		this.port = port;
29
		this.message = message;
30
	}
31
32
	/**
33
	 * 抽取出该方法 (断线重连时使用)
34
	 *
35
	 * @throws InterruptedException 异常
36
	 */
37
	void doConnect() throws InterruptedException {
38
		channelFuture = bootstrap.connect(host, port).sync();
39
		channel = channelFuture.channel();
40
	}
41
42
}

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

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

+ 27 - 0
indoor-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
indoor-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
}

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

@ -0,0 +1,73 @@
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 String SPLIT_DASH = MockConstant.SPLIT_DASH;
19
    private static final Map<String, IMessageGeneration> INSTANCES = new HashMap<>();
20
    private static IMessageGeneration defaultMessageGeneration;
21
22
    private MessageGenerationManager() {
23
        throw new RuntimeException("MessageGenerationManager无法被实例化");
24
    }
25
26
    @SuppressWarnings("unchecked")
27
    private static IMessageGeneration createMessageGeneration(String className) throws Exception {
28
        IMessageGeneration messageGeneration = INSTANCES.get(className);
29
        if (messageGeneration == null) {
30
            synchronized (INSTANCES) {
31
                if (INSTANCES.get(className) == null) {
32
                    Class<?> clazz = Class.forName(className);
33
                    messageGeneration = InstanceManager.createBean((Class<IMessageGeneration>) clazz);
34
                    INSTANCES.put(className, messageGeneration);
35
                }
36
            }
37
        }
38
        return INSTANCES.get(className);
39
    }
40
41
//    public static <Type> Type createBean(Class<Type> clazz) throws Exception {
42
//        return createBean(clazz, true);
43
//    }
44
45
    private static IMessageGeneration getDefaultMessageGeneration() {
46
        if (defaultMessageGeneration == null) {
47
            defaultMessageGeneration = new DefaultMessageGeneration();
48
        }
49
        return defaultMessageGeneration;
50
    }
51
52
    public static void setDefaultMessageGeneration(IMessageGeneration defaultMessageGeneration) {
53
        MessageGenerationManager.defaultMessageGeneration = defaultMessageGeneration;
54
    }
55
56
    public static String getMessage() {
57
    	//String topic = CommonConfig.getTopics()[new Random().nextInt(CommonConfig.getTopics().length)];
58
        String topic = "networkPacket";
59
        return getMessage(topic);
60
    }
61
62
    public static String getMessage(String topic) {
63
        try {
64
            IMessageGeneration messageGeneration = MessageGenerationManager.getDefaultMessageGeneration();;
65
            if (messageGeneration != null) {
66
                return messageGeneration.getMessage(topic);
67
            }
68
        } catch (Exception e) {
69
//            LOGGER.error("Test Message生成异常", e);
70
        }
71
        return "";
72
    }
73
}

+ 59 - 0
indoor-mock-service/src/main/resources/application.properties

@ -0,0 +1,59 @@
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
spring.datasource.url=jdbc:mysql://10.19.90.34:3307/energy?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
19
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
20
spring.datasource.username=ebc
21
spring.datasource.password=ebc@123
22
23
# JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
24
#spring.jpa.database=default
25
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
26
spring.jpa.hibernate.ddl-auto=update
27
spring.jpa.show-sql=true
28
spring.jpa.properties.hibernate.format_sql=true
29
spring.jpa.properties.hibernate.generate_statistics=false
30
spring.main.allow-bean-definition-overriding=true
31
32
# CACHE
33
#spring.cache.type=ehcache
34
#spring.cache.ehcache.config=ehcache.xml
35
36
# LOGGING
37
logging.level.com.ai=info
38
logging.level.org.springframework.data=info
39
40
41
42
43
#============== kafka ===================
44
kafka.consumer.zookeeper.connect=47.105.160.21:2100
45
kafka.consumer.servers=47.105.160.21:9090
46
kafka.consumer.enable.auto.commit=true
47
kafka.consumer.session.timeout=6000
48
kafka.consumer.auto.commit.interval=100
49
kafka.consumer.auto.offset.reset=latest
50
kafka.consumer.topic=productMessage
51
kafka.consumer.group.id=productMessage
52
kafka.consumer.concurrency=10
53
54
kafka.producer.servers=47.105.160.21:9091
55
kafka.producer.retries=0
56
kafka.producer.batch.size=4096
57
kafka.producer.linger=1
58
kafka.producer.buffer.memory=40960
59
kafka.producer.topic=uploadInfoTest

+ 34 - 0
indoor-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

+ 7 - 13
indoor-service/src/main/java/com/ai/bss/location/util/DateUtil.java

@ -161,22 +161,16 @@ public class DateUtil {
161 161
	 * @throws Exception 
162 162
	 */
163 163
	public static int compareDate(String dateStr0, String dateStr1) throws Exception {
164
		if (dateStr0 == null || "".equals(dateStr0)) {
165
			if (dateStr1 == null || "".equals(dateStr1)) {
166
				return 0;
167
			} else {
168
				return -1;
169
			}
170
		}
164
		Date date0 = convertDate(dateStr0);
165
		Date date1 = convertDate(dateStr1);
166
167
		if (date0 == null)
168
			return (date1 == null) ? 0 : -1;
171 169
172
		if (dateStr1 == null || "".equals(dateStr1)) {
170
		if (date1 == null)
173 171
			return 1;
174
		}
175 172
176
		Date date1 = convertDate(dateStr0);
177
		Date date2 = convertDate(dateStr1);
178
		int result = date1.compareTo(date2);
179
		return result;
173
		return date0.compareTo(date1);
180 174
	}
181 175
182 176
	/**