<?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.ads.business.dao.DocTypeDao">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ads.business.entity.DocType">
        <id column="type_id" property="typeId" />
        <result column="name" property="name" />
        <result column="link_url" property="linkUrl" />
        <result column="status" property="status" />
        <result column="create_user" property="createUser" />
        <result column="create_time" property="createTime" />
        <result column="update_user" property="updateUser" />
        <result column="update_time" property="updateTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        type_id, name, link_url, status, create_user, create_time, update_user, update_time
    </sql>

    <select id="findPage" resultType="com.ads.business.service.model.response.DocTypeListResponse">
         select hdt.type_id typeId,
                hdt.name name,
                hdt.link_url linkUrl,
                hdt.status status,
                hu.name createUserName,
                hdt.create_time createTime
        from    hsay_doc_type hdt
        left JOIN hsay_user hu ON hu.user_id = hdt.create_user
        ${ew.customSqlSegment}
    </select>


     <resultMap id="getDropListMap" type="com.ads.business.service.model.response.DropListResponse">
        <id column="typeId" property="typeId" />
        <result column="name" property="name" />
        <result column="linkUrl" property="linkUrl" />
        <collection property="list" ofType="com.ads.business.service.model.response.ConversationTypeResponse" select="childB" column="typeId"/>
    </resultMap>

    <resultMap id="childB_map" type="com.ads.business.service.model.response.ConversationTypeResponse">
        <result column="chat_id" property="chatId" />
        <result column="open_conversation_id" property="openConversationId" />
    </resultMap>

     <select id="childB" resultMap="childB_map">
        select hdtcr.chat_id,
               hdtcr.open_conversation_id
        from   hsay_doc_type_conversation_rel hdtcr right join  hsay_conversation hc on hdtcr.chat_id = hc.chat_id and hc.status = 1
        where  type_id = #{typeId}
    </select>

    <select id="getDropList" resultMap="getDropListMap">
        select  hdt.type_id typeId,
                hdt.name,
                hdt.link_url linkUrl
        from    hsay_doc_type hdt
        where   1 = 1
        <if test="type == 1">
            and status = #{type,jdbcType=INTEGER}
        </if>
        order by create_time desc
    </select>

</mapper>
