EmployeeMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. <result column="lock_flag_" property="lockFlag" />
  22. </resultMap>
  23. <resultMap type="com.yonge.cooleshow.auth.api.entity.SysUser" id="SysUser">
  24. <result column="id_" property="id"/>
  25. <result column="username_" property="username"/>
  26. <result column="password_" property="password"/>
  27. <result column="salt_" property="salt"/>
  28. <result column="phone_" property="phone"/>
  29. <result column="avatar_" property="avatar"/>
  30. <result column="create_time_" property="createTime"/>
  31. <result column="update_time_" property="updateTime"/>
  32. <result column="lock_flag_" property="lockFlag"/>
  33. <result column="del_flag_" property="delFlag"/>
  34. <result column="wx_openid_" property="wxOpenid"/>
  35. <result column="qq_openid_" property="qqOpenid"/>
  36. <result column="user_type_" property="userType"/>
  37. <result column="gender_" property="gender"/>
  38. <result column="nation_" property="nation"/>
  39. <result column="birthdate_" property="birthdate"/>
  40. <result column="email_" property="email"/>
  41. <result column="im_token_" property="imToken"/>
  42. <result column="real_name_" property="realName"/>
  43. <result column="id_card_no_" property="idCardNo"/>
  44. <result column="wechat_id_" property="wechatId"/>
  45. </resultMap>
  46. <sql id="baseColumns">
  47. t.user_id_ as "userId"
  48. , t.job_nature_ as "jobNature"
  49. , t.is_probation_period_ as "isProbationPeriod"
  50. , t.education_background_ as "educationBackground"
  51. , t.graduate_school_ as "graduateSchool"
  52. , t.technical_titles_ as "technicalTitles"
  53. , t.entry_date_ as "entryDate"
  54. , t.update_time_ as "updateTime"
  55. , t.create_time_ as "createTime"
  56. , t.introduction_ as "introduction"
  57. , t.demission_date_ as "demissionDate"
  58. , t.contact_address_ as "contactAddress"
  59. </sql>
  60. <select id="detail" resultType="com.yonge.cooleshow.biz.dal.vo.EmployeeVo">
  61. SELECT
  62. <include refid="baseColumns" />,
  63. if(u.lock_flag_ = 0 and t.lock_flag_ = 0,0,1) as lockFlag,
  64. username_ as username,
  65. phone_ as phone,
  66. gender_ as gender
  67. FROM employee t
  68. left join sys_user u on t.user_id_ = u.id_
  69. where u.del_flag_ = 0 and t.user_id_ = #{id}
  70. </select>
  71. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.EmployeeVo">
  72. SELECT
  73. <include refid="baseColumns" />,
  74. if(u.lock_flag_ = 0 and t.lock_flag_ = 0,0,1) as lockFlag,
  75. u.username_ as username,
  76. u.phone_ as phone,
  77. u.gender_ as gender
  78. FROM employee t
  79. left join sys_user u on t.user_id_ = u.id_
  80. <where>
  81. u.del_flag_ = 0
  82. <if test="null != param.search and '' != param.search">
  83. AND (
  84. t.user_id_ LIKE CONCAT('%', #{param.search}, '%') or
  85. u.username_ LIKE CONCAT('%', #{param.search}, '%') or
  86. u.phone_ LIKE CONCAT('%', #{param.search}, '%')
  87. )
  88. </if>
  89. <if test="null != param.gender">
  90. and u.gender_ = #{param.gender}
  91. </if>
  92. <if test="null != param.lockFlag">
  93. and (u.lock_flag_ = #{param.lockFlag} or t.lock_flag_ = #{param.lockFlag})
  94. </if>
  95. <if test="param.startTime !=null">
  96. <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
  97. </if>
  98. <if test="param.endTime !=null">
  99. <![CDATA[AND t.create_time_ < #{param.endTime} ]]>
  100. </if>
  101. </where>
  102. </select>
  103. <insert id="insertSysUser" parameterType="com.yonge.cooleshow.auth.api.entity.SysUser" useGeneratedKeys="true" keyColumn="id"
  104. keyProperty="id">
  105. INSERT INTO sys_user
  106. (is_super_admin_,im_token_,id_,username_,salt_,phone_,avatar_,create_time_,update_time_,wx_openid_,qq_openid_,user_type_,
  107. gender_,nation_,birthdate_,email_,id_card_no_,wechat_id_,real_name_,certificate_type_,password_)
  108. VALUES(#{isSuperAdmin},#{imToken},#{id},#{username},#{salt},#{phone},#{avatar},now(),now(),#{wxOpenid},#{qqOpenid},#{userType},
  109. #{gender},#{nation},#{birthdate},#{email},#{idCardNo},#{wechatId},#{realName},#{certificateType},#{password})
  110. </insert>
  111. <update id="updateSysUser" parameterType="com.yonge.cooleshow.auth.api.entity.SysUser">
  112. UPDATE sys_user
  113. <set>
  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 del_flag_ = 0 and 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. <if test="lockFlag != null">
  219. lock_flag_ = #{lockFlag},
  220. </if>
  221. </set>
  222. WHERE user_id_ = #{userId}
  223. </update>
  224. <select id="queryUserRole" resultType="java.lang.Long">
  225. SELECT sur.role_id_ FROM sys_user_role sur
  226. LEFT JOIN sys_role r ON sur.role_id_ = r.id_
  227. WHERE r.del_flag_ = 0 and r.is_enable_ = 1 and sur.user_id_ = #{userId}
  228. </select>
  229. <insert id="batchAddEmployeeRole">
  230. INSERT INTO sys_user_role(user_id_,role_id_) values
  231. <foreach collection="roleIds" item="item" index="index" separator=",">
  232. (#{userId},#{item})
  233. </foreach>
  234. </insert>
  235. <delete id="delEmployeeRole">
  236. DELETE FROM sys_user_role WHERE user_id_ = #{userId}
  237. </delete>
  238. <insert id="batchInsertRoleMenu">
  239. INSERT INTO sys_role_menu (role_id_,menu_id_) VALUES
  240. <foreach collection="menuIds" item="item" index="index" separator=",">
  241. (#{roleId}, #{item})
  242. </foreach>
  243. </insert>
  244. <select id="querySysUserByPhoneAndLock" resultMap="SysUser">
  245. select * from sys_user where del_flag_ = 0 and (phone_ = #{phone} OR username_ = #{phone}) LIMIT 1 FOR UPDATE
  246. </select>
  247. <select id="querySysUserByPhone" resultMap="SysUser">
  248. select * from sys_user where del_flag_ = 0 and (phone_ = #{phone} OR username_ = #{phone})
  249. </select>
  250. <select id="querySysUserById" resultMap="SysUser">
  251. select * from sys_user where del_flag_ = 0 and id_ = #{id}
  252. </select>
  253. <update id="updateUserDemissionDate">
  254. UPDATE employee SET demission_date_ = IF(demission_date_ IS NULL,now(),NULL) WHERE user_id_=#{userID}
  255. </update>
  256. <!-- 根据主键查询一条记录 -->
  257. <select id="get" resultMap="Employee">
  258. SELECT * FROM employee WHERE user_id_ = #{userId}
  259. </select>
  260. <!-- 全查询 -->
  261. <select id="findAll" resultMap="Employee">
  262. SELECT * FROM employee ORDER BY user_id_
  263. </select>
  264. <delete id="delRoleMenu">
  265. DELETE FROM `sys_role_menu`
  266. WHERE menu_id_ in
  267. <foreach collection="menuIds" open="(" close=")" item="item" separator=",">
  268. #{item}
  269. </foreach>
  270. </delete>
  271. <insert id="insertSysRole" keyColumn="id_" keyProperty="id" parameterType="com.yonge.cooleshow.auth.api.entity.SysRole"
  272. useGeneratedKeys="true">
  273. INSERT INTO `sys_role` (`role_name_`, `role_code_`, `role_desc_`, `create_time_`,
  274. `update_time_`, `del_flag_`, `organ_id_`, `tenant_id_`)
  275. VALUES (#{roleName}, #{roleCode}, #{roleDesc}, #{createTime},
  276. #{updateTime}, #{delFlag}, #{organId}, #{tenantId});
  277. </insert>
  278. <update id="updatePasswordReq">
  279. UPDATE sys_user SET password_ = #{password} WHERE del_flag_ = 0 and id_ = #{userID}
  280. </update>
  281. <!-- 根据主键删除一条记录 -->
  282. <delete id="delete">
  283. DELETE FROM employee WHERE user_id_ = #{userId}
  284. </delete>
  285. <!-- 查询当前表的总记录数 -->
  286. <select id="queryCount" resultType="int">
  287. SELECT COUNT(*) FROM employee where tenant_id_ = #{tenantId}
  288. </select>
  289. <select id="getUsers" resultMap="SysUser">
  290. select * from sys_user where del_flag_ = 0 and id_ IN
  291. <foreach collection="userIds" open="(" close=")" separator="," item="userId">
  292. #{userId}
  293. </foreach>
  294. </select>
  295. </mapper>