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.
 
 
 
 
 

131 lines
7.3 KiB

<?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.chenhai.system.mapper.PostsMapper">
<resultMap type="Posts" id="PostsResult">
<result property="postId" column="post_id" />
<result property="authorId" column="author_id" />
<result property="postType" column="post_type" />
<result property="title" column="title" />
<result property="content" column="content" />
<result property="category" column="category" />
<result property="images" column="images" />
<result property="videoUrl" column="video_url" />
<result property="status" column="status" />
<result property="isSensitive" column="is_sensitive" />
<result property="sensitiveWords" column="sensitive_words" />
<result property="auditRemark" column="audit_remark" />
<result property="viewCount" column="view_count" />
<result property="publishedAt" column="published_at" />
<result property="lastReplyAt" column="last_reply_at" />
<result property="createdAt" column="created_at" />
<result property="updatedAt" column="updated_at" />
</resultMap>
<sql id="selectPostsVo">
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
</sql>
<select id="selectPostsList" parameterType="Posts" resultMap="PostsResult">
<include refid="selectPostsVo"/>
<where>
<if test="authorId != null "> and author_id = #{authorId}</if>
<if test="postType != null and postType != ''"> and post_type = #{postType}</if>
<if test="title != null and title != ''"> and title = #{title}</if>
<if test="content != null and content != ''"> and content = #{content}</if>
<if test="category != null and category != ''"> and category = #{category}</if>
<if test="images != null and images != ''"> and images = #{images}</if>
<if test="videoUrl != null and videoUrl != ''"> and video_url = #{videoUrl}</if>
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="isSensitive != null "> and is_sensitive = #{isSensitive}</if>
<if test="sensitiveWords != null and sensitiveWords != ''"> and sensitive_words = #{sensitiveWords}</if>
<if test="auditRemark != null and auditRemark != ''"> and audit_remark = #{auditRemark}</if>
<if test="viewCount != null "> and view_count = #{viewCount}</if>
<if test="publishedAt != null "> and published_at = #{publishedAt}</if>
<if test="lastReplyAt != null "> and last_reply_at = #{lastReplyAt}</if>
<if test="createdAt != null "> and created_at = #{createdAt}</if>
<if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
</where>
</select>
<select id="selectPostsByPostId" parameterType="Long" resultMap="PostsResult">
<include refid="selectPostsVo"/>
where post_id = #{postId}
</select>
<insert id="insertPosts" parameterType="Posts" useGeneratedKeys="true" keyProperty="postId">
insert into posts
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="authorId != null">author_id,</if>
<if test="postType != null and postType != ''">post_type,</if>
<if test="title != null and title != ''">title,</if>
<if test="content != null and content != ''">content,</if>
<if test="category != null">category,</if>
<if test="images != null">images,</if>
<if test="videoUrl != null">video_url,</if>
<if test="status != null">status,</if>
<if test="isSensitive != null">is_sensitive,</if>
<if test="sensitiveWords != null">sensitive_words,</if>
<if test="auditRemark != null">audit_remark,</if>
<if test="viewCount != null">view_count,</if>
<if test="publishedAt != null">published_at,</if>
<if test="lastReplyAt != null">last_reply_at,</if>
<if test="createdAt != null">created_at,</if>
<if test="updatedAt != null">updated_at,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="authorId != null">#{authorId},</if>
<if test="postType != null and postType != ''">#{postType},</if>
<if test="title != null and title != ''">#{title},</if>
<if test="content != null and content != ''">#{content},</if>
<if test="category != null">#{category},</if>
<if test="images != null">#{images},</if>
<if test="videoUrl != null">#{videoUrl},</if>
<if test="status != null">#{status},</if>
<if test="isSensitive != null">#{isSensitive},</if>
<if test="sensitiveWords != null">#{sensitiveWords},</if>
<if test="auditRemark != null">#{auditRemark},</if>
<if test="viewCount != null">#{viewCount},</if>
<if test="publishedAt != null">#{publishedAt},</if>
<if test="lastReplyAt != null">#{lastReplyAt},</if>
<if test="createdAt != null">#{createdAt},</if>
<if test="updatedAt != null">#{updatedAt},</if>
</trim>
</insert>
<update id="updatePosts" parameterType="Posts">
update posts
<trim prefix="SET" suffixOverrides=",">
<if test="authorId != null">author_id = #{authorId},</if>
<if test="postType != null and postType != ''">post_type = #{postType},</if>
<if test="title != null and title != ''">title = #{title},</if>
<if test="content != null and content != ''">content = #{content},</if>
<if test="category != null">category = #{category},</if>
<if test="images != null">images = #{images},</if>
<if test="videoUrl != null">video_url = #{videoUrl},</if>
<if test="status != null">status = #{status},</if>
<if test="isSensitive != null">is_sensitive = #{isSensitive},</if>
<if test="sensitiveWords != null">sensitive_words = #{sensitiveWords},</if>
<if test="auditRemark != null">audit_remark = #{auditRemark},</if>
<if test="viewCount != null">view_count = #{viewCount},</if>
<if test="publishedAt != null">published_at = #{publishedAt},</if>
<if test="lastReplyAt != null">last_reply_at = #{lastReplyAt},</if>
<if test="createdAt != null">created_at = #{createdAt},</if>
<if test="updatedAt != null">updated_at = #{updatedAt},</if>
</trim>
where post_id = #{postId}
</update>
<delete id="deletePostsByPostId" parameterType="Long">
delete from posts where post_id = #{postId}
</delete>
<delete id="deletePostsByPostIds" parameterType="String">
delete from posts where post_id in
<foreach item="postId" collection="array" open="(" separator="," close=")">
#{postId}
</foreach>
</delete>
</mapper>