package org.jeecg.modules.demo.externalinternalsite.mapper;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.demo.externalinternalsite.entity.ExternalInternalSite;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * @Description: 扫描链接表
 * @Author: jeecg-boot
 * @Date:   2023-04-03
 * @Version: V1.0
 */
@Mapper
public interface ExternalInternalSiteMapper extends BaseMapper<ExternalInternalSite> {

    @Select("select count(DISTINCT(source)) from external_internal_site where main_url =#{mainUrl} and url != #{anchorLink}")
    Integer countSourceNoAnchor(@Param("mainUrl") String mainUrl,@Param("anchorLink") String anchorLink);

    @Select("select * from external_internal_site where main_url =#{mainUrl} and url != #{anchorLink} GROUP BY source")
    IPage<ExternalInternalSite> pageSourceMainUrlNoAnchor(Page<ExternalInternalSite> page,@Param("mainUrl") String mainUrl,@Param("anchorLink") String anchorLink);



    @Select("select * from external_internal_site GROUP BY source")
    IPage<ExternalInternalSite> pageSource(Page<ExternalInternalSite> page);

    @Select("select count(DISTINCT(source)) from external_internal_site where main_url =#{mainUrl}")
    Integer countSource(@Param("mainUrl") String mainUrl);

    @Select("select count(DISTINCT(url)) from external_internal_site where main_url =#{mainUrl}  and type_url = \"外链\" ")
    Integer countSourceLinkOuter(@Param("mainUrl") String mainUrl);

    @Select("select count(DISTINCT(url)) from external_internal_site where main_url =#{mainUrl}  and state_url = \"访问异常\" ")
    Integer countSourceLinkError(@Param("mainUrl") String mainUrl);

    IPage<ExternalInternalSite> pageGroupByWai(
            Page<ExternalInternalSite> page,
            @Param("url")  String url,
            @Param("stateUrl")  String stateUrl,
            @Param("message")  String message);

    @Select("select * from external_internal_site where main_url =#{mainUrl} GROUP BY source")
    IPage<ExternalInternalSite> pageSourceMainUrl(Page<ExternalInternalSite> page, @Param("mainUrl")  String mainUrl);

    @Select("select * from external_internal_site where main_url =#{mainUrl} and state_url = \"访问异常\" GROUP BY url")
    IPage<ExternalInternalSite> pageSourceErrorMainUrl(
            Page<ExternalInternalSite> page,
            @Param("mainUrl")  String mainUrl);

    @Select("select * from external_internal_site GROUP BY  url limit #{index},#{pageSize}")
    List<ExternalInternalSite> listPage(
            @Param("index")   Integer i,
            @Param("pageSize")   Integer pageSize
    );

    @Select("select * from external_internal_site where main_url =#{mainUrl} and type_url = \"外链\" GROUP BY url")
    IPage<ExternalInternalSite> pageSourceMainUrlLinkOuter(Page<ExternalInternalSite> page, String mainUrl);

    @Select("select * from external_internal_site where type_url = \"外链\" GROUP BY url limit #{index},#{pageSize} ")
    List<ExternalInternalSite> listPageLinkOuter(
            @Param("index")   Integer i,
            @Param("pageSize")   Integer pageSize
    );
    @Select("select * from external_internal_site where state_url = \"访问异常\" GROUP BY url limit #{index},#{pageSize} ")
    List<ExternalInternalSite> listPageLinkChainError(
            @Param("index")   Integer i,
            @Param("pageSize")   Integer pageSize
    );


}
