Showing
3 changed files
with
19 additions
and
20 deletions
@@ -3,6 +3,7 @@ package org.thingsboard.server.controller.yunteng; | @@ -3,6 +3,7 @@ package org.thingsboard.server.controller.yunteng; | ||
3 | import io.swagger.annotations.Api; | 3 | import io.swagger.annotations.Api; |
4 | import io.swagger.annotations.ApiOperation; | 4 | import io.swagger.annotations.ApiOperation; |
5 | import lombok.RequiredArgsConstructor; | 5 | import lombok.RequiredArgsConstructor; |
6 | +import org.apache.commons.lang3.StringUtils; | ||
6 | import org.springframework.http.ResponseEntity; | 7 | import org.springframework.http.ResponseEntity; |
7 | import org.springframework.security.access.prepost.PreAuthorize; | 8 | import org.springframework.security.access.prepost.PreAuthorize; |
8 | import org.springframework.web.bind.annotation.GetMapping; | 9 | import org.springframework.web.bind.annotation.GetMapping; |
@@ -62,14 +63,12 @@ public class YtAlarmInfoController extends BaseController { | @@ -62,14 +63,12 @@ public class YtAlarmInfoController extends BaseController { | ||
62 | @RequestParam(value = "endTime", required = false) Long endTime, | 63 | @RequestParam(value = "endTime", required = false) Long endTime, |
63 | @RequestParam(value = ORDER_FILED, required = false) String orderBy, | 64 | @RequestParam(value = ORDER_FILED, required = false) String orderBy, |
64 | @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) throws ThingsboardException { | 65 | @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) throws ThingsboardException { |
65 | - TimePageLink pageLink = createTimePageLink(pageSize, page > 1 ? page - 1 : 0, textSearch, orderBy, orderType == null ? "" : orderType.name(), startTime, endTime); | ||
66 | Map<String, Object> pageFilter = new HashMap<>(); | 66 | Map<String, Object> pageFilter = new HashMap<>(); |
67 | pageFilter.put(PAGE_SIZE, pageSize); | 67 | pageFilter.put(PAGE_SIZE, pageSize); |
68 | pageFilter.put(PAGE, page); | 68 | pageFilter.put(PAGE, page); |
69 | pageFilter.put(ORDER_FILED, orderBy); | 69 | pageFilter.put(ORDER_FILED, orderBy); |
70 | - if (orderType != null) { | ||
71 | - pageFilter.put(ORDER_TYPE, orderType.name()); | ||
72 | - } | 70 | + pageFilter.put(ORDER_TYPE, orderType); |
71 | + | ||
73 | UUID customerId = null; | 72 | UUID customerId = null; |
74 | if(getCurrentUser().isCustomerUser()){ | 73 | if(getCurrentUser().isCustomerUser()){ |
75 | customerId = getCurrentUser().getCustomerId().getId(); | 74 | customerId = getCurrentUser().getCustomerId().getId(); |
@@ -38,6 +38,7 @@ public class ModelConstants { | @@ -38,6 +38,7 @@ public class ModelConstants { | ||
38 | */ | 38 | */ |
39 | public static final String ID_PROPERTY = "id"; | 39 | public static final String ID_PROPERTY = "id"; |
40 | public static final String CREATED_TIME_PROPERTY = "created_time"; | 40 | public static final String CREATED_TIME_PROPERTY = "created_time"; |
41 | + public static final String STATUS_PROPERTY = "status"; | ||
41 | public static final String USER_ID_PROPERTY = "user_id"; | 42 | public static final String USER_ID_PROPERTY = "user_id"; |
42 | public static final String TENANT_ID_PROPERTY = "tenant_id"; | 43 | public static final String TENANT_ID_PROPERTY = "tenant_id"; |
43 | public static final String CUSTOMER_ID_PROPERTY = "customer_id"; | 44 | public static final String CUSTOMER_ID_PROPERTY = "customer_id"; |
@@ -44,7 +44,7 @@ public class YtAlarmInfoServiceImpl implements YtAlarmInfoService { | @@ -44,7 +44,7 @@ public class YtAlarmInfoServiceImpl implements YtAlarmInfoService { | ||
44 | 44 | ||
45 | @Override | 45 | @Override |
46 | public YtPageData<YtAlarmEntity> 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 | public YtPageData<YtAlarmEntity> 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) { |
47 | - IPage<YtAlarmEntity> page = getPage(pageMap, ModelConstants.CREATED_TIME_PROPERTY, false); | 47 | + IPage<YtAlarmEntity> page = getPage(pageMap, ModelConstants.STATUS_PROPERTY, OrderTypeEnum.ASC); |
48 | List<String> ids = new ArrayList<>(); | 48 | List<String> ids = new ArrayList<>(); |
49 | if (StringUtils.isNotBlank(organizationId)) { | 49 | if (StringUtils.isNotBlank(organizationId)) { |
50 | List<String> filter = new ArrayList<>(); | 50 | List<String> filter = new ArrayList<>(); |
@@ -62,7 +62,7 @@ public class YtAlarmInfoServiceImpl implements YtAlarmInfoService { | @@ -62,7 +62,7 @@ public class YtAlarmInfoServiceImpl implements YtAlarmInfoService { | ||
62 | } | 62 | } |
63 | 63 | ||
64 | 64 | ||
65 | - protected IPage<YtAlarmEntity> getPage(Map<String, Object> params, String defaultOrderField, boolean isAsc) { | 65 | + protected IPage<YtAlarmEntity> getPage(Map<String, Object> params, String defaultOrderField, OrderTypeEnum defaultOrder) { |
66 | int curPage = 1; | 66 | int curPage = 1; |
67 | int limit = 10; | 67 | int limit = 10; |
68 | if (params.get(PAGE) != null) { | 68 | if (params.get(PAGE) != null) { |
@@ -75,21 +75,20 @@ public class YtAlarmInfoServiceImpl implements YtAlarmInfoService { | @@ -75,21 +75,20 @@ public class YtAlarmInfoServiceImpl implements YtAlarmInfoService { | ||
75 | 75 | ||
76 | Page<YtAlarmEntity> page = new Page<>(curPage, limit); | 76 | Page<YtAlarmEntity> page = new Page<>(curPage, limit); |
77 | String orderField = (String) params.get(ORDER_FILED); | 77 | String orderField = (String) params.get(ORDER_FILED); |
78 | - String order = (String) params.get(ORDER_TYPE); | ||
79 | - if (StringUtils.isNotBlank(orderField) && StringUtils.isNotBlank(order)) { | ||
80 | - return OrderTypeEnum.ASC.name().equalsIgnoreCase(order) | ||
81 | - ? page.addOrder(OrderItem.asc(orderField)) | ||
82 | - : page.addOrder(OrderItem.desc(orderField)); | ||
83 | - } else if (StringUtils.isBlank(defaultOrderField)) { | ||
84 | - return page; | ||
85 | - } else { | ||
86 | - if (isAsc) { | ||
87 | - page.addOrder(OrderItem.asc(defaultOrderField)); | ||
88 | - } else { | ||
89 | - page.addOrder(OrderItem.desc(defaultOrderField)); | ||
90 | - } | ||
91 | - return page; | 78 | + OrderTypeEnum order = (OrderTypeEnum) params.get(ORDER_TYPE); |
79 | + if(StringUtils.isBlank(orderField)){ | ||
80 | + orderField = defaultOrderField; | ||
81 | + } | ||
82 | + if(order == null){ | ||
83 | + order = defaultOrder; | ||
92 | } | 84 | } |
85 | + if(OrderTypeEnum.ASC.equals(order)){ | ||
86 | + page.addOrder(OrderItem.asc(orderField)); | ||
87 | + }else{ | ||
88 | + page.addOrder(OrderItem.desc(orderField)); | ||
89 | + } | ||
90 | + | ||
91 | + return page; | ||
93 | } | 92 | } |
94 | 93 | ||
95 | @Override | 94 | @Override |