package com.qmth.distributed.print.api.mark;


import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.distributed.print.business.entity.ExamCard;
import com.qmth.distributed.print.business.service.ExamCardService;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import com.qmth.teachcloud.mark.dto.mark.manage.Task;
import com.qmth.teachcloud.mark.entity.MarkStudent;
import com.qmth.teachcloud.mark.entity.ScanAnswerCard;
import com.qmth.teachcloud.mark.service.MarkStudentService;
import com.qmth.teachcloud.mark.service.MarkTrackService;
import com.qmth.teachcloud.mark.service.ScanAnswerCardService;
import com.qmth.teachcloud.mark.service.TaskService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * <p>
 * 轨迹给分表 前端控制器
 * </p>
 *
 * @author xf
 * @since 2023-09-22
 */
@Api(tags = "评卷-评卷轨迹")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_MARK + "/track")
public class MarkTrackController {
    @Resource
    private TaskService taskService;
    @Resource
    private ExamCardService examCardService;
    @Resource
    private MarkStudentService markStudentService;
    @Resource
    private ScanAnswerCardService scanAnswerCardService;


    /**
     * 轨迹图
     */
    @ApiOperation(value = "轨迹图")
    @RequestMapping(value = "/getTask", method = RequestMethod.POST)
    public Result listStudentScore(@ApiParam(value = "考生ID", required = true) @RequestParam Long studentId) {
        Task task = taskService.build(studentId);
        return ResultUtil.ok(task);
    }

    @ApiOperation(value = "考生扫描的电子卡格式")
    @RequestMapping(value = "/getCard", method = RequestMethod.POST)
    public Result getCard(@ApiParam(value = "考生ID", required = true) @RequestParam Long studentId) {
        MarkStudent student = markStudentService.getById(studentId);
        if(student.getCardNumber()!=null){
            ScanAnswerCard scanAnswerCard=scanAnswerCardService.findByExamAndNumber(student.getExamId(),student.getCardNumber());
            if(scanAnswerCard.getCardId()!=null){
                ExamCard examCard = examCardService.getById(scanAnswerCard.getCardId());
                return ResultUtil.ok(examCard);
            }
        }
        return ResultUtil.ok();
    }

}
