Showing
5 changed files
with
164 additions
and
115 deletions
... | ... | @@ -29,9 +29,7 @@ import java.util.UUID; |
29 | 29 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; |
30 | 30 | |
31 | 31 | /** |
32 | - * @Description 告警中心 | |
33 | - * @Author cxy | |
34 | - * @Date 2021/11/11 9:23 | |
32 | + * @Description 告警中心 @Author cxy @Date 2021/11/11 9:23 | |
35 | 33 | */ |
36 | 34 | @RestController |
37 | 35 | @RequestMapping("/api/yt/alarm") |
... | ... | @@ -39,47 +37,56 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. |
39 | 37 | @Api(tags = "告警中心") |
40 | 38 | public class TkAlarmInfoController extends BaseController { |
41 | 39 | |
42 | - private final TkAlarmInfoService alarmInfoService; | |
40 | + private final TkAlarmInfoService alarmInfoService; | |
43 | 41 | |
42 | + // 分页测试通过 | |
43 | + @ApiOperation(value = "查询") | |
44 | + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})") | |
45 | + @GetMapping(params = {PAGE_SIZE, PAGE}) | |
46 | + public TkPageData<TkAlarmEntity> pageAlarmInfo( | |
47 | + @RequestParam(PAGE_SIZE) int pageSize, | |
48 | + @RequestParam(PAGE) int page, | |
49 | + @RequestParam(value = "status", required = false) List<AlarmStatus> status, | |
50 | + @RequestParam(value = "alarmType", required = false) String alarmType, | |
51 | + @RequestParam(value = "severity", required = false) AlarmSeverity severity, | |
52 | + @RequestParam(value = "organizationId", required = false) String organizationId, | |
53 | + @RequestParam(value = "deviceId", required = false) String deviceId, | |
54 | + @RequestParam(value = "deviceName", required = false) String deviceName, | |
55 | + @RequestParam(value = "deviceType", required = false) DeviceTypeEnum deviceType, | |
56 | + @RequestParam(value = "startTime", required = false) Long startTime, | |
57 | + @RequestParam(value = "endTime", required = false) Long endTime, | |
58 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | |
59 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) | |
60 | + throws ThingsboardException { | |
61 | + Map<String, Object> pageFilter = new HashMap<>(); | |
62 | + pageFilter.put(PAGE_SIZE, pageSize); | |
63 | + pageFilter.put(PAGE, page); | |
64 | + pageFilter.put(ORDER_FILED, orderBy); | |
65 | + pageFilter.put(ORDER_TYPE, orderType); | |
44 | 66 | |
45 | - //分页测试通过 | |
46 | - @ApiOperation(value = "查询") | |
47 | - @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})") | |
48 | - @GetMapping(params = {PAGE_SIZE, PAGE}) | |
49 | - public TkPageData<TkAlarmEntity> pageAlarmInfo( | |
50 | - @RequestParam(PAGE_SIZE) int pageSize, | |
51 | - @RequestParam(PAGE) int page, | |
52 | - @RequestParam(value = "status", required = false) List<AlarmStatus> status, | |
53 | - @RequestParam(value = "textSearch", required = false) String textSearch, | |
54 | - @RequestParam(value = "alarmType", required = false) String alarmType, | |
55 | - @RequestParam(value = "severity", required = false) AlarmSeverity severity, | |
56 | - @RequestParam(value = "organizationId", required = false) String organizationId, | |
57 | - @RequestParam(value = "deviceId", required = false) String deviceId, | |
58 | - @RequestParam(value = "deviceType", required = false) DeviceTypeEnum deviceType, | |
59 | - @RequestParam(value = "startTime", required = false) Long startTime, | |
60 | - @RequestParam(value = "endTime", required = false) Long endTime, | |
61 | - @RequestParam(value = ORDER_FILED, required = false) String orderBy, | |
62 | - @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) throws ThingsboardException { | |
63 | - Map<String, Object> pageFilter = new HashMap<>(); | |
64 | - pageFilter.put(PAGE_SIZE, pageSize); | |
65 | - pageFilter.put(PAGE, page); | |
66 | - pageFilter.put(ORDER_FILED, orderBy); | |
67 | - pageFilter.put(ORDER_TYPE, orderType); | |
68 | - | |
69 | - UUID customerId = null; | |
70 | - if(getCurrentUser().isCustomerUser()){ | |
71 | - customerId = getCurrentUser().getCustomerId().getId(); | |
72 | - } | |
73 | - return alarmInfoService.alarmPage(pageFilter, getCurrentUser().getTenantId(), customerId,severity,alarmType, startTime, endTime, status, deviceId, deviceType, EntityType.DEVICE, organizationId); | |
67 | + UUID customerId = null; | |
68 | + if (getCurrentUser().isCustomerUser()) { | |
69 | + customerId = getCurrentUser().getCustomerId().getId(); | |
74 | 70 | } |
71 | + return alarmInfoService.alarmPage( | |
72 | + pageFilter, | |
73 | + getCurrentUser().getTenantId(), | |
74 | + customerId, | |
75 | + severity, | |
76 | + alarmType, | |
77 | + startTime, | |
78 | + endTime, | |
79 | + status, | |
80 | + deviceId, | |
81 | + deviceName, | |
82 | + deviceType, | |
83 | + EntityType.DEVICE, | |
84 | + organizationId); | |
85 | + } | |
75 | 86 | |
76 | - | |
77 | - @ApiOperation(value = "告警类型") | |
78 | - @GetMapping() | |
79 | - public ResponseEntity<List<SysDictDTO>> alarmType() throws ThingsboardException { | |
80 | - List result = alarmInfoService.alarmType(getCurrentUser().getTenantId()); | |
81 | - return ResponseEntity.ok(result); | |
82 | - } | |
83 | - | |
84 | - | |
87 | + @ApiOperation(value = "告警类型") | |
88 | + @GetMapping() | |
89 | + public ResponseEntity<List<SysDictDTO>> alarmType() throws ThingsboardException { | |
90 | + return ResponseEntity.ok(alarmInfoService.alarmType(getCurrentUser().getTenantId())); | |
91 | + } | |
85 | 92 | } | ... | ... |
... | ... | @@ -38,62 +38,88 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. |
38 | 38 | @Slf4j |
39 | 39 | public class TkAlarmInfoServiceImpl implements TkAlarmInfoService { |
40 | 40 | |
41 | - private final TkAlarmMapper ytJpaAarmDao; | |
42 | - private final OrganizationMapper organizationMapper; | |
41 | + private final TkAlarmMapper tkJpaAarmDao; | |
42 | + private final OrganizationMapper organizationMapper; | |
43 | 43 | |
44 | - @Override | |
45 | - public TkPageData<TkAlarmEntity> alarmPage(Map<String, Object> pageMap, TenantId tenantId, UUID customerId, AlarmSeverity severity, String alarmType, Long startTime, Long endTime, List<AlarmStatus> status, String deviceId, DeviceTypeEnum deviceType, EntityType originatorType, String organizationId) { | |
46 | - StringBuilder defaultOrderFields = new StringBuilder("ack_ts asc,clear_ts asc,"); | |
47 | - defaultOrderFields.append(ModelConstants.CREATED_TIME_PROPERTY); | |
48 | - IPage<TkAlarmEntity> page = getPage(pageMap, defaultOrderFields.toString(), OrderTypeEnum.DESC); | |
49 | - List<String> ids = new ArrayList<>(); | |
50 | - if (StringUtils.isNotBlank(organizationId)) { | |
51 | - List<String> filter = new ArrayList<>(); | |
52 | - filter.add(organizationId); | |
53 | - List<OrganizationDTO> all = organizationMapper.findOrganizationTreeList(tenantId.getId().toString(), filter); | |
54 | - for (OrganizationDTO item : all) { | |
55 | - ids.add(item.getId()); | |
56 | - } | |
57 | - | |
58 | - } | |
59 | - | |
60 | - IPage<TkAlarmEntity> tbDatas = ytJpaAarmDao.alarmPage(page, tenantId.getId(), customerId, severity, alarmType, startTime, endTime, status, deviceId, deviceType, originatorType, ids.size() > 0 ? ids : null); | |
61 | - TkPageData<TkAlarmEntity> result = new TkPageData<>(tbDatas.getRecords(), tbDatas.getTotal()); | |
62 | - return result; | |
44 | + @Override | |
45 | + public TkPageData<TkAlarmEntity> alarmPage( | |
46 | + Map<String, Object> pageMap, | |
47 | + TenantId tenantId, | |
48 | + UUID customerId, | |
49 | + AlarmSeverity severity, | |
50 | + String alarmType, | |
51 | + Long startTime, | |
52 | + Long endTime, | |
53 | + List<AlarmStatus> status, | |
54 | + String deviceId, | |
55 | + String deviceName, | |
56 | + DeviceTypeEnum deviceType, | |
57 | + EntityType originatorType, | |
58 | + String organizationId) { | |
59 | + StringBuilder defaultOrderFields = new StringBuilder("ack_ts asc,clear_ts asc,"); | |
60 | + defaultOrderFields.append(ModelConstants.CREATED_TIME_PROPERTY); | |
61 | + IPage<TkAlarmEntity> page = getPage(pageMap, defaultOrderFields.toString(), OrderTypeEnum.DESC); | |
62 | + List<String> ids = new ArrayList<>(); | |
63 | + if (StringUtils.isNotBlank(organizationId)) { | |
64 | + List<String> filter = new ArrayList<>(); | |
65 | + filter.add(organizationId); | |
66 | + List<OrganizationDTO> all = | |
67 | + organizationMapper.findOrganizationTreeList(tenantId.getId().toString(), filter); | |
68 | + for (OrganizationDTO item : all) { | |
69 | + ids.add(item.getId()); | |
70 | + } | |
63 | 71 | } |
64 | 72 | |
73 | + IPage<TkAlarmEntity> tbDatas = | |
74 | + tkJpaAarmDao.alarmPage( | |
75 | + page, | |
76 | + tenantId.getId(), | |
77 | + customerId, | |
78 | + severity, | |
79 | + alarmType, | |
80 | + startTime, | |
81 | + endTime, | |
82 | + status, | |
83 | + deviceId, | |
84 | + deviceName, | |
85 | + deviceType, | |
86 | + originatorType, | |
87 | + ids.size() > 0 ? ids : null); | |
88 | + return new TkPageData<>(tbDatas.getRecords(), tbDatas.getTotal()); | |
89 | + } | |
65 | 90 | |
66 | - protected IPage<TkAlarmEntity> getPage(Map<String, Object> params, String defaultOrderField, OrderTypeEnum defaultOrder) { | |
67 | - int curPage = 1; | |
68 | - int limit = 10; | |
69 | - if (params.get(PAGE) != null) { | |
70 | - curPage = Integer.parseInt(params.get(PAGE).toString()); | |
71 | - } | |
72 | - | |
73 | - if (params.get(PAGE_SIZE) != null) { | |
74 | - limit = Integer.parseInt(params.get(PAGE_SIZE).toString()); | |
75 | - } | |
76 | - | |
77 | - Page<TkAlarmEntity> page = new Page<>(curPage, limit); | |
78 | - String orderField = (String) params.get(ORDER_FILED); | |
79 | - OrderTypeEnum order = (OrderTypeEnum) params.get(ORDER_TYPE); | |
80 | - if(StringUtils.isBlank(orderField)){ | |
81 | - orderField = defaultOrderField; | |
82 | - } | |
83 | - if(order == null){ | |
84 | - order = defaultOrder; | |
85 | - } | |
86 | - if(OrderTypeEnum.ASC.equals(order)){ | |
87 | - page.addOrder(OrderItem.asc(orderField)); | |
88 | - }else{ | |
89 | - page.addOrder(OrderItem.desc(orderField)); | |
90 | - } | |
91 | + protected IPage<TkAlarmEntity> getPage( | |
92 | + Map<String, Object> params, String defaultOrderField, OrderTypeEnum defaultOrder) { | |
93 | + int curPage = 1; | |
94 | + int limit = 10; | |
95 | + if (params.get(PAGE) != null) { | |
96 | + curPage = Integer.parseInt(params.get(PAGE).toString()); | |
97 | + } | |
91 | 98 | |
92 | - return page; | |
99 | + if (params.get(PAGE_SIZE) != null) { | |
100 | + limit = Integer.parseInt(params.get(PAGE_SIZE).toString()); | |
93 | 101 | } |
94 | 102 | |
95 | - @Override | |
96 | - public List<SysDictDTO> alarmType(TenantId tenantId) { | |
97 | - return ReflectUtils.sourceToTarget(ytJpaAarmDao.alarmType(tenantId.getId()), SysDictDTO.class); | |
103 | + Page<TkAlarmEntity> page = new Page<>(curPage, limit); | |
104 | + String orderField = (String) params.get(ORDER_FILED); | |
105 | + OrderTypeEnum order = (OrderTypeEnum) params.get(ORDER_TYPE); | |
106 | + if (StringUtils.isBlank(orderField)) { | |
107 | + orderField = defaultOrderField; | |
98 | 108 | } |
109 | + if (order == null) { | |
110 | + order = defaultOrder; | |
111 | + } | |
112 | + if (OrderTypeEnum.ASC.equals(order)) { | |
113 | + page.addOrder(OrderItem.asc(orderField)); | |
114 | + } else { | |
115 | + page.addOrder(OrderItem.desc(orderField)); | |
116 | + } | |
117 | + | |
118 | + return page; | |
119 | + } | |
120 | + | |
121 | + @Override | |
122 | + public List<SysDictDTO> alarmType(TenantId tenantId) { | |
123 | + return ReflectUtils.sourceToTarget(tkJpaAarmDao.alarmType(tenantId.getId()), SysDictDTO.class); | |
124 | + } | |
99 | 125 | } | ... | ... |
... | ... | @@ -27,6 +27,7 @@ public interface TkAlarmMapper extends BaseMapper<TkAlarmEntity> { |
27 | 27 | ,@Param("endTime")Long endTime |
28 | 28 | ,@Param("status")List<AlarmStatus> status |
29 | 29 | ,@Param("deviceId")String deviceId |
30 | + ,@Param("deviceName")String deviceName | |
30 | 31 | ,@Param("deviceType") DeviceTypeEnum deviceType |
31 | 32 | ,@Param("originatorType") EntityType originatorType |
32 | 33 | ,@Param("organizationId")List<String> organizationId | ... | ... |
... | ... | @@ -18,27 +18,39 @@ import java.util.UUID; |
18 | 18 | */ |
19 | 19 | public interface TkAlarmInfoService { |
20 | 20 | |
21 | - | |
22 | - /** | |
23 | - * @param pageMap 分页排序信息 | |
24 | - * @param tenantId 租户ID | |
25 | - * @param alarmType 告警类型 | |
26 | - * @param startTime 过滤区间开始时间 | |
27 | - * @param endTime 过滤区间结束时间 | |
28 | - * @param status 告警状态 | |
29 | - * @param deviceId 告警设备ID,设备告警使用 | |
30 | - * @param originatorType 告警源类型 | |
31 | - * @param organizationId 告警所属组织 | |
32 | - * @return | |
33 | - */ | |
34 | - TkPageData<TkAlarmEntity> alarmPage(Map<String, Object> pageMap, TenantId tenantId, UUID customerId, AlarmSeverity severity, String alarmType, Long startTime, Long endTime, List<AlarmStatus> status, String deviceId, DeviceTypeEnum deviceType, EntityType originatorType, String organizationId); | |
35 | - | |
36 | - | |
37 | - /** | |
38 | - * 设备告警类型 | |
39 | - * @param tenantId | |
40 | - * @return | |
41 | - */ | |
42 | - List<SysDictDTO> alarmType(TenantId tenantId); | |
43 | - | |
21 | + /** | |
22 | + * @param pageMap 分页排序信息 | |
23 | + * @param tenantId 租户ID | |
24 | + * @param alarmType 告警类型 | |
25 | + * @param startTime 过滤区间开始时间 | |
26 | + * @param endTime 过滤区间结束时间 | |
27 | + * @param status 告警状态 | |
28 | + * @param deviceId 告警设备ID,设备告警使用 | |
29 | + * @param deviceName 告警设备名称 | |
30 | + * @param originatorType 告警源类型 | |
31 | + * @param organizationId 告警所属组织 | |
32 | + * @return | |
33 | + */ | |
34 | + TkPageData<TkAlarmEntity> alarmPage( | |
35 | + Map<String, Object> pageMap, | |
36 | + TenantId tenantId, | |
37 | + UUID customerId, | |
38 | + AlarmSeverity severity, | |
39 | + String alarmType, | |
40 | + Long startTime, | |
41 | + Long endTime, | |
42 | + List<AlarmStatus> status, | |
43 | + String deviceId, | |
44 | + String deviceName, | |
45 | + DeviceTypeEnum deviceType, | |
46 | + EntityType originatorType, | |
47 | + String organizationId); | |
48 | + | |
49 | + /** | |
50 | + * 设备告警类型 | |
51 | + * | |
52 | + * @param tenantId | |
53 | + * @return | |
54 | + */ | |
55 | + List<SysDictDTO> alarmType(TenantId tenantId); | |
44 | 56 | } | ... | ... |