package cn.com.qmth.stmms.admin.exam;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.com.qmth.stmms.biz.mark.model.MarkSpecialTag;
import cn.com.qmth.stmms.biz.mark.service.MarkSpecialTagService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.qmth.stmms.admin.exam.parameter.BaseParameterController;
import cn.com.qmth.stmms.biz.mark.model.MarkLibrary;
import cn.com.qmth.stmms.biz.mark.model.MarkTrack;
import cn.com.qmth.stmms.biz.mark.service.MarkLibraryService;
import cn.com.qmth.stmms.biz.mark.service.MarkTrackService;
import cn.com.qmth.stmms.common.utils.PictureUrlBuilder;

@Controller("trackController")
@RequestMapping("/admin/exam/track")
public class MarkTrackController extends BaseParameterController {

	protected static Logger log = LoggerFactory.getLogger(MarkTrackController.class);

	@Value("${slice.image.server}")
	private String imageServer;
	
	@Autowired
	private MarkTrackService markTrackService;
	@Autowired
	private MarkLibraryService markLibraryService;

	@Autowired
    private MarkSpecialTagService markSpecialTagService;

	/**
	 * 
	 * @param studentId
	 * @return
	 */
	@ResponseBody
	@RequestMapping
	public HashMap<String, Object> list(Integer studentId) {
		List<MarkTrack> markTracks = markTrackService.findByStudentId(studentId);
  		MarkLibrary markLibrary=markLibraryService.findByStudentId(studentId);
        List<String> picUrls = new ArrayList<String>();
        List<MarkSpecialTag> markSpecialTagList = new ArrayList<MarkSpecialTag>();
		if(markLibrary != null){
          picUrls = PictureUrlBuilder.getSliceUrls(markLibrary.getExamId(), markLibrary.getCampusId(), markLibrary.getSubjectCode(), markLibrary.getExamNumber(), markLibrary.getPicStart(), markLibrary.getPicCount());
          markSpecialTagList = markSpecialTagService.findByLibraryId(markLibrary.getId());
		}
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("picUrls",picUrls);
		map.put("markTracks", markTracks);
		map.put("imageServer", imageServer);
		map.put("markSpecialTagList",markSpecialTagList);
		return map;
	}

}
