package com.muyu.cloud.mart.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.dataformat.yaml.snakeyaml.error.Mark;
import com.muyu.cloud.mart.mapper.ShuJuMapper;
import com.muyu.cloud.mart.service.ShuJuService;
import com.muyu.cloud.mart.utils.IPLocation;
import com.muyu.cloud.mart.utils.MobileLocation;
import com.muyu.common.core.domain.Result;
import com.muyu.domain.IpPlace;
import com.muyu.domain.PhonePlace;
import com.muyu.domain.req.ShuJu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author：chaiyapeng
 * @Package：com.muyu.cloud.mart.service.impl
 * @Project：cloud-port
 * @name：ShuJuServiceImpl
 * @Date：2024/9/8 9:28
 */
@Service
public class ShuJuServiceImpl extends ServiceImpl<ShuJuMapper, ShuJu> implements ShuJuService {
    @Resource
    private ShuJuMapper shuJuMapper;
    @Override
    public Result findShuJuList(ShuJu shuJu) {
        List<ShuJu> list = shuJuMapper.findShuJuList(shuJu);
        if (list.size()==0){
            if (shuJu.getPhone()!=null){
                //如果查询不到手机号就去第三方查询
                PhonePlace phonePlace = MobileLocation.queryMobileLocation(shuJu.getPhone());
                shuJuMapper.addPhonePlace(phonePlace);
                return Result.success(phonePlace);
            }
            if (shuJu.getIp()!=null){
                //如果查询不到ip就去第三方查询
                IpPlace ipPlace = IPLocation.queryIPLocation(shuJu.getIp());
                shuJuMapper.addIpPlace(ipPlace);
                return Result.success(ipPlace);
            }
        }
        return Result.success(list);
    }
}
