package com.qmth.distributed.print.business.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qmth.distributed.print.business.bean.dto.CardCustDto;
import com.qmth.distributed.print.business.bean.dto.CardDetailDto;
import com.qmth.distributed.print.business.bean.dto.SyncExamCardDto;
import com.qmth.distributed.print.business.bean.marking.ConvertJpgStorage;
import com.qmth.distributed.print.business.bean.params.ExamCardParams;
import com.qmth.distributed.print.business.bean.params.GenericExamCardParams;
import com.qmth.distributed.print.business.entity.*;
import com.qmth.distributed.print.business.enums.CardStatusEnum;
import com.qmth.distributed.print.business.enums.CardTypeEnum;
import com.qmth.distributed.print.business.enums.MakeMethodEnum;
import com.qmth.distributed.print.business.enums.TemplateTypeEnum;
import com.qmth.distributed.print.business.mapper.ExamCardMapper;
import com.qmth.distributed.print.business.service.*;
import com.qmth.distributed.print.business.util.HtmlToJpgUtil;
import com.qmth.teachcloud.common.bean.params.ArraysParams;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.entity.BasicAttachment;
import com.qmth.teachcloud.common.entity.SysOrg;
import com.qmth.teachcloud.common.entity.SysUser;
import com.qmth.teachcloud.common.enums.CardCreateMethodEnum;
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
import com.qmth.teachcloud.common.enums.PageSizeEnum;
import com.qmth.teachcloud.common.service.BasicAttachmentService;
import com.qmth.teachcloud.common.service.BasicCourseService;
import com.qmth.teachcloud.common.service.TeachcloudCommonService;
import com.qmth.teachcloud.common.util.ServletUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 题卡 服务实现类
 * </p>
 *
 * @author xf
 * @since 2021-03-23
 */
@Service
public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> implements ExamCardService {

    @Resource
    private BasicExamRuleService basicExamRuleService;

    @Resource
    private ExamCardDetailService examCardDetailService;

    @Resource
    private ExamTaskDetailService examTaskDetailService;

    @Resource
    private ExamTaskService examTaskService;

    @Resource
    private BasicAttachmentService basicAttachmentService;

    @Resource
    TeachcloudCommonService teachcloudCommonService;

    @Resource
    BasicCourseService basicCourseService;

    @Resource
    BasicTemplateOrgService basicTemplateOrgService;

    @Resource
    HtmlToJpgUtil htmlToJpgUtil;

    @Resource
    BasicPrintConfigService basicPrintConfigService;

    @Resource
    BasicCardRuleService basicCardRuleService;

    @Transactional
    @Override
    public String saveExamCard(ExamCardParams examCardParams) throws Exception {
        // ↓专卡
        Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
        SysUser user = (SysUser) ServletUtil.getRequestUser();

        validateCardData(examCardParams);

        // 新增
        ExamCard examCard;
        ExamCardDetail examCardDetail;
        if (examCardParams.getTitle().getBytes().length > 80) {
            throw ExceptionResultEnum.ERROR.exception("标题最长只能输入80个字符");
        }
        if (examCardParams.getId() == null) {
            examCard = new ExamCard();
            examCard.setSchoolId(schoolId);
            if (Objects.isNull(examCardParams.getTemplateId())) {
                examCard.setOrgId(basicCourseService.getOrgIdBySchoolIdAndCourseCode(schoolId, examCardParams.getCourseCode()));
            } else {
                examCard.setOrgId(user.getOrgId());
            }
            examCard.setCourseCode(examCardParams.getCourseCode());
            examCard.setCourseName(examCardParams.getCourseName());
            examCard.setTitle(examCardParams.getTitle());
            examCard.setMakeMethod(examCardParams.getMakeMethod());
            examCard.setStatus(examCardParams.getStatus());
            examCard.setType(examCardParams.getType());
            if (StringUtils.isNotBlank(examCardParams.getAttachmentId())) {
                examCard.setAttachmentId(Long.valueOf(examCardParams.getAttachmentId()));
            }
            examCard.insertInfo(user.getId());
            this.save(examCard);

            examCardDetail = new ExamCardDetail();
            examCardDetail.setCardId(examCard.getId());
            examCardDetail.setContent(examCardParams.getContent());
            String htmlContent = examCardParams.getHtmlContent();
            List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertHtmlToJpgByCard(examCard.getTitle(),htmlContent,PageSizeEnum.A3);
            if (convertJpgStorageList.size() > 0){
                examCardDetail.setJpgAttachmentInfo(JSON.toJSONString(convertJpgStorageList));
            }
            examCardDetail.setHtmlContent(htmlContent);
            examCardDetail.setAttachmentId(examCardParams.getAttachmentId());
            examCardDetail.insertInfo(user.getId());
            examCardDetailService.save(examCardDetail);
        }
        // 修改
        else {
            examCard = this.getById(examCardParams.getId());
            examCard.setTitle(examCardParams.getTitle());
            if (!examCardParams.getCourseCode().equals(examCard.getCourseCode())) {
                throw ExceptionResultEnum.ERROR.exception("课程不能更改");
            }
            if (!examCardParams.getMakeMethod().name().equals(examCard.getMakeMethod().name())) {
                throw ExceptionResultEnum.ERROR.exception("题卡制作方式不能更改");
            }
            examCard.setStatus(examCardParams.getStatus());
            examCard.setUpdateId(user.getId());
            examCard.setUpdateTime(System.currentTimeMillis());
            this.updateById(examCard);

            examCardDetail = examCardDetailService.getByCardId(examCardParams.getId());
            if (examCardDetail == null) {
                throw ExceptionResultEnum.ERROR.exception("题卡数据有误");
            }
            examCardDetail.setContent(examCardParams.getContent());
            String htmlContent = examCardParams.getHtmlContent();
            List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertHtmlToJpgByCard(examCard.getTitle(),htmlContent,PageSizeEnum.A3);
            if (convertJpgStorageList.size() > 0){
                examCardDetail.setJpgAttachmentInfo(JSON.toJSONString(convertJpgStorageList));
            }
            examCardDetail.setHtmlContent(htmlContent);
            examCardDetail.setAttachmentId(examCardParams.getAttachmentId());
            examCardDetail.updateInfo(user.getId());
            examCardDetailService.updateById(examCardDetail);
        }

        // 绑定命题任务
        examTaskDetailService.bindCardId(examCardParams.getExamTaskId(), examCard);

        return String.valueOf(examCard.getId());
    }

    @Override
    public IPage<CardCustDto> listCardCust(String schoolId, String status, String paperNumber, String userId, Long applyStartTime, Long applyEndTime, Long finishStartTime, Long finishEndTime, Integer pageNumber, Integer pageSize) {
        Page<CardCustDto> page = new Page<>(pageNumber, pageSize);
        IPage<CardCustDto> cardCustDtoIPage = this.baseMapper.listCardCust(page, schoolId, status, paperNumber, userId, applyStartTime, applyEndTime, finishStartTime, finishEndTime);
        return cardCustDtoIPage;
    }

    @Transactional
    @Override
    public String saveExamCardCust(ExamCardParams examCardParams) {
        Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
        SysUser user = (SysUser) ServletUtil.getRequestUser();

        if (!MakeMethodEnum.CUST.name().equals(examCardParams.getMakeMethod().name())) {
            throw ExceptionResultEnum.ERROR.exception("题卡制作类型错误");
        }
        if (StringUtils.isBlank(examCardParams.getCustAttachmentId())) {
            throw ExceptionResultEnum.ERROR.exception("客户制卡时，附件未上传");
        }

        ExamCard examCard = new ExamCard();
        examCard.setId(SystemConstant.getDbUuid());
        examCard.setSchoolId(schoolId);
        examCard.setOrgId(user.getOrgId());
        examCard.setCourseCode(examCardParams.getCourseCode());
        examCard.setCourseName(examCardParams.getCourseName());
        examCard.setMakeMethod(examCardParams.getMakeMethod());
        examCard.setTitle(examCardParams.getTitle());
        examCard.setStatus(examCardParams.getStatus());
        examCard.setType(CardTypeEnum.CUSTOM);
        examCard.setCreateId(user.getId());
        examCard.setCreateTime(System.currentTimeMillis());
        this.save(examCard);

        ExamCardDetail examCardDetail = new ExamCardDetail();
        examCardDetail.setId(SystemConstant.getDbUuid());
        examCardDetail.setCardId(examCard.getId());
        examCardDetail.setCustAttachmentId(examCardParams.getCustAttachmentId());
        examCardDetail.setCreateId(user.getId());
        examCardDetail.setCreateTime(System.currentTimeMillis());
        examCardDetailService.save(examCardDetail);

        // 绑定命题任务
        examTaskDetailService.bindCardId(examCardParams.getExamTaskId(), examCard);

        return String.valueOf(examCard.getId());
    }

    @Override
    public CardDetailDto getCardDetail(Long cardId) {
        ExamCard examCard = this.getById(cardId);
        if (!MakeMethodEnum.SELECT.equals(examCard.getMakeMethod())) {
            return this.baseMapper.getCardDetail(cardId);
        } else {
            return this.baseMapper.getCardDetailBySelect(cardId);
        }
    }

    @Override
    public ExamCard getOneByTemplateId(Long templateId) {
        QueryWrapper<ExamCard> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ExamCard::getAttachmentId, templateId);
        return this.getOne(queryWrapper);
    }

    @Override
    public boolean usedCardByTemplateId(Long templateId) {
        List<ExamTaskDetail> list = examTaskDetailService.listByTemplateId(templateId);
        return !list.isEmpty();
    }

    @Override
    public List<ExamCard> listSelectCard(String courseCode, Long cardRuleId) {
        Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
        Set<Long> orgIds = teachcloudCommonService.listSubOrgIds(null);

        // 通用题卡
        List<ExamCard> list = new ArrayList<>();
        List<ExamCard> genericCards = this.baseMapper.listGenericCard(schoolId, orgIds, CardTypeEnum.GENERIC.name(), cardRuleId);
        if (!genericCards.isEmpty()) {
            list.addAll(genericCards);
        }
        // 专卡
        if (SystemConstant.ALL_CARD != cardRuleId) {
            List<ExamCard> customCards = this.baseMapper.listCustom(schoolId, sysUser.getOrgId(), courseCode, CardTypeEnum.CUSTOM.name());
            if (!customCards.isEmpty()) {
                // 只查自己创建的专卡
                customCards = customCards.stream().filter(m -> Objects.equals(m.getCreateId(), sysUser.getId())).collect(Collectors.toList());
                if (!customCards.isEmpty()) {
                    list.addAll(customCards);
                }
            }
        }
        list.sort(Comparator.comparing(ExamCard::getType));
        return list;
    }

    @Override
    public void downloadFiles(HttpServletResponse response, ArraysParams arraysParams) throws Exception {
        // 路径规则：download-temp/{time}/{schoolId}/{courseCode}-{couseName}/{paperNumber}/{fileName}
        long time = System.nanoTime();
        String rootPath = SystemConstant.TEMP_FILES_DIR + File.separator + time;

        Long[] cardIds = arraysParams.getIds();
        // 根据题卡取命题任务
        for (Long cardId : cardIds) {
            List<ExamTask> examTasks = examTaskService.listExamTaskByCardId(cardId);
            if (examTasks.isEmpty() || examTasks.size() > 1) {
                throw ExceptionResultEnum.ERROR.exception("题卡数据异常");
            }
            ExamTask examTask = examTasks.get(0);
            StringJoiner sj = new StringJoiner(File.separator);
            sj.add(rootPath).add(examTask.getSchoolId().toString()).add(examTask.getCourseCode() + "-" + examTask.getCourseName()).add(examTask.getPaperNumber());

            // 附件ID
            ExamCardDetail examCardDetail = examCardDetailService.getByCardId(cardId);
            BasicAttachment attachment = basicAttachmentService.getById(examCardDetail.getCustAttachmentId());
            String fileName = attachment.getName() + attachment.getType();
            teachcloudCommonService.copyFile(sj.toString(), fileName, attachment);
        }
        // 压缩
        teachcloudCommonService.downloadFileAndZip(response, rootPath, time);
    }

    @Override
    public List<SyncExamCardDto> listSyncCardByCourseCodeAndPaperNumber(Long schoolId, String courseCode, String paperNumber) {
        return this.baseMapper.listSyncCardByCourseCodeAndPaperNumber(schoolId, courseCode, paperNumber);
    }


    @Override
    public IPage<ExamCard> listPage(String type, String title, String createMethod, Boolean enable, Long createStartTime, Long createEndTime, Integer pageNumber, Integer pageSize) {
        Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
        Page<ExamCard> page = new Page<>(pageNumber, pageSize);
        IPage<ExamCard> iPage = this.baseMapper.listPage(page, schoolId, type, title, createMethod, enable, createStartTime, createEndTime);

        if (iPage.getRecords().size() > 0) {
            iPage.getRecords().forEach(m -> {
                //查询适用学院
                List<SysOrg> sysOrgs = basicTemplateOrgService.listByTypeAndTemplateId(type, Long.valueOf(m.getId()));
                m.setOrgs(sysOrgs);
            });
        }
        return iPage;
    }

    @Transactional
    @Override
    public Long saveGeneric(GenericExamCardParams params) throws Exception {
        Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();

        QueryWrapper<ExamCard> checkTitleQueryWrapper = new QueryWrapper<>();
        checkTitleQueryWrapper.lambda().eq(ExamCard::getSchoolId, schoolId).eq(ExamCard::getType, CardTypeEnum.GENERIC).eq(ExamCard::getTitle, params.getTitle().trim());
        ExamCard checkTitleExamCardList = this.getOne(checkTitleQueryWrapper);

        ExamCard examCard = new ExamCard();
        ExamCardDetail examCardDetail = new ExamCardDetail();
        // 新增
        if (Objects.isNull(params.getId())) {
            // 保存题卡
            examCard.setId(SystemConstant.getDbUuid());
            examCard.setSchoolId(schoolId);
            examCard.setOrgId(sysUser.getOrgId());

            if (checkTitleExamCardList != null) {
                throw ExceptionResultEnum.ERROR.exception("题卡名称重复");
            }
            examCard.setTitle(params.getTitle());
            examCard.setMakeMethod(MakeMethodEnum.SELECT); // 默认值
            // 上传题卡，状态为提交
            examCard.setStatus(CardCreateMethodEnum.UPLOAD.equals(params.getCreateMethod()) ? CardStatusEnum.SUBMIT : CardStatusEnum.valueOf(params.getStatus()));
            examCard.setType(CardTypeEnum.GENERIC); // 默认值
            examCard.setCreateMethod(params.getCreateMethod());
            examCard.setAttachmentId(params.getAttachmentId());
            examCard.setEnable(true); // 默认值
            examCard.setCardRuleId(params.getCardRuleId());
            examCard.setRemark(params.getRemark());
            examCard.setCreateId(sysUser.getId());
            examCard.setCreateTime(System.currentTimeMillis());
            this.save(examCard);

            // 保存题卡内容
            examCardDetail.setId(SystemConstant.getDbUuid());
            examCardDetail.setCardId(examCard.getId());
            examCardDetail.setCreateId(sysUser.getId());
            examCardDetail.setCreateTime(System.currentTimeMillis());
            // 方式为上传
            String htmlContent = "";
            if (CardCreateMethodEnum.UPLOAD.equals(params.getCreateMethod())) {
                if (params.getAttachmentId() == null) {
                    throw ExceptionResultEnum.ERROR.exception("请上传模板文件");
                }
                BasicAttachment attachment = basicAttachmentService.getById(params.getAttachmentId());
                if (attachment == null) {
                    throw ExceptionResultEnum.ERROR.exception("无模板文件记录");
                }
                if (!".html".equalsIgnoreCase(attachment.getType())) {
                    throw ExceptionResultEnum.ERROR.exception("只能上传后缀为.html文件");
                }
                htmlContent = teachcloudCommonService.readFileContent(attachment.getPath());
                examCardDetail.setHtmlContent(htmlContent);
            }
            // 方式为自定义
            else if (CardCreateMethodEnum.STANDARD.equals(params.getCreateMethod()) || CardCreateMethodEnum.FREE.equals(params.getCreateMethod())) {
                examCardDetail.setContent(params.getContent());
                htmlContent = params.getHtmlContent();
                examCardDetail.setHtmlContent(htmlContent);
            } else {
                throw ExceptionResultEnum.ERROR.exception("题卡创建方式异常");
            }
            List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertHtmlToJpgByCard(examCard.getTitle(),htmlContent,PageSizeEnum.A3);
            if (convertJpgStorageList.size() > 0){
                examCardDetail.setJpgAttachmentInfo(JSON.toJSONString(convertJpgStorageList));
            }
            examCardDetailService.save(examCardDetail);
        }
        // 修改
        else {
            examCard = this.getById(params.getId());
            if (checkTitleExamCardList != null && !Objects.equals(params.getId(), examCard.getId())) {
                throw ExceptionResultEnum.ERROR.exception("题卡名称重复");
            }
            examCard.setTitle(params.getTitle());
            examCard.setAttachmentId(params.getAttachmentId());
            examCard.setCardRuleId(params.getCardRuleId());
            // 上传题卡，状态为提交
            examCard.setStatus(CardCreateMethodEnum.UPLOAD.equals(params.getCreateMethod()) ? CardStatusEnum.SUBMIT : CardStatusEnum.valueOf(params.getStatus()));
            examCard.setRemark(params.getRemark());
            examCard.setUpdateId(sysUser.getId());
            examCard.setUpdateTime(System.currentTimeMillis());
            this.updateById(examCard);

            examCardDetail = examCardDetailService.getByCardId(params.getId());
            examCardDetail.setUpdateId(sysUser.getId());
            examCardDetail.setUpdateTime(System.currentTimeMillis());
            String htmlContent = "";
            // 方式为上传
            if (CardCreateMethodEnum.UPLOAD.equals(params.getCreateMethod())) {
                if (params.getAttachmentId() == null) {
                    throw ExceptionResultEnum.ERROR.exception("请上传模板文件");
                }
                BasicAttachment attachment = basicAttachmentService.getById(params.getAttachmentId());
                if (attachment == null) {
                    throw ExceptionResultEnum.ERROR.exception("无模板文件记录");
                }
                if (!".html".equalsIgnoreCase(attachment.getType())) {
                    throw ExceptionResultEnum.ERROR.exception("只能上传后缀为.html文件");
                }
                htmlContent = teachcloudCommonService.readFileContent(attachment.getPath());
                examCardDetail.setHtmlContent(htmlContent);
                // 上传题卡，状态为提交
                examCard.setStatus(CardStatusEnum.SUBMIT);
            }
            // 方式为自定义
            else if (CardCreateMethodEnum.STANDARD.equals(params.getCreateMethod()) || CardCreateMethodEnum.FREE.equals(params.getCreateMethod())) {
                examCardDetail.setContent(params.getContent());
                htmlContent = params.getHtmlContent();
                examCardDetail.setHtmlContent(htmlContent);
            } else {
                throw ExceptionResultEnum.ERROR.exception("题卡创建方式异常");
            }
            List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertHtmlToJpgByCard(examCard.getTitle(),htmlContent,PageSizeEnum.A3);
            if (convertJpgStorageList.size() > 0){
                examCardDetail.setJpgAttachmentInfo(JSON.toJSONString(convertJpgStorageList));
            }
            examCardDetailService.updateById(examCardDetail);

            //删除权限
            basicTemplateOrgService.removeByRuleId(examCard.getId());

        }

        // 保存适用范围
        if (params.getOrgIds() == null || params.getOrgIds().length == 0) {
            throw ExceptionResultEnum.ERROR.exception("请选择适用范围");
        }
        basicTemplateOrgService.saveBatch(schoolId, TemplateTypeEnum.GENERIC, examCard.getId(), params.getOrgIds(), examCard.getCreateId());
        return examCard.getId();
    }

    @Transactional
    @Override
    public Boolean deleteGeneric(Long id) {
        // 校验题卡是否被绑定
        QueryWrapper<ExamTaskDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ExamTaskDetail::getCardId, id);
        List<ExamTaskDetail> examTaskDetails = examTaskDetailService.list(queryWrapper);
        if (examTaskDetails != null && examTaskDetails.size() > 0) {
            throw ExceptionResultEnum.ERROR.exception("题卡已绑定命题任务，不能删除");
        }

        examCardDetailService.removeByCardId(id);
        return this.removeById(id);
    }

    /**
     * 数据验证
     *
     * @param examCardParams
     */
    private void validateCardData(ExamCardParams examCardParams) {
        BasicExamRule basicExamRule = basicExamRuleService.getBySchoolId();
        if (basicExamRule == null) {
            throw ExceptionResultEnum.ERROR.exception("通用规则未设置");
        }

        if (StringUtils.isBlank(examCardParams.getMakeMethod().name())) {
            throw ExceptionResultEnum.ERROR.exception("题卡制作方式不能为空");
        }
        if (!basicExamRule.getCustomCard() && MakeMethodEnum.CUST.name().equals(examCardParams.getMakeMethod().name())) {
            throw ExceptionResultEnum.ERROR.exception("未启用客服制卡，不能选择该方式制作题卡");
        }
        if (examCardParams.getStatus() == null) {
            throw ExceptionResultEnum.ERROR.exception("提交方式不能为空");
        }
        if (CardTypeEnum.CUSTOM.name().equals(examCardParams.getType())) {
            if (examCardParams.getExamTaskId() == null) {
                throw ExceptionResultEnum.ERROR.exception("命题任务ID不能为空");
            }
            if (StringUtils.isBlank(examCardParams.getCourseCode())) {
                throw ExceptionResultEnum.ERROR.exception("课程代码不能为空");
            }
            if (StringUtils.isBlank(examCardParams.getCourseName())) {
                throw ExceptionResultEnum.ERROR.exception("课程名称不能为空");
            }
            if (MakeMethodEnum.SELECT.name().equals(examCardParams.getMakeMethod().name())) {
                if (examCardParams.getId() == null) {
                    throw ExceptionResultEnum.ERROR.exception("选择已有题卡时，题卡ID不能为空");
                }
                // 当前选择题卡是否已绑定
                List<ExamTaskDetail> list = examTaskDetailService.listByCardId(examCardParams.getId());
                if (list != null && list.size() > 0) {
                    throw ExceptionResultEnum.ERROR.exception("选择的题卡已被其它命题任务绑定");
                }

            } else if (MakeMethodEnum.SELF.name().equals(examCardParams.getMakeMethod().name())) {
                if (StringUtils.isBlank(examCardParams.getTitle())) {
                    throw ExceptionResultEnum.ERROR.exception("题卡标题不能为空");
                }
                if (StringUtils.isBlank(examCardParams.getContent())) {
                    throw ExceptionResultEnum.ERROR.exception("题卡内容不能为空");
                }
                if (CardStatusEnum.SUBMIT.name().equals(examCardParams.getStatus().name())) {
                    if (StringUtils.isBlank(examCardParams.getHtmlContent())) {
                        throw ExceptionResultEnum.ERROR.exception("提交题卡时，html内容不能为空");
                    }
                }
            } else if (MakeMethodEnum.CUST.name().equals(examCardParams.getMakeMethod().name())) {
                if (StringUtils.isBlank(examCardParams.getContent())) {
                    throw ExceptionResultEnum.ERROR.exception("题卡内容不能为空");
                }
                if (CardStatusEnum.SUBMIT.name().equals(examCardParams.getStatus().name())) {
                    if (StringUtils.isBlank(examCardParams.getHtmlContent())) {
                        throw ExceptionResultEnum.ERROR.exception("提交题卡时，html内容不能为空");
                    }
                }
            }
        }
    }
}
