package com.yunzhi.marketing.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunzhi.marketing.entity.TaConsultantInfo;
import com.yunzhi.marketing.entity.TaPersonBuilding;
import com.yunzhi.marketing.entity.TaPersonVisitRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

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

/**
 * <p>
 *   Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2019-07-23
 */
@Mapper
public interface TaPersonVisitRecordMapper extends BaseMapper<TaPersonVisitRecord> {

    IPage<TaPersonVisitRecord> visitRecordByPersonId(IPage<TaPersonVisitRecord> page,@Param("personId") String personId,@Param("personBuildingList") List<TaPersonBuilding> personBuildingList,@Param("buildingId") String buildingId);

    Integer getDurationByPersonId(@Param("personId") String personId);

    LocalDateTime getFirstVisitTimeByPersonId(@Param("personId") String personId);

    /**
     * 行为分析的 列表
     * @param page
     * @return
     */
    IPage<TaPersonVisitRecord> selectAll(IPage<TaPersonVisitRecord> page,
                                         @Param("startDate") LocalDate startDate,
                                         @Param("endDate")LocalDate endDate,
                                         @Param("buildingId") String buildingId,
                                         @Param("eventType") String eventType,
                                         @Param("event") String event,
                                         @Param("activity") String activity,
                                         @Param("orgId") Integer orgId);


    /**
     * 行为分析的 具体数据
     *
     * @return
     */
    @ResultType(TaPersonVisitRecord.class)
    @Select("select * from ta_person_visit_record where event = #{event} and person_id = #{personId} and org_id = #{orgId} ")
    List<TaPersonVisitRecord> selectEventAll(@Param("event") String event, @Param("personId") String personId, @Param("orgId") Integer orgId);
    
    
    /**
     * 获取用户行为列表
     * @param pg
     * @param personId
     * @return
     */
	IPage<TaPersonVisitRecord> getPersonVisitRecordList(IPage<TaPersonVisitRecord> pg,@Param("personId") String personId);

    /**
     * 获取引流信息访问记录
     * @param pg
     * @param orgId
     * @return
     */
	IPage<TaPersonVisitRecord> getDrainageVisitRecord(IPage<TaPersonVisitRecord> pg, @Param("orgId") Integer orgId, @Param("activityName") String activityName, @Param("eventType") String eventType, @Param("shareName") String shareName, @Param("shareTel") String shareTel, @Param("buildingId") String buildingId, @Param("personType") String personType, @Param("personBuildingList") List<TaPersonBuilding> personBuildingList);

    IPage<TaPersonVisitRecord> getWxVisitRecordList(IPage<TaPersonVisitRecord> pg, @Param("userId") Integer userId, @Param("orgId") Integer orgId, @Param("eventType") String eventType,@Param("personId") String personId);

    IPage<TaPersonVisitRecord> getWxActivityVisitRecordList(IPage<TaPersonVisitRecord> pg, @Param("userId") Integer userId, @Param("orgId") Integer orgId, @Param("targetId") String targetId,@Param("personId") String personId, @Param("eventType")String eventType);

    IPage<TaPersonVisitRecord> getWxVisitRecordActivityList(IPage<TaPersonVisitRecord> pg, @Param("userId") Integer userId,@Param("personId") String personId,@Param("orgId") Integer orgId,@Param("eventType") String eventType);

    IPage<TaConsultantInfo> getConsultantShareInfoList(IPage<TaConsultantInfo> pg, @Param("personId") String personId);

    Integer countShareNumByEventType(@Param("orgId")Integer orgId, @Param("targetId") String targetId, @Param("userId")Integer userId, @Param("personId")String personId, @Param("eventType")String eventType);

    List<TaPersonVisitRecord> selectData();

    List<TaPersonVisitRecord> selectTapersonFromShare();

    Integer selectTodayVisitCount(@Param("orgId") Integer orgId,@Param("nowDate") LocalDateTime now);
}
