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 com.opensymphony.xwork2.ActionSupport;

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 {

        EventDAO eventDAO = new EventDAO();

        // 获得登录用户
        Integer userId = 1;
        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());
            }
        });

        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);
            }
        });

        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);
            }
        });

        for(IEvent event : events){
            EventWeightManage eventWeight = new EventWeightManage();
            EventWeight weight = eventWeight.getEventWeight(event.getEventId());
            System.out.println(event.getEventTitle() + " " + weight.getEventReckon());
        }

        return SUCCESS;
    }
}

@@ -215,46 +215,217 @@
 rt c
-om.opensymphony.xwork2.ActionSupport;%0A
+n.updev.Users.Static.FuctionClass.Login;%0Aimport com.opensymphony.xwork2.ActionSupport;%0Aimport org.apache.struts2.ServletActionContext;%0A%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport java.util.ArrayList;
 %0Aimp
@@ -641,24 +641,130 @@
 xception %7B%0A%0A
+        Login login = new Login();%0A        if(login.isNotLogined())%7B%0A            return LOGIN;%0A        %7D%0A%0A
         Even
@@ -839,17 +839,56 @@
 serId = 
-1
+new Login().getLoginedUser().getUserId()
 ;%0A      
@@ -955,17 +955,16 @@
 erId);%0A%0A
-%0A
         
@@ -1433,32 +1433,183 @@
  %7D%0A        %7D);%0A%0A
+        List%3CIEvent%3E weightEventList = new ArrayList%3CIEvent%3E();%0A        for(IEvent event : events)%7B%0A            weightEventList.add(event);%0A        %7D%0A%0A
         Collecti
@@ -2176,32 +2176,183 @@
  %7D%0A        %7D);%0A%0A
+        List%3CIEvent%3E expectEventList = new ArrayList%3CIEvent%3E();%0A        for(IEvent event : events)%7B%0A            expectEventList.add(event);%0A        %7D%0A%0A
         Collecti
@@ -2939,102 +2939,137 @@
     
-for(
+List%3C
 IEvent
- event : events)%7B%0A            EventWeightManage eventWeight = new EventWeightManage(
+%3E reckonEventList = new ArrayList%3CIEvent%3E();%0A        for(IEvent event : events)%7B%0A            reckonEventList.add(event
 );%0A 
@@ -3079,78 +3079,146 @@
     
+%7D%0A%0A
     
-EventWeight weight = eventWeight.getEventWeight(event.ge
+    HttpServletRequest request = ServletActionContext.getRequest();%0A        request.setAttribute(%22weightEventList%22, weigh
 tEvent
-Id()
+List
 );%0A 
@@ -3228,96 +3228,131 @@
     
-    System.out.println(event.getEventTitle() + %22 %22 + weight.getEventReckon());%0A        %7D
+request.setAttribute(%22expectEventList%22, expectEventList);%0A        request.setAttribute(%22reckonEventList%22, reckonEventList);
 %0A%0A  

update TodoListAction