package com.moral.api.pojo.form.aqi; import com.fasterxml.jackson.annotation.JsonFormat; import com.moral.util.DateUtils; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import java.util.Date; /** * @ClassName AreaPollutionLevelForm * @Description TODO * @Author 陈凯裕 * @Date 2021/12/30 10:37 * @Version TODO **/ @Data public class AreaPollutionLevelForm { /* * 地区码 * */ private Integer regionCode; /* * 如果是查年数据则该参数不能为空 * */ @DateTimeFormat(pattern = "yyyy") @JsonFormat(pattern = "yyyy", timezone = "GMT+8") private Date year; /* * 如果是查月数据则该参数不能为空 * */ @DateTimeFormat(pattern = "yyyy-MM") @JsonFormat(pattern = "yyyy-MM", timezone = "GMT+8") private Date month; /* * 用于查询数据的开始时间,由form自行转换 * */ private Date startDate; /* * 用于查询数据的结束时间,由form自行转换 * */ private Date endDate; public boolean valid() { if (regionCode == null || (year == null && month == null)||(year != null && month != null)) return false; //检查regionCode格式 String regionCodeStr = regionCode.toString(); if (!regionCodeStr.substring(regionCodeStr.length() - 2, regionCodeStr.length()).equals("00")) return false; //时间转换 if (year != null) { startDate = DateUtils.getFirstDayOfYear(year); endDate = DateUtils.getLastDayOfYear(year); return true; } startDate = DateUtils.getFirstDayOfMonth(month); endDate = DateUtils.getLastDayOfMonth(month); return true; } }