package com.community.huiju.dao;


import com.community.huiju.model.TaUserVerify;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TaUserVerifyMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(TaUserVerify record);

    int insertSelective(TaUserVerify record);

    TaUserVerify selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(TaUserVerify record);

    int updateByPrimaryKey(TaUserVerify record);

    /**
     * 根据 用户id 查询房产
     * @param userId
     * @return
     */
    List<TaUserVerify> selectByUserId(@Param("userId") Integer userId);

    /**
     * 根据 用户id、小区id 、 期、栋、单元、楼层、户号、审核状态  进行条件查询
     * @param communityId
     * @param phaseId
     * @param buildingId
     * @param unitId
     * @param levelId
     * @param roomNoId
     * @param verifyStatus
     * @return
     */
    List<TaUserVerify> selectCommunityAndAddress(@Param("userId") Integer userId,
                                           @Param("communityId") Integer communityId,
                                           @Param("phaseId") Integer phaseId,
                                           @Param("buildingId") Integer buildingId,
                                           @Param("unitId") Integer unitId,
                                           @Param("levelId") Integer levelId,
                                           @Param("roomNoId") Integer roomNoId,
                                           @Param("verifyStatus") Integer verifyStatus);



    /**
     * 根据 小区id 、 期、栋、单元、楼层、户号, 角色id(业主), 审核通过(值为1) 进行条件查询
     * @param communityId
     * @param phaseId
     * @param buildingId
     * @param unitId
     * @param levelId
     * @param roomNoId
     * @return
     */
    @ResultMap("BaseResultMap")
    @Select("select * from ta_user_verify where community_id=#{communityId}" +
            " and phase_id=#{phaseId} and building_id=#{buildingId}" +
            " and unit_id=#{unitId} and level_id=#{levelId}" +
            " and room_no_id=#{roomNoId} and role_id=1 and verify_status=1")
    TaUserVerify selectCommunityAndAddressAndRoleId(@Param("communityId") Integer communityId,
                                                    @Param("phaseId") Integer phaseId,
                                                    @Param("buildingId") Integer buildingId,
                                                    @Param("unitId") Integer unitId,
                                                    @Param("levelId") Integer levelId,
                                                    @Param("roomNoId") Integer roomNoId);


    /**
     * 根据 用户id、小区id 、 期、栋、单元、楼层、户号、审核状态(不等于2)  进行条件查询
     * @param communityId
     * @param phaseId
     * @param buildingId
     * @param unitId
     * @param levelId
     * @param roomNoId
     * @return
     */
    @ResultMap("BaseResultMap")
    @Select("select * from ta_user_verify where user_id=#{userId} and community_id=#{communityId}" +
            " and phase_id=#{phaseId} and building_id=#{buildingId}" +
            " and unit_id=#{unitId} and level_id=#{levelId}" +
            " and room_no_id=#{roomNoId} and verify_status != 2")
    List<TaUserVerify> selectCommunityAndAddressAndNotVerifyStatus2(@Param("userId") Integer userId,
                                           @Param("communityId") Integer communityId,
                                           @Param("phaseId") Integer phaseId,
                                           @Param("buildingId") Integer buildingId,
                                           @Param("unitId") Integer unitId,
                                           @Param("levelId") Integer levelId,
                                           @Param("roomNoId") Integer roomNoId);

}