package com.moral.api.pojo.form.aqi; 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 AirQualityForm * @Description 空气质量同期对比实体 * @Author 陈凯裕 * @Date 2022/1/12 15:11 * @Version TODO **/ @Data public class AirQualityComparisonForm { /* * 地区码 查询28城市无需传入 * */ Integer regionCode; /* * 地区类型 0为市内城市,1为省内城市,2为28城市 * */ String regionType; /* * 对比类型,0为同比 1为环比 * */ String comparisonType; /* * 查询年份数据的时候需要传递,非必传 * */ @DateTimeFormat(pattern = "yyyy") @JsonFormat(pattern = "yyyy", timezone = "GMT+8") Date year; /* * 查询年份数据的时候需要传递,非必传 * */ @DateTimeFormat(pattern = "yyyy-MM") @JsonFormat(pattern = "yyyy-MM", timezone = "GMT+8") Date month; /* * 自定义开始时间,非必传 * */ @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") Date startDate; /* * 自定义结束时间,非必传 * */ @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") Date endDate; public boolean valid() { //校验地区类型对应的地区码 if(regionType==null||comparisonType==null) return false; if (!regionType.equals(Constants.TWENTY_EIGHT_CITIES) && regionCode == null) return false; if (regionCode.toString().length() != 6) return false; if (regionType.equals(Constants.CITY_TYPE)) { String regionCodeStr = regionCode.toString(); if (!regionCodeStr.substring(regionCodeStr.length() - 2, regionCodeStr.length()).equals("00")) return false; } if (regionType.equals(Constants.PROVINCE_TYPE)) { String regionCodeStr = regionCode.toString(); if (!regionCodeStr.substring(regionCodeStr.length() - 4, regionCodeStr.length()).equals("0000")) return false; } //时间转换 if (year != null) { if(month!=null) return false; startDate = DateUtils.getFirstDayOfYear(year); endDate = DateUtils.getLastDayOfYear(year); return true; } if (month != null) { if(year!=null) return false; startDate = DateUtils.getFirstDayOfMonth(month); endDate = DateUtils.getLastDayOfMonth(month); return true; } if(startDate!=null&&endDate!=null) return true; return false; } }