package com.ssj.service.kmt.kmt.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.ssj.bean.kmt.kmt.domain.KmtExerciseBook;
import com.ssj.bean.kmt.kmt.domain.KmtExerciseQuestion;
import com.ssj.bean.kmt.kmt.domain.KmtExerciseQuestionKnow;
import com.ssj.bean.weixin.libmy.domain.TbLibManager;
import com.ssj.bean.weixin.push.domain.SendTemplateShort;
import com.ssj.bean.weixin.user.domain.User;
import com.ssj.bean.weixin.zyb.domain.ZuoybKnowHowDetailsSort;
import com.ssj.dao.weixin.library.dao.IBookManagerDao;
import com.ssj.dao.weixin.user.dao.UserDao;
import com.ssj.dao.weixin.zuoyb.dao.ZuoybKnowHowDetailsSortDao;
import com.ssj.es.service.base.BaseSearchService;
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.framework.core.util.StringUtil;
import com.ssj.framework.idworker.IdWorker;
import com.ssj.framework.weixin.util.DateUtil;
import com.ssj.service.kmt.dto.KnowHowDetailsDTO;
import com.ssj.service.kmt.dto.KnowledgeBaseDto;
import com.ssj.service.kmt.exercisesys.enums.ProofreadStatusEnum;
import com.ssj.service.kmt.request.AuditingV1Request;
import com.ssj.service.kmt.request.QuestionUpdateRequest;
import com.ssj.service.kmt.service.KmtExerciseQuestionService;
import com.ssj.service.kmt.service.KmtExerciseService;
import com.ssj.service.kmt.service.KmtExerciseSubmitService;
import com.ssj.service.mapper.KmtExerciseMapper;
import com.ssj.service.task.SyncRefreshExerciseBookStatusTask;
import com.ssj.service.weixin.push.service.PushTemplateService;
import com.ssj.taskthread.ThreadPool;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

@Service(version ="1.0")
public class KmtExerciseSubmitServiceImpl implements KmtExerciseSubmitService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IBookManagerDao bookManagerDao;
    @Autowired
    private KmtExerciseMapper kmtExerciseMapper;
    @Autowired
    private UserDao userDao;
    @Autowired
    private ZuoybKnowHowDetailsSortDao zuoybKnowHowDetailsSortDao;
    @Autowired
    private KmtExerciseService kmtExerciseService;
    @Autowired
    private TokenManager tokenManager;
    @Autowired
    private PushTemplateService pushTemplateService;
    @Autowired
    private KmtExerciseQuestionService kmtExerciseQuestionService;
    @Autowired
    private BaseSearchService baseSearchService;


    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public ResponseEntity submit2Auditing(AuditingV1Request request, String userId) {
        ResponseEntity responseEntity = new ResponseEntity();
        if (CollectionUtils.isNotEmpty(request.getQuestions())) {
            List<String> questionIds = request.getQuestions().stream().map(QuestionUpdateRequest::getQuestionId).collect(Collectors.toList());
            List<KmtExerciseQuestion> questions = kmtExerciseMapper.findKmtExerciseQuestionsByIdIn(questionIds);
            kmtExerciseService.appendQuestionDataFromJSONFile(questions); //读文件，把题目信息加载到实体中
            KmtExerciseBook book = kmtExerciseMapper.findExerciseBookById(questions.get(0).getExerciseBookId());
            this.appendUser2QuestionBean(questions, book);  //把加工审核人，校对人加载到实体中
            boolean isManagerSubmit = isManagerSubmit(userId, request.getType());  //是否是管理员提交
            request.setType(isManagerSubmit ? 3 : request.getType());  //管理员提交修改为3, 管理员修改不改变题目的状态

            if (isExistQuestonsPulish(questions, request.getType())){
                return responseEntity.failure(ResponseConstant.CODE_000, "题目已发布，不能提交审核");
            } else if (!isQuestionHandlerSubmitKnowledge(request)) {
                return responseEntity.failure(ResponseConstant.CODE_000, "请添加知识点");
            } else {
                //走事务保存练习册，题目，知识点
                this.updateBookAndQuestionsAndKnow(questions, book, request);
                // 异步刷新练习册加工状态和题目状态统计
                ThreadPool.getInstance().addTask(new SyncRefreshExerciseBookStatusTask(Collections.singletonList(questions.get(0).getExerciseBookId()), 2));
                //数据同步es
                this.updateEsQuestionAndKnow(questions, questionIds);
            }
            responseEntity.success("提交成功");
        }
        return responseEntity;
    }


    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void updateBookAndQuestionsAndKnow (List<KmtExerciseQuestion> questions, KmtExerciseBook book, AuditingV1Request request){
        boolean  isAnswerCorrectSubmit = isAnswerCorrectSubmit(request.getType());  //是否是校对修改提交
        List<String> questionIds = request.getQuestions().stream().map(QuestionUpdateRequest::getQuestionId).collect(Collectors.toList());

        //更新练习册
        this.updateKmtExerciseBookFinishStatus(questions.size(), book, request.getType());
        kmtExerciseMapper.updateKmtExerciseBookHandleStatus(book);

        //更新题目
        this.getKmtExerciseQuestionData(questions, request.getQuestions(), request.getType(), isAnswerCorrectSubmit);
        for (KmtExerciseQuestion kmtExerciseQuestion : questions) {
            kmtExerciseMapper.updateKmtExerciseQuestions(kmtExerciseQuestion);
        }
        //保存大字段文件
        kmtExerciseService.saveQuestionData2JSONFile(questions);

        //更新知识点
        kmtExerciseMapper.deleteKmtExerciseQuestionKnowByQuestionIds(questionIds);
        List<KmtExerciseQuestionKnow> questionKnows = new ArrayList<>();
        for (QuestionUpdateRequest updateRequest : request.getQuestions()) {
            if (CollectionUtils.isNotEmpty(updateRequest.getKnowledges())) {
                for (KmtExerciseQuestion question : questions) {
                    if (question.getId().equals(updateRequest.getQuestionId())){
                        questionKnows.addAll(this.getKmtQuestionKnow(updateRequest.getKnowledges(), question));
                        break;
                    }
                }
            }
        }
        if (CollectionUtils.isNotEmpty(questionKnows)) {
            for (KmtExerciseQuestionKnow know : questionKnows){
                kmtExerciseMapper.insertKmtExerciseQuestionKnow(know);
            }
        }
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void updateEsQuestionAndKnow (List<KmtExerciseQuestion> questions, List<String> questionIds){
        for (KmtExerciseQuestion kmtExerciseQuestion : questions){
            kmtExerciseQuestionService.saveToEs(kmtExerciseQuestion);
        }
        List<Map<String, Object>> knowEsData = kmtExerciseMapper.findData2EsByQuestionList(questionIds);
        if (CollectionUtils.isNotEmpty(knowEsData)) {
            baseSearchService.insertBatch("kmt_exercise_question_know", knowEsData, true);
        }
    }


    /**
     * 是否是管理员提交
     * @param userId
     * @param type
     * @return
     */
    private boolean isManagerSubmit (String userId, int type){
        TbLibManager manager = bookManagerDao.findByUserIdAndType(userId, 18);
        if (manager != null) {
            //管理员把状态设置为3，不改任何状态
            return true;
        }
        return false;
    }

    /**
     * 是否是答案校对提交
     * @param type
     * @return
     */
    private boolean isAnswerCorrectSubmit (int type) {
        // 答案校对修改提交
        if (Objects.equals(type, 6)) {
            return true;
        }
        return false;
    }

    /**
     * 是否存在已发布的题目
     * @param questions
     * @param type
     * @return
     */
    private boolean isExistQuestonsPulish (List<KmtExerciseQuestion> questions, int type){
        boolean exist = false;
        if (type == 4 && questions.stream().anyMatch(q -> q.getDealStatus() == 11)) {
            //解析加工提交， 但是题目存在解析已发布
            exist = true;
        } else if (type == 0 && questions.stream().anyMatch(q -> q.getDealStatus() == 4 || q.getDealStatus() == 5 || q.getDealStatus() > 7)) {
            //题目加工提交，但是题目存在加工已发布
            exist = true;
        }
        return exist;
    }

    /**
     * 练习册加工审核是否提交了知识点
     * @param request
     * @return
     */
    private boolean isQuestionHandlerSubmitKnowledge (AuditingV1Request request){
        boolean  result = true;
        if (request.getType() == 0 || request.getType() == 1 || request.getType() == 3){
            for (QuestionUpdateRequest questionUpdateRequest : request.getQuestions()){
                if (CollectionUtils.isEmpty(questionUpdateRequest.getKnowledges())){
                    result = false;
                    break;
                }
            }
        }
        return result;
    }

    /**
     * 把练习册的加工审核人，校对人加入到题目实体中
     * @param questions
     * @param book
     */
    private void appendUser2QuestionBean (List<KmtExerciseQuestion> questions, KmtExerciseBook book){
        if (CollectionUtils.isNotEmpty(questions)){
            for (KmtExerciseQuestion kmtExerciseQuestion : questions) {
                kmtExerciseQuestion.setHandleUserId(book.getHandleUserId());
                kmtExerciseQuestion.setAuditingUserId(book.getAuditingUserId());
                kmtExerciseQuestion.setAnalysisUserId(book.getAnalysisUserId());
                kmtExerciseQuestion.setAnalysisAuditerId(book.getAnalysisAuditerId());
                kmtExerciseQuestion.setAnswerCorrecterId(book.getAnswerCorrecterId());
            }
        }
    }


    /**
     * 提交审核更新为未加工，未审核
     * @param questionCount
     * @param exerciseBook
     * @param dealType
     */
    private void updateKmtExerciseBookFinishStatus (int questionCount, KmtExerciseBook exerciseBook, int dealType){
        int count = 0;
        if (dealType == 0){
            //题目加工
            if (exerciseBook.getHadHandle() == 0){
                count = kmtExerciseMapper.countUnFinishQuestionsByExerciseBookId(exerciseBook.getId(), 1);
                if (count <= questionCount){
                    exerciseBook.setHadHandle(1);
                }
            }
            if (exerciseBook.getHadHandle() == 1 && StringUtil.isNotBlank(exerciseBook.getAuditingUserId())) {
                //加工完了通知加工审核老师
                this.push2ExerciseTeacher(exerciseBook.getAuditingUserId(),  exerciseBook, 2);
            }
            exerciseBook.setHadAuditing(0);
        } else if (dealType == 1) {
            //题目发布
            if (exerciseBook.getHadAuditing() == 0){
                count = kmtExerciseMapper.countUnFinishQuestionsByExerciseBookId(exerciseBook.getId(), 2);
                if (count <= questionCount){
                    exerciseBook.setHadAuditing(1);
                }
            }
            if (exerciseBook.getHadHandle() == 1 && exerciseBook.getHadAuditing() == 1){
                //加工完了通知加工审核老师
                exerciseBook.setProgress("已发布");
                if (StringUtil.isNotBlank(exerciseBook.getAnalysisUserId())){
                    this.push2ExerciseTeacher(exerciseBook.getAnalysisUserId(),exerciseBook, 3);
                }
            }
            exerciseBook.setAnalysisHandled(0);
        } else if (dealType == 4){
            //题目解析加工
            if (exerciseBook.getAnalysisHandled() == 0){
                count = kmtExerciseMapper.countUnFinishQuestionsByExerciseBookId(exerciseBook.getId(), 3);
                if (count <= questionCount){
                    exerciseBook.setAnalysisHandled(1);
                }
            }

            if (exerciseBook.getHadHandle() == 1 && exerciseBook.getHadAuditing() == 1
                    && exerciseBook.getAnalysisHandled() == 1 && StringUtil.isNotBlank(exerciseBook.getAnalysisAuditerId())){
                //加工完了通知加工审核老师
                this.push2ExerciseTeacher(exerciseBook.getAnalysisAuditerId(), exerciseBook, 4);
            }
            exerciseBook.setAnalysisAudited(0);
        } else if (dealType == 5 && exerciseBook.getAnalysisAudited() == 0){
            //题目解析发布
            count = kmtExerciseMapper.countUnFinishQuestionsByExerciseBookId(exerciseBook.getId(), 4);
            if (count <= questionCount){
                exerciseBook.setAnalysisAudited(1);
            }
        }
    }

    /**
     * 练习册加工完推送下一个阶段的老师
     * @param userId
     * @param exerciseBook
     * @param type
     */
    private void push2ExerciseTeacher (String userId, KmtExerciseBook exerciseBook,int type){
        String key = "push_bookId"+exerciseBook.getId()+userId;
        if(tokenManager.exists(key)){
            return ;
        }

        Map<String, String> data = new HashMap<>();
        String template_id_short = "OPENTM206165551";
        User user = userDao.findOne(userId);
        if  (user != null && StringUtils.isNotEmpty(user.getAccount()) ){
            try{
                TbLibManager libTeacher = bookManagerDao.findByUserIdAndType(userId, 17);
                if (libTeacher != null){
                    String teacherName = null;
                    teacherName = libTeacher.getName();
                    if (StringUtils.isEmpty(teacherName)){
                        teacherName = user.getName();
                    }
                    String authName =  null;
                    switch (type){
                        case 1: authName="题目加工"; break;
                        case 2: authName="审核发布"; break;
                        case 3: authName="解析加工"; break;
                        case 4: authName="解析发布"; break;
                        default: authName="加工"; break;
                    }


                    String bookType =  null;
                    switch (exerciseBook.getBookType()){
                        case 0: bookType="整本"; break;
                        case 1: bookType="上半本"; break;
                        case 2: bookType="下半本"; break;
                        case 3: bookType="不同的页码的新版练习册"; break;
                        default: bookType=""; break;
                    }

                    // 你好，你有一本 数学人教版上册四年级 整本、半本,《我爱写作业(2020)》，

                    StringBuffer sb =new StringBuffer("你好，你有一本");
                    sb.append(exerciseBook.getCourseName()).append(exerciseBook.getVersionName()).append(exerciseBook.getSemester()==1?"上册":"下册");
                    sb.append(exerciseBook.getGrade()).append(bookType).append("《").append(exerciseBook.getBookName()).append("》,");
                    sb.append(authName+"请在规定时间内完成");
                    data.put("first", sb.toString());
                    data.put("keyword1", teacherName);
                    data.put("keyword2", DateUtil.format_yyyyMMddHHmmss(new Date()));
                    data.put("remark", "请及时登录处理，如有疑问请及时联系相关负责老师。");
                    SendTemplateShort sendTemplateShort = new SendTemplateShort(user.getAccount(), template_id_short, null, data);
                    pushTemplateService.saveAndSendPushWxTemplate(sendTemplateShort);
                    tokenManager.setString(key,authName,12*60*60);
                } else {
                    logger.error("没有老师角色" + userId);
                }
            } catch (Exception e){
                logger.error("推送练习册老师失败：", e);
            }
        }
    }

    /**
     * 更新题目信息
     * @param questions
     * @param questionUpdateRequests
     * @param type
     */
    private void getKmtExerciseQuestionData (List<KmtExerciseQuestion> questions, List<QuestionUpdateRequest> questionUpdateRequests,
                                                int type, boolean isAnswerCorrectSubmit) {
        //解析加工或解析审核
        if (isAnswerCorrectSubmit) {
            this.updateProofreadStatusSubmit(questions, questionUpdateRequests);
        } else if (type == 0) {
            this.updateHandlerQuestions(questions, questionUpdateRequests);
        } else if (type == 1) {
            this.updateAuditingUserQuestion(questions, questionUpdateRequests);
        } else if (type == 3){
            this.updateManagerQuestions(questions, questionUpdateRequests);
        } else if (type == 4) {
            this.updateAnalysisHandleQuestions(questions, questionUpdateRequests);
        } else if (type == 5) {
            this.updateAnalysisAuditingQuestions(questions, questionUpdateRequests);
        }
    }

    /**
     * 解析加工的提交功能，如果是加工人（题目deal_status=5,8）, 记录解析加工时间， 修改题目状态
     * @param questions
     * @param questionUpdateRequests
     */
    private void updateAnalysisHandleQuestions (List<KmtExerciseQuestion> questions, List<QuestionUpdateRequest> questionUpdateRequests) {
        for (KmtExerciseQuestion question : questions) {
            for (QuestionUpdateRequest updateRequest : questionUpdateRequests) {
                if (question.getId().equals(updateRequest.getQuestionId())) {
                    question.setAnalysisJson(updateRequest.getAnalysisJson());
                    question.setAnalysis(updateRequest.getQuestionAnalysis());
                    if (question.getDealStatus() == 5 || question.getDealStatus() == 8) {
                        question.setAnalysisHandlerSubmitTime(new Date());
                        question.setDealStatus(9);
                    }
                }
            }
        }
    }

    /**
     * 解析加工的发布功能, 记录解析加工时间， 修改题目状态
     * @param questions
     * @param questionUpdateRequests
     */
    private void updateAnalysisAuditingQuestions (List<KmtExerciseQuestion> questions, List<QuestionUpdateRequest> questionUpdateRequests) {
        for (KmtExerciseQuestion question : questions) {
            for (QuestionUpdateRequest updateRequest : questionUpdateRequests) {
                if (question.getId().equals(updateRequest.getQuestionId())) {
                    question.setAnalysisJson(updateRequest.getAnalysisJson());
                    question.setAnalysis(updateRequest.getQuestionAnalysis());
                    question.setDealStatus(11);
                    question.setAnalysisSubmitTime(new Date());
                }
            }
        }
    }

    /**
     * 题目加工提交功能
     * @param questions
     * @param questionUpdateRequests
     */
    private void updateHandlerQuestions (List<KmtExerciseQuestion> questions, List<QuestionUpdateRequest> questionUpdateRequests) {
        //循坏题目
        for (KmtExerciseQuestion question : questions) {
            for (QuestionUpdateRequest updateRequest : questionUpdateRequests) {
                if (question.getId().equals(updateRequest.getQuestionId())) {
                    this.updateKmtQuestionCommonData(question, updateRequest);
                    if (question.getDealStatus() == 0 || question.getDealStatus() == 1) {
                        question.setHandlerSubmitTime(new Date());
                        question.setDealStatus(3);
                    }
                }
            }
        }
    }

    /**
     * 题目审核提交发布功能
     * @param questions
     * @param questionUpdateRequests
     */
    private void updateAuditingUserQuestion (List<KmtExerciseQuestion> questions, List<QuestionUpdateRequest> questionUpdateRequests) {
        //循坏题目
        for (KmtExerciseQuestion question : questions) {
            for (QuestionUpdateRequest updateRequest : questionUpdateRequests) {
                if (question.getId().equals(updateRequest.getQuestionId())) {
                    this.updateKmtQuestionCommonData(question, updateRequest);
                    question.setPublishTime(new Date());
                    question.setDealStatus(5);
                }
            }
        }
    }

    /**
     * 管理员提交， 不修改题目状态
     * @param questions
     * @param questionUpdateRequests
     */
    private void updateManagerQuestions (List<KmtExerciseQuestion> questions, List<QuestionUpdateRequest> questionUpdateRequests) {
        //循坏题目
        for (KmtExerciseQuestion question : questions) {
            for (QuestionUpdateRequest updateRequest : questionUpdateRequests) {
                if (question.getId().equals(updateRequest.getQuestionId())) {
                    this.updateKmtQuestionCommonData(question, updateRequest);
                }
            }
        }
    }

    /**
     * 校对更新提交
     * @param questions
     * @param questionUpdateRequests
     */
    private void updateProofreadStatusSubmit (List<KmtExerciseQuestion> questions, List<QuestionUpdateRequest> questionUpdateRequests) {
        //循坏题目
        for (KmtExerciseQuestion question : questions) {
            for (QuestionUpdateRequest updateRequest : questionUpdateRequests) {
                if (question.getId().equals(updateRequest.getQuestionId())) {
                    this.updateKmtQuestionCommonData(question, updateRequest);
                    question.setProofreadStatus(ProofreadStatusEnum.ManagerModified.getCode());
                }
            }
        }
    }

    /**
     * 更新单个题目的信息
     * @param question
     * @param updateRequest
     */
    private void updateKmtQuestionCommonData (KmtExerciseQuestion question, QuestionUpdateRequest updateRequest) {
        question.setQuestionText(updateRequest.getQuestionText());
        question.setOptionAnswer(updateRequest.getAnswer());
        question.setAnswerJson(updateRequest.getAnswerJson());
        question.setAnalysis(updateRequest.getQuestionAnalysis());
        question.setAnalysisJson(updateRequest.getAnalysisJson());

        if (CollectionUtils.isNotEmpty(updateRequest.getQuestionTypes())) {
            question.setQuestionType(updateRequest.getQuestionTypes().get(0).getType());
        }
        if (CollectionUtils.isNotEmpty(updateRequest.getDifficultyLevels())) {
            question.setDifficultyLevel(updateRequest.getDifficultyLevels().get(0).getType());
        }

        if (CollectionUtils.isNotEmpty(updateRequest.getRealExamTypes())) {
            List<Integer> types = updateRequest.getRealExamTypes().stream().map(KnowledgeBaseDto::getType).collect(Collectors.toList());
            question.setRealExamType(StringUtils.join(types, ","));
        }

        if (CollectionUtils.isNotEmpty(updateRequest.getTrainingSkills())) {
            List<String> names = updateRequest.getTrainingSkills().stream().map(KnowledgeBaseDto::getName).collect(Collectors.toList());
            question.setTrainingSkill(StringUtils.join(names, ","));
        }
    }

    /**
     * 添加题目关联的知识点 kmt_exercise_question_know， zyb_know_how_details_sort
     * @param knowledges
     * @param question
     */
    private List<KmtExerciseQuestionKnow> getKmtQuestionKnow (List<KnowHowDetailsDTO> knowledges, KmtExerciseQuestion question){
        //知识点不为空添加知识点
        List<KmtExerciseQuestionKnow> questionKnows = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(knowledges)){
            for (KnowHowDetailsDTO detail : knowledges){
                ZuoybKnowHowDetailsSort detailsSort = zuoybKnowHowDetailsSortDao.findOne(detail.getId());
                if (CollectionUtils.isNotEmpty(detail.getPoints())){
                    //有考点的情况
                    detail.getPoints().forEach(point -> {
                        //添加题目与考点的关联记录
                        KmtExerciseQuestionKnow  kmtExerciseQuestionKnow = new KmtExerciseQuestionKnow();
                        kmtExerciseQuestionKnow.setId(IdWorker.generateId());
                        ZuoybKnowHowDetailsSort pointSort = zuoybKnowHowDetailsSortDao.findOne(point.getId());
                        kmtExerciseQuestionKnow.setQuestionId(question.getId());
                        kmtExerciseQuestionKnow.setQuestionParentId(question.getParentId());
                        kmtExerciseQuestionKnow.setHowDetailsId(detailsSort.getHowDetailsId());
                        kmtExerciseQuestionKnow.setHowDetailsKdId(pointSort.getHowDetailsKdId());
                        kmtExerciseQuestionKnow.setVersion(detailsSort.getType());
                        kmtExerciseQuestionKnow.setLoaded(0);
                        kmtExerciseQuestionKnow.setCreateTime(new Date());
                        kmtExerciseQuestionKnow.setUpdateTime(new Date());
                        kmtExerciseQuestionKnow.setHowDetailSortId(detailsSort.getId());
                        kmtExerciseQuestionKnow.setHowDetailKdSortId(pointSort.getId());
                        questionKnows.add(kmtExerciseQuestionKnow);

                    });
                } else {
                    //没有考点的情况只记录知识点
                    KmtExerciseQuestionKnow  kmtExerciseQuestionKnow = new KmtExerciseQuestionKnow();
                    kmtExerciseQuestionKnow.setId(IdWorker.generateId());
                    kmtExerciseQuestionKnow.setQuestionId(question.getId());
                    kmtExerciseQuestionKnow.setQuestionParentId(question.getParentId());
                    kmtExerciseQuestionKnow.setHowDetailsId(detailsSort.getHowDetailsId());
                    kmtExerciseQuestionKnow.setHowDetailSortId(detailsSort.getId());
                    kmtExerciseQuestionKnow.setVersion(detailsSort.getType());
                    kmtExerciseQuestionKnow.setLoaded(0);
                    kmtExerciseQuestionKnow.setCreateTime(new Date());
                    kmtExerciseQuestionKnow.setUpdateTime(new Date());
                    questionKnows.add(kmtExerciseQuestionKnow);
                }
            }
        }
        return questionKnows;
    }
}
