diff --git a/hai-order/src/main/java/com/web/controller/OrderController.java b/hai-order/src/main/java/com/web/controller/OrderController.java index b27a712a..f6e70131 100644 --- a/hai-order/src/main/java/com/web/controller/OrderController.java +++ b/hai-order/src/main/java/com/web/controller/OrderController.java @@ -20,6 +20,7 @@ import com.hai.order.service.OrderService; import com.hai.order.type.OrderChildGoodsType; import com.hai.order.type.OrderChildStatus; import com.hai.order.type.OrderPayType; +import com.hai.order.type.OrderStatus; import com.hai.order.utils.OrderUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -132,7 +133,13 @@ public class OrderController { String orderNo = body.getString("orderNo"); String remarks = body.getString("remarks"); - return ResponseMsgUtil.success(orderService.cancelOrder(orderNo, remarks)); + + // 查询订单 + HighOrder order = orderService.getOrderDetailByNo(orderNo); + if (order == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单"); + } + return ResponseMsgUtil.success(orderService.cancelOrder(order, remarks)); } catch (Exception e) { log.error("OrderController -> cancel() error!",e); diff --git a/hai-order/src/main/java/com/web/controller/OrderPayController.java b/hai-order/src/main/java/com/web/controller/OrderPayController.java index 4de25d6c..1828ad0d 100644 --- a/hai-order/src/main/java/com/web/controller/OrderPayController.java +++ b/hai-order/src/main/java/com/web/controller/OrderPayController.java @@ -55,7 +55,7 @@ import java.util.concurrent.ThreadLocalRandom; @Controller @RequestMapping("/orderPay") @Api(value = "订单支付") -public class OrderPayController { +public class OrderPayController { private static Logger log = LoggerFactory.getLogger(OrderPayController.class); diff --git a/hai-order/src/main/java/com/web/controller/OrderRefundController.java b/hai-order/src/main/java/com/web/controller/OrderRefundController.java index fd48b246..5d1ae6e7 100644 --- a/hai-order/src/main/java/com/web/controller/OrderRefundController.java +++ b/hai-order/src/main/java/com/web/controller/OrderRefundController.java @@ -12,6 +12,7 @@ import com.hai.common.utils.ResponseMsgUtil; import com.hai.entity.HighChildOrder; import com.hai.entity.HighOrder; import com.hai.entity.HighOrderRefund; +import com.hai.enum_type.OrderStatusEnum; import com.hai.model.HighUserModel; import com.hai.model.ResponseData; import com.hai.order.model.CreateOrderChildModel; @@ -21,10 +22,7 @@ import com.hai.order.model.ExportOrderRefundModel; import com.hai.order.service.OrderPaySuccessService; import com.hai.order.service.OrderRefundService; import com.hai.order.service.OrderService; -import com.hai.order.type.OrderChildGoodsType; -import com.hai.order.type.OrderChildStatus; -import com.hai.order.type.OrderPayType; -import com.hai.order.type.OrderRefundStatus; +import com.hai.order.type.*; import com.hai.order.utils.OrderUtil; import com.web.config.SysConst; import io.swagger.annotations.Api; @@ -72,7 +70,16 @@ public class OrderRefundController { if (body == null || StringUtils.isBlank(body.getString("orderNo"))) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单"); } - orderService.refundOrder(body.getString("orderNo"), body.getString("remarks")); + // 查询订单 + HighOrder order = orderService.getOrderDetailByNo(body.getString("orderNo")); + if (order == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单"); + } + if (!order.getOrderStatus().equals(OrderStatus.STATUS2.getNumber()) + && !order.getOrderStatus().equals(OrderStatus.STATUS3.getNumber())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "订单状态错误"); + } + orderService.refundOrder(order, body.getString("remarks")); return ResponseMsgUtil.success("退款成功"); @@ -122,7 +129,6 @@ public class OrderRefundController { if (userModel == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.USE_VISIT_ILLEGAL, ""); } - return ResponseMsgUtil.success(orderRefundService.getRefundByRefundNo(refundOrderNo)); } catch (Exception e) { diff --git a/hai-order/src/main/java/com/web/controller/TestController.java b/hai-order/src/main/java/com/web/controller/TestController.java index 26f9fbf9..58b9019d 100644 --- a/hai-order/src/main/java/com/web/controller/TestController.java +++ b/hai-order/src/main/java/com/web/controller/TestController.java @@ -1 +1 @@ -package com.web.controller; import com.alibaba.fastjson.JSONObject; import com.hai.common.utils.*; import com.hai.config.HuiLianTongConfig; import com.hai.config.HuiLianTongUnionCardConfig; import com.hai.entity.HighOrder; import com.hai.model.ResponseData; import com.hai.order.model.CreateOrderModel; import com.hai.order.service.OrderService; import com.hai.order.type.OrderStatus; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.rocketmq.client.producer.SendCallback; import org.apache.rocketmq.client.producer.SendResult; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.integration.support.MessageBuilder; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Date; import java.util.LinkedList; import java.util.List; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/test") @Api(value = "订单接口") public class TestController { private static Logger log = LoggerFactory.getLogger(TestController.class); @Autowired private RocketMQTemplate rocketMQTemplate; @Resource private OrderService orderService; @Resource private RedisUtil redisUtil; @Autowired private RedisTemplate redisTemplate; @RequestMapping(value = "/q", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "") public ResponseData q(@RequestParam(name = "orderNo", required = true) String orderNo) { try { HighOrder order = orderService.getOrderDetailByNo(orderNo); if (order != null) { orderService.refundOrder(orderNo, DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss")); // order.setRefundTime(new Date()); // orderService.updateOrderData(order); return ResponseMsgUtil.success("修改成功"); } return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighUserCardController --> rocketMq() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/rocketMq", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "") public ResponseData rocketMq(@RequestParam(name = "topicGroup", required = true) String topicGroup, @RequestParam(name = "body", required = true) String body) { try { long startTime = System.currentTimeMillis(); // org.springframework.messaging.Message message = MessageBuilder.withPayload(order).build(); CreateOrderModel createOrder = new CreateOrderModel(); //发送对象消息 HighOrder order = rocketMQTemplate.sendAndReceive("order-topic:create", createOrder, HighOrder.class); System.out.println("订单号:" + order.getOrderNo()); // SendResult sendResult = rocketMQTemplate.syncSend("order-topic:create", message, 3000); /*List list = new LinkedList<>(); for (int i = 0; i <= 100;i++) { list.add(orderService.getDetailByOrderNo("HF2022080918014365701")); *//* list.add(orderService.getDetailByOrderNo("HF2022080918014365701"));*//* *//* updateUserWithRedisLock("coupon_" + couponKey, i+""); new Thread(() -> {*//* *//* redisTemplate.opsForValue().setIfAbsent("coupon_" + couponKey, i); System.out.println("加入数据" + i);*//* // redisTemplate.delete("coupon" + couponKey); // System.out.println("释放数据" + index); *//* });*//* }*/ System.out.println(System.currentTimeMillis() - startTime); return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighUserCardController --> rocketMq() error!", e); return ResponseMsgUtil.exception(e); } } public void updateUserWithRedisLock(String couponKey, String value) throws InterruptedException { // 占分布式锁,去redis占坑 // 1. 分布式锁占坑 Boolean lock = redisTemplate.opsForValue().setIfAbsent("coupon" + couponKey, value); if(lock) { //加锁成功... // todo business System.out.println("加锁成功: " + value); redisTemplate.delete("coupon" + couponKey); //删除key,释放锁 } else { System.out.println("加锁失败"); /* Thread.sleep(100); // 加锁失败,重试 updateUserWithRedisLock("sysUser");*/ } } } \ No newline at end of file +package com.web.controller; import com.alibaba.fastjson.JSONObject; import com.hai.common.utils.*; import com.hai.config.HuiLianTongConfig; import com.hai.config.HuiLianTongUnionCardConfig; import com.hai.entity.HighOrder; import com.hai.model.ResponseData; import com.hai.order.model.CreateOrderModel; import com.hai.order.service.OrderService; import com.hai.order.type.OrderStatus; import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.rocketmq.client.producer.SendCallback; import org.apache.rocketmq.client.producer.SendResult; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.integration.support.MessageBuilder; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Date; import java.util.LinkedList; import java.util.List; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/test") @Api(value = "订单接口") public class TestController { private static Logger log = LoggerFactory.getLogger(TestController.class); @Autowired private RocketMQTemplate rocketMQTemplate; @Resource private OrderService orderService; @Resource private RedisUtil redisUtil; @Autowired private RedisTemplate redisTemplate; @RequestMapping(value = "/q", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "") public ResponseData q(@RequestParam(name = "orderNo", required = true) String orderNo) { try { HighOrder order = orderService.getOrderDetailByNo(orderNo); if (order != null) { // orderService.refundOrder(orderNo, DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss")); // order.setRefundTime(new Date()); // orderService.updateOrderData(order); return ResponseMsgUtil.success("修改成功"); } return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighUserCardController --> rocketMq() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/rocketMq", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "") public ResponseData rocketMq(@RequestParam(name = "topicGroup", required = true) String topicGroup, @RequestParam(name = "body", required = true) String body) { try { long startTime = System.currentTimeMillis(); // org.springframework.messaging.Message message = MessageBuilder.withPayload(order).build(); CreateOrderModel createOrder = new CreateOrderModel(); //发送对象消息 HighOrder order = rocketMQTemplate.sendAndReceive("order-topic:create", createOrder, HighOrder.class); System.out.println("订单号:" + order.getOrderNo()); // SendResult sendResult = rocketMQTemplate.syncSend("order-topic:create", message, 3000); /*List list = new LinkedList<>(); for (int i = 0; i <= 100;i++) { list.add(orderService.getDetailByOrderNo("HF2022080918014365701")); *//* list.add(orderService.getDetailByOrderNo("HF2022080918014365701"));*//* *//* updateUserWithRedisLock("coupon_" + couponKey, i+""); new Thread(() -> {*//* *//* redisTemplate.opsForValue().setIfAbsent("coupon_" + couponKey, i); System.out.println("加入数据" + i);*//* // redisTemplate.delete("coupon" + couponKey); // System.out.println("释放数据" + index); *//* });*//* }*/ System.out.println(System.currentTimeMillis() - startTime); return ResponseMsgUtil.success(null); } catch (Exception e) { log.error("HighUserCardController --> rocketMq() error!", e); return ResponseMsgUtil.exception(e); } } public void updateUserWithRedisLock(String couponKey, String value) throws InterruptedException { // 占分布式锁,去redis占坑 // 1. 分布式锁占坑 Boolean lock = redisTemplate.opsForValue().setIfAbsent("coupon" + couponKey, value); if(lock) { //加锁成功... // todo business System.out.println("加锁成功: " + value); redisTemplate.delete("coupon" + couponKey); //删除key,释放锁 } else { System.out.println("加锁失败"); /* Thread.sleep(100); // 加锁失败,重试 updateUserWithRedisLock("sysUser");*/ } } } \ No newline at end of file diff --git a/hai-order/src/main/java/com/web/controller/business/OrderOilController.java b/hai-order/src/main/java/com/web/controller/business/OrderOilController.java index 07418301..f143fba6 100644 --- a/hai-order/src/main/java/com/web/controller/business/OrderOilController.java +++ b/hai-order/src/main/java/com/web/controller/business/OrderOilController.java @@ -311,7 +311,7 @@ public class OrderOilController { model.setDeductionCouponPrice(gasOrder.getDeductionCouponPrice()); model.setDeductionProductPrice(gasOrder.getDeductionProductPrice()); model.setPayablePrice(gasOrder.getPayablePrice()); - model.setPayGold(gasOrder.getPayGold()/100); + model.setPayGold(gasOrder.getPayGold()==null?null:gasOrder.getPayGold()/100); model.setPayPrice(gasOrder.getPayPrice()!=null?gasOrder.getPayPrice().toString():"未支付"); model.setStatus(OrderOilStatus.getNameByType(gasOrder.getStatus())); model.setCreateTime(gasOrder.getCreateTime()); diff --git a/hai-order/src/main/java/com/web/rocketmq/consumer/OrderCancelConsumer.java b/hai-order/src/main/java/com/web/rocketmq/consumer/OrderCancelConsumer.java index 3d83c4d7..a0acf6f0 100644 --- a/hai-order/src/main/java/com/web/rocketmq/consumer/OrderCancelConsumer.java +++ b/hai-order/src/main/java/com/web/rocketmq/consumer/OrderCancelConsumer.java @@ -23,7 +23,7 @@ public class OrderCancelConsumer implements RocketMQListener { HighOrder highOrder = orderService.getOrderDetailByNo(order.getOrderNo()); if (highOrder != null && highOrder.getOrderStatus().equals(OrderStatus.STATUS1.getNumber())) { // 取消订单 - orderService.cancelOrder(order.getOrderNo(), null); + orderService.cancelOrder(highOrder, null); } } } diff --git a/hai-service/src/main/java/com/hai/order/service/OrderService.java b/hai-service/src/main/java/com/hai/order/service/OrderService.java index 2488c41f..469ee012 100644 --- a/hai-service/src/main/java/com/hai/order/service/OrderService.java +++ b/hai-service/src/main/java/com/hai/order/service/OrderService.java @@ -38,19 +38,19 @@ public interface OrderService { /** * 订单取消 - * @param orderNo 订单号 + * @param order 订单 * @param remarks 备注 * @return */ - HighOrder cancelOrder(String orderNo,String remarks); + HighOrder cancelOrder(HighOrder order,String remarks); /** * 订单退款 - * @param orderNo + * @param order * @param remarks * @return */ - HighOrder refundOrder(String orderNo,String remarks) throws Exception; + HighOrder refundOrder(HighOrder order,String remarks) throws Exception; /** * 子订单退款 diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java index 26f2cff9..8b0c65ad 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java @@ -443,8 +443,8 @@ public class OrderServiceImpl implements OrderService { isolation = Isolation.READ_COMMITTED, timeout = 10, rollbackFor = Exception.class) - public HighOrder cancelOrder(String orderNo,String remarks) { - HighOrder order = getOrderDetailByNo(orderNo); + @CacheUpdate(name = "order:", key = "#order.orderNo", value = "#order") + public HighOrder cancelOrder(HighOrder order,String remarks) { if (!order.getOrderStatus().equals(OrderStatus.STATUS1.getNumber())) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "订单状态错误"); } @@ -497,8 +497,8 @@ public class OrderServiceImpl implements OrderService { isolation = Isolation.READ_COMMITTED, timeout = 10, rollbackFor = Exception.class) - public HighOrder refundOrder(String orderNo, String remarks) throws Exception { - HighOrder order = getOrderDetailByNo(orderNo); + @CacheUpdate(name = "order:", key = "#order.orderNo", value = "#order") + public HighOrder refundOrder(HighOrder order, String remarks) throws Exception { if (!order.getOrderStatus().equals(OrderStatus.STATUS2.getNumber()) && !order.getOrderStatus().equals(OrderStatus.STATUS3.getNumber())) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "订单状态错误");