<?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.xxfc.platform.im.mapper.ImQuestionMapper">


    <resultMap id="listResultMap" type="com.xxfc.platform.im.vo.QuestionListVo">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <collection property="imComment" column="id"
                    select="com.xxfc.platform.im.mapper.ImCommentMapper.selectByQuestionId"
                    ofType="com.xxfc.platform.im.entity.ImComment">
        </collection>

        <collection column="id" property="imPraise"
                    select="com.xxfc.platform.im.mapper.ImPraiseMapper.selectByQuestionId"
                    ofType="com.xxfc.platform.im.entity.ImPraise"></collection>
    </resultMap>
    <select id="getQuestionList" parameterType="java.util.Map" resultMap="listResultMap">
        select * from im_question
        <where>
            <if test="userId != null">
                and user_id = #{userId}
            </if>
            <if test="source != null">
                and source = #{source}
            </if>
            <if test="praiseCount != null">
                and praise_count &gt;= #{source}
            </if>
            <if test="commentCount != null">
                and comment_count &gt;= #{commentCount}
            </if>
            <if test="visible != null">
                and visible = #{visible}
            </if>
            <if test="startTime != null">
                and time &gt;= #{startTime} and time &lt;= #{endTime}
            </if>
            <if test="state != null">
                and state = #{state}
            </if>
                and is_del = 0
        </where>
        order by  upd_time DESC
    </select>

    <select id="getOne" parameterType="java.lang.Integer" resultMap="listResultMap">
        select * from im_question
        where id = #{id}
    </select>

</mapper>