TeacherMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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.TeacherDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.Teacher" id="Teacher">
  9. <result column="id_" property="id"/>
  10. <result column="organ_id_" property="organId"/>
  11. <result column="organ_name_" property="organName"/>
  12. <result column="job_type_" property="jobType"/>
  13. <result column="job_nature_" property="jobNature"/>
  14. <result column="is_probation_period_" property="isProbationPeriod"
  15. typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  16. <result column="education_background_" property="educationBackground"/>
  17. <result column="graduate_school_" property="graduateSchool"/>
  18. <result column="technical_titles_" property="technicalTitles"/>
  19. <result column="work_unit_" property="workUnit"/>
  20. <result column="subject_id_" property="subjectId"/>
  21. <result column="entry_date_" property="entryDate"/>
  22. <result column="demission_date_" property="demissionDate"/>
  23. <result column="certificate_type_" property="certificateType"/>
  24. <result column="certificate_num_" property="certificateNum"/>
  25. <result column="flow_organ_range_" property="flowOrganRange"/>
  26. <result column="introduction_" property="introduction"/>
  27. <result column="update_time_" property="updateTime"/>
  28. <result column="create_time_" property="createTime"/>
  29. <result column="username_" property="username"/>
  30. <result column="password_" property="password"/>
  31. <result column="real_name_" property="realName"/>
  32. <result column="salt_" property="salt"/>
  33. <result column="phone_" property="phone"/>
  34. <result column="avatar_" property="avatar"/>
  35. <result column="lock_flag_" property="lockFlag" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  36. <result column="del_flag_" property="delFlag" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  37. <result column="wx_openid_" property="wxOpenid"/>
  38. <result column="qq_openid_" property="qqOpenid"/>
  39. <result column="user_type_" property="userType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  40. <result column="gender_" property="gender"/>
  41. <result column="nation_" property="nation"/>
  42. <result column="birthdate_" property="birthdate"/>
  43. <result column="email_" property="email"/>
  44. <result column="im_token_" property="imToken"/>
  45. <collection property="subjectName" ofType="string" column="subject_name_"/>
  46. </resultMap>
  47. <!-- 根据主键查询一条记录 -->
  48. <select id="get" resultMap="Teacher">
  49. SELECT t.*,su.username_,su.password_,su.salt_,su.phone_,su.avatar_,
  50. su.lock_flag_,su.del_flag_,su.wx_openid_,su.qq_openid_,su.user_type_,
  51. su.gender_,su.nation_,su.birthdate_,su.email_,su.im_token_
  52. FROM teacher t
  53. LEFT JOIN sys_user su ON t.id_ = su.id_
  54. WHERE t.id_ = #{id} AND su.del_flag_ = 0
  55. </select>
  56. <!-- 全查询 -->
  57. <select id="findAll" resultMap="Teacher">
  58. SELECT *
  59. FROM teacher
  60. ORDER BY id_
  61. </select>
  62. <!-- 向数据库增加一条记录 -->
  63. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.Teacher" useGeneratedKeys="true" keyColumn="id"
  64. keyProperty="id">
  65. INSERT INTO teacher
  66. (id_,organ_id_,job_type_,job_nature_,is_probation_period_,education_background_,graduate_school_,technical_titles_,work_unit_,subject_id_,entry_date_,demission_date_,certificate_type_,certificate_num_,flow_organ_range_,introduction_,update_time_,create_time_)
  67. VALUES(#{id},#{organId},#{jobType},#{jobNature},#{isProbationPeriod,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{educationBackground},#{graduateSchool},#{technicalTitles},#{workUnit},#{subjectId},#{entryDate},#{demissionDate},#{certificateType},#{certificateNum},#{flowOrganRange},#{introduction},now(),now())
  68. </insert>
  69. <insert id="addSysUser" parameterType="com.ym.mec.auth.api.entity.SysUser" useGeneratedKeys="true" keyColumn="id"
  70. keyProperty="id">
  71. INSERT INTO sys_user
  72. (im_token_,id_,username_,salt_,phone_,avatar_,organ_id_,create_time_,update_time_,wx_openid_,qq_openid_,user_type_,gender_,nation_,birthdate_,email_,id_card_no_,esign_id_,wechat_id_,real_name_,password_)
  73. VALUES(#{imToken},#{id},#{username},#{salt},#{phone},#{avatar},#{organId},now(),now(),#{wxOpenid},#{qqOpenid},#{userType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  74. #{gender},#{nation},#{birthdate},#{email},#{idCardNo},#{esignId},#{wechatId},#{realName},#{password})
  75. </insert>
  76. <!-- 根据主键查询一条记录 -->
  77. <update id="update" parameterType="com.ym.mec.biz.dal.entity.Teacher">
  78. UPDATE teacher
  79. <set>
  80. <if test="graduateSchool != null">
  81. graduate_school_ = #{graduateSchool},
  82. </if>
  83. <if test="subjectId != null">
  84. subject_id_ = #{subjectId},
  85. </if>
  86. <if test="organId != null">
  87. organ_id_ = #{organId},
  88. </if>
  89. <if test="technicalTitles != null">
  90. technical_titles_ = #{technicalTitles},
  91. </if>
  92. <if test="entryDate != null">
  93. entry_date_ = #{entryDate},
  94. </if>
  95. <if test="demissionDate != null">
  96. demission_date_ = #{demissionDate},
  97. </if>
  98. <if test="jobType != null">
  99. job_type_ = #{jobType},
  100. </if>
  101. <if test="flowOrganRange != null">
  102. flow_organ_range_ = #{flowOrganRange},
  103. </if>
  104. <if test="certificateType != null">
  105. certificate_type_ = #{certificateType},
  106. </if>
  107. <if test="jobNature != null">
  108. job_nature_ = #{jobNature},
  109. </if>
  110. <if test="isProbationPeriod != null">
  111. is_probation_period_ = #{isProbationPeriod,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  112. </if>
  113. <if test="updateTime != null">
  114. update_time_ = #{updateTime},
  115. </if>
  116. <if test="educationBackground != null">
  117. education_background_ = #{educationBackground},
  118. </if>
  119. <if test="certificateNum != null">
  120. certificate_num_ = #{certificateNum},
  121. </if>
  122. <if test="workUnit != null">
  123. work_unit_ = #{workUnit},
  124. </if>
  125. <if test="introduction != null">
  126. introduction_ = #{introduction},
  127. </if>
  128. </set>
  129. WHERE id_ = #{id}
  130. </update>
  131. <!-- 根据主键删除一条记录 -->
  132. <update id="delete">
  133. DELETE FROM teacher WHERE id_ = #{id}
  134. </update>
  135. <update id="updateUser" parameterType="com.ym.mec.auth.api.entity.SysUser">
  136. UPDATE sys_user
  137. <set>
  138. <if test="delFlag != null">
  139. del_flag_ = #{delFlag, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  140. </if>
  141. <if test="wxOpenid != null">
  142. wx_openid_ = #{wxOpenid},
  143. </if>
  144. <if test="avatar != null">
  145. avatar_ = #{avatar},
  146. </if>
  147. <if test="email != null">
  148. email_ = #{email},
  149. </if>
  150. <if test="gender != null">
  151. gender_ = #{gender},
  152. </if>
  153. <if test="salt != null">
  154. salt_ = #{salt},
  155. </if>
  156. <if test="username != null">
  157. username_ = #{username},
  158. </if>
  159. <if test="userType != null">
  160. user_type_ = #{userType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  161. </if>
  162. <if test="updateTime != null">
  163. update_time_ = #{updateTime},
  164. </if>
  165. <if test="lockFlag != null">
  166. lock_flag_ = #{lockFlag, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  167. </if>
  168. <if test="birthdate != null">
  169. birthdate_ = #{birthdate},
  170. </if>
  171. <if test="phone != null">
  172. phone_ = #{phone},
  173. </if>
  174. <if test="qqOpenid != null">
  175. qq_openid_ = #{qqOpenid},
  176. </if>
  177. <if test="nation != null">
  178. nation_ = #{nation},
  179. </if>
  180. <if test="organId != null">
  181. organ_id_ = #{organId},
  182. </if>
  183. <if test="imToken != null">
  184. im_token_ = #{imToken},
  185. </if>
  186. </set>
  187. WHERE id_ = #{id}
  188. </update>
  189. <!-- 分页查询 -->
  190. <select id="queryPage" resultMap="Teacher" parameterType="map">
  191. SELECT t.id_,su.real_name_,su.lock_flag_,t.subject_id_,su.phone_,su.organ_id_,t.job_nature_,t.is_probation_period_
  192. FROM teacher t LEFT JOIN sys_user su ON t.id_ = su.id_
  193. WHERE su.user_type_ LIKE '%TEACHER%' AND su.del_flag_ = 0
  194. <include refid="queryPageMap"/>
  195. <include refid="global.limit"/>
  196. </select>
  197. <sql id="queryPageMap">
  198. <if test="lockFlag != null">
  199. AND su.lock_flag_ = #{lockFlag}
  200. </if>
  201. <if test="subjectId != null">
  202. AND t.subject_id_ LIKE CONCAT('%',#{subjectId},'%')
  203. </if>
  204. <if test="organId != null">
  205. AND su.organ_id_ = #{organId}
  206. </if>
  207. <if test="jobNature != null">
  208. AND t.job_nature_ = #{jobNature}
  209. </if>
  210. <if test="isProbationPeriod != null">
  211. AND t.is_probation_period_ = #{isProbationPeriod}
  212. </if>
  213. </sql>
  214. <!-- 查询当前表的总记录数 -->
  215. <select id="queryCount" resultType="int">
  216. SELECT COUNT(t.id_)
  217. FROM teacher t LEFT JOIN sys_user su ON t.id_ = su.id_
  218. WHERE su.user_type_ LIKE '%TEACHER%' AND su.del_flag_ = 0
  219. <include refid="queryPageMap"/>
  220. </select>
  221. <!-- 根据证件号查询老师 -->
  222. <select id="findByCertificateNum" resultMap="Teacher">
  223. SELECT * FROM teacher WHERE certificate_num_ = #{certificateNum}
  224. </select>
  225. <select id="queryGroupStudents" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
  226. SELECT su.username_,su.id_ user_id_,su.avatar_ head_url_,su.gender_,s.name_ FROM class_group_teacher_mapper cgtm
  227. LEFT JOIN class_group_student_mapper cgsm ON cgtm.class_group_id_ = cgsm.class_group_id_
  228. LEFT JOIN sys_user su ON cgsm.user_id_ = su.id_
  229. LEFT JOIN student_registration sr ON sr.user_id_ = su.id_
  230. LEFT JOIN `subject` s ON s.id_ = sr.actual_subject_id_
  231. WHERE cgtm.user_id_ = #{teacherId}
  232. <if test="search != null">
  233. AND su.username_ LIKE CONCAT('%',#{search},'%')
  234. </if>
  235. </select>
  236. <select id="queryNameByIds" resultType="java.util.Map" parameterType="list">
  237. select id_ `key`,real_name_ `value` FROM sys_user s WHERE id_ IN
  238. <foreach item="item" index="index" collection="userIds" open="(" separator="," close=")">
  239. #{item}
  240. </foreach>
  241. </select>
  242. <select id="findTeachers" resultMap="Teacher">
  243. SELECT su.* FROM teacher t
  244. LEFT JOIN sys_user su on t.id_ = su.id_ WHERE 1=1
  245. <if test="organId != null and organId !=0">
  246. AND t.organ_id_ = #{organId}
  247. </if>
  248. </select>
  249. <select id="countCloses" resultType="java.lang.Integer">
  250. SELECT COUNT(cs.id_)
  251. FROM course_schedule cs
  252. LEFT JOIN course_schedule_teacher_salary csts ON cs.id_ = csts.course_schedule_id_
  253. LEFT JOIN teacher_attendance ta ON cs.id_ = ta.course_schedule_id_
  254. LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
  255. <include refid="queryCloses"/>
  256. </select>
  257. <resultMap id="TeacherCloseDto" type="com.ym.mec.biz.dal.dto.TeacherCloseDto">
  258. <result property="classDate" column="class_date_"/>
  259. <result property="classTime" column="start_class_time_"/>
  260. <result property="className" column="class_name_"/>
  261. <result property="courseScheduleType" column="class_type_"/>
  262. <result property="teacherRole" column="teacher_role_"/>
  263. <result property="currentClassTimes" column="current_class_times_"/>
  264. <result property="totalClassTimes" column="total_class_times_"/>
  265. <result property="signInStatus" column="sign_in_status_"/>
  266. <result property="signOutStatus" column="sign_out_status_"/>
  267. <result property="actualSalary" column="actual_salary_"/>
  268. <result property="subsidy" column="subsidy_"/>
  269. <result property="settlementTime" column="settlement_time_"/>
  270. <result property="courseScheduleId" column="course_schedule_id_"/>
  271. </resultMap>
  272. <select id="queryCloses" resultMap="TeacherCloseDto">
  273. SELECT cs.id_ course_schedule_id_,cs.class_date_,cs.start_class_time_,cg.name_ class_name_,cs.type_ class_type_,
  274. csts.teacher_role_,cg.current_class_times_,cg.total_class_times_,
  275. ta.sign_in_status_,ta.sign_out_status_,csts.actual_salary_,csts.settlement_time_,csts.subsidy_
  276. FROM course_schedule cs
  277. LEFT JOIN course_schedule_teacher_salary csts ON cs.id_ = csts.course_schedule_id_
  278. LEFT JOIN teacher_attendance ta ON cs.id_ = ta.course_schedule_id_
  279. LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
  280. <include refid="queryCloses"/>
  281. <include refid="global.limit"/>
  282. </select>
  283. <select id="findTeacherNoPay" resultType="decimal">
  284. SELECT SUM(expect_salary_) FROM course_schedule_teacher_salary csts WHERE settlement_time_ IS NULL AND user_id_ = #{teacherId}
  285. </select>
  286. <select id="findTeacherByMusicGroup" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
  287. SELECT
  288. su.id_ user_id_,
  289. su.username_
  290. FROM
  291. class_group_teacher_mapper cgtm
  292. LEFT JOIN class_group cg ON cg.id_=cgtm.class_group_id_
  293. LEFT JOIN sys_user su ON cgtm.user_id_=su.id_
  294. WHERE cg.music_group_id_=#{musicGroupId}
  295. </select>
  296. <resultMap id="MusicGroupTeachersDto" type="com.ym.mec.biz.dal.dto.MusicGroupTeachersDto">
  297. <result property="teacherName" column="real_name_"/>
  298. <result property="teacherPhone" column="phone_"/>
  299. <result property="jobNature" column="job_nature_"/>
  300. <result property="classGroupName" column="class_group_name_"/>
  301. <result property="classGroupId" column="class_group_id_"/>
  302. <result property="teacherId" column="teacher_id_"/>
  303. </resultMap>
  304. <select id="queryMusicGroupTeachers" resultMap="MusicGroupTeachersDto">
  305. SELECT su.real_name_,su.phone_,t.job_nature_,GROUP_CONCAT(cg.name_) class_group_name_,cgtm.class_group_id_,t.id_ teacher_id_
  306. FROM teacher t
  307. LEFT JOIN class_group_teacher_mapper cgtm ON t.id_ = cgtm.user_id_
  308. LEFT JOIN class_group cg ON cg.id_ = cgtm.class_group_id_
  309. LEFT JOIN sys_user su ON t.id_ = su.id_
  310. <include refid="queryMusicGroupTeachersSql"/>
  311. GROUP BY t.id_,cgtm.class_group_id_
  312. <include refid="global.limit"/>
  313. </select>
  314. <select id="countMusicGroupTeachers" resultType="java.lang.Integer">
  315. SELECT COUNT(DISTINCT t.id_)
  316. FROM teacher t
  317. LEFT JOIN class_group_teacher_mapper cgtm ON t.id_ = cgtm.user_id_
  318. LEFT JOIN class_group cg ON cg.id_ = cgtm.class_group_id_
  319. LEFT JOIN sys_user su ON t.id_ = su.id_
  320. <include refid="queryMusicGroupTeachersSql"/>
  321. </select>
  322. <sql id="queryMusicGroupTeachersSql">
  323. <where>
  324. cg.type_ = 'MIX'
  325. <if test="search != null and search != ''">
  326. AND (su.real_name_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%'))
  327. </if>
  328. <if test="musicGroupId != null and musicGroupId != ''">
  329. AND cgtm.music_group_id_ = #{musicGroupId}
  330. </if>
  331. <if test="classGroupId != null">
  332. AND cg.id_ = #{classGroupId}
  333. </if>
  334. </where>
  335. </sql>
  336. <select id="findSignNum" resultType="java.util.Map">
  337. SELECT ta.teacher_id_ 'key',COUNT(ta.id_) 'value' FROM teacher_attendance ta
  338. WHERE FIND_IN_SET(ta.teacher_id_,#{teacherIdStr}) AND FIND_IN_SET(ta.class_group_id_,#{classGroupIdStr})
  339. GROUP BY ta.teacher_id_,ta.class_group_id_
  340. </select>
  341. <sql id="queryTeacherAttendanceSql">
  342. <where>
  343. (cs.type_ = 'SINGLE' OR cs.type_ = 'MIX')
  344. <if test="startTime != null and startTime != ''">
  345. AND cs.class_date_ &gt;= #{startTime}
  346. </if>
  347. <if test="endTime != null and endTime != ''">
  348. AND cs.class_date_ &lt;= #{endTime}
  349. </if>
  350. <if test="musicGroupId != null and musicGroupId != ''">
  351. AND ta.music_group_id_ = #{musicGroupId}
  352. </if>
  353. <if test="teacherName != null and teacherName != ''">
  354. AND su.real_name_ LIKE CONCAT('%',#{teacherName},'%')
  355. </if>
  356. </where>
  357. </sql>
  358. <resultMap id="MusicGroupTeacherAttendanceDto" type="com.ym.mec.biz.dal.dto.MusicGroupTeacherAttendanceDto">
  359. <result property="classDate" column="class_date_"/>
  360. <result property="startClassTime" column="start_class_time_"/>
  361. <result property="courseScheduleName" column="name_"/>
  362. <result property="realName" column="real_name_"/>
  363. <result property="signInStatus" column="sign_in_status_"/>
  364. <result property="signOutStatus" column="sign_out_status_"/>
  365. </resultMap>
  366. <select id="queryTeacherAttendance" resultMap="MusicGroupTeacherAttendanceDto">
  367. SELECT cs.class_date_,cs.start_class_time_,cs.name_,su.real_name_,
  368. IF(ta.sign_in_status_ IS NULL,3,ta.sign_in_status_) sign_in_status_,IF(ta.sign_out_status_ IS NULL,3,ta.sign_out_status_) sign_out_status_
  369. FROM course_schedule cs
  370. LEFT JOIN teacher_attendance ta ON cs.id_ = ta.course_schedule_id_
  371. LEFT JOIN sys_user su ON su.id_ = ta.teacher_id_
  372. <include refid="queryTeacherAttendanceSql"/>
  373. <include refid="global.limit"/>
  374. </select>
  375. <select id="countTeacherAttendance" resultType="java.lang.Integer">
  376. SELECT COUNT(cs.id_)
  377. FROM course_schedule cs
  378. LEFT JOIN teacher_attendance ta ON cs.id_ = ta.course_schedule_id_
  379. LEFT JOIN sys_user su ON su.id_ = ta.teacher_id_
  380. <include refid="queryTeacherAttendanceSql"/>
  381. </select>
  382. <sql id="queryCloses">
  383. <where>
  384. <if test="teacherId != null">
  385. AND cs.actual_teacher_id_ = #{teacherId}
  386. </if>
  387. <if test="courseStartDate != null and courseStartDate != ''">
  388. AND cs.class_date_ &gt;= #{courseStartDate}
  389. </if>
  390. <if test="courseEndDate != null and courseEndDate != ''">
  391. AND cs.class_date_ &lt;= #{courseEndDate}
  392. </if>
  393. <if test="courseScheduleType != null and courseScheduleType != ''">
  394. AND cs.type_ = #{courseScheduleType}
  395. </if>
  396. <if test="teacherRole != null and teacherRole != ''">
  397. AND csts.teacher_role_ = #{teacherRole}
  398. </if>
  399. </where>
  400. </sql>
  401. </mapper>