GoodsMapper.xml 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  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="externalLink" column="external_link"/>
  97. <result property="externalLinkStatus" column="external_link_status"/>
  98. <result property="supplyName" column="supply_name"/>
  99. <result property="educationName" column="education_name"/>
  100. <result property="projectName" column="project_name"/>
  101. <result property="businessName" column="business_name"/>
  102. <result property="schoolName" column="school_name"/>
  103. <result property="categoryName" column="category_name"/>
  104. <result property="handoutsId" column="handouts_id"/>
  105. <result property="templateType" column="template_type"/>
  106. <result property="period" column="period"/>
  107. <result property="makeStartTime" column="make_start_time"/>
  108. <result property="makeEndTime" column="make_end_time"/>
  109. <result property="studyCount" column="study_count"/>
  110. <result property="makeGoodsName" column="make_goods_name"/>
  111. <result property="makeGoodsCode" column="make_goods_code"/>
  112. <result property="courseNum" column="course_num"/>
  113. <result property="sectionNum" column="section_num"/>
  114. <result property="serviceTimeType" column="service_time_type"/>
  115. <result property="serviceTimeNum" column="service_time_num"/>
  116. <result property="gradeNum" column="grade_num"/>
  117. <result property="gradeId" column="grade_id"/>
  118. <result property="gradeName" column="grade_name"/>
  119. <result property="examNumber" column="exam_number"/>
  120. <result property="doNumber" column="do_number"/>
  121. <result property="orderNum" column="order_num"/>
  122. <result property="teacherId" column="teacher_id"/>
  123. <result property="goodsLiveNum" column="goods_live_num"/>
  124. <result property="subjectIds" column="subject_ids"/>
  125. <result property="certificateTypeId" column="certificate_type_id"/>
  126. <result property="certificateId" column="certificate_id"/>
  127. <result property="certificateTpId" column="certificate_tp_id"/>
  128. <result property="subjectNames" column="subject_names"/>
  129. <result property="buyUserNum" column="buy_user_num"/>
  130. <result property="chapterNum" column="chapter_num"/>
  131. <result property="examNum" column="exam_num"/>
  132. <result property="linePrice" column="line_price"/>
  133. <result property="specTemplateNumber" column="spec_template_number"/>
  134. <result property="goodsLearningOrder" column="goods_learning_order"/>
  135. </resultMap>
  136. <resultMap type="com.zhongzheng.modules.exam.vo.ExamNumberGoodsVo" id="ExamNumberGoodsVoResult">
  137. <result property="id" column="id"/>
  138. <result property="examNumberId" column="exam_number_id"/>
  139. <result property="goodsId" column="goods_id"/>
  140. <result property="goodsName" column="goods_name"/>
  141. <result property="code" column="code"/>
  142. <result property="standPrice" column="stand_price"/>
  143. <result property="goodsStatus" column="goods_status"/>
  144. <result property="validityStartTime" column="validity_start_time"/>
  145. <result property="validityEndTime" column="validity_end_time"/>
  146. <result property="goodsStatus" column="goods_status"/>
  147. <result property="status" column="status"/>
  148. <result property="selectStatus" column="select_status"/>
  149. </resultMap>
  150. <select id="getSectionNum" parameterType="Long" resultType="Long">
  151. SELECT COUNT(m.id) + (
  152. SELECT COUNT(n.id)
  153. FROM course_chapter_section n
  154. LEFT JOIN course_module_chapter p ON n.chapter_id = p.chapter_id
  155. LEFT JOIN course_menu m ON m.menu_id = p.module_id
  156. LEFT JOIN goods_course gc ON gc.course_id = m.course_id
  157. WHERE gc.goods_id = #{goodsId}
  158. AND m.type = 1) + (
  159. SELECT COUNT(n.id)
  160. FROM course_chapter_section n
  161. LEFT JOIN course_menu m ON m.menu_id = n.chapter_id
  162. LEFT JOIN goods_course gc ON gc.course_id = m.course_id
  163. WHERE gc.goods_id = #{goodsId}
  164. AND m.type = 2)
  165. FROM course_menu m
  166. LEFT JOIN goods_course gc ON gc.course_id = m.course_id
  167. WHERE gc.goods_id = #{goodsId}
  168. AND m.type = 3
  169. </select>
  170. <select id="selectAllList" parameterType="com.zhongzheng.modules.goods.bo.GoodsQueryBo" resultMap="GoodsResultVo">
  171. SELECT
  172. g.*,
  173. ps.supply_name,
  174. cet.education_name,
  175. cpt.project_name,
  176. cb.business_name,
  177. cb.goods_learning_order,
  178. s.school_name,
  179. m.category_name,
  180. (SELECT GROUP_CONCAT(subject_name) from course_subject where FIND_IN_SET(id,g.subject_ids)) subject_names,
  181. (SELECT COUNT( DISTINCT gar.spec_template_id ) FROM goods_spec_attribute_relation gar WHERE gar.goods_id =
  182. g.goods_id AND gar.`status` = 1 ) spec_template_number,
  183. ot.type AS template_type,
  184. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  185. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code
  186. <if test="chapterNum ==1">
  187. ,(SELECT COUNT(m.id)+(SELECT COUNT(p.id) FROM course_module_chapter p LEFT JOIN course_menu m on m.menu_id =
  188. p.module_id LEFT JOIN goods_course gc on gc.course_id = m.course_id where gc.goods_id = g.goods_id and
  189. m.type in(1))+(SELECT COUNT(cmc.id) FROM course_module_chapter cmc LEFT JOIN course_menu m on m.menu_id =
  190. cmc.module_id LEFT JOIN goods_course gc on gc.course_id = m.course_id where gc.goods_id = g.goods_id and
  191. m.type in(2)) FROM course_menu m LEFT JOIN goods_course gc on gc.course_id = m.course_id where gc.goods_id =
  192. g.goods_id and m.type in(3)) as chapter_num
  193. </if>
  194. ,(case WHEN g.goods_type =1 then (SELECT count(*) FROM goods_course gc LEFT JOIN course c on gc.course_id =
  195. 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
  198. cgg.goods_id = g.goods_id and cg.`status` = 1 ) as grade_num
  199. </if>
  200. <if test="goodsType ==2">
  201. , (SELECT count(*) from order_goods og where og.goods_id = g.goods_id and og.pay_status IN ( 2, 3, 4 )
  202. AND og.refund_status IN (0,3,1) ) as order_num
  203. </if>
  204. <if test="getOrderNum != null and getOrderNum == 1">
  205. ,ou.goods_live_num
  206. </if>
  207. <if test="getUserNum != null and getUserNum == 1">
  208. ,(SELECT count(*) from order_goods og where og.goods_id = g.goods_id and og.`status` = 1
  209. AND og.refund_status in (0,1,3)
  210. AND og.pay_status in (2,3,4)) as buy_user_num
  211. </if>
  212. FROM
  213. goods g
  214. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  215. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  216. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  217. LEFT JOIN course_business cb ON g.business_id = cb.id
  218. LEFT JOIN school s ON s.id = g.school_id
  219. LEFT JOIN major m ON g.major_id = m.id
  220. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  221. <if test="getOrderNum != null and getOrderNum == 1">
  222. LEFT JOIN (
  223. SELECT
  224. og.goods_id,
  225. sum( CASE WHEN g.goods_type = 6 THEN 1 ELSE 0 END ) AS goods_live_num
  226. FROM
  227. `order` o
  228. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  229. LEFT JOIN goods g ON og.goods_id = g.goods_id
  230. WHERE o.`status` = 1
  231. AND og.refund_status in (0,1,3)
  232. AND og.pay_status in (2,3,4)
  233. GROUP BY
  234. og.goods_id
  235. ) ou ON g.goods_id = ou.goods_id
  236. </if>
  237. WHERE
  238. 1 = 1
  239. AND g.goods_type != 5
  240. <if test="status != null and status.size()!=0 ">
  241. AND g.status in
  242. <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
  243. #{item}
  244. </foreach>
  245. </if>
  246. <if test="goodsIds != null and goodsIds.size()!=0 ">
  247. AND g.goods_id in
  248. <foreach collection="goodsIds" item="item" index="index" open="(" close=")" separator=",">
  249. #{item}
  250. </foreach>
  251. </if>
  252. <if test="goodsTypes != null and goodsTypes.size()!=0 ">
  253. AND g.goods_type in
  254. <foreach collection="goodsTypes" item="item" index="index" open="(" close=")" separator=",">
  255. #{item}
  256. </foreach>
  257. </if>
  258. <if test="goodsType != null and goodsType != ''">
  259. AND g.goods_type = #{goodsType}
  260. </if>
  261. <if test="showStatus != null and showStatus != ''">
  262. AND g.show_status = #{showStatus}
  263. </if>
  264. <if test="code != null and code != ''">
  265. AND g.code = #{code}
  266. </if>
  267. <if test="makeGoodsId != null and makeGoodsId != ''">
  268. AND g.make_goods_id = #{makeGoodsId}
  269. </if>
  270. <if test="goodsName != null and goodsName != ''">
  271. AND g.goods_name like concat('%', #{goodsName}, '%')
  272. </if>
  273. <if test="educationTypeId != null and educationTypeId != ''">
  274. AND g.education_type_id = #{educationTypeId}
  275. </if>
  276. <if test="projectId != null and projectId != ''">
  277. AND g.project_id = #{projectId}
  278. </if>
  279. <if test="businessIds != null and businessIds.size()!=0 ">
  280. AND g.business_id in
  281. <foreach collection="businessIds" item="item" index="index" open="(" close=")" separator=",">
  282. #{item}
  283. </foreach>
  284. </if>
  285. <if test="businessId != null and businessId != ''">
  286. AND g.business_id = #{businessId}
  287. </if>
  288. <if test="projectId != null and projectId != ''">
  289. AND g.project_id = #{projectId}
  290. </if>
  291. <if test="schoolId != null and schoolId != ''">
  292. AND g.school_id = #{schoolId}
  293. </if>
  294. <if test="majorId != null and majorId != ''">
  295. AND g.major_id = #{majorId}
  296. </if>
  297. <if test="standPrice != null ">
  298. AND g.stand_price = #{standPrice}
  299. </if>
  300. <if test="searchKey != null and searchKey != ''">
  301. and (g.goods_name like concat('%', #{searchKey}, '%') or g.code like concat('%', #{searchKey}, '%'))
  302. </if>
  303. <if test="goodsStatus != null ">
  304. AND g.goods_status = #{goodsStatus}
  305. </if>
  306. <if test="studyStartTime != null and studyStartTime != '' and studyEndTime != null and studyEndTime != ''">
  307. and #{studyStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{studyEndTime} BETWEEN
  308. g.validity_start_time and g.validity_end_time
  309. </if>
  310. <if test="validityStartTime != null or validityEndTime != null ">
  311. AND (#{validityStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{validityEndTime}
  312. BETWEEN g.validity_start_time and g.validity_end_time)
  313. </if>
  314. <if test="subjectId != null and subjectId >0">
  315. AND FIND_IN_SET(#{subjectId},g.subject_ids)
  316. </if>
  317. <if test="subjectIdList != null and subjectIdList.size > 0 ">
  318. AND (
  319. <foreach collection="subjectIdList" item="item" index="index">
  320. <if test=" index == 0 ">
  321. FIND_IN_SET(#{item},g.subject_ids)
  322. </if>
  323. <if test=" index != 0 ">
  324. OR FIND_IN_SET(#{item},g.subject_ids)
  325. </if>
  326. </foreach>
  327. )
  328. </if>
  329. <if test="goodsType ==1 and haveCourse != null and haveCourse == 1">
  330. AND (SELECT count(*) from goods_course gc LEFT JOIN course c ON gc.course_id = c.course_id where gc.goods_id
  331. = g.goods_id and c.`status` = 1
  332. ) >0
  333. </if>
  334. <!-- 数据范围过滤 -->
  335. ${params.dataScope}
  336. <if test="sortType != null and sortType == 2">
  337. ORDER BY g.show_sort DESC,g.stand_price ASC
  338. </if>
  339. <if test="sortType != null and sortType == 3">
  340. ORDER BY g.show_sort DESC,g.stand_price DESC
  341. </if>
  342. <if test="sortType != null and sortType == 1">
  343. ORDER BY g.show_sort DESC,g.create_time DESC
  344. </if>
  345. <if test="sortType == null">
  346. ORDER BY g.create_time DESC
  347. </if>
  348. </select>
  349. <select id="selectListToInput" parameterType="com.zhongzheng.modules.goods.bo.GoodsQueryBo"
  350. resultMap="GoodsResultVo">
  351. SELECT
  352. g.*,
  353. ps.supply_name,
  354. cet.education_name,
  355. cpt.project_name,
  356. cb.business_name,
  357. s.school_name,
  358. m.category_name,
  359. ot.type AS template_type,
  360. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  361. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code
  362. <if test="sectionNum ==1">
  363. ,(SELECT COUNT(m.id)+(SELECT COUNT(n.id) FROM course_chapter_section n LEFT JOIN course_module_chapter p on
  364. n.chapter_id = p.chapter_id LEFT JOIN course_menu m on m.menu_id = p.module_id LEFT JOIN goods_course gc on
  365. gc.course_id = m.course_id where gc.goods_id = g.goods_id and m.type in(1))+(SELECT COUNT(n.id) FROM
  366. course_chapter_section n LEFT JOIN course_menu m on m.menu_id = n.chapter_id LEFT JOIN goods_course gc on
  367. gc.course_id = m.course_id where gc.goods_id = g.goods_id and m.type in(2)) FROM course_menu m LEFT JOIN
  368. goods_course gc on gc.course_id = m.course_id where gc.goods_id = g.goods_id and m.type in(3)) as
  369. section_num
  370. </if>
  371. <if test="goodsType ==1">
  372. , (SELECT count(*) FROM goods_course where goods_id =g.goods_id ) as course_num
  373. , (SELECT count(*) FROM class_grade cg LEFT JOIN class_grade_goods cgg on cg.grade_id = cgg.grade_id where
  374. cgg.goods_id = g.goods_id and cg.`status` = 1 ) as grade_num
  375. , (SELECT cg.grade_id FROM class_grade cg LEFT JOIN class_grade_goods cgg on cg.grade_id = cgg.grade_id
  376. where cgg.goods_id = g.goods_id and cg.`status` = 1 AND (unix_timestamp(now()) &lt; cg.class_end_time or
  377. cg.class_start_time is null) AND cg.`status` = 1 AND (SELECT COUNT(a.id) FROM class_grade_user a where
  378. a.grade_id = cg.grade_id and a.status =1) &lt; cg.student_upper limit 1) as grade_id
  379. , (SELECT cg.class_name FROM class_grade cg LEFT JOIN class_grade_goods cgg on cg.grade_id = cgg.grade_id
  380. where cgg.goods_id = g.goods_id and cg.`status` = 1 AND (unix_timestamp(now()) &lt; cg.class_end_time or
  381. cg.class_start_time is null) AND cg.`status` = 1 AND (SELECT COUNT(a.id) FROM class_grade_user a where
  382. a.grade_id = cg.grade_id and a.status =1) &lt; cg.student_upper limit 1) as grade_name
  383. </if>
  384. FROM
  385. goods g
  386. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  387. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  388. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  389. LEFT JOIN course_business cb ON g.business_id = cb.id
  390. LEFT JOIN school s ON s.id = g.school_id
  391. LEFT JOIN major m ON g.major_id = m.id
  392. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  393. WHERE
  394. 1 = 1
  395. AND g.goods_type != 5
  396. <if test="status != null and status.size()!=0 ">
  397. AND g.status in
  398. <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
  399. #{item}
  400. </foreach>
  401. </if>
  402. <if test="goodsIds != null and goodsIds.size()!=0 ">
  403. AND g.goods_id in
  404. <foreach collection="goodsIds" item="item" index="index" open="(" close=")" separator=",">
  405. #{item}
  406. </foreach>
  407. </if>
  408. <if test="goodsType != null and goodsType != ''">
  409. AND g.goods_type = #{goodsType}
  410. </if>
  411. <if test="makeGoodsId != null and makeGoodsId != ''">
  412. AND g.make_goods_id = #{makeGoodsId}
  413. </if>
  414. <if test="goodsName != null and goodsName != ''">
  415. AND g.goods_name like concat('%', #{goodsName}, '%')
  416. </if>
  417. <if test="educationTypeId != null and educationTypeId != ''">
  418. AND g.education_type_id = #{educationTypeId}
  419. </if>
  420. <if test="projectId != null and projectId != ''">
  421. AND g.project_id = #{projectId}
  422. </if>
  423. <if test="businessIds != null and businessIds.size()!=0 ">
  424. AND g.business_id in
  425. <foreach collection="businessIds" item="item" index="index" open="(" close=")" separator=",">
  426. #{item}
  427. </foreach>
  428. </if>
  429. <if test="businessId != null and businessId != ''">
  430. AND g.business_id = #{businessId}
  431. </if>
  432. <if test="projectId != null and projectId != ''">
  433. AND g.project_id = #{projectId}
  434. </if>
  435. <if test="schoolId != null and schoolId != ''">
  436. AND g.school_id = #{schoolId}
  437. </if>
  438. <if test="majorId != null and majorId != ''">
  439. AND g.major_id = #{majorId}
  440. </if>
  441. <if test="standPrice != null and standPrice != ''">
  442. AND g.stand_price = #{standPrice}
  443. </if>
  444. <if test="searchKey != null and searchKey != ''">
  445. and (g.goods_name like concat('%', #{searchKey}, '%') or g.code like concat('%', #{searchKey}, '%'))
  446. </if>
  447. <if test="goodsStatus != null ">
  448. AND g.goods_status = #{goodsStatus}
  449. </if>
  450. <if test="studyStartTime != null and studyStartTime != '' and studyEndTime != null and studyEndTime != ''">
  451. and #{studyStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{studyEndTime} BETWEEN
  452. g.validity_start_time and g.validity_end_time
  453. </if>
  454. <if test="validityStartTime != null or validityEndTime != null ">
  455. AND (#{validityStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{validityEndTime}
  456. BETWEEN g.validity_start_time and g.validity_end_time)
  457. </if>
  458. <if test="subjectId != null and subjectId >0">
  459. AND FIND_IN_SET(#{subjectId},g.subject_ids)
  460. </if>
  461. <if test="goodsType ==1 and haveCourse != null and haveCourse == 1">
  462. AND (SELECT count(*) from goods_course gc LEFT JOIN course c ON gc.course_id = c.course_id where gc.goods_id
  463. = g.goods_id and c.`status` = 1
  464. ) >0
  465. </if>
  466. <if test="sortType != null and sortType == 2">
  467. ORDER BY g.stand_price
  468. </if>
  469. <if test="sortType != null and sortType == 3">
  470. ORDER BY g.stand_price DESC
  471. </if>
  472. <if test="sortType == null or sortType == 1">
  473. ORDER BY g.create_time DESC
  474. </if>
  475. </select>
  476. <select id="selectDetail" parameterType="Long" resultMap="GoodsResultVo">
  477. SELECT g.*,
  478. ps.supply_name,
  479. cet.education_name,
  480. cpt.project_name,
  481. cb.business_name,
  482. cb.template_status as special_goods,
  483. s.school_name,
  484. m.category_name,
  485. ot.type AS template_type,
  486. (SELECT gs.goods_name FROM goods gs where 1 = 1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  487. (SELECT gs.code FROM goods gs where 1 = 1 and g.make_goods_id = gs.goods_id) as make_goods_code,
  488. (SELECT count(DISTINCT c.subject_id)
  489. FROM course c
  490. LEFT JOIN goods_course gc ON gc.course_id = c.course_id
  491. WHERE gc.goods_id = g.goods_id) as subject_num,
  492. (SELECT GROUP_CONCAT(subject_name)
  493. from course_subject
  494. where FIND_IN_SET(id, g.subject_ids)) subject_names
  495. FROM goods g
  496. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  497. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  498. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  499. LEFT JOIN course_business cb ON g.business_id = cb.id
  500. LEFT JOIN school s ON s.id = g.school_id
  501. LEFT JOIN major m ON g.major_id = m.id
  502. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  503. WHERE g.goods_id = #{goodsId}
  504. </select>
  505. <select id="listGoods" parameterType="com.zhongzheng.modules.exam.bo.ExamNumberGoodsQueryBo"
  506. resultMap="ExamNumberGoodsVoResult">
  507. SELECT
  508. goods_id,
  509. goods_name,
  510. validity_start_time,
  511. validity_end_time,
  512. goods_status,
  513. status,
  514. CODE,
  515. stand_price,
  516. <if test="filtration != null and filtration == 1">
  517. (case WHEN (SELECT COUNT(gs.goods_id) FROM goods gs where 1=1 and gs.make_goods_id = g.goods_id and
  518. gs.status =1 and gs.goods_type =4) >0 then 0 ELSE 1 end) as select_status
  519. </if>
  520. <if test="filtration != null and filtration == 2">
  521. (case WHEN (SELECT COUNT(gs.goods_id) FROM goods gs where 1=1 and gs.make_goods_id = g.goods_id and
  522. gs.status =1 and gs.goods_type =3) >0 then 0 ELSE 1 end) as select_status
  523. </if>
  524. FROM
  525. goods g
  526. WHERE
  527. 1 = 1
  528. and g.status in(1)
  529. and g.goods_type=1
  530. <if test="businessId != null and businessId != ''">
  531. and g.business_id = #{businessId}
  532. </if>
  533. <if test="goodsId != null and goodsId != ''">
  534. and g.goods_id = #{goodsId}
  535. </if>
  536. <if test="projectId != null and projectId != ''">
  537. and g.project_id = #{projectId}
  538. </if>
  539. <if test="goodsType != null and goodsType != ''">
  540. and g.goods_type = #{goodsType}
  541. </if>
  542. <if test="goodsStatus != null and goodsStatus != ''">
  543. and g.goods_status = #{goodsStatus}
  544. </if>
  545. <if test="searchKey != null and searchKey != ''">
  546. and (g.goods_name like concat('%', #{searchKey}, '%') or g.code like concat('%', #{searchKey}, '%'))
  547. </if>
  548. order by g.create_time desc
  549. </select>
  550. <select id="selectUserDetail" parameterType="map" resultMap="GoodsResultVo">
  551. SELECT g.*,
  552. ps.supply_name,
  553. cet.education_name,
  554. cpt.project_name,
  555. cb.business_name,
  556. cb.template_status AS special_goods,
  557. s.school_name,
  558. m.category_name,
  559. ot.type AS template_type,
  560. (SELECT gs.goods_name FROM goods gs where 1 = 1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  561. (SELECT gs.code FROM goods gs where 1 = 1 and g.make_goods_id = gs.goods_id) as make_goods_code,
  562. (SELECT DISTINCT cg.grade_id
  563. FROM class_grade_user cgu
  564. LEFT JOIN class_grade_goods cgg on cgg.grade_id = cgu.grade_id
  565. LEFT JOIN class_grade cg on cg.grade_id = cgu.grade_id
  566. where cgu.user_id = #{userId}
  567. and cgg.goods_id = g.goods_id
  568. and cg.`status` = 1
  569. and unix_timestamp(now()) BETWEEN cg.class_start_time and cg.class_end_time) as grade_id
  570. FROM goods g
  571. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  572. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  573. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  574. LEFT JOIN course_business cb ON g.business_id = cb.id
  575. LEFT JOIN school s ON s.id = g.school_id
  576. LEFT JOIN major m ON g.major_id = m.id
  577. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  578. WHERE g.goods_id = #{goodsId}
  579. </select>
  580. <select id="getQuestionNum" parameterType="Long" resultType="Long">
  581. SELECT count(DISTINCT question_id) question_num
  582. FROM exam_question
  583. WHERE find_in_set(
  584. exam_id, (
  585. SELECT concat(
  586. IFNULL((
  587. SELECT GROUP_CONCAT(exam_id)
  588. FROM question_chapter_exam
  589. WHERE FIND_IN_SET(chapter_exam_id,
  590. (SELECT concat(
  591. IFNULL(
  592. (SELECT GROUP_CONCAT(major_id) eids
  593. FROM goods_attached
  594. WHERE goods_id = #{goodsId}
  595. AND type = 2), ''),
  596. ',',
  597. IFNULL(
  598. (
  599. SELECT GROUP_CONCAT(chapter_exam_id) eids2
  600. FROM question_module_chapter
  601. WHERE module_exam_id IN
  602. (SELECT major_id
  603. FROM goods_attached
  604. WHERE goods_id = #{goodsId} AND type = 1)),
  605. ''
  606. ))))),
  607. ''
  608. ),
  609. ',',
  610. IFNULL((SELECT GROUP_CONCAT(major_id)
  611. FROM goods_attached
  612. WHERE goods_id = #{goodsId} AND type = 3), ''))))
  613. </select>
  614. <select id="getRandomQuestionNum" parameterType="map" resultType="Long">
  615. SELECT count(DISTINCT eq.question_id) question_num
  616. FROM exam_question eq
  617. LEFT JOIN exam e on eq.exam_id = e.exam_id
  618. WHERE find_in_set(
  619. eq.exam_id, (
  620. SELECT concat(
  621. IFNULL((
  622. SELECT GROUP_CONCAT(exam_id)
  623. FROM question_chapter_exam
  624. WHERE FIND_IN_SET(chapter_exam_id,
  625. (SELECT concat(
  626. IFNULL(
  627. (SELECT GROUP_CONCAT(major_id) eids
  628. FROM goods_attached
  629. WHERE goods_id = #{goodsId}
  630. AND type = 2), ''),
  631. ',',
  632. IFNULL(
  633. (
  634. SELECT GROUP_CONCAT(chapter_exam_id) eids2
  635. FROM question_module_chapter
  636. WHERE module_exam_id IN
  637. (SELECT major_id
  638. FROM goods_attached
  639. WHERE goods_id = #{goodsId} AND type = 1)),
  640. ''
  641. ))))),
  642. ''
  643. ),
  644. ',',
  645. IFNULL((SELECT GROUP_CONCAT(major_id)
  646. FROM goods_attached
  647. WHERE goods_id = #{goodsId} AND type = 3), ''))))
  648. and e.exam_paper_id = #{examPaperId}
  649. </select>
  650. <update id="queryUpGoods">
  651. update goods g
  652. set g.goods_status=0
  653. where unix_timestamp(now()) > g.validity_end_time
  654. and g.goods_status = 1
  655. </update>
  656. <select id="getExamNum" parameterType="Long" resultType="Long">
  657. SELECT count(exam_id) + ((
  658. SELECT count(major_id)
  659. FROM goods_attached
  660. WHERE goods_id = #{goodsId}
  661. AND type = 3
  662. )) AS exam_num
  663. FROM question_chapter_exam
  664. WHERE FIND_IN_SET(
  665. chapter_exam_id,
  666. (
  667. SELECT concat(
  668. IFNULL((SELECT GROUP_CONCAT(major_id) eids
  669. FROM goods_attached
  670. WHERE goods_id = #{goodsId} AND type = 2), ''),
  671. ',',
  672. IFNULL(
  673. (
  674. SELECT GROUP_CONCAT(chapter_exam_id) eids2
  675. FROM question_module_chapter
  676. WHERE module_exam_id IN (SELECT major_id
  677. FROM goods_attached
  678. WHERE goods_id = #{goodsId} AND type = 1)),
  679. ''
  680. ))))
  681. </select>
  682. <select id="getSectionNumByBo" parameterType="Long" resultMap="GoodsResultVo">
  683. SELECT (SELECT IFNULL(COUNT(m.id), 0) + (SELECT IFNULL(COUNT(n.id), 0)
  684. FROM course_chapter_section n
  685. LEFT JOIN course_module_chapter p on n.chapter_id = p.chapter_id
  686. LEFT JOIN course_menu m on m.menu_id = p.module_id
  687. LEFT JOIN goods_course gc on gc.course_id = m.course_id
  688. where gc.goods_id = g.goods_id
  689. and m.type in (1)) + (SELECT IFNULL(COUNT(n.id), 0)
  690. FROM course_chapter_section n
  691. LEFT JOIN course_menu m on m.menu_id = n.chapter_id
  692. LEFT JOIN goods_course gc on gc.course_id = m.course_id
  693. where gc.goods_id = g.goods_id
  694. and m.type in (2))
  695. FROM course_menu m
  696. LEFT JOIN goods_course gc on gc.course_id = m.course_id
  697. where gc.goods_id = g.goods_id
  698. and m.type in (3)) as section_num,
  699. (SELECT IFNULL(COUNT(1), 0) FROM goods_course gc where gc.goods_id = g.goods_id) as course_num,
  700. (SELECT IFNULL(COUNT(m.id), 0)
  701. FROM goods_course c
  702. LEFT JOIN course_menu_exam m ON m.course_id = c.course_id
  703. where m.type = 1
  704. and c.goods_id = g.goods_id) as exam_num
  705. FROM goods g
  706. WHERE g.goods_id = #{goodsId}
  707. </select>
  708. <select id="getOrderGoodsListByUser" parameterType="Long"
  709. resultType="com.zhongzheng.modules.goods.vo.UserGoodsListVo">
  710. SELECT og.goods_id AS goodsId,
  711. og.order_goods_id as orderGoodsId,
  712. o.order_id as orderId,
  713. g.goods_name as categoryName,
  714. m.category_name as majorName,
  715. o.tenant_id as tenantId,
  716. g.goods_type as courseType,
  717. concat('https://file.xyyxt.net/', g.cover_url) as imageUrl,
  718. o.create_time as createTimeStr,
  719. og.grade_id as gradeId
  720. FROM `order` o
  721. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  722. LEFT JOIN goods g ON og.goods_id = g.goods_id
  723. LEFT JOIN major m ON g.major_id = m.id
  724. WHERE o.user_id = #{userId}
  725. AND og.pay_status IN (2, 3, 4)
  726. AND og.refund_status !=2
  727. </select>
  728. <select id="countUserOrderGoods" parameterType="Long" resultType="com.zhongzheng.modules.goods.vo.UserOrderGoodsVo">
  729. SELECT og.order_goods_id,
  730. og.goods_id,
  731. og.grade_id
  732. FROM `order` o
  733. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  734. WHERE o.user_id = #{userId}
  735. AND og.goods_id = #{goodsId}
  736. AND og.pay_status IN (2, 3, 4)
  737. AND og.refund_status != 2
  738. AND o.tenant_id = #{tenantId}
  739. AND og.tenant_id = #{tenantId}
  740. </select>
  741. <select id="queryGoodsByIdTenant" parameterType="map" resultType="com.zhongzheng.modules.goods.domain.Goods">
  742. SELECT *
  743. FROM `goods`
  744. WHERE goods_id = #{goodsId}
  745. AND tenant_id = #{tenantId}
  746. </select>
  747. <select id="queryGoodsByTenant" parameterType="map" resultType="com.zhongzheng.modules.goods.domain.Goods">
  748. SELECT *
  749. FROM `goods`
  750. WHERE `code` = #{code}
  751. AND tenant_id = #{tenantId}
  752. </select>
  753. <update id="updateByTenant" parameterType="com.zhongzheng.modules.goods.domain.Goods">
  754. UPDATE goods
  755. SET `year` = #{year},
  756. supply_id = #{supplyId},
  757. goods_type = #{goodsType},
  758. education_type_id = #{educationTypeId},
  759. business_id = #{businessId},
  760. school_id = #{schoolId},
  761. major_id = #{majorId},
  762. goods_name = #{goodsName},
  763. stand_price = #{standPrice},
  764. lowest_price = #{lowestPrice},
  765. create_time = #{createTime},
  766. update_time = #{updateTime},
  767. `status` = #{status},
  768. validity_start_time = #{validityStartTime},
  769. validity_end_time = #{validityEndTime},
  770. study_start_time = #{studyStartTime},
  771. study_end_time = #{studyEndTime},
  772. certificate_ids = #{certificateIds},
  773. introduce = #{introduce},
  774. suitable_object = #{suitableObject},
  775. buy_note = #{buyNote},
  776. pc_detail_html = #{pcDetailHtml},
  777. mobile_detail_html = #{mobileDetailHtml},
  778. goods_status = #{goodsStatus},
  779. cover_url = #{coverUrl},
  780. class_hours = #{classHours},
  781. stand_price_json = #{standPriceJson},
  782. tenant_id = #{tenantId},
  783. `code` = #{code},
  784. project_id = #{projectId},
  785. goods_audition_config = #{goodsAuditionConfig},
  786. goods_photograph_config = #{goodsPhotographConfig},
  787. goods_play_config = #{goodsPlayConfig},
  788. goods_exam_config = #{goodsExamConfig},
  789. handouts_id = #{handoutsId},
  790. make_start_time = #{makeStartTime},
  791. make_end_time = #{makeEndTime},
  792. study_count = #{studyCount},
  793. goods_photo_exam_config = #{goodsPhotoExamConfig},
  794. make_goods_id = #{makeGoodsId},
  795. service_time_type = #{serviceTimeType},
  796. service_time_num = #{serviceTimeNum},
  797. section_max_num = #{sectionMaxNum},
  798. exam_number = #{examNumber},
  799. do_number = #{doNumber},
  800. teacher_id = #{teacherId},
  801. subject_ids = #{subjectIds},
  802. certificate_type_id = #{certificateTypeId},
  803. certificate_id = #{certificateId},
  804. certificate_tp_id = #{certificateTpId},
  805. line_price = #{linePrice},
  806. spec_template_id = #{specTemplateId},
  807. show_status = #{showStatus},
  808. show_sort = #{showSort}
  809. WHERE goods_id = #{goodsId}
  810. and tenant_id = #{tenantId}
  811. </update>
  812. <select id="getUserGoodsListAll" parameterType="com.zhongzheng.modules.goods.bo.UserGoodsListAllBo"
  813. resultType="com.zhongzheng.modules.goods.vo.GoodsListAllVo">
  814. SELECT
  815. o.order_id,
  816. og.order_goods_id,
  817. g.goods_id,
  818. g.goods_name,
  819. g.goods_type,
  820. g.class_hours,
  821. g.validity_start_time,
  822. g.validity_end_time,
  823. g.study_start_time AS serviceStartTime,
  824. g.study_end_time AS serviceEndTime,
  825. cg.class_status,
  826. cg.class_start_time,
  827. cg.class_end_time
  828. FROM
  829. order_goods og
  830. LEFT JOIN `order` o ON og.order_sn = o.order_sn
  831. LEFT JOIN goods g ON og.goods_id = g.goods_id
  832. LEFT JOIN class_grade cg ON og.grade_id = cg.grade_id
  833. WHERE
  834. og.pay_status IN ( 2, 3, 4 )
  835. AND og.refund_status != 2
  836. <if test="goodsName != null and goodsName != ''">
  837. AND g.goods_name like concat('%', #{goodsName}, '%')
  838. </if>
  839. <if test="educationTypeId != null and educationTypeId != ''">
  840. AND g.education_type_id = #{educationTypeId}
  841. </if>
  842. <if test="businessId != null and businessId != ''">
  843. AND g.business_id = #{businessId}
  844. </if>
  845. <if test="userId != null and userId != ''">
  846. AND o.user_id = #{userId}
  847. </if>
  848. </select>
  849. <select id="getCourseExamNum" parameterType="java.lang.Long" resultType="java.lang.Long">
  850. SELECT
  851. COUNT(*)
  852. FROM
  853. course_menu_exam cme
  854. LEFT JOIN goods_course gc ON cme.course_id = gc.course_id
  855. WHERE
  856. cme.type != 2
  857. AND gc.goods_id = #{goodsId}
  858. </select>
  859. </mapper>