TransferServiceImpl.java
3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.viontech.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.viontech.constant.SystemConstants;
import com.viontech.service.TransferService;
import com.viontech.vo.FxData;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Slf4j
@Service
public class TransferServiceImpl implements TransferService {
private final ThreadPoolExecutor recvDataTaskAsyncPool = new ThreadPoolExecutor(5, 10, 8l, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10), new ThreadPoolExecutor.CallerRunsPolicy());
@Override
public void receiveData(FxData fxdata) {
try {
String event_cate = fxdata.getEvent_cate();
if (!event_cate.equals(SystemConstants.CATE_TRAFFIC)) {
log.warn("event_cate与traffic不匹配,跳过");
return;
}
String event_type = fxdata.getEvent_type();
if (StringUtils.isBlank(event_type)) {
log.warn("event_type为空,跳过");
return;
}
recvDataTaskAsyncPool.submit(new Runnable() {
@Override
public void run() {
switch (event_cate) {
case SystemConstants.CATE_TRAFFIC:
switch (event_type) {
case SystemConstants.TYPE_VEHICLE:
String ID = fxdata.getEvent_data().getID();
String startDt = fxdata.getEvent_data().getStart_dt();
String endDt = fxdata.getEvent_data().getEnd_dt();
String deviceCode = fxdata.getEvent_data().getDevice().getCode();
String vchanRefid = fxdata.getVchan_refid();
Map vehicle = JSONObject.parseObject(JSONObject.toJSONString(fxdata.getEvent_data().getVehicle()), Map.class);
Map illegal = JSONObject.parseObject(JSONObject.toJSONString(fxdata.getEvent_data().getIllegal()), Map.class);
String state = (String) illegal.get("state");
String base64 = fxdata.getPics().get(0).getPic_base64();
Map lane = JSONObject.parseObject(JSONObject.toJSONString(fxdata.getEvent_data().getLane()), Map.class);
try {
if ("1".equals(state)) {
// iilleProcessor.addIill(ID, startDt, endDt, deviceCode, vchanRefid, vehicle, illegal, base64);
} else {
return;
}
} catch (Exception e) {
log.error("handle.Exception", e);
}
break;
default:
log.warn("event_type类型无法判断:{},跳过处理", event_type);
break;
}
break;
default:
log.warn("event_cate类型无法判断:{}跳过处理", event_cate);
break;
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
fxdata.setPics(null);
}
}