新增教程

This commit is contained in:
苏元皓
2024-08-29 22:24:32 +08:00
parent d6492a9657
commit 00cc0b32e2
25 changed files with 744 additions and 21 deletions

View File

@@ -16,6 +16,7 @@
<result property="isOfficial" column="is_official" jdbcType="TINYINT"/>
<result property="isPublic" column="is_public" jdbcType="TINYINT"/>
<result property="location" column="location" jdbcType="VARCHAR"/>
<result property="isDraft" column="is_draft" jdbcType="TINYINT"/>
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
</resultMap>
@@ -37,32 +38,33 @@
<!-- 插入新的帖子 -->
<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, is_public, location, created_at, updated_at
post_id, user_openid, community_id, title, content,
video_url, image_urls,
is_deleted, is_official, is_public, location, is_draft, created_at, updated_at
) VALUES (
#{postId}, #{userOpenid}, #{communityId}, #{title}, #{content},
#{videoUrl}, #{imageUrls},
#{isDeleted}, #{isOfficial}, #{is_public}, #{location}, #{createdAt}, #{updatedAt}
)
#{postId}, #{userOpenid}, #{communityId}, #{title}, #{content},
#{videoUrl}, #{imageUrls},
#{isDeleted}, #{isOfficial}, #{isPublic}, #{location}, #{isDraft}, #{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},
is_public = #{is_public},
location = #{location},
created_at = #{createdAt},
updated_at = #{updatedAt}
user_openid = #{userOpenid},
community_id = #{communityId},
title = #{title},
content = #{content},
video_url = #{videoUrl},
image_urls = #{imageUrls},
is_deleted = #{isDeleted},
is_official = #{isOfficial},
is_public = #{isPublic},
location = #{location},
is_draft = #{isDraft},
created_at = #{createdAt},
updated_at = #{updatedAt}
WHERE post_id = #{postId}
</update>
@@ -80,5 +82,31 @@
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 AND p.is_public = 1
</select>
<select id="selectPopularSearches" resultType="java.lang.String">
SELECT title
FROM post
WHERE is_deleted = 0 AND is_public = 1
ORDER BY view_count DESC, like_count DESC
LIMIT 9
</select>
<select id="searchPosts" resultType="com.ivmiku.tutorial.entity.Post">
SELECT
<include refid="Base_Column_List"/>
FROM post
WHERE is_deleted = 0
AND is_public = 1
AND (title LIKE CONCAT('%', #{keyword}, '%')
OR content LIKE CONCAT('%', #{keyword}, '%'))
</select>
<select id="getTopFavoritedPosts" 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.is_public, p.location, p.created_at, p.updated_at
FROM post p
JOIN favorite f ON p.post_id = f.post_id
WHERE p.is_deleted = 0 AND p.is_public = 1 AND f.is_deleted = 0
GROUP BY p.post_id
ORDER BY COUNT(f.id) DESC
LIMIT #{limit}
</select>
</mapper>