SysPostMapper.xml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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.ufo.module.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. <if test="orderByColumn != null and orderByColumn != ''">
  36. ORDER BY ${orderByColumn} ${isAsc}
  37. </if>
  38. </select>
  39. <select id="selectPostAll" resultMap="SysPostResult">
  40. <include refid="selectPostVo"/>
  41. </select>
  42. <select id="selectPostById" parameterType="Long" resultMap="SysPostResult">
  43. <include refid="selectPostVo"/>
  44. where post_id = #{postId}
  45. </select>
  46. <select id="selectPostListByUserId" parameterType="Long" resultType="Long">
  47. select p.post_id
  48. from sys_post p
  49. left join sys_user_post up on up.post_id = p.post_id
  50. left join sys_user u on u.user_id = up.user_id
  51. where u.user_id = #{userId}
  52. </select>
  53. <select id="selectPostsByUserName" parameterType="String" resultMap="SysPostResult">
  54. select p.post_id, p.post_name, p.post_code
  55. from sys_post p
  56. left join sys_user_post up on up.post_id = p.post_id
  57. left join sys_user u on u.user_id = up.user_id
  58. where u.user_name = #{userName}
  59. </select>
  60. <select id="checkPostNameUnique" parameterType="String" resultMap="SysPostResult">
  61. <include refid="selectPostVo"/>
  62. where post_name=#{postName} limit 1
  63. </select>
  64. <select id="checkPostCodeUnique" parameterType="String" resultMap="SysPostResult">
  65. <include refid="selectPostVo"/>
  66. where post_code=#{postCode} limit 1
  67. </select>
  68. <update id="updatePost" parameterType="SysPost">
  69. update sys_post
  70. <set>
  71. <if test="postCode != null and postCode != ''">post_code = #{postCode},</if>
  72. <if test="postName != null and postName != ''">post_name = #{postName},</if>
  73. <if test="postSort != null">post_sort = #{postSort},</if>
  74. <if test="status != null and status != ''">status = #{status},</if>
  75. <if test="remark != null">remark = #{remark},</if>
  76. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  77. update_time = CURRENT_TIMESTAMP
  78. </set>
  79. where post_id = #{postId}
  80. </update>
  81. <insert id="insertPost" parameterType="SysPost" useGeneratedKeys="true" keyProperty="postId">
  82. insert into sys_post(
  83. <if test="postId != null and postId != 0">post_id,</if>
  84. <if test="postCode != null and postCode != ''">post_code,</if>
  85. <if test="postName != null and postName != ''">post_name,</if>
  86. <if test="postSort != null">post_sort,</if>
  87. <if test="status != null and status != ''">status,</if>
  88. <if test="remark != null and remark != ''">remark,</if>
  89. <if test="createBy != null and createBy != ''">create_by,</if>
  90. create_time
  91. )values(
  92. <if test="postId != null and postId != 0">#{postId},</if>
  93. <if test="postCode != null and postCode != ''">#{postCode},</if>
  94. <if test="postName != null and postName != ''">#{postName},</if>
  95. <if test="postSort != null">#{postSort},</if>
  96. <if test="status != null and status != ''">#{status},</if>
  97. <if test="remark != null and remark != ''">#{remark},</if>
  98. <if test="createBy != null and createBy != ''">#{createBy},</if>
  99. CURRENT_TIMESTAMP
  100. )
  101. </insert>
  102. <delete id="deletePostById" parameterType="Long">
  103. delete from sys_post where post_id = #{postId}
  104. </delete>
  105. <delete id="deletePostByIds" parameterType="Long">
  106. delete from sys_post where post_id in
  107. <foreach collection="array" item="postId" open="(" separator="," close=")">
  108. #{postId}
  109. </foreach>
  110. </delete>
  111. </mapper>