两千万数据框架

master
chaiyapeng 2024-09-04 19:14:03 +08:00
parent 68a4e9a454
commit 2868402653
11 changed files with 302 additions and 29 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,43 @@
package com.muyu.domain;
import lombok.Data;
/**
* @Authorchaiyapeng
* @Packagecom.muyu.domain
* @Projectcloud-port
* @nameWeatherForecast
* @Date2024/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;
}

View File

@ -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;
* @Projectcloud-port * @Projectcloud-port
* @nameDataMillion * @nameDataMillion
* @Date2024/9/4 12:02 * @Date2024/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);
}
} }

View File

@ -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);
}
} }

View File

@ -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;
/** /**
* @Authorchaiyapeng * @Authorchaiyapeng
* @Packagecom.muyu.cloud.mart.mapper * @Packagecom.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);
} }

View File

@ -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;
/** /**
* @Authorchaiyapeng * @Authorchaiyapeng
* @Packagecom.muyu.cloud.mart.service * @Packagecom.muyu.cloud.mart.service
@ -11,4 +14,6 @@ import com.muyu.domain.DataMillion;
* @Date2024/9/4 12:04 * @Date2024/9/4 12:04
*/ */
public interface DataMillionService extends IService<DataMillion> { public interface DataMillionService extends IService<DataMillion> {
Result<List<DataMillion>> findMillionList(DataMillion dataMillion);
} }

View File

@ -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);
} }

View File

@ -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;
/** /**
* @Authorchaiyapeng * @Authorchaiyapeng
* @Packagecom.muyu.cloud.mart.service.impl * @Packagecom.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);
}
} }

View File

@ -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);
}
} }

View File

@ -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;
/**
* @Authorchaiyapeng
* @Packagecom.muyu.cloud.mart.utils
* @Projectcloud-port
* @nameWeatherForecastInquire
* @Date2024/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;
}
/**
* 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

@ -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>