package com.moral.api.pojo.form.dataDisplay; import com.fasterxml.jackson.annotation.JsonFormat; import com.moral.constant.Constants; import com.moral.util.DateUtils; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import java.util.Date; /** * @ClassName MonitorPointDataDisplayForm * @Description TODO * @Author 陈凯裕 * @Date 2021/9/26 10:03 * @Version TODO **/ @Data public class MonitorPointDataDisplayForm { /* * 站点id * */ private Integer monitorPointId; /* * 开始时间 * */ @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") private Date startTime; /* * 结束时间 * */ @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") private Date endTime; /* * 时报,日报,周报,月报类型 * */ private String reportType; /* * 检测数据是否有效 * */ public boolean valid() { if (monitorPointId == null) return false; if (reportType == null) { if (startTime == null || endTime == null) return false; //结束时间获取当天最后一个小时 String endTimeStr = DateUtils.dateToDateString(endTime,"yyyy-MM-dd"); endTimeStr+=" 23:59:59"; endTime = DateUtils.getDate(endTimeStr,"yyyy-MM-dd HH:mm:ss"); } else { if(startTime!=null&&endTime!=null) return false; if (reportType.equals(Constants.HOURYLYREPORT)) { //时报选项默认为上个小时的数据 Date previousHour = DateUtils.getDateOfMin(new Date(), -60); startTime = DateUtils.getHourlyStartTime(previousHour); } else if (reportType.equals(Constants.DAILYREPORT)) { //日报选项默认为昨天的数据 Date yesterday = DateUtils.getDateOfDay(new Date(),-1); startTime = DateUtils.getDailyStartTime(yesterday); } else if (reportType.equals(Constants.WEEKLYREPORT)) { //周报选项默认为上周的数据 Date previous = DateUtils.getDateOfDay(new Date(),-7); startTime = DateUtils.getWeeklyStartTime(previous); endTime = DateUtils.getWeeklyEndTime(previous); } else if (reportType.equals(Constants.MONTHLYREPORT)) { //月报选项默认为上月的数据 Date lastMonthFirstDay = DateUtils.getFirstDayOfLastMonth(); startTime = DateUtils.getMonthlyStartTime(lastMonthFirstDay); endTime = DateUtils.getMonthlyEndTime(lastMonthFirstDay); } else return false; } return true; } }