GoodsMapper.xml 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. <result property="chapterNum" column="chapter_num"/>
  125. <result property="examNum" column="exam_num"/>
  126. <result property="linePrice" column="line_price"/>
  127. </resultMap>
  128. <resultMap type="com.zhongzheng.modules.exam.vo.ExamNumberGoodsVo" id="ExamNumberGoodsVoResult">
  129. <result property="id" column="id"/>
  130. <result property="examNumberId" column="exam_number_id"/>
  131. <result property="goodsId" column="goods_id"/>
  132. <result property="goodsName" column="goods_name"/>
  133. <result property="code" column="code"/>
  134. <result property="standPrice" column="stand_price"/>
  135. <result property="goodsStatus" column="goods_status"/>
  136. <result property="validityStartTime" column="validity_start_time"/>
  137. <result property="validityEndTime" column="validity_end_time"/>
  138. <result property="goodsStatus" column="goods_status"/>
  139. <result property="status" column="status"/>
  140. <result property="selectStatus" column="select_status"/>
  141. </resultMap>
  142. <select id="selectAllList" parameterType="com.zhongzheng.modules.goods.bo.GoodsQueryBo" resultMap="GoodsResultVo">
  143. SELECT
  144. g.*,
  145. ps.supply_name,
  146. cet.education_name,
  147. cpt.project_name,
  148. cb.business_name,
  149. s.school_name,
  150. m.category_name,
  151. (SELECT GROUP_CONCAT(subject_name) from course_subject where FIND_IN_SET(id,g.subject_ids)) subject_names,
  152. ot.type AS template_type,
  153. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  154. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code
  155. <if test="sectionNum ==1">
  156. ,(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
  157. </if>
  158. <if test="chapterNum ==1">
  159. ,(SELECT COUNT(m.id)+(SELECT COUNT(p.id) FROM course_module_chapter p 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(cmc.id) FROM course_module_chapter cmc LEFT JOIN course_menu m on m.menu_id = cmc.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(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 chapter_num
  160. </if>
  161. <if test="goodsType ==1">
  162. , (SELECT count(*) FROM goods_course where goods_id =g.goods_id and course_show=1) as course_num
  163. , (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
  164. </if>
  165. <if test="goodsType ==2">
  166. , (SELECT count(*) from order_goods og where og.goods_id = g.goods_id and og.pay_status IN ( 2, 3, 4 )
  167. AND og.refund_status IN (0,3,1) ) as order_num
  168. </if>
  169. <if test="getOrderNum != null and getOrderNum == 1" >
  170. ,ou.goods_live_num
  171. </if>
  172. <if test="getUserNum != null and getUserNum == 1" >
  173. ,(SELECT count(*) from order_goods og where og.goods_id = g.goods_id and og.`status` = 1
  174. AND og.refund_status in (0,1,3)
  175. AND og.pay_status in (2,3,4)) as buy_user_num
  176. </if>
  177. FROM
  178. goods g
  179. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  180. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  181. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  182. LEFT JOIN course_business cb ON g.business_id = cb.id
  183. LEFT JOIN school s ON s.id = g.school_id
  184. LEFT JOIN major m ON g.major_id = m.id
  185. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  186. <if test="getOrderNum != null and getOrderNum == 1" >
  187. LEFT JOIN (
  188. SELECT
  189. og.goods_id,
  190. sum( CASE WHEN g.goods_type = 6 THEN 1 ELSE 0 END ) AS goods_live_num
  191. FROM
  192. `order` o
  193. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  194. LEFT JOIN goods g ON og.goods_id = g.goods_id
  195. WHERE o.`status` = 1
  196. AND og.refund_status in (0,1,3)
  197. AND og.pay_status in (2,3,4)
  198. GROUP BY
  199. og.goods_id
  200. ) ou ON g.goods_id = ou.goods_id
  201. </if>
  202. WHERE
  203. 1 = 1
  204. AND g.goods_type != 5
  205. <if test="status != null and status.size()!=0 ">
  206. AND g.status in
  207. <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
  208. #{item}
  209. </foreach>
  210. </if>
  211. <if test="goodsIds != null and goodsIds.size()!=0 ">
  212. AND g.goods_id in
  213. <foreach collection="goodsIds" item="item" index="index" open="(" close=")" separator=",">
  214. #{item}
  215. </foreach>
  216. </if>
  217. <if test="goodsTypes != null and goodsTypes.size()!=0 ">
  218. AND g.goods_type in
  219. <foreach collection="goodsTypes" item="item" index="index" open="(" close=")" separator=",">
  220. #{item}
  221. </foreach>
  222. </if>
  223. <if test="goodsType != null and goodsType != ''">
  224. AND g.goods_type = #{goodsType}
  225. </if>
  226. <if test="makeGoodsId != null and makeGoodsId != ''">
  227. AND g.make_goods_id = #{makeGoodsId}
  228. </if>
  229. <if test="goodsName != null and goodsName != ''">
  230. AND g.goods_name like concat('%', #{goodsName}, '%')
  231. </if>
  232. <if test="educationTypeId != null and educationTypeId != ''">
  233. AND g.education_type_id = #{educationTypeId}
  234. </if>
  235. <if test="projectId != null and projectId != ''">
  236. AND g.project_id = #{projectId}
  237. </if>
  238. <if test="businessIds != null and businessIds.size()!=0 ">
  239. AND g.business_id in
  240. <foreach collection="businessIds" item="item" index="index" open="(" close=")" separator=",">
  241. #{item}
  242. </foreach>
  243. </if>
  244. <if test="businessId != null and businessId != ''">
  245. AND g.business_id = #{businessId}
  246. </if>
  247. <if test="projectId != null and projectId != ''">
  248. AND g.project_id = #{projectId}
  249. </if>
  250. <if test="schoolId != null and schoolId != ''">
  251. AND g.school_id = #{schoolId}
  252. </if>
  253. <if test="majorId != null and majorId != ''">
  254. AND g.major_id = #{majorId}
  255. </if>
  256. <if test="standPrice != null ">
  257. AND g.stand_price = #{standPrice}
  258. </if>
  259. <if test="searchKey != null and searchKey != ''">
  260. and (g.goods_name like concat('%', #{searchKey}, '%') or g.code like concat('%', #{searchKey}, '%'))
  261. </if>
  262. <if test="goodsStatus != null ">
  263. AND g.goods_status = #{goodsStatus}
  264. </if>
  265. <if test="studyStartTime != null and studyStartTime != '' and studyEndTime != null and studyEndTime != ''">
  266. and #{studyStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{studyEndTime} BETWEEN g.validity_start_time and g.validity_end_time
  267. </if>
  268. <if test="validityStartTime != null or validityEndTime != null ">
  269. AND (#{validityStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{validityEndTime} BETWEEN g.validity_start_time and g.validity_end_time)
  270. </if>
  271. <if test="subjectId != null and subjectId >0">
  272. AND FIND_IN_SET(#{subjectId},g.subject_ids)
  273. </if>
  274. <if test="subjectIdList != null and subjectIdList.size > 0 ">
  275. AND (
  276. <foreach collection="subjectIdList" item="item" index="index">
  277. <if test=" index == 0 ">
  278. FIND_IN_SET(#{item},g.subject_ids)
  279. </if>
  280. <if test=" index != 0 ">
  281. OR FIND_IN_SET(#{item},g.subject_ids)
  282. </if>
  283. </foreach>
  284. )
  285. </if>
  286. <if test="goodsType ==1 and haveCourse != null and haveCourse == 1">
  287. 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
  288. ) >0
  289. </if>
  290. <!-- 数据范围过滤 -->
  291. ${params.dataScope}
  292. <if test="sortType != null and sortType == 2">
  293. ORDER BY g.stand_price
  294. </if>
  295. <if test="sortType != null and sortType == 3">
  296. ORDER BY g.stand_price DESC
  297. </if>
  298. <if test="sortType == null or sortType == 1">
  299. ORDER BY g.create_time DESC
  300. </if>
  301. </select>
  302. <select id="selectListToInput" parameterType="com.zhongzheng.modules.goods.bo.GoodsQueryBo" resultMap="GoodsResultVo">
  303. SELECT
  304. g.*,
  305. ps.supply_name,
  306. cet.education_name,
  307. cpt.project_name,
  308. cb.business_name,
  309. s.school_name,
  310. m.category_name,
  311. ot.type AS template_type,
  312. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  313. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code
  314. <if test="sectionNum ==1">
  315. ,(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
  316. </if>
  317. <if test="goodsType ==1">
  318. , (SELECT count(*) FROM goods_course where goods_id =g.goods_id ) as course_num
  319. , (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
  320. , (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
  321. , (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
  322. </if>
  323. FROM
  324. goods g
  325. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  326. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  327. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  328. LEFT JOIN course_business cb ON g.business_id = cb.id
  329. LEFT JOIN school s ON s.id = g.school_id
  330. LEFT JOIN major m ON g.major_id = m.id
  331. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  332. WHERE
  333. 1 = 1
  334. AND g.goods_type != 5
  335. <if test="status != null and status.size()!=0 ">
  336. AND g.status in
  337. <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
  338. #{item}
  339. </foreach>
  340. </if>
  341. <if test="goodsIds != null and goodsIds.size()!=0 ">
  342. AND g.goods_id in
  343. <foreach collection="goodsIds" item="item" index="index" open="(" close=")" separator=",">
  344. #{item}
  345. </foreach>
  346. </if>
  347. <if test="goodsType != null and goodsType != ''">
  348. AND g.goods_type = #{goodsType}
  349. </if>
  350. <if test="makeGoodsId != null and makeGoodsId != ''">
  351. AND g.make_goods_id = #{makeGoodsId}
  352. </if>
  353. <if test="goodsName != null and goodsName != ''">
  354. AND g.goods_name like concat('%', #{goodsName}, '%')
  355. </if>
  356. <if test="educationTypeId != null and educationTypeId != ''">
  357. AND g.education_type_id = #{educationTypeId}
  358. </if>
  359. <if test="projectId != null and projectId != ''">
  360. AND g.project_id = #{projectId}
  361. </if>
  362. <if test="businessIds != null and businessIds.size()!=0 ">
  363. AND g.business_id in
  364. <foreach collection="businessIds" item="item" index="index" open="(" close=")" separator=",">
  365. #{item}
  366. </foreach>
  367. </if>
  368. <if test="businessId != null and businessId != ''">
  369. AND g.business_id = #{businessId}
  370. </if>
  371. <if test="projectId != null and projectId != ''">
  372. AND g.project_id = #{projectId}
  373. </if>
  374. <if test="schoolId != null and schoolId != ''">
  375. AND g.school_id = #{schoolId}
  376. </if>
  377. <if test="majorId != null and majorId != ''">
  378. AND g.major_id = #{majorId}
  379. </if>
  380. <if test="standPrice != null and standPrice != ''">
  381. AND g.stand_price = #{standPrice}
  382. </if>
  383. <if test="searchKey != null and searchKey != ''">
  384. and (g.goods_name like concat('%', #{searchKey}, '%') or g.code like concat('%', #{searchKey}, '%'))
  385. </if>
  386. <if test="goodsStatus != null ">
  387. AND g.goods_status = #{goodsStatus}
  388. </if>
  389. <if test="studyStartTime != null and studyStartTime != '' and studyEndTime != null and studyEndTime != ''">
  390. and #{studyStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{studyEndTime} BETWEEN g.validity_start_time and g.validity_end_time
  391. </if>
  392. <if test="validityStartTime != null or validityEndTime != null ">
  393. AND (#{validityStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{validityEndTime} BETWEEN g.validity_start_time and g.validity_end_time)
  394. </if>
  395. <if test="subjectId != null and subjectId >0">
  396. AND FIND_IN_SET(#{subjectId},g.subject_ids)
  397. </if>
  398. <if test="goodsType ==1 and haveCourse != null and haveCourse == 1">
  399. 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
  400. ) >0
  401. </if>
  402. <if test="sortType != null and sortType == 2">
  403. ORDER BY g.stand_price
  404. </if>
  405. <if test="sortType != null and sortType == 3">
  406. ORDER BY g.stand_price DESC
  407. </if>
  408. <if test="sortType == null or sortType == 1">
  409. ORDER BY g.create_time DESC
  410. </if>
  411. </select>
  412. <select id="selectDetail" parameterType="Long" resultMap="GoodsResultVo">
  413. SELECT
  414. g.*,
  415. ps.supply_name,
  416. cet.education_name,
  417. cpt.project_name,
  418. cb.business_name,
  419. s.school_name,
  420. m.category_name,
  421. ot.type AS template_type,
  422. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  423. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code,
  424. (SELECT
  425. count( DISTINCT c.subject_id )
  426. FROM
  427. course c
  428. LEFT JOIN goods_course gc ON gc.course_id = c.course_id
  429. WHERE
  430. gc.goods_id = g.goods_id) as subject_num
  431. FROM
  432. goods g
  433. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  434. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  435. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  436. LEFT JOIN course_business cb ON g.business_id = cb.id
  437. LEFT JOIN school s ON s.id = g.school_id
  438. LEFT JOIN major m ON g.major_id = m.id
  439. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  440. WHERE
  441. g.goods_id = #{goodsId}
  442. </select>
  443. <select id="listGoods" parameterType="com.zhongzheng.modules.exam.bo.ExamNumberGoodsQueryBo" resultMap="ExamNumberGoodsVoResult">
  444. SELECT
  445. goods_id,
  446. goods_name,
  447. validity_start_time,
  448. validity_end_time,
  449. goods_status,
  450. status,
  451. CODE,
  452. stand_price,
  453. <if test="filtration != null and filtration == 1">
  454. (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
  455. </if>
  456. <if test="filtration != null and filtration == 2">
  457. (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
  458. </if>
  459. FROM
  460. goods g
  461. WHERE
  462. 1 = 1
  463. and g.status in(1)
  464. and g.goods_type=1
  465. <if test="businessId != null and businessId != ''">
  466. and g.business_id = #{businessId}
  467. </if>
  468. <if test="goodsId != null and goodsId != ''">
  469. and g.goods_id = #{goodsId}
  470. </if>
  471. <if test="projectId != null and projectId != ''">
  472. and g.project_id = #{projectId}
  473. </if>
  474. <if test="goodsType != null and goodsType != ''">
  475. and g.goods_type = #{goodsType}
  476. </if>
  477. <if test="goodsStatus != null and goodsStatus != ''">
  478. and g.goods_status = #{goodsStatus}
  479. </if>
  480. <if test="searchKey != null and searchKey != ''">
  481. and (g.goods_name like concat('%', #{searchKey}, '%') or g.code like concat('%', #{searchKey}, '%'))
  482. </if>
  483. order by g.create_time desc
  484. </select>
  485. <select id="selectUserDetail" parameterType="map" resultMap="GoodsResultVo">
  486. SELECT
  487. g.*,
  488. ps.supply_name,
  489. cet.education_name,
  490. cpt.project_name,
  491. cb.business_name,
  492. s.school_name,
  493. m.category_name,
  494. ot.type AS template_type,
  495. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  496. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code,
  497. (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
  498. 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
  499. FROM
  500. goods g
  501. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  502. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  503. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  504. LEFT JOIN course_business cb ON g.business_id = cb.id
  505. LEFT JOIN school s ON s.id = g.school_id
  506. LEFT JOIN major m ON g.major_id = m.id
  507. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  508. WHERE
  509. g.goods_id = #{goodsId}
  510. </select>
  511. <select id="getQuestionNum" parameterType="Long" resultType="Long">
  512. SELECT
  513. count( question_id ) question_num
  514. FROM
  515. exam_question
  516. WHERE
  517. find_in_set(
  518. exam_id,(
  519. SELECT
  520. concat(
  521. IFNULL((
  522. SELECT
  523. GROUP_CONCAT( exam_id )
  524. FROM
  525. question_chapter_exam
  526. WHERE
  527. FIND_IN_SET(chapter_exam_id,
  528. (SELECT
  529. concat(
  530. IFNULL(( SELECT GROUP_CONCAT( major_id ) eids FROM goods_attached WHERE goods_id = #{goodsId} AND type = 2 ), '' ),
  531. ',',
  532. IFNULL(
  533. (
  534. SELECT
  535. GROUP_CONCAT( chapter_exam_id ) eids2
  536. FROM
  537. question_module_chapter
  538. WHERE
  539. module_exam_id IN ( SELECT major_id FROM goods_attached WHERE goods_id = #{goodsId} AND type = 1 )),
  540. ''
  541. ))))),
  542. ''
  543. ),
  544. ',',
  545. IFNULL(( SELECT GROUP_CONCAT( major_id ) FROM goods_attached WHERE goods_id = #{goodsId} AND type = 3 ), '' ))))
  546. </select>
  547. <update id="queryUpGoods">
  548. update goods g set g.goods_status=0 where unix_timestamp(now()) > g.validity_end_time and g.goods_status = 1
  549. </update>
  550. <select id="getExamNum" parameterType="Long" resultType="Long">
  551. SELECT
  552. count( exam_id )+((
  553. SELECT
  554. count( major_id )
  555. FROM
  556. goods_attached
  557. WHERE
  558. goods_id = #{goodsId}
  559. AND type = 3
  560. )) AS exam_num
  561. FROM
  562. question_chapter_exam
  563. WHERE
  564. FIND_IN_SET(
  565. chapter_exam_id,
  566. (
  567. SELECT
  568. concat(
  569. IFNULL(( SELECT GROUP_CONCAT( major_id ) eids FROM goods_attached WHERE goods_id = #{goodsId} AND type = 2 ), '' ),
  570. ',',
  571. IFNULL(
  572. (
  573. SELECT
  574. GROUP_CONCAT( chapter_exam_id ) eids2
  575. FROM
  576. question_module_chapter
  577. WHERE
  578. module_exam_id IN ( SELECT major_id FROM goods_attached WHERE goods_id = #{goodsId} AND type = 1 )),
  579. ''
  580. ))))
  581. </select>
  582. <select id="getSectionNum" parameterType="Long" resultMap="GoodsResultVo">
  583. SELECT
  584. (SELECT IFNULL(COUNT(m.id),0)+(SELECT IFNULL(COUNT(n.id),0) 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 IFNULL(COUNT(n.id),0) 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,
  585. (SELECT IFNULL(COUNT(1),0) FROM goods_course gc where gc.goods_id = g.goods_id) as course_num,
  586. (SELECT
  587. IFNULL(COUNT( m.id ),0)
  588. FROM
  589. goods_course c LEFT JOIN course_menu_exam m ON m.course_id = c.course_id
  590. where
  591. m.type = 1
  592. and c.goods_id = g.goods_id) as exam_num
  593. FROM
  594. goods g
  595. WHERE
  596. g.goods_id = #{goodsId}
  597. </select>
  598. </mapper>