UserMapper.xml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4. <mapper namespace="com.tld.mapper.UserMapper">
  5. <sql id="userField">
  6. id,code,user_name,password,real_name,email,landline,phone,department,role
  7. </sql>
  8. <!-- 登录 -->
  9. <select id="login" resultType="com.tld.model.User">
  10. select
  11. a.id,
  12. a.code,
  13. a.user_name,
  14. a.password,
  15. a.real_name,
  16. a.email,
  17. a.landline,
  18. a.phone,
  19. a.department,
  20. a.role,
  21. b.menu
  22. from tld_user a
  23. left join tld_role b on a.role = b.id
  24. where a.user_name = #{userName} and a.password = #{password}
  25. </select>
  26. <!-- 查询所有用户 -->
  27. <select id="getAllUser" resultType="com.tld.model.User">
  28. select
  29. a.id,
  30. a.code,
  31. a.user_name,
  32. a.password,
  33. a.real_name,
  34. a.email,
  35. a.landline,
  36. a.phone,
  37. a.create_time,
  38. c.name as department,
  39. b.role_name as role,
  40. a.role as roleId,
  41. a.department as departmentId,
  42. a.modify_time as modifyTime,
  43. f.user_name as modifyUser
  44. from tld_user a
  45. left join tld_user f on a.modify_user = f.id
  46. left join tld_role b on a.role = b.id
  47. left join tld_department c on a.department = c.code
  48. <trim prefix="WHERE" prefixOverrides="and |or">
  49. <if test="code != null and code != ''">
  50. and a.code like CONCAT(CONCAT('%', #{code}), '%')
  51. </if>
  52. <if test="userName != null and userName != ''">
  53. and a.user_name like CONCAT(CONCAT('%', #{userName}), '%')
  54. </if>
  55. <if test="realName != null and realName != ''">
  56. and a.real_name like CONCAT(CONCAT('%', #{realName}), '%')
  57. </if>
  58. <if test="modifyUser != null and modifyUser != ''">
  59. and f.user_name like CONCAT(CONCAT('%', #{modifyUser}), '%')
  60. </if>
  61. <if test="role != null and role != ''">
  62. and b.role_name like CONCAT(CONCAT('%', #{role}), '%')
  63. </if>
  64. <if test="email != null and email != ''">
  65. and a.email like CONCAT(CONCAT('%', #{email}), '%')
  66. </if>
  67. <if test="landline != null and landline != ''">
  68. and a.landline like CONCAT(CONCAT('%', #{landline}), '%')
  69. </if>
  70. <if test="phone != null and phone != ''">
  71. and a.phone like CONCAT(CONCAT('%', #{phone}), '%')
  72. </if>
  73. <if test="department != null and department != ''">
  74. and a.department = #{department}
  75. </if>
  76. <if test="id != null and id != ''">
  77. and a.id = #{id}
  78. </if>
  79. </trim>
  80. order by a.id desc
  81. </select>
  82. <!-- 新增用户 -->
  83. <insert id="addUser">
  84. <selectKey resultType="java.lang.String" order="AFTER" keyProperty="id">
  85. select LAST_INSERT_ID()
  86. </selectKey>
  87. insert into tld_user(user_name,password,real_name,email,landline,phone,department,role,create_time,modify_user,modify_time)
  88. values(#{userName},#{password},#{realName},#{email},#{landline},#{phone},#{department},#{role},NOW(),#{modifyUser},now())
  89. </insert>
  90. <!-- 修改指定用户信息 -->
  91. <update id="updateUser">
  92. update tld_user
  93. <set>
  94. <trim suffixOverrides=",">
  95. <if test="code != null">
  96. code = #{code},
  97. </if>
  98. <if test="userName != null">
  99. user_name = #{userName},
  100. </if>
  101. <if test="password != null">
  102. password = #{password},
  103. </if>
  104. <if test="realName != null">
  105. real_name = #{realName},
  106. </if>
  107. <if test="email != null">
  108. email = #{email},
  109. </if>
  110. <if test="landline != null">
  111. landline = #{landline},
  112. </if>
  113. <if test="phone != null">
  114. phone = #{phone},
  115. </if>
  116. <if test="department != null">
  117. department = #{department},
  118. </if>
  119. <if test="role != null">
  120. role = #{role},
  121. </if>
  122. modify_user = #{modifyUser},modify_time=now(),
  123. </trim>
  124. </set>
  125. where id = #{id}
  126. </update>
  127. <!-- 删除用户 -->
  128. <delete id="delUser">
  129. delete from tld_user where id = #{id}
  130. </delete>
  131. <!-- 查询用户名是否存在 -->
  132. <select id="getUserIsNot" resultType="int">
  133. select count(*) from tld_user where user_name = #{userName} and id != #{id}
  134. </select>
  135. <!-- 查询导出数据 -->
  136. <select id="getUserExportData" resultType="java.util.LinkedHashMap">
  137. select
  138. a.code,
  139. a.user_name,
  140. if(a.real_name = '', null , a.real_name) as real_name,
  141. if(a.email = '', null , a.email) as email,
  142. if(a.landline = '', null , a.landline) as landline,
  143. if(a.phone = '', null , a.phone) as phone,
  144. c.name as department,
  145. b.role_name as role
  146. from tld_user a
  147. left join tld_role b on a.role = b.id
  148. left join tld_department c on a.department = c.code
  149. left join tld_user f on a.modify_user = f.id
  150. <trim prefix="WHERE" prefixOverrides="and |or">
  151. <if test="code != null and code != ''">
  152. and a.code like CONCAT(CONCAT('%', #{code}), '%')
  153. </if>
  154. <if test="userName != null and userName != ''">
  155. and a.user_name like CONCAT(CONCAT('%', #{userName}), '%')
  156. </if>
  157. <if test="realName != null and realName != ''">
  158. and a.real_name like CONCAT(CONCAT('%', #{realName}), '%')
  159. </if>
  160. <if test="role != null and role != ''">
  161. and b.role_name like CONCAT(CONCAT('%', #{role}), '%')
  162. </if>
  163. <if test="email != null and email != ''">
  164. and a.email like CONCAT(CONCAT('%', #{email}), '%')
  165. </if>
  166. <if test="landline != null and landline != ''">
  167. and a.landline like CONCAT(CONCAT('%', #{landline}), '%')
  168. </if>
  169. <if test="phone != null and phone != ''">
  170. and a.phone like CONCAT(CONCAT('%', #{phone}), '%')
  171. </if>
  172. <if test="modifyUser != null and modifyUser != ''">
  173. and f.user_name like CONCAT(CONCAT('%', #{modifyUser}), '%')
  174. </if>
  175. <if test="department != null and department != ''">
  176. and a.department = #{department}
  177. </if>
  178. </trim>
  179. order by a.id desc
  180. </select>
  181. <!-- 查询指定用户内容 -->
  182. <select id="getUser" resultType="com.tld.model.User">
  183. select
  184. id,
  185. code,
  186. user_name,
  187. password,
  188. real_name,
  189. email,
  190. landline,
  191. phone,
  192. department,
  193. role
  194. from tld_user
  195. where id = #{id}
  196. </select>
  197. </mapper>