SysPostMapper.xml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.slibra.system.mapper.SysPostMapper">
  6. <resultMap type="SysPost" id="SysPostResult">
  7. <id property="postId" column="post_id" />
  8. <result property="postCode" column="post_code" />
  9. <result property="postName" column="post_name" />
  10. <result property="postSort" column="post_sort" />
  11. <result property="status" column="status" />
  12. <result property="createBy" column="create_by" />
  13. <result property="createTime" column="create_time" />
  14. <result property="updateBy" column="update_by" />
  15. <result property="updateTime" column="update_time" />
  16. <result property="remark" column="remark" />
  17. </resultMap>
  18. <sql id="selectPostVo">
  19. select post_id, post_code, post_name, post_sort, status, create_by, create_time, remark
  20. from sys_post
  21. </sql>
  22. <select id="selectPostList" parameterType="SysPost" resultMap="SysPostResult">
  23. <include refid="selectPostVo"/>
  24. <where>
  25. <if test="postCode != null and postCode != ''">
  26. AND post_code like concat('%', #{postCode}, '%')
  27. </if>
  28. <if test="status != null and status != ''">
  29. AND status = #{status}
  30. </if>
  31. <if test="postName != null and postName != ''">
  32. AND post_name like concat('%', #{postName}, '%')
  33. </if>
  34. </where>
  35. </select>
  36. <select id="selectPostAll" resultMap="SysPostResult">
  37. <include refid="selectPostVo"/>
  38. </select>
  39. <select id="selectPostById" parameterType="Long" resultMap="SysPostResult">
  40. <include refid="selectPostVo"/>
  41. where post_id = #{postId}
  42. </select>
  43. <select id="selectPostListByUserId" parameterType="Long" resultType="Long">
  44. select p.post_id
  45. from sys_post p
  46. left join sys_user_post up on up.post_id = p.post_id
  47. left join sys_user u on u.user_id = up.user_id
  48. where u.user_id = #{userId}
  49. </select>
  50. <select id="selectPostsByUserName" parameterType="String" resultMap="SysPostResult">
  51. select p.post_id, p.post_name, p.post_code
  52. from sys_post p
  53. left join sys_user_post up on up.post_id = p.post_id
  54. left join sys_user u on u.user_id = up.user_id
  55. where u.user_name = #{userName}
  56. </select>
  57. <select id="checkPostNameUnique" parameterType="String" resultMap="SysPostResult">
  58. <include refid="selectPostVo"/>
  59. where post_name=#{postName} limit 1
  60. </select>
  61. <select id="checkPostCodeUnique" parameterType="String" resultMap="SysPostResult">
  62. <include refid="selectPostVo"/>
  63. where post_code=#{postCode} limit 1
  64. </select>
  65. <update id="updatePost" parameterType="SysPost">
  66. update sys_post
  67. <set>
  68. <if test="postCode != null and postCode != ''">post_code = #{postCode},</if>
  69. <if test="postName != null and postName != ''">post_name = #{postName},</if>
  70. <if test="postSort != null">post_sort = #{postSort},</if>
  71. <if test="status != null and status != ''">status = #{status},</if>
  72. <if test="remark != null">remark = #{remark},</if>
  73. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  74. update_time = sysdate()
  75. </set>
  76. where post_id = #{postId}
  77. </update>
  78. <insert id="insertPost" parameterType="SysPost" useGeneratedKeys="true" keyProperty="postId">
  79. insert into sys_post(
  80. <if test="postId != null and postId != 0">post_id,</if>
  81. <if test="postCode != null and postCode != ''">post_code,</if>
  82. <if test="postName != null and postName != ''">post_name,</if>
  83. <if test="postSort != null">post_sort,</if>
  84. <if test="status != null and status != ''">status,</if>
  85. <if test="remark != null and remark != ''">remark,</if>
  86. <if test="createBy != null and createBy != ''">create_by,</if>
  87. create_time
  88. )values(
  89. <if test="postId != null and postId != 0">#{postId},</if>
  90. <if test="postCode != null and postCode != ''">#{postCode},</if>
  91. <if test="postName != null and postName != ''">#{postName},</if>
  92. <if test="postSort != null">#{postSort},</if>
  93. <if test="status != null and status != ''">#{status},</if>
  94. <if test="remark != null and remark != ''">#{remark},</if>
  95. <if test="createBy != null and createBy != ''">#{createBy},</if>
  96. sysdate()
  97. )
  98. </insert>
  99. <delete id="deletePostById" parameterType="Long">
  100. delete from sys_post where post_id = #{postId}
  101. </delete>
  102. <delete id="deletePostByIds" parameterType="Long">
  103. delete from sys_post where post_id in
  104. <foreach collection="array" item="postId" open="(" separator="," close=")">
  105. #{postId}
  106. </foreach>
  107. </delete>
  108. <!-- 下面是新增的 -->
  109. <select id="getPostNamesByIds" resultType="string" parameterType="Long">
  110. SELECT
  111. GROUP_CONCAT( post_name SEPARATOR ', ' )
  112. FROM
  113. ( SELECT DISTINCT post_name FROM sys_post WHERE post_id IN
  114. <foreach collection="array" item="postId" open="(" separator="," close=")">
  115. #{postId}
  116. </foreach> ) temp
  117. </select>
  118. <select id="getPostNamesByUserId" resultType="string" parameterType="Long">
  119. SELECT
  120. GROUP_CONCAT( post_name SEPARATOR ', ' )
  121. FROM
  122. ( SELECT DISTINCT post_name FROM sys_post WHERE post_id IN (SELECT post_id FROM sys_user_post WHERE user_id = #{userId}) ) temp
  123. </select>
  124. </mapper>