GoodsAttachedMapper.xml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.zhongzheng.modules.goods.mapper.GoodsAttachedMapper">
  6. <resultMap type="com.zhongzheng.modules.goods.domain.GoodsAttached" id="GoodsAttachedResult">
  7. <result property="id" column="id"/>
  8. <result property="goodsId" column="goods_id"/>
  9. <result property="majorId" column="major_id"/>
  10. <result property="sort" column="sort"/>
  11. <result property="type" column="type"/>
  12. <result property="createTime" column="create_time"/>
  13. <result property="updateTime" column="update_time"/>
  14. </resultMap>
  15. <resultMap type="com.zhongzheng.modules.goods.vo.GoodsAttachedVo" id="GoodsAttachedResultVo">
  16. <result property="id" column="id"/>
  17. <result property="goodsId" column="goods_id"/>
  18. <result property="majorId" column="major_id"/>
  19. <result property="sort" column="sort"/>
  20. <result property="type" column="type"/>
  21. <result property="name" column="name"/>
  22. <result property="subjectName" column="subject_name"/>
  23. <result property="questionNum" column="question_num"/>
  24. <result property="recordId" column="record_id"/>
  25. <result property="recordStatus" column="record_status"/>
  26. <result property="totalScore" column="total_score"/>
  27. <result property="totalQuestionNum" column="total_question_num"/>
  28. <result property="rightQuestionNum" column="right_question_num"/>
  29. </resultMap>
  30. <select id="selectList" parameterType="com.zhongzheng.modules.goods.bo.GoodsAttachedQueryBo" resultMap="GoodsAttachedResultVo">
  31. SELECT
  32. ga.*,
  33. CASE
  34. WHEN ga.type = 1 THEN
  35. qm.module_name
  36. WHEN ga.type = 2 THEN
  37. qc.`name`
  38. WHEN ga.type = 3 THEN
  39. e.exam_name
  40. END NAME,
  41. CASE
  42. WHEN ga.type = 1 THEN
  43. cs.subject_name
  44. WHEN ga.type = 2 THEN
  45. cs1.subject_name
  46. WHEN ga.type = 3 THEN
  47. cs2.subject_name
  48. END subject_name,
  49. CASE
  50. WHEN ga.type = 1 THEN
  51. 0
  52. WHEN ga.type = 2 THEN
  53. 0
  54. WHEN ga.type = 3 THEN
  55. e.question_num
  56. END question_num,
  57. CASE
  58. WHEN ga.type = 1 THEN
  59. qm.publish_status
  60. WHEN ga.type = 2 THEN
  61. qc.publish_status
  62. WHEN ga.type = 3 THEN
  63. e.publish_status
  64. END publish_status
  65. FROM
  66. goods_attached ga
  67. LEFT JOIN question_module qm ON ga.major_id = qm.module_exam_id
  68. AND ga.type = 1
  69. LEFT JOIN question_business qb ON qb.major_id = qm.module_exam_id
  70. AND qb.type = 4
  71. LEFT JOIN course_subject cs ON qb.subject_id = cs.id
  72. LEFT JOIN question_chapter qc ON ga.major_id = qc.chapter_exam_id
  73. AND ga.type = 2
  74. LEFT JOIN question_business qb1 ON qb1.major_id = qc.chapter_exam_id
  75. AND qb1.type = 3
  76. LEFT JOIN course_subject cs1 ON qb1.subject_id = cs1.id
  77. LEFT JOIN (
  78. SELECT
  79. e.*,
  80. count( eq.question_id ) question_num
  81. FROM
  82. exam e
  83. LEFT JOIN exam_question eq ON e.exam_id = eq.exam_id
  84. GROUP BY
  85. e.exam_id
  86. ) e ON ga.major_id = e.exam_id
  87. AND ga.type = 3
  88. AND e.STATUS = 1
  89. LEFT JOIN question_business qb2 ON qb2.major_id = e.exam_id
  90. AND qb2.type = 2
  91. LEFT JOIN course_subject cs2 ON qb2.subject_id = cs2.id
  92. WHERE
  93. ga.goods_id = #{goodsId}
  94. </select>
  95. <select id="selectDoList" parameterType="com.zhongzheng.modules.goods.bo.GoodsAttachedQueryBo" resultMap="GoodsAttachedResultVo">
  96. SELECT
  97. ga.*,
  98. CASE
  99. WHEN ga.type = 1 THEN
  100. qm.module_name
  101. WHEN ga.type = 2 THEN
  102. qc.`name`
  103. WHEN ga.type = 3 THEN
  104. e.exam_name
  105. END NAME,
  106. CASE
  107. WHEN ga.type = 1 THEN
  108. cs.subject_name
  109. WHEN ga.type = 2 THEN
  110. cs1.subject_name
  111. WHEN ga.type = 3 THEN
  112. cs2.subject_name
  113. END subject_name,
  114. CASE
  115. WHEN ga.type = 1 THEN
  116. 0
  117. WHEN ga.type = 2 THEN
  118. 0
  119. WHEN ga.type = 3 THEN
  120. e.question_num
  121. END question_num,
  122. CASE
  123. WHEN ga.type = 1 THEN
  124. qm.publish_status
  125. WHEN ga.type = 2 THEN
  126. qc.publish_status
  127. WHEN ga.type = 3 THEN
  128. e.publish_status
  129. END publish_status,
  130. CASE
  131. WHEN ga.type = 1 THEN
  132. 0
  133. WHEN ga.type = 2 THEN
  134. 0
  135. WHEN ga.type = 3 THEN
  136. uer.record_id
  137. END record_id,
  138. CASE
  139. WHEN ga.type = 1 THEN
  140. 0
  141. WHEN ga.type = 2 THEN
  142. 0
  143. WHEN ga.type = 3 THEN
  144. uer.status
  145. END record_status,
  146. uer.total_question_num,
  147. uer.right_question_num,
  148. uer.do_question_num
  149. FROM
  150. goods_attached ga
  151. LEFT JOIN question_module qm ON ga.major_id = qm.module_exam_id
  152. AND ga.type = 1
  153. LEFT JOIN question_business qb ON qb.major_id = qm.module_exam_id
  154. AND qb.type = 4
  155. LEFT JOIN course_subject cs ON qb.subject_id = cs.id
  156. LEFT JOIN question_chapter qc ON ga.major_id = qc.chapter_exam_id
  157. AND ga.type = 2
  158. LEFT JOIN question_business qb1 ON qb1.major_id = qc.chapter_exam_id
  159. AND qb1.type = 3
  160. LEFT JOIN course_subject cs1 ON qb1.subject_id = cs1.id
  161. LEFT JOIN (
  162. SELECT
  163. e.*,
  164. count( eq.question_id ) question_num
  165. FROM
  166. exam e
  167. LEFT JOIN exam_question eq ON e.exam_id = eq.exam_id
  168. GROUP BY
  169. e.exam_id
  170. ) e ON ga.major_id = e.exam_id
  171. AND ga.type = 3
  172. AND e.STATUS = 1
  173. LEFT JOIN question_business qb2 ON qb2.major_id = e.exam_id
  174. AND qb2.type = 2
  175. LEFT JOIN course_subject cs2 ON qb2.subject_id = cs2.id
  176. LEFT JOIN (SELECT
  177. record_id,
  178. `status`,
  179. exam_id,
  180. total_question_num,
  181. right_question_num,
  182. do_question_num
  183. FROM
  184. user_exam_record
  185. WHERE
  186. record_id IN (
  187. SELECT
  188. MAX( record_id ) record_id
  189. FROM
  190. user_exam_record
  191. WHERE
  192. user_id = #{userId}
  193. AND goods_id = #{goodsId}
  194. GROUP BY
  195. exam_id)) uer on uer.exam_id = e.exam_id
  196. WHERE
  197. ga.goods_id = #{goodsId}
  198. AND ((
  199. ga.type = 3
  200. AND ga.major_id IN ( SELECT exam_id FROM user_exam_record WHERE user_id = #{userId} AND goods_id = #{goodsId} AND module_exam_id = 0 AND chapter_exam_id = 0 GROUP BY exam_id )
  201. AND e.STATUS = 1
  202. )
  203. OR (
  204. ga.type = 2
  205. AND ga.major_id IN ( SELECT chapter_exam_id FROM user_exam_record WHERE user_id = #{userId} AND goods_id = #{goodsId} AND module_exam_id = 0 AND chapter_exam_id > 0 GROUP BY chapter_exam_id ))
  206. OR (
  207. ga.type = 1
  208. AND ga.major_id IN ( SELECT module_exam_id FROM user_exam_record WHERE user_id = #{userId} AND goods_id = #{goodsId} AND module_exam_id > 0 GROUP BY module_exam_id )))
  209. </select>
  210. </mapper>