PostMapper.xml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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.juxiao.xchat.module.system.mapper.PostMapper">
  6. <resultMap type="com.juxiao.xchat.module.system.domain.Post" id="PostResult">
  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="com.juxiao.xchat.module.system.domain.Post" resultMap="PostResult">
  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="PostResult">
  37. <include refid="selectPostVo"/>
  38. </select>
  39. <select id="selectPostsByUserId" parameterType="java.lang.Long" resultMap="PostResult">
  40. SELECT p.post_id, p.post_name, p.post_code
  41. FROM sys_user u
  42. LEFT JOIN sys_user_post up ON u.user_id = up.user_id
  43. LEFT JOIN sys_post p ON up.post_id = p.post_id
  44. WHERE up.user_id = #{userId}
  45. </select>
  46. <select id="selectPostById" parameterType="java.lang.Long" resultMap="PostResult">
  47. <include refid="selectPostVo"/>
  48. where post_id = #{postId}
  49. </select>
  50. <select id="checkPostNameUnique" parameterType="java.lang.String" resultMap="PostResult">
  51. <include refid="selectPostVo"/>
  52. where post_name=#{postName}
  53. </select>
  54. <select id="checkPostCodeUnique" parameterType="java.lang.String" resultMap="PostResult">
  55. <include refid="selectPostVo"/>
  56. where post_code=#{postCode}
  57. </select>
  58. <delete id="deletePostByIds" parameterType="java.lang.Long">
  59. delete from sys_post where post_id in
  60. <foreach collection="array" item="postId" open="(" separator="," close=")">
  61. #{postId}
  62. </foreach>
  63. </delete>
  64. <update id="updatePost" parameterType="com.juxiao.xchat.module.system.domain.Post">
  65. update sys_post
  66. <set>
  67. <if test="postCode != null and postCode != ''">post_code = #{postCode},</if>
  68. <if test="postName != null and postName != ''">post_name = #{postName},</if>
  69. <if test="postSort != null and postSort != ''">post_sort = #{postSort},</if>
  70. <if test="status != null and status != ''">status = #{status},</if>
  71. <if test="remark != null">remark = #{remark},</if>
  72. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  73. update_time = sysdate()
  74. </set>
  75. where post_id = #{postId}
  76. </update>
  77. <insert id="insertPost" parameterType="com.juxiao.xchat.module.system.domain.Post" useGeneratedKeys="true" keyProperty="postId">
  78. insert into sys_post(
  79. <if test="postId != null and postId != 0">post_id,</if>
  80. <if test="postCode != null and postCode != ''">post_code,</if>
  81. <if test="postName != null and postName != ''">post_name,</if>
  82. <if test="postSort != null and postSort != ''">post_sort,</if>
  83. <if test="status != null and status != ''">status,</if>
  84. <if test="remark != null and remark != ''">remark,</if>
  85. <if test="createBy != null and createBy != ''">create_by,</if>
  86. create_time
  87. )values(
  88. <if test="postId != null and postId != 0">#{postId},</if>
  89. <if test="postCode != null and postCode != ''">#{postCode},</if>
  90. <if test="postName != null and postName != ''">#{postName},</if>
  91. <if test="postSort != null and postSort != ''">#{postSort},</if>
  92. <if test="status != null and status != ''">#{status},</if>
  93. <if test="remark != null and remark != ''">#{remark},</if>
  94. <if test="createBy != null and createBy != ''">#{createBy},</if>
  95. sysdate()
  96. )
  97. </insert>
  98. </mapper>