meisiyu | c98fc52 | 2025-06-02 20:33:40 +0800 | [diff] [blame^] | 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.ruoyi.web.controller.post.mapper.PostContentMapper"> |
| 6 | |
| 7 | <resultMap type="Post" id="PostResult"> |
| 8 | <id property="postId" column="post_id" /> |
| 9 | <result property="title" column="title" /> |
| 10 | <result property="content" column="content" /> |
| 11 | <result property="summary" column="summary" /> |
| 12 | <result property="coverImage" column="cover_image" /> |
| 13 | <result property="authorId" column="author_id" /> |
| 14 | <result property="author" column="author" /> |
| 15 | <result property="views" column="views" /> |
| 16 | <result property="comments" column="comments" /> |
| 17 | <result property="favorites" column="favorites" /> |
| 18 | <result property="likes" column="likes" /> |
| 19 | <result property="status" column="status" /> |
| 20 | <result property="publishTime" column="publish_time" /> |
| 21 | <result property="tags" column="tags" /> |
| 22 | <result property="promotionPlanId" column="promotion_plan_id"/> |
| 23 | <result property="createBy" column="create_by" /> |
| 24 | <result property="createTime" column="create_time" /> |
| 25 | <result property="updateBy" column="update_by" /> |
| 26 | <result property="updateTime" column="update_time" /> |
| 27 | <result property="remark" column="remark" /> |
| 28 | </resultMap> |
| 29 | |
| 30 | <sql id="selectPostVo"> |
| 31 | select post_id, title, content, summary, cover_image, author_id, author, views, comments, favorites, likes, |
| 32 | status, publish_time, tags, promotion_plan_id, create_by, create_time, update_by, update_time, remark |
| 33 | from post |
| 34 | </sql> |
| 35 | |
| 36 | <select id="selectPostList" parameterType="Post" resultMap="PostResult"> |
| 37 | <include refid="selectPostVo"/> |
| 38 | <where> |
| 39 | <if test="title != null and title != ''"> |
| 40 | AND title like concat('%', #{title}, '%') |
| 41 | </if> |
| 42 | <if test="author != null and author != ''"> |
| 43 | AND author like concat('%', #{author}, '%') |
| 44 | </if> |
| 45 | <if test="status != null and status != ''"> |
| 46 | AND status = #{status} |
| 47 | </if> |
| 48 | <if test="tags != null and tags != ''"> |
| 49 | AND tags like concat('%', #{tags}, '%') |
| 50 | </if> |
| 51 | <if test="authorId != null"> |
| 52 | AND author_id = #{authorId} |
| 53 | </if> |
| 54 | </where> |
| 55 | order by |
| 56 | case when promotion_plan_id is not null then 0 else 1 end, |
| 57 | create_time desc |
| 58 | </select> |
| 59 | |
| 60 | <select id="selectPostById" parameterType="Long" resultMap="PostResult"> |
| 61 | <include refid="selectPostVo"/> |
| 62 | where post_id = #{postId} |
| 63 | </select> |
| 64 | |
| 65 | <select id="selectAuthorOtherPosts" resultMap="PostResult"> |
| 66 | <include refid="selectPostVo"/> |
| 67 | where author_id = #{authorId} and post_id != #{postId} and status = '1' |
| 68 | order by create_time desc |
| 69 | limit #{limit} |
| 70 | </select> |
| 71 | |
| 72 | <select id="selectSimilarTagsPosts" resultMap="PostResult"> |
| 73 | <include refid="selectPostVo"/> |
| 74 | <where> |
| 75 | post_id != #{postId} and status = '1' |
| 76 | <if test="tags != null and tags != ''"> |
| 77 | AND tags like concat('%', #{tags}, '%') |
| 78 | </if> |
| 79 | </where> |
| 80 | order by create_time desc |
| 81 | limit #{limit} |
| 82 | </select> |
| 83 | |
| 84 | <insert id="insertPost" parameterType="Post" useGeneratedKeys="true" keyProperty="postId"> |
| 85 | insert into post ( |
| 86 | title, |
| 87 | content, |
| 88 | summary, |
| 89 | cover_image, |
| 90 | author_id, |
| 91 | author, |
| 92 | views, |
| 93 | comments, |
| 94 | favorites, |
| 95 | likes, |
| 96 | status, |
| 97 | publish_time, |
| 98 | tags, |
| 99 | promotion_plan_id, |
| 100 | create_by, |
| 101 | create_time, |
| 102 | update_by, |
| 103 | update_time, |
| 104 | remark |
| 105 | ) values ( |
| 106 | #{title}, |
| 107 | #{content}, |
| 108 | #{summary}, |
| 109 | #{coverImage}, |
| 110 | #{authorId}, |
| 111 | #{author}, |
| 112 | #{views}, |
| 113 | #{comments}, |
| 114 | #{favorites}, |
| 115 | #{likes}, |
| 116 | #{status}, |
| 117 | #{publishTime}, |
| 118 | #{tags}, |
| 119 | #{promotionPlanId}, |
| 120 | #{createBy}, |
| 121 | now(), |
| 122 | #{updateBy}, |
| 123 | now(), |
| 124 | #{remark} |
| 125 | ) |
| 126 | </insert> |
| 127 | |
| 128 | <update id="updatePost" parameterType="Post"> |
| 129 | update post |
| 130 | <set> |
| 131 | <if test="title != null and title != ''">title = #{title},</if> |
| 132 | <if test="content != null">content = #{content},</if> |
| 133 | <if test="summary != null">summary = #{summary},</if> |
| 134 | <if test="coverImage != null">cover_image = #{coverImage},</if> |
| 135 | <if test="status != null and status != ''">status = #{status},</if> |
| 136 | <if test="tags != null">tags = #{tags},</if> |
| 137 | <if test="promotionPlanId != null">promotion_plan_id = #{promotionPlanId},</if> |
| 138 | <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> |
| 139 | update_time = now(), |
| 140 | <if test="remark != null">remark = #{remark},</if> |
| 141 | </set> |
| 142 | where post_id = #{postId} |
| 143 | </update> |
| 144 | |
| 145 | <delete id="deletePostById" parameterType="Long"> |
| 146 | delete from post where post_id = #{postId} |
| 147 | </delete> |
| 148 | |
| 149 | <delete id="deletePostByIds" parameterType="Long"> |
| 150 | delete from post where post_id in |
| 151 | <foreach collection="array" item="postId" open="(" separator="," close=")"> |
| 152 | #{postId} |
| 153 | </foreach> |
| 154 | </delete> |
| 155 | |
| 156 | <update id="updatePostViews" parameterType="Long"> |
| 157 | update post set views = views + 1 where post_id = #{postId} |
| 158 | </update> |
| 159 | |
| 160 | <update id="updatePostComments" parameterType="Post"> |
| 161 | update post set comments = comments + #{comments} where post_id = #{postId} |
| 162 | </update> |
| 163 | |
| 164 | <update id="updatePostFavorites" parameterType="Post"> |
| 165 | update post set favorites = favorites + #{favorites} where post_id = #{postId} |
| 166 | </update> |
| 167 | |
| 168 | <update id="updatePostLikes" parameterType="Post"> |
| 169 | update post set likes = likes + #{likes} where post_id = #{postId} |
| 170 | </update> |
| 171 | |
| 172 | </mapper> |