两千万数据框架
parent
68a4e9a454
commit
2868402653
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,43 @@
|
||||||
|
package com.muyu.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:chaiyapeng
|
||||||
|
* @Package:com.muyu.domain
|
||||||
|
* @Project:cloud-port
|
||||||
|
* @name:WeatherForecast
|
||||||
|
* @Date:2024/9/4 19:05
|
||||||
|
* 天气预报
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class WeatherForecast {
|
||||||
|
/**
|
||||||
|
* 城市
|
||||||
|
*/
|
||||||
|
private String city;
|
||||||
|
/**
|
||||||
|
* 天气
|
||||||
|
*/
|
||||||
|
private String info;
|
||||||
|
/**
|
||||||
|
* 温度
|
||||||
|
*/
|
||||||
|
private String temperature;
|
||||||
|
/**
|
||||||
|
* 湿度
|
||||||
|
*/
|
||||||
|
private String humidity;
|
||||||
|
/**
|
||||||
|
* 风向
|
||||||
|
*/
|
||||||
|
private String direct;
|
||||||
|
/**
|
||||||
|
* 风力
|
||||||
|
*/
|
||||||
|
private String power;
|
||||||
|
/**
|
||||||
|
* 空气质量
|
||||||
|
*/
|
||||||
|
private String aqi;
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package com.muyu.cloud.mart.controller;
|
||||||
import cn.hutool.db.PageResult;
|
import cn.hutool.db.PageResult;
|
||||||
import com.dtflys.forest.annotation.Post;
|
import com.dtflys.forest.annotation.Post;
|
||||||
import com.muyu.cloud.mart.service.DataMillionService;
|
import com.muyu.cloud.mart.service.DataMillionService;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.web.controller.BaseController;
|
import com.muyu.common.core.web.controller.BaseController;
|
||||||
import com.muyu.domain.DataMillion;
|
import com.muyu.domain.DataMillion;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -11,7 +12,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.xml.transform.Result;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,6 +20,7 @@ import java.util.List;
|
||||||
* @Project:cloud-port
|
* @Project:cloud-port
|
||||||
* @name:DataMillion
|
* @name:DataMillion
|
||||||
* @Date:2024/9/4 12:02
|
* @Date:2024/9/4 12:02
|
||||||
|
* 数据源接口
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("million")
|
@RequestMapping("million")
|
||||||
|
@ -27,5 +28,9 @@ public class DataMillionController extends BaseController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private DataMillionService dataMillionService;
|
private DataMillionService dataMillionService;
|
||||||
|
|
||||||
|
@PostMapping("findMillionList")
|
||||||
|
public Result<List<DataMillion>> findMillionList(@RequestBody DataMillion dataMillion){
|
||||||
|
return dataMillionService.findMillionList(dataMillion);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,5 +85,11 @@ public class MarketController extends BaseController {
|
||||||
public Result getPostcode(@RequestParam(name = "code") String code){
|
public Result getPostcode(@RequestParam(name = "code") String code){
|
||||||
return marketService.getPostcode(code);
|
return marketService.getPostcode(code);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 天气预报
|
||||||
|
*/
|
||||||
|
@GetMapping("getWeatherForecast")
|
||||||
|
public Result getWeatherForecast(@RequestParam(name = "city") String city){
|
||||||
|
return marketService.getWeatherForecast(city);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.muyu.domain.DataMillion;
|
import com.muyu.domain.DataMillion;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author:chaiyapeng
|
* @Author:chaiyapeng
|
||||||
* @Package:com.muyu.cloud.mart.mapper
|
* @Package:com.muyu.cloud.mart.mapper
|
||||||
|
@ -13,4 +15,5 @@ import org.apache.ibatis.annotations.Mapper;
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface DataMillionMapper extends BaseMapper<DataMillion> {
|
public interface DataMillionMapper extends BaseMapper<DataMillion> {
|
||||||
|
List<DataMillion> findMillionList(DataMillion dataMillion);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package com.muyu.cloud.mart.service;
|
package com.muyu.cloud.mart.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.domain.DataMillion;
|
import com.muyu.domain.DataMillion;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author:chaiyapeng
|
* @Author:chaiyapeng
|
||||||
* @Package:com.muyu.cloud.mart.service
|
* @Package:com.muyu.cloud.mart.service
|
||||||
|
@ -11,4 +14,6 @@ import com.muyu.domain.DataMillion;
|
||||||
* @Date:2024/9/4 12:04
|
* @Date:2024/9/4 12:04
|
||||||
*/
|
*/
|
||||||
public interface DataMillionService extends IService<DataMillion> {
|
public interface DataMillionService extends IService<DataMillion> {
|
||||||
|
|
||||||
|
Result<List<DataMillion>> findMillionList(DataMillion dataMillion);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,4 +29,6 @@ public interface MarketService extends IService<Market> {
|
||||||
Result getBirthday(BirthdayRes birthdayRes);
|
Result getBirthday(BirthdayRes birthdayRes);
|
||||||
|
|
||||||
Result getPostcode(String code);
|
Result getPostcode(String code);
|
||||||
|
|
||||||
|
Result getWeatherForecast(String city);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,14 @@ package com.muyu.cloud.mart.service.impl;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.muyu.cloud.mart.mapper.DataMillionMapper;
|
import com.muyu.cloud.mart.mapper.DataMillionMapper;
|
||||||
import com.muyu.cloud.mart.service.DataMillionService;
|
import com.muyu.cloud.mart.service.DataMillionService;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.domain.DataMillion;
|
import com.muyu.domain.DataMillion;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author:chaiyapeng
|
* @Author:chaiyapeng
|
||||||
* @Package:com.muyu.cloud.mart.service.impl
|
* @Package:com.muyu.cloud.mart.service.impl
|
||||||
|
@ -20,6 +23,13 @@ import org.springframework.stereotype.Service;
|
||||||
public class DataMillionServiceImpl extends ServiceImpl<DataMillionMapper, DataMillion> implements DataMillionService {
|
public class DataMillionServiceImpl extends ServiceImpl<DataMillionMapper, DataMillion> implements DataMillionService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private DataMillionMapper dataMillionMapper;
|
private DataMillionMapper dataMillionMapper;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<List<DataMillion>> findMillionList(DataMillion dataMillion) {
|
||||||
|
List<DataMillion> list = dataMillionMapper.findMillionList(dataMillion);
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -96,4 +96,10 @@ public class MarketServiceImpl extends ServiceImpl<MarketMapper, Market> impleme
|
||||||
List<Postcode> list = PostcodeInquire.queryPostcode(code);
|
List<Postcode> list = PostcodeInquire.queryPostcode(code);
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result getWeatherForecast(String city) {
|
||||||
|
WeatherForecast weatherForecast = WeatherForecastInquire.queryWeather(city);
|
||||||
|
return Result.success(weatherForecast);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,160 @@
|
||||||
|
package com.muyu.cloud.mart.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import com.muyu.domain.WeatherForecast;
|
||||||
|
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;
|
||||||
|
/**
|
||||||
|
* @Author:chaiyapeng
|
||||||
|
* @Package:com.muyu.cloud.mart.utils
|
||||||
|
* @Project:cloud-port
|
||||||
|
* @name:WeatherForecastInquire
|
||||||
|
* @Date:2024/9/4 19:06
|
||||||
|
*/
|
||||||
|
public class WeatherForecastInquire {
|
||||||
|
// 天气情况查询接口地址
|
||||||
|
public static String API_URL = "http://apis.juhe.cn/simpleWeather/query";
|
||||||
|
// 接口请求Key
|
||||||
|
public static String API_KEY = "c25e94d2042d154ac79b20d57eaec43b";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String cityName = "北京";
|
||||||
|
queryWeather(cityName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据城市名查询天气情况
|
||||||
|
*
|
||||||
|
* @param cityName
|
||||||
|
*/
|
||||||
|
public static WeatherForecast queryWeather(String cityName) {
|
||||||
|
Map<String, Object> params = new HashMap<>();//组合参数
|
||||||
|
params.put("city", cityName);
|
||||||
|
params.put("key", API_KEY);
|
||||||
|
String queryParams = urlencode(params);
|
||||||
|
|
||||||
|
String response = doGet(API_URL, queryParams);
|
||||||
|
WeatherForecast weatherForecast = new WeatherForecast();
|
||||||
|
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");
|
||||||
|
JSONObject realtime = result.getJSONObject("realtime");
|
||||||
|
|
||||||
|
weatherForecast.setCity(result.getString("city"));
|
||||||
|
weatherForecast.setInfo(realtime.getString("info"));
|
||||||
|
weatherForecast.setTemperature(realtime.getString("temperature"));
|
||||||
|
weatherForecast.setHumidity(realtime.getString("humidity"));
|
||||||
|
weatherForecast.setDirect(realtime.getString("direct"));
|
||||||
|
weatherForecast.setPower(realtime.getString("power"));
|
||||||
|
weatherForecast.setAqi(realtime.getString("aqi"));
|
||||||
|
|
||||||
|
System.out.printf("城市:%s%n", result.getString("city"));
|
||||||
|
System.out.printf("天气:%s%n", realtime.getString("info"));
|
||||||
|
System.out.printf("温度:%s%n", realtime.getString("temperature"));
|
||||||
|
System.out.printf("湿度:%s%n", realtime.getString("humidity"));
|
||||||
|
System.out.printf("风向:%s%n", realtime.getString("direct"));
|
||||||
|
System.out.printf("风力:%s%n", realtime.getString("power"));
|
||||||
|
System.out.printf("空气质量:%s%n", realtime.getString("aqi"));
|
||||||
|
} else {
|
||||||
|
System.out.println("调用接口失败:" + jsonObject.getString("reason"));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return weatherForecast;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get方式的http请求
|
||||||
|
*
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,4 +4,7 @@
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.muyu.cloud.mart.mapper.DataMillionMapper">
|
<mapper namespace="com.muyu.cloud.mart.mapper.DataMillionMapper">
|
||||||
|
|
||||||
|
<select id="findMillionList" resultType="com.muyu.domain.DataMillion">
|
||||||
|
select *from data_million
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue