package com.lightinit.hsdatashow.model.topic.water;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Author: sunxiang
 * @Date: 2018/12/26 15:11
 * @Description:
 **/
public class STRainSearchModel extends PageNewModel{

    private Long id;
    private String stationType;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date fromTime;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date toTime;
    private String dateText;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getStationType() {
        return stationType;
    }

    public void setStationType(String stationType) {
        this.stationType = stationType;
    }

    public Date getFromTime() {
        return fromTime;
    }

    public void setFromTime(Date fromTime) {
        this.fromTime = fromTime;
    }

    public Date getToTime() {
        return toTime;
    }

    public void setToTime(Date toTime) {
        this.toTime = toTime;
    }

    public String getDateText() {
        if(!StringUtils.isEmpty(dateText)){
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
            try {
                Calendar calendar = Calendar.getInstance();
                Date time = calendar.getTime();
                if("今日".equals(dateText)){
                    String format = df.format(time);
                    Date date = df.parse(format);
                    fromTime=date;
                    toTime=date;
                }else if("本月".equals(dateText)){
                    int minmun = calendar.getActualMinimum(Calendar.DATE);
                    calendar.set(Calendar.DATE,minmun);
                    String format1 = df.format(calendar.getTime());
                    Date date1 = df.parse(format1);
                    fromTime=date1;
                    int maximum = calendar.getActualMaximum(Calendar.DATE);
                    calendar.set(Calendar.DATE,maximum);
                    String format2 = df.format(calendar.getTime());
                    Date date2 = df.parse(format2);
                    toTime=date2;
                }else if("今年".equals(dateText)){
                    String start = calendar.get(Calendar.YEAR) + "-01-01";
                    String end = calendar.get(Calendar.YEAR) + "-12-31";
                    fromTime=df.parse(start);
                    toTime=df.parse(end);;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return dateText;
    }

    public void setDateText(String dateText) {
        this.dateText = dateText;
        /*if(!StringUtils.isEmpty(dateText)){
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
            try {
                Calendar calendar = Calendar.getInstance();
                Date time = calendar.getTime();
                if("今日".equals(dateText)){
                    String format = df.format(time);
                    Date date = df.parse(format);
                    fromTime=date;
                    toTime=date;
                }else if("本月".equals(dateText)){
                    int minmun = calendar.getActualMinimum(Calendar.DATE);
                    calendar.set(Calendar.DATE,minmun);
                    String format1 = df.format(calendar.getTime());
                    Date date1 = df.parse(format1);
                    fromTime=date1;
                    int maximum = calendar.getActualMaximum(Calendar.DATE);
                    calendar.set(Calendar.DATE,maximum);
                    String format2 = df.format(calendar.getTime());
                    Date date2 = df.parse(format2);
                    toTime=date2;
                }else if("今年".equals(dateText)){
                    String start = calendar.get(Calendar.YEAR) + "-01-01";
                    String end = calendar.get(Calendar.YEAR) + "-12-31";
                    fromTime=df.parse(start);
                    toTime=df.parse(end);;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }*/
    }
}
