GoodsAttachedMapper.xml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. <result property="doQuestionNum" column="do_question_num"/>
  30. <result property="recordStatus" column="record_status"/>
  31. <result property="recordId" column="record_id"/>
  32. <result property="doType" column="do_type"/>
  33. <result property="doNum" column="do_num"/>
  34. <result property="answerNum" column="answer_num"/>
  35. </resultMap>
  36. <select id="getList" parameterType="com.zhongzheng.modules.goods.bo.GoodsAttachedQueryBo" resultMap="GoodsAttachedResultVo">
  37. SELECT
  38. ga.*,
  39. CASE
  40. WHEN ga.type = 1 THEN
  41. 0
  42. WHEN ga.type = 2 THEN
  43. 0
  44. WHEN ga.type = 3 THEN
  45. e.do_type
  46. END do_type,
  47. CASE
  48. WHEN ga.type = 1 THEN
  49. qm.module_name
  50. WHEN ga.type = 2 THEN
  51. qc.`name`
  52. WHEN ga.type = 3 THEN
  53. e.exam_name
  54. END NAME,
  55. CASE
  56. WHEN ga.type = 1 THEN
  57. cs.subject_name
  58. WHEN ga.type = 2 THEN
  59. cs1.subject_name
  60. WHEN ga.type = 3 THEN
  61. cs2.subject_name
  62. END subject_name,
  63. CASE
  64. WHEN ga.type = 1 THEN
  65. 0
  66. WHEN ga.type = 2 THEN
  67. 0
  68. WHEN ga.type = 3 THEN
  69. e.question_num
  70. END question_num,
  71. CASE
  72. WHEN ga.type = 1 THEN
  73. qm.publish_status
  74. WHEN ga.type = 2 THEN
  75. qc.publish_status
  76. WHEN ga.type = 3 THEN
  77. e.publish_status
  78. END publish_status
  79. <if test="userId != null ">
  80. ,
  81. CASE
  82. WHEN ga.type = 1 THEN
  83. -1
  84. WHEN ga.type = 2 THEN
  85. -1
  86. WHEN ga.type = 3 THEN
  87. ifnull( (select `status` from user_exam_record uer where uer.exam_id = ga.major_id and uer.user_id = #{userId} and uer.order_goods_id = #{orderGoodsId} and ga.goods_id =uer.goods_id ORDER BY uer.record_id desc limit 1),-1)
  88. END record_status
  89. ,
  90. CASE
  91. WHEN ga.type = 1 THEN
  92. -1
  93. WHEN ga.type = 2 THEN
  94. -1
  95. WHEN ga.type = 3 THEN
  96. ifnull( (select record_id from user_exam_record uer where uer.exam_id = ga.major_id and uer.user_id = #{userId} and uer.order_goods_id = #{orderGoodsId} and ga.goods_id =uer.goods_id ORDER BY uer.record_id desc limit 1),-1)
  97. END record_id
  98. ,
  99. CASE
  100. WHEN ga.type = 1 THEN
  101. -1
  102. WHEN ga.type = 2 THEN
  103. -1
  104. WHEN ga.type = 3 THEN
  105. e.answer_num
  106. END answer_num
  107. ,
  108. CASE
  109. WHEN ga.type = 1 THEN
  110. -1
  111. WHEN ga.type = 2 THEN
  112. -1
  113. WHEN ga.type = 3 THEN
  114. (select count(*) from user_exam_record uer where uer.exam_id = ga.major_id and uer.user_id = #{userId} and uer.order_goods_id = #{orderGoodsId} and ga.goods_id =uer.goods_id )
  115. END do_num
  116. ,
  117. CASE
  118. WHEN ga.type = 1 THEN
  119. -1
  120. WHEN ga.type = 2 THEN
  121. -1
  122. WHEN ga.type = 3 THEN
  123. (select do_question_num from user_exam_record uer where uer.exam_id = ga.major_id and uer.user_id = #{userId} and uer.order_goods_id = #{orderGoodsId} and uer.chapter_exam_id = 0 and uer.module_exam_id = 0 ORDER BY uer.record_id desc limit 1)
  124. END do_question_num
  125. ,
  126. CASE
  127. WHEN ga.type = 1 THEN
  128. -1
  129. WHEN ga.type = 2 THEN
  130. -1
  131. WHEN ga.type = 3 THEN
  132. (select right_question_num from user_exam_record uer where uer.exam_id = ga.major_id and uer.user_id = #{userId} and uer.order_goods_id = #{orderGoodsId} and uer.chapter_exam_id = 0 and uer.module_exam_id = 0 ORDER BY uer.record_id desc limit 1)
  133. END right_question_num
  134. </if>
  135. FROM
  136. goods_attached ga
  137. LEFT JOIN question_module qm ON ga.major_id = qm.module_exam_id
  138. AND ga.type = 1
  139. LEFT JOIN question_business qb ON qb.major_id = qm.module_exam_id
  140. AND qb.type = 4
  141. LEFT JOIN course_subject cs ON qb.subject_id = cs.id
  142. LEFT JOIN question_chapter qc ON ga.major_id = qc.chapter_exam_id
  143. AND ga.type = 2
  144. LEFT JOIN question_business qb1 ON qb1.major_id = qc.chapter_exam_id
  145. AND qb1.type = 3
  146. LEFT JOIN course_subject cs1 ON qb1.subject_id = cs1.id
  147. LEFT JOIN (
  148. SELECT
  149. e.*,
  150. count( eq.question_id ) question_num
  151. FROM
  152. exam e
  153. LEFT JOIN exam_question eq ON e.exam_id = eq.exam_id
  154. GROUP BY
  155. e.exam_id
  156. ) e ON ga.major_id = e.exam_id
  157. AND ga.type = 3
  158. AND e.STATUS = 1
  159. LEFT JOIN question_business qb2 ON qb2.major_id = e.exam_id
  160. AND qb2.type = 2
  161. LEFT JOIN course_subject cs2 ON qb2.subject_id = cs2.id
  162. WHERE
  163. ga.goods_id = #{goodsId}
  164. order by ga.sort,ga.id asc
  165. </select>
  166. <select id="selectDoList" parameterType="com.zhongzheng.modules.goods.bo.GoodsAttachedQueryBo" resultMap="GoodsAttachedResultVo">
  167. SELECT
  168. ga.*,
  169. CASE
  170. WHEN ga.type = 1 THEN
  171. qm.module_name
  172. WHEN ga.type = 2 THEN
  173. qc.`name`
  174. WHEN ga.type = 3 THEN
  175. e.exam_name
  176. END NAME,
  177. CASE
  178. WHEN ga.type = 1 THEN
  179. cs.subject_name
  180. WHEN ga.type = 2 THEN
  181. cs1.subject_name
  182. WHEN ga.type = 3 THEN
  183. cs2.subject_name
  184. END subject_name,
  185. CASE
  186. WHEN ga.type = 1 THEN
  187. 0
  188. WHEN ga.type = 2 THEN
  189. 0
  190. WHEN ga.type = 3 THEN
  191. e.question_num
  192. END question_num,
  193. CASE
  194. WHEN ga.type = 1 THEN
  195. qm.publish_status
  196. WHEN ga.type = 2 THEN
  197. qc.publish_status
  198. WHEN ga.type = 3 THEN
  199. e.publish_status
  200. END publish_status,
  201. CASE
  202. WHEN ga.type = 1 THEN
  203. 0
  204. WHEN ga.type = 2 THEN
  205. 0
  206. WHEN ga.type = 3 THEN
  207. uer.record_id
  208. END record_id,
  209. CASE
  210. WHEN ga.type = 1 THEN
  211. 0
  212. WHEN ga.type = 2 THEN
  213. 0
  214. WHEN ga.type = 3 THEN
  215. uer.status
  216. END record_status,
  217. uer.total_question_num,
  218. uer.right_question_num,
  219. uer.do_question_num
  220. FROM
  221. goods_attached ga
  222. LEFT JOIN question_module qm ON ga.major_id = qm.module_exam_id
  223. AND ga.type = 1
  224. LEFT JOIN question_business qb ON qb.major_id = qm.module_exam_id
  225. AND qb.type = 4
  226. LEFT JOIN course_subject cs ON qb.subject_id = cs.id
  227. LEFT JOIN question_chapter qc ON ga.major_id = qc.chapter_exam_id
  228. AND ga.type = 2
  229. LEFT JOIN question_business qb1 ON qb1.major_id = qc.chapter_exam_id
  230. AND qb1.type = 3
  231. LEFT JOIN course_subject cs1 ON qb1.subject_id = cs1.id
  232. LEFT JOIN (
  233. SELECT
  234. e.*,
  235. count( eq.question_id ) question_num
  236. FROM
  237. exam e
  238. LEFT JOIN exam_question eq ON e.exam_id = eq.exam_id
  239. GROUP BY
  240. e.exam_id
  241. ) e ON ga.major_id = e.exam_id
  242. AND ga.type = 3
  243. AND e.STATUS = 1
  244. LEFT JOIN question_business qb2 ON qb2.major_id = e.exam_id
  245. AND qb2.type = 2
  246. LEFT JOIN course_subject cs2 ON qb2.subject_id = cs2.id
  247. LEFT JOIN (SELECT
  248. record_id,
  249. `status`,
  250. exam_id,
  251. total_question_num,
  252. right_question_num,
  253. do_question_num
  254. FROM
  255. user_exam_record
  256. WHERE
  257. record_id IN (
  258. SELECT
  259. MAX( record_id ) record_id
  260. FROM
  261. user_exam_record
  262. WHERE
  263. user_id = #{userId}
  264. AND order_goods_id = #{orderGoodsId}
  265. GROUP BY
  266. exam_id)) uer on uer.exam_id = e.exam_id
  267. WHERE
  268. ga.goods_id = #{goodsId}
  269. AND ((
  270. ga.type = 3
  271. AND ga.major_id IN ( SELECT exam_id FROM user_exam_record WHERE user_id = #{userId} AND order_goods_id = #{orderGoodsId} AND module_exam_id = 0 AND chapter_exam_id = 0 GROUP BY exam_id )
  272. AND e.STATUS = 1
  273. )
  274. OR (
  275. ga.type = 2
  276. AND ga.major_id IN ( SELECT chapter_exam_id FROM user_exam_record WHERE user_id = #{userId} AND order_goods_id = #{orderGoodsId} AND module_exam_id = 0 AND chapter_exam_id > 0 GROUP BY chapter_exam_id ))
  277. OR (
  278. ga.type = 1
  279. AND ga.major_id IN ( SELECT module_exam_id FROM user_exam_record WHERE user_id = #{userId} AND order_goods_id = #{orderGoodsId} AND module_exam_id > 0 GROUP BY module_exam_id )))
  280. </select>
  281. </mapper>