修改了商品类别接口

This commit is contained in:
chen-xin-zhi 2024-11-06 10:12:23 +08:00
parent e63b31e637
commit 4088f26758
2 changed files with 123 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import com.cultural.heritage.common.ResultUtils;
import com.cultural.heritage.constant.UserConstant;
import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.model.dto.CommonRequest;
import com.cultural.heritage.model.dto.order.OrderAddRequest;
import com.cultural.heritage.model.dto.order.OrderItemAddRequest;
import com.cultural.heritage.model.dto.order.OrderQueryRequest;
@ -176,6 +177,33 @@ public class OrderController {
// }
//
/**
* 小程序端用户查询订单
* @param commonRequest 用户id请求体
* @return 用户订单列表
*/
@PostMapping("/list")
@Operation(summary = "小程序端用户查询订单", description = "参数用户id请求体权限所有人方法名listUserOrder")
public BaseResponse<List<OrderVO>> listUserOrder(@RequestBody CommonRequest commonRequest) {
if (commonRequest == null || commonRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long id = commonRequest.getId();
QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("userId", id);
List<Order> orders = orderService.list(queryWrapper);
List<OrderVO> orderVOS = orders.stream().map(order -> {
Long orderId = order.getId();
QueryWrapper<OrderItems> orderItemsQueryWrapper = new QueryWrapper<>();
orderItemsQueryWrapper.eq("orderId", orderId);
List<OrderItems> orderItemsList = orderItemService.list(orderItemsQueryWrapper);
OrderVO orderVO = new OrderVO();
BeanUtils.copyProperties(order, orderVO);
orderVO.setOrderItemList(orderItemsList);
return orderVO;
}).toList();
return ResultUtils.success(orderVOS);
}
/**

View File

@ -0,0 +1,95 @@
package com.cultural.heritage.controller.wx;
import com.alibaba.fastjson.JSON;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/wx")
@Slf4j
@Tag(name = "小程序获取公众号文章")
public class WeChatController {
private String getToken() throws MalformedURLException, IOException, ProtocolException {
// access_token接口https请求方式: GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
String path = " https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential";
String appid = "wx3f968a09e31d6bed";
String secret = "847bdda7c2b01e88d59948b9ba50ef8d";
URL url = new URL(path+"&appid=" + appid + "&secret=" + secret);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
InputStream in = connection.getInputStream();
byte[] b = new byte[100];
int len = -1;
StringBuffer sb = new StringBuffer();
while((len = in.read(b)) != -1) {
sb.append(new String(b,0,len));
}
System.out.println(sb.toString());
in.close();
return sb.toString();
}
private String getContentList(String token) throws IOException {
String path = " https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=" + token;
URL url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("content-type", "application/json;charset=utf-8");
connection.connect();
// post发送的参数
Map<String, Object> map = new HashMap<>();
map.put("type", "news"); // news表示图文类型的素材具体看API文档
map.put("offset", 0);
map.put("count", 1);
// 将map转换成json字符串
String paramBody = JSON.toJSONString(map); // 这里用了Alibaba的fastjson
OutputStream out = connection.getOutputStream();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
bw.write(paramBody); // 向流中写入参数字符串
bw.flush();
InputStream in = connection.getInputStream();
byte[] b = new byte[100];
int len = -1;
StringBuffer sb = new StringBuffer();
while((len = in.read(b)) != -1) {
sb.append(new String(b,0,len));
}
in.close();
return sb.toString();
}
@Test
public void test() throws IOException {
String result1 = getToken();
Map<String,Object> token = (Map<String, Object>) JSON.parseObject(result1);
String result2 = getContentList(token.get("access_token").toString());
System.out.println(result2);
}
}