<?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="BaseResultMap" type="com.xxfc.platform.im.entity.ImQuestion">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="title" jdbcType="VARCHAR" property="title"/>
        <result column="latitude" jdbcType="VARCHAR" property="latitude"/>
        <result column="longitude" jdbcType="VARCHAR" property="longitude"/>
        <result column="model" jdbcType="VARCHAR" property="model"/>
        <result column="time" jdbcType="BIGINT" property="time"/>
        <result column="user_id" jdbcType="BIGINT" property="userId"/>
        <result column="visible" jdbcType="INTEGER" property="visible"/>
        <result column="state" jdbcType="VARCHAR" property="state"/>
        <result column="is_del" jdbcType="BIT" property="isDel"/>
        <result column="content" jdbcType="LONGVARCHAR" property="content"/>
    </resultMap>

    <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="visible != null">
                and visible = #{visible}
            </if>
            <if test="state != null">
                and state = #{state}
            </if>
            <if test="isDel != null">
                and is_del = #{isDel}
            </if>
        </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>