SubjectMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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.ym.mec.biz.dal.dao.SubjectDao">
  8. <resultMap type="com.ym.mec.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="create_time_" property="createTime"/>
  16. <result column="update_time_" property="updateTime"/>
  17. <result column="instrumentIds" property="instrumentIds"/>
  18. <result column="del_flag_" property="delFlag" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  19. </resultMap>
  20. <!-- 根据主键查询一条记录 -->
  21. <select id="get" resultMap="Subject">
  22. SELECT * FROM subject WHERE id_ = #{id}
  23. </select>
  24. <!-- 全查询 -->
  25. <select id="findAll" resultMap="Subject">
  26. SELECT * FROM subject ORDER BY id_
  27. </select>
  28. <!-- 向数据库增加一条记录 -->
  29. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.Subject" useGeneratedKeys="true" keyColumn="id"
  30. keyProperty="id">
  31. INSERT INTO subject (id_,cbs_subject_id_,name_,code_,parent_subject_id_,img_,create_time_,update_time_)
  32. VALUES(#{id},#{cbsSubjectId},#{name},#{code},#{parentSubjectId},#{img},now(),now())
  33. </insert>
  34. <!-- 根据主键查询一条记录 -->
  35. <update id="update" parameterType="com.ym.mec.biz.dal.entity.Subject">
  36. UPDATE subject
  37. <set>
  38. <if test="delFlag != null">
  39. del_flag_ = #{delFlag,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  40. </if>
  41. <if test="parentSubjectId != null">
  42. parent_subject_id_ = #{parentSubjectId},
  43. </if>
  44. <if test="cbsSubjectId != null">
  45. cbs_subject_id_ = #{cbsSubjectId},
  46. </if>
  47. <if test="code != null">
  48. code_ = #{code},
  49. </if>
  50. <if test="img != null">
  51. img_ = #{img},
  52. </if>
  53. <if test="updateTime != null">
  54. update_time_ = NOW(),
  55. </if>
  56. <if test="name != null">
  57. name_ = #{name},
  58. </if>
  59. </set>
  60. WHERE id_ = #{id}
  61. </update>
  62. <!-- 根据主键删除一条记录 -->
  63. <update id="delete">
  64. UPDATE `subject` SET del_flag_ = 1 WHERE id_ = #{id} OR parent_subject_id_ = #{id}
  65. </update>
  66. <!-- 分页查询 -->
  67. <select id="queryPage" resultMap="Subject" parameterType="map">
  68. SELECT * FROM subject
  69. <include refid="querySubPageSql"/>
  70. ORDER BY id_
  71. <include refid="global.limit"/>
  72. </select>
  73. <!-- 查询当前表的总记录数 -->
  74. <select id="queryCount" resultType="int">
  75. SELECT COUNT(*) FROM subject <include refid="querySubPageSql"/>
  76. </select>
  77. <select id="findSubByMusicGroupId" resultMap="Subject">
  78. SELECT s.* FROM music_group_subject_plan mgsp
  79. LEFT JOIN `subject` s ON mgsp.subject_id_ = s.id_
  80. WHERE mgsp.music_group_id_ = #{musicGroupId} AND s.del_flag_ = 0
  81. </select>
  82. <select id="findByParentId" resultMap="Subject">
  83. SELECT * FROM subject <include refid="querySubPageSql"/>
  84. </select>
  85. <select id="findDefaultSubByChargeTypeId" resultMap="Subject">
  86. SELECT s.* FROM charge_type_subject_mapper ctsm
  87. LEFT JOIN `subject` s ON subject_id_ = s.id_
  88. WHERE ctsm.course_view_type_ = #{courseViewType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler} AND s.del_flag_ = 0
  89. </select>
  90. <resultMap id="subApplyDetail" type="com.ym.mec.biz.dal.dto.SubjectApplyDetailDto">
  91. <result column="pay_num_" property="payNum"/>
  92. <result column="name_" property="subjectName"/>
  93. <result column="subject_id_" property="subjectId"/>
  94. <result column="expected_student_num_" property="expectedStudentNum"/>
  95. <result column="music_group_subject_plan_id_" property="musicGroupSubjectPlanId"/>
  96. <result column="apply_student_num_" property="applyStudentNum"/>
  97. <result column="not_part_class_num_" property="notPartClassNum"/>
  98. </resultMap>
  99. <select id="findSubApplyDetail" resultMap="subApplyDetail">
  100. SELECT mgsp.subject_id_,s.name_,mgsp.expected_student_num_,mgsp.apply_student_num_,
  101. mgsp.paid_student_num_ pay_num_,mgsp.id_ music_group_subject_plan_id_
  102. FROM music_group_subject_plan mgsp
  103. LEFT JOIN `subject` s ON mgsp.subject_id_ = s.id_
  104. WHERE mgsp.music_group_id_ = #{musicGroupId} AND s.del_flag_ = 0
  105. </select>
  106. <select id="findBySubIds" resultType="string">
  107. SELECT name_ FROM `subject` WHERE del_flag_ = 0 AND FIND_IN_SET (id_,#{subIds})
  108. </select>
  109. <select id="findTeacherSubjects" resultMap="Subject">
  110. SELECT s.* FROM teacher t
  111. LEFT JOIN `subject` s ON FIND_IN_SET(s.id_,t.subject_id_)
  112. WHERE t.id_=#{teacherId} AND s.del_flag_ = 0
  113. </select>
  114. <select id="findSubjectConditions" resultType="com.ym.mec.biz.dal.dto.ConditionDto">
  115. select id_ id,name_ `name` from subject where parent_subject_id_ != 0 AND del_flag_ = 0
  116. </select>
  117. <select id="queryNameByIds" resultType="java.util.Map">
  118. select id_ `key`,name_ `value` FROM `subject` s WHERE FIND_IN_SET(s.id_,#{subjectIds}) AND s.del_flag_ = 0
  119. </select>
  120. <select id="findBySubjecIds" resultType="java.util.Map">
  121. select id_ `key`,name_ `value` FROM `subject` s WHERE FIND_IN_SET(s.id_,#{subjectIds}) AND s.del_flag_ = 0
  122. </select>
  123. <select id="findSubSubjects" resultMap="Subject">
  124. SELECT * FROM `subject`
  125. <where>
  126. parent_subject_id_ != 0 AND del_flag_ = 0
  127. <if test="parentSubjectId != null and parentSubjectId != ''">
  128. AND parent_subject_id_ = #{parentSubjectId}
  129. </if>
  130. <if test="cbsFlag != null and cbsFlag == true">
  131. AND cbs_subject_id_ IS NOT NULL
  132. </if>
  133. </where>
  134. </select>
  135. <select id="queryPageByIdOrNameCount" resultType="integer">
  136. SELECT count(1) FROM `subject`
  137. <where>
  138. del_flag_ = 0 AND parent_subject_id_ != 0
  139. <if test="parentSubjectId != null and parentSubjectId != ''">
  140. AND parent_subject_id_ = #{parentSubjectId}
  141. </if>
  142. <if test="search != null and search != ''">
  143. AND (id_ = #{search} or name_ like concat('%', #{search}, '%'))
  144. </if>
  145. </where>
  146. </select>
  147. <select id="queryPageByIdOrName" resultMap="Subject">
  148. SELECT *,
  149. (select name_ from `subject` s1 where s.parent_subject_id_ = s1.id_) as parentSubjectName
  150. FROM `subject` s
  151. <where>
  152. s.del_flag_ = 0 AND s.parent_subject_id_ != 0
  153. <if test="parentSubjectId != null and parentSubjectId != ''">
  154. AND s.parent_subject_id_ = #{parentSubjectId}
  155. </if>
  156. <if test="search != null and search != ''">
  157. AND (s.id_ = #{search} or s.name_ like concat('%', #{search}, '%'))
  158. </if>
  159. </where>
  160. <include refid="global.limit"/>
  161. </select>
  162. <sql id="querySubPageSql">
  163. <where>
  164. <if test="parentId != null">
  165. AND parent_subject_id_ = #{parentId}
  166. </if>
  167. <if test="delFlag != null">
  168. AND del_flag_ = #{delFlag,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  169. </if>
  170. </where>
  171. </sql>
  172. <select id="findBySubjectByIdList" resultMap="Subject">
  173. SELECT * FROM `subject` WHERE del_flag_ = 0 AND FIND_IN_SET(id_,#{subjectIdList})
  174. </select>
  175. <select id="findByMusicGroupUserSubject" resultType="map">
  176. SELECT
  177. sr.user_id_ AS `key`,
  178. s.name_ AS `value`
  179. FROM
  180. student_registration sr
  181. LEFT JOIN `subject` s ON sr.actual_subject_id_=s.id_
  182. WHERE sr.music_group_id_=#{musicGroupId} AND s.del_flag_ = 0 AND sr.music_group_status_ != 'QUIT'
  183. AND sr.user_id_ IN
  184. <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  185. #{userId}
  186. </foreach>
  187. </select>
  188. <select id="findSubjectNameCourseMaps" resultType="java.util.Map">
  189. SELECT
  190. cs.id_ AS 'key',
  191. GROUP_CONCAT(s.name_) AS 'value'
  192. FROM
  193. course_schedule cs
  194. LEFT JOIN class_group cg ON cs.class_group_id_=cg.id_
  195. LEFT JOIN `subject` s ON FIND_IN_SET(s.id_,cg.subject_id_list_)
  196. WHERE cs.id_ IN
  197. <foreach collection="courseScheduleIds" item="courseScheduleId" open="(" close=")" separator=",">
  198. #{courseScheduleId}
  199. </foreach>
  200. AND cg.subject_id_list_ IS NOT NULL
  201. GROUP BY cs.id_
  202. </select>
  203. <select id="findClassGroupSubjectId" resultType="java.util.Map">
  204. SELECT
  205. cs.id_ AS 'key',
  206. cg.subject_id_list_ AS 'value'
  207. FROM
  208. course_schedule cs
  209. LEFT JOIN class_group cg ON cs.class_group_id_=cg.id_
  210. WHERE cs.id_ IN
  211. <foreach collection="courseScheduleIds" item="courseScheduleId" open="(" close=")" separator=",">
  212. #{courseScheduleId}
  213. </foreach>
  214. AND cg.subject_id_list_ IS NOT NULL
  215. GROUP BY cs.id_
  216. </select>
  217. <select id="findNames" resultType="java.lang.String">
  218. SELECT GROUP_CONCAT(DISTINCT s.name_) FROM `subject` s WHERE FIND_IN_SET(s.id_,#{subjectIdList})
  219. </select>
  220. <select id="findStudentSubjectNameMaps" resultType="java.util.Map">
  221. SELECT
  222. sr.user_id_ as 'key',
  223. s.name_ as 'value'
  224. FROM
  225. student_registration sr
  226. LEFT JOIN `subject` s ON sr.actual_subject_id_ = s.id_
  227. WHERE 1=1
  228. AND
  229. <foreach collection="studentInfos" item="student" open="(" close=")" separator=" OR ">
  230. sr.user_id_=#{student.studentId} AND sr.music_group_id_=#{student.musicGroupId}
  231. </foreach>
  232. </select>
  233. <select id="findStudentSubjectIdMaps" resultType="java.util.Map">
  234. SELECT
  235. sr.user_id_ as 'key',
  236. sr.actual_subject_id_ as 'value'
  237. FROM
  238. student_registration sr
  239. WHERE 1=1
  240. AND
  241. <foreach collection="studentInfos" item="student" open="(" close=")" separator=" OR ">
  242. sr.user_id_=#{student.studentId} AND sr.music_group_id_=#{student.musicGroupId}
  243. </foreach>
  244. </select>
  245. <select id="findBySubjectIds" resultMap="Subject">
  246. SELECT * FROM subject WHERE id_ IN
  247. <foreach collection="subjectIds" item="subjectId" separator="," open="(" close=")">
  248. #{subjectId}
  249. </foreach>
  250. </select>
  251. <select id="getRegisterSubject" resultMap="com.ym.mec.biz.dal.dao.StudentRegistrationDao.StudentRegistration">
  252. SELECT sr.user_id_, s.name_ subject_name_,sr.actual_subject_id_ FROM student_registration sr
  253. LEFT JOIN subject s ON sr.actual_subject_id_=s.id_
  254. WHERE sr.music_group_id_=#{musicGroupId} AND s.del_flag_ = 0
  255. AND sr.user_id_ IN
  256. <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  257. #{userId}
  258. </foreach>
  259. </select>
  260. <select id="list" resultMap="Subject">
  261. select * from subject where del_flag_ = 0 and parent_subject_id_ != 0
  262. </select>
  263. <select id="getSubjectByStudentId" resultType="com.ym.mec.biz.dal.dto.StudentSubjectDto">
  264. SELECT
  265. sr.user_id_ AS studentId,
  266. s.id_ AS subjectId,
  267. s.name_ AS subjectName
  268. FROM
  269. student sr
  270. LEFT JOIN `subject` s ON sr.subject_id_list_=s.id_
  271. WHERE sr.user_id_ IN
  272. <foreach collection="studentIds" item="userId" open="(" close=")" separator=",">
  273. #{userId}
  274. </foreach>
  275. </select>
  276. <select id="getSubjectListByIdAndCoopId" resultType="com.ym.mec.biz.dal.entity.Subject">
  277. SELECT
  278. distinct s.id_ as id
  279. ,s.name_ as name
  280. FROM
  281. `subject` s
  282. LEFT JOIN music_group_subject_plan mgsp on s.id_ = mgsp.subject_id_
  283. LEFT JOIN music_group mg on mg.id_ = mgsp.music_group_id_
  284. WHERE
  285. s.del_flag_ = 0 and mg.status_ = 'PROGRESS'
  286. <if test="musicGroupId != null and musicGroupId != ''">
  287. AND mg.id_ = #{musicGroupId}
  288. </if>
  289. <if test="coopId != null">
  290. AND mg.cooperation_organ_id_ = #{coopId}
  291. </if>
  292. </select>
  293. <select id="findByNames" resultMap="Subject">
  294. SELECT * FROM `subject` where name_ IN ('长笛','单簧管','萨克斯','小号','长号','圆号','上低音号','大号','打击乐') and del_flag_ = 0
  295. </select>
  296. <select id="queryCbsList" resultMap="Subject">
  297. SELECT * FROM `subject` WHERE del_flag_ = 0 AND parent_subject_id_ != 0 AND cbs_subject_id_ IS NOT NULL
  298. <if test="cbsSubjectIds != null and cbsSubjectIds.size > 0">
  299. AND cbs_subject_id_ IN
  300. <foreach collection="cbsSubjectIds" item="cbsSubjectId" open="(" close=")" separator=",">
  301. #{cbsSubjectId}
  302. </foreach>
  303. </if>
  304. </select>
  305. <select id="notInSubjectIds" resultMap="Subject">
  306. SELECT * FROM subject WHERE del_flag_ = 0 and id_ != #{subjectId}
  307. </select>
  308. <select id="findCount" resultType="java.lang.Integer">
  309. select count(DISTINCT t.id_) from
  310. (SELECT t.id_
  311. FROM subject t
  312. LEFT JOIN instrument i on t.id_ = i.subject_id_
  313. <where>
  314. <if test="parentSubjectId != null">
  315. AND t.parent_subject_id_ = #{parentSubjectId}
  316. </if>
  317. <if test="parentSubjectId == null">
  318. AND t.parent_subject_id_ != 0 AND t.cbs_subject_id_ is not null
  319. </if>
  320. <if test="keyword != null and keyword != ''">
  321. AND (t.name_ LIKE CONCAT('%',#{keyword},'%') OR t.code_ LIKE CONCAT('%',#{keyword},'%'))
  322. </if>
  323. <if test="delFlag != null">
  324. AND t.del_flag_ = #{delFlag}
  325. </if>
  326. <if test="subjectId != null">
  327. AND t.id_ = #{subjectId}
  328. </if>
  329. <if test="subjectIds != null">
  330. AND find_in_set(t.id_,#{subjectIds})
  331. </if>
  332. <if test="instrumentIds != null">
  333. AND find_in_set(i.id_, #{instrumentIds})
  334. </if>
  335. <if test="enableFlag != null">
  336. AND t.enable_flag_ = #{enableFlag} and i.enable_flag_ = #{enableFlag}
  337. </if>
  338. </where>
  339. group by t.id_
  340. <if test="hasInstrument != null">
  341. <if test="hasInstrument == true">
  342. having count(i.id_) > 0
  343. </if>
  344. <if test="hasInstrument == false">
  345. having count(i.id_) = 0
  346. </if>
  347. </if>) t
  348. </select>
  349. <sql id="baseColumns">
  350. t.id_ as id
  351. , t.name_ as name
  352. , t.code_ as code
  353. , t.parent_subject_id_ as parentSubjectId
  354. , t.img_ as img
  355. , t.del_flag_ as delFlag
  356. , t.update_time_ as updateTime
  357. , t.create_time_ as createTime
  358. ,t.cbs_subject_id_ as cbsSubjectId
  359. </sql>
  360. <select id="findPage" resultType="com.ym.mec.biz.dal.wrapper.SubjectWrapper$Subject">
  361. SELECT
  362. <include refid="baseColumns" />
  363. FROM subject t
  364. LEFT JOIN instrument i on t.id_ = i.subject_id_
  365. <where>
  366. <if test="parentSubjectId != null">
  367. AND t.parent_subject_id_ = #{parentSubjectId}
  368. </if>
  369. <if test="parentSubjectId == null">
  370. AND t.parent_subject_id_ != 0 AND t.cbs_subject_id_ is not null
  371. </if>
  372. <if test="keyword != null and keyword != ''">
  373. AND (t.name_ LIKE CONCAT('%',#{keyword},'%') OR t.code_ LIKE CONCAT('%',#{keyword},'%'))
  374. </if>
  375. <if test="delFlag != null">
  376. AND t.del_flag_ = #{delFlag}
  377. </if>
  378. <if test="subjectId != null">
  379. AND t.id_ = #{subjectId}
  380. </if>
  381. <if test="subjectIds != null">
  382. AND find_in_set(t.id_,#{subjectIds})
  383. </if>
  384. <if test="instrumentIds != null">
  385. AND find_in_set(i.id_, #{instrumentIds})
  386. </if>
  387. <if test="enableFlag != null">
  388. AND t.enable_flag_ = #{enableFlag} and i.enable_flag_ = #{enableFlag}
  389. </if>
  390. </where>
  391. group by t.id_
  392. <if test="hasInstrument != null">
  393. <if test="hasInstrument == true">
  394. having count(i.id_) > 0
  395. </if>
  396. <if test="hasInstrument == false">
  397. having count(i.id_) = 0
  398. </if>
  399. </if>
  400. <include refid="global.limit"/>
  401. </select>
  402. <select id="queryCbsSubjects"
  403. resultType="com.dayaedu.cbs.openfeign.wrapper.music.CbsSubjectApiWrapper$Subject">
  404. SELECT id_ subjectId,cbs_subject_id_ cbsSubjectId,name_ subjectName,code_ code FROM `subject`
  405. WHERE del_flag_ = 0 AND cbs_subject_id_ IS NOT NULL
  406. <if test="query.cbsSubjectIds != null and query.cbsSubjectIds.size > 0">
  407. AND cbs_subject_id_ IN
  408. <foreach collection="query.cbsSubjectIds" item="cbsSubjectId" open="(" close=")" separator=",">
  409. #{cbsSubjectId}
  410. </foreach>
  411. </if>
  412. <if test="query.subjectIds != null and query.subjectIds.size > 0">
  413. AND id_ IN
  414. <foreach collection="query.subjectIds" item="subjectId" open="(" close=")" separator=",">
  415. #{subjectId}
  416. </foreach>
  417. </if>
  418. </select>
  419. </mapper>