package cn.pluss.platform.mapper;

import cn.pluss.platform.entity.UserAddress;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户地址信息表 Mapper 接口
 * </p>
 *
 * @author bzg
 * @since 2021-11-17
 */
public interface UserAddressMapper extends BaseMapper<UserAddress> {


    default List<UserAddress> getAddressList(Long userId, Integer type, boolean defFlag){
        if(defFlag){
            return getDefaultAddressList(userId,type, UserAddress.DEFAULT_FLAG);
        }else{
            return getAddressList(userId,type);
        }
    }

    @Select("select * from tb_pluss_user_address where userId = #{userId} and type = #{type} order by defFlag desc,id desc")
    List<UserAddress> getAddressList(@Param("userId") Long userId, @Param("type") Integer type);

    @Select("select * from tb_pluss_user_address where userId = #{userId} and type = #{type} and defFlag = #{defFlag} order by id desc")
    List<UserAddress> getDefaultAddressList(@Param("userId") Long userId, @Param("type") Integer type,@Param("defFlag") String defFlag);
}
