EmployeeMapper.xml 13 KB

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