GoodsMapper.xml 19 KB

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