AlarmDsmServiceImpl.java
2.27 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
package com.bsth.service.alarm.impl;
import com.bsth.data.alarm.AlarmCenter;
import com.bsth.message.entity.AlarmADASVo;
import com.bsth.message.entity.AlarmDSMVo;
import com.bsth.service.alarm.AlarmDsmService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.lang.reflect.Field;
import java.util.*;
@Service
public class AlarmDsmServiceImpl implements AlarmDsmService {
@Override
public List<AlarmDSMVo> list(Map<String, String> map, int page, int size, String order, int direction) {
List<AlarmDSMVo> alarmDSMVoList = new ArrayList<>();
for (AlarmDSMVo alarmDSMVo : AlarmCenter.findAllDsm()) {
try {
if (filter(alarmDSMVo, map)) {
alarmDSMVoList.add(alarmDSMVo);
}
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return alarmDSMVoList;
}
private boolean filter(Object obj, Map<String, String> param) throws NoSuchFieldException, IllegalAccessException {
boolean result = true;
ObjectMapper mapper = new ObjectMapper();
if (param.get("lines") != null) {
AlarmDSMVo alarmDSMVo = (AlarmDSMVo) obj;
if (param.get("lines").toString().indexOf(String.format("%s,", alarmDSMVo.getLineCode())) < 0) {
return false;
}
}
AlarmDSMVo other = mapper.convertValue(param, AlarmDSMVo.class);
Field[] fields = obj.getClass().getDeclaredFields();
for (Map.Entry<String, String> entry : param.entrySet()) {
String key = entry.getKey(), val = entry.getValue();
if (StringUtils.isEmpty(val)) {
continue;
}
for (Field field : fields) {
if (field.getName().equals(key)) {
field.setAccessible(true);
Object fv1 = field.get(obj), fv2 = field.get(other);
if (!fv2.equals(fv1)) {
return false;
}
}
}
}
return result;
}
}