<?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.mcwl.communityCenter.mapper.PublishCollectMapper">
    <insert id="savePublishCollect">
        insert into cc_publish_collect(tenant_id, community_id, publish_id, user_id)
        values (#{publishCollect.tenantId}, #{publishCollect.communityId}, #{publishCollect.publishId}, #{publishCollect.userId})
    </insert>
    <update id="updatePublishCollect">
        update cc_publish_collect
        set del_flag = #{publishCollect.delFlag}
        where tenant_id = #{publishCollect.tenantId}
          and community_id = #{publishCollect.communityId}
          and publish_id = #{publishCollect.publishId}
          and user_id = #{publishCollect.userId}
    </update>

    <select id="myCollectList" resultType="com.mcwl.communityCenter.domain.vo.PublishVo">
        select p.*, IF(pc.id is not null, 1, 0) as is_collect
        from cc_publish p left join cc_publish_collect pc
        on p.id = pc.publish_id
        and p.tenant_id = pc.tenant_id
        and p.community_id = pc.community_id
        <where>
            and pc.tenant_id = #{myPublishCollectPageRes.tenantId}
            and pc.community_id = #{myPublishCollectPageRes.communityId}
            and pc.user_id = #{userId}
            and pc.del_flag = '0'
        </where>
    </select>
    <select id="getPublishCollect" resultType="com.mcwl.communityCenter.domain.PublishCollect">
        select *
        from cc_publish_collect
        where tenant_id = #{publishCollectRes.tenantId}
          and community_id = #{publishCollectRes.communityId}
          and publish_id = #{publishCollectRes.publishId}
          and user_id = #{userId}
    </select>
</mapper>
