UserMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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.dayou.mapper.UserMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="userDepartmentPostMap" type="com.dayou.vo.UserVO">
  6. <result column="id" property="id" />
  7. <result column="deleted" property="deleted" />
  8. <result column="created" property="created" />
  9. <result column="modified" property="modified" />
  10. <result column="name" property="name" />
  11. <result column="id_no" property="idNo" />
  12. <result column="user_type" property="userType" />
  13. <result column="mobile" property="mobile" />
  14. <result column="sex" property="sex" />
  15. <result column="password" property="password" />
  16. <result column="salt" property="salt" />
  17. <result column="birthday" property="birthday" />
  18. <result column="enable" property="enable" />
  19. <result column="staff_no" property="staffNo"/>
  20. <result column="nation" property="nation"/>
  21. <result column="politics" property="politics"/>
  22. <result column="home_address" property="homeAddress"/>
  23. <result column="resign_state" property="resignState"/>
  24. <result column="hire_date" property="hireDate"/>
  25. <result column="resign_date" property="resignDate"/>
  26. <result column="remark" property="remark"/>
  27. <result column="native_place" property="nativePlace"/>
  28. <collection property="departmentPostVOList" ofType="com.dayou.vo.DepartmentPostVO" select="selectDepartmentPostVO" column="id"/>
  29. <collection property="userPosts" ofType="com.dayou.vo.IdNameVO" select="selectUserPosts" column="id"/>
  30. </resultMap>
  31. <!-- 通用查询结果列 -->
  32. <sql id="Base_Column_List">
  33. id,
  34. deleted,
  35. created,
  36. modified,
  37. name, id_no, user_type, mobile, sex, password, salt, birthday, enable,staff_no,nation,politics,home_address,resign_state,hire_date,resign_date,remark,native_place,settle_password
  38. </sql>
  39. <insert id="saveOrUpdateById" parameterType="com.dayou.entity.User">
  40. insert into user(`id`,`name`, `staff_no`,`password`,`user_type`,`sex`) values
  41. (#{user.id},#{user.name},#{user.staffNo},#{user.password},#{user.userType},#{user.sex})
  42. on duplicate key update
  43. id=id
  44. </insert>
  45. <select id="xPage" parameterType="com.dayou.vo.UserVO" resultMap="userDepartmentPostMap">
  46. select <include refid="Base_Column_List" /> from user
  47. <where>
  48. deleted = 0
  49. <if test="userVO!=null and userVO.sex!=null and userVO.sex!='' ">
  50. and sex = #{userVO.sex}
  51. </if>
  52. <if test="userVO!=null and userVO.resignState!=null">
  53. and resign_state = #{userVO.resignState}
  54. </if>
  55. <if test="userVO!=null and userVO.staffNo!=null and userVO.staffNo!='' ">
  56. and staff_no like concat('%',#{userVO.staffNo},'%')
  57. </if>
  58. <if test="userVO!=null and userVO.name!=null and userVO.name!='' ">
  59. and NAME like concat('%',#{userVO.name},'%')
  60. </if>
  61. <if test="userVO!=null and userVO.keyword!=null and userVO.keyword!='' ">
  62. and NAME like concat('%',#{userVO.keyword},'%') or staff_no like concat('%',#{userVO.keyword},'%')
  63. </if>
  64. </where>
  65. </select>
  66. <select id="selectDepartmentPostVO" parameterType="java.lang.Long" resultType="com.dayou.vo.DepartmentPostVO">
  67. SELECT
  68. d.NAME AS departmentName,
  69. p.name as postName
  70. FROM
  71. user_post up
  72. left join
  73. post p
  74. on up.post_id = p.id
  75. LEFT JOIN department d ON p.department_id = d.id
  76. where up.user_id = #{id} and up.deleted = 0 and d.deleted=0 and p.deleted=0
  77. </select>
  78. <select id="detail" parameterType="java.lang.Long" resultMap="userDepartmentPostMap">
  79. select <include refid="Base_Column_List" /> from user where deleted = 0 and id=#{id}
  80. </select>
  81. <select id="selectUserPosts" parameterType="java.lang.Long" resultType="com.dayou.vo.IdNameVO">
  82. SELECT
  83. p.id,
  84. CONCAT( p.NAME, '-', d.NAME ) AS NAME
  85. FROM
  86. user_post up
  87. LEFT JOIN post p ON up.post_id = p.id
  88. LEFT JOIN department d ON p.department_id = d.id
  89. WHERE
  90. up.user_id = #{id}
  91. AND p.deleted = 0
  92. AND d.deleted =0
  93. AND up.deleted = 0
  94. </select>
  95. <select id="getDepartmentIdByUserId" parameterType="java.lang.Long" resultType="java.lang.Long">
  96. SELECT
  97. p.department_id
  98. FROM
  99. user_post up
  100. LEFT JOIN post p ON p.id = up.post_id
  101. left join user u on u.id = up.user_id
  102. WHERE
  103. u.id = #{userId}
  104. AND p.deleted = 0
  105. AND up.deleted = 0
  106. and u.deleted =0
  107. </select>
  108. <select id="simplePostName" parameterType="java.lang.String" resultType="com.dayou.entity.User">
  109. SELECT
  110. u.id,u.name,enable
  111. FROM
  112. user_post up
  113. LEFT JOIN post p ON p.id = up.post_id
  114. left join user u on u.id = up.user_id
  115. WHERE
  116. p.NAME = #{postName}
  117. AND p.deleted = 0
  118. AND up.deleted = 0
  119. and u.deleted =0
  120. and resign_state = 0
  121. and `enable` = 1
  122. order by u.id
  123. </select>
  124. <select id="listPostName" parameterType="com.dayou.vo.UserVO" resultMap="userDepartmentPostMap">
  125. select u.id,u.staff_no,u.name ,u.sex FROM
  126. user_post up
  127. LEFT JOIN post p ON p.id = up.post_id
  128. left join user u on u.id = up.user_id
  129. WHERE
  130. p.NAME = #{postName}
  131. AND p.deleted = 0
  132. AND up.deleted = 0
  133. and u.deleted =0
  134. and
  135. not exists (
  136. select 1 from team_member where team_member.deleted = 0 and team_member.member_id = u.id
  137. )
  138. </select>
  139. <select id="usersByDepartment" parameterType="java.lang.String" resultType="com.dayou.vo.IdNameVO">
  140. SELECT DISTINCT
  141. u.id,
  142. u.name
  143. FROM
  144. user_post up
  145. INNER JOIN ( SELECT id FROM post WHERE department_id =( SELECT id FROM department WHERE NAME = #{departmentName} AND deleted = 0 ) AND deleted = 0 ) p ON up.post_id = p.id
  146. LEFT JOIN user u ON u.id = up.user_id
  147. WHERE
  148. up.deleted = 0
  149. AND u.deleted = 0
  150. </select>
  151. <select id="usersByDepartments" parameterType="java.util.List" resultType="com.dayou.vo.IdNameVO">
  152. SELECT DISTINCT
  153. u.id,
  154. u.name
  155. FROM
  156. user_post up
  157. INNER JOIN ( SELECT id FROM post WHERE department_id in ( SELECT id FROM department WHERE NAME
  158. in (
  159. <foreach collection="list" index="index" item="item" separator=",">
  160. #{item}
  161. </foreach>
  162. )
  163. AND deleted = 0 ) AND deleted = 0 ) p ON up.post_id = p.id
  164. LEFT JOIN user u ON u.id = up.user_id
  165. WHERE
  166. up.deleted = 0
  167. AND u.deleted = 0
  168. </select>
  169. <select id="usersByDepartmentIds" parameterType="java.util.Set" resultType="com.dayou.vo.IdNameVO">
  170. SELECT DISTINCT
  171. u.id,
  172. u.name
  173. FROM
  174. user_post up
  175. INNER JOIN ( SELECT id FROM post WHERE department_id in (
  176. <foreach collection="list" index="index" item="item" separator=",">
  177. #{item}
  178. </foreach>
  179. )
  180. AND deleted = 0 ) p ON up.post_id = p.id
  181. LEFT JOIN user u ON u.id = up.user_id
  182. WHERE
  183. up.deleted = 0
  184. AND u.deleted = 0
  185. </select>
  186. <select id="byDepartmentId" parameterType="java.lang.Long" resultType="com.dayou.entity.User">
  187. SELECT DISTINCT
  188. u.id,
  189. u.NAME
  190. FROM
  191. user_post up
  192. LEFT JOIN user u ON u.id = up.user_id
  193. WHERE
  194. up.post_id IN ( SELECT id FROM post WHERE department_id = #{departmentId} AND deleted = 0 )
  195. AND up.deleted = 0
  196. AND u.deleted = 0
  197. AND u.resign_state = 0
  198. </select>
  199. <select id="allotDepartmentUsers" parameterType="java.util.Set" resultType="com.dayou.common.PullDownModel">
  200. SELECT DISTINCT
  201. u.id,
  202. u.NAME
  203. FROM
  204. user_post up
  205. LEFT JOIN user u ON u.id = up.user_id
  206. WHERE
  207. up.post_id IN ( SELECT id FROM post WHERE department_id in (
  208. <foreach collection="departmentIds" index="index" separator="," item="item">
  209. #{item}
  210. </foreach>
  211. )
  212. AND deleted = 0 )
  213. AND u.deleted = 0
  214. </select>
  215. <select id="infoPostName" parameterType="java.lang.String" resultType="com.dayou.entity.User">
  216. SELECT
  217. u.id,u.name,u.mobile
  218. FROM
  219. user_post up
  220. LEFT JOIN post p ON p.id = up.post_id
  221. left join user u on u.id = up.user_id
  222. WHERE
  223. p.NAME = #{postName}
  224. AND p.deleted = 0
  225. AND up.deleted = 0
  226. and u.deleted =0
  227. order by u.id
  228. </select>
  229. <!--获取资产评估师用户-->
  230. <select id="byAssetEvaluator" resultType="com.dayou.entity.User">
  231. SELECT user.id,
  232. user.name
  233. FROM user, user_archive
  234. WHERE user.id = user_archive.user_id
  235. AND user_archive.asset_evaluator_registration_no IS NOT NULL
  236. AND user.deleted = 0
  237. AND user_archive.deleted = 0
  238. </select>
  239. <!--根据部门名称获取部门及其下辖部门人员-->
  240. <select id="byDepartmentName" resultType="com.dayou.entity.User">
  241. SELECT DISTINCT user.id, user.name
  242. FROM (SELECT user.id,user.name,post.department_id FROM user, user_post, post WHERE user.id = user_post.user_id AND user_post.post_id = post.id AND user.deleted = 0 AND user_post.deleted = 0 AND post.deleted = 0) AS user
  243. INNER JOIN (SELECT id
  244. FROM (SELECT id,parent_id FROM department WHERE deleted = 0 ORDER BY parent_id, id ) org_query,
  245. (SELECT @id := (SELECT id FROM department WHERE name = #{depName} AND deleted = 0)) initialisation
  246. WHERE (FIND_IN_SET(parent_id, @id) > 0 OR FIND_IN_SET(id, @id) > 0)
  247. AND @id := CONCAT(@id, ',', id)) AS depId ON depId.id = user.department_id
  248. </select>
  249. </mapper>