EmployeeMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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"/>
  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.vo.EmployeeVo">
  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_ = #{id}
  68. </select>
  69. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.EmployeeVo">
  70. SELECT
  71. <include refid="baseColumns" />,
  72. u.username_ as username,
  73. u.phone_ as phone,
  74. u.gender_ as gender,
  75. u.lock_flag_ as lockFlag
  76. FROM employee t
  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. </select>
  100. <insert id="insertSysUser" parameterType="com.yonge.cooleshow.auth.api.entity.SysUser" useGeneratedKeys="true" keyColumn="id"
  101. keyProperty="id">
  102. INSERT INTO sys_user
  103. (is_super_admin_,im_token_,id_,username_,salt_,phone_,avatar_,create_time_,update_time_,wx_openid_,qq_openid_,user_type_,
  104. gender_,nation_,birthdate_,email_,id_card_no_,wechat_id_,real_name_,certificate_type_,password_)
  105. VALUES(#{isSuperAdmin},#{imToken},#{id},#{username},#{salt},#{phone},#{avatar},now(),now(),#{wxOpenid},#{qqOpenid},#{userType},
  106. #{gender},#{nation},#{birthdate},#{email},#{idCardNo},#{wechatId},#{realName},#{certificateType},#{password})
  107. </insert>
  108. <update id="updateSysUser" parameterType="com.yonge.cooleshow.auth.api.entity.SysUser">
  109. UPDATE sys_user
  110. <set>
  111. <if test="delFlag != null">
  112. del_flag_ = #{delFlag},
  113. </if>
  114. <if test="wxOpenid != null and wxOpenid != ''">
  115. wx_openid_ = #{wxOpenid},
  116. </if>
  117. <if test="avatar != null and avatar != ''">
  118. avatar_ = #{avatar},
  119. </if>
  120. <if test="email != null and email != ''">
  121. email_ = #{email},
  122. </if>
  123. <if test="gender != null">
  124. gender_ = #{gender},
  125. </if>
  126. <if test="salt != null and salt != ''">
  127. salt_ = #{salt},
  128. </if>
  129. <if test="username != null and username != ''">
  130. username_ = #{username},
  131. </if>
  132. <if test="userType != null and userType != ''">
  133. user_type_ = #{userType},
  134. </if>
  135. <if test="updateTime != null">
  136. update_time_ = NOW(),
  137. </if>
  138. <if test="lockFlag != null">
  139. lock_flag_ = #{lockFlag},
  140. </if>
  141. <if test="birthdate != null">
  142. birthdate_ = #{birthdate},
  143. </if>
  144. <if test="phone != null and phone != ''">
  145. phone_ = #{phone},
  146. </if>
  147. <if test="qqOpenid != null and qqOpenid != ''">
  148. qq_openid_ = #{qqOpenid},
  149. </if>
  150. <if test="nation != null and nation != ''">
  151. nation_ = #{nation},
  152. </if>
  153. <if test="imToken != null and imToken != ''">
  154. im_token_ = #{imToken},
  155. </if>
  156. <if test="idCardNo != null and idCardNo != ''">
  157. id_card_no_ = #{idCardNo},
  158. </if>
  159. <if test="password != null and password != ''">
  160. password_ = #{password},
  161. </if>
  162. <if test="wechatId != null and wechatId != ''">
  163. wechat_id_ = #{wechatId},
  164. </if>
  165. <if test="realName != null and realName != ''">
  166. real_name_ = #{realName},
  167. </if>
  168. <if test="isSuperAdmin != null">
  169. is_super_admin_ = #{isSuperAdmin},
  170. </if>
  171. <if test="certificateType != null">
  172. certificate_type_ = #{certificateType},
  173. </if>
  174. </set>
  175. WHERE id_ = #{id}
  176. </update>
  177. <insert id="insert" parameterType="com.yonge.cooleshow.biz.dal.entity.Employee" useGeneratedKeys="true" keyColumn="id"
  178. keyProperty="id">
  179. INSERT INTO employee
  180. (user_id_,job_nature_,is_probation_period_,education_background_,graduate_school_,technical_titles_,
  181. entry_date_,update_time_,create_time_,introduction_,demission_date_,contact_address_)
  182. VALUES(#{userId},#{jobNature},#{isProbationPeriod},#{educationBackground},#{graduateSchool},
  183. #{technicalTitles},#{entryDate},now(),now(),#{introduction},#{demissionDate},#{contactAddress})
  184. </insert>
  185. <update id="update" parameterType="com.yonge.cooleshow.biz.dal.entity.Employee">
  186. UPDATE employee
  187. <set>
  188. <if test="jobNature != null">
  189. job_nature_ = #{jobNature},
  190. </if>
  191. <if test="isProbationPeriod != null">
  192. is_probation_period_ = #{isProbationPeriod},
  193. </if>
  194. <if test="educationBackground != null">
  195. education_background_ = #{educationBackground},
  196. </if>
  197. <if test="graduateSchool != null">
  198. graduate_school_ = #{graduateSchool},
  199. </if>
  200. <if test="technicalTitles != null">
  201. technical_titles_ = #{technicalTitles},
  202. </if>
  203. <if test="entryDate != null">
  204. entry_date_ = #{entryDate},
  205. </if>
  206. <if test="updateTime != null">
  207. update_time_ = NOW(),
  208. </if>
  209. <if test="introduction != null">
  210. introduction_ = #{introduction},
  211. </if>
  212. <if test="demissionDate != null">
  213. demission_date_ = #{demissionDate},
  214. </if>
  215. <if test="contactAddress != null">
  216. contact_address_ = #{contactAddress},
  217. </if>
  218. </set>
  219. WHERE user_id_ = #{userId}
  220. </update>
  221. <select id="queryUserRole" resultType="java.lang.Long">
  222. SELECT sur.role_id_ FROM sys_user_role sur
  223. LEFT JOIN sys_role r ON sur.role_id_ = r.id_
  224. WHERE r.del_flag_ = 0 and r.is_enable_ = 1 and sur.user_id_ = #{userId}
  225. </select>
  226. <insert id="batchAddEmployeeRole">
  227. INSERT INTO sys_user_role(user_id_,role_id_) values
  228. <foreach collection="roleIds" item="item" index="index" separator=",">
  229. (#{userId},#{item})
  230. </foreach>
  231. </insert>
  232. <delete id="delEmployeeRole">
  233. DELETE FROM sys_user_role WHERE user_id_ = #{userId}
  234. </delete>
  235. <insert id="batchInsertRoleMenu">
  236. INSERT INTO sys_role_menu (role_id_,menu_id_) VALUES
  237. <foreach collection="menuIds" item="item" index="index" separator=",">
  238. (#{roleId}, #{item})
  239. </foreach>
  240. </insert>
  241. <select id="querySysUserByPhoneAndLock" resultMap="SysUser">
  242. select * from sys_user where phone_ = #{phone} OR username_ = #{phone} LIMIT 1 FOR UPDATE
  243. </select>
  244. <select id="querySysUserByPhone" resultMap="SysUser">
  245. select * from sys_user where phone_ = #{phone} OR username_ = #{phone}
  246. </select>
  247. <select id="querySysUserById" resultMap="SysUser">
  248. select * from sys_user where id_ = #{id}
  249. </select>
  250. <update id="updateUserDemissionDate">
  251. UPDATE employee SET demission_date_ = IF(demission_date_ IS NULL,now(),NULL) WHERE user_id_=#{userID}
  252. </update>
  253. <!-- 根据主键查询一条记录 -->
  254. <select id="get" resultMap="Employee">
  255. SELECT * FROM employee WHERE user_id_ = #{userId}
  256. </select>
  257. <!-- 全查询 -->
  258. <select id="findAll" resultMap="Employee">
  259. SELECT * FROM employee ORDER BY user_id_
  260. </select>
  261. <delete id="delRoleMenu">
  262. DELETE FROM `sys_role_menu`
  263. WHERE menu_id_ in
  264. <foreach collection="menuIds" open="(" close=")" item="item" separator=",">
  265. #{item}
  266. </foreach>
  267. </delete>
  268. <insert id="insertSysRole" keyColumn="id_" keyProperty="id" parameterType="com.yonge.cooleshow.auth.api.entity.SysRole"
  269. useGeneratedKeys="true">
  270. INSERT INTO `sys_role` (`role_name_`, `role_code_`, `role_desc_`, `create_time_`,
  271. `update_time_`, `del_flag_`, `organ_id_`, `tenant_id_`)
  272. VALUES (#{roleName}, #{roleCode}, #{roleDesc}, #{createTime},
  273. #{updateTime}, #{delFlag}, #{organId}, #{tenantId});
  274. </insert>
  275. <update id="updatePasswordReq">
  276. UPDATE sys_user SET password_ = #{password} WHERE id_ = #{userID}
  277. </update>
  278. <!-- 根据主键删除一条记录 -->
  279. <delete id="delete">
  280. DELETE FROM employee 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>