GoodsMapper.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  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.GoodsMapper">
  6. <resultMap type="com.zhongzheng.modules.goods.domain.Goods" id="GoodsResult">
  7. <result property="goodsId" column="goods_id"/>
  8. <result property="year" column="year"/>
  9. <result property="supplyId" column="supply_id"/>
  10. <result property="goodsType" column="goods_type"/>
  11. <result property="educationTypeId" column="education_type_id"/>
  12. <result property="businessId" column="business_id"/>
  13. <result property="schoolId" column="school_id"/>
  14. <result property="majorId" column="major_id"/>
  15. <result property="goodsName" column="goods_name"/>
  16. <result property="standPrice" column="stand_price"/>
  17. <result property="lowestPrice" column="lowest_price"/>
  18. <result property="createTime" column="create_time"/>
  19. <result property="updateTime" column="update_time"/>
  20. <result property="status" column="status"/>
  21. <result property="validityStartTime" column="validity_start_time"/>
  22. <result property="validityEndTime" column="validity_end_time"/>
  23. <result property="studyStartTime" column="study_start_time"/>
  24. <result property="studyEndTime" column="study_end_time"/>
  25. <result property="certificateIds" column="certificate_ids"/>
  26. <result property="introduce" column="introduce"/>
  27. <result property="suitableObject" column="suitable_object"/>
  28. <result property="buyNote" column="buy_note"/>
  29. <result property="pcDetailHtml" column="pc_detail_html"/>
  30. <result property="mobileDetailHtml" column="mobile_detail_html"/>
  31. <result property="goodsStatus" column="goods_status"/>
  32. <result property="coverUrl" column="cover_url"/>
  33. <result property="classHours" column="class_hours"/>
  34. <result property="standPriceJson" column="stand_price_json"/>
  35. <result property="code" column="code"/>
  36. <result property="supplyName" column="supply_name"/>
  37. <result property="projectId" column="project_id"/>
  38. <result property="goodsAuditionConfig" column="goods_audition_config"/>
  39. <result property="goodsPhotographConfig" column="goods_photograph_config"/>
  40. <result property="goodsPlayConfig" column="goods_play_config"/>
  41. <result property="goodsExamConfig" column="goods_exam_config"/>
  42. <result property="handoutsId" column="handouts_id"/>
  43. <result property="serviceTimeType" column="service_time_type"/>
  44. <result property="serviceTimeNum" column="service_time_num"/>
  45. <result property="sectionMaxNum" column="section_max_num"/>
  46. <result property="examNumber" column="exam_number"/>
  47. <result property="doNumber" column="do_number"/>
  48. <result property="teacherId" column="teacher_id"/>
  49. <result property="subjectIds" column="subject_ids"/>
  50. <result property="certificateTypeId" column="certificate_type_id"/>
  51. <result property="certificateId" column="certificate_id"/>
  52. <result property="certificateTpId" column="certificate_tp_id"/>
  53. </resultMap>
  54. <resultMap type="com.zhongzheng.modules.goods.vo.GoodsVo" id="GoodsResultVo">
  55. <result property="goodsId" column="goods_id"/>
  56. <result property="year" column="year"/>
  57. <result property="supplyId" column="supply_id"/>
  58. <result property="goodsType" column="goods_type"/>
  59. <result property="gradeId" column="grade_id"/>
  60. <result property="educationTypeId" column="education_type_id"/>
  61. <result property="businessId" column="business_id"/>
  62. <result property="schoolId" column="school_id"/>
  63. <result property="majorId" column="major_id"/>
  64. <result property="goodsName" column="goods_name"/>
  65. <result property="standPrice" column="stand_price"/>
  66. <result property="lowestPrice" column="lowest_price"/>
  67. <result property="createTime" column="create_time"/>
  68. <result property="updateTime" column="update_time"/>
  69. <result property="status" column="status"/>
  70. <result property="validityStartTime" column="validity_start_time"/>
  71. <result property="validityEndTime" column="validity_end_time"/>
  72. <result property="studyStartTime" column="study_start_time"/>
  73. <result property="studyEndTime" column="study_end_time"/>
  74. <result property="certificateIds" column="certificate_ids"/>
  75. <result property="introduce" column="introduce"/>
  76. <result property="suitableObject" column="suitable_object"/>
  77. <result property="buyNote" column="buy_note"/>
  78. <result property="pcDetailHtml" column="pc_detail_html"/>
  79. <result property="mobileDetailHtml" column="mobile_detail_html"/>
  80. <result property="goodsStatus" column="goods_status"/>
  81. <result property="coverUrl" column="cover_url"/>
  82. <result property="classHours" column="class_hours"/>
  83. <result property="standPriceJson" column="stand_price_json"/>
  84. <result property="code" column="code"/>
  85. <result property="projectId" column="project_id"/>
  86. <result property="goodsAuditionConfig" column="goods_audition_config"/>
  87. <result property="goodsPhotographConfig" column="goods_photograph_config"/>
  88. <result property="goodsAuditionExamConfig" column="goods_audition_exam_config"/>
  89. <result property="goodsPlayConfig" column="goods_play_config"/>
  90. <result property="goodsExamConfig" column="goods_exam_config"/>
  91. <result property="sectionMaxNum" column="section_max_num"/>
  92. <result property="supplyName" column="supply_name"/>
  93. <result property="educationName" column="education_name"/>
  94. <result property="projectName" column="project_name"/>
  95. <result property="businessName" column="business_name"/>
  96. <result property="schoolName" column="school_name"/>
  97. <result property="categoryName" column="category_name"/>
  98. <result property="handoutsId" column="handouts_id"/>
  99. <result property="templateType" column="template_type"/>
  100. <result property="period" column="period"/>
  101. <result property="makeStartTime" column="make_start_time"/>
  102. <result property="makeEndTime" column="make_end_time"/>
  103. <result property="studyCount" column="study_count"/>
  104. <result property="makeGoodsName" column="make_goods_name"/>
  105. <result property="makeGoodsCode" column="make_goods_code"/>
  106. <result property="courseNum" column="course_num"/>
  107. <result property="sectionNum" column="section_num"/>
  108. <result property="serviceTimeType" column="service_time_type"/>
  109. <result property="serviceTimeNum" column="service_time_num"/>
  110. <result property="gradeNum" column="grade_num"/>
  111. <result property="gradeId" column="grade_id"/>
  112. <result property="gradeName" column="grade_name"/>
  113. <result property="examNumber" column="exam_number"/>
  114. <result property="doNumber" column="do_number"/>
  115. <result property="orderNum" column="order_num"/>
  116. <result property="teacherId" column="teacher_id"/>
  117. <result property="goodsLiveNum" column="goods_live_num"/>
  118. <result property="subjectIds" column="subject_ids"/>
  119. <result property="certificateTypeId" column="certificate_type_id"/>
  120. <result property="certificateId" column="certificate_id"/>
  121. <result property="certificateTpId" column="certificate_tp_id"/>
  122. <result property="subjectNames" column="subject_names"/>
  123. <result property="buyUserNum" column="buy_user_num"/>
  124. </resultMap>
  125. <resultMap type="com.zhongzheng.modules.exam.vo.ExamNumberGoodsVo" id="ExamNumberGoodsVoResult">
  126. <result property="id" column="id"/>
  127. <result property="examNumberId" column="exam_number_id"/>
  128. <result property="goodsId" column="goods_id"/>
  129. <result property="goodsName" column="goods_name"/>
  130. <result property="code" column="code"/>
  131. <result property="standPrice" column="stand_price"/>
  132. <result property="goodsStatus" column="goods_status"/>
  133. <result property="validityStartTime" column="validity_start_time"/>
  134. <result property="validityEndTime" column="validity_end_time"/>
  135. <result property="goodsStatus" column="goods_status"/>
  136. <result property="status" column="status"/>
  137. <result property="selectStatus" column="select_status"/>
  138. </resultMap>
  139. <select id="selectAllList" parameterType="com.zhongzheng.modules.goods.bo.GoodsQueryBo" resultMap="GoodsResultVo">
  140. SELECT
  141. g.*,
  142. ps.supply_name,
  143. cet.education_name,
  144. cpt.project_name,
  145. cb.business_name,
  146. s.school_name,
  147. m.category_name,
  148. (SELECT GROUP_CONCAT(subject_name) from course_subject where FIND_IN_SET(id,g.subject_ids)) subject_names,
  149. ot.type AS template_type,
  150. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  151. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code
  152. <if test="sectionNum ==1">
  153. ,(SELECT COUNT(m.id)+(SELECT COUNT(n.id) FROM course_chapter_section n LEFT JOIN course_module_chapter p on n.chapter_id = p.chapter_id LEFT JOIN course_menu m on m.menu_id = p.module_id LEFT JOIN goods_course gc on gc.course_id = m.course_id where gc.goods_id = g.goods_id and m.type in(1))+(SELECT COUNT(n.id) FROM course_chapter_section n LEFT JOIN course_menu m on m.menu_id = n.chapter_id LEFT JOIN goods_course gc on gc.course_id = m.course_id where gc.goods_id = g.goods_id and m.type in(2)) FROM course_menu m LEFT JOIN goods_course gc on gc.course_id = m.course_id where gc.goods_id = g.goods_id and m.type in(3)) as section_num
  154. </if>
  155. <if test="goodsType ==1">
  156. , (SELECT count(*) FROM goods_course where goods_id =g.goods_id ) as course_num
  157. , (SELECT count(*) FROM class_grade cg LEFT JOIN class_grade_goods cgg on cg.grade_id = cgg.grade_id where cgg.goods_id = g.goods_id and cg.`status` = 1 ) as grade_num
  158. </if>
  159. <if test="goodsType ==2">
  160. , (SELECT count(*) from order_goods og where og.goods_id = g.goods_id and og.pay_status IN ( 2, 3, 4 )
  161. AND og.refund_status IN (0,3,1) ) as order_num
  162. </if>
  163. <if test="getOrderNum != null and getOrderNum == 1" >
  164. ,ou.goods_live_num
  165. </if>
  166. <if test="getUserNum != null and getUserNum == 1" >
  167. ,(SELECT count(*) from order_goods og where og.goods_id = g.goods_id and o.`status` = 1
  168. AND og.refund_status in (0,1,3)
  169. AND og.pay_status in (2,3,4)) as buy_user_num
  170. </if>
  171. FROM
  172. goods g
  173. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  174. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  175. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  176. LEFT JOIN course_business cb ON g.business_id = cb.id
  177. LEFT JOIN school s ON s.id = g.school_id
  178. LEFT JOIN major m ON g.major_id = m.id
  179. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  180. <if test="getOrderNum != null and getOrderNum == 1" >
  181. LEFT JOIN (
  182. SELECT
  183. og.goods_id,
  184. sum( CASE WHEN g.goods_type = 6 THEN 1 ELSE 0 END ) AS goods_live_num
  185. FROM
  186. `order` o
  187. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  188. LEFT JOIN goods g ON og.goods_id = g.goods_id
  189. WHERE o.`status` = 1
  190. AND og.refund_status in (0,1,3)
  191. AND og.pay_status in (2,3,4)
  192. GROUP BY
  193. og.goods_id
  194. ) ou ON g.goods_id = ou.goods_id
  195. </if>
  196. WHERE
  197. 1 = 1
  198. AND g.goods_type != 5
  199. <if test="status != null and status.size()!=0 ">
  200. AND g.status in
  201. <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
  202. #{item}
  203. </foreach>
  204. </if>
  205. <if test="goodsIds != null and goodsIds.size()!=0 ">
  206. AND g.goods_id in
  207. <foreach collection="goodsIds" item="item" index="index" open="(" close=")" separator=",">
  208. #{item}
  209. </foreach>
  210. </if>
  211. <if test="goodsType != null and goodsType != ''">
  212. AND g.goods_type = #{goodsType}
  213. </if>
  214. <if test="makeGoodsId != null and makeGoodsId != ''">
  215. AND g.make_goods_id = #{makeGoodsId}
  216. </if>
  217. <if test="goodsName != null and goodsName != ''">
  218. AND g.goods_name like concat('%', #{goodsName}, '%')
  219. </if>
  220. <if test="educationTypeId != null and educationTypeId != ''">
  221. AND g.education_type_id = #{educationTypeId}
  222. </if>
  223. <if test="projectId != null and projectId != ''">
  224. AND g.project_id = #{projectId}
  225. </if>
  226. <if test="businessIds != null and businessIds.size()!=0 ">
  227. AND g.business_id in
  228. <foreach collection="businessIds" item="item" index="index" open="(" close=")" separator=",">
  229. #{item}
  230. </foreach>
  231. </if>
  232. <if test="businessId != null and businessId != ''">
  233. AND g.business_id = #{businessId}
  234. </if>
  235. <if test="schoolId != null and schoolId != ''">
  236. AND g.school_id = #{schoolId}
  237. </if>
  238. <if test="majorId != null and majorId != ''">
  239. AND g.major_id = #{majorId}
  240. </if>
  241. <if test="standPrice != null ">
  242. AND g.stand_price = #{standPrice}
  243. </if>
  244. <if test="searchKey != null and searchKey != ''">
  245. and (g.goods_name like concat('%', #{searchKey}, '%') or g.code like concat('%', #{searchKey}, '%'))
  246. </if>
  247. <if test="goodsStatus != null ">
  248. AND g.goods_status = #{goodsStatus}
  249. </if>
  250. <if test="studyStartTime != null and studyStartTime != '' and studyEndTime != null and studyEndTime != ''">
  251. and #{studyStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{studyEndTime} BETWEEN g.validity_start_time and g.validity_end_time
  252. </if>
  253. <if test="validityStartTime != null or validityEndTime != null ">
  254. AND (#{validityStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{validityEndTime} BETWEEN g.validity_start_time and g.validity_end_time)
  255. </if>
  256. <if test="subjectId != null and subjectId >0">
  257. AND FIND_IN_SET(#{subjectId},g.subject_ids)
  258. </if>
  259. <if test="goodsType ==1 and haveCourse != null and haveCourse == 1">
  260. AND (SELECT count(*) from goods_course gc LEFT JOIN course c ON gc.course_id = c.course_id where gc.goods_id = g.goods_id and c.`status` = 1
  261. ) >0
  262. </if>
  263. <!-- 数据范围过滤 -->
  264. ${params.dataScope}
  265. <if test="sortType != null and sortType == 2">
  266. ORDER BY g.stand_price
  267. </if>
  268. <if test="sortType != null and sortType == 3">
  269. ORDER BY g.stand_price DESC
  270. </if>
  271. <if test="sortType == null or sortType == 1">
  272. ORDER BY g.create_time DESC
  273. </if>
  274. </select>
  275. <select id="selectListToInput" parameterType="com.zhongzheng.modules.goods.bo.GoodsQueryBo" resultMap="GoodsResultVo">
  276. SELECT
  277. g.*,
  278. ps.supply_name,
  279. cet.education_name,
  280. cpt.project_name,
  281. cb.business_name,
  282. s.school_name,
  283. m.category_name,
  284. ot.type AS template_type,
  285. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  286. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code
  287. <if test="sectionNum ==1">
  288. ,(SELECT COUNT(m.id)+(SELECT COUNT(n.id) FROM course_chapter_section n LEFT JOIN course_module_chapter p on n.chapter_id = p.chapter_id LEFT JOIN course_menu m on m.menu_id = p.module_id LEFT JOIN goods_course gc on gc.course_id = m.course_id where gc.goods_id = g.goods_id and m.type in(1))+(SELECT COUNT(n.id) FROM course_chapter_section n LEFT JOIN course_menu m on m.menu_id = n.chapter_id LEFT JOIN goods_course gc on gc.course_id = m.course_id where gc.goods_id = g.goods_id and m.type in(2)) FROM course_menu m LEFT JOIN goods_course gc on gc.course_id = m.course_id where gc.goods_id = g.goods_id and m.type in(3)) as section_num
  289. </if>
  290. <if test="goodsType ==1">
  291. , (SELECT count(*) FROM goods_course where goods_id =g.goods_id ) as course_num
  292. , (SELECT count(*) FROM class_grade cg LEFT JOIN class_grade_goods cgg on cg.grade_id = cgg.grade_id where cgg.goods_id = g.goods_id and cg.`status` = 1 ) as grade_num
  293. , (SELECT cg.grade_id FROM class_grade cg LEFT JOIN class_grade_goods cgg on cg.grade_id = cgg.grade_id where cgg.goods_id = g.goods_id and cg.`status` = 1 AND (unix_timestamp(now()) &lt; cg.class_end_time or cg.class_start_time is null) AND cg.`status` = 1 AND (SELECT COUNT(a.id) FROM class_grade_user a where a.grade_id = cg.grade_id and a.status =1) &lt; cg.student_upper limit 1) as grade_id
  294. , (SELECT cg.class_name FROM class_grade cg LEFT JOIN class_grade_goods cgg on cg.grade_id = cgg.grade_id where cgg.goods_id = g.goods_id and cg.`status` = 1 AND (unix_timestamp(now()) &lt; cg.class_end_time or cg.class_start_time is null) AND cg.`status` = 1 AND (SELECT COUNT(a.id) FROM class_grade_user a where a.grade_id = cg.grade_id and a.status =1) &lt; cg.student_upper limit 1) as grade_name
  295. </if>
  296. FROM
  297. goods g
  298. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  299. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  300. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  301. LEFT JOIN course_business cb ON g.business_id = cb.id
  302. LEFT JOIN school s ON s.id = g.school_id
  303. LEFT JOIN major m ON g.major_id = m.id
  304. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  305. WHERE
  306. 1 = 1
  307. AND g.goods_type != 5
  308. <if test="status != null and status.size()!=0 ">
  309. AND g.status in
  310. <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
  311. #{item}
  312. </foreach>
  313. </if>
  314. <if test="goodsIds != null and goodsIds.size()!=0 ">
  315. AND g.goods_id in
  316. <foreach collection="goodsIds" item="item" index="index" open="(" close=")" separator=",">
  317. #{item}
  318. </foreach>
  319. </if>
  320. <if test="goodsType != null and goodsType != ''">
  321. AND g.goods_type = #{goodsType}
  322. </if>
  323. <if test="makeGoodsId != null and makeGoodsId != ''">
  324. AND g.make_goods_id = #{makeGoodsId}
  325. </if>
  326. <if test="goodsName != null and goodsName != ''">
  327. AND g.goods_name like concat('%', #{goodsName}, '%')
  328. </if>
  329. <if test="educationTypeId != null and educationTypeId != ''">
  330. AND g.education_type_id = #{educationTypeId}
  331. </if>
  332. <if test="projectId != null and projectId != ''">
  333. AND g.project_id = #{projectId}
  334. </if>
  335. <if test="businessIds != null and businessIds.size()!=0 ">
  336. AND g.business_id in
  337. <foreach collection="businessIds" item="item" index="index" open="(" close=")" separator=",">
  338. #{item}
  339. </foreach>
  340. </if>
  341. <if test="businessId != null and businessId != ''">
  342. AND g.business_id = #{businessId}
  343. </if>
  344. <if test="schoolId != null and schoolId != ''">
  345. AND g.school_id = #{schoolId}
  346. </if>
  347. <if test="majorId != null and majorId != ''">
  348. AND g.major_id = #{majorId}
  349. </if>
  350. <if test="standPrice != null and standPrice != ''">
  351. AND g.stand_price = #{standPrice}
  352. </if>
  353. <if test="searchKey != null and searchKey != ''">
  354. and (g.goods_name like concat('%', #{searchKey}, '%') or g.code like concat('%', #{searchKey}, '%'))
  355. </if>
  356. <if test="goodsStatus != null ">
  357. AND g.goods_status = #{goodsStatus}
  358. </if>
  359. <if test="studyStartTime != null and studyStartTime != '' and studyEndTime != null and studyEndTime != ''">
  360. and #{studyStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{studyEndTime} BETWEEN g.validity_start_time and g.validity_end_time
  361. </if>
  362. <if test="validityStartTime != null or validityEndTime != null ">
  363. AND (#{validityStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{validityEndTime} BETWEEN g.validity_start_time and g.validity_end_time)
  364. </if>
  365. <if test="subjectId != null and subjectId >0">
  366. AND FIND_IN_SET(#{subjectId},g.subject_ids)
  367. </if>
  368. <if test="goodsType ==1 and haveCourse != null and haveCourse == 1">
  369. AND (SELECT count(*) from goods_course gc LEFT JOIN course c ON gc.course_id = c.course_id where gc.goods_id = g.goods_id and c.`status` = 1
  370. ) >0
  371. </if>
  372. <if test="sortType != null and sortType == 2">
  373. ORDER BY g.stand_price
  374. </if>
  375. <if test="sortType != null and sortType == 3">
  376. ORDER BY g.stand_price DESC
  377. </if>
  378. <if test="sortType == null or sortType == 1">
  379. ORDER BY g.create_time DESC
  380. </if>
  381. </select>
  382. <select id="selectDetail" parameterType="Long" resultMap="GoodsResultVo">
  383. SELECT
  384. g.*,
  385. ps.supply_name,
  386. cet.education_name,
  387. cpt.project_name,
  388. cb.business_name,
  389. s.school_name,
  390. m.category_name,
  391. ot.type AS template_type,
  392. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  393. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code,
  394. (SELECT
  395. count( DISTINCT c.subject_id )
  396. FROM
  397. course c
  398. LEFT JOIN goods_course gc ON gc.course_id = c.course_id
  399. WHERE
  400. gc.goods_id = g.goods_id) as subject_num
  401. FROM
  402. goods g
  403. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  404. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  405. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  406. LEFT JOIN course_business cb ON g.business_id = cb.id
  407. LEFT JOIN school s ON s.id = g.school_id
  408. LEFT JOIN major m ON g.major_id = m.id
  409. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  410. WHERE
  411. g.goods_id = #{goodsId}
  412. </select>
  413. <select id="listGoods" parameterType="com.zhongzheng.modules.exam.bo.ExamNumberGoodsQueryBo" resultMap="ExamNumberGoodsVoResult">
  414. SELECT
  415. goods_id,
  416. goods_name,
  417. validity_start_time,
  418. validity_end_time,
  419. goods_status,
  420. status,
  421. CODE,
  422. stand_price,
  423. <if test="filtration != null and filtration == 1">
  424. (case WHEN (SELECT COUNT(gs.goods_id) FROM goods gs where 1=1 and gs.make_goods_id = g.goods_id and gs.status =1 and gs.goods_type =4) >0 then 0 ELSE 1 end) as select_status
  425. </if>
  426. <if test="filtration != null and filtration == 2">
  427. (case WHEN (SELECT COUNT(gs.goods_id) FROM goods gs where 1=1 and gs.make_goods_id = g.goods_id and gs.status =1 and gs.goods_type =3) >0 then 0 ELSE 1 end) as select_status
  428. </if>
  429. FROM
  430. goods g
  431. WHERE
  432. 1 = 1
  433. and g.status in(1)
  434. and g.goods_type=1
  435. <if test="businessId != null and businessId != ''">
  436. and g.business_id = #{businessId}
  437. </if>
  438. <if test="goodsId != null and goodsId != ''">
  439. and g.goods_id = #{goodsId}
  440. </if>
  441. <if test="projectId != null and projectId != ''">
  442. and g.project_id = #{projectId}
  443. </if>
  444. <if test="goodsType != null and goodsType != ''">
  445. and g.goods_type = #{goodsType}
  446. </if>
  447. <if test="goodsStatus != null and goodsStatus != ''">
  448. and g.goods_status = #{goodsStatus}
  449. </if>
  450. <if test="searchKey != null and searchKey != ''">
  451. and (g.goods_name like concat('%', #{searchKey}, '%') or g.code like concat('%', #{searchKey}, '%'))
  452. </if>
  453. order by g.create_time desc
  454. </select>
  455. <select id="selectUserDetail" parameterType="map" resultMap="GoodsResultVo">
  456. SELECT
  457. g.*,
  458. ps.supply_name,
  459. cet.education_name,
  460. cpt.project_name,
  461. cb.business_name,
  462. s.school_name,
  463. m.category_name,
  464. ot.type AS template_type,
  465. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  466. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code,
  467. (SELECT DISTINCT cg.grade_id FROM class_grade_user cgu LEFT JOIN class_grade_goods cgg on cgg.grade_id = cgu.grade_id LEFT JOIN class_grade cg on cg.grade_id = cgu.grade_id
  468. where cgu.user_id = #{userId} and cgg.goods_id=g.goods_id and cg.`status` =1 and unix_timestamp(now()) BETWEEN cg.class_start_time and cg.class_end_time) as grade_id
  469. FROM
  470. goods g
  471. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  472. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  473. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  474. LEFT JOIN course_business cb ON g.business_id = cb.id
  475. LEFT JOIN school s ON s.id = g.school_id
  476. LEFT JOIN major m ON g.major_id = m.id
  477. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  478. WHERE
  479. g.goods_id = #{goodsId}
  480. </select>
  481. <select id="getQuestionNum" parameterType="Long" resultType="Long">
  482. SELECT
  483. count( question_id ) question_num
  484. FROM
  485. exam_question
  486. WHERE
  487. find_in_set(
  488. exam_id,(
  489. SELECT
  490. concat(
  491. IFNULL((
  492. SELECT
  493. GROUP_CONCAT( exam_id )
  494. FROM
  495. question_chapter_exam
  496. WHERE
  497. FIND_IN_SET(chapter_exam_id,
  498. (SELECT
  499. concat(
  500. IFNULL(( SELECT GROUP_CONCAT( major_id ) eids FROM goods_attached WHERE goods_id = #{goodsId} AND type = 2 ), '' ),
  501. ',',
  502. IFNULL(
  503. (
  504. SELECT
  505. GROUP_CONCAT( chapter_exam_id ) eids2
  506. FROM
  507. question_module_chapter
  508. WHERE
  509. module_exam_id IN ( SELECT major_id FROM goods_attached WHERE goods_id = #{goodsId} AND type = 1 )),
  510. ''
  511. ))))),
  512. ''
  513. ),
  514. ',',
  515. IFNULL(( SELECT GROUP_CONCAT( major_id ) FROM goods_attached WHERE goods_id = #{goodsId} AND type = 3 ), '' ))))
  516. </select>
  517. <update id="queryUpGoods">
  518. update goods g set g.goods_status=0 where unix_timestamp(now()) > g.validity_end_time and g.goods_status = 1
  519. </update>
  520. <select id="getExamNum" parameterType="Long" resultType="Long">
  521. SELECT
  522. count( exam_id )+((
  523. SELECT
  524. count( major_id )
  525. FROM
  526. goods_attached
  527. WHERE
  528. goods_id = #{goodsId}
  529. AND type = 3
  530. )) AS exam_num
  531. FROM
  532. question_chapter_exam
  533. WHERE
  534. FIND_IN_SET(
  535. chapter_exam_id,
  536. (
  537. SELECT
  538. concat(
  539. IFNULL(( SELECT GROUP_CONCAT( major_id ) eids FROM goods_attached WHERE goods_id = #{goodsId} AND type = 2 ), '' ),
  540. ',',
  541. IFNULL(
  542. (
  543. SELECT
  544. GROUP_CONCAT( chapter_exam_id ) eids2
  545. FROM
  546. question_module_chapter
  547. WHERE
  548. module_exam_id IN ( SELECT major_id FROM goods_attached WHERE goods_id = #{goodsId} AND type = 1 )),
  549. ''
  550. ))))
  551. </select>
  552. </mapper>