<?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.IntroduceInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.diagbot.entity.IntroduceInfo">
        <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="name" property="name" />
        <result column="remark" property="remark" />
    </resultMap>

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMapDTO" type="com.diagbot.dto.IntroducePageDTO">
        <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="name" property="name" />
        <result column="remark" property="remark" />
        <result column="tag_name" property="tagName" />
    </resultMap>

    <!-- 分页查询 -->
    <select id="getIntroducePage" resultMap="BaseResultMapDTO">
    SELECT info.*, t.tag_name FROM icss_introduce_info info,
	    (SELECT tt.introduce_id,GROUP_CONCAT(tt.tag_name) AS tag_name
		    FROM
			(
				SELECT
					a.introduce_id,
					b.tag_name,
					b.id
				FROM
					icss_introduce_map a,
					icss_question_info b
				WHERE
					a.question_id = b.id
				AND a.type = b.type
			) tt
		    GROUP BY tt.introduce_id
	    ) t
    WHERE info.id = t.introduce_id
	<if test="introducePageVO.name != null and introducePageVO.name != '' ">
	    and info.name like concat('%',#{introducePageVO.name},'%')
    </if>
    <if test="introducePageVO.tagName != null and introducePageVO.tagName != '' ">
        and t.tag_name like concat('%',#{introducePageVO.tagName},'%')
    </if>
    </select>
</mapper>
