Commit 0d922d5257fb149a16a7a0b14488f60196c2f109

Authored by xp.Huang
1 parent 09ba724a

perf: 抽离controller的startTime、endTime验证到BaseController

@@ -110,6 +110,7 @@ import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService; @@ -110,6 +110,7 @@ import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService;
110 110
111 import javax.mail.MessagingException; 111 import javax.mail.MessagingException;
112 import javax.servlet.http.HttpServletResponse; 112 import javax.servlet.http.HttpServletResponse;
  113 +import java.sql.Timestamp;
113 import java.util.*; 114 import java.util.*;
114 115
115 import static org.thingsboard.server.controller.ControllerConstants.DEFAULT_PAGE_SIZE; 116 import static org.thingsboard.server.controller.ControllerConstants.DEFAULT_PAGE_SIZE;
@@ -978,4 +979,16 @@ public abstract class BaseController { @@ -978,4 +979,16 @@ public abstract class BaseController {
978 dto.setPublicId(publicCustomerId); 979 dto.setPublicId(publicCustomerId);
979 } 980 }
980 } 981 }
  982 +
  983 + protected void checkTimeAndPut(Map<String, Object> queryMap,Long startTime,Long endTime)
  984 + {
  985 + if (null != endTime && null != startTime) {
  986 + if (startTime > endTime) {
  987 + throw new TkDataValidationException(
  988 + ErrorMessage.START_TIME_NOT_MORE_THAN_END_TIME.getMessage());
  989 + }
  990 + queryMap.put("startTime", new Timestamp(startTime).toLocalDateTime());
  991 + queryMap.put("endTime", new Timestamp(endTime).toLocalDateTime());
  992 + }
  993 + }
981 } 994 }
@@ -61,14 +61,7 @@ public class SysJobLogController extends BaseController { @@ -61,14 +61,7 @@ public class SysJobLogController extends BaseController {
61 queryMap.put(ORDER_TYPE, orderType.name()); 61 queryMap.put(ORDER_TYPE, orderType.name());
62 } 62 }
63 63
64 - if (null != startTime && null != endTime) {  
65 - if (startTime > endTime) {  
66 - throw new TkDataValidationException(  
67 - ErrorMessage.START_TIME_NOT_MORE_THAN_END_TIME.getMessage());  
68 - }  
69 - queryMap.put("startTime", new Timestamp(startTime).toLocalDateTime());  
70 - queryMap.put("endTime", new Timestamp(endTime).toLocalDateTime());  
71 - } 64 + checkTimeAndPut(queryMap,startTime,endTime);
72 return tkSysJobLogService.sysJobLogPageByJobId(queryMap); 65 return tkSysJobLogService.sysJobLogPageByJobId(queryMap);
73 } 66 }
74 67
@@ -136,14 +136,7 @@ public class TkDeviceScriptController extends BaseController { @@ -136,14 +136,7 @@ public class TkDeviceScriptController extends BaseController {
136 if (!StringUtils.isEmpty(name)) { 136 if (!StringUtils.isEmpty(name)) {
137 queryMap.put("name", name); 137 queryMap.put("name", name);
138 } 138 }
139 - if (null != startTime && null != endTime) {  
140 - if (startTime > endTime) {  
141 - throw new TkDataValidationException(  
142 - ErrorMessage.START_TIME_NOT_MORE_THAN_END_TIME.getMessage());  
143 - }  
144 - queryMap.put("startTime", new Timestamp(startTime).toLocalDateTime());  
145 - queryMap.put("endTime", new Timestamp(endTime).toLocalDateTime());  
146 - } 139 + checkTimeAndPut(queryMap,startTime,endTime);
147 140
148 return scriptService.page(queryMap, getCurrentUser().isTenantAdmin()); 141 return scriptService.page(queryMap, getCurrentUser().isTenantAdmin());
149 } 142 }
@@ -54,14 +54,7 @@ public class TkDeviceStateLogController extends BaseController { @@ -54,14 +54,7 @@ public class TkDeviceStateLogController extends BaseController {
54 queryMap.put("organizationName", organizationName); 54 queryMap.put("organizationName", organizationName);
55 queryMap.put("deviceProfileName", deviceProfileName); 55 queryMap.put("deviceProfileName", deviceProfileName);
56 queryMap.put("status", status); 56 queryMap.put("status", status);
57 - if (null != startTime && null != endTime) {  
58 - if (startTime > endTime) {  
59 - throw new TkDataValidationException(  
60 - ErrorMessage.START_TIME_NOT_MORE_THAN_END_TIME.getMessage());  
61 - }  
62 - queryMap.put("startTime", new Timestamp(startTime).toLocalDateTime());  
63 - queryMap.put("endTime", new Timestamp(endTime).toLocalDateTime());  
64 - } 57 + checkTimeAndPut(queryMap,startTime,endTime);
65 queryMap.put(PAGE_SIZE, pageSize); 58 queryMap.put(PAGE_SIZE, pageSize);
66 queryMap.put(PAGE, page); 59 queryMap.put(PAGE, page);
67 queryMap.put(ORDER_FILED, orderBy); 60 queryMap.put(ORDER_FILED, orderBy);
@@ -64,14 +64,7 @@ public class TkReportFormConfigController extends BaseController { @@ -64,14 +64,7 @@ public class TkReportFormConfigController extends BaseController {
64 queryMap.put(ORDER_TYPE, orderType.name()); 64 queryMap.put(ORDER_TYPE, orderType.name());
65 } 65 }
66 queryMap.put("userId",getCurrentUser().getCurrentUserId()); 66 queryMap.put("userId",getCurrentUser().getCurrentUserId());
67 - if (null != startTime && null != endTime) {  
68 - if (startTime > endTime) {  
69 - throw new TkDataValidationException(  
70 - ErrorMessage.START_TIME_NOT_MORE_THAN_END_TIME.getMessage());  
71 - }  
72 - queryMap.put("startTime", new Timestamp(startTime).toLocalDateTime());  
73 - queryMap.put("endTime", new Timestamp(endTime).toLocalDateTime());  
74 - } 67 + checkTimeAndPut(queryMap,startTime,endTime);
75 return reportFormConfigService.page(queryMap, getCurrentUser().isTenantAdmin()); 68 return reportFormConfigService.page(queryMap, getCurrentUser().isTenantAdmin());
76 } 69 }
77 70
@@ -57,15 +57,7 @@ public class TkReportGenerateRecordController extends BaseController { @@ -57,15 +57,7 @@ public class TkReportGenerateRecordController extends BaseController {
57 throws ThingsboardException { 57 throws ThingsboardException {
58 58
59 HashMap<String, Object> queryMap = new HashMap<>(); 59 HashMap<String, Object> queryMap = new HashMap<>();
60 - if (null != startTime && null != endTime) {  
61 - if (startTime > endTime) {  
62 - throw new TkDataValidationException(  
63 - ErrorMessage.START_TIME_NOT_MORE_THAN_END_TIME.getMessage());  
64 - }  
65 -  
66 - queryMap.put("startTime", new Timestamp(startTime).toLocalDateTime());  
67 - queryMap.put("endTime", new Timestamp(endTime).toLocalDateTime());  
68 - } 60 + checkTimeAndPut(queryMap,startTime,endTime);
69 queryMap.put(PAGE_SIZE, pageSize); 61 queryMap.put(PAGE_SIZE, pageSize);
70 queryMap.put(PAGE, page); 62 queryMap.put(PAGE, page);
71 queryMap.put(ORDER_FILED, orderBy); 63 queryMap.put(ORDER_FILED, orderBy);