fix:测试次数

master
chaiyapeng 2024-09-09 14:43:08 +08:00
parent b703f606e6
commit 38a93aafb0
11 changed files with 4 additions and 693 deletions

View File

@ -31,6 +31,10 @@ public class ConnectorUser {
* *
*/ */
private Integer connectorFrequency; private Integer connectorFrequency;
/**
*
*/
private Integer textNumber;
/** /**
* *
*/ */

View File

@ -1,92 +0,0 @@
package com.muyu.cloud.mart.controller;
import com.alibaba.fastjson.JSON;
import com.muyu.cloud.mart.config.IPLocation;
import com.muyu.cloud.mart.service.MarketService;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.domain.Birthday;
import com.muyu.domain.Market;
import com.muyu.domain.Postcode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @Authorchaiyapeng
* @Packagecom.muyu.cloud.etl.controller
* @Projectcloud-mart
* @nameMarketController
* @Date2024/8/21 21:53
*/
@RestController
@RequestMapping("/list")
public class MarketController extends BaseController {
@Autowired
private MarketService marketService;
@Autowired
private RedisTemplate<String,String>redisTemplate;
// @RequiresPermissions("mart:info:list")
/**
*
* @return
*/
@GetMapping("/findMarketList")
public Result<TableDataInfo<Market>> findMarketList(){
List<Market> list = marketService.findMarketList();
return getDataTable(list);
}
/**
*
*/
@GetMapping("/getPhonePlace")
public Result getPhonePlace(@RequestParam(name = "tel") String tel){
return marketService.getPhonePlace(tel);
}
/**
* IP
*/
@GetMapping("/getIpPlace")
public Result getIpPlace(@RequestParam(name = "ip") String ip){
return marketService.getIpPlace(ip);
}
/**
*
*/
@GetMapping("/getHeadlines")
public Result getHeadlines(){
return marketService.getHeadlines();
}
/**
*
*/
@GetMapping("/getWeather")
public Result getWeather(){
return marketService.getWeather();
}
/**
*
*/
@PostMapping("/getBirthday")
public Result getBirthday(@RequestBody Birthday birthday){
return marketService.getBirthday(birthday);
}
/**
*
*/
@PostMapping("/getPostcode")
public Result getPostcode(@RequestBody Postcode postcode){
return marketService.getPostcode(postcode);
}
}

View File

@ -1,32 +0,0 @@
package com.muyu.cloud.mart.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.common.core.domain.Result;
import com.muyu.domain.Birthday;
import com.muyu.domain.Market;
import com.muyu.domain.Postcode;
import java.util.List;
/**
* @Authorchaiyapeng
* @Packagecom.muyu.cloud.etl.service
* @Projectcloud-mart
* @nameMarketService
* @Date2024/8/21 21:54
*/
public interface MarketService extends IService<Market> {
List<Market> findMarketList();
Result getPhonePlace(String tel);
Result getIpPlace(String ip);
Result getHeadlines();
Result getWeather();
Result getBirthday(Birthday birthday);
Result getPostcode(Postcode postcode);
}

View File

@ -1,118 +0,0 @@
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.Birthday;
import com.muyu.domain.Market;
import com.muyu.domain.PhonePlace;
import com.muyu.domain.Postcode;
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;
/**
* @Authorchaiyapeng
* @Packagecom.muyu.cloud.etl.service.impl
* @Projectcloud-mart
* @nameMarketServiceImpl
* @Date2024/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;
@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();
/**
*
* @param tel
*/
@Override
public Result getPhonePlace(String tel) {
PhonePlace phonePlace = MobileLocation.queryMobileLocation(tel);
return Result.success(phonePlace);
}
/**
* IP
* @param ip
* @return
*/
@Override
public Result getIpPlace(String ip) {
StringBuffer stringBuffer = IPLocation.queryIPLocation(ip);
return Result.success(stringBuffer);
}
/**
*
* @return
*/
@Override
public Result getHeadlines() {
StringBuffer stringBuffer = Headlines.queryHeadlines();
return Result.success(stringBuffer);
}
/**
*
*/
@Override
public Result getWeather() {
StringBuffer stringBuffer = Weather.queryWeather();
return Result.success(stringBuffer);
}
/**
*
*/
@Override
public Result getBirthday(Birthday birthday) {
StringBuffer stringBuffer = BirthdayHelper.queryBirthday(birthday);
return Result.success(stringBuffer);
}
/**
*
*/
@Override
public Result getPostcode(Postcode postcode) {
StringBuffer stringBuffer = PostcodeInquire.queryPostcode(postcode);
return Result.success(stringBuffer);
}
}

View File

@ -1,67 +0,0 @@
package com.muyu.cloud.mart.utils;
import com.muyu.domain.Birthday;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Authorchaiyapeng
* @Packagecom.muyu.cloud.mart.utils
* @Projectcloud-mart
* @nameBirthdayHelper
* @Date2024/8/24 19:36
*
*/
public class BirthdayHelper {
public static StringBuffer queryBirthday(Birthday birthday){
String apiKey = "9bbfc46233d4931c39207b090ed4b27c";
String apiUrl = "http://apis.juhe.cn/birthEight/query";
HashMap<String, String> map = new HashMap<>();
map.put("key", apiKey);
map.put("year", birthday.getYear());
birthday.setYear(map.put("year", birthday.getYear()));
map.put("month", birthday.getMonth());
birthday.setMonth(map.put("month", birthday.getMonth()));
map.put("day", birthday.getDay());
birthday.setDay(map.put("day", birthday.getDay()));
map.put("hour", birthday.getHour());
birthday.setHour(map.put("hour", birthday.getHour()));
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 response;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static String params(Map<String, String> map) {
return map.entrySet().stream()
.map(entry -> {
try {
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString());
} catch (Exception e) {
e.printStackTrace();
return entry.getKey() + "=" + entry.getValue();
}
})
.collect(Collectors.joining("&"));
}
}

View File

@ -1,47 +0,0 @@
package com.muyu.cloud.mart.utils;
import com.muyu.common.core.domain.Result;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import static com.muyu.cloud.mart.config.IPLocation.params;
/**
* @Authorchaiyapeng
* @Packagecom.muyu.cloud.mart.utils
* @Projectcloud-mart
* @nameHeadlines
* @Date2024/8/24 18:39
*
*/
public class Headlines {
public static StringBuffer queryHeadlines(){
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 response;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@ -1,56 +0,0 @@
package com.muyu.cloud.mart.utils;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Authorchaiyapeng
* @Packagecom.muyu.cloud.mart.utils
* @Projectcloud-mart
* @nameIPLocation
* @Date2024/8/23 20:54
* IP
*/
public class IPLocation {
public static StringBuffer queryIPLocation(String ip){
String apiKey = "e84b7d13a9fb87b4ebcc9813e4518955";
String apiUrl = "http://apis.juhe.cn/ip/ipNewV3";
HashMap<String, String> map = new HashMap<>();
map.put("key", apiKey);
map.put("ip", ip);
try {
URL url = new URL(String.format(apiUrl + "?" + params(map)));
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));
String inputLine;
StringBuffer stringBuffer = new StringBuffer();
while ((inputLine = in.readLine()) != null){
stringBuffer.append(inputLine);
}
in.close();
System.out.println(stringBuffer);
return stringBuffer;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static String params(Map<String, String> map) {
return map.entrySet().stream()
.map(entry -> {
try {
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString());
} catch (Exception e) {
e.printStackTrace();
return entry.getKey() + "=" + entry.getValue();
}
})
.collect(Collectors.joining("&"));
}
}

View File

@ -1,154 +0,0 @@
package com.muyu.cloud.mart.utils;
import com.muyu.domain.PhonePlace;
import net.sf.json.JSONObject;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
/**
*
*/
public class MobileLocation {
// 手机归属地查询接口地址
// http://apis.juhe.cn/mobile/get http://127.0.0.1:8369/query?mobile
public static String API_URL = "http://apis.juhe.cn/mobile/get";
// 接口请求Key
public static String API_KEY = "8e5493da8edee8e42831574b9a2c3492";
/**
* /7
* @param tel
*/
public static PhonePlace queryMobileLocation(String tel)
{
Map<String, Object> params = new HashMap<>();//组合参数
params.put("phone", tel);
params.put("key", API_KEY);
String queryParams = urlencode(params);
PhonePlace phonePlace = new PhonePlace();
String response = doGet(API_URL, queryParams);
try {
JSONObject jsonObject = JSONObject.fromObject(response);
int error_code = jsonObject.getInt("error_code");
if (error_code == 0) {
System.out.println("调用接口成功");
JSONObject result = jsonObject.getJSONObject("result");
phonePlace.setProvince(result.getString("province"));
phonePlace.setCity(result.getString("city"));
phonePlace.setAreacode(result.getString("areacode"));
phonePlace.setZip(result.getString("zip"));
phonePlace.setCompany(result.getString("company"));
System.out.printf("省份:%s%n", result.getString("province"));
System.out.printf("城市:%s%n", result.getString("city"));
System.out.printf("区号:%s%n", result.getString("areacode"));
System.out.printf("邮编:%s%n", result.getString("zip"));
System.out.printf("运营商:%s%n", result.getString("company"));
} else {
System.out.println("调用接口失败:" + jsonObject.getString("reason"));
}
} catch (Exception e) {
e.printStackTrace();
}
return phonePlace;
}
/**
* gethttp
*
* @param httpUrl
* @return
*/
public static String doGet(String httpUrl, String queryParams) {
HttpURLConnection connection = null;
InputStream inputStream = null;
BufferedReader bufferedReader = null;
String result = null;// 返回结果字符串
try {
// 创建远程url连接对象
URL url = new URL(new StringBuffer(httpUrl).append("?").append(queryParams).toString());
// 通过远程url连接对象打开一个连接强转成httpURLConnection类
connection = (HttpURLConnection) url.openConnection();
// 设置连接方式get
connection.setRequestMethod("GET");
// 设置连接主机服务器的超时时间15000毫秒
connection.setConnectTimeout(5000);
// 设置读取远程返回的数据时间60000毫秒
connection.setReadTimeout(6000);
// 发送请求
connection.connect();
// 通过connection连接获取输入流
if (connection.getResponseCode() == 200) {
inputStream = connection.getInputStream();
// 封装输入流,并指定字符集
bufferedReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
// 存放数据
StringBuilder sbf = new StringBuilder();
String temp;
while ((temp = bufferedReader.readLine()) != null) {
sbf.append(temp);
sbf.append(System.getProperty("line.separator"));
}
result = sbf.toString();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
// 关闭资源
if (null != bufferedReader) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != inputStream) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (connection != null) {
connection.disconnect();// 关闭远程连接
}
}
return result;
}
/**
* map
*
* @param data
* @return
*/
public static String urlencode(Map<String, ?> data) {
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, ?> i : data.entrySet()) {
try {
sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue() + "", "UTF-8")).append("&");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
String result = sb.toString();
result = result.substring(0, result.lastIndexOf("&"));
return result;
}
}

View File

@ -1,62 +0,0 @@
package com.muyu.cloud.mart.utils;
import com.muyu.domain.Postcode;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Authorchaiyapeng
* @Packagecom.muyu.cloud.mart.utils
* @Projectcloud-mart
* @namePostcode
* @Date2024/8/24 20:50
*/
public class PostcodeInquire {
public static StringBuffer queryPostcode(Postcode postcode){
String apiKey = "0cabcd31c150369d8afb2c8b7e41a2c0";
String apiUrl = "http://v.juhe.cn/postcode/query";
HashMap<String, String> map = new HashMap<>();
map.put("key", apiKey);
map.put("postcode", postcode.getPostcode());//邮编215001
postcode.setPostcode(map.put("postcode", postcode.getPostcode()));
map.put("page", String.valueOf(postcode.getPage()));//页数默认1
map.put("pagesize", "");//每页返回,默认:20,最大不超过50
map.put("dtype", "json");//返回数据的格式,xml或json默认json
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 response;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static String params(Map<String, String> map) {
return map.entrySet().stream()
.map(entry -> {
try {
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString());
} catch (Exception e) {
e.printStackTrace();
return entry.getKey() + "=" + entry.getValue();
}
})
.collect(Collectors.joining("&"));
}
}

View File

@ -1,56 +0,0 @@
package com.muyu.cloud.mart.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Authorchaiyapeng
* @Packagecom.muyu.cloud.mart.utils
* @Projectcloud-mart
* @nameWeather
* @Date2024/8/24 18:51
*
*/
public class Weather {
public static StringBuffer queryWeather() {
String apiKey = "80e78ee9adaded8b1f42ec9cbdf69ac9";
String apiUrl = "https://apis.juhe.cn/fapig/alarm/citys";
HashMap<String, String> map = new HashMap<>();
map.put("key", apiKey);
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 response;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static String params(Map<String, String> map) {
return map.entrySet().stream()
.map(entry -> {
try {
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString());
} catch (Exception e) {
e.printStackTrace();
return entry.getKey() + "=" + entry.getValue();
}
})
.collect(Collectors.joining("&"));
}
}

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.cloud.mart.mapper.MarketMapper">
</mapper>