package com.qmth.jkserver.controller.system;

import com.qmth.jkserver.core.annotation.LoginValidate;
import com.qmth.jkserver.enums.LoginStatus;
import com.qmth.jkserver.service.ExamStudentAdditionalService;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping("/system/test")
public class TestController {

    private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(TestController.class);

    @Resource
    @Lazy
    private ExamStudentAdditionalService examStudentAdditionalService;

    @RequestMapping("/mongo_query")
    @LoginValidate(status = LoginStatus.IGNORE)
    public Object add() {
//		examPlanService.updateRoomKwAlready("AwtA", "1031", "100323", ExamKwProgressType.KW);
//		examPlanService.updateRoomKjAlready("AwtA", "1031", "100323");
//
////		examPlanService.updateRoomKwAlready("AwtA", "1011", "100303", ExamKwProgressType.KW);
//		Query query = new Query();
//		query.addCriteria(Criteria.where("examCode").is("AwtA"));
//		query.addCriteria(Criteria.where("placeCode").is("1031"));
//		query.addCriteria(Criteria.where("roomCode").is("100323"));
//		List<ExamRoom> examRooms = mongoTemplate.find(query, ExamRoom.class);
//		DBObject delRepeatQuery = new BasicDBObject();
//		delRepeatQuery.put("exam_code", "9ko1ho1A");
//		delRepeatQuery.put("place_code", "420101");
//		delRepeatQuery.put("room_code", "42010101");
//		Set<String> batchIds = new HashSet<String>();
//		batchIds.add("1");
//		delRepeatQuery.put("batch_id", new BasicDBObject("$in", batchIds));
//		long time8 = System.currentTimeMillis();
//		mongoTemplate.getCollection("jk_exam_repeat_record").remove(delRepeatQuery);
//		long time9 = System.currentTimeMillis();
//		LOGGER.info("----remove old exam repeat dbobject use time:" + (time9-time8) +"ms");
//		System.out.println(examRooms.get(0));
//		examPlanService.updateRoomKwAlready("AwtA", "1011", "100303",ExamKwProgressType.PAPER);
//		examPlanService.updateRoomKwAlready("AwtA", "1011", "100303",ExamKwProgressType.UNCOILING);
//		DBObject query = new BasicDBObject();
//		query.put("exam_code", "8QyK");
//		query.put("is_absent", false);
//		query.put("decode_file", new BasicDBObject("$exists", true));
//		DBObject porjection = new BasicDBObject("decode_file.access_uri",1);
//		porjection.put("exam_code", 1);
//		DBCursor dbCursor = mongoTemplate.getCollection("jk_exam_student_answer").find(query, porjection);
//		Set<String> set = new LinkedHashSet<String>();
//		while(dbCursor.hasNext()) {
//			DBObject dbObject = dbCursor.next();
//			DBObject dbObject2 = (DBObject) dbObject.get("decode_file");
//			if(dbObject2.get("access_uri") != null){
//				set.add(dbObject.get("decode_file.access_uri").toString());
//			}
//		}
        examStudentAdditionalService.findDistinctStudent("JVF9");
        return 1;
    }
}
