<?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.question.mapper.QuestionCollectionMapper">

    <resultMap type="QuestionCollection" id="QuestionCollectionResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="questionId"    column="question_id"    />
        <result property="deviceType"    column="device_type"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectQuestionCollectionVo">
        select * from question_collection
    </sql>

    <select id="selectQuestionCollectionList"  parameterType="QuestionCollectionListDTO" resultMap="QuestionCollectionResult">
        <include refid="selectQuestionCollectionVo"/>
        <where>
            <if test="userId != null and userId !='' "> and user_id = #{userId}</if>
            <if test="km != null and km !='' "> and km = #{km}</if>
        </where>
        order by create_time asc
    </select>




    <select id="selectCollectionIdByUserId" resultType="com.miaxis.question.vo.QuestionColIdDateVo">

        select q1.id,q2.create_time from question_info q1 join question_collection q2 on q1.id = q2.question_id
        <where>
            <if test="userId != null and userId !='' "> and q2.user_id = #{userId}</if>
            <if test="km != null and km!='' "> and q2.km = #{km}</if>
        </where>
        order by q2.create_time asc

    </select>



    <select id="selectCollectionCountByUserId" resultType="java.lang.Integer">

        select count(1) from question_info q1 join question_collection q2 on q1.id = q2.question_id
        <where>
            <if test="userId != null and userId !='' "> and q2.user_id = #{userId}</if>
            <if test="km != null and km!='' "> and q2.km = #{km}</if>
        </where>

    </select>


</mapper>
