<?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.miaxis.topic.mapper.TopicInfoMapper">

    <resultMap type="TopicInfo" id="TopicInfoResult">
        <result property="id"    column="id"    />
        <result property="topicName"    column="topic_name"    />
        <result property="topicIllustration"    column="topic_illustration"    />
        <result property="sharingStatus"    column="sharing_status"    />
        <result property="sharingNumberStatus"    column="sharing_number_status"    />
        <result property="commentStatus"    column="comment_status"    />
        <result property="commentNumberStatus"    column="comment_number_status"    />
        <result property="collectionNumberStatus"    column="collection_number_status"    />
        <result property="topicContent"    column="topic_content"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="shelfStatus"    column="shelf_status"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectTopicInfoVo">
        select id, topic_name, topic_illustration, sharing_status, sharing_number_status, comment_status, comment_number_status, collection_number_status, topic_content, create_time, update_time, shelf_status,status from topic_info
    </sql>

    <select id="selectTopicInfoList" resultType="com.miaxis.topic.vo.TopicInfoVo">
        select
        ti.id,
        ti.topic_name,
        ti.topic_illustration,
        ti.sharing_status,
        ti.sharing_number_status,
        ti.comment_status,
        ti.comment_number_status,
        ti.collection_number_status,
        ti.topic_content,
        ti.create_time,
        ti.update_time,
        ti.shelf_status,
        f.file_url as fileUrl,
        ti.status
        from topic_info ti
        LEFT JOIN file_info f on f.file_id = ti.topic_illustration
        <where>
            <if test="topicName != null  and topicName != ''"> and topic_name like concat('%', #{topicName}, '%')</if>
            <if test="topicIllustration != null "> and topic_illustration = #{topicIllustration}</if>
            <if test="sharingStatus != null "> and sharing_status = #{sharingStatus}</if>
            <if test="sharingNumberStatus != null "> and sharing_number_status = #{sharingNumberStatus}</if>
            <if test="commentStatus != null "> and comment_status = #{commentStatus}</if>
            <if test="commentNumberStatus != null "> and comment_number_status = #{commentNumberStatus}</if>
            <if test="collectionNumberStatus != null "> and collection_number_status = #{collectionNumberStatus}</if>
            <if test="topicContent != null  and topicContent != ''"> and topic_content = #{topicContent}</if>
            <if test="shelfStatus != null "> and shelf_status = #{shelfStatus}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>

    <!--获取专题详情信息-->
    <select id="getTopicDetailsById" resultType="com.miaxis.topic.vo.TopicInfoVo">
        select
        ti.id,
        ti.topic_name,
        ti.topic_illustration,
        ti.sharing_status,
        ti.sharing_number_status,
        ti.comment_status,
        ti.comment_number_status,
        ti.collection_number_status,
        ti.topic_content,
        ti.create_time,
        ti.update_time,
        ti.shelf_status,
        f.file_url as fileUrl,
        ti.status
        from topic_info ti
        LEFT JOIN file_info f on f.file_id = ti.topic_illustration
        WHERE ti.id = #{id}
    </select>

</mapper>
