package cn.com.qmth.stmms.monitor;

import java.util.Date;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.qmth.stmms.biz.utils.CurrentTaskUtil;
import cn.com.qmth.stmms.biz.utils.TaskEntry;
import cn.com.qmth.stmms.common.utils.DateUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Controller("taskMonitor")
@RequestMapping("/monitor/task")
public class TaskMonitorController {

    @RequestMapping
    @ResponseBody
    public Object list(HttpServletRequest request, @RequestParam Integer examId, @RequestParam String subjectCode,
            @RequestParam Integer groupNumber) {
        Set<TaskEntry> set = CurrentTaskUtil.list(examId, subjectCode, groupNumber);
        JSONArray array = new JSONArray();
        for (TaskEntry entry : set) {
            JSONObject obj = new JSONObject();
            obj.accumulate("taskId", entry.getTaskId());
            obj.accumulate("markerId", entry.getMarkerId());
            obj.accumulate("time", DateUtils.formatDateTime(new Date(entry.getTimestamp())));
            array.add(obj);
        }
        return array;
    }

}
