GoodsMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. </resultMap>
  46. <resultMap type="com.zhongzheng.modules.goods.vo.GoodsVo" id="GoodsResultVo">
  47. <result property="goodsId" column="goods_id"/>
  48. <result property="year" column="year"/>
  49. <result property="supplyId" column="supply_id"/>
  50. <result property="goodsType" column="goods_type"/>
  51. <result property="gradeId" column="grade_id"/>
  52. <result property="educationTypeId" column="education_type_id"/>
  53. <result property="businessId" column="business_id"/>
  54. <result property="schoolId" column="school_id"/>
  55. <result property="majorId" column="major_id"/>
  56. <result property="goodsName" column="goods_name"/>
  57. <result property="standPrice" column="stand_price"/>
  58. <result property="lowestPrice" column="lowest_price"/>
  59. <result property="createTime" column="create_time"/>
  60. <result property="updateTime" column="update_time"/>
  61. <result property="status" column="status"/>
  62. <result property="validityStartTime" column="validity_start_time"/>
  63. <result property="validityEndTime" column="validity_end_time"/>
  64. <result property="studyStartTime" column="study_start_time"/>
  65. <result property="studyEndTime" column="study_end_time"/>
  66. <result property="certificateIds" column="certificate_ids"/>
  67. <result property="introduce" column="introduce"/>
  68. <result property="suitableObject" column="suitable_object"/>
  69. <result property="buyNote" column="buy_note"/>
  70. <result property="pcDetailHtml" column="pc_detail_html"/>
  71. <result property="mobileDetailHtml" column="mobile_detail_html"/>
  72. <result property="goodsStatus" column="goods_status"/>
  73. <result property="coverUrl" column="cover_url"/>
  74. <result property="classHours" column="class_hours"/>
  75. <result property="standPriceJson" column="stand_price_json"/>
  76. <result property="code" column="code"/>
  77. <result property="projectId" column="project_id"/>
  78. <result property="goodsAuditionConfig" column="goods_audition_config"/>
  79. <result property="goodsPhotographConfig" column="goods_photograph_config"/>
  80. <result property="goodsAuditionExamConfig" column="goods_audition_exam_config"/>
  81. <result property="goodsPlayConfig" column="goods_play_config"/>
  82. <result property="goodsExamConfig" column="goods_exam_config"/>
  83. <result property="supplyName" column="supply_name"/>
  84. <result property="educationName" column="education_name"/>
  85. <result property="projectName" column="project_name"/>
  86. <result property="businessName" column="business_name"/>
  87. <result property="schoolName" column="school_name"/>
  88. <result property="categoryName" column="category_name"/>
  89. <result property="handoutsId" column="handouts_id"/>
  90. <result property="templateType" column="template_type"/>
  91. <result property="period" column="period"/>
  92. <result property="makeStartTime" column="make_start_time"/>
  93. <result property="makeEndTime" column="make_end_time"/>
  94. <result property="studyCount" column="study_count"/>
  95. <result property="makeGoodsName" column="make_goods_name"/>
  96. <result property="makeGoodsCode" column="make_goods_code"/>
  97. <result property="courseNum" column="course_num"/>
  98. <result property="sectionNum" column="section_num"/>
  99. <result property="serviceTimeType" column="service_time_type"/>
  100. <result property="serviceTimeNum" column="service_time_num"/>
  101. <result property="gradeNum" column="grade_num"/>
  102. </resultMap>
  103. <resultMap type="com.zhongzheng.modules.exam.vo.ExamNumberGoodsVo" id="ExamNumberGoodsVoResult">
  104. <result property="id" column="id"/>
  105. <result property="examNumberId" column="exam_number_id"/>
  106. <result property="goodsId" column="goods_id"/>
  107. <result property="goodsName" column="goods_name"/>
  108. <result property="code" column="code"/>
  109. <result property="standPrice" column="stand_price"/>
  110. <result property="goodsStatus" column="goods_status"/>
  111. <result property="validityStartTime" column="validity_start_time"/>
  112. <result property="validityEndTime" column="validity_end_time"/>
  113. <result property="goodsStatus" column="goods_status"/>
  114. <result property="status" column="status"/>
  115. <result property="selectStatus" column="select_status"/>
  116. </resultMap>
  117. <select id="selectList" parameterType="com.zhongzheng.modules.goods.bo.GoodsQueryBo" resultMap="GoodsResultVo">
  118. SELECT
  119. g.*,
  120. ps.supply_name,
  121. cet.education_name,
  122. cpt.project_name,
  123. cb.business_name,
  124. s.school_name,
  125. m.category_name,
  126. ot.type AS template_type,
  127. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  128. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code
  129. <if test="sectionNum ==1">
  130. ,(SELECT COUNT(m.id)+(SELECT COUNT(n.id) FROM course_chapter_section n LEFT JOIN course_module_chapter p on n.chapter_id = p.chapter_id LEFT JOIN course_menu m on m.menu_id = p.module_id LEFT JOIN goods_course gc on gc.course_id = m.course_id where gc.goods_id = g.goods_id and m.type in(1))+(SELECT COUNT(n.id) FROM course_chapter_section n LEFT JOIN course_menu m on m.menu_id = n.chapter_id LEFT JOIN goods_course gc on gc.course_id = m.course_id where gc.goods_id = g.goods_id and m.type in(2)) FROM course_menu m LEFT JOIN goods_course gc on gc.course_id = m.course_id where gc.goods_id = g.goods_id and m.type in(3)) as section_num
  131. </if>
  132. <if test="goodsType ==1">
  133. , (SELECT count(*) FROM goods_course where goods_id =g.goods_id ) as course_num
  134. , (SELECT count(*) FROM class_grade_goods where goods_id =g.goods_id ) as grade_num
  135. </if>
  136. FROM
  137. goods g
  138. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  139. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  140. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  141. LEFT JOIN course_business cb ON g.business_id = cb.id
  142. LEFT JOIN school s ON s.id = g.school_id
  143. LEFT JOIN major m ON g.major_id = m.id
  144. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  145. WHERE
  146. 1 = 1
  147. <if test="status != null and status.size()!=0 ">
  148. AND g.status in
  149. <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
  150. #{item}
  151. </foreach>
  152. </if>
  153. <if test="goodsIds != null and goodsIds.size()!=0 ">
  154. AND g.goods_id in
  155. <foreach collection="goodsIds" item="item" index="index" open="(" close=")" separator=",">
  156. #{item}
  157. </foreach>
  158. </if>
  159. <if test="goodsType != null and goodsType != ''">
  160. AND g.goods_type = #{goodsType}
  161. </if>
  162. <if test="makeGoodsId != null and makeGoodsId != ''">
  163. AND g.make_goods_id = #{makeGoodsId}
  164. </if>
  165. <if test="goodsName != null and goodsName != ''">
  166. AND g.goods_name like concat('%', #{goodsName}, '%')
  167. </if>
  168. <if test="educationTypeId != null and educationTypeId != ''">
  169. AND g.education_type_id = #{educationTypeId}
  170. </if>
  171. <if test="businessIds != null and businessIds.size()!=0 ">
  172. AND g.business_id in
  173. <foreach collection="businessIds" item="item" index="index" open="(" close=")" separator=",">
  174. #{item}
  175. </foreach>
  176. </if>
  177. <if test="businessId != null and businessId != ''">
  178. AND g.business_id = #{businessId}
  179. </if>
  180. <if test="schoolId != null and schoolId != ''">
  181. AND g.school_id = #{schoolId}
  182. </if>
  183. <if test="majorId != null and majorId != ''">
  184. AND g.major_id = #{majorId}
  185. </if>
  186. <if test="searchKey != null and searchKey != ''">
  187. and (g.goods_name like concat('%', #{searchKey}, '%') or g.code like concat('%', #{searchKey}, '%'))
  188. </if>
  189. <if test="goodsStatus != null ">
  190. AND g.goods_status = #{goodsStatus}
  191. </if>
  192. <if test="studyStartTime != null and studyStartTime != '' and studyEndTime != null and studyEndTime != ''">
  193. and #{studyStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{studyEndTime} BETWEEN g.validity_start_time and g.validity_end_time
  194. </if>
  195. <if test="validityStartTime != null or validityEndTime != null ">
  196. AND (#{validityStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{validityEndTime} BETWEEN g.validity_start_time and g.validity_end_time)
  197. </if>
  198. <if test="goodsType ==1 and subjectId >0">
  199. AND (SELECT count(*) from goods_course gc LEFT JOIN course c ON gc.course_id = c.course_id where gc.goods_id = g.goods_id and c.`status` = 1
  200. AND c.subject_id = #{subjectId}) >0
  201. </if>
  202. <if test="goodsType ==2 and subjectId >0">
  203. AND g.goods_id in(
  204. SELECT
  205. ga.goods_id
  206. FROM
  207. goods_attached ga
  208. LEFT JOIN question_business qb ON ga.major_id = qb.major_id
  209. WHERE
  210. ((
  211. qb.type = 4
  212. AND ga.type = 1
  213. )
  214. OR ( qb.type = 3 AND ga.type = 2 )
  215. OR ( qb.type = 2 AND ga.type = 3 ))
  216. AND qb.subject_id = #{subjectId}
  217. )
  218. </if>
  219. ORDER BY g.create_time DESC
  220. </select>
  221. <select id="selectDetail" parameterType="Long" resultMap="GoodsResultVo">
  222. SELECT
  223. g.*,
  224. ps.supply_name,
  225. cet.education_name,
  226. cpt.project_name,
  227. cb.business_name,
  228. s.school_name,
  229. m.category_name,
  230. ot.type AS template_type,
  231. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  232. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code,
  233. (SELECT
  234. count( DISTINCT c.subject_id )
  235. FROM
  236. course c
  237. LEFT JOIN goods_course gc ON gc.course_id = c.course_id
  238. WHERE
  239. gc.goods_id = g.goods_id) as subject_num
  240. FROM
  241. goods g
  242. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  243. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  244. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  245. LEFT JOIN course_business cb ON g.business_id = cb.id
  246. LEFT JOIN school s ON s.id = g.school_id
  247. LEFT JOIN major m ON g.major_id = m.id
  248. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  249. WHERE
  250. g.goods_id = #{goodsId}
  251. </select>
  252. <select id="listGoods" parameterType="com.zhongzheng.modules.exam.bo.ExamNumberGoodsQueryBo" resultMap="ExamNumberGoodsVoResult">
  253. SELECT
  254. goods_id,
  255. goods_name,
  256. validity_start_time,
  257. validity_end_time,
  258. goods_status,
  259. status,
  260. CODE,
  261. stand_price,
  262. <if test="filtration != null and filtration == 1">
  263. (case WHEN (SELECT COUNT(gs.goods_id) FROM goods gs where 1=1 and gs.make_goods_id = g.goods_id and gs.status =1 and gs.goods_type =4) >0 then 0 ELSE 1 end) as select_status
  264. </if>
  265. <if test="filtration != null and filtration == 2">
  266. (case WHEN (SELECT COUNT(gs.goods_id) FROM goods gs where 1=1 and gs.make_goods_id = g.goods_id and gs.status =1 and gs.goods_type =3) >0 then 0 ELSE 1 end) as select_status
  267. </if>
  268. FROM
  269. goods g
  270. WHERE
  271. 1 = 1
  272. and g.status in(1)
  273. and g.goods_type=1
  274. <if test="businessId != null and businessId != ''">
  275. and g.business_id = #{businessId}
  276. </if>
  277. <if test="goodsId != null and goodsId != ''">
  278. and g.goods_id = #{goodsId}
  279. </if>
  280. <if test="projectId != null and projectId != ''">
  281. and g.project_id = #{projectId}
  282. </if>
  283. <if test="goodsType != null and goodsType != ''">
  284. and g.goods_type = #{goodsType}
  285. </if>
  286. <if test="goodsStatus != null and goodsStatus != ''">
  287. and g.goods_status = #{goodsStatus}
  288. </if>
  289. <if test="searchKey != null and searchKey != ''">
  290. and (g.goods_name like concat('%', #{searchKey}, '%') or g.code like concat('%', #{searchKey}, '%'))
  291. </if>
  292. order by g.create_time desc
  293. </select>
  294. <select id="selectUserDetail" parameterType="map" resultMap="GoodsResultVo">
  295. SELECT
  296. g.*,
  297. ps.supply_name,
  298. cet.education_name,
  299. cpt.project_name,
  300. cb.business_name,
  301. s.school_name,
  302. m.category_name,
  303. ot.type AS template_type,
  304. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  305. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code,
  306. (SELECT DISTINCT cg.grade_id FROM class_grade_user cgu LEFT JOIN class_grade_goods cgg on cgg.grade_id = cgu.grade_id LEFT JOIN class_grade cg on cg.grade_id = cgu.grade_id
  307. where cgu.user_id = #{userId} and cgg.goods_id=g.goods_id and cg.`status` =1 and unix_timestamp(now()) BETWEEN cg.class_start_time and cg.class_end_time) as grade_id
  308. FROM
  309. goods g
  310. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  311. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  312. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  313. LEFT JOIN course_business cb ON g.business_id = cb.id
  314. LEFT JOIN school s ON s.id = g.school_id
  315. LEFT JOIN major m ON g.major_id = m.id
  316. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  317. WHERE
  318. g.goods_id = #{goodsId}
  319. </select>
  320. <select id="getQuestionNum" parameterType="Long" resultType="Long">
  321. SELECT
  322. count( question_id ) question_num
  323. FROM
  324. exam_question
  325. WHERE
  326. find_in_set(
  327. exam_id,(
  328. SELECT
  329. concat(
  330. IFNULL((
  331. SELECT
  332. GROUP_CONCAT( exam_id )
  333. FROM
  334. question_chapter_exam
  335. WHERE
  336. FIND_IN_SET(chapter_exam_id,
  337. (SELECT
  338. concat(
  339. IFNULL(( SELECT GROUP_CONCAT( major_id ) eids FROM goods_attached WHERE goods_id = #{goodsId} AND type = 2 ), '' ),
  340. ',',
  341. IFNULL(
  342. (
  343. SELECT
  344. GROUP_CONCAT( chapter_exam_id ) eids2
  345. FROM
  346. question_module_chapter
  347. WHERE
  348. module_exam_id IN ( SELECT major_id FROM goods_attached WHERE goods_id = #{goodsId} AND type = 1 )),
  349. ''
  350. ))))),
  351. ''
  352. ),
  353. ',',
  354. IFNULL(( SELECT GROUP_CONCAT( major_id ) FROM goods_attached WHERE goods_id = #{goodsId} AND type = 3 ), '' ))))
  355. </select>
  356. <update id="queryUpGoods">
  357. update goods g set g.goods_status=0 where unix_timestamp(now()) > g.validity_end_time and g.goods_status = 1
  358. </update>
  359. </mapper>