<?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.diagbot.mapper.QcQuestionInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.diagbot.entity.QcQuestionInfo">
        <id column="id" property="id" />
        <result column="is_deleted" property="isDeleted" />
        <result column="gmt_create" property="gmtCreate" />
        <result column="gmt_modified" property="gmtModified" />
        <result column="creator" property="creator" />
        <result column="modifier" property="modifier" />
        <result column="hospital_id" property="hospitalId" />
        <result column="mode_id" property="modeId" />
        <result column="tag_name" property="tagName" />
        <result column="name" property="name" />
        <result column="val" property="val" />
        <result column="tag_type" property="tagType" />
        <result column="control_type" property="controlType" />
        <result column="retract" property="retract" />
        <result column="add_line" property="addLine" />
        <result column="mono_line" property="monoLine" />
        <result column="bold" property="bold" />
        <result column="cases_entry_ids" property="casesEntryIds" />
        <result column="remark" property="remark" />
    </resultMap>


    <select id="getByQuestionMapping" parameterType="java.util.Map" resultType="com.diagbot.entity.wrapper.QuestionInfoWrapper">
        select t.*, m.parent_question from qc_question_info t, qc_question_mapping m
        where t.is_deleted = 'N' and m.is_deleted = 'N' and m.son_question = t.id
        <if test="id != null">
            and m.parent_question = #{id}
        </if>
        <if test="ids != null and ids.size > 0">
            <foreach item="myId" collection="ids" open="and(" separator="or" close=")" >
                m.parent_question = #{myId}
            </foreach>
        </if>
        <if test="id != null">
            order by m.order_no
        </if>
        <if test="ids != null and ids.size > 0">
            order by m.parent_question, m.order_no
        </if>
    </select>

    <select id="getByCaseEntryIds" resultType="com.diagbot.dto.QuestionEntryDTO">
        SELECT q2.question_id id, q2.cases_entry_id FROM qc_question_info q1, qc_question_entry q2
        where q1.is_deleted = 'N' and q2.is_deleted = 'N' and q1.id = q2.question_id
        <if test="hospitalId != null">
            AND q1.hospital_id = #{hospitalId}
        </if>
        <if test="casesEntryIds != null and casesEntryIds.size > 0">
            and q2.cases_entry_id in
            <foreach  collection="casesEntryIds" item="item" open="("  separator=","  close=")">
                #{item}
            </foreach>
        </if>
    </select>
</mapper>
