QuMapper.xml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.ydl.exam.modules.qu.mapper.QuMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.ydl.exam.modules.qu.entity.Qu">
  6. <id column="id" property="id" />
  7. <result column="qu_type" property="quType" />
  8. <result column="level" property="level" />
  9. <result column="image" property="image" />
  10. <result column="content" property="content" />
  11. <result column="create_time" property="createTime" />
  12. <result column="update_time" property="updateTime" />
  13. <result column="remark" property="remark" />
  14. <result column="analysis" property="analysis" />
  15. </resultMap>
  16. <!-- 通用查询结果列 -->
  17. <sql id="Base_Column_List">
  18. `id`,`qu_type`,`level`,`image`,`content`,`create_time`,`update_time`,`remark`,`analysis`
  19. </sql>
  20. <!-- 随机取数据 -->
  21. <select id="listByRandom" resultMap="BaseResultMap">
  22. SELECT a.*
  23. FROM el_qu a
  24. LEFT JOIN el_qu_repo b ON a.id=b.qu_id
  25. WHERE b.repo_id=#{repoId} AND a.qu_type=#{quType}
  26. <if test="excludes!=null">
  27. AND a.id NOT IN
  28. <foreach item="item" collection="excludes" separator="," open="(" close=")" index="">'${item}'</foreach>
  29. </if>
  30. <if test="level!=null and level>0">
  31. AND a.`level`=#{level}
  32. </if>
  33. ORDER BY RAND()
  34. LIMIT ${size}
  35. </select>
  36. <resultMap id="ExportResultMap" type="com.ydl.exam.modules.qu.dto.export.QuExportDTO">
  37. <id column="q_id" property="qId" />
  38. <result column="qu_type" property="quType" />
  39. <result column="q_content" property="qContent" />
  40. <result column="q_analysis" property="qAnalysis" />
  41. <result column="a_is_right" property="aIsRight" />
  42. <result column="a_content" property="aContent" />
  43. <result column="a_analysis" property="aAnalysis" />
  44. <collection property="repoList" column="q_id" select="selectRepos"/>
  45. </resultMap>
  46. <select id="selectRepos" resultType="String">
  47. SELECT repo_id FROM el_qu_repo po WHERE po.qu_id=#{qId}
  48. </select>
  49. <sql id="query">
  50. <where>
  51. <if test="query!=null">
  52. <if test="query.quType!=null">
  53. AND q.qu_type = #{query.quType}
  54. </if>
  55. <if test="query.repoIds!=null and query.repoIds.size()>0">
  56. AND po.repo_id IN
  57. <foreach collection="query.repoIds" open="(" close=")" separator="," item="repoId">#{repoId}</foreach>
  58. </if>
  59. <if test="query.content!=null and query.content!=''">
  60. AND q.content LIKE '%${query.content}%'
  61. </if>
  62. <if test="query.excludes!=null and query.excludes.size()>0">
  63. AND q.id NOT IN
  64. <foreach collection="query.excludes" open="(" close=")" separator="," item="quId">
  65. #{quId}
  66. </foreach>
  67. </if>
  68. </if>
  69. </where>
  70. </sql>
  71. <select id="paging" resultMap="BaseResultMap">
  72. SELECT q.*
  73. FROM el_qu q
  74. LEFT JOIN el_qu_repo po ON q.id=po.qu_id
  75. <include refid="query" />
  76. GROUP BY q.id ORDER BY q.update_time DESC
  77. </select>
  78. <select id="listForExport" resultMap="ExportResultMap">
  79. SELECT
  80. q.id as q_id,
  81. q.qu_type,
  82. q.content AS q_content,
  83. q.analysis as q_analysis,
  84. a.content as a_content,
  85. a.is_right as a_is_right,
  86. a.analysis as a_analysis
  87. FROM el_qu q
  88. LEFT JOIN el_qu_answer a ON q.id=a.qu_id
  89. LEFT JOIN el_qu_repo po ON q.id=po.qu_id
  90. <include refid="query" />
  91. GROUP BY a.id ORDER BY q.id
  92. LIMIT 10000
  93. </select>
  94. </mapper>