Commit 42a1e46b by xmh

first commit

0 parents
### Example user template template
### Example user template
# IntelliJ project files
.idea
*.iml
out
gen
target
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
</parent>
<groupId>com.viontech</groupId>
<artifactId>fanxing2-tvp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.20</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file \ No newline at end of file
package com.viontech.tvp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* .
*
* @author 谢明辉
* @date 2022/3/7
*/
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
package com.viontech.tvp;
import cn.hutool.json.JSONObject;
import cn.hutool.json.xml.JSONXMLSerializer;
import lombok.extern.slf4j.Slf4j;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Optional;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* .
*
* @author 谢明辉
* @date 2022/3/7
*/
@Service
@Slf4j
public class ForwardService {
private static final ThreadPoolExecutor POOL = new ThreadPoolExecutor(20, 40, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<>(1000), new ThreadPoolExecutor.CallerRunsPolicy());
@Value("${vion.tvp.url}")
private String tvpUrl;
public void forwardAsync(JSONObject fxData) {
POOL.submit(new Task(fxData, tvpUrl));
}
private static class Task implements Runnable {
private final JSONObject fxData;
private final String tvpUrl;
public Task(JSONObject fxData, String tvpUrl) {
this.fxData = fxData;
this.tvpUrl = tvpUrl;
}
@Override
public void run() {
try {
JSONObject cast = cast(fxData);
String data = JSONXMLSerializer.toXml(cast, "Data");
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(tvpUrl);
Object[] res = client.invoke("InPeccancyInfo", data);
log.info("发送消息结果:[{}]", res[0]);
} catch (Exception e) {
e.printStackTrace();
}
}
public JSONObject cast(JSONObject fxData) {
JSONObject res = new JSONObject();
res.set("DataType", "Violation");
res.set("SFQJ", "00");
res.set("CJYH", "VION");
res.set("SJLY", "09");
String eventDt = fxData.getStr("event_dt").substring(0, 19);
JSONObject eventData = fxData.getJSONObject("event_data");
JSONObject plate = eventData.getJSONObject("vehicle").getJSONObject("plate");
JSONObject illegal = eventData.getJSONObject("illegal");
JSONObject illegalDetail = illegal.getJSONObject("detail");
String illegalCode = illegal.getStr("code");
boolean overSpeed = overSpeed(illegalCode);
// 违法时间
res.set("WFSJ", eventDt);
// 采集时间
res.set("CJSJ", eventDt);
// 号牌种类
res.set("HPZL", castPlateType(plate.getStr("type_code")));
// 号牌号码
res.set("HPHM", plate.getStr("text"));
// 违法行为
res.set("WFXW", IllegalCodeUtil.cast(illegalCode));
// 违法地点
res.set("WFDD", eventData.getJSONObject("location").getStr("name"));
if (overSpeed) {
// 车辆速度
res.set("CLSD", eventData.getFloat("speed"));
// 车辆限速
res.set("CLXS", illegalDetail.getStr("limit_speed"));
// 超速比例
res.set("CSBL", illegalDetail.getStr("over_speed_rate"));
}
// 车道编号
res.set("CDBH", String.valueOf(eventData.getJSONObject("lane").getInt("number")));
// todo 方向编号
// res.set("FXBH", "");
// 设备编号
res.set("SBBH", fxData.getStr("vchan_refid"));
// 违法图片
String base64 = Optional.of(fxData).map(x -> x.getJSONArray("pics")).map(x -> x.getJSONObject(0)).map(x -> x.getStr("pic_base64")).orElse(null);
res.set("ZJWJ1", base64);
return res;
}
private String castPlateType(String plateType) {
if ("31".equals(plateType)) {
return "51";
}
if ("32".equals(plateType)) {
return "52";
}
return plateType;
}
private boolean overSpeed(String illegalCode) {
switch (illegalCode) {
case "51":
case "52":
case "33":
case "45":
case "50":
case "48":
case "49":
case "47":
case "46":
case "21":
return true;
default:
return false;
}
}
}
}
package com.viontech.tvp;
import cn.hutool.core.util.StrUtil;
import cn.hutool.setting.dialect.Props;
import cn.hutool.setting.dialect.PropsUtil;
import lombok.extern.slf4j.Slf4j;
/**
* .
*
* @author 谢明辉
* @date 2022/3/8
*/
@Slf4j
public class IllegalCodeUtil {
private static final Props PROPS = PropsUtil.get("illegalCode.properties");
public static String cast(String vionIllegalCode) {
String str = PROPS.getStr(vionIllegalCode);
return StrUtil.isEmpty(str) ? vionIllegalCode : str;
}
}
package com.viontech.tvp;
import cn.hutool.core.lang.Dict;
import cn.hutool.json.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Optional;
/**
* .
*
* @author 谢明辉
* @date 2022/3/7
*/
@RestController
@Slf4j
public class ReceiveController {
@Resource
private ForwardService forwardService;
@PostMapping("/recv")
public Object receive(@RequestBody JSONObject fxData) {
String eventCate = fxData.getStr("event_cate");
String eventType = fxData.getStr("event_type");
boolean illegal = Optional.of(fxData)
.map(x -> x.getJSONObject("event_data"))
.map(x -> x.getJSONObject("illegal"))
.map(x -> x.getInt("state"))
.map(x -> x == 1)
.orElse(false);
if ("traffic".equals(eventCate) && "vehicle".equals(eventType) && illegal) {
// 进行异步转发
forwardService.forwardAsync(fxData);
} else {
log.debug("非违法数据, 不转发: event_cate: {}, event_type: {}", eventCate, eventType);
}
return Dict.of("code", "200", "msg", "success");
}
}
server.port=60005
vion.tvp.url=http://IP:8080/EHL_TVPDB_WEBSERVICE/services/TvpService?wsdl
\ No newline at end of file \ No newline at end of file
00=00
01=01
02=02
03=03
04=04
05=05
06=06
07=07
08=08
09=09
10=10
11=11
12=12
13=13
14=14
15=15
16=16
17=17
18=18
19=19
20=20
21=21
22=22
23=23
24=24
25=25
26=26
27=27
28=28
29=29
30=30
31=31
32=32
33=33
36=36
37=37
38=38
40=40
41=41
42=42
43=43
44=44
45=45
46=46
47=47
48=48
49=49
50=50
51=51
52=52
53=53
54=54
55=55
56=56
57=57
58=58
59=59
60=60
61=61
62=62
63=63
64=64
65=65
66=66
67=67
68=68
69=69
70=70
71=71
72=72
73=73
74=74
75=75
76=76
77=77
78=78
79=79
80=80
81=81
82=82
83=83
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!