修改订单接口,添加商品属性,添加微信小程序依赖
This commit is contained in:
parent
4990e5551a
commit
05df26e87c
7
pom.xml
7
pom.xml
|
@ -56,6 +56,13 @@
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
<version>1.2.83</version>
|
<version>1.2.83</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- 微信支付API -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.wxpay</groupId>
|
||||||
|
<artifactId>wxpay-sdk</artifactId>
|
||||||
|
<version>0.0.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.bigdata.wxappserver.config;
|
||||||
|
|
||||||
|
import com.github.wxpay.sdk.WXPayConfig;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @Author: Cool
|
||||||
|
* @Date: 2024/08/31/20:53
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
public class WxPayConfig implements WXPayConfig {
|
||||||
|
|
||||||
|
private byte[] certData;
|
||||||
|
|
||||||
|
public void MyConfig() throws Exception {
|
||||||
|
//此处暂时用不到,这里是读取证书的地方
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppID() {
|
||||||
|
return "这里是你的appid";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMchID() {
|
||||||
|
//申请普通商户时分配给你的商户号
|
||||||
|
return "这里是你的商户号";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
//这里的key 就是你在支付平台设置的API密钥
|
||||||
|
return "这是就是你的Key了";
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream getCertStream() {
|
||||||
|
ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
|
||||||
|
return certBis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHttpConnectTimeoutMs() {
|
||||||
|
return 8000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHttpReadTimeoutMs() {
|
||||||
|
return 10000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.bigdata.wxappserver.dto;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.bigdata.wxappserver.entity.Base;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA.
|
||||||
|
*
|
||||||
|
* @Author: Cool
|
||||||
|
* @Date: 2024/09/01/2:23
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class OrderDto extends Base {
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private Integer userId;
|
||||||
|
private Integer goodsId;
|
||||||
|
private String address;
|
||||||
|
private LocalDateTime deliveryTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单状态 @see
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
private String statusDescription;
|
||||||
|
/**
|
||||||
|
* 购买数量
|
||||||
|
*/
|
||||||
|
private Integer num;
|
||||||
|
/**
|
||||||
|
* 商品规格
|
||||||
|
*/
|
||||||
|
private String specs;
|
||||||
|
/**
|
||||||
|
* 商品名称
|
||||||
|
*/
|
||||||
|
private String goodName;
|
||||||
|
/**
|
||||||
|
* 商品价格
|
||||||
|
*/
|
||||||
|
private BigDecimal goodPrice;
|
||||||
|
/**
|
||||||
|
* 商品图片路径
|
||||||
|
*/
|
||||||
|
private String goodImage;
|
||||||
|
/**
|
||||||
|
* 商品描述
|
||||||
|
*/
|
||||||
|
private String goodDetail;
|
||||||
|
|
||||||
|
}
|
|
@ -3,17 +3,21 @@ package com.bigdata.wxappserver.service;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.bigdata.wxappserver.dto.OrderDto;
|
||||||
|
import com.bigdata.wxappserver.entity.Goods;
|
||||||
import com.bigdata.wxappserver.entity.Order;
|
import com.bigdata.wxappserver.entity.Order;
|
||||||
import com.bigdata.wxappserver.entity.User;
|
import com.bigdata.wxappserver.entity.User;
|
||||||
import com.bigdata.wxappserver.enums.OrderStatusEnum;
|
import com.bigdata.wxappserver.enums.OrderStatusEnum;
|
||||||
import com.bigdata.wxappserver.mapper.OrderMapper;
|
import com.bigdata.wxappserver.mapper.OrderMapper;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
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 org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA.
|
* Created with IntelliJ IDEA.
|
||||||
|
@ -28,6 +32,8 @@ public class OrderService extends ServiceImpl<OrderMapper, Order> {
|
||||||
@Autowired
|
@Autowired
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
GoodsService goodsService;
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public JSONObject addOrUpdate(JSONObject jsonObject) {
|
public JSONObject addOrUpdate(JSONObject jsonObject) {
|
||||||
Order order = jsonObject.toJavaObject(Order.class);
|
Order order = jsonObject.toJavaObject(Order.class);
|
||||||
|
@ -52,20 +58,34 @@ public class OrderService extends ServiceImpl<OrderMapper, Order> {
|
||||||
wrapper.eq(userId != null, Order::getUserId, userId);
|
wrapper.eq(userId != null, Order::getUserId, userId);
|
||||||
// IPage<Order> orderIPage = page(page, wrapper);
|
// IPage<Order> orderIPage = page(page, wrapper);
|
||||||
List<Order> list = list(wrapper);
|
List<Order> list = list(wrapper);
|
||||||
dealList(list);
|
List<OrderDto> orderDtoList = dealList(list);
|
||||||
JSONObject returnData = new JSONObject();
|
JSONObject returnData = new JSONObject();
|
||||||
returnData.fluentPut("data", list);
|
returnData.fluentPut("data", orderDtoList);
|
||||||
return returnData;
|
return returnData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dealList(List<Order> records) {
|
private List<OrderDto> dealList(List<Order> records) {
|
||||||
if (CollectionUtils.isEmpty(records)) {
|
if (CollectionUtils.isEmpty(records)) {
|
||||||
return;
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
List<Goods> goodsList = goodsService.listByIds(records.stream().map(Order::getGoodsId).collect(Collectors.toSet()));
|
||||||
|
Set<Goods> goodsSet =new HashSet<>(goodsList);
|
||||||
|
List<OrderDto> list =new ArrayList<>();
|
||||||
for (Order record : records) {
|
for (Order record : records) {
|
||||||
|
OrderDto orderDto=new OrderDto();
|
||||||
record.setStatusDescription(OrderStatusEnum.describe(record.getStatus()));
|
record.setStatusDescription(OrderStatusEnum.describe(record.getStatus()));
|
||||||
|
BeanUtils.copyProperties(record,orderDto);
|
||||||
|
Goods goods = goodsSet.stream().filter(item -> Objects.equals(item.getId(), record.getGoodsId()))
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
if(goods!=null){
|
||||||
|
orderDto.setGoodDetail(goods.getGoodDetail());
|
||||||
|
orderDto.setGoodPrice(goods.getGoodPrice());
|
||||||
|
orderDto.setGoodImage(goods.getGoodImage());
|
||||||
|
orderDto.setGoodName(goods.getGoodName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public JSONObject queryById(Integer id) {
|
public JSONObject queryById(Integer id) {
|
||||||
|
@ -73,8 +93,8 @@ public class OrderService extends ServiceImpl<OrderMapper, Order> {
|
||||||
return new JSONObject().fluentPut("success", false).fluentPut("message", "缺少ID");
|
return new JSONObject().fluentPut("success", false).fluentPut("message", "缺少ID");
|
||||||
}
|
}
|
||||||
Order order = getById(id);
|
Order order = getById(id);
|
||||||
dealList(Collections.singletonList(order));
|
List<OrderDto> orderDtoList = dealList(Collections.singletonList(order));
|
||||||
return new JSONObject().fluentPut("data", order);
|
return new JSONObject().fluentPut("data", orderDtoList.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue