package cn.com.ty.lift.ud.userCollect.mapper;


import cn.com.ty.lift.ud.userCollect.controller.query.UserCollectQuery;
import cn.com.ty.lift.ud.userCollect.mapper.entity.*;
import cn.com.ty.lift.ud.userCollect.mapper.entity.*;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * 我的收藏 -Repository
 * 
 * @author Xson
 * @date 2020-04-28
 */
public interface UserCollectMapper extends BaseMapper<UserCollectEntity> {

    /**
     *  查看是否被收藏过
     * @param userId  用户ID
     * @param collectType 收集类型
     * @param infoId  内容ID
     * @return
     */
    @Select("select * from user_collect where user_id = #{userId} and collect_type = #{collectType} and info_id  = #{infoId}")
    UserCollectEntity isCollect(@Param("userId") Long userId,@Param("collectType") Integer collectType,@Param("infoId") Long infoId);

    @Delete("delete from user_collect where user_id = #{userId} and collect_type = #{type} and info_id  = #{dataId}")
    void deleteByUserAndDataId(@Param("userId")Long userId,@Param("dataId") Long dataId,@Param("type") int type);

    /**
     * 查询收藏的问题
     *
     * @param condition
     * @param page
     * @param uId
     * @return
     */
    List<UserCollectQuestionVo> selectQuestionById(@Param("ew") Wrapper condition, @Param("page") UserCollectQuery page
            , @Param("uId") Long uId);

    /**
     * 查询收藏的问题总数量
     *
     * @param condition
     * @return
     */
    int countQuestionById(@Param("ew") Wrapper condition, @Param("uId") Long uId);


    /**
     * 查询我收藏的视频
     *
     * @param condition
     * @param page
     * @return
     */
    List<UserCollectSchoolVideoVo> selectSchoolVideoById(@Param("ew") Wrapper condition, @Param("page") UserCollectQuery page
            , @Param("uId") Long uId);

    /**
     * 查询我收藏的视频的总数量
     *
     * @param condition
     * @return
     */
    int countSchoolVideoById(@Param("ew") Wrapper condition, @Param("uId") Long uId);


    /**
     * 查询我收藏的职位
     *
     * @param condition
     * @param page
     * @return
     */
    List<UserCollectRecruitmentInfoVo> selectRecruitmentInfoById(@Param("ew") Wrapper condition, @Param("page") UserCollectQuery page
            , @Param("uId") Long uId);

    /**
     * 查询我收藏的职位的总数量
     *
     * @param condition
     * @return
     */
    int countRecruitmentInfoById(@Param("ew") Wrapper condition, @Param("uId") Long uId);



    /**
     * 查询我收藏的商品
     *
     * @param condition
     * @param page
     * @return
     */
    List<UserCollectShoppingVo> selectShoppingById(@Param("ew") Wrapper condition, @Param("page") UserCollectQuery page
            , @Param("uId") Long uId);

    /**
     * 查询我收藏的商品的总数量
     *
     * @param condition
     * @return
     */
    int countShoppingById(@Param("ew") Wrapper condition, @Param("uId") Long uId);

    List<UserCollectAttachmentFileVo> selectAttachmentFileById(UserCollectQuery query);
    int countAttachmentFileById(UserCollectQuery query);
    /**
     * 删除信息
     * @param userCollectEntity
     */
    @Delete("delete from user_collect where info_id = #{co.infoId} and collect_type = #{co.collectType}" +
            "  and user_id = #{co.userId}")
    void noCollect(@Param("co")UserCollectEntity userCollectEntity);

    /**
     * 根据数据ID 和 类型删除
     * @param dataId
     * @param type
     */
    @Delete("delete from user_collect where collect_type = #{type} and info_id  = #{dataId}")
    void deleteByTypeAndDataId(@Param("dataId") Long dataId,@Param("type") Integer type);
}
