package com.huiju.estateagents.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huiju.estateagents.entity.TaBuildingApartment;
import com.huiju.estateagents.entity.TaHousingResources;
import com.huiju.estateagents.entity.TaSalesBatch;
import com.huiju.estateagents.po.TaHousingResourcesPO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 房源表  Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2020-02-10
 */
@Mapper
@Component
public interface TaHousingResourcesMapper extends BaseMapper<TaHousingResources> {

    /**
     * 分页获取房源列表
     *
     * @param salesBatchId
     * @param startPrice
     * @param endPrice
     * @param apartmentId
     * @return
     */
    List<TaHousingResourcesPO> listHousingResources(@Param("orgId") Integer orgId,
                                                    @Param("salesBatchId") String salesBatchId,
                                                    @Param("startPrice") String startPrice,
                                                    @Param("endPrice") String endPrice,
                                                    @Param("apartmentId") String apartmentId,
                                                    @Param("personId") String personId,
                                                    @Param("source") String source);

    /**
     * 分页获取房源列表
     *
     * @param salesBatchId
     * @param startPrice
     * @param endPrice
     * @param apartmentId
     * @param type         为1只展示已发布的房源
     * @return
     */
    List<TaHousingResourcesPO> listHousingResourcesForCms(@Param("orgId") Integer orgId,
                                                          @Param("salesBatchId") String salesBatchId,
                                                          @Param("startPrice") String startPrice,
                                                          @Param("endPrice") String endPrice,
                                                          @Param("apartmentId") String apartmentId,
                                                          @Param("type") Integer type);

    /**
     * 获取某销售批次下所有房源户型
     *
     * @param salesBatchId
     * @return
     */
    List<TaBuildingApartment> listBuildApartmentBySalesBatchId(@Param("salesBatchId") String salesBatchId);

    /**
     * 增加热度值
     *
     * @param houseId
     * @return
     */
    Boolean updateForAddHeat(@Param("houseId") Integer houseId);

    /**
     * 减少热度值
     *
     * @param houseId
     * @return
     */
    Boolean updateForSubtractHeat(@Param("houseId") Integer houseId);

    /**
     * 减少认筹热度值
     * @param raiseRecordId
     * @return
     */
    Boolean updateForSubtractRaiseHeat(@Param("raiseRecordId") Integer raiseRecordId);

    /**
     * 更新房源锁定状态
     *
     * @param raiseRecordId
     * @param houseLockingStatus
     * @return
     */
    Boolean updateHouseLockingStatus(@Param("raiseRecordId") Integer raiseRecordId,
                                     @Param("houseLockingStatus") String houseLockingStatus,
                                     @Param("personId") String personId);

    /**
     * 根据房源ID获取房源详情
     *
     * @param houseId
     * @param type    是否只查询已发布数据，1是 0否
     * @return
     */
    TaHousingResourcesPO getHousingDetailById(@Param("houseId") Integer houseId,
                                              @Param("type") String type);

    /**
     * 分页获取数据
     *
     * @param pg
     * @param salesBatchId
     * @param buildingId
     * @param orgId
     * @param termName
     * @param blockName
     * @param unitName
     * @param floorName
     * @param roomNamesa
     * @param apartmentId
     * @param status
     * @param houseId
     * @return
     */
    IPage<TaHousingResources> getHouseResourceList(IPage<TaHousingResources> pg, @Param("salesBatchId") Integer salesBatchId, @Param("buildingId") String buildingId,
                                                   @Param("orgId") Integer orgId, @Param("termName") String termName, @Param("blockName") String blockName,
                                                   @Param("unitName") String unitName, @Param("floorName") String floorName, @Param("roomName") String roomName,
                                                   @Param("apartmentId") String apartmentId, @Param("status") Integer status, @Param("houseId") String houseId,
                                                   @Param("lockingStatus") String lockingStatus,@Param("actulStartHot") String actulStartHot,@Param("actulEndHot") String actulEndHot);

    List<TaHousingResources> selectHousingList(@Param("orgId") Integer orgId, @Param("taSalesBatchList") List<TaSalesBatch> taSalesBatchList);

    /**
     * 批量更新房源认筹基础认读
     *
     * @param housingResourcesList
     * @param raiseHeat
     * @param salesBatchId
     * @param orgId
     * @return
     */
    Integer batchUpdateRaiseHeat(@Param("housingResourcesList") List<TaHousingResources> housingResourcesList,
                                 @Param("raiseHeat") Integer raiseHeat,
                                 @Param("updateUser") Integer updateUser,
                                 @Param("salesBatchId") Integer salesBatchId,
                                 @Param("orgId") Integer orgId);

    /**
     * 批量更新房源认筹基础热度
     *
     * @param housingResourcesList
     * @param heat
     * @param salesBatchId
     * @param orgId
     * @return
     */
    Integer batchUpdateHeat(@Param("housingResourcesList") List<TaHousingResources> housingResourcesList,
                            @Param("heat") Integer heat,
                            @Param("updateUser") Integer updateUser,
                            @Param("salesBatchId") Integer salesBatchId,
                            @Param("orgId") Integer orgId);

    /**
     * 根据认筹单ID查询房源列表
     *
     * @param pg
     * @param raiseRecordId
     * @param orgId
     * @return
     */
    IPage<TaHousingResourcesPO> listHouseByRaiseRecordId(IPage<TaHousingResourcesPO> pg,
                                                         @Param("raiseRecordId") Integer raiseRecordId,
                                                         @Param("orgId") Integer orgId);

    /**
     * 根据认筹房源关联表ID查询房源信息
     *
     * @param orgId
     * @param raiseHouseId
     * @return
     */
    TaHousingResourcesPO getHouseByRaiseHouseId(@Param("orgId") Integer orgId,
                                                @Param("raiseHouseId") Integer raiseHouseId);
}
