EmployeeMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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.EmployeeDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.Employee" id="Employee">
  9. <result column="user_id_" property="userId"/>
  10. <result column="organ_id_list_" property="organIdList"/>
  11. <result column="job_nature_" property="jobNature"/>
  12. <result column="is_probation_period_" property="isProbationPeriod"/>
  13. <result column="education_background_" property="educationBackground"/>
  14. <result column="graduate_school_" property="graduateSchool"/>
  15. <result column="technical_titles_" property="technicalTitles"/>
  16. <result column="entry_date_" property="entryDate"/>
  17. <result column="certificate_type_" property="certificateType"/>
  18. <result column="certificate_num_" property="certificateNum"/>
  19. <result column="update_time_" property="updateTime"/>
  20. <result column="create_time_" property="createTime"/>
  21. <result column="introduction_" property="introduction"/>
  22. <result column="demission_date_" property="demissionDate"/>
  23. <result column="contact_address_" property="contactAddress"/>
  24. <result column="postal_code_" property="postalCode"/>
  25. <result column="dept_id_" property="deptId"/>
  26. <result column="dept_ids_" property="deptIds"/>
  27. <result column="post_ids_" property="postIds"/>
  28. <result column="post_dept_ids_" property="postDeptIds"/>
  29. <result column="bank_card_" property="bankCard"/>
  30. <result column="open_bank_address_" property="openBankAddress"/>
  31. <result column="tenant_id_" property="tenantId" />
  32. </resultMap>
  33. <resultMap type="com.ym.mec.auth.api.entity.SysUser" id="SysUser">
  34. <result column="id_" property="id"/>
  35. <result column="username_" property="username"/>
  36. <result column="password_" property="password"/>
  37. <result column="salt_" property="salt"/>
  38. <result column="phone_" property="phone"/>
  39. <result column="avatar_" property="avatar"/>
  40. <result column="organ_id_" property="organId"/>
  41. <result column="create_time_" property="createTime"/>
  42. <result column="update_time_" property="updateTime"/>
  43. <result column="lock_flag_" property="lockFlag"/>
  44. <result column="del_flag_" property="delFlag" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  45. <result column="wx_openid_" property="wxOpenid"/>
  46. <result column="qq_openid_" property="qqOpenid"/>
  47. <result column="user_type_" property="userType"/>
  48. <result column="gender_" property="gender"/>
  49. <result column="nation_" property="nation"/>
  50. <result column="birthdate_" property="birthdate"/>
  51. <result column="email_" property="email"/>
  52. <result column="im_token_" property="imToken"/>
  53. <result column="real_name_" property="realName"/>
  54. <result column="id_card_no_" property="idCardNo"/>
  55. <result column="wechat_id_" property="wechatId"/>
  56. </resultMap>
  57. <!-- 根据主键查询一条记录 -->
  58. <select id="get" resultMap="Employee">
  59. SELECT * FROM employee WHERE user_id_ = #{userId}
  60. </select>
  61. <!-- 全查询 -->
  62. <select id="findAll" resultMap="Employee">
  63. SELECT * FROM employee where tenant_id_ = #{tenantId} ORDER BY user_id_
  64. </select>
  65. <!-- 向数据库增加一条记录 -->
  66. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.Employee" useGeneratedKeys="true" keyColumn="id"
  67. keyProperty="id">
  68. INSERT INTO employee
  69. (user_id_,organ_id_list_,job_nature_,is_probation_period_,education_background_,graduate_school_,technical_titles_,
  70. entry_date_,certificate_type_,certificate_num_,update_time_,create_time_,introduction_,demission_date_,contact_address_,postal_code_,dept_id_,dept_ids_,post_ids_,post_dept_ids_,tenant_id_)
  71. VALUES(#{userId},#{organIdList},#{jobNature},#{isProbationPeriod},#{educationBackground},#{graduateSchool},
  72. #{technicalTitles},#{entryDate},#{certificateType},#{certificateNum},now(),now(),#{introduction},#{demissionDate},#{contactAddress},#{postalCode},#{deptId},#{deptIds},#{postIds},#{postDeptIds},#{tenantId})
  73. </insert>
  74. <insert id="batchAddEmployeeRole">
  75. INSERT INTO sys_user_role(user_id_,role_id_,tenant_id_) values
  76. <foreach collection="roleIds" item="item" index="index" separator=",">
  77. (#{userId},#{item},#{tenantId})
  78. </foreach>
  79. </insert>
  80. <insert id="batchInsertRoleMenu">
  81. INSERT INTO sys_role_menu (role_id_,menu_id_,tenant_id_) VALUES
  82. <foreach collection="menuIds" item="item" index="index" separator=",">
  83. (#{roleId}, #{item},#{tenantId})
  84. </foreach>
  85. </insert>
  86. <delete id="delRoleMenu">
  87. DELETE FROM `sys_role_menu`
  88. WHERE tenant_id_ = #{tenantId}
  89. and menu_id_ in
  90. <foreach collection="menuIds" open="(" close=")" item="item" separator=",">
  91. #{item}
  92. </foreach>
  93. </delete>
  94. <insert id="insertSysRole" keyColumn="id_" keyProperty="id" parameterType="com.ym.mec.auth.api.entity.SysRole"
  95. useGeneratedKeys="true">
  96. INSERT INTO `sys_role` (`role_name_`, `role_code_`, `role_desc_`, `create_time_`,
  97. `update_time_`, `del_flag_`, `organ_id_`, `tenant_id_`)
  98. VALUES (#{roleName}, #{roleCode}, #{roleDesc}, #{createTime},
  99. #{updateTime}, #{delFlag}, #{organId}, #{tenantId});
  100. </insert>
  101. <select id="queryByPhone" resultMap="SysUser">
  102. select * from sys_user where phone_ = #{phone} OR username_ = #{phone}
  103. </select>
  104. <!-- 根据主键查询一条记录 -->
  105. <update id="update" parameterType="com.ym.mec.biz.dal.entity.Employee">
  106. UPDATE employee
  107. <set>
  108. <if test="contactAddress != null">
  109. contact_address_ = #{contactAddress},
  110. </if>
  111. <if test="postalCode != null">
  112. postal_code_ = #{postalCode},
  113. </if>
  114. <if test="isProbationPeriod != null">
  115. is_probation_period_ = #{isProbationPeriod},
  116. </if>
  117. <if test="graduateSchool != null">
  118. graduate_school_ = #{graduateSchool},
  119. </if>
  120. <if test="organIdList != null">
  121. organ_id_list_ = #{organIdList},
  122. </if>
  123. <if test="introduction != null">
  124. introduction_ = #{introduction},
  125. </if>
  126. <if test="technicalTitles != null">
  127. technical_titles_ = #{technicalTitles},
  128. </if>
  129. <if test="entryDate != null">
  130. entry_date_ = #{entryDate},
  131. </if>
  132. <if test="jobNature != null">
  133. job_nature_ = #{jobNature},
  134. </if>
  135. <if test="certificateType != null">
  136. certificate_type_ = #{certificateType},
  137. </if>
  138. <if test="updateTime != null">
  139. update_time_ = NOW(),
  140. </if>
  141. <if test="educationBackground != null">
  142. education_background_ = #{educationBackground},
  143. </if>
  144. <if test="certificateNum != null">
  145. certificate_num_ = #{certificateNum},
  146. </if>
  147. <if test="demissionDate != null">
  148. demission_date_ = #{demissionDate},
  149. </if>
  150. dept_id_ = #{deptId},
  151. <if test="deptIds != null">
  152. dept_ids_ = #{deptIds},
  153. </if>
  154. <if test="postIds != null">
  155. post_ids_ = #{postIds},
  156. </if>
  157. <if test="postDeptIds != null">
  158. post_dept_ids_ = #{postDeptIds},
  159. </if>
  160. </set>
  161. WHERE user_id_ = #{userId} and tenant_id_ = #{tenantId}
  162. </update>
  163. <update id="updatePassword">
  164. UPDATE sys_user SET password_ = #{password} WHERE id_ = #{userID}
  165. </update>
  166. <update id="updateUserLockStatus">
  167. UPDATE sys_user SET lock_flag_ = IF(lock_flag_=0,1,0) WHERE id_=#{userID}
  168. </update>
  169. <update id="updateUserDemissionDate">
  170. UPDATE employee SET demission_date_ = IF(demission_date_ IS NULL,now(),NULL) WHERE user_id_=#{userID}
  171. </update>
  172. <update id="updateUserLock">
  173. UPDATE sys_user SET lock_flag_ = #{status} WHERE id_=#{userID}
  174. </update>
  175. <update id="updateEducationTeacherId">
  176. UPDATE music_group SET educational_teacher_id_ = #{targetUserId} WHERE educational_teacher_id_ = #{currentUserId} AND status_ != 'CANCELED';
  177. UPDATE vip_group SET educational_teacher_id_ = #{targetUserId} WHERE educational_teacher_id_ = #{currentUserId} AND group_status_ IN (0,1,5,2,6,4);
  178. UPDATE practice_group SET educational_teacher_id_ = #{targetUserId} WHERE educational_teacher_id_ = #{currentUserId} AND group_status_ != 'CANCEL';
  179. </update>
  180. <!-- 根据主键删除一条记录 -->
  181. <delete id="delete">
  182. DELETE FROM employee WHERE user_id_ = #{userId}
  183. </delete>
  184. <delete id="delEmployeeRole">
  185. DELETE FROM sys_user_role WHERE user_id_ = #{userId}
  186. </delete>
  187. <!-- 分页查询 -->
  188. <select id="queryPage" resultMap="Employee" parameterType="map">
  189. SELECT * FROM employee where tenant_id_ = #{tenantId} ORDER BY user_id_
  190. <include refid="global.limit"/>
  191. </select>
  192. <!-- 查询当前表的总记录数 -->
  193. <select id="queryCount" resultType="int">
  194. SELECT COUNT(*) FROM employee where tenant_id_ = #{tenantId}
  195. </select>
  196. <resultMap type="com.ym.mec.biz.dal.dto.EmployeeDto" id="EmployeeDto">
  197. <result property="id" column="user_id_"/>
  198. <result property="realName" column="real_name_"/>
  199. <result property="gender" column="gender_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  200. <result property="phone" column="phone_"/>
  201. <result property="lockFlag" column="lock_flag_"/>
  202. <result property="jobNature" column="job_nature_"/>
  203. <result property="entryDate" column="entry_date_"/>
  204. <result property="demissionDate" column="demission_date_"/>
  205. <result property="contactAddress" column="contact_address_"/>
  206. <result property="postalCode" column="postal_code_"/>
  207. <result property="organIdStr" column="organ_id_str_"/>
  208. <result property="deptId" column="dept_id_"/>
  209. <result property="deptIds" column="dept_ids_"/>
  210. <result property="postIds" column="post_ids_"/>
  211. <result property="postDeptIds" column="post_dept_ids_"/>
  212. <collection property="roleNames" ofType="string" javaType="list">
  213. <result column="role_name_"/>
  214. </collection>
  215. <collection property="roleIds" ofType="integer" javaType="list">
  216. <result column="role_id_"/>
  217. </collection>
  218. </resultMap>
  219. <select id="queryEmployByOrganId" resultMap="EmployeeDto">
  220. SELECT ue.*,ue.organ_id_ organ_id_str_,sr.role_name_,sr.id_ role_id_
  221. FROM (SELECT e.user_id_,su.real_name_,su.gender_,su.phone_,su.user_type_,e.job_nature_,su.lock_flag_,
  222. e.entry_date_,e.demission_date_,e.organ_id_list_ organ_id_,e.create_time_,e.contact_address_,
  223. e.postal_code_,e.dept_id_,e.dept_ids_,e.post_ids_,e.post_dept_ids_
  224. FROM employee e
  225. LEFT JOIN sys_user su ON e.user_id_ = su.id_
  226. <if test="roleId != null">
  227. LEFT JOIN sys_user_role sur ON sur.user_id_ = e.user_id_
  228. </if>
  229. <where>
  230. su.del_flag_ = 0 and su.tenant_id_ = #{tenantId}
  231. <if test="lockFlag != null">
  232. AND su.lock_flag_ = #{lockFlag}
  233. </if>
  234. <if test="demissionflag != null and demissionflag == 1">
  235. AND e.demission_date_ IS NOT NULL
  236. </if>
  237. <if test="demissionflag != null and demissionflag == 0">
  238. AND e.demission_date_ IS NULL
  239. </if>
  240. <if test="organId != null">
  241. AND INTE_ARRAY(e.organ_id_list_,#{organId})
  242. </if>
  243. <if test="roleId != null">
  244. AND sur.role_id_ = #{roleId}
  245. </if>
  246. <if test="jobNature != null">
  247. AND e.job_nature_ = #{jobNature}
  248. </if>
  249. <if test="search != null">
  250. AND (su.real_name_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%') or su.id_ like CONCAT('%',#{search},'%'))
  251. </if>
  252. </where>
  253. ORDER BY e.create_time_ DESC <include refid="global.limit"/>) ue
  254. LEFT JOIN sys_user_role sur ON sur.user_id_ = ue.user_id_
  255. LEFT JOIN sys_role sr ON sr.id_ = sur.role_id_
  256. </select>
  257. <select id="queryEmployByOrganIdCount" resultType="int">
  258. SELECT COUNT(DISTINCT e.user_id_)
  259. FROM employee e
  260. LEFT JOIN sys_user su ON e.user_id_ = su.id_
  261. <if test="roleId != null">
  262. LEFT JOIN sys_user_role sur ON sur.user_id_ = e.user_id_
  263. </if>
  264. <where>
  265. su.del_flag_ = 0 and su.tenant_id_ = #{tenantId}
  266. <if test="organId != null">
  267. AND INTE_ARRAY(e.organ_id_list_,#{organId})
  268. </if>
  269. <if test="demissionflag != null and demissionflag == 1">
  270. AND e.demission_date_ IS NOT NULL
  271. </if>
  272. <if test="demissionflag != null and demissionflag == 0">
  273. AND e.demission_date_ IS NULL
  274. </if>
  275. <if test="jobNature != null">
  276. AND e.job_nature_ = #{jobNature}
  277. </if>
  278. <if test="search != null">
  279. AND (su.real_name_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%') or su.id_ like CONCAT('%',#{search},'%'))
  280. </if>
  281. <if test="roleId != null">
  282. AND sur.role_id_ = #{roleId}
  283. </if>
  284. </where>
  285. </select>
  286. <select id="queryUserRole" resultType="java.lang.Integer">
  287. SELECT sur.role_id_ FROM sys_user_role sur WHERE sur.user_id_ = #{userId}
  288. </select>
  289. <select id="findByRole" resultType="com.ym.mec.biz.dal.dto.SimpleUserDto">
  290. SELECT DISTINCT su.id_ userId,
  291. su.real_name_ userName,
  292. su.avatar_ avatar,
  293. e.organ_id_list_ organIds
  294. FROM
  295. sys_user su
  296. LEFT JOIN sys_user_role sur ON su.id_ = sur.user_id_
  297. LEFT JOIN employee e ON e.user_id_ = su.id_
  298. WHERE
  299. su.lock_flag_ = 0 AND su.del_flag_ = 0 AND FIND_IN_SET(sur.role_id_, #{roleIds})
  300. <if test="organIds!=null and organIds!=''">
  301. AND INTE_ARRAY(e.organ_id_list_,#{organIds})
  302. </if>
  303. </select>
  304. <select id="findByIds" resultType="com.ym.mec.biz.dal.dto.SimpleUserDto">
  305. SELECT su.id_ userId,su.real_name_ userName
  306. FROM sys_user su
  307. WHERE id_ IN
  308. <foreach collection="userIds" item="userId" separator="," open="(" close=")">
  309. #{userId}
  310. </foreach>
  311. </select>
  312. <select id="hasCourseGroupRelation" resultType="java.lang.Integer">
  313. SELECT SUM(a.num) FROM
  314. (SELECT COUNT(vg.id_) num FROM vip_group vg WHERE vg.educational_teacher_id_ = #{employeeId} AND vg.group_status_ IN (0,1,5,2,6,4)
  315. UNION ALL
  316. SELECT COUNT(mg.id_) num FROM music_group mg WHERE mg.educational_teacher_id_ = #{employeeId} AND mg.status_ != 'CANCELED'
  317. UNION ALL
  318. SELECT COUNT(pg.id_) num FROM practice_group pg WHERE pg.educational_teacher_id_ = #{employeeId} AND pg.group_status_ != 'CANCEL')a
  319. </select>
  320. <select id="hasCourseSchedule" resultType="java.lang.Integer">
  321. SELECT COUNT(DISTINCT cs.id_)
  322. FROM course_schedule_teacher_salary csts
  323. LEFT JOIN course_schedule cs ON cs.id_ = csts.course_schedule_id_
  324. AND CONCAT(cs.class_date_,' ',cs.start_class_time_) > NOW() AND cs.del_flag_ = 0 AND cs.pre_course_flag_ = 0
  325. WHERE csts.user_id_ = #{employeeId}
  326. </select>
  327. <select id="queryRepairOrganList" resultType="java.lang.Integer">
  328. SELECT DISTINCT organ_id_ FROM music_group mg
  329. WHERE repair_user_id_ = #{userId}
  330. </select>
  331. <select id="queryEducationOrganList" resultType="java.lang.Integer">
  332. SELECT DISTINCT c.organ_id_ FROM (
  333. SELECT organ_id_ FROM music_group
  334. WHERE educational_teacher_id_ = #{userId}
  335. UNION
  336. SELECT organ_id_ FROM practice_group
  337. WHERE educational_teacher_id_ = #{userId}
  338. UNION
  339. SELECT organ_id_ FROM vip_group
  340. WHERE educational_teacher_id_ = #{userId}) c
  341. </select>
  342. <select id="queryTeamTeacherOrganList" resultType="java.lang.Integer">
  343. SELECT DISTINCT organ_id_ FROM music_group
  344. WHERE team_teacher_id_ = #{userId}
  345. </select>
  346. <select id="queryDirectorOrganList" resultType="java.lang.Integer">
  347. SELECT DISTINCT organ_id_ FROM music_group
  348. WHERE director_user_id_ = #{userId}
  349. </select>
  350. <update id="employeeLevel">
  351. <foreach collection="employeeLevelDtos" item="item">
  352. <if test="item.roleName == 'repair'">
  353. UPDATE music_group SET repair_user_id_ = #{item.transferUserId} WHERE repair_user_id_ = #{item.levelUserId} AND organ_id_ = #{item.organId};
  354. </if>
  355. <if test="item.roleName == 'education'">
  356. UPDATE music_group SET educational_teacher_id_ = #{item.transferUserId} WHERE educational_teacher_id_ = #{item.levelUserId} AND organ_id_ = #{item.organId};
  357. UPDATE practice_group SET educational_teacher_id_ = #{item.transferUserId} WHERE educational_teacher_id_ = #{item.levelUserId} AND organ_id_ = #{item.organId};
  358. UPDATE vip_group SET educational_teacher_id_ = #{item.transferUserId} WHERE educational_teacher_id_ = #{item.levelUserId} AND organ_id_ = #{item.organId};
  359. </if>
  360. <if test="item.roleName == 'teamTeacher'">
  361. UPDATE music_group SET team_teacher_id_ = #{item.transferUserId} WHERE team_teacher_id_ = #{item.levelUserId} AND organ_id_ = #{item.organId};
  362. </if>
  363. <if test="item.roleName == 'director'">
  364. UPDATE music_group SET director_user_id_ = #{item.transferUserId} WHERE director_user_id_ = #{item.levelUserId} AND organ_id_ = #{item.organId};
  365. </if>
  366. </foreach>
  367. </update>
  368. <select id="findAllByRole" resultType="com.ym.mec.biz.dal.dto.SimpleUserDto">
  369. SELECT DISTINCT su.id_ userId,
  370. su.real_name_ userName,
  371. su.avatar_ avatar,
  372. e.organ_id_list_ organIds
  373. FROM
  374. sys_user su
  375. LEFT JOIN sys_user_role sur ON su.id_ = sur.user_id_
  376. LEFT JOIN employee e ON e.user_id_ = su.id_
  377. WHERE FIND_IN_SET(sur.role_id_, #{roleIds})
  378. <if test="organIds!=null and organIds!=''">
  379. AND INTE_ARRAY(e.organ_id_list_,#{organIds})
  380. </if>
  381. </select>
  382. <select id="queryMusicGroupIdByUserId" resultType="java.lang.String">
  383. SELECT DISTINCT id_ FROM music_group
  384. WHERE (director_user_id_ = #{levelUserId} OR educational_teacher_id_ = #{levelUserId} OR team_teacher_id_ = #{levelUserId} OR repair_user_id_ = #{levelUserId})
  385. AND status_ IN ('PROGRESS','PAUSE','PREPARE')
  386. </select>
  387. <select id="queryPracticeGroupIdByUserId" resultType="java.lang.String">
  388. SELECT DISTINCT id_ FROM practice_group
  389. WHERE educational_teacher_id_ = #{levelUserId} AND group_status_ = 'NORMAL'
  390. </select>
  391. <select id="queryVipGroupIdByUserId" resultType="java.lang.String">
  392. SELECT DISTINCT id_ FROM vip_group
  393. WHERE educational_teacher_id_ = #{levelUserId} AND group_status_ IN (2,6)
  394. </select>
  395. <select id="getUsers" resultMap="SysUser">
  396. select * from sys_user where id_ IN
  397. <foreach collection="userIds" open="(" close=")" separator="," item="userId">
  398. #{userId}
  399. </foreach>
  400. </select>
  401. </mapper>