GoodsAttachedMapper.xml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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="selectList" 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. </if>
  117. FROM
  118. goods_attached ga
  119. LEFT JOIN question_module qm ON ga.major_id = qm.module_exam_id
  120. AND ga.type = 1
  121. LEFT JOIN question_business qb ON qb.major_id = qm.module_exam_id
  122. AND qb.type = 4
  123. LEFT JOIN course_subject cs ON qb.subject_id = cs.id
  124. LEFT JOIN question_chapter qc ON ga.major_id = qc.chapter_exam_id
  125. AND ga.type = 2
  126. LEFT JOIN question_business qb1 ON qb1.major_id = qc.chapter_exam_id
  127. AND qb1.type = 3
  128. LEFT JOIN course_subject cs1 ON qb1.subject_id = cs1.id
  129. LEFT JOIN (
  130. SELECT
  131. e.*,
  132. count( eq.question_id ) question_num
  133. FROM
  134. exam e
  135. LEFT JOIN exam_question eq ON e.exam_id = eq.exam_id
  136. GROUP BY
  137. e.exam_id
  138. ) e ON ga.major_id = e.exam_id
  139. AND ga.type = 3
  140. AND e.STATUS = 1
  141. LEFT JOIN question_business qb2 ON qb2.major_id = e.exam_id
  142. AND qb2.type = 2
  143. LEFT JOIN course_subject cs2 ON qb2.subject_id = cs2.id
  144. WHERE
  145. ga.goods_id = #{goodsId}
  146. order by ga.sort,ga.id asc
  147. </select>
  148. <select id="selectDoList" parameterType="com.zhongzheng.modules.goods.bo.GoodsAttachedQueryBo" resultMap="GoodsAttachedResultVo">
  149. SELECT
  150. ga.*,
  151. CASE
  152. WHEN ga.type = 1 THEN
  153. qm.module_name
  154. WHEN ga.type = 2 THEN
  155. qc.`name`
  156. WHEN ga.type = 3 THEN
  157. e.exam_name
  158. END NAME,
  159. CASE
  160. WHEN ga.type = 1 THEN
  161. cs.subject_name
  162. WHEN ga.type = 2 THEN
  163. cs1.subject_name
  164. WHEN ga.type = 3 THEN
  165. cs2.subject_name
  166. END subject_name,
  167. CASE
  168. WHEN ga.type = 1 THEN
  169. 0
  170. WHEN ga.type = 2 THEN
  171. 0
  172. WHEN ga.type = 3 THEN
  173. e.question_num
  174. END question_num,
  175. CASE
  176. WHEN ga.type = 1 THEN
  177. qm.publish_status
  178. WHEN ga.type = 2 THEN
  179. qc.publish_status
  180. WHEN ga.type = 3 THEN
  181. e.publish_status
  182. END publish_status,
  183. CASE
  184. WHEN ga.type = 1 THEN
  185. 0
  186. WHEN ga.type = 2 THEN
  187. 0
  188. WHEN ga.type = 3 THEN
  189. uer.record_id
  190. END record_id,
  191. CASE
  192. WHEN ga.type = 1 THEN
  193. 0
  194. WHEN ga.type = 2 THEN
  195. 0
  196. WHEN ga.type = 3 THEN
  197. uer.status
  198. END record_status,
  199. uer.total_question_num,
  200. uer.right_question_num,
  201. uer.do_question_num
  202. FROM
  203. goods_attached ga
  204. LEFT JOIN question_module qm ON ga.major_id = qm.module_exam_id
  205. AND ga.type = 1
  206. LEFT JOIN question_business qb ON qb.major_id = qm.module_exam_id
  207. AND qb.type = 4
  208. LEFT JOIN course_subject cs ON qb.subject_id = cs.id
  209. LEFT JOIN question_chapter qc ON ga.major_id = qc.chapter_exam_id
  210. AND ga.type = 2
  211. LEFT JOIN question_business qb1 ON qb1.major_id = qc.chapter_exam_id
  212. AND qb1.type = 3
  213. LEFT JOIN course_subject cs1 ON qb1.subject_id = cs1.id
  214. LEFT JOIN (
  215. SELECT
  216. e.*,
  217. count( eq.question_id ) question_num
  218. FROM
  219. exam e
  220. LEFT JOIN exam_question eq ON e.exam_id = eq.exam_id
  221. GROUP BY
  222. e.exam_id
  223. ) e ON ga.major_id = e.exam_id
  224. AND ga.type = 3
  225. AND e.STATUS = 1
  226. LEFT JOIN question_business qb2 ON qb2.major_id = e.exam_id
  227. AND qb2.type = 2
  228. LEFT JOIN course_subject cs2 ON qb2.subject_id = cs2.id
  229. LEFT JOIN (SELECT
  230. record_id,
  231. `status`,
  232. exam_id,
  233. total_question_num,
  234. right_question_num,
  235. do_question_num
  236. FROM
  237. user_exam_record
  238. WHERE
  239. record_id IN (
  240. SELECT
  241. MAX( record_id ) record_id
  242. FROM
  243. user_exam_record
  244. WHERE
  245. user_id = #{userId}
  246. AND goods_id = #{goodsId}
  247. GROUP BY
  248. exam_id)) uer on uer.exam_id = e.exam_id
  249. WHERE
  250. ga.goods_id = #{goodsId}
  251. AND ((
  252. ga.type = 3
  253. 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 )
  254. AND e.STATUS = 1
  255. )
  256. OR (
  257. ga.type = 2
  258. 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 ))
  259. OR (
  260. ga.type = 1
  261. 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 )))
  262. </select>
  263. </mapper>