<?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.qxgmat.data.relation.UserNoteQuestionRelationMapper">
  <resultMap id="IdMap" type="com.qxgmat.data.dao.entity.UserNoteQuestion">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="INTEGER" property="id" />
  </resultMap>
  <sql id="Id_Column_List">
    <!--
      WARNING - @mbg.generated
    -->
    up.`id`
  </sql>

  <!--
    用户预习作业列表: 后台
    https://blog.csdn.net/t_1007/article/details/52369261
  -->
  <select id="list" resultMap="IdMap">
    select
    <include refid="Id_Column_List" />
    from `user_paper` up
    left join `homework_preview` hp on hp.`id` = up.`module_id`
      and up.`module` = "homework_preview"
      <if test="previewId != null">
        and hp.`id` = #{previewId,jdbcType=VARCHAR}
      </if>
      <if test="category != null">
        and hp.`category` = #{category,jdbcType=VARCHAR}
      </if>
    where
    hp.`id` != null
    <if test="userId != null">
      and up.`user_id` = #{userId,jdbcType=VARCHAR}
    </if>
    <if test="startTime != null">
      and up.`createTime` &gt; #{startTime,jdbcType=VARCHAR}
    </if>
    <if test="endTime != null">
      and up.`createTime` &lt; #{endTime,jdbcType=VARCHAR}
    </if>
  </select>

</mapper>