package cn.updev.Action.Todo;

import cn.updev.EventWeight.Weight.EventWeight;
import cn.updev.EventWeight.Weight.EventWeightManage;
import cn.updev.Events.Event.EventDAO;
import cn.updev.Events.Static.IEvent;
import cn.updev.Users.Static.FuctionClass.Login;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * Created by hypo on 15-11-25.
 */
public class TodoListAction extends ActionSupport {

    public String execute() throws Exception {

        Login login = new Login();
        if(login.isNotLogined()){
            return LOGIN;
        }

        EventDAO eventDAO = new EventDAO();

        // 获得登录用户
        Integer userId = new Login().getLoginedUser().getUserId();
        List<IEvent> events = eventDAO.getUnfinishEventByUserId(userId);

        Collections.sort(events, new Comparator<IEvent>() {
            @Override
            public int compare(IEvent o1, IEvent o2) {
                EventWeightManage eventWeight = new EventWeightManage();
                EventWeight weight1 = eventWeight.getEventWeight(o1.getEventId());
                EventWeight weight2 = eventWeight.getEventWeight(o2.getEventId());
                return (int)(weight1.getEventWeight() - weight2.getEventWeight());
            }
        });

        List<IEvent> weightEventList = new ArrayList<IEvent>();
        for(IEvent event : events){
            weightEventList.add(event);
        }

        Collections.sort(events, new Comparator<IEvent>() {
            @Override
            public int compare(IEvent o1, IEvent o2) {
                EventWeightManage eventWeight = new EventWeightManage();
                EventWeight weight1 = eventWeight.getEventWeight(o1.getEventId());
                EventWeight weight2 = eventWeight.getEventWeight(o2.getEventId());
                Long time1 = weight1.getEventExpect().getTime() / 1000;
                Long time2 = weight2.getEventExpect().getTime() / 1000;
                return (int)(time2 - time1);
            }
        });

        List<IEvent> expectEventList = new ArrayList<IEvent>();
        for(IEvent event : events){
            expectEventList.add(event);
        }

        Collections.sort(events, new Comparator<IEvent>() {
            @Override
            public int compare(IEvent o1, IEvent o2) {
                EventWeightManage eventWeight = new EventWeightManage();
                EventWeight weight1 = eventWeight.getEventWeight(o1.getEventId());
                EventWeight weight2 = eventWeight.getEventWeight(o2.getEventId());
                Long time1 = weight1.getEventReckon().getTime() / 1000;
                Long time2 = weight2.getEventReckon().getTime() / 1000;
                return (int)(time1 - time2);
            }
        });

        List<IEvent> reckonEventList = new ArrayList<IEvent>();
        for(IEvent event : events){
            reckonEventList.add(event);
        }

        HttpServletRequest request = ServletActionContext.getRequest();
        request.setAttribute("weightEventList", weightEventList);
        request.setAttribute("expectEventList", expectEventList);
        request.setAttribute("reckonEventList", reckonEventList);

        return SUCCESS;
    }
}

@@ -165,16 +165,57 @@
 entDAO;%0A
+import cn.updev.Events.Static.EventInfo;%0A
 import c
@@ -1403,25 +1403,25 @@
 (int)(weight
-1
+2
 .getEventWei
@@ -1430,25 +1430,25 @@
 t() - weight
-2
+1
 .getEventWei
@@ -1495,22 +1495,25 @@
    List%3C
-I
 Event
+Info
 %3E weight
@@ -1530,38 +1530,41 @@
 = new ArrayList%3C
-I
 Event
+Info
 %3E();%0A        for
@@ -1612,37 +1612,52 @@
 htEventList.add(
-event
+new EventInfo(event)
 );%0A        %7D%0A%0A  
@@ -2211,17 +2211,17 @@
 time
-2
+1
  - time
-1
+2
 );%0A 
@@ -2259,22 +2259,25 @@
    List%3C
-I
 Event
+Info
 %3E expect
@@ -2294,38 +2294,41 @@
 = new ArrayList%3C
-I
 Event
+Info
 %3E();%0A        for
@@ -2376,37 +2376,52 @@
 ctEventList.add(
-event
+new EventInfo(event)
 );%0A        %7D%0A%0A  
@@ -3023,22 +3023,25 @@
    List%3C
-I
 Event
+Info
 %3E reckon
@@ -3066,22 +3066,25 @@
 rayList%3C
-I
 Event
+Info
 %3E();%0A   
@@ -3148,22 +3148,37 @@
 ist.add(
+new EventInfo(
 event)
+)
 ;%0A      

update todo list