package com.ssj.aijia.kmt.exercise.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.ssj.bean.kmt.kmt.request.exercise.KmtHandlingQuestionRequest;
import com.ssj.bean.kmt.kmtsys.domain.KmtSysUser;
import com.ssj.framework.core.common.controller.BaseController;
import com.ssj.framework.core.security.annotation.IgnoreSecurity;
import com.ssj.framework.core.security.annotation.ModifySecurity;
import com.ssj.framework.core.security.exception.CommonException;
import com.ssj.framework.core.security.manager.TokenManager;
import com.ssj.framework.core.util.ResponseConstant;
import com.ssj.framework.core.util.ResponseEntity;
import com.ssj.service.conch.common.request.PageReq;
import com.ssj.service.conch.parents.request.exercise.KmtExerciseQuestionRequest;
import com.ssj.service.kmt.dto.ExerciseBookCourseClassDto;
import com.ssj.service.kmt.dto.ExerciseBookCourseDTO;
import com.ssj.service.kmt.dto.ExerciseBookDto;
import com.ssj.service.kmt.dto.KmtSysUserDTO;
import com.ssj.service.kmt.dto.exercise.ExerciseQuestionRollbacks;
import com.ssj.service.kmt.exercise.request.SubmitAnswerProofreadResultReq;
import com.ssj.service.kmt.request.*;
import com.ssj.service.kmt.service.*;
import com.ssj.service.sys.homework.service.HomeworkService;
import com.ssj.service.sys.picturepredeal.service.ProblemSimilarPreDealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 *
 * kmt练习册
 * @author chchen
 * 2019-01-14
 */
@RestController
@RequestMapping("/api/kmt/exercise")
@Api(value = "kmt练习册接口", tags = "kmt练习册接口")
public class KmtExerciseController extends BaseController {

    @Autowired
    private TokenManager tokenManager;

    @Reference(version = "1.0" ,timeout = 60000)
    private KmtExerciseService kmtExerciseService;

    @Reference(version = "1.0" ,timeout = 60000)
    private KmtQualityQuestionsService kmtQualityQuestionsService;
    
    @Reference(version = "1.0" ,timeout = 60000)
    private KmtSysUserService kmtSysUserService;

    @Reference(version = "1.0" ,timeout = 60000)
    private KmtExerciseBookCourseService kmtExerciseBookCourseService;

    @Reference(version = "1.0" ,timeout = 60000)
    private KmtExerciseQuestionService kmtExerciseQuestionService;
    @Reference(version = "1.0" ,timeout = 60000)
    private HomeworkService homeworkService;

    @Reference(version = "1.0" ,timeout = 60000)
    private KmtExerciseMapperService kmtExerciseMapperService;

    @Reference(version = "1.0", timeout = 60000)
    private KmtExerciseSubmitService kmtExerciseSubmitService;

    /**
     * 废弃
     * @param accessToken
     * @param request
     * @return
     */
    @RequestMapping(value = "/getExerciseCondition", method = RequestMethod.POST)
    @ApiOperation(value = "获取分配练习册列表", httpMethod = "POST",  notes = "获取分配练习册列表")
    public ResponseEntity getExerciseCondition(@RequestParam(name = "accessToken") String accessToken,
                                          @RequestBody ExerciseConditionRequest request) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            String userId = tokenManager.getUserId(accessToken);
            List<ExerciseBookDto> list = kmtExerciseBookCourseService.getExerciseCondition(request, userId);
            Map<String, Object> data = new HashMap<>();
            data.put("books", list);
            responseEntity.success(data, "保存成功");
        } catch (Exception e) {
            logger.error("入参={}", request);
            logger.error("练习册筛选条件异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @ModifySecurity
    @RequestMapping(value = "/questionRollback", method = RequestMethod.POST)
    @ApiOperation(value = "题目打回", httpMethod = "POST",  notes = "题目打回")
    public ResponseEntity questionRollback(@RequestParam(name = "accessToken") String accessToken,
                                           @RequestBody QuestionRollbackRequest request) {

        ResponseEntity responseEntity = new ResponseEntity();
        try{
            List<String> questionIdList = request.getQuestionIds();
            if (CollectionUtils.isEmpty(questionIdList)) {
                responseEntity.failure(ResponseConstant.CODE_000, "请先选择题目");
            } else {
                String userId = tokenManager.getUserId(accessToken);
                responseEntity = kmtExerciseService.questionRollback(userId, request);
            }
        } catch (Exception e){
            logger.error("入参={}", request);
            logger.error("打回异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }

        return responseEntity;
    }

    @RequestMapping(value = "/getHandlingQuestions", method = RequestMethod.POST)
    @ApiOperation(value = "待加工/待审核题目", httpMethod = "POST",  notes = "待加工/待审核题目")
    public ResponseEntity getHandlingQuestions(@RequestParam(name = "accessToken") String accessToken,
                                               @RequestBody ExerciseQuestionsRequest request) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            String userId = tokenManager.getUserId(accessToken);
            responseEntity = kmtExerciseQuestionService.findExerciseQuestions(userId, request);
        } catch (Exception e) {
            logger.error("入参={}", request);
            logger.error("待加工/待审核题目", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/V1/submit2Auditing", method = RequestMethod.POST)
    @ModifySecurity
    @ApiOperation(value = "提交审核/发布", httpMethod = "POST",  notes = "提交审核/发布")
    public ResponseEntity submit2AuditingV1(@RequestParam(name = "accessToken") String accessToken,
                                            @RequestBody AuditingV1Request request) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            String userId = tokenManager.getUserId(accessToken);
            responseEntity = kmtExerciseSubmitService.submit2Auditing(request, userId);
        } catch (CommonException e) {
            return responseEntity.failure(ResponseConstant.CODE_500, e.getMessage());
        } catch (Exception e){
            logger.error("入参={}", request);
            logger.error("异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }


        return responseEntity;
    }
    @ModifySecurity
    @RequestMapping(value = "/publishQuestion", method = RequestMethod.POST)
    @ApiOperation(value = "发布题目", httpMethod = "POST",  notes = "修改题目")
    public ResponseEntity publishQuestion(@RequestParam(name = "accessToken") String accessToken,
                                          @RequestBody QuestionPublishRequest request) {

        ResponseEntity responseEntity = new ResponseEntity();
        try {
            List<String> questionIdList = request.getQuestionIds();
            if (CollectionUtils.isEmpty(questionIdList)) {
                responseEntity.failure("请先选择题目");
                return responseEntity;
            }
            String userId = tokenManager.getUserId(accessToken);
            responseEntity = kmtExerciseService.publishQuestion(request, userId);
        } catch (CommonException e) {
            throw e;
        } catch (Exception e){
            logger.error("入参={}", request);
            logger.error("异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }


    @RequestMapping(value = "/getDistributeCondition", method = RequestMethod.POST)
    @ApiOperation(value = "分配筛选条件筛选", httpMethod = "POST",  notes = "修改题目")
    public ResponseEntity getDistributeCondition(@RequestParam(name = "accessToken") String accessToken,
                                          @RequestBody DistributionConditionRequest request) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            int dealType = request.getDealType();
            if (dealType != 1 && dealType != 2) {
                responseEntity.failure("操作类型错误");
                return responseEntity;
            }

            List<KmtSysUserDTO> kmtSysUserDTOList = kmtSysUserService.getDistributeCondition(dealType);
            Map<String, Object> resultMap = new HashMap<>();
            resultMap.put("users", kmtSysUserDTOList);
            responseEntity.success(resultMap, "查询成功");
        } catch (Exception e) {
            logger.error("入参={}", request);
            logger.error("分配筛选条件筛选", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/distributeQuestions", method = RequestMethod.POST)
    @ApiOperation(value = "分配题目", httpMethod = "POST",  notes = "分配题目")
    public ResponseEntity distributeQuestions(@RequestParam(name = "accessToken") String accessToken,
                                              @RequestBody QuestionDistributeRequest request) {

        ResponseEntity responseEntity = new ResponseEntity();
        try {
            logger.info("分配题目请求参数={}", JSON.toJSON(request));
            int dealType = request.getDealType();
            if (dealType != 1 && dealType != 2) {
                responseEntity.failure("操作类型错误");
                return responseEntity;
            }

            String userId = request.getUserId();
            if (StringUtils.isBlank(userId)) {
                responseEntity.failure("请选择用户");
                return responseEntity;
            }

            KmtSysUser selectedUser = kmtSysUserService.getById(userId);
            String selectedUserType = selectedUser.getType();
            if ((dealType == 1 && !Objects.equals("QPM", selectedUserType)) || (dealType == 2 && !Objects.equals("SYS", selectedUserType))) {
                logger.warn(String.format("dealType=%s, userId=%s", dealType, userId));
                responseEntity.failure("所选用户与操作类型不匹配");
                return responseEntity;
            }

            if (request.getPeriodId() == null && request.getUnitId() == null && request.getBookId() == null) {
                responseEntity.failure("请选择课时id或单元id或练习册id");
                return responseEntity;
            }

            kmtExerciseService.distributeQuestions(request);
            responseEntity.success(ResponseConstant.CODE_999, "保存成功");
        } catch (Exception e) {
            logger.error("入参={}", request);
            logger.error("分配题目", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/getBookExerciseList", method = RequestMethod.POST)
    @ApiOperation(value = "练习册课时列表", httpMethod = "POST",  notes = "分配题目")
    public ResponseEntity getBookExerciseList(@RequestParam(name = "accessToken") String accessToken,
                                              @RequestBody QuestionDistributeRequest request) {

        ResponseEntity responseEntity = new ResponseEntity();
        try {
            if (StringUtils.isBlank(request.getGrade())) {
                responseEntity.failure("请选择年级");
                return responseEntity;
            }

            if (StringUtils.isBlank(request.getSubject())) {
                responseEntity.failure("请选择科目");
                return responseEntity;
            }

            if (!Objects.equals(1, request.getSemester()) && !Objects.equals(2, request.getSemester())) {
                responseEntity.failure("请选择上下册");
                return responseEntity;
            }

            List<ExerciseBookCourseDTO> exerciseBookCourseDTOList = kmtExerciseService.getBookExerciseList(request);
            Map<String, Object> resultMap = new HashMap<>();
            resultMap.put("list", exerciseBookCourseDTOList);
            responseEntity.success(resultMap, "查询成功");
        } catch (Exception e) {
            logger.error("入参={}", request);
            logger.error("练习册课时列表", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/getBookExerciseDetail", method = RequestMethod.POST)
    @ApiOperation(value = "练习册课时详情", httpMethod = "POST",  notes = "分配题目")
    public ResponseEntity getBookExerciseDetail(@RequestParam(name = "accessToken") String accessToken,
                                              @RequestBody ExerciseDetailRequest request) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            List<ExerciseBookCourseClassDto> list = kmtExerciseQuestionService.findQusetionsByCourseId(request.getCourseId());
            Map<String, Object> data = new HashMap<>();
            data.put("list", list);
            responseEntity.success(data, "保存成功");
        } catch (Exception e) {
            logger.error("入参={}", request);
            logger.error("练习册课时详情", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }


    @RequestMapping(value = "/findQuestionRollbackRecord", method = RequestMethod.POST)
    @ApiOperation(value = "查询打回理由记录", httpMethod = "POST",  notes = "查询打回理由记录")
    public ResponseEntity findQuestionRollbackRecord(@RequestParam(name = "accessToken") String accessToken,
                                                @RequestBody KmtExerciseQuestionRequest request) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            List<ExerciseQuestionRollbacks> list = kmtExerciseService.findQuestionRollbackRecord(request.getQuestionId());
            Map<String, Object> data = new HashMap<>();
            data.put("list", list);
            responseEntity.success(data, "保存成功");
        } catch (Exception e) {
            logger.error("入参={}", request);
            logger.error("查询打回理由", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findQuestionAttributeFilter", method = RequestMethod.POST)
    @ApiOperation(value = "查询题目类型筛选项", httpMethod = "POST",  notes = "查询题目类型筛选项")
    public ResponseEntity findQuestionAttributeFilter(@RequestParam(name = "accessToken") String accessToken) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            Map<String, Object> data = new HashMap<>();
            data.put("list", kmtExerciseQuestionService.findQuestionAttributeFilter());
            responseEntity.success(data, "成功");
        } catch (Exception e) {
            logger.error("练习册筛选条件异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findExerciseBooks", method = RequestMethod.POST)
    @ApiOperation(value = "查询练习册", httpMethod = "POST",  notes = "查询练习册")
    public ResponseEntity findExerciseBooks(@RequestParam(name = "accessToken") String accessToken, @RequestBody ExerciseConditionRequest request) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            Map<String, Object> data = new HashMap<>();
            data.put("list", kmtExerciseMapperService.findExerciseBooks(request, tokenManager.getUserId(accessToken)));
            responseEntity.success(data, "成功");
        } catch (Exception e) {
            logger.error("查询练习册", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findExerciseBookDetail", method = RequestMethod.POST)
    @ApiOperation(value = "查询题目单元课时", httpMethod = "POST",  notes = "查询题目单元课时")
    public ResponseEntity findExerciseBookDetail(@RequestParam(name = "accessToken") String accessToken, @RequestBody ExerciseBookIdDealTypeRequest request) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            Map<String, Object> data = new HashMap<>();
            String userId = tokenManager.getUserId(accessToken);
            data.put("units", kmtExerciseMapperService.findExerciseBookDetail(request, userId));
            responseEntity.success(data, "成功");
        } catch (Exception e) {
            logger.error("练习册筛选条件异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/unitAndPeriodList", method = RequestMethod.POST)
    @ApiOperation(value = "查询题目单元课时2(答案报错)", httpMethod = "POST",  notes = "查询题目单元课时2(答案报错)")
    public ResponseEntity findUnitAndPeriodList(@RequestParam(name = "accessToken") String accessToken,
                                                @RequestBody @Valid UnitAndPeriodListRequest request) {

        ResponseEntity responseEntity = new ResponseEntity();
        try {
            Map<String, Object> data = new HashMap<>();
            data.put("units", kmtExerciseMapperService.findUnitAndPeriodList(request));
            responseEntity.success(data, "成功");
        } catch (Exception e) {
            logger.error("request={}", request);
            logger.error("查询题目单元课时2(答案报错)异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/getKmtHandlingQuestions", method = RequestMethod.POST)
    @ApiOperation(value = "kmt题库查询待加工/待审核的题目", httpMethod = "POST",  notes = "kmt题库查询待加工/待审核的题目")
    public ResponseEntity getKmtHandlingQuestions(@RequestParam(name = "accessToken") String accessToken, @RequestBody KmtHandlingQuestionRequest request) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            responseEntity.success(kmtQualityQuestionsService.getKmtHandlingQuestions(request, tokenManager.getUserId(accessToken)), "成功");
        } catch (Exception e) {
            logger.error("练习册筛选条件异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/submitKmtQuestions2Auditing", method = RequestMethod.POST)
    @ApiOperation(value = "kmt题目提交审核", httpMethod = "POST",  notes = "kmt题目提交审核")
    public ResponseEntity submitKmtQuestions2Auditing(@RequestParam(name = "accessToken") String accessToken, @RequestBody AuditingRequest request) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            logger.info(JSON.toJSONString(request));
            String userId = tokenManager.getUserId(accessToken);
            responseEntity = kmtQualityQuestionsService.submitKmtQuestions2Auditing(request, userId);
        } catch (Exception e) {
            logger.error("练习册筛选条件异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/deleteKmtQuestion", method = RequestMethod.POST)
    @ApiOperation(value = "删除题目", httpMethod = "POST",  notes = "删除题目")
    public ResponseEntity deleteKmtQuestion(@RequestParam(name = "accessToken") String accessToken, @RequestBody QuestionIdRequest request) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            logger.warn("用户{}删除了题目{}", tokenManager.getUserId(accessToken), request.getQuestionId());
            String userId = tokenManager.getUserId(accessToken);
            kmtQualityQuestionsService.deleteKmtQuestion(request.getQuestionId(), userId);
            responseEntity.success(ResponseConstant.CODE_999, "成功");
        } catch (Exception e) {
            logger.error("练习册筛选条件异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findQuestionListByParentId", method = RequestMethod.POST)
    @ApiOperation(value = "查询大小题目", httpMethod = "POST",  notes = "删除题目")
    public ResponseEntity findQuestionListByParentId(@RequestParam(name = "accessToken") String accessToken, @RequestBody ParentIdListRequest request) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            responseEntity = kmtQualityQuestionsService.findQuestionListByParentId(request.getParentIdList());
        } catch (Exception e) {
            logger.error("练习册筛选条件异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @ModifySecurity
    @RequestMapping(value = "/kmtQuestionRollback", method = RequestMethod.POST)
    @ApiOperation(value = "kmt题目打回", httpMethod = "POST",  notes = "题目打回")
    public ResponseEntity kmtQuestionRollback(@RequestParam(name = "accessToken") String accessToken,
                                           @RequestBody KmtQuestionRollbackRequest request) {

        ResponseEntity responseEntity = new ResponseEntity();
        try{
            List<String> questionIdList = request.getParentIds();
            if (CollectionUtils.isEmpty(questionIdList)) {
                responseEntity.failure(ResponseConstant.CODE_000, "请先选择题目");
            } else {
                String userId = tokenManager.getUserId(accessToken);
                responseEntity = kmtQualityQuestionsService.kmtQuestionRollback(userId, request);
            }
        } catch (Exception e){
            logger.error("入参={}", request);
            logger.error("打回异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }

        return responseEntity;
    }

    @RequestMapping(value = "/publishKmtQuestion", method = RequestMethod.POST)
    @ApiOperation(value = "发布kmt题目", httpMethod = "POST",  notes = "修改题目")
    public ResponseEntity publishKmtQuestion(@RequestParam(name = "accessToken") String accessToken,
                                          @RequestBody KmtQuestionPublishRequest request) {

        ResponseEntity responseEntity = new ResponseEntity();
        try {
            List<String> questionIdList = request.getParentIds();
            if (CollectionUtils.isEmpty(questionIdList)) {
                responseEntity.failure("请先选择题目");
                return responseEntity;
            }

            String userId = tokenManager.getUserId(accessToken);
            responseEntity = kmtQualityQuestionsService.publishKmtQuestion(request, userId);
        } catch (CommonException e) {
            System.out.println(e.getMessage());
            responseEntity.failure(ResponseConstant.CODE_000, e.getMessage());
        } catch (Exception e){
            logger.error("入参={}", request);
            logger.error("异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/submitAnswerProofreadResult", method = RequestMethod.POST)
    @ApiOperation(value = "提交答案校对结果", httpMethod = "POST",  notes = "提交答案校对结果")
    public ResponseEntity submitAnswerProofreadResult(@RequestParam(name = "accessToken") String accessToken,
                                             @RequestBody SubmitAnswerProofreadResultReq request) {

        ResponseEntity responseEntity = new ResponseEntity();
        try {
            String userId = tokenManager.getUserId(accessToken);
            responseEntity = kmtExerciseService.submitAnswerProofreadResult(request);
        } catch (Exception e){
            logger.error("入参={}", request);
            logger.error("异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/answerProofreadSubmitAnswer", method = RequestMethod.POST)
    @ModifySecurity
    @ApiOperation(value = "答案校对提交答案", httpMethod = "POST",  notes = "答案校对提交答案")
    public ResponseEntity answerProofreadSubmitAnswer(@RequestParam(name = "accessToken") String accessToken,
                                                      @RequestBody @Valid AnswerProofreadSubmitAnswerRequest request) {

        ResponseEntity responseEntity = new ResponseEntity();
        try {
            responseEntity = kmtExerciseService.answerProofreadSubmitAnswer(request);
        } catch (Exception e){
            logger.error("入参={}", request);
            logger.error("答案校对提交答案异常", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }

        return responseEntity;
    }

    @RequestMapping(value = "/teacherAnswerProofreadDetail", method = RequestMethod.POST)
    @ApiOperation(value = "查询答案校对本数", httpMethod = "POST", notes = "查询答案校对本数")
    public ResponseEntity teacherAnswerProofreadDetail(@RequestParam(name = "accessToken") String accessToken) {
        ResponseEntity responseEntity;
        try {
            String userId = tokenManager.getUserId(accessToken);
            responseEntity = kmtExerciseService.teacherAnswerProofreadDetail(userId);
        } catch (Exception e) {
            logger.error("查询答案校对本数异常", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/questionErrors", method = RequestMethod.POST)
    @ApiOperation(value = "题目报错", httpMethod = "POST", notes = "题目报错")
    public ResponseEntity questionErrors(@RequestParam(name = "accessToken") String accessToken,
                                         @RequestBody @Valid QuestionRollbackRequest request) {
        ResponseEntity responseEntity;
        try {
            String userId = tokenManager.getUserId(accessToken);
            responseEntity = kmtExerciseService.questionsError(userId, request);
        } catch (Exception e) {
            logger.error("题目报错", e);
            responseEntity = new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @RequestMapping(value = "/findExerciseErrorQuestions", method = RequestMethod.POST)
    @ApiOperation(value = "报错明细", httpMethod = "POST", notes = "报错明细")
    public ResponseEntity findExerciseErrorQuestions(@RequestParam(name = "accessToken") String accessToken,
                                         @RequestBody PageReq request) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            String userId = tokenManager.getUserId(accessToken);
            responseEntity.success(kmtExerciseService.findExerciseErrorQuestions(request, userId), "成功");
        } catch (Exception e) {
            logger.error("报错明细", e);
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;
    }

    @IgnoreSecurity
    @RequestMapping(value = "updateRollbackUserId",method = RequestMethod.POST)
    @ApiOperation(value = "更新打回数据",httpMethod = "POST",notes = "更新打回数据")
    public ResponseEntity updateRollbackUserId(@RequestParam(name = "accessToken") String accessToken){
        ResponseEntity responseEntity;
        try {
            responseEntity=kmtExerciseService.updateRollbackUserId();
        }catch (Exception e){
            logger.error("更新打回数据失败", e);
            responseEntity=new ResponseEntity();
            responseEntity.failure(ResponseConstant.CODE_500, "系统繁忙，请稍后重试");
        }
        return responseEntity;

    }

}
