SysUserDao.xml 3.8 KB

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