|
@@ -0,0 +1,102 @@
|
|
|
|
+package com.shkpr.service.aimodelpower.jsonbean.zilaishui;
|
|
|
|
+
|
|
|
|
+import com.global.base.log.LogLevelFlag;
|
|
|
|
+import com.global.base.log.LogPrintMgr;
|
|
|
|
+import com.shkpr.service.aimodelpower.commtools.TimeTool;
|
|
|
|
+import com.shkpr.service.aimodelpower.controllervalid.CommonParamValidList;
|
|
|
|
+import com.shkpr.service.aimodelpower.controllervalid.CommonParamValidSS;
|
|
|
|
+import lombok.Data;
|
|
|
|
+import org.hibernate.validator.constraints.Range;
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
+
|
|
|
|
+import java.time.Instant;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.ZoneId;
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
+import java.time.temporal.TemporalAdjusters;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @ClassName JPTbMHourPump
|
|
|
|
+ * @Description: TODO
|
|
|
|
+ * @Author LX
|
|
|
|
+ * @Date 2025/6/6
|
|
|
|
+ * @Version V1.0
|
|
|
|
+ **/
|
|
|
|
+@Data
|
|
|
|
+public class JPTbMHourPump {
|
|
|
|
+ private Boolean isPage = false;//是否分页 默认false
|
|
|
|
+
|
|
|
|
+ private String orgId;//水厂id
|
|
|
|
+
|
|
|
|
+ @Range(min = 0, max = 65535, groups = {CommonParamValidList.class, CommonParamValidSS.class})
|
|
|
|
+ private Integer limit = 20;//若分页 默认数为20
|
|
|
|
+
|
|
|
|
+ @Range(min = 0, max = Integer.MAX_VALUE, groups = {CommonParamValidList.class, CommonParamValidSS.class})
|
|
|
|
+ private Integer offset = 0;//若分页 默认起始值为0
|
|
|
|
+
|
|
|
|
+ private Long startDate;//开始日期 (实际时间为 年 月 日(就为当月的一号),时分秒为 00:00:00,如2023-03-01 00:00:00)
|
|
|
|
+
|
|
|
|
+ private Long endDate;//结束日期 (实际时间为 年 月 日(就为当月的一号),时分秒为 00:00:00,如2023-03-01 00:00:00)
|
|
|
|
+
|
|
|
|
+ //业务字段
|
|
|
|
+ private String forDateStr;
|
|
|
|
+
|
|
|
|
+ public boolean checkValid(){
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ if (startDate == null && endDate != null) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ StringBuilder strSql = new StringBuilder("");
|
|
|
|
+ if (startDate == null && endDate == null) {
|
|
|
|
+ //TODO 说明前端没传,那么默认为查今天0点到当前小时点的
|
|
|
|
+ LocalDateTime nowDate = LocalDateTime.now();//结束时间
|
|
|
|
+ nowDate = nowDate.withHour(0);
|
|
|
|
+ nowDate = nowDate.withMinute(0);
|
|
|
|
+ nowDate = nowDate.withSecond(0);
|
|
|
|
+
|
|
|
|
+ LocalDateTime startLocalDate = nowDate;
|
|
|
|
+
|
|
|
|
+ String startLocalDateStr = startLocalDate.format(formatter);
|
|
|
|
+ String endLocalDateStr = LocalDateTime.now().withMinute(0).withSecond(0).format(formatter);
|
|
|
|
+ strSql.append(" AND CONCAT(\"Date\", ' ', \"Hour\") BETWEEN '" + startLocalDateStr + "' " + "AND '" + endLocalDateStr + "'");
|
|
|
|
+ forDateStr = strSql.toString();
|
|
|
|
+ startDate = TimeTool.convertDateStr2UTC(startLocalDateStr);
|
|
|
|
+ endDate = TimeTool.convertDateStr2UTC(endLocalDateStr);
|
|
|
|
+ } else if (startDate != null && endDate != null) {
|
|
|
|
+ try {
|
|
|
|
+ LocalDateTime startLocalDate = LocalDateTime.parse(TimeTool.convertUTC2DateStr(startDate, TimeTool.TIMESTAMP_FORMAT), DateTimeFormatter.ofPattern(TimeTool.TIMESTAMP_FORMAT));
|
|
|
|
+ LocalDateTime endLocalDate = LocalDateTime.parse(TimeTool.convertUTC2DateStr(endDate, TimeTool.TIMESTAMP_FORMAT), DateTimeFormatter.ofPattern(TimeTool.TIMESTAMP_FORMAT));
|
|
|
|
+// long monthsBetween = ChronoUnit.MONTHS.between(startLocalDate, endLocalDate);
|
|
|
|
+ if (startLocalDate.isAfter(endLocalDate)) {
|
|
|
|
+ return false;
|
|
|
|
+ } else if (endLocalDate.isBefore(startLocalDate)) {
|
|
|
|
+ return false;
|
|
|
|
+ } else if (startLocalDate.equals(endLocalDate) || startLocalDate.isBefore(endLocalDate)) {
|
|
|
|
+ //TODO 说明符合可组成查询日期的条件
|
|
|
|
+ //TODO 按照需求,特殊化结束时间再加4天
|
|
|
|
+ String startLocalDateStr = startLocalDate.format(formatter);
|
|
|
|
+ String endLocalDateStr = endLocalDate.format(formatter);
|
|
|
|
+ strSql.append(" AND CONCAT(\"Date\", ' ', \"Hour\") BETWEEN '" + startLocalDateStr + "' " + "AND '" + endLocalDateStr + "'");
|
|
|
|
+ forDateStr = strSql.toString();
|
|
|
|
+ startDate = TimeTool.convertDateStr2UTC(startLocalDateStr);
|
|
|
|
+ endDate = TimeTool.convertDateStr2UTC(endLocalDateStr);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, "JPCustomerMeterSS", "JPCustomerMeterSS"
|
|
|
|
+ , String.format("errorMsg:%s====>"
|
|
|
|
+ , ex.getLocalizedMessage()));
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ } else if (startDate != null && endDate == null) {//警告没事,增加代码可读性
|
|
|
|
+ //TODO 说明startDate传了 endDate没传 , 那么endDate为startDate月的最后一天
|
|
|
|
+ LocalDateTime startLocalDate = LocalDateTime.parse(TimeTool.convertUTC2DateStr(startDate, TimeTool.TIMESTAMP_FORMAT), DateTimeFormatter.ofPattern(TimeTool.TIMESTAMP_FORMAT));
|
|
|
|
+ LocalDateTime endLocalDate = LocalDateTime.now().withMinute(0).withSecond(0);
|
|
|
|
+ String startLocalDateStr = startLocalDate.format(formatter);
|
|
|
|
+ String endLocalDateStr = endLocalDate.format(formatter);
|
|
|
|
+ strSql.append(" AND CONCAT(\"Date\", ' ', \"Hour\") BETWEEN '" + startLocalDateStr + "' " + "AND '" + endLocalDateStr + "'");
|
|
|
|
+ forDateStr = strSql.toString();
|
|
|
|
+ endDate = TimeTool.convertDateStr2UTC(endLocalDateStr);
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+}
|