You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
7.3 KiB

  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.chenhai.system.mapper.PostsMapper">
  6. <resultMap type="Posts" id="PostsResult">
  7. <result property="postId" column="post_id" />
  8. <result property="authorId" column="author_id" />
  9. <result property="postType" column="post_type" />
  10. <result property="title" column="title" />
  11. <result property="content" column="content" />
  12. <result property="category" column="category" />
  13. <result property="images" column="images" />
  14. <result property="videoUrl" column="video_url" />
  15. <result property="status" column="status" />
  16. <result property="isSensitive" column="is_sensitive" />
  17. <result property="sensitiveWords" column="sensitive_words" />
  18. <result property="auditRemark" column="audit_remark" />
  19. <result property="viewCount" column="view_count" />
  20. <result property="publishedAt" column="published_at" />
  21. <result property="lastReplyAt" column="last_reply_at" />
  22. <result property="createdAt" column="created_at" />
  23. <result property="updatedAt" column="updated_at" />
  24. </resultMap>
  25. <sql id="selectPostsVo">
  26. select post_id, author_id, post_type, title, content, category, images, video_url, status, is_sensitive, sensitive_words, audit_remark, view_count, published_at, last_reply_at, created_at, updated_at from posts
  27. </sql>
  28. <select id="selectPostsList" parameterType="Posts" resultMap="PostsResult">
  29. <include refid="selectPostsVo"/>
  30. <where>
  31. <if test="authorId != null "> and author_id = #{authorId}</if>
  32. <if test="postType != null and postType != ''"> and post_type = #{postType}</if>
  33. <if test="title != null and title != ''"> and title = #{title}</if>
  34. <if test="content != null and content != ''"> and content = #{content}</if>
  35. <if test="category != null and category != ''"> and category = #{category}</if>
  36. <if test="images != null and images != ''"> and images = #{images}</if>
  37. <if test="videoUrl != null and videoUrl != ''"> and video_url = #{videoUrl}</if>
  38. <if test="status != null and status != ''"> and status = #{status}</if>
  39. <if test="isSensitive != null "> and is_sensitive = #{isSensitive}</if>
  40. <if test="sensitiveWords != null and sensitiveWords != ''"> and sensitive_words = #{sensitiveWords}</if>
  41. <if test="auditRemark != null and auditRemark != ''"> and audit_remark = #{auditRemark}</if>
  42. <if test="viewCount != null "> and view_count = #{viewCount}</if>
  43. <if test="publishedAt != null "> and published_at = #{publishedAt}</if>
  44. <if test="lastReplyAt != null "> and last_reply_at = #{lastReplyAt}</if>
  45. <if test="createdAt != null "> and created_at = #{createdAt}</if>
  46. <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
  47. </where>
  48. </select>
  49. <select id="selectPostsByPostId" parameterType="Long" resultMap="PostsResult">
  50. <include refid="selectPostsVo"/>
  51. where post_id = #{postId}
  52. </select>
  53. <insert id="insertPosts" parameterType="Posts" useGeneratedKeys="true" keyProperty="postId">
  54. insert into posts
  55. <trim prefix="(" suffix=")" suffixOverrides=",">
  56. <if test="authorId != null">author_id,</if>
  57. <if test="postType != null and postType != ''">post_type,</if>
  58. <if test="title != null and title != ''">title,</if>
  59. <if test="content != null and content != ''">content,</if>
  60. <if test="category != null">category,</if>
  61. <if test="images != null">images,</if>
  62. <if test="videoUrl != null">video_url,</if>
  63. <if test="status != null">status,</if>
  64. <if test="isSensitive != null">is_sensitive,</if>
  65. <if test="sensitiveWords != null">sensitive_words,</if>
  66. <if test="auditRemark != null">audit_remark,</if>
  67. <if test="viewCount != null">view_count,</if>
  68. <if test="publishedAt != null">published_at,</if>
  69. <if test="lastReplyAt != null">last_reply_at,</if>
  70. <if test="createdAt != null">created_at,</if>
  71. <if test="updatedAt != null">updated_at,</if>
  72. </trim>
  73. <trim prefix="values (" suffix=")" suffixOverrides=",">
  74. <if test="authorId != null">#{authorId},</if>
  75. <if test="postType != null and postType != ''">#{postType},</if>
  76. <if test="title != null and title != ''">#{title},</if>
  77. <if test="content != null and content != ''">#{content},</if>
  78. <if test="category != null">#{category},</if>
  79. <if test="images != null">#{images},</if>
  80. <if test="videoUrl != null">#{videoUrl},</if>
  81. <if test="status != null">#{status},</if>
  82. <if test="isSensitive != null">#{isSensitive},</if>
  83. <if test="sensitiveWords != null">#{sensitiveWords},</if>
  84. <if test="auditRemark != null">#{auditRemark},</if>
  85. <if test="viewCount != null">#{viewCount},</if>
  86. <if test="publishedAt != null">#{publishedAt},</if>
  87. <if test="lastReplyAt != null">#{lastReplyAt},</if>
  88. <if test="createdAt != null">#{createdAt},</if>
  89. <if test="updatedAt != null">#{updatedAt},</if>
  90. </trim>
  91. </insert>
  92. <update id="updatePosts" parameterType="Posts">
  93. update posts
  94. <trim prefix="SET" suffixOverrides=",">
  95. <if test="authorId != null">author_id = #{authorId},</if>
  96. <if test="postType != null and postType != ''">post_type = #{postType},</if>
  97. <if test="title != null and title != ''">title = #{title},</if>
  98. <if test="content != null and content != ''">content = #{content},</if>
  99. <if test="category != null">category = #{category},</if>
  100. <if test="images != null">images = #{images},</if>
  101. <if test="videoUrl != null">video_url = #{videoUrl},</if>
  102. <if test="status != null">status = #{status},</if>
  103. <if test="isSensitive != null">is_sensitive = #{isSensitive},</if>
  104. <if test="sensitiveWords != null">sensitive_words = #{sensitiveWords},</if>
  105. <if test="auditRemark != null">audit_remark = #{auditRemark},</if>
  106. <if test="viewCount != null">view_count = #{viewCount},</if>
  107. <if test="publishedAt != null">published_at = #{publishedAt},</if>
  108. <if test="lastReplyAt != null">last_reply_at = #{lastReplyAt},</if>
  109. <if test="createdAt != null">created_at = #{createdAt},</if>
  110. <if test="updatedAt != null">updated_at = #{updatedAt},</if>
  111. </trim>
  112. where post_id = #{postId}
  113. </update>
  114. <delete id="deletePostsByPostId" parameterType="Long">
  115. delete from posts where post_id = #{postId}
  116. </delete>
  117. <delete id="deletePostsByPostIds" parameterType="String">
  118. delete from posts where post_id in
  119. <foreach item="postId" collection="array" open="(" separator="," close=")">
  120. #{postId}
  121. </foreach>
  122. </delete>
  123. </mapper>