AlarmDsmController.java
2.17 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
package com.bsth.controller.alaram;
import com.bsth.common.ResponseCode;
import com.bsth.message.entity.AlarmDSMVo;
import com.bsth.service.alarm.AlarmDsmService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
@RestController
@RequestMapping("alarm_dsm")
public class AlarmDsmController {
private final static Logger log = LoggerFactory.getLogger(AlarmDsmController.class);
@Autowired
private AlarmDsmService alarmDsmService;
@RequestMapping(value = "/list")
public Map<String, Object> list(@RequestParam Map<String, String> param,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "15") int size,
@RequestParam(defaultValue = "timestamp") String order,
@RequestParam(defaultValue = "0") int direction) {
Map<String, Object> result = new HashMap<>();
try {
List<AlarmDSMVo> alarmDSMVoList = alarmDsmService.list(param, page, size, order, direction);
Collections.sort(alarmDSMVoList, new Comparator<AlarmDSMVo>() {
@Override
public int compare(AlarmDSMVo o1, AlarmDSMVo o2) {
return (int) (o2.getAlarmTimeBegin() - o1.getAlarmTimeBegin());
}
});
int total = alarmDSMVoList.size(), start = page * size, end = start + size;
if (end > total) {
end = total;
}
result.put("list", alarmDSMVoList.subList(start, end));
result.put("totalPages", total % size == 0 ? total / size - 1 : total / size);
result.put("page", page);
result.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
result.put("status", ResponseCode.ERROR);
log.error(e.getMessage(), e);
}
return result;
}
}