EmployeeMapper.xml 20 KB

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