package cn.updev.Message.Template;

import cn.updev.EventWeight.Weight.EventWeight;
import cn.updev.Events.Group.EventGroupDAO;
import cn.updev.Events.Group.EventGroupInfo;
import cn.updev.Events.Static.IEvent;

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

/**
 * Created by hypo on 15-11-27.
 */
public class EventRemidTemplate {

    private String userNickName;
    private String title;
    private String content;
    private IEvent event;
    private String eventTitle;
    private EventWeight eventWeight;

    public EventRemidTemplate(String userNickName, IEvent event, EventWeight eventWeight) {
        this.userNickName = userNickName;
        this.event = event;
        this.eventWeight = eventWeight;
    }

    public String getContent() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

        Long eventExpect = eventWeight.getEventExpect().getTime();
        Long eventReckon = eventWeight.getEventReckon().getTime();
        Long sub = eventExpect - eventReckon;
        String status;

        if(sub > 0){
            status = "就目前进度来看，有可能提前完成。请继续加油！";
        }else {
            status = "就目前进度来看，有可能无法按计划完成任务，还需努力。";
        }

        this.content = "<p>客官 "+userNickName+"：</p><p>早上好！\n这是一封事件提醒邮件。</p>"+
                "<p>您的事件 <b>" + eventTitle + "</b> ，曾计划于"+dateFormat.format(eventWeight.getEventExpect())+"完成，到您收到这封邮件为止，你的预计时间余额不足两天。</p>"+
                "<p>我们预计这件事件将在"+dateFormat.format(eventWeight.getEventReckon())+"完成，"+status+"</p><p>小的汇报完毕，暂行告退。Have a Good Day！</p><p>还在加班的SpongeTime任务进度控制君敬上！</p><p>"+(new Date())+"</p>";
        return content;
    }

    public String getTitle() {

        title = "客官，有任务！ " + eventTitle;

        return title;

    }

    public BasicTemplate getTemplate(){
        return new BasicTemplate(getTitle(),getContent());
    }
}

@@ -723,16 +723,323 @@
 Weight;%0A
+%0A        if(event.getGroupId() != null)%7B%0A%0A            EventGroupInfo groupInfo = new EventGroupDAO().getEventGroupInfo(event.getGroupId());%0A            this.eventTitle = groupInfo.getGroupTitle() + %22 %22 + event.getEventTitle();%0A        %7Delse %7B%0A            this.eventTitle = event.getEventTitle();%0A        %7D%0A%0A
     %7D%0A%0A 
@@ -1446,32 +1446,208 @@
        s
-tatus = %22%E5%B0%B1%E7%9B%AE%E5%89%8D%E8%BF%9B%E5%BA%A6%E6%9D%A5%E7%9C%8B
+ub = -sub / (1000 * 3600 * 24);%0A            if(sub %3E 4)%7B%0A%0A                status = %22%E5%B0%B1%E7%9B%AE%E5%89%8D%E8%BF%9B%E5%BA%A6%E6%9D%A5%E7%9C%8B%EF%BC%8C%E8%BF%9B%E5%B1%95%E8%BF%87%E6%85%A2%EF%BC%8C%E5%BE%88%E6%9C%89%E5%8F%AF%E8%83%BD%E6%97%A0%E6%B3%95%E6%8C%89%E7%90%86%E6%83%B3%E6%97%B6%E9%97%B4%E5%AE%8C%E6%88%90%E4%BB%BB%E5%8A%A1%EF%BC%8C%E8%BF%98%E9%9C%80%E6%8C%89%E8%BD%BB%E9%87%8D%E7%BC%93%E6%80%A5%E5%8F%8A%E6%97%B6%E8%B0%83%E6%95%B4%EF%BC%8C%E7%BB%A7%E7%BB%AD%E5%8A%AA%E5%8A%9B%E3%80%82%22;%0A            %7Delse %7B%0A%0A                status = %22%E5%B0%B1%E7%9B%AE%E5%89%8D%E8%BF%9B%E5%BA%A6%E6%9D%A5%E7%9C%8B%EF%BC%8C%E8%BF%9B%E5%B1%95%E7%A8%8D%E6%85%A2
 %EF%BC%8C%E6%9C%89%E5%8F%AF%E8%83%BD%E6%97%A0%E6%B3%95%E6%8C%89%E8%AE%A1
@@ -1647,16 +1647,18 @@
 %E6%9C%89%E5%8F%AF%E8%83%BD%E6%97%A0%E6%B3%95%E6%8C%89%E8%AE%A1%E5%88%92
+%E5%8F%8A%E6%97%B6
 %E5%AE%8C%E6%88%90%E4%BB%BB%E5%8A%A1%EF%BC%8C%E8%BF%98%E9%9C%80%E5%8A%AA
@@ -1658,24 +1658,38 @@
 %E6%88%90%E4%BB%BB%E5%8A%A1%EF%BC%8C%E8%BF%98%E9%9C%80%E5%8A%AA%E5%8A%9B%E3%80%82%22;%0A
+            %7D%0A
         %7D%0A%0A 
@@ -1749,10 +1749,9 @@
 %E6%97%A9%E4%B8%8A%E5%A5%BD%EF%BC%81
-%5Cn
+ 
 %E8%BF%99%E6%98%AF%E4%B8%80%E5%B0%81

update EventRemidTemplate