package com.fs.store.mapper;

import java.util.List;
import com.fs.store.domain.FsUserAddress;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 用户地址Mapper接口
 *
 * @author fs
 * @date 2022-03-15
 */
public interface FsUserAddressMapper
{
    /**
     * 查询用户地址
     *
     * @param id 用户地址ID
     * @return 用户地址
     */
    public FsUserAddress selectFsUserAddressById(Long id);

    /**
     * 查询用户地址列表
     *
     * @param fsUserAddress 用户地址
     * @return 用户地址集合
     */
    public List<FsUserAddress> selectFsUserAddressList(FsUserAddress fsUserAddress);

    /**
     * 新增用户地址
     *
     * @param fsUserAddress 用户地址
     * @return 结果
     */
    public int insertFsUserAddress(FsUserAddress fsUserAddress);

    /**
     * 修改用户地址
     *
     * @param fsUserAddress 用户地址
     * @return 结果
     */
    public int updateFsUserAddress(FsUserAddress fsUserAddress);

    /**
     * 删除用户地址
     *
     * @param id 用户地址ID
     * @return 结果
     */
    public int deleteFsUserAddressById(Long id);

    /**
     * 批量删除用户地址
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    public int deleteFsUserAddressByIds(Long[] ids);
    @Select("select * from fs_user_address where user_id=#{uid} and is_default=1 and is_del=0 limit 1")
    FsUserAddress selectFsUserAddressByDefaultAddress(long uid);
    @Update("update fs_user_address set is_default=0 where user_id=#{userId}")
    int clearIsDefalut(long userId);
    @Select("select IFNULL(count(1),0) from fs_user_address where user_id=#{userId}  and is_del=0 " )
    Integer selectFsUserAddressCountsByUserId(long userId);
    @Update(" update fs_user_address set is_del=1 where user_id = #{userId}")
    Integer delAllAddress(Long userId);
    @Select("select city_id from fs_city where name=#{city} and level = 1 limit 1 ")
    Long selectFsUserAddressByCityName(String city);
    @Select("select id,city from fs_user_address where city_id is  null  ")
    List<FsUserAddress> deleteFsUserAddressByCityIdIsNull();

}
