meisiyu | c98fc52 | 2025-06-02 20:33:40 +0800 | [diff] [blame^] | 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <!DOCTYPE mapper |
| 3 | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| 4 | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| 5 | <mapper namespace="com.ruoyi.web.controller.post.mapper.PostFavoriteMapper"> |
| 6 | |
| 7 | <resultMap type="PostFavorite" id="PostFavoriteResult"> |
| 8 | <id property="favoriteId" column="favorite_id" /> |
| 9 | <result property="postId" column="post_id" /> |
| 10 | <result property="userId" column="user_id" /> |
| 11 | <result property="postTitle" column="post_title" /> |
| 12 | <result property="postCover" column="post_cover" /> |
| 13 | <result property="status" column="status" /> |
| 14 | <result property="createBy" column="create_by" /> |
| 15 | <result property="createTime" column="create_time" /> |
| 16 | <result property="updateBy" column="update_by" /> |
| 17 | <result property="updateTime" column="update_time" /> |
| 18 | <result property="remark" column="remark" /> |
| 19 | </resultMap> |
| 20 | |
| 21 | <sql id="selectPostFavoriteVo"> |
| 22 | select favorite_id, post_id, user_id, post_title, post_cover, status, |
| 23 | create_by, create_time, update_by, update_time, remark |
| 24 | from post_favorite |
| 25 | </sql> |
| 26 | |
| 27 | <select id="selectPostFavoriteList" parameterType="PostFavorite" resultMap="PostFavoriteResult"> |
| 28 | <include refid="selectPostFavoriteVo"/> |
| 29 | <where> |
| 30 | <if test="postId != null"> |
| 31 | AND post_id = #{postId} |
| 32 | </if> |
| 33 | <if test="userId != null"> |
| 34 | AND user_id = #{userId} |
| 35 | </if> |
| 36 | <if test="status != null and status != ''"> |
| 37 | AND status = #{status} |
| 38 | </if> |
| 39 | </where> |
| 40 | order by create_time desc |
| 41 | </select> |
| 42 | |
| 43 | <select id="selectPostFavoriteById" parameterType="Long" resultMap="PostFavoriteResult"> |
| 44 | <include refid="selectPostFavoriteVo"/> |
| 45 | where favorite_id = #{favoriteId} |
| 46 | </select> |
| 47 | |
| 48 | <select id="selectPostFavoriteByPostIdAndUserId" resultMap="PostFavoriteResult"> |
| 49 | <include refid="selectPostFavoriteVo"/> |
| 50 | where post_id = #{postId} and user_id = #{userId} |
| 51 | </select> |
| 52 | |
| 53 | <insert id="insertPostFavorite" parameterType="PostFavorite" useGeneratedKeys="true" keyProperty="favoriteId"> |
| 54 | insert into post_favorite ( |
| 55 | post_id, |
| 56 | user_id, |
| 57 | post_title, |
| 58 | post_cover, |
| 59 | status, |
| 60 | create_by, |
| 61 | create_time, |
| 62 | update_by, |
| 63 | update_time, |
| 64 | remark |
| 65 | ) values ( |
| 66 | #{postId}, |
| 67 | #{userId}, |
| 68 | #{postTitle}, |
| 69 | #{postCover}, |
| 70 | #{status}, |
| 71 | #{createBy}, |
| 72 | now(), |
| 73 | #{updateBy}, |
| 74 | now(), |
| 75 | #{remark} |
| 76 | ) |
| 77 | </insert> |
| 78 | |
| 79 | <update id="updatePostFavorite" parameterType="PostFavorite"> |
| 80 | update post_favorite |
| 81 | <set> |
| 82 | <if test="status != null and status != ''">status = #{status},</if> |
| 83 | <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> |
| 84 | update_time = now(), |
| 85 | <if test="remark != null">remark = #{remark},</if> |
| 86 | </set> |
| 87 | where favorite_id = #{favoriteId} |
| 88 | </update> |
| 89 | |
| 90 | <delete id="deletePostFavoriteById" parameterType="Long"> |
| 91 | delete from post_favorite where favorite_id = #{favoriteId} |
| 92 | </delete> |
| 93 | |
| 94 | <delete id="deletePostFavoriteByIds" parameterType="Long"> |
| 95 | delete from post_favorite where favorite_id in |
| 96 | <foreach collection="array" item="favoriteId" open="(" separator="," close=")"> |
| 97 | #{favoriteId} |
| 98 | </foreach> |
| 99 | </delete> |
| 100 | |
| 101 | <delete id="deletePostFavoriteByPostId" parameterType="Long"> |
| 102 | delete from post_favorite where post_id = #{postId} |
| 103 | </delete> |
| 104 | |
| 105 | <update id="cancelPostFavorite"> |
| 106 | update post_favorite set status = '1', update_time = now() |
| 107 | where post_id = #{postId} and user_id = #{userId} |
| 108 | </update> |
| 109 | |
| 110 | </mapper> |