ruoyi-api/ruoyi-api-order/src/main/java/com/ruoyi/order/api/factory/ShoppingOrderFallbackFactory.java
New file @@ -0,0 +1,31 @@ package com.ruoyi.order.api.factory; import com.ruoyi.order.api.feignClient.ShoppingOrderClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; /** * 充电订单服务降级处理 * * @author ruoyi */ @Component public class ShoppingOrderFallbackFactory implements org.springframework.cloud.openfeign.FallbackFactory<ShoppingOrderClient> { private static final Logger log = LoggerFactory.getLogger(ShoppingOrderFallbackFactory.class); @Override public ShoppingOrderClient create(Throwable cause) { log.error("调用失败:{}", cause.getMessage()); return new ShoppingOrderClient() { @Override public void cancelShoppingOrderWxRefund(String out_refund_no, String refund_id, String tradeState, String success_time) { log.error("商城订单去掉退款回调通知失败:" + cause.getMessage()); } }; } } ruoyi-api/ruoyi-api-order/src/main/java/com/ruoyi/order/api/feignClient/ShoppingOrderClient.java
New file @@ -0,0 +1,29 @@ package com.ruoyi.order.api.feignClient; import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.order.api.factory.ShoppingOrderFallbackFactory; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; /** * @author zhibing.pu * @Date 2024/9/29 16:23 */ @FeignClient(contextId = "ShoppingOrderClient", value = ServiceNameConstants.ORDER_SERVICE, fallbackFactory = ShoppingOrderFallbackFactory.class) public interface ShoppingOrderClient { /** * 商城订单去掉退款回调通知 * @param out_refund_no * @param refund_id * @param tradeState * @param success_time */ @PostMapping("/t-shopping-order/cancelShoppingOrderWxRefund") void cancelShoppingOrderWxRefund(@RequestParam("out_refund_no") String out_refund_no, @RequestParam("refund_id") String refund_id, @RequestParam("tradeState") String tradeState, @RequestParam("success_time") String success_time); } ruoyi-api/ruoyi-api-order/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -3,4 +3,5 @@ com.ruoyi.order.api.factory.ExchangeOrderFallbackFactory com.ruoyi.order.api.factory.ChargingOrderAccountingStrategyFallbackFactory com.ruoyi.order.api.factory.AccountingStrategyDetailOrderFallbackFactory com.ruoyi.order.api.factory.AccountingStrategyOrderFallbackFactory com.ruoyi.order.api.factory.AccountingStrategyOrderFallbackFactory com.ruoyi.order.api.factory.ShoppingOrderFallbackFactory ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/PartnerServiceImpl.java
@@ -97,7 +97,7 @@ if(null != roleId){ continue; } SysRole sysRole = data.stream().filter(s -> roleId.equals(s.getRoleId())).findFirst().get(); SysRole sysRole = data.stream().filter(s -> roleId.compareTo(s.getRoleId().intValue()) == 0).findFirst().get(); if(null != sysRole){ partnerListDTO.setRoleName(sysRole.getRoleName()); } ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TShoppingOrderController.java
@@ -265,6 +265,7 @@ return AjaxResult.error("订单已取消,不允许操作。"); } shoppingOrder.setStatus(3); shoppingOrder.setReceivingTime(LocalDateTime.now()); shoppingOrderService.updateById(shoppingOrder); return AjaxResult.success(); } @@ -280,15 +281,11 @@ * 商城订单取消微信退款回调 */ @PostMapping("/cancelShoppingOrderWxRefund") public void cancelShoppingOrderWxRefund(HttpServletRequest request) { // WxRefundNotifyResp data = wxPaymentClient.refundNotify(request).getData(); // if (null != data) { // String out_refund_no = data.getOut_refund_no(); // String refund_id = data.getRefund_id(); // String tradeState = data.getTradeState(); // String success_time = data.getSuccess_time(); // shoppingOrderService.cancelShoppingOrderWxRefund(out_refund_no, refund_id, tradeState, success_time); // } public void cancelShoppingOrderWxRefund(@RequestParam("out_refund_no") String out_refund_no, @RequestParam("refund_id") String refund_id, @RequestParam("tradeState") String tradeState, @RequestParam("success_time") String success_time) { shoppingOrderService.cancelShoppingOrderWxRefund(out_refund_no, refund_id, tradeState, success_time); } ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TShoppingOrderServiceImpl.java
@@ -364,6 +364,9 @@ shoppingOrderRefund.setRefundRemark("全额退款"); shoppingOrderRefund.setRefundTotalAmount(refundAmount.add(bigDecimal)); shoppingOrderRefund.setPayAmount(shoppingOrder.getPaymentAmount()); shoppingOrder.setCancellationTime(LocalDateTime.now()); shoppingOrder.setCancellationId(shoppingOrder.getAppUserId()); if(1 == paymentType){ WxPaymentRefundModel model = new WxPaymentRefundModel(); model.setOut_trade_no(shoppingOrder.getCode()); @@ -378,6 +381,7 @@ model.setAmount(amount); R<String> orderR = wxPaymentClient.refundOrderR(model); if(200 == orderR.getCode()){ this.updateById(shoppingOrder); shoppingOrderRefundService.save(shoppingOrderRefund); } } @@ -389,49 +393,9 @@ dto.setRefundReason("取消订单"); RefundResp resp = aliPaymentClient.refund(dto).getData(); if(null != resp){ this.updateById(shoppingOrder); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-DDTHH:mm:ss+TIMEZONE"); AjaxResult success = cancelShoppingOrderWxRefund(resp.getOutTradeNo(), resp.getTradeNo(), "SUCCESS", sdf1.format(new Date())); if(success.isSuccess()){ shoppingOrderRefundService.save(shoppingOrderRefund); //商品 if(shoppingOrder.getOrderType() == 1){ //redis锁 和支付使用同一个锁 RedisLock redisLock = new RedisLock(redisTemplate, "SHOPPING_GOODS_LOCK", 5, 30000); try { redisLock.lock(); TGoods goods = goodsClient.getGoodsById(shoppingOrder.getGoodsId()).getData(); Integer inventory = goods.getInventory(); if(-1 != inventory){ goods.setInventory(inventory + shoppingOrder.getPurchaseQuantity()); goodsClient.updateGoods(goods); } }catch (Exception e){ e.printStackTrace(); }finally { //解锁 redisLock.unlock(); } } //优惠券 if(shoppingOrder.getOrderType() == 2){ //redis锁 和支付使用同一个锁 RedisLock redisLock = new RedisLock(redisTemplate, "SHOPPING_COUPON_LOCK", 5, 30000); try { redisLock.lock(); TCoupon coupon = couponClient.getCouponById1(shoppingOrder.getCouponId()).getData(); Integer inventory = coupon.getInventoryQuantity(); if(-1 != inventory){ coupon.setInventoryQuantity(inventory + shoppingOrder.getPurchaseQuantity()); couponClient.updateCoupon(coupon); } }catch (Exception e){ e.printStackTrace(); }finally { //解锁 redisLock.unlock(); } } } } } return AjaxResult.success(); @@ -457,6 +421,13 @@ shoppingOrderRefundService.updateById(one); //判断是否需要回退库存 TShoppingOrder shoppingOrder = this.getById(one.getShoppingOrderId()); shoppingOrder.setStatus(4); shoppingOrder.setRefundCode(one.getRefundSerialNumber()); shoppingOrder.setRefundAmount(one.getRefundAmount()); shoppingOrder.setRefundStatus(2); shoppingOrder.setRefundTime(one.getRefundTime()); this.updateById(shoppingOrder); //商品 if(shoppingOrder.getOrderType() == 1){ //redis锁 和支付使用同一个锁 ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml
@@ -62,7 +62,7 @@ </if> </select> <select id="getNoInvoicedOrder" resultMap="BaseResultMap"> select * from t_charging_order where del_flag = 0 and app_user_id = #{appUserId} select * from t_charging_order where del_flag = 0 and status = 5 and recharge_payment_status = 2 and payment_amount is null and app_user_id = #{appUserId} <if test="null != month and '' != month"> and DATE_FORMAT(end_time, '%Y-%m') = #{month} </if> ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TShoppingOrderMapper.xml
@@ -214,7 +214,7 @@ <select id="getNoInvoicedOrder" resultMap="BaseResultMap"> select * from t_shopping_order where del_flag = 0 and app_user_id = #{appUserId} select * from t_shopping_order where del_flag = 0 and payment_status = 2 and status = 3 and app_user_id = #{appUserId} <if test="null != month and '' != month"> and DATE_FORMAT(create_time, '%Y-%m') = #{month} </if> ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/controller/WxPayController.java
@@ -5,6 +5,7 @@ import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.order.api.feignClient.ChargingOrderClient; import com.ruoyi.order.api.feignClient.OrderClient; import com.ruoyi.order.api.feignClient.ShoppingOrderClient; import com.ruoyi.payment.api.vo.PaymentOrder; import com.ruoyi.payment.api.vo.WxRefundNotifyResp; import com.ruoyi.payment.wx.enums.RefundEnum; @@ -41,6 +42,9 @@ @Resource private ChargingOrderClient chargingOrderClient; @Resource private ShoppingOrderClient shoppingOrderClient; @@ -196,6 +200,10 @@ chargingOrderClient.chargingOrderStartupFailureWxRefund(out_refund_no, refund_id, tradeState, success_time); System.err.println("----充电启动失败退款回调通知"); break; case "GDF": shoppingOrderClient.cancelShoppingOrderWxRefund(out_refund_no, refund_id, tradeState, success_time); System.err.println("----商城订单取消退款回调通知"); break; } WxRefundNotifyResp resp = new WxRefundNotifyResp();