DateVO.java 3.2 KB
package com.skua.modules.common.vo;

import com.skua.tool.util.DateUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Data
public class DateVO {

    @ApiModelProperty(value = "去年(yyyy)")
    private int lastYear;

    @ApiModelProperty(value = "去年(yyyy-MM)")
    private String lastYearMonth;
    @ApiModelProperty(value = "去年(yyyy-MM-dd)")
    private String lastYearStartDate;
    @ApiModelProperty(value = "去年(yyyy-MM-dd)")
    private String lastYearEndDate;
    @ApiModelProperty(value = "去年月开始时间(yyyy-MM-dd)")
    private String lastYearMonthStartTime;
    @ApiModelProperty(value = "上月结束时间(yyyy-MM-dd)")
    private String lastYearMonthEndTime;


    @ApiModelProperty(value = "上月(yyyy-MM)")
    private String lastMonth;
    @ApiModelProperty(value = "上月(yyyy-MM-dd)")
    private String lastMonthDay;
    @ApiModelProperty(value = "上月开始时间(yyyy-MM-dd)")
    private String lastMonthStartTime;
    @ApiModelProperty(value = "上月结束时间(yyyy-MM-dd)")
    private String lastMonthEndTime;



    @ApiModelProperty(value = "昨天")
    private String yesterday;

    @ApiModelProperty(value = "当月(yyyy)")
    private int nowYear;

    @ApiModelProperty(value = "当月(yyyy-MM)")
    private String nowMonth;

    @ApiModelProperty(value = "当月(yyyy-MM-dd)")
    private String nowMonthStartDate;

    @ApiModelProperty(value = "当月(yyyy-MM-dd)")
    private String nowMonthEndDate;

    @ApiModelProperty(value = "当月(yyyy-MM-dd)")
    private String nowYearStartDate;
    @ApiModelProperty(value = "当月(yyyy-MM-dd)")
    private String nowYearEndDate;


    public DateVO(String currentDate) {
        this.nowMonth = DateUtils.dateformat(currentDate,"yyyy-MM");
        this.nowMonthStartDate = nowMonth+"-01";
        // 获取当前日期
        LocalDate now = LocalDate.now();
        String currentMonth = now.format(DateTimeFormatter.ofPattern("yyyy-MM"));
        // 判断是否为当前年月
        if (this.nowMonth.equals(currentMonth)) {
            this.nowMonthEndDate = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        } else {
            this.nowMonthEndDate = nowMonth + "-31";
        }

        this.nowYear = Integer.parseInt(DateUtils.dateformat(currentDate,"yyyy"));
        this.nowYearStartDate = nowYear + "-01-01";
        // 判断是否为当前年
        int currentYear = now.getYear();
        if (this.nowYear == currentYear) {
            this.nowYearEndDate = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        } else {
            this.nowYearEndDate = nowYear + "-12-31";
        }

        //同比时间
        this.lastYear = nowYear -1 ;
        this.lastYearMonth = DateUtils.getTbMonth(this.nowMonth);
        this.lastYearMonthStartTime = lastYearMonth+"-01";
        this.lastYearMonthEndTime = lastYearMonth+"-31";
        this.lastYearStartDate = this.lastYear+"-01-01";
        this.lastYearEndDate = this.lastYear+"-12-31";

        //环比时间
        this.lastMonth = DateUtils.getHbMonth(this.nowMonth);
        this.lastMonthStartTime = lastMonth+"-01";
        this.lastMonthEndTime = lastMonth+"-31";
    }
}