145 lines
5.2 KiB
XML
145 lines
5.2 KiB
XML
<?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.bao.dating.mapper.PostMapper">
|
|
|
|
<!--动态添加-->
|
|
<insert id="insert" useGeneratedKeys="true" keyProperty="postId">
|
|
INSERT INTO post
|
|
(user_id, content,
|
|
<if test="mediaOssKeys != null and mediaOssKeys != ''">
|
|
media_oss_keys,
|
|
</if>
|
|
tags,
|
|
<if test="location != null and location != ''">
|
|
location,
|
|
</if>
|
|
is_public, like_count, favorite_count, created_at, updated_at)
|
|
VALUES
|
|
(#{userId}, #{content},
|
|
<if test="mediaOssKeys != null and mediaOssKeys != ''">
|
|
#{mediaOssKeys, typeHandler=com.bao.dating.handler.ListToVarcharTypeHandler},
|
|
</if>
|
|
#{tags, typeHandler=com.bao.dating.handler.ListToVarcharTypeHandler},
|
|
<if test="location != null and location != ''">
|
|
#{location},
|
|
</if>
|
|
#{isPublic}, 0, 0, #{createdAt}, #{updatedAt})
|
|
</insert>
|
|
|
|
<!--修改动态状态-->
|
|
<update id="updatePublicById">
|
|
UPDATE post
|
|
<set>
|
|
is_public = 3,
|
|
updated_at = NOW()
|
|
</set>
|
|
WHERE post_id IN
|
|
<foreach item="postId" index="index" collection="postIds" separator="," open="(" close=")">
|
|
#{postId}
|
|
</foreach>
|
|
AND user_id = #{userId}
|
|
</update>
|
|
|
|
<!--删除收藏记录-->
|
|
<delete id="deletePostFavoriteByPostId">
|
|
DELETE FROM post_favorite WHERE post_id = #{postId}
|
|
</delete>
|
|
<!--删除点赞记录-->
|
|
<delete id="deletePostLikeByPostId">
|
|
DELETE FROM post_like WHERE post_id = #{postId}
|
|
</delete>
|
|
<!--动态评论删除-->
|
|
<delete id="deleteCommentsByPostId">
|
|
DELETE FROM comments WHERE post_id = #{postId}
|
|
</delete>
|
|
|
|
<!--动态查询-->
|
|
<resultMap id="PostResultMap" type="com.bao.dating.pojo.entity.Post">
|
|
<id property="postId" column="post_id"/>
|
|
<result property="userId" column="user_id"/>
|
|
<result property="content" column="content"/>
|
|
<result property="mediaOssKeys" column="media_oss_keys" typeHandler="com.bao.dating.handler.ListToVarcharTypeHandler"/>
|
|
<result property="tags" column="tags" typeHandler="com.bao.dating.handler.ListToVarcharTypeHandler"/>
|
|
<result property="location" column="location"/>
|
|
<result property="isPublic" column="is_public"/>
|
|
<result property="likeCount" column="like_count"/>
|
|
<result property="favoriteCount" column="favorite_count"/>
|
|
<result property="createdAt" column="created_at"/>
|
|
<result property="updatedAt" column="updated_at"/>
|
|
</resultMap>
|
|
<select id="selectById" resultMap="PostResultMap">
|
|
SELECT
|
|
post_id,
|
|
user_id,
|
|
content,
|
|
media_oss_keys,
|
|
tags,
|
|
location,
|
|
is_public,
|
|
like_count,
|
|
favorite_count,
|
|
created_at,
|
|
updated_at
|
|
FROM post WHERE post_id = #{postId}
|
|
</select>
|
|
|
|
<!--动态更新-->
|
|
<update id="updateById">
|
|
UPDATE post
|
|
<set>
|
|
<if test="content != null and content != '' ">
|
|
content = #{content},
|
|
</if>
|
|
<if test="tags != null and tags != '' ">
|
|
tags = #{tags, typeHandler=com.bao.dating.handler.ListToVarcharTypeHandler},
|
|
</if>
|
|
<if test="mediaOssKeys != null">
|
|
media_oss_keys =
|
|
#{mediaOssKeys, typeHandler=com.bao.dating.handler.ListToVarcharTypeHandler},
|
|
</if>
|
|
is_public = #{isPublic},
|
|
updated_at = #{updatedAt}
|
|
</set>
|
|
WHERE post_id = #{postId}
|
|
</update>
|
|
|
|
<!--增加点赞数量-->
|
|
<update id="increaseLikeCount">
|
|
update dating.post set like_count = like_count + 1 where post.post_id = #{postId}
|
|
</update>
|
|
|
|
<!--减少点赞数量-->
|
|
<update id="decreaseLikeCount">
|
|
update dating.post set like_count= like_count - 1 where post.post_id = #{postId}
|
|
</update>
|
|
<!--增加收藏数量-->
|
|
<update id="increaseFavoriteCount">
|
|
update post set favorite_count = favorite_count + 1 where post_id = #{post_id}
|
|
</update>
|
|
<!--减少收藏数量-->
|
|
<update id="decreaseFavoriteCount">
|
|
update post set favorite_count = favorite_count - 1 where post_id = #{post_id}
|
|
</update>
|
|
|
|
<!--查询点赞当前数量-->
|
|
<select id="selectLikeCount" resultType="java.lang.Integer">
|
|
select dating.post.like_count from dating.post where post.post_id = #{postId}
|
|
</select>
|
|
<!--查询当前动态的用户id-->
|
|
<select id="selectUserIdByPostId" resultType="java.lang.Long">
|
|
SELECT user_id FROM post WHERE post_id = #{post_id}
|
|
</select>
|
|
<!--查询当前收藏数量-->
|
|
<select id="selectFavoriteCount" resultType="java.lang.Integer">
|
|
select dating.post.favorite_count from dating.post where post.post_id = #{postId}
|
|
</select>
|
|
<select id="getUsernameByUserId" resultType="map">
|
|
SELECT u.user_name, u.user_id, p.media_oss_keys
|
|
FROM post p
|
|
LEFT JOIN user u ON p.user_id = u.user_id
|
|
WHERE p.post_id = #{postId}
|
|
</select>
|
|
|
|
</mapper> |