GoodsMapper.xml 47 KB

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