Bladeren bron

与en+开发约定使用接口:query_equip_charge_status 更新正在充电中的订单的金额信息,解决充电过程中用户充值续充场景

skyline 2 jaren geleden
bovenliggende
commit
1d9dffc17a

+ 2 - 0
service/src/main/java/com/kym/service/enplus/EnPlusService.java

@@ -26,5 +26,7 @@ public interface EnPlusService {
 
     JSONObject queryEquipChargeStatus(String startChargeSeq);
 
+    JSONObject updateBalanceByQueryEquipChargeStatus(String startChargeSeq, int amount);
+
     JSONObject queryStopCharge(String startChargeSeq, String connectorId);
 }

+ 19 - 0
service/src/main/java/com/kym/service/enplus/impl/EnPlusServiceImpl.java

@@ -287,6 +287,25 @@ public class EnPlusServiceImpl implements EnPlusService {
         return JSONObject.parseObject(AESUtil.decrypt(response.getData()));
     }
 
+    /**
+     * 与en+开发约定使用该接口更新正在充电中的订单的金额信息,解决充电过程中用户充值续充场景
+     *
+     * @param startChargeSeq
+     * @param amount
+     * @return
+     */
+    @Override
+    public JSONObject updateBalanceByQueryEquipChargeStatus(String startChargeSeq, int amount) {
+        var param = """
+                {
+                    "StartChargeSeq":"%s",
+                    "amount":%d
+                }
+                """.formatted(startChargeSeq, amount);
+        var response = enPlusPost(EnPlusApi.EN_PLUS_QUERY_EQUIP_CHARGE_STATUS.getApi(), buildParams(param));
+        return JSONObject.parseObject(AESUtil.decrypt(response.getData()));
+    }
+
     /**
      * 请求停止充电
      *

+ 13 - 1
service/src/main/java/com/kym/service/wechat/impl/WxPayServiceImpl.java

@@ -19,6 +19,7 @@ import com.kym.common.utils.OrderUtils;
 import com.kym.entity.miniapp.Account;
 import com.kym.entity.miniapp.*;
 import com.kym.entity.wechat.*;
+import com.kym.service.enplus.EnPlusService;
 import com.kym.service.miniapp.*;
 import com.kym.service.wechat.WxPayService;
 import com.wechat.pay.java.core.Config;
@@ -94,13 +95,15 @@ public class WxPayServiceImpl implements WxPayService {
 
     private final InvoiceTitleService invoiceTitleService;
 
+    private final EnPlusService enPlusService;
+
     /**
      * 微信支付专用,支持自动签名验签解密等
      */
     private OkHttpClientAdapter wxHttpClient;
 
 
-    public WxPayServiceImpl(WxPayConfig conf, WxFapiaoConfig fapiaoConfig, WalletDetailService walletDetailService, PayLogService payLogService, AccountService accountService, ChargeOrderService chargeOrderService, RefundLogService refundLogService, InvoiceService invoiceService, InvoiceTitleService invoiceTitleService) {
+    public WxPayServiceImpl(WxPayConfig conf, WxFapiaoConfig fapiaoConfig, WalletDetailService walletDetailService, PayLogService payLogService, AccountService accountService, ChargeOrderService chargeOrderService, RefundLogService refundLogService, InvoiceService invoiceService, InvoiceTitleService invoiceTitleService, EnPlusService enPlusService) {
         this.conf = conf;
         this.fapiaoConfig = fapiaoConfig;
         this.walletDetailService = walletDetailService;
@@ -110,6 +113,7 @@ public class WxPayServiceImpl implements WxPayService {
         this.refundLogService = refundLogService;
         this.invoiceService = invoiceService;
         this.invoiceTitleService = invoiceTitleService;
+        this.enPlusService = enPlusService;
     }
 
     /**
@@ -318,6 +322,14 @@ public class WxPayServiceImpl implements WxPayService {
                 payLogService.save(payLog);
                 LOGGER.info("微信支付回调{}:业务处理结束", notifyRes[2]);
 
+                // 如果存在进行中的订单,则向en+更新用户余额
+                var chargingOrder = chargeOrderService.getChargingOrderByUserId(walletDetail.getUserId());
+                if (chargingOrder != null) {
+                    var account = accountService.getAccountByUserId(walletDetail.getUserId());
+                    var res = enPlusService.updateBalanceByQueryEquipChargeStatus(chargingOrder.getStartChargeSeq(), account.getBalance() - 50);
+                    LOGGER.info("用户:{}充电过程中充值,已更新en+充电金额,en+返回数据:{}", account.getUserId(), res);
+                }
+
             } else {
                 LOGGER.error("微信支付通知处理异常,资金流水为空,回调信息:{}", transaction);
 //                return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR);