EmployeeMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. </resultMap>
  26. <resultMap type="com.ym.mec.auth.api.entity.SysUser" id="SysUser">
  27. <result column="id_" property="id"/>
  28. <result column="username_" property="username"/>
  29. <result column="password_" property="password"/>
  30. <result column="salt_" property="salt"/>
  31. <result column="phone_" property="phone"/>
  32. <result column="avatar_" property="avatar"/>
  33. <result column="organ_id_" property="organId"/>
  34. <result column="create_time_" property="createTime"/>
  35. <result column="update_time_" property="updateTime"/>
  36. <result column="lock_flag_" property="lockFlag"/>
  37. <result column="del_flag_" property="delFlag" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  38. <result column="wx_openid_" property="wxOpenid"/>
  39. <result column="qq_openid_" property="qqOpenid"/>
  40. <result column="user_type_" property="userType"/>
  41. <result column="gender_" property="gender"/>
  42. <result column="nation_" property="nation"/>
  43. <result column="birthdate_" property="birthdate"/>
  44. <result column="email_" property="email"/>
  45. <result column="im_token_" property="imToken"/>
  46. <result column="id_card_no_" property="idCardNo"/>
  47. <result column="wechat_id_" property="wechatId"/>
  48. </resultMap>
  49. <!-- 根据主键查询一条记录 -->
  50. <select id="get" resultMap="Employee">
  51. SELECT * FROM employee WHERE user_id_ = #{userId}
  52. </select>
  53. <!-- 全查询 -->
  54. <select id="findAll" resultMap="Employee">
  55. SELECT * FROM employee ORDER BY user_id_
  56. </select>
  57. <!-- 向数据库增加一条记录 -->
  58. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.Employee" useGeneratedKeys="true" keyColumn="id"
  59. keyProperty="id">
  60. <!--
  61. <selectKey resultClass="int" keyProperty="id" >
  62. SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL
  63. </selectKey>
  64. -->
  65. INSERT INTO employee
  66. (user_id_,organ_id_list_,job_nature_,is_probation_period_,education_background_,graduate_school_,technical_titles_,
  67. entry_date_,certificate_type_,certificate_num_,update_time_,create_time_,introduction_,demission_date_,contact_address_,postal_code_)
  68. VALUES(#{userId},#{organIdList},#{jobNature},#{isProbationPeriod},#{educationBackground},#{graduateSchool},
  69. #{technicalTitles},#{entryDate},#{certificateType},#{certificateNum},now(),now(),#{introduction},#{demissionDate},#{contactAddress},#{postalCode})
  70. </insert>
  71. <insert id="batchAddEmployeeRole">
  72. INSERT INTO sys_user_role(user_id_,role_id_) values
  73. <foreach collection="roleIds" item="item" index="index" separator=",">
  74. (#{userId},#{item})
  75. </foreach>
  76. </insert>
  77. <select id="queryByPhone" resultMap="SysUser">
  78. select * from sys_user where phone_ = #{phone} OR username_ = #{phone}
  79. </select>
  80. <!-- 根据主键查询一条记录 -->
  81. <update id="update" parameterType="com.ym.mec.biz.dal.entity.Employee">
  82. UPDATE employee
  83. <set>
  84. <if test="contactAddress != null">
  85. contact_address_ = #{contactAddress},
  86. </if>
  87. <if test="postalCode != null">
  88. postal_code_ = #{postalCode},
  89. </if>
  90. <if test="isProbationPeriod != null">
  91. is_probation_period_ = #{isProbationPeriod},
  92. </if>
  93. <if test="graduateSchool != null">
  94. graduate_school_ = #{graduateSchool},
  95. </if>
  96. <if test="organIdList != null">
  97. organ_id_list_ = #{organIdList},
  98. </if>
  99. <if test="introduction != null">
  100. introduction_ = #{introduction},
  101. </if>
  102. <if test="technicalTitles != null">
  103. technical_titles_ = #{technicalTitles},
  104. </if>
  105. <if test="entryDate != null">
  106. entry_date_ = #{entryDate},
  107. </if>
  108. <if test="jobNature != null">
  109. job_nature_ = #{jobNature},
  110. </if>
  111. <if test="certificateType != null">
  112. certificate_type_ = #{certificateType},
  113. </if>
  114. <if test="updateTime != null">
  115. update_time_ = NOW(),
  116. </if>
  117. <if test="educationBackground != null">
  118. education_background_ = #{educationBackground},
  119. </if>
  120. <if test="certificateNum != null">
  121. certificate_num_ = #{certificateNum},
  122. </if>
  123. <if test="demissionDate != null">
  124. demission_date_ = #{demissionDate},
  125. </if>
  126. </set>
  127. WHERE user_id_ = #{userId}
  128. </update>
  129. <update id="updatePassword">
  130. UPDATE sys_user SET password_ = #{password} WHERE id_ = #{userID}
  131. </update>
  132. <update id="updateUserLockStatus">
  133. UPDATE sys_user SET lock_flag_ = IF(lock_flag_=0,1,0) WHERE id_=#{userID}
  134. </update>
  135. <update id="updateUserDemissionDate">
  136. UPDATE employee SET demission_date_ = IF(demission_date_ IS NULL,now(),NULL) WHERE user_id_=#{userID}
  137. </update>
  138. <update id="updateUserLock">
  139. UPDATE sys_user SET lock_flag_ = #{status} WHERE id_=#{userID}
  140. </update>
  141. <update id="updateEducationTeacherId">
  142. UPDATE music_group SET educational_teacher_id_ = #{targetUserId} WHERE educational_teacher_id_ = #{currentUserId} AND status_ != 'CANCELED';
  143. UPDATE vip_group SET educational_teacher_id_ = #{targetUserId} WHERE educational_teacher_id_ = #{currentUserId} AND group_status_ IN (0,1,5,2,6,4);
  144. UPDATE practice_group SET educational_teacher_id_ = #{targetUserId} WHERE educational_teacher_id_ = #{currentUserId} AND group_status_ != 'CANCEL';
  145. </update>
  146. <!-- 根据主键删除一条记录 -->
  147. <delete id="delete">
  148. DELETE FROM employee WHERE user_id_ = #{userId}
  149. </delete>
  150. <delete id="delEmployeeRole">
  151. DELETE FROM sys_user_role WHERE user_id_ = #{userId}
  152. </delete>
  153. <!-- 分页查询 -->
  154. <select id="queryPage" resultMap="Employee" parameterType="map">
  155. SELECT * FROM employee ORDER BY user_id_
  156. <include refid="global.limit"/>
  157. </select>
  158. <!-- 查询当前表的总记录数 -->
  159. <select id="queryCount" resultType="int">
  160. SELECT COUNT(*) FROM employee
  161. </select>
  162. <resultMap type="com.ym.mec.biz.dal.dto.EmployeeDto" id="EmployeeDto">
  163. <result property="id" column="user_id_"/>
  164. <result property="realName" column="real_name_"/>
  165. <result property="gender" column="gender_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  166. <result property="phone" column="phone_"/>
  167. <result property="lockFlag" column="lock_flag_"/>
  168. <result property="jobNature" column="job_nature_"/>
  169. <result property="entryDate" column="entry_date_"/>
  170. <result property="demissionDate" column="demission_date_"/>
  171. <result property="contactAddress" column="contact_address_"/>
  172. <result property="postalCode" column="postal_code_"/>
  173. <collection property="roleNames" ofType="string" javaType="list">
  174. <result column="role_name_"/>
  175. </collection>
  176. <collection property="organNameList" ofType="string" javaType="list">
  177. <result column="organ_name_list_"/>
  178. </collection>
  179. <collection property="roleIds" ofType="integer" javaType="list">
  180. <result column="role_id_"/>
  181. </collection>
  182. <collection property="organIdList" ofType="Long" javaType="list">
  183. <result column="organ_id_list_"/>
  184. </collection>
  185. </resultMap>
  186. <select id="queryEmployByOrganId" resultMap="EmployeeDto">
  187. SELECT ue.*,o.name_ organ_name_list_,o.id_ organ_id_list_,sr.role_name_,sr.id_ role_id_
  188. FROM (SELECT e.user_id_,su.real_name_,su.gender_,su.phone_,su.user_type_,e.job_nature_,su.lock_flag_,
  189. e.entry_date_,e.demission_date_,e.organ_id_list_ organ_id_,e.create_time_,e.contact_address_,e.postal_code_
  190. FROM employee e
  191. LEFT JOIN sys_user su ON e.user_id_ = su.id_
  192. <if test="roleId != null">
  193. LEFT JOIN sys_user_role sur ON sur.user_id_ = e.user_id_
  194. </if>
  195. <where>
  196. <if test="demissionflag != null and demissionflag == 1">
  197. AND e.demission_date_ IS NOT NULL
  198. </if>
  199. <if test="demissionflag != null and demissionflag == 0">
  200. AND e.demission_date_ IS NULL
  201. </if>
  202. <if test="organId != null">
  203. AND INTE_ARRAY(e.organ_id_list_,#{organId})
  204. </if>
  205. <if test="roleId != null">
  206. AND sur.role_id_ = #{roleId}
  207. </if>
  208. <if test="jobNature != null">
  209. AND e.job_nature_ = #{jobNature}
  210. </if>
  211. <if test="search != null">
  212. AND (su.real_name_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%'))
  213. </if>
  214. </where>
  215. ORDER BY e.create_time_ DESC <include refid="global.limit"/>) ue
  216. LEFT JOIN sys_user_role sur ON sur.user_id_ = ue.user_id_
  217. LEFT JOIN sys_role sr ON sr.id_ = sur.role_id_
  218. LEFT JOIN organization o ON FIND_IN_SET(o.id_,ue.organ_id_)
  219. </select>
  220. <select id="queryEmployByOrganIdCount" resultType="int">
  221. SELECT COUNT(DISTINCT e.user_id_)
  222. FROM employee e
  223. LEFT JOIN sys_user su ON e.user_id_ = su.id_
  224. <if test="roleId != null">
  225. LEFT JOIN sys_user_role sur ON sur.user_id_ = e.user_id_
  226. </if>
  227. <where>
  228. <if test="organId != null">
  229. AND INTE_ARRAY(e.organ_id_list_,#{organId})
  230. </if>
  231. <if test="demissionflag != null and demissionflag == 1">
  232. AND e.demission_date_ IS NOT NULL
  233. </if>
  234. <if test="demissionflag != null and demissionflag == 0">
  235. AND e.demission_date_ IS NULL
  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},'%'))
  242. </if>
  243. <if test="roleId != null">
  244. AND sur.role_id_ = #{roleId}
  245. </if>
  246. </where>
  247. </select>
  248. <select id="queryUserRole" resultType="java.lang.Integer">
  249. SELECT sur.role_id_ FROM sys_user_role sur WHERE sur.user_id_ = #{userId}
  250. </select>
  251. <select id="findByRole" resultType="com.ym.mec.biz.dal.dto.SimpleUserDto">
  252. SELECT DISTINCT su.id_ userId,
  253. su.real_name_ userName,
  254. su.avatar_ avatar,
  255. e.organ_id_list_ organIds
  256. FROM
  257. sys_user su
  258. LEFT JOIN sys_user_role sur ON su.id_ = sur.user_id_
  259. LEFT JOIN employee e ON e.user_id_ = su.id_
  260. WHERE
  261. su.lock_flag_ = 0 AND su.del_flag_ = 0 AND FIND_IN_SET(sur.role_id_, #{roleIds})
  262. <if test="organIds!=null and organIds!=''">
  263. AND INTE_ARRAY(e.organ_id_list_,#{organIds})
  264. </if>
  265. </select>
  266. <select id="findByIds" resultType="com.ym.mec.biz.dal.dto.SimpleUserDto">
  267. SELECT su.id_ userId,su.real_name_ userName
  268. FROM sys_user su
  269. WHERE id_ IN
  270. <foreach collection="userIds" item="userId" separator="," open="(" close=")">
  271. #{userId}
  272. </foreach>
  273. </select>
  274. <select id="hasCourseGroupRelation" resultType="java.lang.Integer">
  275. SELECT SUM(a.num) FROM
  276. (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)
  277. UNION ALL
  278. SELECT COUNT(mg.id_) num FROM music_group mg WHERE mg.educational_teacher_id_ = #{employeeId} AND mg.status_ != 'CANCELED'
  279. UNION ALL
  280. SELECT COUNT(pg.id_) num FROM practice_group pg WHERE pg.educational_teacher_id_ = #{employeeId} AND pg.group_status_ != 'CANCEL')a
  281. </select>
  282. <select id="hasCourseSchedule" resultType="java.lang.Integer">
  283. SELECT COUNT(DISTINCT cs.id_)
  284. FROM course_schedule_teacher_salary csts
  285. LEFT JOIN course_schedule cs ON cs.id_ = csts.course_schedule_id_
  286. AND CONCAT(cs.class_date_,' ',cs.start_class_time_) > NOW() AND cs.del_flag_ = 0
  287. WHERE csts.user_id_ = #{employeeId}
  288. </select>
  289. <select id="queryRepairOrganList" resultType="java.lang.Integer">
  290. SELECT DISTINCT organ_id_ FROM music_group mg
  291. WHERE repair_user_id_ = #{userId}
  292. </select>
  293. <select id="queryEducationOrganList" resultType="java.lang.Integer">
  294. SELECT DISTINCT c.organ_id_ FROM (
  295. SELECT organ_id_ FROM music_group
  296. WHERE educational_teacher_id_ = #{userId}
  297. UNION
  298. SELECT organ_id_ FROM practice_group
  299. WHERE educational_teacher_id_ = #{userId}
  300. UNION
  301. SELECT organ_id_ FROM vip_group
  302. WHERE educational_teacher_id_ = #{userId}) c
  303. </select>
  304. <select id="queryTeamTeacherOrganList" resultType="java.lang.Integer">
  305. SELECT DISTINCT organ_id_ FROM music_group
  306. WHERE team_teacher_id_ = #{userId}
  307. </select>
  308. <select id="queryDirectorOrganList" resultType="java.lang.Integer">
  309. SELECT DISTINCT organ_id_ FROM music_group
  310. WHERE director_user_id_ = #{userId}
  311. </select>
  312. <update id="employeeLevel">
  313. <foreach collection="employeeLevelDtos" item="item">
  314. <if test="item.roleName == 'repair'">
  315. UPDATE music_group SET repair_user_id_ = #{item.transferUserId} WHERE repair_user_id_ = #{item.levelUserId} AND organ_id_ = #{item.organId};
  316. </if>
  317. <if test="item.roleName == 'education'">
  318. UPDATE music_group SET educational_teacher_id_ = #{item.transferUserId} WHERE educational_teacher_id_ = #{item.levelUserId} AND organ_id_ = #{item.organId};
  319. UPDATE practice_group SET educational_teacher_id_ = #{item.transferUserId} WHERE educational_teacher_id_ = #{item.levelUserId} AND organ_id_ = #{item.organId};
  320. UPDATE vip_group SET educational_teacher_id_ = #{item.transferUserId} WHERE educational_teacher_id_ = #{item.levelUserId} AND organ_id_ = #{item.organId};
  321. </if>
  322. <if test="item.roleName == 'teamTeacher'">
  323. UPDATE music_group SET team_teacher_id_ = #{item.transferUserId} WHERE team_teacher_id_ = #{item.levelUserId} AND organ_id_ = #{item.organId};
  324. </if>
  325. <if test="item.roleName == 'director'">
  326. UPDATE music_group SET director_user_id_ = #{item.transferUserId} WHERE director_user_id_ = #{item.levelUserId} AND organ_id_ = #{item.organId};
  327. </if>
  328. </foreach>
  329. </update>
  330. </mapper>