GoodsAttachedMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. <result property="publishStatus" column="publish_status"/>
  36. <result property="code" column="code"/>
  37. <result property="paperName" column="paper_name"/>
  38. <result property="externalLink" column="external_link"/>
  39. </resultMap>
  40. <select id="getList" parameterType="com.zhongzheng.modules.goods.bo.GoodsAttachedQueryBo" resultMap="GoodsAttachedResultVo">
  41. SELECT
  42. g.external_link,
  43. ga.*,
  44. CASE
  45. WHEN ga.type = 1 THEN
  46. 0
  47. WHEN ga.type = 2 THEN
  48. 0
  49. WHEN ga.type = 3 THEN
  50. e.do_type
  51. END do_type,
  52. CASE
  53. WHEN ga.type = 1 THEN
  54. qm.module_name
  55. WHEN ga.type = 2 THEN
  56. qc.`name`
  57. WHEN ga.type = 3 THEN
  58. e.exam_name
  59. END NAME,
  60. CASE
  61. WHEN ga.type = 1 THEN
  62. cs.subject_name
  63. WHEN ga.type = 2 THEN
  64. cs1.subject_name
  65. WHEN ga.type = 3 THEN
  66. cs2.subject_name
  67. END subject_name,
  68. CASE
  69. WHEN ga.type = 1 THEN
  70. 0
  71. WHEN ga.type = 2 THEN
  72. 0
  73. WHEN ga.type = 3 THEN
  74. e.question_num
  75. END question_num,
  76. CASE
  77. WHEN ga.type = 1 THEN
  78. qm.publish_status
  79. WHEN ga.type = 2 THEN
  80. qc.publish_status
  81. WHEN ga.type = 3 THEN
  82. e.publish_status
  83. END publish_status,
  84. CASE
  85. WHEN ga.type = 1 THEN
  86. qm.`code`
  87. WHEN ga.type = 2 THEN
  88. qc.`code`
  89. WHEN ga.type = 3 THEN
  90. e.`code`
  91. END code,
  92. CASE
  93. WHEN ga.type = 1 THEN
  94. ''
  95. WHEN ga.type = 2 THEN
  96. ''
  97. WHEN ga.type = 3 THEN
  98. e.paper_name
  99. END paper_name
  100. <if test="userId != null ">
  101. ,
  102. CASE
  103. WHEN ga.type = 1 THEN
  104. -1
  105. WHEN ga.type = 2 THEN
  106. -1
  107. WHEN ga.type = 3 THEN
  108. 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)
  109. END record_status
  110. ,
  111. CASE
  112. WHEN ga.type = 1 THEN
  113. -1
  114. WHEN ga.type = 2 THEN
  115. -1
  116. WHEN ga.type = 3 THEN
  117. 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)
  118. END record_id
  119. ,
  120. CASE
  121. WHEN ga.type = 1 THEN
  122. -1
  123. WHEN ga.type = 2 THEN
  124. -1
  125. WHEN ga.type = 3 THEN
  126. e.answer_num
  127. END answer_num
  128. ,
  129. CASE
  130. WHEN ga.type = 1 THEN
  131. -1
  132. WHEN ga.type = 2 THEN
  133. -1
  134. WHEN ga.type = 3 THEN
  135. (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 )
  136. END do_num
  137. ,
  138. CASE
  139. WHEN ga.type = 1 THEN
  140. -1
  141. WHEN ga.type = 2 THEN
  142. -1
  143. WHEN ga.type = 3 THEN
  144. (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)
  145. END do_question_num
  146. ,
  147. CASE
  148. WHEN ga.type = 1 THEN
  149. -1
  150. WHEN ga.type = 2 THEN
  151. -1
  152. WHEN ga.type = 3 THEN
  153. (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)
  154. END right_question_num
  155. </if>
  156. FROM
  157. goods_attached ga
  158. LEFT JOIN goods g ON ga.goods_id = g.goods_id
  159. LEFT JOIN question_module qm ON ga.major_id = qm.module_exam_id
  160. AND ga.type = 1
  161. LEFT JOIN question_business qb ON qb.major_id = qm.module_exam_id
  162. AND qb.type = 4
  163. LEFT JOIN course_subject cs ON qb.subject_id = cs.id
  164. LEFT JOIN question_chapter qc ON ga.major_id = qc.chapter_exam_id
  165. AND ga.type = 2
  166. LEFT JOIN question_business qb1 ON qb1.major_id = qc.chapter_exam_id
  167. AND qb1.type = 3
  168. LEFT JOIN course_subject cs1 ON qb1.subject_id = cs1.id
  169. LEFT JOIN (
  170. SELECT
  171. e.*,
  172. count( eq.question_id ) question_num,
  173. ep.paper_name
  174. FROM
  175. exam e
  176. LEFT JOIN exam_question eq ON e.exam_id = eq.exam_id
  177. LEFT JOIN exam_paper ep ON e.exam_paper_id = ep.paper_id
  178. GROUP BY
  179. e.exam_id
  180. ) e ON ga.major_id = e.exam_id
  181. AND ga.type = 3
  182. AND e.STATUS = 1
  183. LEFT JOIN question_business qb2 ON qb2.major_id = e.exam_id
  184. AND qb2.type = 2
  185. LEFT JOIN course_subject cs2 ON qb2.subject_id = cs2.id
  186. WHERE
  187. ga.goods_id = #{goodsId}
  188. order by ga.sort,ga.id asc
  189. </select>
  190. <select id="selectDoList" parameterType="com.zhongzheng.modules.goods.bo.GoodsAttachedQueryBo" resultMap="GoodsAttachedResultVo">
  191. SELECT
  192. ga.*,
  193. CASE
  194. WHEN ga.type = 1 THEN
  195. qm.module_name
  196. WHEN ga.type = 2 THEN
  197. qc.`name`
  198. WHEN ga.type = 3 THEN
  199. e.exam_name
  200. END NAME,
  201. CASE
  202. WHEN ga.type = 1 THEN
  203. cs.subject_name
  204. WHEN ga.type = 2 THEN
  205. cs1.subject_name
  206. WHEN ga.type = 3 THEN
  207. cs2.subject_name
  208. END subject_name,
  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. e.question_num
  216. END question_num,
  217. CASE
  218. WHEN ga.type = 1 THEN
  219. qm.publish_status
  220. WHEN ga.type = 2 THEN
  221. qc.publish_status
  222. WHEN ga.type = 3 THEN
  223. e.publish_status
  224. END publish_status,
  225. CASE
  226. WHEN ga.type = 1 THEN
  227. 0
  228. WHEN ga.type = 2 THEN
  229. 0
  230. WHEN ga.type = 3 THEN
  231. uer.record_id
  232. END record_id,
  233. CASE
  234. WHEN ga.type = 1 THEN
  235. 0
  236. WHEN ga.type = 2 THEN
  237. 0
  238. WHEN ga.type = 3 THEN
  239. uer.status
  240. END record_status,
  241. CASE
  242. WHEN ga.type = 1 THEN
  243. -1
  244. WHEN ga.type = 2 THEN
  245. -1
  246. WHEN ga.type = 3 THEN
  247. e.do_type
  248. END do_type,
  249. uer.total_question_num,
  250. uer.right_question_num,
  251. uer.do_question_num
  252. FROM
  253. goods_attached ga
  254. LEFT JOIN question_module qm ON ga.major_id = qm.module_exam_id
  255. AND ga.type = 1
  256. LEFT JOIN question_business qb ON qb.major_id = qm.module_exam_id
  257. AND qb.type = 4
  258. LEFT JOIN course_subject cs ON qb.subject_id = cs.id
  259. LEFT JOIN question_chapter qc ON ga.major_id = qc.chapter_exam_id
  260. AND ga.type = 2
  261. LEFT JOIN question_business qb1 ON qb1.major_id = qc.chapter_exam_id
  262. AND qb1.type = 3
  263. LEFT JOIN course_subject cs1 ON qb1.subject_id = cs1.id
  264. LEFT JOIN (
  265. SELECT
  266. e.*,
  267. count( eq.question_id ) question_num
  268. FROM
  269. exam e
  270. LEFT JOIN exam_question eq ON e.exam_id = eq.exam_id
  271. GROUP BY
  272. e.exam_id
  273. ) e ON ga.major_id = e.exam_id
  274. AND ga.type = 3
  275. AND e.STATUS = 1
  276. LEFT JOIN question_business qb2 ON qb2.major_id = e.exam_id
  277. AND qb2.type = 2
  278. LEFT JOIN course_subject cs2 ON qb2.subject_id = cs2.id
  279. LEFT JOIN (SELECT
  280. record_id,
  281. `status`,
  282. exam_id,
  283. total_question_num,
  284. right_question_num,
  285. do_question_num
  286. FROM
  287. user_exam_record
  288. WHERE
  289. record_id IN (
  290. SELECT
  291. MAX( record_id ) record_id
  292. FROM
  293. user_exam_record
  294. WHERE
  295. user_id = #{userId}
  296. AND order_goods_id = #{orderGoodsId}
  297. GROUP BY
  298. exam_id)) uer on uer.exam_id = e.exam_id
  299. WHERE
  300. ga.goods_id = #{goodsId}
  301. AND ((
  302. ga.type = 3
  303. 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 )
  304. AND e.STATUS = 1
  305. )
  306. OR (
  307. ga.type = 2
  308. 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 ))
  309. OR (
  310. ga.type = 1
  311. 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 )))
  312. </select>
  313. <select id="getPaperIds" parameterType="java.lang.Long" resultType="com.zhongzheng.modules.goods.vo.GoodsAttachedPaperVo">
  314. SELECT
  315. ga.id as goodsAttachedId,
  316. e.exam_paper_id as examPaperId
  317. FROM
  318. goods_attached ga
  319. LEFT JOIN question_module_chapter qmc ON ga.major_id = qmc.module_exam_id
  320. LEFT JOIN question_chapter_exam qce ON qmc.chapter_exam_id = qce.chapter_exam_id
  321. LEFT JOIN exam e ON qce.exam_id = e.exam_id
  322. WHERE
  323. ga.goods_id = #{goodsId} AND ga.type = 1
  324. UNION ALL
  325. SELECT
  326. ga.id as goodsAttachedId,
  327. e.exam_paper_id as examPaperId
  328. FROM
  329. goods_attached ga
  330. LEFT JOIN question_chapter_exam qce ON ga.major_id = qce.chapter_exam_id
  331. LEFT JOIN exam e ON qce.exam_id = e.exam_id
  332. WHERE
  333. ga.goods_id = #{goodsId} AND ga.type = 2
  334. UNION ALL
  335. SELECT
  336. ga.id as goodsAttachedId,
  337. e.exam_paper_id as examPaperId
  338. FROM
  339. goods_attached ga
  340. LEFT JOIN exam e ON ga.major_id = e.exam_id
  341. WHERE
  342. ga.goods_id = #{goodsId} AND ga.type = 3
  343. </select>
  344. <delete id="deleteByIdTenant" parameterType="map">
  345. delete from goods_attached where goods_id = #{newGoodsId} and tenant_id = #{newTenantId}
  346. </delete>
  347. </mapper>