JudgmentService.java
13.4 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
package cn.com.glsx.admin.modules.service;
import cn.com.glsx.admin.common.enums.TypeConverseEnum;
import cn.com.glsx.admin.modules.mapper.VehicleMapper;
import cn.com.glsx.admin.modules.model.export.JudgmentExport;
import cn.com.glsx.admin.modules.model.param.JudgmentSearch;
import cn.com.glsx.admin.modules.remote.RemoteStuJudgeAlarmService;
import cn.com.glsx.alarm.services.model.StuJudgeAlarmDto;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.common.utils.StringUtils;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* 大数据研判 service
*
* @author yll
*/
@Slf4j
@Service
public class JudgmentService extends AbstractCommonService {
@Autowired
private RemoteStuJudgeAlarmService remoteStuJudgeAlarmService;
@Autowired
private VehicleMapper vehicleMapper;
/**
* 查询大数据研判数据列表
*
* @param search
*
* @return
*/
public PageInfo findJudgmentList(JudgmentSearch search) {
long allStart = System.currentTimeMillis();
injectOrgChecked(search);
List<JudgmentExport> judgmentList = vehicleMapper.findJudgmentList(search);
if (CollectionUtil.isEmpty(judgmentList)) {
log.info("judgment.search early-return: baseListEmpty=true, costMs={}", (System.currentTimeMillis() - allStart));
return new PageInfo<>();
}
log.info("judgment.search baseListSize={}", judgmentList.size());
List<String> snList = judgmentList.stream().map(JudgmentExport::getSn).collect(Collectors.toList());
long remoteStart = System.currentTimeMillis();
PageInfo stuJudgeAlarmListByPage;
try {
stuJudgeAlarmListByPage = remoteStuJudgeAlarmService.searchStuJudgeAlarmListByPage(snList, search);
} catch (RuntimeException ex) {
log.error("judgment.search remote-call-failed: snSize={}, costMs={}, error={}",
snList != null ? snList.size() : 0, (System.currentTimeMillis() - remoteStart), ex.toString());
throw ex;
}
log.info("judgment.search remote-call-ok: snSize={}, remoteCount={}, costMs={}",
snList != null ? snList.size() : 0,
stuJudgeAlarmListByPage != null && stuJudgeAlarmListByPage.getList() != null ? stuJudgeAlarmListByPage.getList().size() : 0,
(System.currentTimeMillis() - remoteStart));
List<StuJudgeAlarmDto> stuJudgeAlarmList = JSON.parseArray(JSON.toJSONString(stuJudgeAlarmListByPage.getList()), StuJudgeAlarmDto.class);
if (CollectionUtil.isEmpty(stuJudgeAlarmList)) {
log.info("judgment.search early-return: remoteListEmpty=true, costMs={}", (System.currentTimeMillis() - allStart));
return new PageInfo<>();
}
Map<String, JudgmentExport> judgmentExportMap = judgmentList.stream().filter(judExport -> StringUtils.isNotBlank(judExport.getSn())).collect(Collectors.toMap(JudgmentExport::getSn, Function.identity(), (v1, v2) -> v1));
List<JudgmentExport> judgmentExportList = Lists.newArrayList();
stuJudgeAlarmList.forEach(stuJudgeAlarm -> {
if (StringUtils.isBlank(stuJudgeAlarm.getSn())) {
return;
}
JudgmentExport judgmentExportTemp = judgmentExportMap.get(stuJudgeAlarm.getSn());
if (judgmentExportTemp != null) {
JudgmentExport judgmentExport = new JudgmentExport();
BeanUtils.copyProperties(judgmentExportTemp, judgmentExport);
judgmentExport.setSourceStr(TypeConverseEnum.SourceEnum.getStrBySourceType(judgmentExport.getSource()));
judgmentExport.setAlarmType(stuJudgeAlarm.getAlarmType());
judgmentExport.setAlarmTypeStr(TypeConverseEnum.AlarmTypeEnum.getStrByAlarmType(stuJudgeAlarm.getAlarmType()));
judgmentExport.setAlarmStatus(stuJudgeAlarm.getAlarmStatus());
judgmentExport.setAlarmStatusStr(TypeConverseEnum.AlarmStatusEnum.getStrByAlarmStatus(stuJudgeAlarm.getAlarmStatus()));
judgmentExport.setGeoCode(stuJudgeAlarm.getGeoCode());
judgmentExport.setAlarmAddress(stuJudgeAlarm.getAlarmAddress());
judgmentExport.setAlarmBeginTime(stuJudgeAlarm.getAlarmBeginTime());
judgmentExport.setAlarmEndTime(stuJudgeAlarm.getAlarmEndTime());
if (TypeConverseEnum.AlarmStatusEnum.TAKE_EFFECT.getAlarmStatus().equals(stuJudgeAlarm.getAlarmStatus())) {
// 如果警情为生效警情 则将失效时间设备为 --
judgmentExport.setAlarmEndTime("--");
}
// 计算报警持续时间(驶出-进入):显示规则 <1天按小时;≥1天按X天Y小时;任一时间为"--"时显示"--"
if ("--".equals(judgmentExport.getAlarmBeginTime()) || "--".equals(judgmentExport.getAlarmEndTime())) {
judgmentExport.setAlarmDuration("--");
} else {
try {
java.util.Date begin = DateUtil.parse(judgmentExport.getAlarmBeginTime());
java.util.Date end = DateUtil.parse(judgmentExport.getAlarmEndTime());
long diffMs = end.getTime() - begin.getTime();
if (diffMs <= 0) {
judgmentExport.setAlarmDuration("0小时");
} else {
long hours = diffMs / (1000 * 60 * 60);
if (hours < 24) {
judgmentExport.setAlarmDuration(hours + "小时");
} else {
long days = hours / 24;
long remainHours = hours % 24;
judgmentExport.setAlarmDuration(days + "天" + remainHours + "小时");
}
}
} catch (Exception e) {
judgmentExport.setAlarmDuration("--");
}
}
judgmentExport.setAlarmLng(stuJudgeAlarm.getAlarmLng());
judgmentExport.setAlarmLat(stuJudgeAlarm.getAlarmLat());
judgmentExport.setAlarmAddress(stuJudgeAlarm.getAlarmAddress());
judgmentExport.setAlarmCount(stuJudgeAlarm.getAlarmCount());
judgmentExport.setAlarmLevel(stuJudgeAlarm.getAlarmLevel());
judgmentExportList.add(judgmentExport);
}
});
stuJudgeAlarmListByPage.setList(judgmentExportList);
if (log.isDebugEnabled() && CollectionUtil.isNotEmpty(judgmentExportList)) {
JudgmentExport s = judgmentExportList.get(0);
log.debug("judgment.search sample: sn={}, vin={}, alarmType={}, alarmStatus={}",
s.getSn(), s.getVin(), s.getAlarmType(), s.getAlarmStatus());
}
log.info("judgment.search assembledCount={}, totalCostMs={}",
judgmentExportList.size(), (System.currentTimeMillis() - allStart));
return stuJudgeAlarmListByPage;
}
public List<JudgmentExport> exportJudgmentList(JudgmentSearch search) {
long allStart = System.currentTimeMillis();
injectOrgChecked(search);
List<JudgmentExport> judgmentList = vehicleMapper.findJudgmentList(search);
if (ObjectUtil.isNull(judgmentList)) {
log.info("judgment.export early-return: baseListNull=true, costMs={}", (System.currentTimeMillis() - allStart));
return null;
}
log.info("judgment.export baseListSize={}", judgmentList.size());
List<String> snList = judgmentList.stream().map(JudgmentExport::getSn).collect(Collectors.toList());
long remoteStart = System.currentTimeMillis();
List<StuJudgeAlarmDto> stuJudgeAlarmDtoList;
try {
stuJudgeAlarmDtoList = remoteStuJudgeAlarmService.searchStuJudgeAlarmDataList(snList, search);
} catch (RuntimeException ex) {
log.error("judgment.export remote-call-failed: snSize={}, costMs={}, error={}",
snList != null ? snList.size() : 0, (System.currentTimeMillis() - remoteStart), ex.toString());
throw ex;
}
log.info("judgment.export remote-call-ok: snSize={}, remoteCount={}, costMs={}",
snList != null ? snList.size() : 0,
stuJudgeAlarmDtoList != null ? stuJudgeAlarmDtoList.size() : 0,
(System.currentTimeMillis() - remoteStart));
if (CollectionUtil.isEmpty(stuJudgeAlarmDtoList)) {
log.info("judgment.export early-return: remoteListEmpty=true, costMs={}", (System.currentTimeMillis() - allStart));
return null;
}
Map<String, JudgmentExport> judgmentExportMap = judgmentList.stream().filter(judgement -> StringUtils.isNotBlank(judgement.getSn())).collect(Collectors.toMap(JudgmentExport::getSn, Function.identity(), (v1, v2) -> v1));
List<JudgmentExport> judgmentExportList = Lists.newArrayList();
stuJudgeAlarmDtoList.forEach(stuJudgeAlarm -> {
if (StringUtils.isBlank(stuJudgeAlarm.getSn())) {
return;
}
JudgmentExport judgmentExportTemp = judgmentExportMap.get(stuJudgeAlarm.getSn());
if (judgmentExportTemp != null) {
JudgmentExport judgmentExport = new JudgmentExport();
BeanUtils.copyProperties(judgmentExportTemp, judgmentExport);
judgmentExport.setSourceStr(TypeConverseEnum.SourceEnum.getStrBySourceType(judgmentExport.getSource()));
judgmentExport.setAlarmType(stuJudgeAlarm.getAlarmType());
judgmentExport.setAlarmTypeStr(TypeConverseEnum.AlarmTypeEnum.getStrByAlarmType(stuJudgeAlarm.getAlarmType()));
judgmentExport.setAlarmStatus(stuJudgeAlarm.getAlarmStatus());
judgmentExport.setAlarmStatusStr(TypeConverseEnum.AlarmStatusEnum.getStrByAlarmStatus(stuJudgeAlarm.getAlarmStatus()));
judgmentExport.setGeoCode(stuJudgeAlarm.getGeoCode());
judgmentExport.setAlarmAddress(stuJudgeAlarm.getAlarmAddress());
judgmentExport.setAlarmBeginTime(stuJudgeAlarm.getAlarmBeginTime());
judgmentExport.setAlarmEndTime(stuJudgeAlarm.getAlarmEndTime());
if (TypeConverseEnum.AlarmStatusEnum.TAKE_EFFECT.getAlarmStatus().equals(stuJudgeAlarm.getAlarmStatus())) {
// 如果警情为生效警情 则将失效时间设备为 --
judgmentExport.setAlarmEndTime("--");
}
// 计算报警持续时间(驶出-进入):显示规则 <1天按小时;≥1天按X天Y小时;任一时间为"--"时显示"--"
if ("--".equals(judgmentExport.getAlarmBeginTime()) || "--".equals(judgmentExport.getAlarmEndTime())) {
judgmentExport.setAlarmDuration("--");
} else {
try {
java.util.Date begin = DateUtil.parse(judgmentExport.getAlarmBeginTime());
java.util.Date end = DateUtil.parse(judgmentExport.getAlarmEndTime());
long diffMs = end.getTime() - begin.getTime();
if (diffMs <= 0) {
judgmentExport.setAlarmDuration("0小时");
} else {
long hours = diffMs / (1000 * 60 * 60);
if (hours < 24) {
judgmentExport.setAlarmDuration(hours + "小时");
} else {
long days = hours / 24;
long remainHours = hours % 24;
judgmentExport.setAlarmDuration(days + "天" + remainHours + "小时");
}
}
} catch (Exception e) {
judgmentExport.setAlarmDuration("--");
}
}
judgmentExport.setAlarmLng(stuJudgeAlarm.getAlarmLng());
judgmentExport.setAlarmLat(stuJudgeAlarm.getAlarmLat());
judgmentExport.setAlarmAddress(stuJudgeAlarm.getAlarmAddress());
judgmentExport.setAlarmCount(stuJudgeAlarm.getAlarmCount());
judgmentExport.setAlarmLevel(stuJudgeAlarm.getAlarmLevel());
judgmentExportList.add(judgmentExport);
}
});
if (log.isDebugEnabled() && CollectionUtil.isNotEmpty(judgmentExportList)) {
JudgmentExport s = judgmentExportList.get(0);
log.debug("judgment.export sample: sn={}, vin={}, alarmType={}, alarmStatus={}",
s.getSn(), s.getVin(), s.getAlarmType(), s.getAlarmStatus());
}
log.info("judgment.export assembledCount={}, totalCostMs={}",
judgmentExportList.size(), (System.currentTimeMillis() - allStart));
return judgmentExportList;
}
}