package com.huiju.estateagents.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huiju.estateagents.entity.TaBuilding;
import com.huiju.estateagents.entity.TaPersonBuilding;
import com.huiju.estateagents.excel.StatsBuilding;
import com.huiju.estateagents.excel.StatsTimeBuilding;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

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

/**
 * <p>
 * 项目表 Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2019-05-10
 */
@Mapper
public interface TaBuildingMapper extends BaseMapper<TaBuilding> {
    /**
     * 楼盘列表
     * @param page
     * @return
     */
    List<TaBuilding> buildingList(IPage<TaBuilding> page, @Param("Name") String name, @Param("Code")String code,@Param("startDate")LocalDateTime startDate, @Param("buildingStatus")String buildingStatus, @Param("marketStatus")String marketStatus, @Param("cityId")Integer cityId, @Param("isMain")Integer isMain, @Param("orgId") Integer orgId,@Param("personBuildingList") List<TaPersonBuilding> personBuildingList);

    /**
     * 楼盘列表
     * @param
     * @return
     */
    List<TaBuilding> buildingListSelect(@Param("Name") String name, @Param("Code") String code, @Param("startDate") LocalDateTime startDate, @Param("buildingStatus") String buildingStatus, @Param("marketStatus") String marketStatus, @Param("cityId") Integer cityId, @Param("isMain") Integer isMain, @Param("orgId") Integer orgId, @Param("personBuildingList") List<TaPersonBuilding> personBuildingList);


    @Update("UPDATE ta_building  SET ${field} = IFNULL(${field}, 0) + #{increment}  WHERE building_id = #{buildingId}")
    void setFieldNum(@Param("buildingId") String buildingId, @Param("field") String field, @Param("increment") int increment);

    List<TaBuilding> buildingAll(@Param("orgId") Integer orgId);

    List<TaBuilding> getBuildingListById(@Param("orgId") Integer orgId,@Param("cityId") Integer cityId);
    /**
     * 查询当前楼盘
     * @param buildingId
     * @return
     */
    TaBuilding selectBuilding(@Param("buildingId") String buildingId);

    /**
     * 转化率 项目收藏 / 项目分享
     * @return
     */
    Map<String, Object> selectBuildingStatistical(@Param("orgId")Integer orgId, @Param("saveOrShare") String saveOrShare);

    /**
     * 查询楼盘
     * @param page
     * @param name
     * @param cityId
     * @param targets
     * @param houseTypeList
     * @param buildingTypeList
     * @param priceList
     * @param areaList
     * @return
     */
    IPage<TaBuilding> selectBuildingPage(IPage<TaBuilding> page,
                                         @Param("name") String name,
                                         @Param("cityId") Integer cityId,
                                         @Param("targets") List<String> targets,
                                         @Param("houseTypeList") String[] houseTypeList,
                                         @Param("buildingTypeList") String[] buildingTypeList,
                                         @Param("priceList") List<String[]> priceList,
                                         @Param("areaList") List<String[]> areaList,
                                         @Param("orgId")Integer orgId,
                                         @Param("priceType") String priceType);

    /**
     * 根据项目类型Id 查询
     * @param buildingTypeId
     * @return
     */
    List<TaBuilding> selectBuildingByBuildingTypeId(Integer buildingTypeId);

    /**
     * 根据权重统计该权重是否存在
     * @return
     */
    int countNumByHeavy(@Param("heavy") Integer heavy, @Param("dynamicId") String dynamicId);

    List<TaBuilding> selectMainBuildings(@Param("cityId") String cityId, @Param("orgId") Integer orgId);

    /**
     * 获取公客统计图数据
     * @param orgId
     * @param startDate
     * @param endDate
     * @param personBuildingList
     * @return
     */
    List<Map<String, Object>> getGkBarData(@Param("orgId") Integer orgId,@Param("startDate") LocalDate startDate,@Param("endDate") LocalDate endDate,@Param("personBuildingList") List<TaPersonBuilding> personBuildingList);

    /**
     * 获取私客统计图数据
     * @param orgId
     * @param startDate
     * @param endDate
     * @param personBuildingList
     * @return
     */
    List<Map<String, Object>> getSkBarData(@Param("orgId") Integer orgId,@Param("startDate") LocalDate startDate,@Param("endDate") LocalDate endDate,@Param("personBuildingList") List<TaPersonBuilding> personBuildingList);

    /**
     * 项目访问人数排行折线图获取
     * @param orgId
     * @param startDate
     * @param endDate
     * @param personBuildingList
     * @return
     */
    List<Map<String, Object>> getWgBarData(@Param("orgId") Integer orgId,@Param("startDate") LocalDate startDate,@Param("endDate") LocalDate endDate,@Param("personBuildingList") List<TaPersonBuilding> personBuildingList);

    /**
     * 项目访问次数排行折线图获取
     * @param orgId
     * @param startDate
     * @param endDate
     * @param personBuildingList
     * @return
     */
    List<Map<String, Object>> getFwBarData(@Param("orgId") Integer orgId,@Param("startDate") LocalDate startDate,@Param("endDate") LocalDate endDate,@Param("personBuildingList") List<TaPersonBuilding> personBuildingList);

    /**
     * 获取项目统计列表数据
     * @param orgId
     * @param startDate
     * @param endDate
     * @param buildingId
     * @param personBuildingList
     * @return
     */
    IPage<StatsBuilding> getStatsTableList(IPage<StatsBuilding> page, @Param("orgId") Integer orgId, @Param("startDate")  LocalDate startDate, @Param("endDate")  LocalDate endDate, @Param("buildingId") String buildingId, @Param("personBuildingList") List<TaPersonBuilding> personBuildingList,@Param("sortField") String sortField,@Param("orderType") String orderType);

    /**
     * 获取导出的数据
     * @param orgId
     * @param startDate
     * @param endDate
     * @param buildingId
     * @param personBuildingList
     * @return
     */
    List<StatsBuilding> getExportTableList(@Param("orgId") Integer orgId, @Param("startDate")  LocalDate startDate, @Param("endDate")  LocalDate endDate, @Param("buildingId") String buildingId, @Param("personBuildingList") List<TaPersonBuilding> personBuildingList);

    /**
     * 获取单独building的折线图数据
     * @param orgId
     * @param startDate
     * @param endDate
     * @param buildingId
     * @return
     */
    List<StatsTimeBuilding> getStatsTimeBarList(@Param("orgId") Integer orgId,@Param("startDate") LocalDate startDate,@Param("endDate") LocalDate endDate,@Param("buildingId") String buildingId, @Param("buildingName") String buildingName);

    /**
     * 获取详情数据表格
     * @param pg
     * @param orgId
     * @param startDate
     * @param endDate
     * @param buildingId
     * @param sortField
     * @param orderType
     * @return
     */
    IPage<StatsTimeBuilding> getStatsTimeTableList(IPage<StatsTimeBuilding> pg,@Param("orgId") Integer orgId,@Param("startDate") LocalDate startDate,@Param("endDate") LocalDate endDate,@Param("buildingId") String buildingId,@Param("sortField") String sortField,@Param("orderType") String orderType);
}
