package com.lutao.cloud.admin.api.dto;

import lombok.Data;

import java.time.LocalDate;
import java.time.Period;

@Data
public class DataSearchDTO{

    /**
     * 开始时间
     */
    private LocalDate startTime;

    /**
     * 结束时间
     */
    private LocalDate endTime;


    public static DataSearchDTO getDataSearchDTO(DataSearchDTO searchDTO){
        if (searchDTO == null){
            searchDTO = new DataSearchDTO();
            LocalDate nowTime = LocalDate.now();
            searchDTO.setEndTime(nowTime);
            searchDTO.setStartTime(nowTime.plusDays(-30));
            return searchDTO;
        } else{
            if (searchDTO.getStartTime() == null){
                if (searchDTO.getEndTime() == null){
                    LocalDate nowTime = LocalDate.now();
                    searchDTO.setEndTime(nowTime);
                    searchDTO.setStartTime(nowTime.plusDays(-30));
                } else{
                    searchDTO.setStartTime(searchDTO.getEndTime().plusDays(-30));
                }
                return searchDTO;
            } else{
                searchDTO.setEndTime(searchDTO.getStartTime().plusDays(30));

                Period period = Period.between(searchDTO.getEndTime(), LocalDate.now());
                //判断startDate是不是早于endDate，早于则false，否则true
                System.out.println(period.isNegative());//false
                if (period.isNegative()){
                    searchDTO.setEndTime(LocalDate.now());
                }
                return searchDTO;
            }
        }
    }
}
