SubjectMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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="name_" property="name"/>
  11. <result column="code_" property="code"/>
  12. <result column="parent_subject_id_" property="parentSubjectId"/>
  13. <result column="img_" property="img"/>
  14. <result column="ai_default_frequency_" property="aiDefaultFrequency"/>
  15. <result column="desc_" property="desc"/>
  16. <result column="create_time_" property="createTime"/>
  17. <result column="update_time_" property="updateTime"/>
  18. <result column="del_flag_" property="delFlag"/>
  19. </resultMap>
  20. <!-- 根据主键查询一条记录 -->
  21. <select id="get" resultMap="Subject">
  22. SELECT * FROM subject WHERE del_flag_ = 0 and id_ = #{id}
  23. </select>
  24. <!-- 全查询 -->
  25. <select id="findAll" resultMap="Subject">
  26. SELECT * FROM subject where del_flag_ = 0 ORDER BY id_
  27. </select>
  28. <select id="subjectSelect" resultType="com.yonge.cooleshow.biz.dal.entity.Subject">
  29. select t.* from subject t
  30. join (
  31. select a.subject_id_ from (
  32. <trim prefixOverrides="union all">
  33. <if test="type == null or type =='MUSIC'">
  34. union all
  35. (select a.music_subject_ as subject_id_ from music_sheet a
  36. where a.del_flag_ = 0 and a.state_ = 1 AND a.cbs_music_sheet_id_ IS NOT NULL
  37. GROUP BY a.music_subject_)
  38. </if>
  39. <if test="type == null or type =='ALBUM'">
  40. union all
  41. (SELECT cm.subject_id_ from music_album cm WHERE cm.album_status_ = 1 and cm.del_flag_ = 0 GROUP BY cm.subject_id_)
  42. </if>
  43. <if test="type == null or type =='VIDEO'">
  44. union all
  45. (select a.lesson_subject_ as subject_id_ from video_lesson_group a
  46. where a.audit_status_ = 'PASS' and a.shelves_flag_ = 1
  47. GROUP BY a.lesson_subject_)
  48. </if>
  49. <if test="type == null or type =='PIANO_ROOM'">
  50. union all
  51. (select a.subject_id_ as subject_id_ from course_group a
  52. where a.type_ = 'PIANO_ROOM_CLASS' and a.status_ in ('ING','COMPLETE','APPLY')
  53. GROUP BY a.subject_id_)
  54. </if>
  55. <if test="type == null or type =='PRACTICE'">
  56. union all
  57. (select a.subject_id_ as subject_id_ from course_group a
  58. where a.type_ = 'PRACTICE' and a.status_ in ('ING','COMPLETE','APPLY')
  59. GROUP BY a.subject_id_)
  60. </if>
  61. <if test="type == null or type =='LIVE'">
  62. union all
  63. (select a.subject_id_ as subject_id_ from course_group a
  64. where a.type_ = 'LIVE' and a.status_ in ('APPLY')
  65. GROUP BY a.subject_id_)
  66. </if>
  67. </trim>
  68. ) a group by a.subject_id_
  69. ) a on t.id_ = a.subject_id_
  70. where t.parent_subject_id_ != 0 group by t.id_
  71. </select>
  72. <!-- 向数据库增加一条记录 -->
  73. <insert id="insert" parameterType="com.yonge.cooleshow.biz.dal.entity.Subject" useGeneratedKeys="true"
  74. keyColumn="id"
  75. keyProperty="id">
  76. INSERT INTO subject (id_,name_,code_,parent_subject_id_,img_,create_time_,update_time_,desc_,ai_default_frequency_,cbs_subject_id_)
  77. VALUES(#{id},#{name},#{code},#{parentSubjectId},#{img},now(),now(),#{desc},#{aiDefaultFrequency},#{cbsSubjectId})
  78. </insert>
  79. <!-- 根据主键查询一条记录 -->
  80. <update id="update" parameterType="com.yonge.cooleshow.biz.dal.entity.Subject">
  81. UPDATE subject
  82. <set>
  83. <if test="delFlag != null">
  84. del_flag_ = #{delFlag},
  85. </if>
  86. <if test="enableFlag != null">
  87. enable_flag_ = #{enableFlag},
  88. </if>
  89. <if test="parentSubjectId != null">
  90. parent_subject_id_ = #{parentSubjectId},
  91. </if>
  92. <if test="code != null">
  93. code_ = #{code},
  94. </if>
  95. <if test="img != null">
  96. img_ = #{img},
  97. </if>
  98. <if test="updateTime != null">
  99. update_time_ = NOW(),
  100. </if>
  101. <if test="name != null">
  102. name_ = #{name},
  103. </if>
  104. <if test="desc != null">
  105. desc_ = #{desc},
  106. </if>
  107. <if test="aiDefaultFrequency != null">
  108. ai_default_frequency_ = #{aiDefaultFrequency},
  109. </if>
  110. </set>
  111. WHERE id_ = #{id}
  112. </update>
  113. <!-- 根据主键删除一条记录 -->
  114. <update id="delete">
  115. UPDATE `subject` SET del_flag_ = 1 WHERE id_ = #{id} OR parent_subject_id_ = #{id}
  116. </update>
  117. <delete id="deleteById">
  118. update subject set del_flag_ = 1 where id_ = #{id}
  119. </delete>
  120. <!-- 分页查询 -->
  121. <select id="queryPage" resultMap="Subject" parameterType="map">
  122. SELECT * FROM subject
  123. <include refid="querySubPageSql"/>
  124. ORDER BY id_
  125. <include refid="global.limit"/>
  126. </select>
  127. <!-- 查询当前表的总记录数 -->
  128. <select id="queryCount" resultType="int">
  129. SELECT COUNT(*) FROM subject
  130. <include refid="querySubPageSql"/>
  131. </select>
  132. <select id="findByParentId" resultMap="Subject">
  133. SELECT * FROM subject
  134. where del_flag_ = 0
  135. <if test="parentId != null">
  136. AND parent_subject_id_ = #{parentId}
  137. </if>
  138. </select>
  139. <sql id="querySubPageSql">
  140. where del_flag_ = 0
  141. <if test="parentId != null">
  142. AND parent_subject_id_ = #{parentId}
  143. </if>
  144. <if test="delFlag != null">
  145. AND del_flag_ = #{delFlag}
  146. </if>
  147. <if test="search != null and search != ''">
  148. AND (id_ like concat('%',#{search},'%') or name_ like concat('%',#{search},'%'))
  149. </if>
  150. <if test="queryType != null and queryType == 'category'">
  151. and (parent_subject_id_ = 0 or parent_subject_id_ is null)
  152. </if>
  153. <if test="queryType != null and queryType == 'list'">
  154. and parent_subject_id_ > 0
  155. </if>
  156. </sql>
  157. <select id="findBySubjectByIdList" resultMap="Subject">
  158. SELECT * FROM `subject` WHERE del_flag_ = 0 AND FIND_IN_SET(id_,#{subjectIdList})
  159. </select>
  160. <select id="findBySubjectIds" resultMap="Subject">
  161. SELECT * FROM subject WHERE del_flag_ = 0 and id_ IN
  162. <foreach collection="subjectIds" item="subjectId" separator="," open="(" close=")">
  163. #{subjectId}
  164. </foreach>
  165. </select>
  166. <select id="selectSubjectById" resultType="com.yonge.cooleshow.biz.dal.entity.Subject"
  167. parameterType="java.lang.String">
  168. SELECT * FROM subject WHERE del_flag_ = 0 and id_=#{lessonSubject}
  169. </select>
  170. <select id="queryByCode" resultType="com.yonge.cooleshow.biz.dal.entity.Subject"
  171. parameterType="java.lang.String">
  172. SELECT * FROM subject WHERE del_flag_ = 0 and code_ = #{code}
  173. </select>
  174. <select id="queryByName" resultType="com.yonge.cooleshow.biz.dal.entity.Subject"
  175. parameterType="java.lang.String">
  176. SELECT * FROM subject WHERE del_flag_ = 0 and name_ = #{name}
  177. </select>
  178. <select id="useSubject" resultType="java.lang.Boolean">
  179. select
  180. case when (
  181. select count(1) from teacher a where find_in_set(t.id_,a.subject_id_)
  182. )> 0 then 1 when (
  183. select count(1) from student a where find_in_set(t.id_,a.subject_id_)
  184. )> 0 then 1 else 0 end
  185. from `subject` t
  186. where t.id_ = #{id}
  187. </select>
  188. <!--声部模糊匹配-->
  189. <select id="getSubjectMatchByName" resultType="com.yonge.cooleshow.biz.dal.entity.Subject">
  190. SELECT * FROM subject WHERE del_flag_ = 0 and name_ LIKE CONCAT('%', #{name}, '%') LIMIT 1
  191. </select>
  192. <select id="getByCbsId" resultType="com.yonge.cooleshow.biz.dal.entity.Subject">
  193. SELECT * FROM `subject` WHERE cbs_subject_id_ = #{subjectId} AND del_flag_ = 0 LIMIT 1
  194. </select>
  195. <select id="queryCbsList"
  196. resultType="com.dayaedu.cbs.openfeign.wrapper.music.CbsSubjectApiWrapper$Subject">
  197. SELECT id_ subjectId,cbs_subject_id_ cbsSubjectId,name_ subjectName,code_ code FROM `subject`
  198. WHERE del_flag_ = 0
  199. <if test="query.cbsSubjectIds != null and query.cbsSubjectIds.size > 0">
  200. AND cbs_subject_id_ IN
  201. <foreach collection="query.cbsSubjectIds" item="cbsSubjectId" open="(" close=")" separator=",">
  202. #{cbsSubjectId}
  203. </foreach>
  204. </if>
  205. <if test="query.subjectIds != null and query.subjectIds.size > 0">
  206. AND id_ IN
  207. <foreach collection="query.subjectIds" item="subjectId" open="(" close=")" separator=",">
  208. #{subjectId}
  209. </foreach>
  210. </if>
  211. </select>
  212. <select id="getAll" resultMap="Subject">
  213. SELECT * FROM subject
  214. </select>
  215. <select id="getByCbsSubjectIds" resultMap="Subject">
  216. select * from subject where find_in_set(cbs_subject_id_,#{subjectIds})
  217. </select>
  218. <select id="findCount" resultType="java.lang.Integer">
  219. select count(DISTINCT t.id_) from
  220. (SELECT t.id_
  221. FROM subject t
  222. LEFT JOIN instrument i on t.id_ = i.subject_id_
  223. <where>
  224. <if test="parentSubjectId != null">
  225. AND t.parent_subject_id_ = #{parentSubjectId}
  226. </if>
  227. <if test="parentSubjectId == null">
  228. AND t.parent_subject_id_ != 0 AND t.cbs_subject_id_ is not null
  229. </if>
  230. <if test="keyword != null and keyword != ''">
  231. AND (t.name_ LIKE CONCAT('%',#{keyword},'%') OR t.code_ LIKE CONCAT('%',#{keyword},'%'))
  232. </if>
  233. <if test="delFlag != null">
  234. AND t.del_flag_ = #{delFlag}
  235. </if>
  236. <if test="subjectId != null">
  237. AND t.id_ = #{subjectId}
  238. </if>
  239. <if test="subjectIds != null">
  240. AND find_in_set(t.id_,#{subjectIds})
  241. </if>
  242. <if test="instrumentIds != null">
  243. AND find_in_set(i.id_, #{instrumentIds})
  244. </if>
  245. <if test="enableFlag != null">
  246. AND t.enable_flag_ = #{enableFlag} and i.enable_flag_ = #{enableFlag}
  247. </if>
  248. </where>
  249. group by t.id_
  250. <if test="hasInstrument != null">
  251. <if test="hasInstrument == true">
  252. having count(i.id_) > 0
  253. </if>
  254. <if test="hasInstrument == false">
  255. having count(i.id_) = 0
  256. </if>
  257. </if>) t
  258. </select>
  259. <sql id="baseColumns">
  260. t.id_ as id
  261. , t.name_ as name
  262. , t.code_ as code
  263. , t.parent_subject_id_ as parentSubjectId
  264. , t.img_ as img
  265. , t.del_flag_ as delFlag
  266. , t.update_time_ as updateTime
  267. , t.create_time_ as createTime
  268. , t.enable_flag_ as enableFlag
  269. ,t.orientation_ as orientation
  270. ,t.enable_flag_ as enableFlag
  271. ,t.logo_ as logo
  272. ,t.media_ as media
  273. ,t.cbs_subject_id_ as cbsSubjectId
  274. </sql>
  275. <select id="findPage" resultType="com.yonge.cooleshow.biz.dal.wrapper.SubjectWrapper$Subject">
  276. SELECT
  277. <include refid="baseColumns" />
  278. FROM subject t
  279. LEFT JOIN instrument i on t.id_ = i.subject_id_
  280. <where>
  281. <if test="parentSubjectId != null">
  282. AND t.parent_subject_id_ = #{parentSubjectId}
  283. </if>
  284. <if test="parentSubjectId == null">
  285. AND t.parent_subject_id_ != 0 AND t.cbs_subject_id_ is not null
  286. </if>
  287. <if test="keyword != null and keyword != ''">
  288. AND (t.name_ LIKE CONCAT('%',#{keyword},'%') OR t.code_ LIKE CONCAT('%',#{keyword},'%'))
  289. </if>
  290. <if test="delFlag != null">
  291. AND t.del_flag_ = #{delFlag}
  292. </if>
  293. <if test="subjectId != null">
  294. AND t.id_ = #{subjectId}
  295. </if>
  296. <if test="subjectIds != null">
  297. AND find_in_set(t.id_,#{subjectIds})
  298. </if>
  299. <if test="instrumentIds != null">
  300. AND find_in_set(i.id_, #{instrumentIds})
  301. </if>
  302. <if test="enableFlag != null">
  303. AND t.enable_flag_ = #{enableFlag} and i.enable_flag_ = #{enableFlag}
  304. </if>
  305. </where>
  306. group by t.id_
  307. <if test="hasInstrument != null">
  308. <if test="hasInstrument == true">
  309. having count(i.id_) > 0
  310. </if>
  311. <if test="hasInstrument == false">
  312. having count(i.id_) = 0
  313. </if>
  314. </if>
  315. <include refid="global.limit"/>
  316. </select>
  317. <select id="notInSubjectIds" resultMap="Subject">
  318. SELECT * FROM subject WHERE del_flag_ = 0 and id_ != #{subjectId}
  319. </select>
  320. <update id="updateCbsSubjectIdNull">
  321. update subject set cbs_subject_id_ = null where id_ = #{subjectId}
  322. </update>
  323. <!--声部模糊匹配-->
  324. </mapper>