GoodsMapper.xml 49 KB

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