package com.steerinfo.ems.common;

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

import com.steerinfo.ems.Utils.DateUtils;

/**
 * @author 李日量
 * @Date 2019/12/20 15:29
 * @Copyright 湖南视拓信息技术股份有限公司
 */
public enum DateTypeEnum {
    dm("dm"){
        public String getDate(){
            return calendar.get(Calendar.DAY_OF_MONTH)+"";
        }
    },
    dy("dy"){
        public String getDate(){
            return calendar.get(Calendar.DAY_OF_YEAR)+"";
        }
    },
    thisMoth("thisMonth"){
        public String getDate(){
            return new SimpleDateFormat("yyyy-MM").format(calendar.getTime());
        }
    },
    thisYear("thisYear"){
        public String getDate() {
            return new SimpleDateFormat("yyyy").format(calendar.getTime());
        }
    },
    lastMonth("lastMonth"){
        public String getDate(){
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.MONTH, -1);
            return new SimpleDateFormat("yyyy-MM").format(calendar.getTime());
        }
    },
    lastYear("lastYear"){
        public String getDate(){
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DAY_OF_YEAR, -1);
            return  new SimpleDateFormat("yyyy").format(calendar.getTime());
        }
    },
    yesterday("yesterday"){
        public String getDate(){
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DAY_OF_YEAR, -1);
            return new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
        }
    },
    today("today"){
    	public String getDate(){
    		 String dateStr = DateUtils.dateStr(new Date(), "yyyy-MM-dd HH:mm:ss");
            return dateStr;
        }
    };
    public Calendar calendar = Calendar.getInstance();
    private static Map<String, DateTypeEnum> map = new HashMap<String, DateTypeEnum>();

    static {
      for(DateTypeEnum mediaTypeEnum : DateTypeEnum.values()){
          map.put(mediaTypeEnum.getSymbol(),mediaTypeEnum);
      }
    }
    
    private String symbol;
    DateTypeEnum(String symbol){
        this.symbol = symbol;
    }
    public String getSymbol(){
        return symbol;
    }
    public static DateTypeEnum getMethod(String ssymbol){
        return map.get(ssymbol);
    }
        public abstract String getDate();
}
