GoodsMapper.xml 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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="specTemplateId" column="spec_template_id"/>
  93. <result property="showStatus" column="show_status"/>
  94. <result property="showSort" column="show_sort"/>
  95. <result property="specialGoods" column="special_goods"/>
  96. <result property="supplyName" column="supply_name"/>
  97. <result property="educationName" column="education_name"/>
  98. <result property="projectName" column="project_name"/>
  99. <result property="businessName" column="business_name"/>
  100. <result property="schoolName" column="school_name"/>
  101. <result property="categoryName" column="category_name"/>
  102. <result property="handoutsId" column="handouts_id"/>
  103. <result property="templateType" column="template_type"/>
  104. <result property="period" column="period"/>
  105. <result property="makeStartTime" column="make_start_time"/>
  106. <result property="makeEndTime" column="make_end_time"/>
  107. <result property="studyCount" column="study_count"/>
  108. <result property="makeGoodsName" column="make_goods_name"/>
  109. <result property="makeGoodsCode" column="make_goods_code"/>
  110. <result property="courseNum" column="course_num"/>
  111. <result property="sectionNum" column="section_num"/>
  112. <result property="serviceTimeType" column="service_time_type"/>
  113. <result property="serviceTimeNum" column="service_time_num"/>
  114. <result property="gradeNum" column="grade_num"/>
  115. <result property="gradeId" column="grade_id"/>
  116. <result property="gradeName" column="grade_name"/>
  117. <result property="examNumber" column="exam_number"/>
  118. <result property="doNumber" column="do_number"/>
  119. <result property="orderNum" column="order_num"/>
  120. <result property="teacherId" column="teacher_id"/>
  121. <result property="goodsLiveNum" column="goods_live_num"/>
  122. <result property="subjectIds" column="subject_ids"/>
  123. <result property="certificateTypeId" column="certificate_type_id"/>
  124. <result property="certificateId" column="certificate_id"/>
  125. <result property="certificateTpId" column="certificate_tp_id"/>
  126. <result property="subjectNames" column="subject_names"/>
  127. <result property="buyUserNum" column="buy_user_num"/>
  128. <result property="chapterNum" column="chapter_num"/>
  129. <result property="examNum" column="exam_num"/>
  130. <result property="linePrice" column="line_price"/>
  131. <result property="specTemplateNumber" column="spec_template_number"/>
  132. <result property="goodsLearningOrder" column="goods_learning_order"/>
  133. </resultMap>
  134. <resultMap type="com.zhongzheng.modules.exam.vo.ExamNumberGoodsVo" id="ExamNumberGoodsVoResult">
  135. <result property="id" column="id"/>
  136. <result property="examNumberId" column="exam_number_id"/>
  137. <result property="goodsId" column="goods_id"/>
  138. <result property="goodsName" column="goods_name"/>
  139. <result property="code" column="code"/>
  140. <result property="standPrice" column="stand_price"/>
  141. <result property="goodsStatus" column="goods_status"/>
  142. <result property="validityStartTime" column="validity_start_time"/>
  143. <result property="validityEndTime" column="validity_end_time"/>
  144. <result property="goodsStatus" column="goods_status"/>
  145. <result property="status" column="status"/>
  146. <result property="selectStatus" column="select_status"/>
  147. </resultMap>
  148. <select id="getSectionNum" parameterType="Long" resultType="Long">
  149. SELECT
  150. COUNT( m.id ) + (
  151. SELECT
  152. COUNT( n.id )
  153. FROM
  154. course_chapter_section n
  155. LEFT JOIN course_module_chapter p ON n.chapter_id = p.chapter_id
  156. LEFT JOIN course_menu m ON m.menu_id = p.module_id
  157. LEFT JOIN goods_course gc ON gc.course_id = m.course_id
  158. WHERE
  159. gc.goods_id = #{goodsId}
  160. AND m.type =1) + (
  161. SELECT
  162. COUNT( n.id )
  163. FROM
  164. course_chapter_section n
  165. LEFT JOIN course_menu m ON m.menu_id = n.chapter_id
  166. LEFT JOIN goods_course gc ON gc.course_id = m.course_id
  167. WHERE
  168. gc.goods_id = #{goodsId}
  169. AND m.type =2)
  170. FROM
  171. course_menu m
  172. LEFT JOIN goods_course gc ON gc.course_id = m.course_id
  173. WHERE
  174. gc.goods_id = #{goodsId}
  175. AND m.type =3
  176. </select>
  177. <select id="selectAllList" parameterType="com.zhongzheng.modules.goods.bo.GoodsQueryBo" resultMap="GoodsResultVo">
  178. SELECT
  179. g.*,
  180. ps.supply_name,
  181. cet.education_name,
  182. cpt.project_name,
  183. cb.business_name,
  184. cb.goods_learning_order,
  185. s.school_name,
  186. m.category_name,
  187. (SELECT GROUP_CONCAT(subject_name) from course_subject where FIND_IN_SET(id,g.subject_ids)) subject_names,
  188. (SELECT COUNT( DISTINCT gar.spec_template_id ) FROM goods_spec_attribute_relation gar WHERE gar.goods_id = g.goods_id AND gar.`status` = 1 ) spec_template_number,
  189. ot.type AS template_type,
  190. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  191. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code
  192. <if test="chapterNum ==1">
  193. ,(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
  194. </if>
  195. ,(case WHEN g.goods_type =1 then (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.course_show=1) ELSE 0 end) as course_num
  196. <if test="goodsType ==1">
  197. , (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
  198. </if>
  199. <if test="goodsType ==2">
  200. , (SELECT count(*) from order_goods og where og.goods_id = g.goods_id and og.pay_status IN ( 2, 3, 4 )
  201. AND og.refund_status IN (0,3,1) ) as order_num
  202. </if>
  203. <if test="getOrderNum != null and getOrderNum == 1" >
  204. ,ou.goods_live_num
  205. </if>
  206. <if test="getUserNum != null and getUserNum == 1" >
  207. ,(SELECT count(*) from order_goods og where og.goods_id = g.goods_id and og.`status` = 1
  208. AND og.refund_status in (0,1,3)
  209. AND og.pay_status in (2,3,4)) as buy_user_num
  210. </if>
  211. FROM
  212. goods g
  213. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  214. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  215. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  216. LEFT JOIN course_business cb ON g.business_id = cb.id
  217. LEFT JOIN school s ON s.id = g.school_id
  218. LEFT JOIN major m ON g.major_id = m.id
  219. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  220. <if test="getOrderNum != null and getOrderNum == 1" >
  221. LEFT JOIN (
  222. SELECT
  223. og.goods_id,
  224. sum( CASE WHEN g.goods_type = 6 THEN 1 ELSE 0 END ) AS goods_live_num
  225. FROM
  226. `order` o
  227. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  228. LEFT JOIN goods g ON og.goods_id = g.goods_id
  229. WHERE o.`status` = 1
  230. AND og.refund_status in (0,1,3)
  231. AND og.pay_status in (2,3,4)
  232. GROUP BY
  233. og.goods_id
  234. ) ou ON g.goods_id = ou.goods_id
  235. </if>
  236. WHERE
  237. 1 = 1
  238. AND g.goods_type != 5
  239. <if test="status != null and status.size()!=0 ">
  240. AND g.status in
  241. <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
  242. #{item}
  243. </foreach>
  244. </if>
  245. <if test="goodsIds != null and goodsIds.size()!=0 ">
  246. AND g.goods_id in
  247. <foreach collection="goodsIds" item="item" index="index" open="(" close=")" separator=",">
  248. #{item}
  249. </foreach>
  250. </if>
  251. <if test="goodsTypes != null and goodsTypes.size()!=0 ">
  252. AND g.goods_type in
  253. <foreach collection="goodsTypes" item="item" index="index" open="(" close=")" separator=",">
  254. #{item}
  255. </foreach>
  256. </if>
  257. <if test="goodsType != null and goodsType != ''">
  258. AND g.goods_type = #{goodsType}
  259. </if>
  260. <if test="showStatus != null and showStatus != ''">
  261. AND g.show_status = #{showStatus}
  262. </if>
  263. <if test="code != null and code != ''">
  264. AND g.code = #{code}
  265. </if>
  266. <if test="makeGoodsId != null and makeGoodsId != ''">
  267. AND g.make_goods_id = #{makeGoodsId}
  268. </if>
  269. <if test="goodsName != null and goodsName != ''">
  270. AND g.goods_name like concat('%', #{goodsName}, '%')
  271. </if>
  272. <if test="educationTypeId != null and educationTypeId != ''">
  273. AND g.education_type_id = #{educationTypeId}
  274. </if>
  275. <if test="projectId != null and projectId != ''">
  276. AND g.project_id = #{projectId}
  277. </if>
  278. <if test="businessIds != null and businessIds.size()!=0 ">
  279. AND g.business_id in
  280. <foreach collection="businessIds" item="item" index="index" open="(" close=")" separator=",">
  281. #{item}
  282. </foreach>
  283. </if>
  284. <if test="businessId != null and businessId != ''">
  285. AND g.business_id = #{businessId}
  286. </if>
  287. <if test="projectId != null and projectId != ''">
  288. AND g.project_id = #{projectId}
  289. </if>
  290. <if test="schoolId != null and schoolId != ''">
  291. AND g.school_id = #{schoolId}
  292. </if>
  293. <if test="majorId != null and majorId != ''">
  294. AND g.major_id = #{majorId}
  295. </if>
  296. <if test="standPrice != null ">
  297. AND g.stand_price = #{standPrice}
  298. </if>
  299. <if test="searchKey != null and searchKey != ''">
  300. and (g.goods_name like concat('%', #{searchKey}, '%') or g.code like concat('%', #{searchKey}, '%'))
  301. </if>
  302. <if test="goodsStatus != null ">
  303. AND g.goods_status = #{goodsStatus}
  304. </if>
  305. <if test="studyStartTime != null and studyStartTime != '' and studyEndTime != null and studyEndTime != ''">
  306. and #{studyStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{studyEndTime} BETWEEN g.validity_start_time and g.validity_end_time
  307. </if>
  308. <if test="validityStartTime != null or validityEndTime != null ">
  309. AND (#{validityStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{validityEndTime} BETWEEN g.validity_start_time and g.validity_end_time)
  310. </if>
  311. <if test="subjectId != null and subjectId >0">
  312. AND FIND_IN_SET(#{subjectId},g.subject_ids)
  313. </if>
  314. <if test="subjectIdList != null and subjectIdList.size > 0 ">
  315. AND (
  316. <foreach collection="subjectIdList" item="item" index="index">
  317. <if test=" index == 0 ">
  318. FIND_IN_SET(#{item},g.subject_ids)
  319. </if>
  320. <if test=" index != 0 ">
  321. OR FIND_IN_SET(#{item},g.subject_ids)
  322. </if>
  323. </foreach>
  324. )
  325. </if>
  326. <if test="goodsType ==1 and haveCourse != null and haveCourse == 1">
  327. 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
  328. ) >0
  329. </if>
  330. <!-- 数据范围过滤 -->
  331. ${params.dataScope}
  332. <if test="sortType != null and sortType == 2">
  333. ORDER BY g.show_sort DESC,g.stand_price ASC
  334. </if>
  335. <if test="sortType != null and sortType == 3">
  336. ORDER BY g.show_sort DESC,g.stand_price DESC
  337. </if>
  338. <if test="sortType != null and sortType == 1">
  339. ORDER BY g.show_sort DESC,g.create_time DESC
  340. </if>
  341. <if test="sortType == null" >
  342. ORDER BY g.create_time DESC
  343. </if>
  344. </select>
  345. <select id="selectListToInput" parameterType="com.zhongzheng.modules.goods.bo.GoodsQueryBo" resultMap="GoodsResultVo">
  346. SELECT
  347. g.*,
  348. ps.supply_name,
  349. cet.education_name,
  350. cpt.project_name,
  351. cb.business_name,
  352. s.school_name,
  353. m.category_name,
  354. ot.type AS template_type,
  355. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  356. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code
  357. <if test="sectionNum ==1">
  358. ,(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
  359. </if>
  360. <if test="goodsType ==1">
  361. , (SELECT count(*) FROM goods_course where goods_id =g.goods_id ) as course_num
  362. , (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
  363. , (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
  364. , (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
  365. </if>
  366. FROM
  367. goods g
  368. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  369. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  370. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  371. LEFT JOIN course_business cb ON g.business_id = cb.id
  372. LEFT JOIN school s ON s.id = g.school_id
  373. LEFT JOIN major m ON g.major_id = m.id
  374. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  375. WHERE
  376. 1 = 1
  377. AND g.goods_type != 5
  378. <if test="status != null and status.size()!=0 ">
  379. AND g.status in
  380. <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
  381. #{item}
  382. </foreach>
  383. </if>
  384. <if test="goodsIds != null and goodsIds.size()!=0 ">
  385. AND g.goods_id in
  386. <foreach collection="goodsIds" item="item" index="index" open="(" close=")" separator=",">
  387. #{item}
  388. </foreach>
  389. </if>
  390. <if test="goodsType != null and goodsType != ''">
  391. AND g.goods_type = #{goodsType}
  392. </if>
  393. <if test="makeGoodsId != null and makeGoodsId != ''">
  394. AND g.make_goods_id = #{makeGoodsId}
  395. </if>
  396. <if test="goodsName != null and goodsName != ''">
  397. AND g.goods_name like concat('%', #{goodsName}, '%')
  398. </if>
  399. <if test="educationTypeId != null and educationTypeId != ''">
  400. AND g.education_type_id = #{educationTypeId}
  401. </if>
  402. <if test="projectId != null and projectId != ''">
  403. AND g.project_id = #{projectId}
  404. </if>
  405. <if test="businessIds != null and businessIds.size()!=0 ">
  406. AND g.business_id in
  407. <foreach collection="businessIds" item="item" index="index" open="(" close=")" separator=",">
  408. #{item}
  409. </foreach>
  410. </if>
  411. <if test="businessId != null and businessId != ''">
  412. AND g.business_id = #{businessId}
  413. </if>
  414. <if test="projectId != null and projectId != ''">
  415. AND g.project_id = #{projectId}
  416. </if>
  417. <if test="schoolId != null and schoolId != ''">
  418. AND g.school_id = #{schoolId}
  419. </if>
  420. <if test="majorId != null and majorId != ''">
  421. AND g.major_id = #{majorId}
  422. </if>
  423. <if test="standPrice != null and standPrice != ''">
  424. AND g.stand_price = #{standPrice}
  425. </if>
  426. <if test="searchKey != null and searchKey != ''">
  427. and (g.goods_name like concat('%', #{searchKey}, '%') or g.code like concat('%', #{searchKey}, '%'))
  428. </if>
  429. <if test="goodsStatus != null ">
  430. AND g.goods_status = #{goodsStatus}
  431. </if>
  432. <if test="studyStartTime != null and studyStartTime != '' and studyEndTime != null and studyEndTime != ''">
  433. and #{studyStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{studyEndTime} BETWEEN g.validity_start_time and g.validity_end_time
  434. </if>
  435. <if test="validityStartTime != null or validityEndTime != null ">
  436. AND (#{validityStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{validityEndTime} BETWEEN g.validity_start_time and g.validity_end_time)
  437. </if>
  438. <if test="subjectId != null and subjectId >0">
  439. AND FIND_IN_SET(#{subjectId},g.subject_ids)
  440. </if>
  441. <if test="goodsType ==1 and haveCourse != null and haveCourse == 1">
  442. 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
  443. ) >0
  444. </if>
  445. <if test="sortType != null and sortType == 2">
  446. ORDER BY g.stand_price
  447. </if>
  448. <if test="sortType != null and sortType == 3">
  449. ORDER BY g.stand_price DESC
  450. </if>
  451. <if test="sortType == null or sortType == 1">
  452. ORDER BY g.create_time DESC
  453. </if>
  454. </select>
  455. <select id="selectDetail" parameterType="Long" resultMap="GoodsResultVo">
  456. SELECT
  457. g.*,
  458. ps.supply_name,
  459. cet.education_name,
  460. cpt.project_name,
  461. cb.business_name,
  462. cb.template_status as special_goods,
  463. s.school_name,
  464. m.category_name,
  465. ot.type AS template_type,
  466. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  467. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code,
  468. (SELECT
  469. count( DISTINCT c.subject_id )
  470. FROM
  471. course c
  472. LEFT JOIN goods_course gc ON gc.course_id = c.course_id
  473. WHERE
  474. gc.goods_id = g.goods_id) as subject_num,
  475. (SELECT GROUP_CONCAT(subject_name) from course_subject where FIND_IN_SET(id,g.subject_ids)) subject_names
  476. FROM
  477. goods g
  478. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  479. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  480. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  481. LEFT JOIN course_business cb ON g.business_id = cb.id
  482. LEFT JOIN school s ON s.id = g.school_id
  483. LEFT JOIN major m ON g.major_id = m.id
  484. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  485. WHERE
  486. g.goods_id = #{goodsId}
  487. </select>
  488. <select id="listGoods" parameterType="com.zhongzheng.modules.exam.bo.ExamNumberGoodsQueryBo" resultMap="ExamNumberGoodsVoResult">
  489. SELECT
  490. goods_id,
  491. goods_name,
  492. validity_start_time,
  493. validity_end_time,
  494. goods_status,
  495. status,
  496. CODE,
  497. stand_price,
  498. <if test="filtration != null and filtration == 1">
  499. (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
  500. </if>
  501. <if test="filtration != null and filtration == 2">
  502. (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
  503. </if>
  504. FROM
  505. goods g
  506. WHERE
  507. 1 = 1
  508. and g.status in(1)
  509. and g.goods_type=1
  510. <if test="businessId != null and businessId != ''">
  511. and g.business_id = #{businessId}
  512. </if>
  513. <if test="goodsId != null and goodsId != ''">
  514. and g.goods_id = #{goodsId}
  515. </if>
  516. <if test="projectId != null and projectId != ''">
  517. and g.project_id = #{projectId}
  518. </if>
  519. <if test="goodsType != null and goodsType != ''">
  520. and g.goods_type = #{goodsType}
  521. </if>
  522. <if test="goodsStatus != null and goodsStatus != ''">
  523. and g.goods_status = #{goodsStatus}
  524. </if>
  525. <if test="searchKey != null and searchKey != ''">
  526. and (g.goods_name like concat('%', #{searchKey}, '%') or g.code like concat('%', #{searchKey}, '%'))
  527. </if>
  528. order by g.create_time desc
  529. </select>
  530. <select id="selectUserDetail" parameterType="map" resultMap="GoodsResultVo">
  531. SELECT
  532. g.*,
  533. ps.supply_name,
  534. cet.education_name,
  535. cpt.project_name,
  536. cb.business_name,
  537. cb.template_status AS special_goods,
  538. s.school_name,
  539. m.category_name,
  540. ot.type AS template_type,
  541. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  542. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code,
  543. (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
  544. 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
  545. FROM
  546. goods g
  547. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  548. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  549. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  550. LEFT JOIN course_business cb ON g.business_id = cb.id
  551. LEFT JOIN school s ON s.id = g.school_id
  552. LEFT JOIN major m ON g.major_id = m.id
  553. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  554. WHERE
  555. g.goods_id = #{goodsId}
  556. </select>
  557. <select id="getQuestionNum" parameterType="Long" resultType="Long">
  558. SELECT
  559. count(DISTINCT question_id ) question_num
  560. FROM
  561. exam_question
  562. WHERE
  563. find_in_set(
  564. exam_id,(
  565. SELECT
  566. concat(
  567. IFNULL((
  568. SELECT
  569. GROUP_CONCAT( exam_id )
  570. FROM
  571. question_chapter_exam
  572. WHERE
  573. FIND_IN_SET(chapter_exam_id,
  574. (SELECT
  575. concat(
  576. IFNULL(( SELECT GROUP_CONCAT( major_id ) eids FROM goods_attached WHERE goods_id = #{goodsId} AND type = 2 ), '' ),
  577. ',',
  578. IFNULL(
  579. (
  580. SELECT
  581. GROUP_CONCAT( chapter_exam_id ) eids2
  582. FROM
  583. question_module_chapter
  584. WHERE
  585. module_exam_id IN ( SELECT major_id FROM goods_attached WHERE goods_id = #{goodsId} AND type = 1 )),
  586. ''
  587. ))))),
  588. ''
  589. ),
  590. ',',
  591. IFNULL(( SELECT GROUP_CONCAT( major_id ) FROM goods_attached WHERE goods_id = #{goodsId} AND type = 3 ), '' ))))
  592. </select>
  593. <select id="getRandomQuestionNum" parameterType="map" resultType="Long">
  594. SELECT
  595. count(DISTINCT eq.question_id ) question_num
  596. FROM
  597. exam_question eq LEFT JOIN exam e on eq.exam_id = e.exam_id
  598. WHERE
  599. find_in_set(
  600. eq.exam_id,(
  601. SELECT
  602. concat(
  603. IFNULL((
  604. SELECT
  605. GROUP_CONCAT( exam_id )
  606. FROM
  607. question_chapter_exam
  608. WHERE
  609. FIND_IN_SET(chapter_exam_id,
  610. (SELECT
  611. concat(
  612. IFNULL(( SELECT GROUP_CONCAT( major_id ) eids FROM goods_attached WHERE goods_id = #{goodsId} AND type = 2 ), '' ),
  613. ',',
  614. IFNULL(
  615. (
  616. SELECT
  617. GROUP_CONCAT( chapter_exam_id ) eids2
  618. FROM
  619. question_module_chapter
  620. WHERE
  621. module_exam_id IN ( SELECT major_id FROM goods_attached WHERE goods_id = #{goodsId} AND type = 1 )),
  622. ''
  623. ))))),
  624. ''
  625. ),
  626. ',',
  627. IFNULL(( SELECT GROUP_CONCAT( major_id ) FROM goods_attached WHERE goods_id = #{goodsId} AND type = 3 ), '' )))) and e.exam_paper_id = #{examPaperId}
  628. </select>
  629. <update id="queryUpGoods">
  630. update goods g set g.goods_status=0 where unix_timestamp(now()) > g.validity_end_time and g.goods_status = 1
  631. </update>
  632. <select id="getExamNum" parameterType="Long" resultType="Long">
  633. SELECT
  634. count( exam_id )+((
  635. SELECT
  636. count( major_id )
  637. FROM
  638. goods_attached
  639. WHERE
  640. goods_id = #{goodsId}
  641. AND type = 3
  642. )) AS exam_num
  643. FROM
  644. question_chapter_exam
  645. WHERE
  646. FIND_IN_SET(
  647. chapter_exam_id,
  648. (
  649. SELECT
  650. concat(
  651. IFNULL(( SELECT GROUP_CONCAT( major_id ) eids FROM goods_attached WHERE goods_id = #{goodsId} AND type = 2 ), '' ),
  652. ',',
  653. IFNULL(
  654. (
  655. SELECT
  656. GROUP_CONCAT( chapter_exam_id ) eids2
  657. FROM
  658. question_module_chapter
  659. WHERE
  660. module_exam_id IN ( SELECT major_id FROM goods_attached WHERE goods_id = #{goodsId} AND type = 1 )),
  661. ''
  662. ))))
  663. </select>
  664. <select id="getSectionNum" parameterType="Long" resultMap="GoodsResultVo">
  665. SELECT
  666. (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,
  667. (SELECT IFNULL(COUNT(1),0) FROM goods_course gc where gc.goods_id = g.goods_id) as course_num,
  668. (SELECT
  669. IFNULL(COUNT( m.id ),0)
  670. FROM
  671. goods_course c LEFT JOIN course_menu_exam m ON m.course_id = c.course_id
  672. where
  673. m.type = 1
  674. and c.goods_id = g.goods_id) as exam_num
  675. FROM
  676. goods g
  677. WHERE
  678. g.goods_id = #{goodsId}
  679. </select>
  680. </mapper>