Files
guidance-backend/community-8073/src/main/resources/mapper/PostMapper.xml
苏元皓 a018f5b85d minio
2024-08-09 09:27:23 +08:00

81 lines
3.4 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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.ivmiku.tutorial.mapper.PostMapper">
<resultMap id="BaseResultMap" type="com.ivmiku.tutorial.entity.Post">
<id property="postId" column="post_id" jdbcType="BIGINT"/>
<result property="userOpenid" column="user_openid" jdbcType="VARCHAR"/>
<result property="communityId" column="community_id" jdbcType="BIGINT"/>
<result property="title" column="title" jdbcType="VARCHAR"/>
<result property="content" column="content" jdbcType="VARCHAR"/>
<result property="videoUrl" column="video_url" jdbcType="VARCHAR"/> <!-- 新增字段 -->
<result property="imageUrls" column="image_urls" jdbcType="VARCHAR"/> <!-- 新增字段 -->
<result property="isDeleted" column="is_deleted" jdbcType="TINYINT"/>
<result property="isOfficial" column="is_official" jdbcType="TINYINT"/> <!-- 新增字段 -->
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
post_id, user_openid, community_id, title, content,
video_url, image_urls, <!-- 新增字段 -->
is_deleted, is_official, created_at, updated_at
</sql>
<!-- 查询指定帖子的所有评论 -->
<select id="selectCommentsByPostId" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM post
WHERE post_id = #{postId} AND is_deleted = 0
</select>
<!-- 插入新的帖子 -->
<insert id="insertPost" parameterType="com.ivmiku.tutorial.entity.Post">
INSERT INTO post (
post_id, user_openid, community_id, title, content,
video_url, image_urls, <!-- 新增字段 -->
is_deleted, is_official, created_at, updated_at
) VALUES (
#{postId}, #{userOpenid}, #{communityId}, #{title}, #{content},
#{videoUrl}, #{imageUrls}, <!-- 新增字段 -->
#{isDeleted}, #{isOfficial}, #{createdAt}, #{updatedAt}
)
</insert>
<!-- 更新帖子 -->
<update id="updatePost" parameterType="com.ivmiku.tutorial.entity.Post">
UPDATE post
SET
user_openid = #{userOpenid},
community_id = #{communityId},
title = #{title},
content = #{content},
video_url = #{videoUrl}, <!-- 新增字段 -->
image_urls = #{imageUrls}, <!-- 新增字段 -->
is_deleted = #{isDeleted},
is_official = #{isOfficial},
created_at = #{createdAt},
updated_at = #{updatedAt}
WHERE post_id = #{postId}
</update>
<!-- 删除帖子实际上是将is_deleted字段设置为1 -->
<update id="deletePost">
UPDATE post
SET is_deleted = 1, updated_at = CURRENT_TIMESTAMP
WHERE post_id = #{postId}
</update>
<select id="getTagPostList" resultType="com.ivmiku.tutorial.entity.Post">
SELECT p.post_id, p.user_openid, p.community_id, p.title, p.content,
p.is_deleted, p.is_official, p.created_at, p.updated_at
FROM post p, posttag pt, tag t
WHERE p.post_id = pt.post_id AND pt.tag_id = t.tag_id AND t.tag_id = #{tagId} AND p.is_deleted = 0
</select>
</mapper>