package cn.pluss.platform.ys.impl;

import cn.pluss.platform.entity.SubMercCodeYs;
import cn.pluss.platform.ipLocation.IpLocationService;
import cn.pluss.platform.mapper.SubMercCodeYsMapper;
import cn.pluss.platform.ys.SubMercCodeYsService;
import com.aliyuncs.geoip.model.v20200101.DescribeIpv4LocationResponse;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 银盛二级商户省市区code 服务实现类
 * </p>
 *
 * @author crystal
 * @since 2022-06-15
 */
@Service
@Slf4j
public class SubMercCodeYsServiceImpl extends ServiceImpl<SubMercCodeYsMapper, SubMercCodeYs> implements SubMercCodeYsService {

    @Autowired
    @Qualifier("ipLocationService")
    private IpLocationService ipLocationService;

    @Override
    public SubMercCodeYs getSubCodeByIp(String ip) {
        DescribeIpv4LocationResponse response = ipLocationService.getLocation(ip);
        if(response == null){
            return null;
        }
        return  baseMapper.getSubMercCodeYsByCity(response.getCity());
    }
}
