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

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.muyu.cloud.mart.utils.*;
import com.muyu.cloud.mart.mapper.MarketMapper;
import com.muyu.cloud.mart.service.MarketService;
import com.muyu.common.core.domain.Result;
import com.muyu.domain.*;
import com.muyu.domain.res.BirthdayRes;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import static com.muyu.cloud.mart.config.IPLocation.params;
import static com.muyu.common.core.utils.PageUtils.startPage;

/**
 * @Author：chaiyapeng
 * @Package：com.muyu.cloud.etl.service.impl
 * @Project：cloud-mart
 * @name：MarketServiceImpl
 * @Date：2024/8/21 21:54
 */
@Service
@Log4j2
public class MarketServiceImpl extends ServiceImpl<MarketMapper, Market> implements MarketService {

    @Autowired
    private MarketMapper marketMapper;
    @Autowired
    private RedisTemplate<String,String>redisTemplate;




    /**
     * 手机号查询归属地
     * @param tel
     */
    @Override
    public Result phonePlace(String tel) {
        PhonePlace phonePlace = MobileLocation.queryMobileLocation(tel);
//        Integer resultInt =marketMapper.addPhonePlace(phonePlace);
        return Result.success(phonePlace);
    }

    /**
     * IP查询归属地
     * @param ip
     * @return
     */
    @Override
    public Result getIpPlace(String ip) {
        IpPlace ipPlace = IPLocation.queryIPLocation(ip);
//        marketMapper.addIpPlace(ipPlace);
        return Result.success(ipPlace);
    }
    /**
     * 新闻头条
     * @return
     */
    @Override
    public Result getHeadlines() {
        List<News> list = Headlines.queryHeadlines();
        return Result.success(list);
    }
    /**
     * 气象预警
     */
    @Override
    public Result getWeather() {
        List<Weather> weathers = WeatherInquire.queryWeather();
        return Result.success(weathers);
    }
    /**
     * 生辰助手
     */
    @Override
    public Result getBirthday(BirthdayRes birthdayRes) {
        Birthday birthday1 = BirthdayHelper.queryBirthday(birthdayRes);
        return Result.success(birthday1);
    }
    /**
     * 邮编查询
     */
    @Override
    public Result getPostcode(String code) {
        List<Postcode> list = PostcodeInquire.queryPostcode(code);
        return Result.success(list);
    }
    /**
     * 天气预报
     */
    @Override
    public Result getWeatherForecast(String cityName) {
        WeatherForecast weatherForecast = WeatherForecastInquire.queryWeather(cityName);
        return Result.success(weatherForecast);
    }

    @Override
    public Result realName(IdCard idCard) {
        IdCard idCard1 = IdCardInquire.queryIdCard(idCard);
        if (idCard1.getName()==null || idCard1.getIdCard()==null){
            return Result.error("身份证或姓名有误");
        }
//        marketMapper.addIdCard(idCard1);
        return Result.success(idCard1);
    }
}
