blob: 5254e6fe7f4cbde42fee8086e5d8b356e26c4682 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.web.controller.post.mapper.PostContentMapper">
<resultMap type="Post" id="PostResult">
<id property="postId" column="post_id" />
<result property="title" column="title" />
<result property="content" column="content" />
<result property="summary" column="summary" />
<result property="coverImage" column="cover_image" />
<result property="authorId" column="author_id" />
<result property="author" column="author" />
<result property="views" column="views" />
<result property="comments" column="comments" />
<result property="favorites" column="favorites" />
<result property="likes" column="likes" />
<result property="status" column="status" />
<result property="publishTime" column="publish_time" />
<result property="tags" column="tags" />
<result property="promotionPlanId" column="promotion_plan_id"/>
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
</resultMap>
<sql id="selectPostVo">
select post_id, title, content, summary, cover_image, author_id, author, views, comments, favorites, likes,
status, publish_time, tags, promotion_plan_id, create_by, create_time, update_by, update_time, remark
from post
</sql>
<select id="selectPostList" parameterType="Post" resultMap="PostResult">
<include refid="selectPostVo"/>
<where>
<if test="title != null and title != ''">
AND title like concat('%', #{title}, '%')
</if>
<if test="author != null and author != ''">
AND author like concat('%', #{author}, '%')
</if>
<if test="status != null and status != ''">
AND status = #{status}
</if>
<if test="tags != null and tags != ''">
AND tags like concat('%', #{tags}, '%')
</if>
<if test="authorId != null">
AND author_id = #{authorId}
</if>
</where>
order by
case when promotion_plan_id is not null then 0 else 1 end,
create_time desc
</select>
<select id="selectPostById" parameterType="Long" resultMap="PostResult">
<include refid="selectPostVo"/>
where post_id = #{postId}
</select>
<select id="selectAuthorOtherPosts" resultMap="PostResult">
<include refid="selectPostVo"/>
where author_id = #{authorId} and post_id != #{postId} and status = '1'
order by create_time desc
limit #{limit}
</select>
<select id="selectSimilarTagsPosts" resultMap="PostResult">
<include refid="selectPostVo"/>
<where>
post_id != #{postId} and status = '1'
<if test="tags != null and tags != ''">
AND tags like concat('%', #{tags}, '%')
</if>
</where>
order by create_time desc
limit #{limit}
</select>
<insert id="insertPost" parameterType="Post" useGeneratedKeys="true" keyProperty="postId">
insert into post (
title,
content,
summary,
cover_image,
author_id,
author,
views,
comments,
favorites,
likes,
status,
publish_time,
tags,
promotion_plan_id,
create_by,
create_time,
update_by,
update_time,
remark
) values (
#{title},
#{content},
#{summary},
#{coverImage},
#{authorId},
#{author},
#{views},
#{comments},
#{favorites},
#{likes},
#{status},
#{publishTime},
#{tags},
#{promotionPlanId},
#{createBy},
now(),
#{updateBy},
now(),
#{remark}
)
</insert>
<update id="updatePost" parameterType="Post">
update post
<set>
<if test="title != null and title != ''">title = #{title},</if>
<if test="content != null">content = #{content},</if>
<if test="summary != null">summary = #{summary},</if>
<if test="coverImage != null">cover_image = #{coverImage},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="tags != null">tags = #{tags},</if>
<if test="promotionPlanId != null">promotion_plan_id = #{promotionPlanId},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = now(),
<if test="remark != null">remark = #{remark},</if>
</set>
where post_id = #{postId}
</update>
<delete id="deletePostById" parameterType="Long">
delete from post where post_id = #{postId}
</delete>
<delete id="deletePostByIds" parameterType="Long">
delete from post where post_id in
<foreach collection="array" item="postId" open="(" separator="," close=")">
#{postId}
</foreach>
</delete>
<update id="updatePostViews" parameterType="Long">
update post set views = views + 1 where post_id = #{postId}
</update>
<update id="updatePostComments" parameterType="Post">
update post set comments = comments + #{comments} where post_id = #{postId}
</update>
<update id="updatePostFavorites" parameterType="Post">
update post set favorites = favorites + #{favorites} where post_id = #{postId}
</update>
<update id="updatePostLikes" parameterType="Post">
update post set likes = likes + #{likes} where post_id = #{postId}
</update>
</mapper>