UserMapper.xml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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
  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. </select>
  121. <select id="listPostName" parameterType="com.dayou.vo.UserVO" resultMap="userDepartmentPostMap">
  122. select u.id,u.staff_no,u.name ,u.sex FROM
  123. user_post up
  124. LEFT JOIN post p ON p.id = up.post_id
  125. left join user u on u.id = up.user_id
  126. WHERE
  127. p.NAME = #{postName}
  128. AND p.deleted = 0
  129. AND up.deleted = 0
  130. and u.deleted =0
  131. and
  132. not exists (
  133. select 1 from team_member where team_member.deleted = 0 and team_member.member_id = u.id
  134. )
  135. </select>
  136. <select id="usersByDepartment" parameterType="java.lang.String" resultType="com.dayou.vo.IdNameVO">
  137. SELECT DISTINCT
  138. u.id,
  139. u.name
  140. FROM
  141. user_post up
  142. INNER JOIN ( SELECT id FROM post WHERE department_id =( SELECT id FROM department WHERE NAME = '市场部' AND deleted = 0 ) AND deleted = 0 ) p ON up.post_id = p.id
  143. LEFT JOIN user u ON u.id = up.user_id
  144. WHERE
  145. up.deleted = 0
  146. AND u.deleted = 0
  147. </select>
  148. </mapper>