package com.fzm.mall.server.front.user.mapper;

import com.fzm.mall.server.front.user.model.MailAddress;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fzm.mall.server.front.user.model.vo.AddrVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 用户收货地址表 Mapper 接口
 * </p>
 *
 * @author fzm
 * @since 2021-03-30
 */
public interface MailAddressMapper extends BaseMapper<MailAddress> {
    @Update("update user_mail_address set default_addr = 2 where uid = #{uid} and status = 1")
    void updateNotDefault(@Param("uid") String uid);

    @Select("select a.* ,b.name as province,c.name as city,d.name as county,e.name as street from user_mail_address a left join dict_cn_province b on a.province_code = b.code" +
            "  left join dict_cn_city c on a.city_code = c.code left join dict_cn_county d on a.county_code = d.code left join dict_cn_street e on a.street_code = e.code where a.uid = #{uid} and status = 1 order by a.default_addr asc")
    List<AddrVo> getListByUid(@Param("uid") String uid);

    @Update("update user_mail_address set status = 2 where uid = #{uid} and id = #{id}")
    void deleteByIdAndUid(@Param("id") Integer id, @Param("uid") String uid);
}
