GoodsMapper.xml 30 KB

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