package com.fs.his.mapper;

import java.util.List;
import com.fs.his.domain.FsUserAddress;
import com.fs.his.param.FsUserParam;
import com.fs.his.vo.FsUserVO;
import com.fs.his.vo.UserVo;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 用户地址Mapper接口
 *
 * @author fs
 * @date 2023-07-03
 */
public interface FsUserAddressMapper
{
    /**
     * 查询用户地址
     *
     * @param addressId 用户地址主键
     * @return 用户地址
     */
    public FsUserAddress selectFsUserAddressByAddressId(Long addressId);

    /**
     * 查询用户地址列表
     *
     * @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 addressId 用户地址主键
     * @return 结果
     */
    public int deleteFsUserAddressByAddressId(Long addressId);

    /**
     * 批量删除用户地址
     *
     * @param addressIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsUserAddressByAddressIds(Long[] addressIds);

    @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_default=0 where user_id=#{userId} ")
    int clearIsDefalut(long userId);

    @Select("select user_id id,CONCAT_WS('-',nick_name) `name` from fs_user  where  phone =#{name} ")
    List<UserVo> selectUserVOList(String name);

    @Select("select * from fs_user_address where user_id=#{userId} and  is_del=0 and is_default=1 limit 1 ")
    FsUserAddress selectFsUserAddressByDefault(long userId);
    @Select({"<script>select count(1) fs_user_address" +
            "and is_del = 0\n" +
            "            <if test=\"userId != null \"> and user_id = #{userId}</if>\n" +
            "            <if test=\"realName != null  and realName != ''\"> and real_name like concat('%', #{realName}, '%')</if>\n" +
            "            <if test=\"phone != null  and phone != ''\"> and phone = #{phone}</if>\n" +
            "            <if test=\"province != null  and province != ''\"> and province = #{province}</if>\n" +
            "            <if test=\"city != null  and city != ''\"> and city = #{city}</if>\n" +
            "            <if test=\"district != null  and district != ''\"> and district = #{district}</if>\n" +
            "            <if test=\"cityIds != null  and cityIds != ''\"> and city_ids = #{cityIds}</if>\n" +
            "            <if test=\"detail != null  and detail != ''\"> and detail = #{detail}</if>\n" +
            "            <if test=\"postCode != null  and postCode != ''\"> and post_code = #{postCode}</if>\n" +
            "            <if test=\"longitude != null  and longitude != ''\"> and longitude = #{longitude}</if>\n" +
            "            <if test=\"latitude != null  and latitude != ''\"> and latitude = #{latitude}</if>\n" +
            "            <if test=\"isDefault != null \"> and is_default = #{isDefault}</if>" +
            "</script>"})
    Long selectFsUserAddressListCount(FsUserAddress fsUserAddress);
}
