EmployeeMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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.yonge.cooleshow.biz.dal.dao.EmployeeDao">
  8. <resultMap type="com.yonge.cooleshow.biz.dal.entity.Employee" id="Employee">
  9. <result column="user_id_" property="userId"/>
  10. <result column="job_nature_" property="jobNature"/>
  11. <result column="is_probation_period_" property="isProbationPeriod"/>
  12. <result column="education_background_" property="educationBackground"/>
  13. <result column="graduate_school_" property="graduateSchool"/>
  14. <result column="technical_titles_" property="technicalTitles"/>
  15. <result column="entry_date_" property="entryDate"/>
  16. <result column="update_time_" property="updateTime"/>
  17. <result column="create_time_" property="createTime"/>
  18. <result column="introduction_" property="introduction"/>
  19. <result column="demission_date_" property="demissionDate"/>
  20. <result column="contact_address_" property="contactAddress"/>
  21. </resultMap>
  22. <resultMap type="com.yonge.cooleshow.auth.api.entity.SysUser" id="SysUser">
  23. <result column="id_" property="id"/>
  24. <result column="username_" property="username"/>
  25. <result column="password_" property="password"/>
  26. <result column="salt_" property="salt"/>
  27. <result column="phone_" property="phone"/>
  28. <result column="avatar_" property="avatar"/>
  29. <result column="create_time_" property="createTime"/>
  30. <result column="update_time_" property="updateTime"/>
  31. <result column="lock_flag_" property="lockFlag"/>
  32. <result column="del_flag_" property="delFlag" typeHandler="com.yonge.cooleshow.common.dal.CustomEnumTypeHandler"/>
  33. <result column="wx_openid_" property="wxOpenid"/>
  34. <result column="qq_openid_" property="qqOpenid"/>
  35. <result column="user_type_" property="userType"/>
  36. <result column="gender_" property="gender"/>
  37. <result column="nation_" property="nation"/>
  38. <result column="birthdate_" property="birthdate"/>
  39. <result column="email_" property="email"/>
  40. <result column="im_token_" property="imToken"/>
  41. <result column="real_name_" property="realName"/>
  42. <result column="id_card_no_" property="idCardNo"/>
  43. <result column="wechat_id_" property="wechatId"/>
  44. </resultMap>
  45. <sql id="baseColumns">
  46. t.user_id_ as "userId"
  47. , t.job_nature_ as "jobNature"
  48. , t.is_probation_period_ as "isProbationPeriod"
  49. , t.education_background_ as "educationBackground"
  50. , t.graduate_school_ as "graduateSchool"
  51. , t.technical_titles_ as "technicalTitles"
  52. , t.entry_date_ as "entryDate"
  53. , t.update_time_ as "updateTime"
  54. , t.create_time_ as "createTime"
  55. , t.introduction_ as "introduction"
  56. , t.demission_date_ as "demissionDate"
  57. , t.contact_address_ as "contactAddress"
  58. </sql>
  59. <select id="detail" resultType="com.yonge.cooleshow.biz.dal.entity.Employee">
  60. SELECT
  61. <include refid="baseColumns" />,
  62. username_ as username,
  63. phone_ as phone,
  64. gender_ as gender
  65. FROM employee t
  66. left join sys_user u on t.user_id_ = u.id_
  67. where t.user_id_ = #{userId}
  68. </select>
  69. <select id="queryPage" resultType="com.yonge.cooleshow.biz.dal.entity.Employee">
  70. SELECT
  71. <include refid="baseColumns" />,
  72. username_ as username,
  73. phone_ as phone,
  74. gender_ as gender,
  75. lock_flag_ as lockFlag
  76. FROM employee
  77. left join sys_user u on t.user_id_ = u.id
  78. <where>
  79. <if test="null != param.search and '' != param.search">
  80. AND (
  81. t.user_id_ LIKE CONCAT('%', #{param.search}, '%') or
  82. u.username_ LIKE CONCAT('%', #{param.search}, '%') or
  83. u.phone_ LIKE CONCAT('%', #{param.search}, '%')
  84. )
  85. </if>
  86. <if test="null != param.gender">
  87. and u.gender_ = #{param.gender}
  88. </if>
  89. <if test="null != param.lockFlag">
  90. and u.lock_flag_ = #{param.lockFlag}
  91. </if>
  92. <if test="param.startTime !=null">
  93. <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
  94. </if>
  95. <if test="param.endTime !=null">
  96. <![CDATA[AND t.create_time_ <= #{param.endTime} ]]>
  97. </if>
  98. </where>
  99. ORDER BY user_id_
  100. <include refid="global.limit"/>
  101. </select>
  102. <insert id="insertSysUser" parameterType="com.yonge.cooleshow.auth.api.entity.SysUser" useGeneratedKeys="true" keyColumn="id"
  103. keyProperty="id">
  104. INSERT INTO sys_user
  105. (is_super_admin_,im_token_,id_,username_,salt_,phone_,avatar_,create_time_,update_time_,wx_openid_,qq_openid_,user_type_,
  106. gender_,nation_,birthdate_,email_,id_card_no_,wechat_id_,real_name_,certificate_type_)
  107. VALUES(#{isSuperAdmin},#{imToken},#{id},#{username},#{salt},#{phone},#{avatar},now(),now(),#{wxOpenid},#{qqOpenid},#{userType},
  108. #{gender},#{nation},#{birthdate},#{email},#{idCardNo},#{wechatId},#{realName},#{certificateType})
  109. </insert>
  110. <update id="updateSysUser" parameterType="com.yonge.cooleshow.auth.api.entity.SysUser">
  111. UPDATE sys_user
  112. <set>
  113. <if test="delFlag != null">
  114. del_flag_ = #{delFlag, typeHandler=com.yonge.cooleshow.common.dal.CustomEnumTypeHandler},
  115. </if>
  116. <if test="wxOpenid != null and wxOpenid != ''">
  117. wx_openid_ = #{wxOpenid},
  118. </if>
  119. <if test="avatar != null and avatar != ''">
  120. avatar_ = #{avatar},
  121. </if>
  122. <if test="email != null and email != ''">
  123. email_ = #{email},
  124. </if>
  125. <if test="gender != null">
  126. gender_ = #{gender},
  127. </if>
  128. <if test="salt != null and salt != ''">
  129. salt_ = #{salt},
  130. </if>
  131. <if test="username != null and username != ''">
  132. username_ = #{username},
  133. </if>
  134. <if test="userType != null and userType != ''">
  135. user_type_ = #{userType},
  136. </if>
  137. <if test="updateTime != null">
  138. update_time_ = NOW(),
  139. </if>
  140. <if test="lockFlag != null">
  141. lock_flag_ = #{lockFlag},
  142. </if>
  143. <if test="birthdate != null">
  144. birthdate_ = #{birthdate},
  145. </if>
  146. <if test="phone != null and phone != ''">
  147. phone_ = #{phone},
  148. </if>
  149. <if test="qqOpenid != null and qqOpenid != ''">
  150. qq_openid_ = #{qqOpenid},
  151. </if>
  152. <if test="nation != null and nation != ''">
  153. nation_ = #{nation},
  154. </if>
  155. <if test="imToken != null and imToken != ''">
  156. im_token_ = #{imToken},
  157. </if>
  158. <if test="idCardNo != null and idCardNo != ''">
  159. id_card_no_ = #{idCardNo},
  160. </if>
  161. <if test="password != null and password != ''">
  162. password_ = #{password},
  163. </if>
  164. <if test="wechatId != null and wechatId != ''">
  165. wechat_id_ = #{wechatId},
  166. </if>
  167. <if test="realName != null and realName != ''">
  168. real_name_ = #{realName},
  169. </if>
  170. <if test="isSuperAdmin != null">
  171. is_super_admin_ = #{isSuperAdmin},
  172. </if>
  173. <if test="certificateType != null">
  174. certificate_type_ = #{certificateType},
  175. </if>
  176. </set>
  177. WHERE id_ = #{id}
  178. </update>
  179. <insert id="insert" parameterType="com.yonge.cooleshow.biz.dal.entity.Employee" useGeneratedKeys="true" keyColumn="id"
  180. keyProperty="id">
  181. INSERT INTO employee
  182. (user_id_,job_nature_,is_probation_period_,education_background_,graduate_school_,technical_titles_,
  183. entry_date_,update_time_,create_time_,introduction_,demission_date_,contact_address_)
  184. VALUES(#{userId},#{jobNature},#{isProbationPeriod},#{educationBackground},#{graduateSchool},
  185. #{technicalTitles},#{entryDate},now(),now(),#{introduction},#{demissionDate},#{contactAddress})
  186. </insert>
  187. <update id="update" parameterType="com.yonge.cooleshow.biz.dal.entity.Employee">
  188. UPDATE employee
  189. <set>
  190. <if test="jobNature != null">
  191. job_nature_ = #{jobNature},
  192. </if>
  193. <if test="isProbationPeriod != null">
  194. is_probation_period_ = #{isProbationPeriod},
  195. </if>
  196. <if test="educationBackground != null">
  197. education_background_ = #{educationBackground},
  198. </if>
  199. <if test="graduateSchool != null">
  200. graduate_school_ = #{graduateSchool},
  201. </if>
  202. <if test="technicalTitles != null">
  203. technical_titles_ = #{technicalTitles},
  204. </if>
  205. <if test="entryDate != null">
  206. entry_date_ = #{entryDate},
  207. </if>
  208. <if test="updateTime != null">
  209. update_time_ = NOW(),
  210. </if>
  211. <if test="introduction != null">
  212. introduction_ = #{introduction},
  213. </if>
  214. <if test="demissionDate != null">
  215. demission_date_ = #{demissionDate},
  216. </if>
  217. <if test="contactAddress != null">
  218. contact_address_ = #{contactAddress},
  219. </if>
  220. </set>
  221. WHERE user_id_ = #{userId}
  222. </update>
  223. <insert id="batchAddEmployeeRole">
  224. INSERT INTO sys_user_role(user_id_,role_id_) values
  225. <foreach collection="roleIds" item="item" index="index" separator=",">
  226. (#{userId},#{item})
  227. </foreach>
  228. </insert>
  229. <insert id="batchInsertRoleMenu">
  230. INSERT INTO sys_role_menu (role_id_,menu_id_) VALUES
  231. <foreach collection="menuIds" item="item" index="index" separator=",">
  232. (#{roleId}, #{item})
  233. </foreach>
  234. </insert>
  235. <select id="querySysUserByPhoneAndLock" resultMap="SysUser">
  236. select * from sys_user where phone_ = #{phone} OR username_ = #{phone} LIMIT 1 FOR UPDATE
  237. </select>
  238. <select id="querySysUserByPhone" resultMap="SysUser">
  239. select * from sys_user where phone_ = #{phone} OR username_ = #{phone}
  240. </select>
  241. <select id="querySysUserById" resultMap="SysUser">
  242. select * from sys_user where id_ = #{id}
  243. </select>
  244. <select id="queryUserRole" resultType="java.lang.Long">
  245. SELECT sur.role_id_ FROM sys_user_role sur WHERE sur.user_id_ = #{userId}
  246. </select>
  247. <!-- 根据主键查询一条记录 -->
  248. <select id="get" resultMap="Employee">
  249. SELECT * FROM employee WHERE user_id_ = #{userId}
  250. </select>
  251. <!-- 全查询 -->
  252. <select id="findAll" resultMap="Employee">
  253. SELECT * FROM employee ORDER BY user_id_
  254. </select>
  255. <delete id="delRoleMenu">
  256. DELETE FROM `sys_role_menu`
  257. WHERE menu_id_ in
  258. <foreach collection="menuIds" open="(" close=")" item="item" separator=",">
  259. #{item}
  260. </foreach>
  261. </delete>
  262. <insert id="insertSysRole" keyColumn="id_" keyProperty="id" parameterType="com.yonge.cooleshow.auth.api.entity.SysRole"
  263. useGeneratedKeys="true">
  264. INSERT INTO `sys_role` (`role_name_`, `role_code_`, `role_desc_`, `create_time_`,
  265. `update_time_`, `del_flag_`, `organ_id_`, `tenant_id_`)
  266. VALUES (#{roleName}, #{roleCode}, #{roleDesc}, #{createTime},
  267. #{updateTime}, #{delFlag}, #{organId}, #{tenantId});
  268. </insert>
  269. <update id="updatePasswordReq">
  270. UPDATE sys_user SET password_ = #{password} WHERE id_ = #{userID}
  271. </update>
  272. <update id="updateUserDemissionDate">
  273. UPDATE employee SET demission_date_ = IF(demission_date_ IS NULL,now(),NULL) WHERE user_id_=#{userID}
  274. </update>
  275. <!-- 根据主键删除一条记录 -->
  276. <delete id="delete">
  277. DELETE FROM employee WHERE user_id_ = #{userId}
  278. </delete>
  279. <delete id="delEmployeeRole">
  280. DELETE FROM sys_user_role WHERE user_id_ = #{userId}
  281. </delete>
  282. <!-- 查询当前表的总记录数 -->
  283. <select id="queryCount" resultType="int">
  284. SELECT COUNT(*) FROM employee where tenant_id_ = #{tenantId}
  285. </select>
  286. <select id="getUsers" resultMap="SysUser">
  287. select * from sys_user where id_ IN
  288. <foreach collection="userIds" open="(" close=")" separator="," item="userId">
  289. #{userId}
  290. </foreach>
  291. </select>
  292. </mapper>