package org.dromara.system.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONValidator;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.aspectj.weaver.ast.Or;
import org.dromara.common.core.constant.BizConst;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.enums.biz.QuestionsList;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StreamUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.system.domain.SysRecipe;
import org.dromara.system.domain.SysScreeningAssessmentQuestion;
import org.dromara.system.domain.SysUser;
import org.dromara.system.domain.bo.SysScreeningAssessmentQuestionBo;
import org.dromara.system.domain.vo.SysDictDataVo;
import org.dromara.system.domain.vo.SysScreeningAssessmentQuestionVo;
import org.dromara.system.mapper.SysScreeningAssessmentQuestionMapper;
import org.dromara.system.mapper.SysUserMapper;
import org.dromara.system.service.ISysDictDataService;
import org.dromara.system.service.ISysUserService;
import org.springframework.stereotype.Service;
import org.dromara.system.domain.bo.SysScreeningAssessmentConfigBo;
import org.dromara.system.domain.vo.SysScreeningAssessmentConfigVo;
import org.dromara.system.domain.SysScreeningAssessmentConfig;
import org.dromara.system.mapper.SysScreeningAssessmentConfigMapper;
import org.dromara.system.service.ISysScreeningAssessmentConfigService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 筛查/评估配置Service业务层处理
 *
 * @author Lion Li
 * @date 2025-07-08
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class SysScreeningAssessmentConfigServiceImpl implements ISysScreeningAssessmentConfigService {

    private final SysScreeningAssessmentConfigMapper baseMapper;
    private final SysScreeningAssessmentQuestionMapper questionMapper;
    private final ISysDictDataService dictDataService;
    private final SysUserMapper userMapper;

    @Override
    public int updateConfigStatus(List<Long> configIdIds, String status) {
        return baseMapper.update(null,
            new LambdaUpdateWrapper<SysScreeningAssessmentConfig>()
                .set(SysScreeningAssessmentConfig::getStatus, status)
                .in(SysScreeningAssessmentConfig::getConfigId, configIdIds));
    }

    /**
     * 查询筛查/评估配置
     *
     * @param configId 主键
     * @return 筛查/评估配置
     */
    @Override
    public SysScreeningAssessmentConfigVo queryById(Long configId) {
        SysScreeningAssessmentConfigVo vo = baseMapper.selectVoById(configId);
        if (ObjUtil.isNotNull(vo)) {
            List<SysScreeningAssessmentQuestionVo> voList = questionMapper.selectVoList(Wrappers.lambdaQuery(SysScreeningAssessmentQuestion.class)
                .eq(SysScreeningAssessmentQuestion::getConfigId, vo.getConfigId()));

            Map<String, List<SysScreeningAssessmentQuestionVo>> voMap = voList.stream().collect(Collectors.groupingBy(v -> {
                if (StrUtil.isNotBlank(v.getContent())) {
                    v.setContentList(JSON.parseArray(v.getContent(), SysScreeningAssessmentQuestionVo.QuestionAttrVo.class));
                }
                if (BizConst.QUESTION_BASE_INFO.equalsIgnoreCase(v.getQuestionType())) {
                    return BizConst.QUESTION_BASE_INFO;
                } else {
                    return BizConst.QUESTION_OTHER_INFO;
                }
            }));

            List<SysScreeningAssessmentQuestionVo> questionList = voMap.get(BizConst.QUESTION_BASE_INFO);
            if (CollUtil.isNotEmpty(questionList)) {
                vo.setBaseInfo(questionList.get(0));
            }

            questionList = voMap.get(BizConst.QUESTION_OTHER_INFO);
            if (CollUtil.isNotEmpty(questionList)) {
                vo.setOtherInfo(questionList);
            }
        }

        return vo;
    }

    /**
     * 分页查询筛查/评估配置列表
     *
     * @param bo        查询条件
     * @param pageQuery 分页参数
     * @return 筛查/评估配置分页列表
     */
    @Override
    public TableDataInfo<SysScreeningAssessmentConfigVo> queryPageList(SysScreeningAssessmentConfigBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<SysScreeningAssessmentConfig> lqw = buildQueryWrapper(bo);
        Page<SysScreeningAssessmentConfigVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        if (CollUtil.isNotEmpty(result.getRecords())) {
            Map<String, SysDictDataVo> dictMap = dictDataService.selectMapByType(BizConst.SCALE_TYPE).getData();
            Set<Long> userList = CollUtil.newHashSet();
            result.getRecords().forEach(v -> {
                userList.add(v.getCreateBy());
                SysDictDataVo dataVo = dictMap.get(v.getType());
                if (ObjUtil.isNotNull(dataVo)) {
                    v.setTypeName(dataVo.getDictLabel());
                }
            });

            Map<Long, String> userMap = userMapper.selectList(Wrappers.lambdaQuery(SysUser.class)
                .select(SysUser::getUserId, SysUser::getNickName)
                .in(SysUser::getUserId, userList)).stream().collect(Collectors.toMap(k1 -> k1.getUserId(), k2 -> k2.getNickName(), (k1, k2) -> k1));

            result.getRecords().forEach(v -> {
                v.setCreateByName(userMap.get(v.getCreateBy()));
            });

        }
        return TableDataInfo.build(result);
    }

    /**
     * 查询符合条件的筛查/评估配置列表
     *
     * @param bo 查询条件
     * @return 筛查/评估配置列表
     */
    @Override
    public List<SysScreeningAssessmentConfigVo> queryList(SysScreeningAssessmentConfigBo bo) {
        LambdaQueryWrapper<SysScreeningAssessmentConfig> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<SysScreeningAssessmentConfig> buildQueryWrapper(SysScreeningAssessmentConfigBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<SysScreeningAssessmentConfig> lqw = Wrappers.lambdaQuery();
        lqw.orderByDesc(SysScreeningAssessmentConfig::getConfigId);
        lqw.eq(StringUtils.isNotBlank(bo.getType()), SysScreeningAssessmentConfig::getType, bo.getType());
        lqw.eq(StringUtils.isNotBlank(bo.getGender()), SysScreeningAssessmentConfig::getGender, bo.getGender());
        lqw.eq(StringUtils.isNotBlank(bo.getAge()), SysScreeningAssessmentConfig::getAge, bo.getAge());
        lqw.like(StringUtils.isNotBlank(bo.getName()), SysScreeningAssessmentConfig::getName, bo.getName());
        lqw.eq(StringUtils.isNotBlank(bo.getDescription()), SysScreeningAssessmentConfig::getDescription, bo.getDescription());
        lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SysScreeningAssessmentConfig::getStatus, bo.getStatus());
        return lqw;
    }

    /**
     * 新增筛查/评估配置
     *
     * @param bo 筛查/评估配置
     * @return 是否新增成功
     */
    @Override
    @Transactional
    public Boolean insertByBo(SysScreeningAssessmentConfigBo bo) {
        SysScreeningAssessmentConfig add = MapstructUtils.convert(bo, SysScreeningAssessmentConfig.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setConfigId(add.getConfigId());

            if (ObjUtil.isNotNull(bo.getBaseInfo())) {
                SysScreeningAssessmentQuestionBo questionBo = bo.getBaseInfo();
                questionBo.setConfigId(add.getConfigId());
                questionBo.setContent(JSON.toJSONString(questionBo.getContentList()));
                SysScreeningAssessmentQuestion question = MapstructUtils.convert(questionBo, SysScreeningAssessmentQuestion.class);
                questionMapper.insert(question);
            }
            if (CollUtil.isNotEmpty(bo.getOtherInfo())) {
                List<SysScreeningAssessmentQuestionBo> questionBoList = bo.getOtherInfo();
                questionBoList.forEach(questionBo -> {
                    questionBo.setConfigId(add.getConfigId());
                    questionBo.setContent(JSON.toJSONString(questionBo.getContentList()));
                });

                List<SysScreeningAssessmentQuestion> questionList = MapstructUtils.convert(questionBoList, SysScreeningAssessmentQuestion.class);
                questionMapper.insertBatch(questionList);
            }
        }
        return flag;
    }

    @Override
    public Boolean editConclusion(SysScreeningAssessmentConfigBo bo) {
        SysScreeningAssessmentConfig update = MapstructUtils.convert(bo, SysScreeningAssessmentConfig.class);
        boolean flag = baseMapper.updateById(update) > 0;
        return flag;
    }

    /**
     * 修改筛查/评估配置
     *
     * @param bo 筛查/评估配置
     * @return 是否修改成功
     */
    @Override
    @Transactional
    public Boolean updateByBo(SysScreeningAssessmentConfigBo bo) {
        SysScreeningAssessmentConfig update = MapstructUtils.convert(bo, SysScreeningAssessmentConfig.class);
        validEntityBeforeSave(update);
        boolean flag = baseMapper.updateById(update) > 0;

        if (flag) {
            questionMapper.delete(Wrappers.lambdaQuery(SysScreeningAssessmentQuestion.class)
                .eq(SysScreeningAssessmentQuestion::getConfigId, update.getConfigId()));

            if (ObjUtil.isNotNull(bo.getBaseInfo())) {
                SysScreeningAssessmentQuestionBo questionBo = bo.getBaseInfo();
                questionBo.setConfigId(update.getConfigId());
                questionBo.setContent(JSON.toJSONString(questionBo.getContentList()));
                SysScreeningAssessmentQuestion question = MapstructUtils.convert(questionBo, SysScreeningAssessmentQuestion.class);
                questionMapper.insert(question);
            }
            if (CollUtil.isNotEmpty(bo.getOtherInfo())) {
                List<SysScreeningAssessmentQuestionBo> questionBoList = bo.getOtherInfo();
                questionBoList.forEach(questionBo -> {
                    questionBo.setConfigId(update.getConfigId());
                    questionBo.setContent(JSON.toJSONString(questionBo.getContentList()));
                });

                List<SysScreeningAssessmentQuestion> questionList = MapstructUtils.convert(questionBoList, SysScreeningAssessmentQuestion.class);
                questionMapper.insertBatch(questionList);
            }
        }

        return flag;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(SysScreeningAssessmentConfig entity) {
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 校验并批量删除筛查/评估配置信息
     *
     * @param ids     待删除的主键集合
     * @param isValid 是否进行有效性校验
     * @return 是否删除成功
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if (isValid) {
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteByIds(ids) > 0;
    }

    private void setQId(SysScreeningAssessmentQuestionBo questionBo, JSONObject question) {
        if (question.containsKey("id")) {
            questionBo.setQId(question.getString("id"));
        } else if (question.containsKey("questionId")) {
            questionBo.setQId(question.getString("questionId"));
        } else if (question.containsKey("question_id")) {
            questionBo.setQId(question.getString("question_id"));
        } else if (question.containsKey("question_id")) {
            questionBo.setQId(question.getString("question_id"));
        }
    }

    @Override
    public R<?> importFile(MultipartFile file, String configType) throws Exception {
        if (ObjUtil.isNull(file)) {
            return R.fail("请选择文件!");
        }

        String content = IoUtil.read(file.getInputStream(), StandardCharsets.UTF_8);
        JSONObject jsonObject = JSON.parseObject(content);

        SysScreeningAssessmentConfigBo config = new SysScreeningAssessmentConfigBo();
        config.setName(jsonObject.getString("purpose"));
        config.setPurpose("import");
        config.setSource(jsonObject.getString("source"));
        config.setRemark(jsonObject.getString("title"));
        config.setType(configType);

        if (jsonObject.containsKey("scoring")) {
            config.setConclusion(JSON.toJSONString(jsonObject.getJSONObject("scoring")));
        } else if (jsonObject.containsKey("scoring_rules")) {
            config.setConclusion(JSON.toJSONString(jsonObject.getJSONObject("scoring_rules")));
        } else if (jsonObject.containsKey("scoringRules")) {
            config.setConclusion(JSON.toJSONString(jsonObject.getJSONObject("scoringRules")));
        }

        JSONArray questions = jsonObject.getJSONArray("questions");
        List<SysScreeningAssessmentQuestionBo> otherInfo = new ArrayList<>(questions.size());
        config.setOtherInfo(otherInfo);

        for (int i = 0, len = questions.size(); i < len; i++) {
            JSONObject question = questions.getJSONObject(i);
            String type = question.getString("type");
            if ("单选".equals(type) || "多选".equals(type)) {
                SysScreeningAssessmentQuestionBo questionBo = new SysScreeningAssessmentQuestionBo();
                otherInfo.add(questionBo);

                if (question.containsKey("text")) {
                    questionBo.setTitle(question.getString("text"));
                }

                setQId(questionBo, question);
                questionBo.setArrangement("2");
                if ("单选".equals(type)) {
                    questionBo.setQuestionType(QuestionsList.QUESTION_TYPE_SELECTION.getCode());
                    questionBo.setQuestionChildType(QuestionsList.SINGLE_CHOICE.getCode());
                } else if ("多选".equals(type)) {
                    questionBo.setQuestionType(QuestionsList.QUESTION_TYPE_SELECTION.getCode());
                    questionBo.setQuestionChildType(QuestionsList.MULTIPLE_CHOICE.getCode());
                }
                questionBo.setRequired(Boolean.TRUE);

                JSONArray options = question.getJSONArray("options");
                List<SysScreeningAssessmentQuestionBo.QuestionAttrBo> contentList = CollUtil.newArrayList();
                for (int j = 0, len2 = options.size(); j < len2; j++) {
                    SysScreeningAssessmentQuestionBo.QuestionAttrBo questionAttrBo = new SysScreeningAssessmentQuestionBo.QuestionAttrBo();
                    JSONObject op = options.getJSONObject(j);
                    if (op.containsKey("text")) {
                        questionAttrBo.setLabel(op.getString("text"));
                    } else if (op.containsKey("input_text")) {
                        questionAttrBo.setLabel(op.getString("input_text"));
                    }
                    questionAttrBo.setScore(op.getString("score"));
                    if ("单选".equals(type)) {
                        questionAttrBo.setNameEn("single" + j);
                    } else if ("多选".equals(type)) {
                        questionAttrBo.setNameEn("multiple" + j);
                    }
                    questionAttrBo.setAllowFillBlank(Boolean.FALSE);
                    contentList.add(questionAttrBo);
                }
                questionBo.setContentList(contentList);
                questionBo.setContent(JSON.toJSONString(contentList));
            } else if ("是/否".equals(type)) {
                SysScreeningAssessmentQuestionBo questionBo = new SysScreeningAssessmentQuestionBo();
                otherInfo.add(questionBo);

                if (question.containsKey("text")) {
                    questionBo.setTitle(question.getString("text"));
                }

                questionBo.setArrangement("2");
                setQId(questionBo, question);
                questionBo.setQuestionType(QuestionsList.QUESTION_TYPE_SELECTION.getCode());
                questionBo.setQuestionChildType(QuestionsList.SINGLE_CHOICE.getCode());
                JSONArray options = question.getJSONArray("options");
                questionBo.setRequired(CollUtil.isNotEmpty(options));
                List<SysScreeningAssessmentQuestionBo.QuestionAttrBo> contentList = CollUtil.newArrayList();

                if (CollUtil.isNotEmpty(options)) {
                    for (int j = 0, len2 = options.size(); j < len2; j++) {
                        SysScreeningAssessmentQuestionBo.QuestionAttrBo questionAttrBo = new SysScreeningAssessmentQuestionBo.QuestionAttrBo();
                        JSONObject op = options.getJSONObject(j);
                        if (op.containsKey("text")) {
                            questionAttrBo.setLabel(op.getString("text"));
                        } else if (op.containsKey("input_text")) {
                            questionAttrBo.setLabel(op.getString("input_text"));
                        }
                        questionAttrBo.setScore(op.getString("score"));
                        questionAttrBo.setNameEn("single" + j);
                        questionAttrBo.setAllowFillBlank(Boolean.FALSE);
                        contentList.add(questionAttrBo);
                    }
                } else {
                    SysScreeningAssessmentQuestionBo.QuestionAttrBo questionAttrBo = new SysScreeningAssessmentQuestionBo.QuestionAttrBo();
                    questionAttrBo.setLabel("是");
                    questionAttrBo.setScore("0");
                    questionAttrBo.setNameEn("single1");
                    questionAttrBo.setAllowFillBlank(Boolean.FALSE);
                    contentList.add(questionAttrBo);
                    questionAttrBo = new SysScreeningAssessmentQuestionBo.QuestionAttrBo();
                    questionAttrBo.setLabel("否");
                    questionAttrBo.setScore("0");
                    questionAttrBo.setNameEn("single0");
                    questionAttrBo.setAllowFillBlank(Boolean.FALSE);
                    contentList.add(questionAttrBo);
                }
                questionBo.setContentList(contentList);
                questionBo.setContent(JSON.toJSONString(contentList));
            } else if ("multiple_choice".equalsIgnoreCase(type) || "single_choice".equalsIgnoreCase(type)) {
                SysScreeningAssessmentQuestionBo questionBo = new SysScreeningAssessmentQuestionBo();
                otherInfo.add(questionBo);

                if (question.containsKey("text")) {
                    questionBo.setTitle(question.getString("text"));
                } else if (question.containsKey("title")) {
                    questionBo.setTitle(question.getString("title"));
                }

                setQId(questionBo, question);
                questionBo.setArrangement("2");

                if ("single_choice".equalsIgnoreCase(type)) {
                    questionBo.setQuestionType(QuestionsList.QUESTION_TYPE_SELECTION.getCode());
                    questionBo.setQuestionChildType(QuestionsList.SINGLE_CHOICE.getCode());
                } else if ("multiple_choice".equalsIgnoreCase(type)) {
                    questionBo.setQuestionType(QuestionsList.QUESTION_TYPE_SELECTION.getCode());
                    questionBo.setQuestionChildType(QuestionsList.MULTIPLE_CHOICE.getCode());
                }

                JSONArray options = question.getJSONArray("options");
                List<SysScreeningAssessmentQuestionBo.QuestionAttrBo> contentList = CollUtil.newArrayList();
                for (int j = 0, len2 = options.size(); j < len2; j++) {
                    SysScreeningAssessmentQuestionBo.QuestionAttrBo questionAttrBo = new SysScreeningAssessmentQuestionBo.QuestionAttrBo();
                    Object op = options.get(j);
                    String opStr = JSON.toJSONString(op);
                    if (JSONValidator.Type.Value.equals(JSONValidator.from(opStr).getType())) {
                        questionAttrBo.setLabel(String.valueOf(op));
                        questionAttrBo.setScore("0");
                        questionAttrBo.setAllowFillBlank(Boolean.FALSE);
                        questionBo.setRequired(Boolean.FALSE);
                    } else {
                        questionBo.setRequired(Boolean.TRUE);
                        JSONObject opObj = (JSONObject) op;
                        if (opObj.containsKey("label")) {
                            questionAttrBo.setLabel(opObj.getString("label"));
                        } else if (opObj.containsKey("text")) {
                            questionAttrBo.setLabel(opObj.getString("text"));
                        } else if (opObj.containsKey("value")) {
                            questionAttrBo.setLabel(opObj.getString("value"));
                        }

                        if (opObj.containsKey("score")) {
                            questionAttrBo.setScore(opObj.getString("score"));
                        } else if (opObj.containsKey("value")) {
                            questionAttrBo.setScore(opObj.getString("value"));
                        }

                        String val = opObj.getString("input_text");
                        questionAttrBo.setAllowFillBlank(String.valueOf(Boolean.TRUE).equalsIgnoreCase(val));
                    }

                    if ("single_choice".equalsIgnoreCase(type)) {
                        questionAttrBo.setNameEn("single" + j);
                    } else if ("multiple_choice".equalsIgnoreCase(type)) {
                        questionAttrBo.setNameEn("multiple" + j);
                    }

                    contentList.add(questionAttrBo);
                }
                questionBo.setContentList(contentList);
                questionBo.setContent(JSON.toJSONString(contentList));
            } else if ("input_number".equalsIgnoreCase(type) || "input_text".equalsIgnoreCase(type) || "calculated".equalsIgnoreCase(type)) {
                SysScreeningAssessmentQuestionBo questionBo = new SysScreeningAssessmentQuestionBo();
                otherInfo.add(questionBo);

                questionBo.setQId("Q" + i);
                setQId(questionBo, question);

                if ("input_number".equalsIgnoreCase(type)) {
                    questionBo.setQuestionType(QuestionsList.INPUT_BOX.getCode());
                    questionBo.setQuestionChildType(QuestionsList.INPUT_NUMBER.getCode());
                } else if ("input_text".equalsIgnoreCase(type)) {
                    questionBo.setQuestionType(QuestionsList.INPUT_BOX.getCode());
                    questionBo.setQuestionChildType(QuestionsList.INPUT_TEXT.getCode());
                } else if ("calculated".equalsIgnoreCase(type)) {
                    questionBo.setQuestionType(QuestionsList.INPUT_BOX.getCode());
                    questionBo.setQuestionChildType(QuestionsList.CALCULATED.getCode());
                }

                if (question.containsKey("text")) {
                    questionBo.setTitle(question.getString("text"));
                } else if (question.containsKey("title")) {
                    questionBo.setTitle(question.getString("title"));
                }

                questionBo.setRequired(Boolean.FALSE);

            } else if (StrUtil.isBlank(type) && question.containsKey("question_text")) {
                SysScreeningAssessmentQuestionBo questionBo = new SysScreeningAssessmentQuestionBo();
                otherInfo.add(questionBo);

                if (question.containsKey("question_text")) {
                    questionBo.setTitle(question.getString("question_text"));
                }

                questionBo.setQId("Q" + i);
                setQId(questionBo, question);
                questionBo.setArrangement("2");
                questionBo.setQuestionType(QuestionsList.QUESTION_TYPE_SELECTION.getCode());
                questionBo.setQuestionChildType(QuestionsList.SINGLE_CHOICE.getCode());
                questionBo.setRequired(Boolean.TRUE);

                JSONArray options = question.getJSONArray("options");
                List<SysScreeningAssessmentQuestionBo.QuestionAttrBo> contentList = CollUtil.newArrayList();
                for (int j = 0, len2 = options.size(); j < len2; j++) {
                    SysScreeningAssessmentQuestionBo.QuestionAttrBo questionAttrBo = new SysScreeningAssessmentQuestionBo.QuestionAttrBo();
                    JSONObject op = options.getJSONObject(j);
                    questionAttrBo.setLabel(op.getString("input_text"));
                    questionAttrBo.setScore(op.getString("score"));
                    questionAttrBo.setNameEn("single" + j);
                    String inputType = op.getString("input_type");
                    questionAttrBo.setAllowFillBlank(StrUtil.isNotBlank(inputType) && "input_text".equalsIgnoreCase(inputType));
                    contentList.add(questionAttrBo);
                }
                questionBo.setContentList(contentList);
                questionBo.setContent(JSON.toJSONString(contentList));
            }
        }

        insertByBo(config);
        return R.ok("导入成功");
    }
}
