GoodsMapper.xml 30 KB

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