GoodsMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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="subjectNum" column="subject_num"/>
  96. </resultMap>
  97. <resultMap type="com.zhongzheng.modules.exam.vo.ExamNumberGoodsVo" id="ExamNumberGoodsVoResult">
  98. <result property="id" column="id"/>
  99. <result property="examNumberId" column="exam_number_id"/>
  100. <result property="goodsId" column="goods_id"/>
  101. <result property="goodsName" column="goods_name"/>
  102. <result property="code" column="code"/>
  103. <result property="standPrice" column="stand_price"/>
  104. <result property="goodsStatus" column="goods_status"/>
  105. </resultMap>
  106. <select id="selectList" parameterType="com.zhongzheng.modules.goods.bo.GoodsQueryBo" resultMap="GoodsResultVo">
  107. SELECT
  108. g.*,
  109. ps.supply_name,
  110. cet.education_name,
  111. cpt.project_name,
  112. cb.business_name,
  113. s.school_name,
  114. m.category_name,
  115. ot.type AS template_type,
  116. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  117. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code
  118. <if test="goodsType ==1">
  119. , IFNULL(gs.subject_num,0) as subject_num
  120. </if>
  121. FROM
  122. goods g
  123. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  124. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  125. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  126. LEFT JOIN course_business cb ON g.business_id = cb.id
  127. LEFT JOIN school s ON s.id = g.school_id
  128. LEFT JOIN major m ON g.major_id = m.id
  129. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  130. <if test="goodsType ==1">
  131. LEFT JOIN (SELECT
  132. IFNULL(count(DISTINCT c.subject_id ),0) subject_num,
  133. gc.goods_id
  134. FROM
  135. goods g
  136. LEFT JOIN goods_course gc ON g.goods_id = gc.course_id
  137. LEFT JOIN course c ON gc.course_id = c.course_id
  138. GROUP BY
  139. gc.goods_id) gs on g.goods_id = gs.goods_id
  140. </if>
  141. <if test="goodsType ==1 and subjectId >0">
  142. LEFT JOIN goods_course gc ON gc.goods_id = g.goods_id
  143. LEFT JOIN course c ON gc.course_id = c.course_id
  144. </if>
  145. <if test="goodsType ==2 and subjectId >0">
  146. LEFT JOIN goods_attached ga on g.goods_id = ga.goods_id
  147. LEFT JOIN question_business qb on ga.major_id = qb.major_id
  148. </if>
  149. WHERE
  150. 1 = 1
  151. <if test="status != null and status.size()!=0 ">
  152. AND g.status in
  153. <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
  154. #{item}
  155. </foreach>
  156. </if>
  157. <if test="goodsIds != null and goodsIds.size()!=0 ">
  158. AND g.goods_id in
  159. <foreach collection="goodsIds" item="item" index="index" open="(" close=")" separator=",">
  160. #{item}
  161. </foreach>
  162. </if>
  163. <if test="goodsType != null and goodsType != ''">
  164. AND g.goods_type = #{goodsType}
  165. </if>
  166. <if test="makeGoodsId != null and makeGoodsId != ''">
  167. AND g.make_goods_id = #{makeGoodsId}
  168. </if>
  169. <if test="goodsName != null and goodsName != ''">
  170. AND g.goods_name like concat('%', #{goodsName}, '%')
  171. </if>
  172. <if test="educationTypeId != null and educationTypeId != ''">
  173. AND g.education_type_id = #{educationTypeId}
  174. </if>
  175. <if test="businessIds != null and businessIds.size()!=0 ">
  176. AND g.business_id in
  177. <foreach collection="businessIds" item="item" index="index" open="(" close=")" separator=",">
  178. #{item}
  179. </foreach>
  180. </if>
  181. <if test="businessId != null and businessId != ''">
  182. AND g.business_id = #{businessId}
  183. </if>
  184. <if test="schoolId != null and schoolId != ''">
  185. AND g.school_id = #{schoolId}
  186. </if>
  187. <if test="majorId != null and majorId != ''">
  188. AND g.major_id = #{majorId}
  189. </if>
  190. <if test="goodsStatus != null ">
  191. AND g.goods_status = #{goodsStatus}
  192. </if>
  193. <if test="studyStartTime != null and studyStartTime != '' and studyEndTime != null and studyEndTime != ''">
  194. and #{studyStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{studyEndTime} BETWEEN g.validity_start_time and g.validity_end_time
  195. </if>
  196. <if test="validityStartTime != null or validityEndTime != null ">
  197. AND (#{validityStartTime} BETWEEN g.validity_start_time and g.validity_end_time or #{validityEndTime} BETWEEN g.validity_start_time and g.validity_end_time)
  198. </if>
  199. <if test="goodsType ==1 and subjectId >0">
  200. AND c.`status` = 1
  201. AND c.subject_id = #{subjectId}
  202. </if>
  203. <if test="goodsType ==2 and subjectId >0">
  204. AND ((
  205. qb.type = 4
  206. AND ga.type = 1
  207. )
  208. OR ( qb.type = 3 AND ga.type = 2 )
  209. OR ( qb.type = 2 AND ga.type = 3 )) AND qb.subject_id = #{subjectId}
  210. </if>
  211. ORDER BY g.create_time DESC
  212. </select>
  213. <select id="selectDetail" parameterType="Long" resultMap="GoodsResultVo">
  214. SELECT
  215. g.*,
  216. ps.supply_name,
  217. cet.education_name,
  218. cpt.project_name,
  219. cb.business_name,
  220. s.school_name,
  221. m.category_name,
  222. ot.type AS template_type,
  223. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  224. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code,
  225. (SELECT
  226. count( DISTINCT c.subject_id )
  227. FROM
  228. course c
  229. LEFT JOIN goods_course gc ON gc.course_id = c.course_id
  230. WHERE
  231. gc.goods_id = g.goods_id) as subject_num
  232. FROM
  233. goods g
  234. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  235. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  236. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  237. LEFT JOIN course_business cb ON g.business_id = cb.id
  238. LEFT JOIN school s ON s.id = g.school_id
  239. LEFT JOIN major m ON g.major_id = m.id
  240. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  241. WHERE
  242. g.goods_id = #{goodsId}
  243. </select>
  244. <select id="listGoods" parameterType="com.zhongzheng.modules.exam.bo.ExamNumberGoodsQueryBo" resultMap="ExamNumberGoodsVoResult">
  245. SELECT
  246. goods_id,
  247. goods_name,
  248. CODE,
  249. stand_price,
  250. <if test="filtration != null and filtration == 1">
  251. (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 goods_status
  252. </if>
  253. <if test="filtration != null and filtration == 2">
  254. (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 goods_status
  255. </if>
  256. FROM
  257. goods g
  258. WHERE
  259. 1 = 1
  260. and g.status in(1)
  261. and g.goods_type=1
  262. <if test="businessId != null and businessId != ''">
  263. and g.business_id = #{businessId}
  264. </if>
  265. <if test="goodsId != null and goodsId != ''">
  266. and g.goods_id = #{goodsId}
  267. </if>
  268. <if test="projectId != null and projectId != ''">
  269. and g.project_id = #{projectId}
  270. </if>
  271. <if test="goodsType != null and goodsType != ''">
  272. and g.goods_type = #{goodsType}
  273. </if>
  274. <if test="goodsStatus != null and goodsStatus != ''">
  275. and g.goods_status = #{goodsStatus}
  276. </if>
  277. order by g.create_time desc
  278. </select>
  279. <select id="selectUserDetail" parameterType="map" resultMap="GoodsResultVo">
  280. SELECT
  281. g.*,
  282. ps.supply_name,
  283. cet.education_name,
  284. cpt.project_name,
  285. cb.business_name,
  286. s.school_name,
  287. m.category_name,
  288. ot.type AS template_type,
  289. (SELECT gs.goods_name FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_name,
  290. (SELECT gs.code FROM goods gs where 1=1 and g.make_goods_id = gs.goods_id) as make_goods_code,
  291. (SELECT 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
  292. 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
  293. FROM
  294. goods g
  295. LEFT JOIN pay_supply ps ON g.supply_id = ps.supply_id
  296. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  297. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  298. LEFT JOIN course_business cb ON g.business_id = cb.id
  299. LEFT JOIN school s ON s.id = g.school_id
  300. LEFT JOIN major m ON g.major_id = m.id
  301. LEFT JOIN order_input_template ot ON cb.template_status = ot.id
  302. WHERE
  303. g.goods_id = #{goodsId}
  304. </select>
  305. <select id="getQuestionNum" parameterType="Long" resultType="Long">
  306. SELECT
  307. count( question_id ) question_num
  308. FROM
  309. exam_question
  310. WHERE
  311. find_in_set(
  312. exam_id,(
  313. SELECT
  314. concat(
  315. IFNULL((
  316. SELECT
  317. GROUP_CONCAT( exam_id )
  318. FROM
  319. question_chapter_exam
  320. WHERE
  321. chapter_exam_id IN (
  322. SELECT
  323. concat(
  324. IFNULL(( SELECT GROUP_CONCAT( major_id ) eids FROM goods_attached WHERE goods_id = #{goodsId} AND type = 2 ), '' ),
  325. ',',
  326. IFNULL(
  327. (
  328. SELECT
  329. GROUP_CONCAT( chapter_exam_id ) eids2
  330. FROM
  331. question_module_chapter
  332. WHERE
  333. module_exam_id IN ( SELECT major_id FROM goods_attached WHERE goods_id = #{goodsId} AND type = 1 )),
  334. ''
  335. )))),
  336. ''
  337. ),
  338. ',',
  339. IFNULL(( SELECT GROUP_CONCAT( major_id ) FROM goods_attached WHERE goods_id = #{goodsId} AND type = 3 ), '' ))))
  340. </select>
  341. <update id="queryUpGoods">
  342. update goods g set g.goods_status=0 where unix_timestamp(now()) > g.validity_end_time and g.goods_status = 1
  343. </update>
  344. </mapper>