SysUserDao.xml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. <mapper namespace="com.kmall.common.dao.SysUserDao">
  4. <select id="queryObject" resultType="com.kmall.common.entity.SysUserEntity">
  5. SELECT
  6. u.*, ( SELECT d.NAME FROM sys_dept d WHERE d.dept_id = u.dept_id ) deptName, ur.role_id
  7. FROM
  8. sys_user u
  9. LEFT JOIN sys_user_role ur ON u.user_id = ur.user_id
  10. where u.user_id = #{value}
  11. </select>
  12. <select id="queryList" resultType="com.kmall.common.entity.SysUserEntity">
  13. SELECT
  14. u.*,
  15. ( SELECT d.NAME FROM sys_dept d WHERE d.dept_id = u.dept_id ) deptName,
  16. ur.role_id
  17. FROM
  18. sys_user u
  19. LEFT JOIN sys_user_role ur ON u.user_id = ur.user_id
  20. <where>
  21. <if test="createUserId != null">
  22. and `create_user_id` = #{createUserId}
  23. </if>
  24. <if test="username != null and username.trim() != ''">
  25. and u.`username` like concat('%',#{username},'%')
  26. </if>
  27. </where>
  28. <choose>
  29. <when test="sidx != null and sidx.trim() != ''">
  30. order by u.${sidx} ${order}
  31. </when>
  32. <otherwise>
  33. order by u.user_id desc
  34. </otherwise>
  35. </choose>
  36. <if test="offset != null and limit != null">
  37. limit #{offset}, #{limit}
  38. </if>
  39. </select>
  40. <select id="queryTotal" resultType="int">
  41. select count(*) from sys_user
  42. <where>
  43. <if test="createUserId != null">
  44. and `create_user_id` = #{createUserId}
  45. </if>
  46. <if test="username != null and username.trim() != ''">
  47. and `username` like concat('%',#{username},'%')
  48. </if>
  49. <if test="status != null and status.trim() != ''">
  50. and `status` = #{status}
  51. </if>
  52. </where>
  53. </select>
  54. <!-- 查询用户的所有权限 -->
  55. <select id="queryAllPerms" resultType="string">
  56. select m.perms from sys_user_role ur
  57. LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id
  58. LEFT JOIN sys_menu m on rm.menu_id = m.menu_id
  59. where ur.user_id = #{userId}
  60. </select>
  61. <!-- 查询用户的所有菜单ID -->
  62. <select id="queryAllMenuId" resultType="long">
  63. select distinct rm.menu_id from sys_user_role ur
  64. LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id
  65. where ur.user_id = #{userId}
  66. </select>
  67. <select id="queryByUserName" resultType="com.kmall.common.entity.SysUserEntity">
  68. select * from sys_user where username = #{username}
  69. </select>
  70. <insert id="save" parameterType="com.kmall.common.entity.SysUserEntity" useGeneratedKeys="true" keyProperty="userId">
  71. insert into sys_user
  72. (
  73. `user_id`,
  74. `username`,
  75. `password`,
  76. `email`,
  77. `mobile`,
  78. `status`,
  79. `create_user_id`,
  80. `dept_id`,
  81. `store_id`,
  82. `role_type`,
  83. `create_time`
  84. )
  85. values
  86. (
  87. #{userId},
  88. #{username},
  89. #{password},
  90. #{email},
  91. #{mobile},
  92. #{status},
  93. #{createUserId},
  94. #{deptId},
  95. #{storeId},
  96. #{roleType},
  97. #{createTime}
  98. )
  99. </insert>
  100. <update id="update" parameterType="com.kmall.common.entity.SysUserEntity">
  101. update sys_user
  102. <set>
  103. <if test="username != null">`username` = #{username}, </if>
  104. <if test="email != null">`email` = #{email}, </if>
  105. <if test="mobile != null">`mobile` = #{mobile}, </if>
  106. <if test="status != null">`status` = #{status}, </if>
  107. <if test="deptId != null">`dept_id` = #{deptId}, </if>
  108. <if test="storeId != null">`store_id` = #{storeId}, </if>
  109. <if test="roleType != null">`role_type` = #{roleType}, </if>
  110. </set>
  111. where user_id = #{userId}
  112. <if test="createUserId != null">
  113. and `create_user_id` = #{createUserId}
  114. </if>
  115. </update>
  116. <update id="updatePassword" parameterType="map">
  117. update sys_user set `password` = #{newPassword}
  118. where user_id = #{userId} and password = #{password}
  119. </update>
  120. <delete id="deleteBatch">
  121. delete from sys_user where user_id in
  122. <foreach item="userId" collection="array" open="(" separator="," close=")">
  123. #{userId}
  124. </foreach>
  125. ;
  126. delete from sys_user_role where user_id in
  127. <foreach item="userId" collection="array" open="(" separator="," close=")">
  128. #{userId}
  129. </foreach>
  130. </delete>
  131. </mapper>