|
@@ -2,6 +2,7 @@ package com.pig4cloud.pig.statistics.api.dto.user;
|
|
|
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
+import jakarta.validation.constraints.AssertTrue;
|
|
|
import jakarta.validation.constraints.NotBlank;
|
|
|
import jakarta.validation.constraints.NotNull;
|
|
|
import lombok.Data;
|
|
@@ -9,6 +10,7 @@ import lombok.Data;
|
|
|
import java.io.Serial;
|
|
|
import java.io.Serializable;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -61,4 +63,64 @@ public class UserAnalyseQueryBaseDTO implements Serializable {
|
|
|
*/
|
|
|
@Schema(description = "版本", example = "[\"1.0.0\"]")
|
|
|
private List<String> version;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验规则1:fromDate不能大于toDate,只能小于等于
|
|
|
+ */
|
|
|
+ @Schema(hidden = true)
|
|
|
+ @AssertTrue(message = "开始时间不能晚于结束时间")
|
|
|
+ public boolean isFromDateLessThanOrEqualToToDate() {
|
|
|
+ if (fromDate == null || toDate == null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return !fromDate.isAfter(toDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验规则2:如果timeUnit为hour,则fromDate~toDate的天数不能大于一周
|
|
|
+ */
|
|
|
+ @Schema(hidden = true)
|
|
|
+ @AssertTrue(message = "小时维度查询时间跨度不能超过7天")
|
|
|
+ public boolean isHourTimeUnitWithinOneWeek() {
|
|
|
+ if (fromDate == null || toDate == null || timeUnit == null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if ("hour".equals(timeUnit)) {
|
|
|
+ long days = ChronoUnit.DAYS.between(fromDate, toDate);
|
|
|
+ return days < 7;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验规则3:如果timeUnit为week,则跨度不能小于一周
|
|
|
+ */
|
|
|
+ @Schema(hidden = true)
|
|
|
+ @AssertTrue(message = "周维度查询时间跨度不能小于7天")
|
|
|
+ public boolean isWeekTimeUnitAtLeastOneWeek() {
|
|
|
+ if (fromDate == null || toDate == null || timeUnit == null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if ("week".equals(timeUnit)) {
|
|
|
+ long days = ChronoUnit.DAYS.between(fromDate, toDate);
|
|
|
+ return days >= 7;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验规则4:月维度查询时间跨度不能小于30天
|
|
|
+ */
|
|
|
+ @Schema(hidden = true)
|
|
|
+ @AssertTrue(message = "月维度查询时间跨度不能小于30天")
|
|
|
+ public boolean isMonthTimeUnitAtLeastMonth() {
|
|
|
+ if (fromDate == null || toDate == null || timeUnit == null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if ("month".equals(timeUnit)) {
|
|
|
+ long days = ChronoUnit.DAYS.between(fromDate, toDate);
|
|
|
+ return days >= 30;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|