SysUserPostDao.xml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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.liang.dao.SysUserPostDao">
  4. <resultMap type="com.liang.entity.SysUserPost" id="SysUserPostMap">
  5. <result property="userId" column="user_id" jdbcType="INTEGER"/>
  6. <result property="postId" column="post_id" jdbcType="INTEGER"/>
  7. <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
  8. <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
  9. </resultMap>
  10. <!--查询单个-->
  11. <select id="queryById" resultMap="SysUserPostMap">
  12. select
  13. user_id, post_id, create_time, update_time
  14. from sys_user_post
  15. where user_id = #{userId}
  16. </select>
  17. <!--查询指定行数据-->
  18. <select id="queryAllByLimit" resultMap="SysUserPostMap">
  19. select
  20. user_id, post_id, create_time, update_time
  21. from sys_user_post
  22. <where>
  23. <if test="userId != null">
  24. and user_id = #{userId}
  25. </if>
  26. <if test="postId != null">
  27. and post_id = #{postId}
  28. </if>
  29. <if test="createTime != null">
  30. and create_time = #{createTime}
  31. </if>
  32. <if test="updateTime != null">
  33. and update_time = #{updateTime}
  34. </if>
  35. </where>
  36. limit #{pageable.offset}, #{pageable.pageSize}
  37. </select>
  38. <!--统计总行数-->
  39. <select id="count" resultType="java.lang.Long">
  40. select count(1)
  41. from sys_user_post
  42. <where>
  43. <if test="userId != null">
  44. and user_id = #{userId}
  45. </if>
  46. <if test="postId != null">
  47. and post_id = #{postId}
  48. </if>
  49. <if test="createTime != null">
  50. and create_time = #{createTime}
  51. </if>
  52. <if test="updateTime != null">
  53. and update_time = #{updateTime}
  54. </if>
  55. </where>
  56. </select>
  57. <!--新增所有列-->
  58. <insert id="insert" keyProperty="userId" useGeneratedKeys="true">
  59. insert into sys_user_post(create_time, update_time)
  60. values (#{createTime}, #{updateTime})
  61. </insert>
  62. <insert id="insertBatch" keyProperty="userId" useGeneratedKeys="true">
  63. insert into sys_user_post(create_time, update_time)
  64. values
  65. <foreach collection="entities" item="entity" separator=",">
  66. (#{entity.createTime}, #{entity.updateTime})
  67. </foreach>
  68. </insert>
  69. <insert id="insertOrUpdateBatch" keyProperty="userId" useGeneratedKeys="true">
  70. insert into sys_user_post(create_time, update_time)
  71. values
  72. <foreach collection="entities" item="entity" separator=",">
  73. (#{entity.createTime}, #{entity.updateTime})
  74. </foreach>
  75. on duplicate key update
  76. create_time = values(create_time),
  77. update_time = values(update_time)
  78. </insert>
  79. <!--通过主键修改数据-->
  80. <update id="update">
  81. update sys_user_post
  82. <set>
  83. <if test="createTime != null">
  84. create_time = #{createTime},
  85. </if>
  86. <if test="updateTime != null">
  87. update_time = #{updateTime},
  88. </if>
  89. </set>
  90. where user_id = #{userId}
  91. </update>
  92. <!--通过主键删除-->
  93. <delete id="deleteById">
  94. delete from sys_user_post where user_id = #{userId}
  95. update sys_user_post
  96. set del_flag = 1,
  97. update_user = #{updateUser},
  98. update_time = GETDATE()
  99. where user_id = #{userId}
  100. </delete>
  101. <!--获取全部岗位信息XmSelect列表-->
  102. <select id="listAllPost" resultType="com.liang.vo.PostXmSelect" parameterType="string">
  103. SELECT
  104. a.post_id AS value,
  105. a.post_name AS name,
  106. 0 AS selected
  107. FROM sys_post_info a
  108. WHERE a.status = '0'
  109. </select>
  110. <!--获取用户岗位信息XmSelect列表-->
  111. <select id="listPostByUserId" resultType="com.liang.vo.PostXmSelect" parameterType="java.lang.Integer">
  112. SELECT
  113. a.post_id AS value,
  114. a.post_name AS name,
  115. ( CASE WHEN b.user_id IS NULL THEN 0 ELSE 1 END ) AS selected
  116. FROM
  117. sys_post_info a
  118. LEFT JOIN sys_user_post b ON ( a.post_id = b.post_id AND b.user_id = #{userId} )
  119. WHERE a.status = '0'
  120. </select>
  121. <!--删除用户岗位-->
  122. <delete id="deleteUserPostByUserId" parameterType="java.lang.Integer">
  123. delete from sys_user_post where user_id = #{userId}
  124. </delete>
  125. <!--批量保存用户岗位-->
  126. <insert id="batchSaveUserPost" parameterType="java.util.List">
  127. insert into sys_user_post(user_id, post_id, create_time)
  128. <foreach collection="list" item="item" index="index" separator="UNION ALL">
  129. select
  130. #{item.userId, jdbcType=INTEGER},
  131. #{item.postId, jdbcType=INTEGER},
  132. GETDATE()
  133. </foreach>
  134. </insert>
  135. <!--岗位用户列表-->
  136. <select id="getPostUserList" resultMap="SysUserPostMap">
  137. select p.post_id, u.user_id, u.account, u.name, u.status
  138. from sys_user_post p
  139. left join sys_user_info u on u.user_id = p.user_id
  140. where u.status = '0' and u.del_flag = '0'
  141. <if test="postId!= null and postId!= ''">
  142. and p.post_id = #{postId}
  143. </if>
  144. <if test="userName!= null and userName!= ''">
  145. and u.name like '%'+#{userName}+'%'
  146. </if>
  147. </select>
  148. <!--用户岗位列表-->
  149. <select id="getUserPostList" resultMap="SysUserPostMap">
  150. select u.user_id, p.post_id, p.post_name
  151. from sys_user_post u
  152. left join sys_post_info p on p.post_id = u.post_id
  153. where p.status = '0'
  154. <if test="userId!= null and userId!= ''">
  155. and u.user_id = #{userId}
  156. </if>
  157. <if test="postName!= null and postName!= ''">
  158. and p.post_name like '%'+#{postName}+'%'
  159. </if>
  160. </select>
  161. </mapper>