IP查询归属地
parent
5032bcc26e
commit
6d4f0c67b9
|
@ -40,20 +40,7 @@ public class MarketController extends BaseController {
|
|||
*/
|
||||
@GetMapping("findMarketList")
|
||||
public Result<TableDataInfo<Market>> findMarketList(){
|
||||
if (redisTemplate.hasKey("list")){
|
||||
List<String> list = redisTemplate.opsForList().range("list", 0, -1);
|
||||
ArrayList<Market> markets = new ArrayList<>();
|
||||
for (String s : list) {
|
||||
markets.add(JSON.parseObject(s, Market.class));
|
||||
}
|
||||
return getDataTable(markets);
|
||||
}
|
||||
|
||||
startPage();
|
||||
List<Market> list = marketService.findMarketList();
|
||||
for (Market market1 : list) {
|
||||
redisTemplate.opsForList().rightPush("list", JSON.toJSONString(market1));
|
||||
}
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
|
@ -71,5 +58,12 @@ public class MarketController extends BaseController {
|
|||
public Result getIpPlace(@RequestParam(name = "ip") String ip){
|
||||
return marketService.getIpPlace(ip);
|
||||
}
|
||||
/**
|
||||
* 新闻头条
|
||||
*/
|
||||
@GetMapping("getHeadlines")
|
||||
public Result getHeadlines(){
|
||||
return marketService.getHeadlines();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,4 +19,6 @@ public interface MarketService extends IService<Market> {
|
|||
void getPhonePlace(String tel);
|
||||
|
||||
Result getIpPlace(String ip);
|
||||
|
||||
Result getHeadlines();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.muyu.cloud.mart.service.impl;
|
||||
|
||||
import cn.hutool.log.Log;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import com.muyu.cloud.mart.config.JuheDemo;
|
||||
|
@ -12,17 +13,20 @@ import com.muyu.common.core.utils.StringUtils;
|
|||
import com.muyu.domain.Market;
|
||||
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.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.muyu.cloud.mart.config.IPLocation.params;
|
||||
import static com.muyu.common.core.utils.PageUtils.startPage;
|
||||
|
||||
/**
|
||||
* @Author:chaiyapeng
|
||||
|
@ -37,10 +41,25 @@ public class MarketServiceImpl extends ServiceImpl<MarketMapper, Market> impleme
|
|||
|
||||
@Autowired
|
||||
private MarketMapper marketMapper;
|
||||
@Autowired
|
||||
private RedisTemplate<String,String>redisTemplate;
|
||||
|
||||
@Override
|
||||
public List<Market> findMarketList() {
|
||||
if (redisTemplate.hasKey("list")){
|
||||
List<String> list = redisTemplate.opsForList().range("list", 0, -1);
|
||||
ArrayList<Market> markets = new ArrayList<>();
|
||||
for (String s : list) {
|
||||
markets.add(JSON.parseObject(s, Market.class));
|
||||
}
|
||||
return markets;
|
||||
}
|
||||
startPage();
|
||||
// List<Market> list = marketService.findMarketList();
|
||||
List<Market> list = marketMapper.selectList(null);
|
||||
for (Market market1 : list) {
|
||||
redisTemplate.opsForList().rightPush("list", JSON.toJSONString(market1));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
// public static final PhoneNumberOfflineGeocoder GEOCODER = PhoneNumberOfflineGeocoder.getInstance();
|
||||
|
@ -81,4 +100,34 @@ public class MarketServiceImpl extends ServiceImpl<MarketMapper, Market> impleme
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 新闻头条
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Result getHeadlines() {
|
||||
String apiKey = "cdbb93769c75054e6beda4c1dc0b6a0b";
|
||||
String apiUrl = "http://v.juhe.cn/toutiao/index";
|
||||
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("key", apiKey);
|
||||
map.put("type", "top");
|
||||
map.put("page", "20");
|
||||
map.put("page_size", "");
|
||||
map.put("is_filter", "");
|
||||
try {
|
||||
URL url = new URL(String.format(apiUrl + "?" + params(map)));
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));
|
||||
String inputLine;
|
||||
StringBuffer response = new StringBuffer();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
System.out.println(response);
|
||||
return Result.success(response);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue