package com.dev.swms.server.action.formatter;

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

import com.dev.energy.server.format.Formatter;

public class ValidPeriodremindFormatter implements Formatter{
	@Override
	public String format(String property, Object storageDate, List origenData,
			String referenceModel, String locale) {
		String type=storageDate.toString();
		Calendar calc =Calendar.getInstance();
		SimpleDateFormat sdf  = new SimpleDateFormat("yyyy-MM-dd");
		String dqDate = String.valueOf(origenData.get(19));//到期日期
		if(dqDate.equals("") || dqDate.equals("-")){
			return type;
		}
		Date minDate=null;
		try {
			
				System.out.println(dqDate);
				calc.setTime(sdf.parse(dqDate));
				calc.add(calc.DATE, -30); 
				minDate =calc.getTime();  
				String minDateStr = sdf.format(minDate);//到期30天提醒时间
				Date date = new Date();
				String newDate=sdf.format(date);//当前时间
			
				if(newDate.compareTo(dqDate) >= 0 ){
					return "<div style='background-color:red' >" + type + "</div>";
				}else if(newDate.compareTo(minDateStr) >= 0){
					return "<div style='background-color:yellow' >" + type + "</div>";
				}
				
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			 
			
			return type;
			
	}
	
}
