GoodsAttachedMapper.xml 11 KB

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