package com.yunzhi.marketing.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunzhi.marketing.entity.TaPerson;
import com.yunzhi.marketing.entity.TsConsultantKpi;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunzhi.marketing.excel.ConsultantKPIExport;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 置业顾问KPI  Mapper 接口
 * </p>
 *
 * @author yansen
 * @since 2020-04-14
 */
@Mapper
public interface TsConsultantKpiMapper extends BaseMapper<TsConsultantKpi> {

    /**
     * 置业KPI 汇总
     * bug #6929 要求跟时间没关系
     * @param page
     * @param orgId
     * @param buildingIds
     * @param startDate
     * @param endDate
     * @param asc
     * @param desc
     * @return
     */
    IPage<TsConsultantKpi> stsKPIDaily(IPage<TsConsultantKpi> page,
                                       @Param("orgId") Integer orgId,
                                       @Param("buildingIds") List<String> buildingIds,
                                       @Param("startDate") String startDate,
                                       @Param("endDate") String endDate,
                                       @Param("asc") String asc,
                                       @Param("desc") String desc);

    TsConsultantKpi stsKPITotalByOrg(@Param("orgId") Integer orgId,
                                     @Param("buildingIds") List<String> buildingIds,
                                     @Param("startDate") String startDate,
                                     @Param("endDate") String endDate);

    List<ConsultantKPIExport> stsKPIDailyExport(@Param("orgId") Integer orgId,
                                                @Param("buildingIds") List<String> buildingIds,
                                                @Param("startDate") String startDate,
                                                @Param("endDate") String endDate);

    /**
     * 统计当前时间段内的, 已经固化的置业数据的所有客户
     * bug #6929 要求跟时间没关系
     * @param orgId
     * @param buildingIds
     * @param startDate
     * @param endDate
     * @return
     */
    Integer stsAllCustomersByOrg(@Param("orgId") Integer orgId,
                                 @Param("buildingIds") List<String> buildingIds,
                                 @Param("startDate") String startDate,
                                 @Param("endDate") String endDate);


    /**
     * 获取置业分享拓客
     * buildingId 暂时没有用到
     * @param page
     * @param orgId
     * @param userId
     * @param buildingId
     * @param startDate
     * @param endDate
     * @return
     */
    IPage<TaPerson> getConsultantShareCustomers(IPage<TaPerson> page,
                                              @Param("orgId") Integer orgId,
                                              @Param("userId") String userId,
                                              @Param("buildingId") String buildingId,
                                              @Param("startDate") LocalDateTime startDate,
                                              @Param("endDate") LocalDateTime endDate);

    /**
     * 置业卡片访问人数明细
     * @param page
     * @param orgId
     * @param userId
     * @param buildingId
     * @param startDate
     * @param endDate
     * @return
     */
    IPage<TaPerson> getConsultantHomePagePersons(IPage<TaPerson> page,
                                                 @Param("orgId") Integer orgId,
                                                 @Param("userId") String userId,
                                                 @Param("buildingId") String buildingId,
                                                 @Param("startDate") LocalDateTime startDate,
                                                 @Param("endDate") LocalDateTime endDate);

    /**
     * 置业卡片访问次数明细
     * @param page
     * @param orgId
     * @param userId
     * @param buildingId
     * @param startDate
     * @param endDate
     * @return
     */
    IPage<TaPerson> getConsultantHomePageTimes(IPage<TaPerson> page,
                                               @Param("orgId") Integer orgId,
                                               @Param("userId") String userId,
                                               @Param("buildingId") String buildingId,
                                               @Param("startDate") LocalDateTime startDate,
                                               @Param("endDate") LocalDateTime endDate,
                                               @Param("personId") String personId);

    /**
     * 咨询置业人员
     * @param page
     * @param orgId
     * @param userId
     * @param buildingId
     * @param startDate
     * @param endDate
     * @return
     */
    IPage<TaPerson> getConsultantChatPersons(IPage<TaPerson> page,
                                             @Param("orgId") Integer orgId,
                                             @Param("userId") String userId,
                                             @Param("buildingId") String buildingId,
                                             @Param("startDate") LocalDateTime startDate,
                                             @Param("endDate") LocalDateTime endDate);

    /**
     * 点赞详情
     * @param page
     * @param orgId
     * @param userId
     * @param buildingId
     * @param startDate
     * @param endDate
     * @return
     */
    IPage<TaPerson> getConsultantFavor(IPage<TaPerson> page,
                                       @Param("orgId") Integer orgId,
                                       @Param("userId") String userId,
                                       @Param("buildingId") String buildingId,
                                       @Param("startDate") LocalDateTime startDate,
                                       @Param("endDate") LocalDateTime endDate);


    /**
     * 置业分享记录
     * @param page
     * @param orgId
     * @param userId
     * @param buildingId
     * @param startDate
     * @param endDate
     * @param targetType
     * @param targetName
     * @return
     */
    IPage<TaPerson> getConsultantShareTargets(IPage<TaPerson> page,
                                                  @Param("orgId") Integer orgId,
                                                  @Param("userId") String userId,
                                                  @Param("buildingId") String buildingId,
                                                  @Param("startDate") LocalDateTime startDate,
                                                  @Param("endDate") LocalDateTime endDate,
                                                  @Param("targetType") String targetType,
                                                  @Param("targetName") String targetName);

    /**
     * 置业分享访问人
     * @param page
     * @param orgId
     * @param userId
     * @param buildingId
     * @param startDate
     * @param endDate
     * @return
     */
    IPage<TaPerson> getConsultantSharePersons(IPage<TaPerson> page,
                                              @Param("orgId") Integer orgId,
                                              @Param("userId") String userId,
                                              @Param("buildingId") String buildingId,
                                              @Param("startDate") LocalDateTime startDate,
                                              @Param("endDate") LocalDateTime endDate);

    /**
     * 置业分享访问明细
     * @param page
     * @param orgId
     * @param userId
     * @param buildingId
     * @param startDate
     * @param endDate
     * @param targetType
     * @param targetName
     * @return
     */
    IPage<TaPerson> getConsultantShareTimes(IPage<TaPerson> page,
                                            @Param("orgId") Integer orgId,
                                            @Param("userId") String userId,
                                            @Param("buildingId") String buildingId,
                                            @Param("startDate") LocalDateTime startDate,
                                            @Param("endDate") LocalDateTime endDate,
                                            @Param("targetType") String targetType,
                                            @Param("targetName") String targetName,
                                            @Param("userName") String userName,
                                            @Param("personId") String personId);
}
