fix[订单服务]:新增订单号查询景区素材,设备序号的逻辑

This commit is contained in:
2025-02-27 16:18:44 +08:00
parent 6a8c66618a
commit ad08065cf1
14 changed files with 219 additions and 117 deletions
@@ -4,10 +4,10 @@ server:
spring:
application:
name: device-center
# cloud:
# nacos:
# discovery:
# ip: 81.70.164.178
cloud:
nacos:
discovery:
ip: 119.45.169.13
# cloud:
# nacos:
# discovery:
@@ -15,10 +15,8 @@ import com.central.order.feign.UserCenterService;
import com.central.order.model.Order;
import com.central.order.model.OrderFile;
import com.central.order.model.QrCode;
import com.central.order.service.IOrderFileService;
import com.central.order.service.IOrderService;
import com.central.order.service.IQrCodeService;
import com.central.order.service.ITourismService;
import com.central.order.model.TourismFile;
import com.central.order.service.*;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
@@ -66,6 +64,9 @@ public class OrderController {
@Autowired
private ITourismService tourismService;
@Autowired
private ITourismFileService tourismFileService;
@Autowired
private UserCenterService userCenterService;
@@ -363,6 +364,30 @@ public class OrderController {
return Result.failed("不满足执行条件");
}
@Operation(summary = "获取订单对应的景区素材")
@GetMapping("/tourism/{orderNo}")
public Result<List<TourismFile>> getTourismByOrder(@PathVariable("orderNo") String orderNo) {
Order order = orderService.getOrderByNumber(orderNo);
Assert.notNull(order,"订单数据不存在");
List<TourismFile> tourismFiles = tourismFileService.getByTourismId(order.getTourismId());
if (!tourismFiles.isEmpty()){
for (TourismFile tourismFile : tourismFiles){
tourismFile.setImageUrl(fileCenterService.getViewUrlByPath(tourismFile.getImageUrl()));
}
}
return Result.succeed(tourismFiles,"获取成功");
}
@Operation(summary = "获取订单的设备")
@GetMapping("/device/{orderNo}")
public Result<String> getDeviceByOrder(@PathVariable("orderNo") String orderNo) {
Order order = orderService.getOrderByNumber(orderNo);
Assert.notNull(order,"订单数据不存在");
return Result.succeed(order.getDeviceSn(),"获取成功");
}
/**
* 将分的价格转换为元的str,方便前端显示
* @param str
@@ -15,6 +15,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
@@ -25,7 +26,7 @@ import java.util.Map;
@RestController
@RequestMapping("/refund")
public class OrderRefundController {
public class RefundController {
@Autowired
private RefundService service;
@@ -63,6 +64,10 @@ public class OrderRefundController {
// 创建退款订单
com.central.order.model.Refund refund = new com.central.order.model.Refund();
refund.setRefundNo("RF" + order.getOrderNo());
com.central.order.model.Refund existRefund = refundService.getRefundByNo(refund.getRefundNo());
if (existRefund != null){
return Result.succeed("已提交");
}
refund.setOrderNo(order.getOrderNo());
refund.setUserId(order.getUserId());
refund.setOrderAmount(order.getOrderAmount());
@@ -72,22 +77,43 @@ public class OrderRefundController {
boolean res = refundService.createRefund(refund);
if (res) {
order.setOrderStatus(OrderStatus.REFUNDING.getId());
orderService.updateOrder(order);
return Result.succeed("退款成功");
}
return Result.failed("请重试");
}
@Operation(summary = "微信支付退款")
@PatchMapping()
@PostMapping("/approve")
@Transactional(rollbackFor = Exception.class)
public Result<com.central.order.model.Refund> refundOrder(@RequestBody String orderNo) {
public Result<com.central.order.model.Refund> approveOrder(@RequestBody com.central.order.model.Refund refund) {
// 检查订单是否存在
Order order = orderService.getOrderByNumber(refund.getOrderNo());
Assert.notNull(order, "ORDER DATA不存在");
if (!order.getOrderStatus().equals(OrderStatus.REFUNDING.getId())){
return Result.failed("请重试");
}
if (! refund.getStatus().equals(OrderStatus.REFUNDING.getId())){
return Result.failed("该状态不支持审核");
}
if (refund.getState().equals(RefundState.APPROVED.getId())){
dealRefundRequest(order);
return Result.succeed("已处理退款");
}
if (refund.getState().equals(RefundState.REFUSED.getId())){
order.setOrderStatus(OrderStatus.REFUND_FAILED.getId());
refund.setStatus(OrderStatus.REFUND_FAILED.getId());
orderService.updateOrder(order);
refundService.updateById(refund);
return Result.succeed("处理成功");
}
return Result.failed("处理退款失败");
}
@NotNull
private Refund dealRefundRequest(Order order) {
try {
// 检查订单是否存在
Order order = orderService.getOrderByNumber(orderNo);
Assert.notNull(order, "ORDER DATA不存在");
if (!order.getOrderStatus().equals(OrderStatus.REFUNDING.getId())){
return Result.failed("请重试");
}
// 创建微信退款请求
CreateRequest request = new CreateRequest();
request.setOutTradeNo(order.getOrderNo());
@@ -102,17 +128,18 @@ public class OrderRefundController {
amount.setTotal(Long.valueOf(order.getOrderAmount()));
// 退款金额,单位为分
amount.setRefund(Long.valueOf(order.getOrderAmount()));
amount.setCurrency("CNY");
request.setAmount(amount);
// 发起退款请求
Refund response = service.create(request);
Assert.notNull(response, "退款失败");
return Result.succeed("已提交,请关注账户资金变化");
return response;
} catch (Exception e) {
// 记录异常信息
e.printStackTrace();
return Result.failed("退款失败:" + e.getMessage());
}
return null;
}
@@ -1,6 +1,7 @@
package com.central.order.controller;
import com.central.order.enums.OrderStatus;
import com.central.order.enums.RefundState;
import com.central.order.model.Order;
import com.central.order.service.IOrderService;
import com.central.order.service.IRefundService;
@@ -9,6 +10,7 @@ import com.wechat.pay.java.core.notification.NotificationParser;
import com.wechat.pay.java.core.notification.RequestParam;
import com.wechat.pay.java.service.payments.model.Transaction;
import com.wechat.pay.java.service.refund.model.RefundNotification;
import com.wechat.pay.java.service.refund.model.Status;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -134,14 +136,15 @@ public class WxPayController {
private void handleRefundResult(RefundNotification notification) {
// 获取退款通知中的关键信息
String outRefundNo = notification.getOutRefundNo();
String refundStatus = notification.getRefundStatus().name();
log.info("回调返回结果"+notification);
// 根据退款状态进行相应处理
if ("SUCCESS".equals(refundStatus)) {
if (Status.SUCCESS.equals(notification.getRefundStatus())) {
// 退款成功,更新订单状态等操作
com.central.order.model.Refund refund = refundService.getRefundByNo(outRefundNo);
Assert.notNull(refund,"退款订单数据不存在");
refund.setStatus(OrderStatus.REFUNDED.getId());
refund.setState(RefundState.APPROVED.getId());
refund.setRefundTime(new Date());
refundService.updateById(refund);
@@ -149,7 +152,7 @@ public class WxPayController {
Assert.notNull(order,"订单数据不存在");
order.setOrderStatus(OrderStatus.REFUNDED.getId());
orderService.updateOrder(order);
} else if ("CLOSED".equals(refundStatus)) {
} else if ("CLOSED".equals(notification.getRefundStatus())) {
// 退款关闭,处理退款关闭逻辑
} else {
// 其他退款状态,如退款中、失败等
@@ -13,9 +13,9 @@ public enum OrderStatus implements ZltEnum {
PAID(1, "已支付排队中"),
CANCELED(2, "已取消"),
DOING(4,"正在服务中"),
COMPLETE(3,"用户下载完成"),
COMPLETE(3,"设备执行完成"),
UPLOADING(5,"素材上传中"),
UPLOADED(6,"素材上传完成"),
UPLOADED(6,"素材上传完成(任务完成)"),
REFUNDING(7,"退款中"),
REFUNDED(8,"已退款"),
REFUND_FAILED(9,"退款失败");
@@ -4,10 +4,10 @@ server:
spring:
application:
name: order-center
# cloud:
# nacos:
# discovery:
# ip: 81.70.164.178
cloud:
nacos:
discovery:
ip: 81.70.164.178
# cloud:
# nacos:
# discovery: