kaiyu
2021-09-30 eba6f1988c6a7e37e619a27e493b17c244979070
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
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;
    }
 
}