AlarmAdasServiceImpl.java
2.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
package com.bsth.service.alarm.impl;
import com.bsth.data.alarm.AlarmCenter;
import com.bsth.message.entity.AlarmADASVo;
import com.bsth.service.alarm.AlarmAdasService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service
public class AlarmAdasServiceImpl implements AlarmAdasService {
@Override
public List<AlarmADASVo> list(Map<String, String> map, int page, int size, String order, int direction) {
List<AlarmADASVo> alarmAdasVoList = new ArrayList<>();
for (AlarmADASVo alarmADASVo : AlarmCenter.findAllAdas()) {
try {
if (filter(alarmADASVo, map)) {
alarmAdasVoList.add(alarmADASVo);
}
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return alarmAdasVoList;
}
private boolean filter(Object obj, Map<String, String> param) throws NoSuchFieldException, IllegalAccessException {
boolean result = true;
ObjectMapper mapper = new ObjectMapper();
if (param.get("lines") != null) {
AlarmADASVo alarmADASVo = (AlarmADASVo) obj;
if (param.get("lines").toString().indexOf(String.format("%s,", alarmADASVo.getLineCode())) < 0) {
return false;
}
AlarmADASVo other = mapper.convertValue(param, AlarmADASVo.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;
}
}
}
}
} else {
result = false;
}
return result;
}
}