1
0

SysUserDao.xml 4.1 KB

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