<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.rongwei.trainingcommon.sys.dao.DemandSurveyContentDao">
    <resultMap type="com.rongwei.training.vo.TrainingDemandVo" id="trainingDemandMap">
        <result property="surverid" column="surverid"></result>
        <result property="contentid" column="contentid"></result>
        <result property="modelName" column="modelName" ></result>
        <result property="num" column="num" ></result>
        <result property="questionContent" column="questionContent" ></result>
        <result property="questionType" column="questionType" ></result>
        <result property="questionOptions" column="questionOptions" typeHandler="com.rongwei.trainingcommon.sys.utils.CustomerTypeHandler.ListStringToVarcharTypeHandlerUtil"></result>
        <result property="userAnswer" column="userAnswer" ></result>
    </resultMap>

    <select id="getSurveyContent" resultMap="trainingDemandMap">
        SELECT ifnull(dsc.TEMPNAME, 'customQuestion') AS modelName,
               dsc.NUM                                AS num,
               dsc.QUESTIONNAME                       AS questionContent,
               dsc.QUESTIONTYPE                       AS questionType,
               dsc.`OPTIONS`                          AS questionOptions,
               dsua.ANSWER                            AS userAnswer,
               dsc.ID                                 AS contentid,
               dsc.SURVERID                           AS surverid
        FROM `demand_survey_content` dsc
                 LEFT JOIN demand_survey_user_answer dsua
                           on dsc.ID = dsua.SURVERCONTENTID and dsc.SURVERID = dsua.SURVERID
                               and dsua.CREATEUSERID = #{userId}
        where dsc.SURVERID = #{surverId}
        order by NUM
    </select>
</mapper>
