李雨欣 8.30 18:37 测试查询接口

master
liyuxin 2024-08-30 18:37:56 +08:00
parent 6e71b8533f
commit 2bef3c2e9c
23 changed files with 744 additions and 162 deletions

View File

@ -9,8 +9,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.market.admain.request.OrdersUpdResp;
import com.muyu.market.admain.request.ProductUpdReq;
import com.muyu.market.admain.response.OrdersUpdResp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;

View File

@ -70,6 +70,16 @@ public class Product extends BaseEntity {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Schema(description = "更新时间",defaultValue = "2024-5-15 10:00:52",type = "Date")
private Date updateTime;
/**
*
*/
@Excel(name = "接口地址")
private String apiAddr;
/**
*
*/
@Excel(name = "请求方式")
private String apiWay;
@ -91,6 +101,8 @@ public class Product extends BaseEntity {
.status(productSave.getStatus())
.createTime(productSave.getCreateTime())
.updateTime(productSave.getUpdateTime())
.apiAddr(productSave.getApiAddr())
.apiWay(productSave.getApiWay())
.build();
}
@ -107,9 +119,12 @@ public class Product extends BaseEntity {
.status(productUpdReq.getStatus())
.createTime(productUpdReq.getCreateTime())
.updateTime(productUpdReq.getUpdateTime())
.apiAddr(productUpdReq.getApiAddr())
.apiWay(productUpdReq.getApiWay())
.build();
}
//https://gitea.qinmian.online/cloud/cloud-ui.git
}

View File

@ -0,0 +1,18 @@
package com.muyu.market.admain;
import lombok.Data;
@Data
public class SelectByPhone {
// 省份
private String province;
// 城市
private String city;
// 区号
private String areacode;
// 邮编
private String zip;
// 运营商
private String company;
}

View File

@ -0,0 +1,37 @@
package com.muyu.market.admain;
import lombok.Data;
@Data
public class SelectWeather {
/**
*
*/
private String city;
/**
*
*/
private String info;
/**
*
*/
private String temperature;
/**
* 湿
*/
private String humidity;
/**
*
*/
private String direct;
/**
*
*/
private String power;
/**
*
*/
private String aqi;
}

View File

@ -1,11 +1,14 @@
package com.muyu.market.admain.request;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@Tag(name = "订单查询", description = "订单查询")
@AllArgsConstructor
@ -23,5 +26,41 @@ public class OrdersSelectReq {
*/
@Schema(type = "Long",defaultValue = "用户ID",description = "用户ID")
private Long userId;
/**
* ID
*/
@Schema(type = "Long",defaultValue = "商品ID",description = "1")
private Long productId;
/**
*
*/
@Schema(type = "String",defaultValue = "订单号",description = "订单号")
private String orderNo;
/**
*
*/
@Schema(type = "String",defaultValue = "订单状态",description = "订单状态")
private String orderStatus;
/**
*
*/
@Schema(type = "BigDecimal",defaultValue = "25.3",description = "订单总金额")
private String totalAmount;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Schema(description = "订单创建时间",defaultValue = "2024-5-15 10:00:52",type = "Date")
private Date createTime;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Schema(description = "订单更新时间",defaultValue = "2024-5-15 10:00:52",type = "Date")
private Date updateTime;
/**
*
*/
@Schema(type = "String",defaultValue = "订单备注",description = "订单备注")
private String note;
}

View File

@ -1,6 +1,7 @@
package com.muyu.market.admain.request;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.common.core.annotation.Excel;
import com.muyu.market.admain.Product;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -60,6 +61,16 @@ public class ProductListReq {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Schema(description = "更新时间",defaultValue = "2024-5-15 10:00:52",type = "Date")
private Date updateTime;
/**
*
*/
@Schema(type = "String",defaultValue = "接口地址",description = "接口地址")
private String apiAddr;
/**
*
*/
@Schema(type = "String",defaultValue = "请求方式",description = "请求方式")
private String apiWay;

View File

@ -55,6 +55,16 @@ public class ProductSaveReq {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Schema(description = "更新时间",defaultValue = "2024-5-15 10:00:52",type = "Date")
private Date updateTime;
/**
*
*/
@Schema(type = "String",defaultValue = "接口地址",description = "接口地址")
private String apiAddr;
/**
*
*/
@Schema(type = "String",defaultValue = "请求方式",description = "请求方式")
private String apiWay;

View File

@ -60,6 +60,16 @@ public class ProductUpdReq {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Schema(description = "更新时间",defaultValue = "2024-5-15 10:00:52",type = "Date")
private Date updateTime;
/**
*
*/
@Schema(type = "String",defaultValue = "接口地址",description = "接口地址")
private String apiAddr;
/**
*
*/
@Schema(type = "String",defaultValue = "请求方式",description = "请求方式")
private String apiWay;

View File

@ -1,4 +1,4 @@
package com.muyu.market.admain.request;
package com.muyu.market.admain.response;
import com.fasterxml.jackson.annotation.JsonFormat;

View File

@ -61,6 +61,17 @@ public class ProductListResp {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Schema(description = "更新时间",defaultValue = "2024-5-15 10:00:52",type = "Date")
private Date updateTime;
/**
*
*/
@Schema(type = "String",defaultValue = "接口地址",description = "接口地址")
private String apiAddr;
/**
*
*/
@Schema(type = "String",defaultValue = "请求方式",description = "请求方式")
private String apiWay;
private BigDecimal begin;
private BigDecimal end;
@ -78,6 +89,8 @@ public class ProductListResp {
.status(productlist.getStatus())
.createTime(productlist.getCreateTime())
.updateTime(productlist.getUpdateTime())
.apiAddr(productlist.getApiAddr())
.apiWay(productlist.getApiWay())
.build();
}

View File

@ -56,7 +56,16 @@ public class ProductSaveResp {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Schema(description = "更新时间",defaultValue = "2024-5-15 10:00:52",type = "Date")
private Date updateTime;
/**
*
*/
@Schema(type = "String",defaultValue = "接口地址",description = "接口地址")
private String apiAddr;
/**
*
*/
@Schema(type = "String",defaultValue = "请求方式",description = "请求方式")
private String apiWay;

View File

@ -103,6 +103,31 @@
<artifactId>cloud-common-nacos-api</artifactId>
</dependency>
<!-- api接口 需要用到的依赖 -->
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk13</classifier>
</dependency>
</dependencies>
<build>

View File

@ -1,19 +1,13 @@
package com.muyu.market.server.controller;
import com.muyu.common.core.domain.Result;
import com.muyu.market.admain.Orders;
import com.muyu.market.admain.Product;
import com.muyu.market.admain.request.OrdersSelectReq;
import com.muyu.market.admain.request.OrdersUpdResp;
import com.muyu.market.admain.response.OrdersSelectResp;
import com.muyu.market.server.service.OrdersService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.log4j.Log4j2;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -29,31 +23,40 @@ public class OrdersController {
private OrdersService orderService;
@PostMapping("/orderSelect")
@Operation(summary = "查询订信息",description = "查询订信息")
public Result<List<OrdersSelectResp>> orderSelect(@RequestBody OrdersSelectReq ordersSelectReq){
/**
*
* @param product
* @return
*/
@PostMapping("/orders")
@Operation(summary = "订单添加",description = "添加添加订单")
public Result<String> creatOrder(@RequestBody Product product){
List<OrdersSelectResp> sellist = orderService.orderSelect(ordersSelectReq);
return Result.success(sellist);
orderService.saveOrder(product);
return Result.success();
}
/**
*
* @param ordersSelectResp
* @return
*/
@RequestMapping(path = "/orderSelect",method = RequestMethod.POST)
@Operation(summary = "查询订单",description = "根据接口查看订单信息")
public Result<List<OrdersSelectResp>> findByorderList(@RequestBody OrdersSelectResp ordersSelectResp){
return Result.success(orderService.findByorderList(ordersSelectResp));
}
// /**
// * 点击下单 添加订单信息
// * @param product
// * @return
// */
// @PostMapping("/orders")
// @Operation(summary = "订单添加",description = "添加添加订单")
// public Result<String> creatOrder(@RequestBody Product product){
//
// orderService.saveOrder(product);
// return Result.success();
// }
// /**
// * 查询订信息
// * @param ordersSelectResp
// * @return
// */
// @RequestMapping(path = "/orderSelect",method = RequestMethod.POST)
// @Operation(summary = "查询订单",description = "根据接口查看订单信息")
// public Result<List<OrdersSelectResp>> findByorderList(@RequestBody OrdersSelectResp ordersSelectResp){
// return Result.success(orderService.findByorderList(ordersSelectResp));
// }
// /**
@ -69,36 +72,36 @@ public class OrdersController {
/**
* ID
* @param orderId
* @return
*/
@DeleteMapping
@Operation(summary = "刪除订单",description = "根据订单Id 删除订单")
public Result<String> removeById(@RequestParam(value = "orderId") Long orderId){
orderService.removeById(orderId);
return Result.success(null,"操作成功");
}
/**
*
* @param orderId
* @param ordersUpdResp
* @return
*/
@PutMapping("/{orderId}")
@Operation(summary = "订单的修改",description = "通过ID修改订单")
public Result<String> update(
@Schema(title = "订单ID",type = "Long",description = "修改订单信息",defaultValue = "1")
@PathVariable("orderId") Long orderId,
@RequestBody @Validated OrdersUpdResp ordersUpdResp){
orderService.updateById(Orders.UpdOrdersReq(ordersUpdResp,()->orderId));
return Result.success(null,"操作成功");
}
// /**
// * 根据ID删除订单
// * @param orderId
// * @return
// */
// @DeleteMapping
// @Operation(summary = "刪除订单",description = "根据订单Id 删除订单")
// public Result<String> removeById(@RequestParam(value = "orderId") Long orderId){
// orderService.removeById(orderId);
// return Result.success(null,"操作成功");
// }
//
//
// /**
// * 修改订单
// * @param orderId
// * @param ordersUpdResp
// * @return
// */
// @PutMapping("/{orderId}")
// @Operation(summary = "订单的修改",description = "通过ID修改订单")
// public Result<String> update(
// @Schema(title = "订单ID",type = "Long",description = "修改订单信息",defaultValue = "1")
// @PathVariable("orderId") Long orderId,
// @RequestBody @Validated OrdersUpdResp ordersUpdResp){
//
// orderService.updateById(Orders.UpdOrdersReq(ordersUpdResp,()->orderId));
// return Result.success(null,"操作成功");
//
// }

View File

@ -0,0 +1,33 @@
package com.muyu.market.server.controller;
import com.muyu.common.core.domain.Result;
import com.muyu.market.admain.Product;
import com.muyu.market.admain.SelectByPhone;
import com.muyu.market.server.util.SelectPhoneUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
@RequestMapping("/party")
@Tag(name = "查询手机号",description = "订单查询")
public class PartyController {
@PostMapping("/selparty")
@Operation(summary = "查询手机号",description = "查询手机号")
public SelectByPhone selparty(@RequestParam("phoneNumber") String phoneNumber){
return SelectPhoneUtil.queryMobileLocation(phoneNumber);
}
//测试
public static void main(String[] args) {
SelectPhoneUtil.queryMobileLocation("18790307917");
}
}

View File

@ -0,0 +1,32 @@
package com.muyu.market.server.controller;
import com.muyu.market.admain.SelectWeather;
import com.muyu.market.server.util.SelectWeatherUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping("/weather")
@Tag(name = "查询天气",description = "查询天气")
public class WeatherController {
@PostMapping("/selweather")
@Operation(summary = "查询天气",description = "查询天气")
public SelectWeather selweather(@RequestParam("cityName") String cityName){
return SelectWeatherUtil.queryWeather(cityName);
}
public static void main(String[] args) {
SelectWeatherUtil.queryWeather("南京");
}
}

View File

@ -9,8 +9,10 @@ import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface OrdersMapper extends BaseMapper<Orders> {
List<OrdersSelectResp> findByorderList(OrdersSelectResp ordersSelectResp);
public interface OrdersMapper {
List<OrdersSelectResp> orderSelect(OrdersSelectReq ordersSelectReq);
// List<OrdersSelectResp> findByorderList(OrdersSelectResp ordersSelectResp);
/**
*

View File

@ -15,60 +15,65 @@ import java.util.Date;
import java.util.List;
import java.util.UUID;
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements OrdersService {
public class OrdersServiceImpl implements OrdersService {
@Autowired
private OrdersMapper orderMapper;
@Override
public void saveOrder(Product product) {
Orders order = new Orders();
//获取用户ID
Long userId = SecurityUtils.getUserId();
order.setUserId(userId);
//获取商品ID
order.setProductId(product.getProductId());
// 生成一个随机的UUID
UUID uuid = UUID.randomUUID();
// 将UUID转换为字符串
String random = uuid.toString();
//随机生成订单编号
order.setOrderNo(random);
//订单状态(0:未支付 1:已支付)(订单刚生成状态都为未支付)
order.setOrderStatus("0");
//订单总金额
order.setTotalAmount(product.getProductPrice());
//订单创建时间(为当前时间)
order.setCreateTime(new Date());
//订单更新时间(为当前时间)
order.setUpdateTime(new Date());
try {
orderMapper.insert(order);
} catch (Exception e) {
public List<OrdersSelectResp> orderSelect(OrdersSelectReq ordersSelectReq) {
return orderMapper.orderSelect(ordersSelectReq);
}
}
// @Override
// public List<OrdersSelectResp> findAll() {
// return orderMapper.findAll();
// public void saveOrder(Product product) {
//
// Orders order = new Orders();
// //获取用户ID
// Long userId = SecurityUtils.getUserId();
// order.setUserId(userId);
// //获取商品ID
// order.setProductId(product.getProductId());
//
// // 生成一个随机的UUID
// UUID uuid = UUID.randomUUID();
// // 将UUID转换为字符串
// String random = uuid.toString();
// //随机生成订单编号
// order.setOrderNo(random);
//
// //订单状态(0:未支付 1:已支付)(订单刚生成状态都为未支付)
// order.setOrderStatus("0");
// //订单总金额
// order.setTotalAmount(product.getProductPrice());
// //订单创建时间(为当前时间)
// order.setCreateTime(new Date());
// //订单更新时间(为当前时间)
// order.setUpdateTime(new Date());
//
// try {
// orderMapper.insert(order);
// } catch (Exception e) {
//
// }
@Override
public List<OrdersSelectResp> findByorderList(OrdersSelectResp ordersSelectResp) {
return orderMapper.findByorderList(ordersSelectResp);
}
//
//
//
// }
//
//
//
//// @Override
//// public List<OrdersSelectResp> findAll() {
//// return orderMapper.findAll();
//// }
//
// @Override
// public List<OrdersSelectResp> findByorderList(OrdersSelectResp ordersSelectResp) {
// return orderMapper.findByorderList(ordersSelectResp);
// }
//

View File

@ -48,6 +48,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
Product::getProductPrice,productListResp.getEnd()
);
}
List<Product> productlist = this.list(lambdaQueryWrapperlist);
// return productlist.stream()

View File

@ -2,6 +2,7 @@ package com.muyu.market.server.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.common.core.domain.Result;
import com.muyu.market.admain.Orders;
import com.muyu.market.admain.Product;
import com.muyu.market.admain.request.OrdersSelectReq;
@ -9,13 +10,15 @@ import com.muyu.market.admain.response.OrdersSelectResp;
import java.util.List;
public interface OrdersService extends IService<Orders> {
public interface OrdersService {
List<OrdersSelectResp> orderSelect(OrdersSelectReq ordersSelectReq);
void saveOrder(Product product);
List<OrdersSelectResp> findByorderList(OrdersSelectResp ordersSelectResp);
// List<OrdersSelectResp> findAll();
// void saveOrder(Product product);
//
// List<OrdersSelectResp> findByorderList(OrdersSelectResp ordersSelectResp);
//
//// List<OrdersSelectResp> findAll();
}

View File

@ -7,7 +7,8 @@ import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.alipay.api.response.AlipayTradeWapPayResponse;
//测试 是能用的 好像 希望啥 写完啦 快了 我只要把公钥私钥换了就行了
public class PayUtils {
public static void main(String[] args) {
AlipayClient alipayClient = new DefaultAlipayClient(

View File

@ -0,0 +1,147 @@
package com.muyu.market.server.util;
import com.muyu.market.admain.SelectByPhone;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.RestController;
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;
@RestController
public class SelectPhoneUtil {
// 手机归属地查询接口地址
public static String API_URL = "http://apis.juhe.cn/mobile/get";
// 接口请求Key
public static String API_KEY = "4cfc25ee624fc08ad83b61a3a0ab1bcb";
/**
* /7
* @param mobile
*/
public static SelectByPhone queryMobileLocation(String mobile)
{
Map<String, Object> params = new HashMap<>();//组合参数
params.put("phone", mobile);
params.put("key", API_KEY);
String queryParams = urlencode(params);
String response = doGet(API_URL, queryParams);
SelectByPhone selectByPhone = new SelectByPhone();
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");
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"));
selectByPhone.setCompany(result.getString("company"));
selectByPhone.setCity(result.getString("city"));
selectByPhone.setZip(result.getString("zip"));
selectByPhone.setAreacode(result.getString("areacode"));
selectByPhone.setProvince(result.getString("province"));
} else {
System.out.println("调用接口失败:" + jsonObject.getString("reason"));
}
} catch (Exception e) {
e.printStackTrace();
}
return selectByPhone;
}
/**
* 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

@ -0,0 +1,154 @@
package com.muyu.market.server.util;
import com.muyu.market.admain.SelectWeather;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.RestController;
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;
@RestController
public class SelectWeatherUtil {
// 天气情况查询接口地址
public static String API_URL = "http://apis.juhe.cn/simpleWeather/query";
// 接口请求Key
public static String API_KEY = "2e7b031d32a2eac211c099bf4918a4dd";
/**
*
*
* @param cityName
*/
public static SelectWeather 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);
SelectWeather selectWeather = new SelectWeather();
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");
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"));
selectWeather.setCity(result.getString("city"));
selectWeather.setInfo(realtime.getString("info"));
selectWeather.setTemperature(realtime.getString("temperature"));
selectWeather.setHumidity(realtime.getString("humidity"));
selectWeather.setDirect(realtime.getString("direct"));
selectWeather.setPower(realtime.getString("power"));
selectWeather.setAqi(realtime.getString("aqi"));
} else {
System.out.println("调用接口失败:" + jsonObject.getString("reason"));
}
} catch (Exception e) {
e.printStackTrace();
}
return selectWeather;
}
/**
* 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

@ -17,7 +17,7 @@
</resultMap>
<select id="findByorderList" resultType="com.muyu.market.admain.response.OrdersSelectResp">
<select id="orderSelect" resultType="com.muyu.market.admain.response.OrdersSelectResp">
SELECT
orders.*,
sys_user.user_name,
@ -32,6 +32,21 @@
</select>
<!-- <select id="findByorderList" resultType="com.muyu.market.admain.response.OrdersSelectResp">-->
<!-- SELECT-->
<!-- orders.*,-->
<!-- sys_user.user_name,-->
<!-- product.product_name,-->
<!-- product.product_price,-->
<!-- product.description,-->
<!-- product.`status`-->
<!-- FROM-->
<!-- orders-->
<!-- LEFT JOIN sys_user ON orders.order_id = sys_user.user_id-->
<!-- LEFT JOIN product ON orders.order_id = product.product_id-->
<!-- </select>-->
<!-- <select id="findAll" resultType="com.muyu.market.admain.response.OrdersSelectResp">-->
<!-- SELECT-->
<!-- orders.*,-->