package cn.updev.EventWeight.Rate;

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

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

/**
 * Created by hypo on 15-11-24.
 */
public class EventGroupRate {

    private Integer eventGroupId;
    private String eventGroupTitle;
    private Integer evnetNum;
    private Integer finishEventNum;
    private Integer groupRate;
    private EventWeight weight;
    private String createTime;
    private String groupExpect;
    private Date finishTime;

    public EventGroupRate(Integer eventGroupId) {
        this.eventGroupId = eventGroupId;
        EventGroupDAO groupDAO = new EventGroupDAO();
        EventDAO eventDAO = new EventDAO();
        EventGroupInfo groupInfo = groupDAO.getEventGroupInfo(eventGroupId);
        this.eventGroupTitle = groupInfo.getGroupTitle();
        this.weight = groupInfo.getWeight();

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        this.createTime = dateFormat.format(groupInfo.getCreateTime());
        this.groupExpect = dateFormat.format(groupInfo.getGroupExpect());

        List<IEvent> events = eventDAO.getEventByEventGroupId(eventGroupId);
        this.evnetNum = events.size();
        this.finishEventNum = 0;

        this.finishTime = null;
        for(IEvent event : events){
            if(event.isFinish()){
                this.finishEventNum++;
            }
            EventWeightManage eventWeight = new EventWeightManage();
            cn.updev.EventWeight.Weight.EventWeight weight = eventWeight.getEventWeight(event.getEventId());

            if(finishTime == null){
                finishTime = weight.getEventReckon();
            }else {
                Long temp = finishTime.getTime();
                Long next = weight.getEventReckon().getTime();

                if(next > temp){
                    finishTime = weight.getEventReckon();
                }
            }
        }
        this.groupRate = 100 * this.finishEventNum / this.evnetNum;
    }

    public Integer getEventGroupId() {
        return eventGroupId;
    }

    public String getEventGroupTitle() {
        return eventGroupTitle;
    }

    public Integer getEvnetNum() {
        return evnetNum;
    }

    public Integer getFinishEventNum() {
        return finishEventNum;
    }

    public Integer getGroupRate() {
        return groupRate;
    }

    public String getCreateTime() {
        return createTime;
    }

    public String getGroupExpect() {
        return groupExpect;
    }

    public EventWeight getWeight() {
        return weight;
    }

    public String getFinishTime() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        return dateFormat.format(finishTime);
    }
}

@@ -736,16 +736,44 @@
 ishTime;
+%0A    private Integer teamId;
 %0A%0A    pu
@@ -1352,24 +1352,69 @@
 upExpect());
+%0A        this.teamId = groupInfo.getTeamId();
 %0A%0A        Li
@@ -3059,11 +3059,74 @@
 );%0A    %7D
+%0A%0A    public Integer getTeamId() %7B%0A        return teamId;%0A    %7D
 %0A%7D%0A

add team id