UserMapper.xml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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.department_name as department,
  39. b.role_name as role,
  40. a.role as roleId,
  41. a.department as departmentId
  42. from tld_user a
  43. left join tld_role b on a.role = b.id
  44. left join tld_department c on a.department = c.id
  45. <trim prefix="WHERE" prefixOverrides="and |or">
  46. <if test="code != null and code != ''">
  47. and a.code like CONCAT(CONCAT('%', #{code}), '%')
  48. </if>
  49. <if test="userName != null and userName != ''">
  50. and a.user_name like CONCAT(CONCAT('%', #{userName}), '%')
  51. </if>
  52. <if test="id != null and id != ''">
  53. and a.id = #{id}
  54. </if>
  55. </trim>
  56. </select>
  57. <!-- 新增用户 -->
  58. <insert id="addUser">
  59. <selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
  60. select LAST_INSERT_ID()
  61. </selectKey>
  62. insert into tld_user(user_name,password,real_name,email,landline,phone,department,role,create_time)
  63. values(#{userName},#{password},#{realName},#{email},#{landline},#{phone},#{department},#{role}, DATE_FORMAT(NOW(), '%Y-%m-%d'))
  64. </insert>
  65. <!-- 修改指定用户信息 -->
  66. <update id="updateUser">
  67. update tld_user
  68. <set>
  69. <trim suffixOverrides=",">
  70. <if test="code != null and code != ''">
  71. code = #{code},
  72. </if>
  73. <if test="userName != null and userName != ''">
  74. user_name = #{userName},
  75. </if>
  76. <if test="password != null and password != ''">
  77. password = #{password},
  78. </if>
  79. <if test="realName != null and realName != ''">
  80. real_name = #{realName},
  81. </if>
  82. <if test="email != null and email != ''">
  83. email = #{email},
  84. </if>
  85. <if test="landline != null and landline != ''">
  86. landline = #{landline},
  87. </if>
  88. <if test="phone != null and phone != ''">
  89. phone = #{phone},
  90. </if>
  91. <if test="department != null and department != ''">
  92. department = #{department},
  93. </if>
  94. <if test="role != null and role != ''">
  95. role = #{role},
  96. </if>
  97. </trim>
  98. </set>
  99. where id = #{id}
  100. </update>
  101. <!-- 删除用户 -->
  102. <delete id="delUser">
  103. delete from tld_user where id = #{id}
  104. </delete>
  105. <!-- 查询用户名是否存在 -->
  106. <select id="getUserIsNot" resultType="int">
  107. select count(*) from tld_user where user_name = #{userName} and id != #{id}
  108. </select>
  109. <!-- 查询导出数据 -->
  110. <select id="getUserExportData" resultType="java.util.LinkedHashMap">
  111. select
  112. a.code,
  113. a.user_name,
  114. a.real_name,
  115. a.email,
  116. a.landline,
  117. a.phone,
  118. c.department_name as department,
  119. b.role_name as role,
  120. a.create_time
  121. from tld_user a
  122. left join tld_role b on a.role = b.id
  123. left join tld_department c on a.department = c.id
  124. <trim prefix="WHERE" prefixOverrides="and |or">
  125. <if test="code != null and code != ''">
  126. and a.code like CONCAT(CONCAT('%', #{code}), '%')
  127. </if>
  128. <if test="userName != null and userName != ''">
  129. and a.user_name like CONCAT(CONCAT('%', #{userName}), '%')
  130. </if>
  131. </trim>
  132. </select>
  133. </mapper>