SubjectMapper.xml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.yonge.cooleshow.biz.dal.dao.SubjectDao">
  8. <resultMap type="com.yonge.cooleshow.biz.dal.entity.Subject" id="Subject">
  9. <result column="id_" property="id"/>
  10. <result column="cbs_subject_id_" property="cbsSubjectId"/>
  11. <result column="name_" property="name"/>
  12. <result column="code_" property="code"/>
  13. <result column="parent_subject_id_" property="parentSubjectId"/>
  14. <result column="img_" property="img"/>
  15. <result column="ai_default_frequency_" property="aiDefaultFrequency"/>
  16. <result column="desc_" property="desc"/>
  17. <result column="create_time_" property="createTime"/>
  18. <result column="update_time_" property="updateTime"/>
  19. <result column="del_flag_" property="delFlag"/>
  20. </resultMap>
  21. <!-- 根据主键查询一条记录 -->
  22. <select id="get" resultMap="Subject">
  23. SELECT * FROM subject WHERE del_flag_ = 0 and id_ = #{id}
  24. </select>
  25. <!-- 全查询 -->
  26. <select id="findAll" resultMap="Subject">
  27. SELECT * FROM subject where del_flag_ = 0 ORDER BY id_
  28. </select>
  29. <select id="subjectSelect" resultType="com.yonge.cooleshow.biz.dal.entity.Subject">
  30. select t.* from subject t
  31. join (
  32. select a.subject_id_ from (
  33. <trim prefixOverrides="union all">
  34. <if test="type == null or type =='MUSIC'">
  35. union all
  36. (select a.music_subject_ as subject_id_ from music_sheet a
  37. where a.del_flag_ = 0 and a.state_ = 1
  38. GROUP BY a.music_subject_)
  39. </if>
  40. <if test="type == null or type =='ALBUM'">
  41. union all
  42. (SELECT cm.subject_id_ from music_album cm WHERE cm.album_status_ = 1 and cm.del_flag_ = 0 GROUP BY cm.subject_id_)
  43. </if>
  44. <if test="type == null or type =='VIDEO'">
  45. union all
  46. (select a.lesson_subject_ as subject_id_ from video_lesson_group a
  47. where a.audit_status_ = 'PASS' and a.shelves_flag_ = 1
  48. GROUP BY a.lesson_subject_)
  49. </if>
  50. <if test="type == null or type =='PIANO_ROOM'">
  51. union all
  52. (select a.subject_id_ as subject_id_ from course_group a
  53. where a.type_ = 'PIANO_ROOM_CLASS' and a.status_ in ('ING','COMPLETE','APPLY')
  54. GROUP BY a.subject_id_)
  55. </if>
  56. <if test="type == null or type =='PRACTICE'">
  57. union all
  58. (select a.subject_id_ as subject_id_ from course_group a
  59. where a.type_ = 'PRACTICE' and a.status_ in ('ING','COMPLETE','APPLY')
  60. GROUP BY a.subject_id_)
  61. </if>
  62. <if test="type == null or type =='LIVE'">
  63. union all
  64. (select a.subject_id_ as subject_id_ from course_group a
  65. where a.type_ = 'LIVE' and a.status_ in ('APPLY')
  66. GROUP BY a.subject_id_)
  67. </if>
  68. </trim>
  69. ) a group by a.subject_id_
  70. ) a on t.id_ = a.subject_id_
  71. where t.parent_subject_id_ != 0
  72. </select>
  73. <!-- 向数据库增加一条记录 -->
  74. <insert id="insert" parameterType="com.yonge.cooleshow.biz.dal.entity.Subject" useGeneratedKeys="true"
  75. keyColumn="id"
  76. keyProperty="id">
  77. INSERT INTO subject (id_,name_,code_,parent_subject_id_,img_,create_time_,update_time_,desc_,ai_default_frequency_,cbs_subject_id_)
  78. VALUES(#{id},#{name},#{code},#{parentSubjectId},#{img},now(),now(),#{desc},#{aiDefaultFrequency},#{cbsSubjectId})
  79. </insert>
  80. <!-- 根据主键查询一条记录 -->
  81. <update id="update" parameterType="com.yonge.cooleshow.biz.dal.entity.Subject">
  82. UPDATE subject
  83. <set>
  84. <if test="cbsSubjectId != null">
  85. cbs_subject_id_ = #{cbsSubjectId},
  86. </if>
  87. <if test="delFlag != null">
  88. del_flag_ = #{delFlag},
  89. </if>
  90. <if test="parentSubjectId != null">
  91. parent_subject_id_ = #{parentSubjectId},
  92. </if>
  93. <if test="code != null">
  94. code_ = #{code},
  95. </if>
  96. <if test="img != null">
  97. img_ = #{img},
  98. </if>
  99. <if test="updateTime != null">
  100. update_time_ = NOW(),
  101. </if>
  102. <if test="name != null">
  103. name_ = #{name},
  104. </if>
  105. <if test="desc != null">
  106. desc_ = #{desc},
  107. </if>
  108. <if test="aiDefaultFrequency != null">
  109. ai_default_frequency_ = #{aiDefaultFrequency},
  110. </if>
  111. </set>
  112. WHERE id_ = #{id}
  113. </update>
  114. <!-- 根据主键删除一条记录 -->
  115. <update id="delete">
  116. UPDATE `subject` SET del_flag_ = 1 WHERE id_ = #{id} OR parent_subject_id_ = #{id}
  117. </update>
  118. <delete id="deleteById">
  119. update subject set del_flag_ = 1 where id_ = #{id}
  120. </delete>
  121. <!-- 分页查询 -->
  122. <select id="queryPage" resultMap="Subject" parameterType="map">
  123. SELECT * FROM subject
  124. <include refid="querySubPageSql"/>
  125. ORDER BY id_
  126. <include refid="global.limit"/>
  127. </select>
  128. <!-- 查询当前表的总记录数 -->
  129. <select id="queryCount" resultType="int">
  130. SELECT COUNT(*) FROM subject
  131. <include refid="querySubPageSql"/>
  132. </select>
  133. <select id="findByParentId" resultMap="Subject">
  134. SELECT * FROM subject
  135. where del_flag_ = 0
  136. <if test="parentId != null">
  137. AND parent_subject_id_ = #{parentId}
  138. </if>
  139. </select>
  140. <sql id="querySubPageSql">
  141. where del_flag_ = 0
  142. <if test="parentId != null">
  143. AND parent_subject_id_ = #{parentId}
  144. </if>
  145. <if test="delFlag != null">
  146. AND del_flag_ = #{delFlag}
  147. </if>
  148. <if test="search != null and search != ''">
  149. AND (id_ like concat('%',#{search},'%') or name_ like concat('%',#{search},'%'))
  150. </if>
  151. <if test="queryType != null and queryType == 'category'">
  152. and (parent_subject_id_ = 0 or parent_subject_id_ is null)
  153. </if>
  154. <if test="queryType != null and queryType == 'list'">
  155. and parent_subject_id_ > 0
  156. </if>
  157. </sql>
  158. <select id="findBySubjectByIdList" resultMap="Subject">
  159. SELECT * FROM `subject` WHERE del_flag_ = 0 AND FIND_IN_SET(id_,#{subjectIdList})
  160. </select>
  161. <select id="findBySubjectIds" resultMap="Subject">
  162. SELECT * FROM subject WHERE del_flag_ = 0 and id_ IN
  163. <foreach collection="subjectIds" item="subjectId" separator="," open="(" close=")">
  164. #{subjectId}
  165. </foreach>
  166. </select>
  167. <select id="selectSubjectById" resultType="com.yonge.cooleshow.biz.dal.entity.Subject"
  168. parameterType="java.lang.String">
  169. SELECT * FROM subject WHERE del_flag_ = 0 and id_=#{lessonSubject}
  170. </select>
  171. <select id="queryByCode" resultType="com.yonge.cooleshow.biz.dal.entity.Subject"
  172. parameterType="java.lang.String">
  173. SELECT * FROM subject WHERE del_flag_ = 0 and code_ = #{code}
  174. </select>
  175. <select id="queryByName" resultType="com.yonge.cooleshow.biz.dal.entity.Subject"
  176. parameterType="java.lang.String">
  177. SELECT * FROM subject WHERE del_flag_ = 0 and name_ = #{name}
  178. </select>
  179. <select id="useSubject" resultType="java.lang.Boolean">
  180. select
  181. case when (
  182. select count(1) from teacher a where find_in_set(t.id_,a.subject_id_)
  183. )> 0 then 1 when (
  184. select count(1) from student a where find_in_set(t.id_,a.subject_id_)
  185. )> 0 then 1 else 0 end
  186. from `subject` t
  187. where t.id_ = #{id}
  188. </select>
  189. <!--声部模糊匹配-->
  190. <select id="getSubjectMatchByName" resultType="com.yonge.cooleshow.biz.dal.entity.Subject">
  191. SELECT * FROM subject WHERE del_flag_ = 0 and name_ LIKE CONCAT('%', #{name}, '%') LIMIT 1
  192. </select>
  193. <select id="getByCbsId" resultType="com.yonge.cooleshow.biz.dal.entity.Subject">
  194. SELECT * FROM `subject` WHERE cbs_subject_id_ = #{subjectId} AND del_flag_ = 0 LIMIT 1
  195. </select>
  196. <select id="queryCbsList"
  197. resultType="com.dayaedu.cbs.openfeign.wrapper.music.CbsSubjectApiWrapper$Subject">
  198. SELECT id_ subjectId,cbs_subject_id_ cbsSubjectId,name_ subjectName,code_ code FROM `subject`
  199. WHERE del_flag_ = 0
  200. <if test="query.cbsSubjectIds != null and query.cbsSubjectIds.size > 0">
  201. AND cbs_subject_id_ IN
  202. <foreach collection="query.cbsSubjectIds" item="cbsSubjectId" open="(" close=")" separator=",">
  203. #{cbsSubjectId}
  204. </foreach>
  205. </if>
  206. <if test="query.subjectIds != null and query.subjectIds.size > 0">
  207. AND id_ IN
  208. <foreach collection="query.subjectIds" item="subjectId" open="(" close=")" separator=",">
  209. #{subjectId}
  210. </foreach>
  211. </if>
  212. </select>
  213. <select id="getAll" resultMap="Subject">
  214. SELECT * FROM subject
  215. </select>
  216. <select id="getByCbsSubjectIds" resultMap="Subject">
  217. select * from subject where find_in_set(cbs_subject_id_,#{subjectIds})
  218. </select>
  219. <update id="updateCbsSubjectIdNull">
  220. update subject set cbs_subject_id_ = null where id_ = #{subjectId}
  221. </update>
  222. <!--声部模糊匹配-->
  223. </mapper>