package com.fs.qw.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fs.common.annotation.DataSource;
import com.fs.common.enums.DataSourceType;
import com.fs.fastGpt.domain.FastGptPushTokenTotal;
import com.fs.fastGpt.param.FastGptPushTokenDeptTotalParam;
import com.fs.fastGpt.vo.FastGptPushTokenDeptTotalVO;
import com.fs.qw.domain.QwRestrictionPushRecord;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 记录销售推送成功信息Mapper接口
 *
 * @author liupeng
 * @date 2025-08-20
 */
@Repository
public interface QwRestrictionPushRecordMapper extends BaseMapper<QwRestrictionPushRecord> {

    int insert(QwRestrictionPushRecord qwRestrictionPushRecord);
    /**
     * 查询当前销售ID对应类型的QW推送成功的记录
     *
     * @param type
     * @param startTime
     * @param endTime
     * @return
     */
    @Select("select count(id) from qw_restriction_push_record where qw_user_id=#{qwUserId} and qw_external_id=#{qwExternalId} and type=#{type} and time>#{startTime} and time<=#{endTime}")
    int selectQwRestrictionPushRecord(@Param("qwUserId") Long qwUserId,
                                      @Param("qwExternalId") Long qwExternalId,
                                      @Param("type") Integer type,
                                      @Param("startTime") Long startTime,
                                      @Param("endTime") Long endTime);

    @Select("select id from qw_restriction_push_record where time<#{time}")
    List<Long> selectExpirePushRecord(@Param("time") Long time);

    @Delete("<script>" +
            "delete from qw_restriction_push_record " +
            "where id in " +
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    public int deleteQwRestrictionPushRecordIds(@Param("ids") Long[] ids);

    @DataSource(DataSourceType.SLAVE)
    List<FastGptPushTokenTotal> selectFastgptPushTokenTotal(String dateTime);

    FastGptPushTokenTotal selectFastGptPushTokenTotalByInfo(FastGptPushTokenTotal fastGptPushTotal);

    void insertPushTokenTotal(FastGptPushTokenTotal fastGptPushTotal);

    void updatePushTokenTotal(FastGptPushTokenTotal fastGptPushTotal);

    List<FastGptPushTokenTotal> selectFastGptPushTokenTotalList(FastGptPushTokenTotal pushTokenInfo);

    List<FastGptPushTokenDeptTotalVO>  selectFastGptPushTokenTotalDeptList(FastGptPushTokenDeptTotalParam pushTokenInfo);
}

