6276623cd82c8ac3e44f4c56ce4d698d293b106f.svn-base 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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="org.jeecg.modules.system.mapper.SysUserMapper">
  4. <!-- 根据用户名查询 -->
  5. <select id="getUserByName" resultType="org.jeecg.modules.system.entity.SysUser">
  6. select * from sys_user where username = #{username} and del_flag = 0
  7. </select>
  8. <!-- 根据部门Id查询 -->
  9. <select id="getUserByDepId" resultType="org.jeecg.modules.system.entity.SysUser">
  10. select * from sys_user where del_flag = 0 and id in (select user_id from sys_user_depart where dep_id=#{departId})
  11. <if test="username!=null and username!=''">
  12. and username = #{username}
  13. </if>
  14. </select>
  15. <!-- 查询用户的所属部门名称信息 -->
  16. <select id="getDepNamesByUserIds" resultType="org.jeecg.modules.system.vo.SysUserDepVo">
  17. select d.depart_name,ud.user_id from sys_user_depart ud,sys_depart d where d.id = ud.dep_id and ud.user_id in
  18. <foreach collection="userIds" index="index" item="id" open="(" separator="," close=")">
  19. #{id}
  20. </foreach>
  21. </select>
  22. <!-- 通过多个部门IDS,查询部门下的用户信息 -->
  23. <select id="getUserByDepIds" resultType="org.jeecg.modules.system.entity.SysUser">
  24. select * from sys_user where del_flag = 0
  25. <if test="departIds!=null and departIds.size()>0">
  26. and id in (select user_id from sys_user_depart where dep_id in
  27. <foreach collection="departIds" index="index" item="id" open="(" separator="," close=")">
  28. #{id}
  29. </foreach>
  30. )
  31. </if>
  32. <if test="username!=null and username!=''">
  33. and username = #{username}
  34. </if>
  35. </select>
  36. <!-- 根据角色Id查询 -->
  37. <select id="getUserByRoleId" resultType="org.jeecg.modules.system.entity.SysUser">
  38. select * from sys_user where del_flag = 0 and id in (select user_id from sys_user_role where role_id=#{roleId})
  39. <if test="username!=null and username!=''">
  40. and username = #{username}
  41. </if>
  42. </select>
  43. <!-- 修改用户部门code -->
  44. <update id="updateUserDepart">
  45. UPDATE sys_user SET org_code = #{orgCode} where username = #{username}
  46. </update>
  47. <!-- 根据手机号查询 -->
  48. <select id="getUserByPhone" resultType="org.jeecg.modules.system.entity.SysUser">
  49. select * from sys_user where phone = #{phone} and del_flag = 0
  50. </select>
  51. <!-- 根据邮箱查询用户信息 -->
  52. <select id="getUserByEmail" resultType="org.jeecg.modules.system.entity.SysUser">
  53. select * from sys_user where email = #{email} and del_flag = 0
  54. </select>
  55. <!-- SQL片段:getUserByOrgCode 的 FROM 和 WHERE 部分 -->
  56. <sql id="getUserByOrgCodeFromSql">
  57. FROM
  58. sys_depart
  59. INNER JOIN sys_user_depart ON sys_user_depart.dep_id = sys_depart.id
  60. INNER JOIN sys_user ON sys_user.id = sys_user_depart.user_id
  61. WHERE
  62. sys_user.del_flag = 0 AND sys_depart.org_code LIKE '${orgCode}%'
  63. <if test="userParams != null">
  64. <if test="userParams.realname != null and userParams.realname != ''">
  65. AND sys_user.realname LIKE concat(concat('%',#{userParams.realname}),'%')
  66. </if>
  67. <if test="userParams.workNo != null and userParams.workNo != ''">
  68. AND sys_user.work_no LIKE concat(concat('%',#{userParams.workNo}),'%')
  69. </if>
  70. </if>
  71. </sql>
  72. <!-- 根据 orgCode 查询用户,包括子部门下的用户 -->
  73. <select id="getUserByOrgCode" resultType="org.jeecg.modules.system.model.SysUserSysDepartModel">
  74. SELECT
  75. sys_user.id AS id,
  76. sys_user.realname AS realname,
  77. sys_user.avatar AS avatar,
  78. sys_user.work_no AS workNo,
  79. sys_user.post AS post,
  80. sys_user.telephone AS telephone,
  81. sys_user.email AS email,
  82. sys_user.phone AS phone,
  83. sys_depart.id AS departId,
  84. sys_depart.depart_name AS departName
  85. <include refid="getUserByOrgCodeFromSql"/>
  86. ORDER BY
  87. sys_depart.org_code ASC
  88. </select>
  89. <!-- 查询 getUserByOrgCode 的总数-->
  90. <select id="getUserByOrgCodeTotal" resultType="java.lang.Integer">
  91. SELECT COUNT(1) <include refid="getUserByOrgCodeFromSql"/>
  92. </select>
  93. <!-- 批量删除角色的与用户关系-->
  94. <update id="deleteBathRoleUserRelation">
  95. delete from sys_user_role
  96. where role_id in
  97. <foreach item="id" collection="roleIdArray" open="(" separator="," close=")">
  98. #{id}
  99. </foreach>
  100. </update>
  101. <!-- 批量删除角色的与权限关系-->
  102. <update id="deleteBathRolePermissionRelation">
  103. delete from sys_role_permission
  104. where role_id in
  105. <foreach item="id" collection="roleIdArray" open="(" separator="," close=")">
  106. #{id}
  107. </foreach>
  108. </update>
  109. <!-- 查询被逻辑删除的用户 -->
  110. <select id="selectLogicDeleted" resultType="org.jeecg.modules.system.entity.SysUser">
  111. SELECT * FROM sys_user ${ew.customSqlSegment}
  112. </select>
  113. <!-- 更新被逻辑删除的用户 -->
  114. <update id="revertLogicDeleted">
  115. UPDATE
  116. sys_user
  117. SET
  118. del_flag = 0,
  119. update_by = #{entity.updateBy},
  120. update_time = #{entity.updateTime}
  121. WHERE
  122. del_flag = 1
  123. AND id IN (${userIds})
  124. </update>
  125. <!-- 彻底删除被逻辑删除的用户 -->
  126. <delete id="deleteLogicDeleted">
  127. DELETE FROM sys_user WHERE del_flag = 1 AND id IN (${userIds})
  128. </delete>
  129. <!-- 更新空字符串为null -->
  130. <update id="updateNullByEmptyString">
  131. UPDATE sys_user SET ${fieldName} = NULL WHERE ${fieldName} = ''
  132. </update>
  133. <!-- 通过多个部门IDS,查询部门下的用户信息 -->
  134. <select id="queryByDepIds" resultType="org.jeecg.modules.system.entity.SysUser">
  135. select * from sys_user where del_flag = 0
  136. <if test="departIds!=null and departIds.size()>0">
  137. and id in (select user_id from sys_user_depart where dep_id in
  138. <foreach collection="departIds" index="index" item="id" open="(" separator="," close=")">
  139. #{id}
  140. </foreach>
  141. )
  142. </if>
  143. <if test="username!=null and username!=''">
  144. and username != #{username}
  145. </if>
  146. </select>
  147. </mapper>