kaiyu
2022-01-17 21a44d6cb9a372bce5c7418d2a82c88bb0485e60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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;
 
    /*
    * 地区类型 city为市内城市,province为省内城市,28为28城市
    * */
    String regionType;
 
    /*
    * 对比类型,yoy为同比 mom为环比
    * */
    String comparisonType;
 
    /*
     * 查询年份数据的时候需要传递,非必传
     * */
    String dateType;
 
    /*
     * 查询年份数据的时候需要传递,非必传
     * */
    String time;
 
    /*
     * 自定义开始时间,非必传
     * */
    @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;
 
    /*
    * 对比开始时间
    * */
    Date comparisonStartDate;
 
    /*
    * 对比结束时间
    * */
    Date comparisonEndDate;
 
    public boolean valid() {
        //校验地区类型对应的地区码
        if(regionType==null||comparisonType==null)
            return false;
        if (!regionType.equals(Constants.TWENTY_EIGHT_CITIES) && regionCode == null)
            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();
            regionCode = Integer.parseInt(regionCodeStr.substring(0,regionCodeStr.length()-4)+"0000");
        }
        //时间转换
        if(dateType.equals(Constants.MONTH)){
            Date date = DateUtils.getDate(time, "yyyy-MM");
            startDate = DateUtils.getFirstDayOfMonth(date);
            endDate = DateUtils.getLastDayOfMonth(date);
        }
 
        if(dateType.equals(Constants.YEAR)){
            Date date = DateUtils.getDate(time, "yyyy");
            startDate = DateUtils.getFirstDayOfYear(date);
            endDate = DateUtils.getLastDayOfYear(date);
        }
 
        if(startDate==null||endDate==null)
            return false;
 
        calculateComparisonDate();
 
        return true;
    }
 
    /**
    * @Description: 计算对比时间
            * @Param: [startDate, endDate]
            * @return: void
            * @Author: 陈凯裕
            * @Date: 2022/1/14
            */
    private void calculateComparisonDate(){
        if(comparisonType.equals(Constants.MOM)){
            comparisonStartDate = DateUtils.addMonths(startDate,-1);
            comparisonEndDate = DateUtils.addMonths(endDate,-1);
        }else{
            comparisonStartDate = DateUtils.addMonths(startDate,-12);
            comparisonEndDate = DateUtils.addMonths(endDate,-12);
        }
    }
}