Pu Zhibing
2025-01-22 2f30ea680b7867cc42681d8eff7b55f5fdf15201
修改bug
7个文件已修改
518 ■■■■■ 已修改文件
ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/model/TransactionRecord.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-order/src/main/java/com/ruoyi/order/api/vo/TransactionRecordMessageVO.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/model/TransactionRecordMessage.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/produce/ChargingMessageListener.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java 28 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/TChargingOrderService.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java 474 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/model/TransactionRecord.java
@@ -22,7 +22,7 @@
    private String end_time;// 结束时间
    private BigDecimal total_electricity;// 总电量
    private BigDecimal loss_total_electricity;// 计损总电量
    private BigDecimal pay_amount;// 消费金额
    private BigDecimal payment_amount;// 消费金额
    private Integer method;// 交易标识(1:app 启动,2:卡启动,4:离线卡启动,5: vin 码启动充电)
    private String trade_date;// 交易日期、时间
    private Integer stop_reason;// 停止原因
@@ -183,6 +183,7 @@
    private BigDecimal valley_charge12;// 谷电量
    private BigDecimal loss_valley_charge12;// 计损谷电量
    private BigDecimal valley_amount12;// 谷金额
    private String result;//原始字符串
}
ruoyi-api/ruoyi-api-order/src/main/java/com/ruoyi/order/api/vo/TransactionRecordMessageVO.java
@@ -18,7 +18,7 @@
    private String end_time;// 结束时间
    private BigDecimal total_electricity;// 总电量
    private BigDecimal loss_total_electricity;// 计损总电量
    private BigDecimal pay_amount;// 消费金额
    private BigDecimal payment_amount;// 消费金额
    private Integer method;// 交易标识(1:app 启动,2:卡启动,4:离线卡启动,5: vin 码启动充电)
    private String trade_date;// 交易日期、时间
    private Integer stop_reason;// 停止原因
@@ -167,6 +167,7 @@
    private BigDecimal valley_charge12;// 谷电量
    private BigDecimal loss_valley_charge12;// 计损谷电量
    private BigDecimal valley_amount12;// 谷金额
    private String result;//原始字符串
}
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/model/TransactionRecordMessage.java
@@ -21,7 +21,7 @@
    private String end_time;// 结束时间
    private BigDecimal total_electricity;// 总电量
    private BigDecimal loss_total_electricity;// 计损总电量
    private BigDecimal pay_amount;// 消费金额
    private BigDecimal payment_amount;// 消费金额
    private Integer method;// 交易标识(1:app 启动,2:卡启动,4:离线卡启动,5: vin 码启动充电)
    private String trade_date;// 交易日期、时间
    private Integer stop_reason;// 停止原因
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/produce/ChargingMessageListener.java
@@ -1,6 +1,7 @@
package com.ruoyi.integration.rocket.produce;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.chargingPile.api.feignClient.AccountingStrategyDetailClient;
import com.ruoyi.chargingPile.api.feignClient.ChargingGunClient;
import com.ruoyi.chargingPile.api.feignClient.ChargingPileClient;
@@ -325,6 +326,7 @@
            case SendTagConstant.TRANSACTION_RECORD:
                TransactionRecordMessage transactionRecordMessage = message.getTransactionRecordMessage();
                log.info("交易记录-业务消息处理:{}",transactionRecordMessage);
                transactionRecordMessage.setResult(JSONObject.toJSONString(message));
                // 持久化消息
                TransactionRecord transactionRecord = new TransactionRecord();
                BeanUtils.copyProperties(transactionRecordMessage,transactionRecord);
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java
@@ -234,6 +234,9 @@
        data.setRecords(res1);
        return R.ok(data);
    }
    public static List<PayOrderDto> testing5(long total, long current, long size, List<PayOrderDto> str){
    List<PayOrderDto> result = new ArrayList<>();
    //获取初始化分页结构
@@ -255,6 +258,9 @@
    }
    return result;
}
    @ResponseBody
    @PostMapping(value = "/pay/order/refund")
    @ApiOperation(value = "退款", tags = {"管理后台-支付订单-订单信息"})
@@ -325,6 +331,10 @@
        return R.ok();
    }
    @ResponseBody
    @GetMapping(value = "/pay/order/refund/detail")
    @ApiOperation(value = "退款信息", tags = {"管理后台-支付订单-订单信息"})
@@ -470,6 +480,10 @@
        }
        return result;
    }
    @ResponseBody
    @PostMapping(value = "/pay/order/refund/list1")
    @ApiOperation(value = "列表1", tags = {"管理后台-支付订单-退款订单"})
@@ -578,6 +592,8 @@
                .between(TChargingOrder::getStartTime, req.getStartTime(), req.getEndTime())).size();
        return R.ok(size);
    }
    //用户订单数量
    @PostMapping(value = "/useOrderCount")
    public R<Long> useOrderCount(@RequestParam("userId") Long userId) {
@@ -586,11 +602,15 @@
        return R.ok(count);
    }
    //订单详情
    @PostMapping(value = "/detail")
    public R<TChargingOrder> detail(@RequestParam("orderId") Long orderId) {
        return R.ok(chargingOrderService.getById(orderId));
    }
    @PostMapping(value = "/getList")
    public R<List<TChargingOrder>> getList(@RequestParam("siteId") Integer siteId) {
@@ -598,6 +618,8 @@
        List<TChargingOrder> list = chargingOrderService.lambdaQuery().eq(TChargingOrder::getSiteId, siteId).list();
        return R.ok(list);
    }
    @PostMapping(value = "/getBySiteIdAndTime")
    public R<List<ChargingOrderGroup>> getBySiteIdAndTime(@RequestBody ChargingPercentProvinceDto chargingPercentProvinceDto) {
@@ -783,12 +805,6 @@
        chargingOrderService.endChargeBillingCharge(vo);
    }
    
//    @PostMapping("/endChargeBillingCharge1")
//    public void endChargeBillingCharge1(@RequestBody TransactionRecordMessageVO vo){
//        log.info("-------------------停止充电返回账单后计算费用及修改业务状态-------------------:" + vo);
//        chargingOrderService.endChargeBillingCharge1(vo);
//    }
    
    
    
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/TChargingOrderService.java
@@ -178,12 +178,6 @@
     */
    void endChargeBillingCharge(TransactionRecordMessageVO vo);
    
//    /**
//     * 停止充电返回账单后计算费用
//     * @param vo
//     */
//    void endChargeBillingCharge1(TransactionRecordMessageVO vo);
    
    /**
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -888,10 +888,13 @@
                dto.setRefundReason("充电失败,取消充电订单");
                RefundResp resp = aliPaymentClient.refund(dto).getData();
                if(null != resp){
                    AjaxResult success = chargingOrderStartupFailureWxRefund(resp.getOutTradeNo(), resp.getTradeNo(), "SUCCESS", null);
                    if(success.isSuccess()){
                        chargingOrderRefundService.save(chargingOrderRefund);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null);
                }
            }
@@ -2112,6 +2115,7 @@
            BigDecimal vipDiscountAmount = BigDecimal.ZERO;
            //计算优惠金额
            if(null != chargingOrder.getVipDiscount()){
                //0.58折
                vipDiscountAmount = serviceCharge.multiply(new BigDecimal(1).subtract(chargingOrder.getVipDiscount()));
                serviceCharge = serviceCharge.multiply(chargingOrder.getVipDiscount());
            }
@@ -2126,9 +2130,7 @@
            periodElectricPrice_total = periodElectricPrice_total.add(electrovalenc);
            periodServicePrice_total = periodServicePrice_total.add(originalServicePrice);
            total = total.add(electrovalenc.add(originalServicePrice));
        }
        
        //原金额
        BigDecimal rechargeAmount = chargingOrder.getRechargeAmount();
@@ -2363,442 +2365,6 @@
    }
    
    
//    /**
//     * 停止充电返回账单后计算费用
//     * @param vo
//     */
//    @Override
//    @GlobalTransactional(rollbackFor = Exception.class)
//    public void endChargeBillingCharge1(TransactionRecordMessageVO vo) {
//        TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, vo.getTransaction_serial_number()));
//        Integer status = chargingOrder.getStatus();
////        if(status == 5){
////            return;
////        }
//
//        //如果使用优惠券需要判断优惠券是否满足使用条件
//        //根据实际的充电金额计算退款金额   退回费用=(原金额/总金额)*(总金额-实际充电金额)
//        //退款金额=优惠券金额+剩余充电金额
//        BigDecimal periodElectricPrice_total = BigDecimal.ZERO;
//        BigDecimal periodServicePrice_total = BigDecimal.ZERO;
//        BigDecimal total = BigDecimal.ZERO;
//
//        //获取订单的计费策略
//        List<AccountingStrategyDetailOrder> accountingStrategyDetailOrderList = accountingStrategyDetailOrderClient.getAllAccountingStrategyDetailOrder(chargingOrder.getId()).getData();
//        accountingStrategyDetailOrderList.get(accountingStrategyDetailOrderList.size() - 1).setEndTime("23:59");
//        //开始处理计费明细数据和优惠数据
////        chargingOrderAccountingStrategyService.remove(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>().eq(TChargingOrderAccountingStrategy::getChargingOrderId, chargingOrder.getId()));
//        SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        List<AccountingStrategyDetailOrderVo> lists = new ArrayList<>();
//        try {
//            //跨天
//            if(!vo.getStart_time().split(" ")[0].equals(vo.getEnd_time().split(" ")[0])){
//                //当天的
//                //开始通过计费策略遍历解析每个时段的费用明细
//                String start_time = vo.getStart_time();
//                String end_time = vo.getEnd_time();
//                long start = sdfs.parse(start_time).getTime();
//                long end = sdfs.parse(end_time).getTime();
//                Class<? extends TransactionRecordMessageVO> clazz = vo.getClass();
//                /**
//                 * "start_time": "2025-01-03 23:06:43.00",
//                 *     "end_time": "2025-01-04 00:39:39.00",
//                 */
//                for (int i = accountingStrategyDetailOrderList.size(); i > 0; i--) {
//                    AccountingStrategyDetailOrder strategyDetail = accountingStrategyDetailOrderList.get(i - 1);
//                    long time = sdfs.parse(start_time.split(" ")[0] + " " + strategyDetail.getEndTime() + ":00").getTime();
//                    if(time < start){
//                        break;
//                    }
//                    //阶段(1=尖阶段,2=峰阶段,3=平阶段,4=谷阶段)
//                    Object invoke = null;
//                    switch (strategyDetail.getType()){
//                        case 1:
//                            //充电度数
//                            invoke = clazz.getMethod("getSpike_charge" + (i)).invoke(vo);
//                            break;
//                        case 2:
//                            //充电度数
//                            invoke = clazz.getMethod("getPeak_charge" + (i)).invoke(vo);
//                            break;
//                        case 3:
//                            //充电度数
//                            invoke = clazz.getMethod("getFlat_charge" + (i)).invoke(vo);
//                            break;
//                        case 4:
//                            //充电度数
//                            invoke = clazz.getMethod("getValley_charge" + (i)).invoke(vo);
//                            break;
//                    }
//                    if(null == invoke || Double.valueOf(invoke.toString()) == 0){
//                        continue;
//                    }
//                    BigDecimal sharp_peak_charge = new BigDecimal(invoke.toString());
//                    AccountingStrategyDetailOrderVo vo1 = new AccountingStrategyDetailOrderVo();
//                    BeanUtils.copyProperties(strategyDetail, vo1);
//                    vo1.setChargingCapacity(sharp_peak_charge);
//                    lists.add(vo1);
//                }
//
//                //第二天的
//                //开始通过计费策略遍历解析每个时段的费用明细
//                for (int i = 0; i < accountingStrategyDetailOrderList.size(); i++) {
//                    AccountingStrategyDetailOrder strategyDetail = accountingStrategyDetailOrderList.get(i);
//                    long time = sdfs.parse(end_time.split(" ")[0] + " " + strategyDetail.getStartTime() + ":00").getTime();
//                    if(time > end){
//                        break;
//                    }
//                    //阶段(1=尖阶段,2=峰阶段,3=平阶段,4=谷阶段)
//                    Object invoke = null;
//                    switch (strategyDetail.getType()){
//                        case 1:
//                            //充电度数
//                            invoke = clazz.getMethod("getSpike_charge" + (i + 1)).invoke(vo);
//                            break;
//                        case 2:
//                            //充电度数
//                            invoke = clazz.getMethod("getPeak_charge" + (i + 1)).invoke(vo);
//                            break;
//                        case 3:
//                            //充电度数
//                            invoke = clazz.getMethod("getFlat_charge" + (i + 1)).invoke(vo);
//                            break;
//                        case 4:
//                            //充电度数
//                            invoke = clazz.getMethod("getValley_charge" + (i + 1)).invoke(vo);
//                            break;
//                    }
//                    if(null == invoke || Double.valueOf(invoke.toString()) == 0){
//                        continue;
//                    }
//                    BigDecimal sharp_peak_charge = new BigDecimal(invoke.toString());
//                    AccountingStrategyDetailOrderVo vo1 = new AccountingStrategyDetailOrderVo();
//                    BeanUtils.copyProperties(strategyDetail, vo1);
//                    vo1.setChargingCapacity(sharp_peak_charge);
//                    lists.add(vo1);
//                }
//            }else{
//                for (int i = 0; i < accountingStrategyDetailOrderList.size(); i++) {
//                    Class<? extends TransactionRecordMessageVO> clazz = vo.getClass();
//                    AccountingStrategyDetailOrder strategyDetail = accountingStrategyDetailOrderList.get(i);
//                    //阶段(1=尖阶段,2=峰阶段,3=平阶段,4=谷阶段)
//                    Object invoke = null;
//                    switch (strategyDetail.getType()){
//                        case 1:
//                            //充电度数
//                            invoke = clazz.getMethod("getSpike_charge" + (i + 1)).invoke(vo);
//                            break;
//                        case 2:
//                            //充电度数
//                            invoke = clazz.getMethod("getPeak_charge" + (i + 1)).invoke(vo);
//                            break;
//                        case 3:
//                            //充电度数
//                            invoke = clazz.getMethod("getFlat_charge" + (i + 1)).invoke(vo);
//                            break;
//                        case 4:
//                            //充电度数
//                            invoke = clazz.getMethod("getValley_charge" + (i + 1)).invoke(vo);
//                            break;
//                    }
//                    if(null == invoke || Double.valueOf(invoke.toString()) == 0){
//                        continue;
//                    }
//                    BigDecimal sharp_peak_charge = new BigDecimal(invoke.toString());
//                    AccountingStrategyDetailOrderVo vo1 = new AccountingStrategyDetailOrderVo();
//                    BeanUtils.copyProperties(strategyDetail, vo1);
//                    vo1.setChargingCapacity(sharp_peak_charge);
//                    lists.add(vo1);
//                }
//            }
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//
//        //开始处理明细
//        for (int i = 0; i < lists.size(); i++) {
//            AccountingStrategyDetailOrderVo strategyDetail = lists.get(i);
//            BigDecimal sharp_peak_charge = strategyDetail.getChargingCapacity();
//            TChargingOrderAccountingStrategy chargingOrderAccountingStrategy = new TChargingOrderAccountingStrategy();
//            chargingOrderAccountingStrategy.setChargingOrderId(chargingOrder.getId());
//            chargingOrderAccountingStrategy.setAccountingStrategyDetailId(strategyDetail.getId());
//            chargingOrderAccountingStrategy.setType(strategyDetail.getType());
//            chargingOrderAccountingStrategy.setElectrovalence(strategyDetail.getElectrovalence());
//            chargingOrderAccountingStrategy.setServiceCharge(strategyDetail.getServiceCharge());
//            chargingOrderAccountingStrategy.setCostServiceCharge(strategyDetail.getCostServiceCharge());
//            if(i == 0){
//                String time = vo.getStart_time().split(" ")[1];
//                chargingOrderAccountingStrategy.setStartTime(time.substring(0, time.lastIndexOf(":")));
//            }else{
//                chargingOrderAccountingStrategy.setStartTime(strategyDetail.getStartTime());
//            }
//            if(i == lists.size() - 1){
//                String time = vo.getEnd_time().split(" ")[1];
//                chargingOrderAccountingStrategy.setEndTime(time.substring(0, time.lastIndexOf(":")));
//            }else{
//                chargingOrderAccountingStrategy.setEndTime(strategyDetail.getEndTime());
//            }
//
//            //已充电总度数
//            BigDecimal electrovalenc = strategyDetail.getElectrovalence().multiply(sharp_peak_charge);
//            BigDecimal originalServicePrice = strategyDetail.getServiceCharge().multiply(sharp_peak_charge);
//            BigDecimal serviceCharge = originalServicePrice;
//            BigDecimal vipDiscountAmount = BigDecimal.ZERO;
//            //计算优惠金额
//            if(null != chargingOrder.getVipDiscount()){
//                vipDiscountAmount = serviceCharge.multiply(new BigDecimal(1).subtract(chargingOrder.getVipDiscount()));
//                serviceCharge = serviceCharge.multiply(chargingOrder.getVipDiscount());
//            }
//            chargingOrderAccountingStrategy.setChargingCapacity(sharp_peak_charge);
//            chargingOrderAccountingStrategy.setPeriodElectricPrice(electrovalenc.setScale(4, RoundingMode.HALF_EVEN));
//            chargingOrderAccountingStrategy.setPeriodServicePrice(serviceCharge.setScale(4, RoundingMode.HALF_EVEN));
//            chargingOrderAccountingStrategy.setPeriodOriginalServicePrice(originalServicePrice.setScale(4, RoundingMode.HALF_EVEN));
//            chargingOrderAccountingStrategy.setVipDiscountAmount(vipDiscountAmount.setScale(4, RoundingMode.HALF_EVEN));
//            chargingOrderAccountingStrategy.setCreateTime(LocalDateTime.now());
////            chargingOrderAccountingStrategyService.save(chargingOrderAccountingStrategy);
//            System.err.println("----------"+JSON.toJSONString(chargingOrderAccountingStrategy));
//
//            periodElectricPrice_total = periodElectricPrice_total.add(electrovalenc);
//            periodServicePrice_total = periodServicePrice_total.add(originalServicePrice);
//            total = total.add(electrovalenc.add(originalServicePrice));
//
//        }
//
//
//        //原金额
//        BigDecimal rechargeAmount = chargingOrder.getRechargeAmount();
//        BigDecimal vipDiscountAmount = chargingOrder.getVipDiscountAmount();
//        //总金额(充值金额+会员折扣金额)
//        BigDecimal decimal = rechargeAmount.add(vipDiscountAmount);
//        //退款金额(已经计算了折扣优惠部分)
//        //如果充电总金额未使用完,则需要退回费用=(原金额/总金额)*(总金额-实际充电金额)
//        BigDecimal refundAmount = rechargeAmount.divide(decimal, new MathContext(4, RoundingMode.HALF_EVEN)).multiply(decimal.subtract(total));
//        BigDecimal orderAmount = BigDecimal.valueOf(total.doubleValue());
//        BigDecimal payAmount = BigDecimal.valueOf(total.doubleValue());
//        //折扣金额
//        BigDecimal discountAmount = BigDecimal.ZERO;
////        if(null != chargingOrder.getVipDiscount()){
////            TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData();
////            //判断会员是否还有充电优惠次数
////            GetAppUserVipDetail getAppUserVipDetail = new GetAppUserVipDetail();
////            getAppUserVipDetail.setAppUserId(chargingOrder.getAppUserId());
////            getAppUserVipDetail.setVipId(appUser.getVipId());
////            TAppUserVipDetail data = appUserVipDetailClient.getAppUserVipDetail(getAppUserVipDetail).getData();
////            if(null != data && data.getChargeNum() > 0){
////                data.setChargeNum(data.getChargeNum() - 1);
////                appUserVipDetailClient.updateAppUserVipDetail(data);
////
////                //服务费折扣
////                discountAmount = periodServicePrice_total.multiply((new BigDecimal(1).subtract(chargingOrder.getVipDiscount())));
////                TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
////                BigDecimal maximumDeduction = vip.getMaximumDeduction();
////                //普通会员有最高优惠限制
////                if(vip.getType() == 1 && discountAmount.compareTo(maximumDeduction) > 0){
////                    discountAmount = maximumDeduction;
////                }
////            }
////        }
//        //会员折扣金额
//        discountAmount = discountAmount.setScale(4, RoundingMode.HALF_EVEN);
//        payAmount = payAmount.subtract(discountAmount);
//        periodServicePrice_total = periodServicePrice_total.subtract(discountAmount);
//
//        TChargingOrder order = new TChargingOrder();
//        order.setId(chargingOrder.getId());
//        order.setAppUserId(chargingOrder.getAppUserId());
//        UploadRealTimeMonitoringData uploadRealTimeMonitoringData = uploadRealTimeMonitoringDataClient.chargingOrderInfo(chargingOrder.getCode()).getData();
//        if(null != uploadRealTimeMonitoringData && null == chargingOrder.getEndMode()){
//            Integer soc = uploadRealTimeMonitoringData.getSoc();
//            order.setEndMode(soc > 98 ? 2 : 3);
//        }else{
//            order.setEndMode(1);
//        }
//        order.setResidualAmount(rechargeAmount.subtract(total).setScale(2, RoundingMode.HALF_EVEN));
//        order.setStartTime(LocalDateTime.parse(vo.getStart_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS")));
//        order.setEndTime(LocalDateTime.parse(vo.getEnd_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS")));
//        order.setStatus(5);
//        order.setOrderAmount(orderAmount.setScale(2, RoundingMode.HALF_EVEN));
//        order.setVipDiscountAmount(discountAmount.setScale(2, RoundingMode.HALF_EVEN));
//        order.setElectrovalence(periodElectricPrice_total.setScale(2, RoundingMode.HALF_EVEN));
//        order.setChargingCapacity(vo.getTotal_electricity());
//        order.setElectricity(vo.getTotal_electricity());
//
//        //计算优惠券
//        BigDecimal couponDiscount = BigDecimal.ZERO;
////        if(null != chargingOrder.getAppCouponId()){
////            //判断实际充电金额是否满足优惠券使用条件,如果不满足则不适用优惠券。
////            TAppCoupon appCoupon = appCouponClient.getAppCouponById(chargingOrder.getAppCouponId()).getData();
////            String couponJson = appCoupon.getCouponJson();
////            TCoupon tCoupon = JSON.parseObject(couponJson, TCoupon.class);
////            Integer preferentialMode = tCoupon.getPreferentialMode();
////            if(1 == preferentialMode){
////                //满减
////                if(payAmount.compareTo(tCoupon.getMeetTheConditions()) >= 0){
////                    BigDecimal couponDiscountAmount = tCoupon.getDiscountAmount();
////                    //如果优惠金额大于服务费金额,以服务费作为最大限制
////                    if(periodServicePrice_total.compareTo(couponDiscountAmount) < 0){
////                        couponDiscount = periodServicePrice_total;
////                        periodServicePrice_total = BigDecimal.ZERO;
////                    }else{
////                        couponDiscount = couponDiscountAmount;
////                    }
////                    appCoupon.setStatus(2);
//////                    appCouponClient.updateAppCoupon(appCoupon);
////                }else{
////                    order.setAppCouponId(null);
////                    order.setCouponDiscountAmount(BigDecimal.ZERO);
//////                    appCouponClient.refund(chargingOrder.getAppCouponId().toString());
////                }
////            }
////            if(2 == preferentialMode){
////                //抵扣
////                if(payAmount.compareTo(tCoupon.getMeetTheConditions()) >= 0){
////                    //折扣金额
////                    BigDecimal divide = payAmount.multiply(new BigDecimal(10).subtract(tCoupon.getDiscount())).divide(new BigDecimal(10));
////                    divide = divide.compareTo(tCoupon.getMaximumDiscountAmount()) > 0 ? tCoupon.getMaximumDiscountAmount() : divide;
////                    //如果优惠金额大于服务费金额,以服务费作为最大限制
////                    if(periodServicePrice_total.compareTo(divide) < 0){
////                        couponDiscount = periodServicePrice_total;
////                        periodServicePrice_total = BigDecimal.ZERO;
////                    }else{
////                        couponDiscount = divide;
////                    }
////
////                    appCoupon.setStatus(2);
////                    appCouponClient.updateAppCoupon(appCoupon);
////                }else{
////                    order.setAppCouponId(null);
////                    order.setCouponDiscountAmount(BigDecimal.ZERO);
////                    appCouponClient.refund(chargingOrder.getAppCouponId().toString());
////                }
////            }
////        }
//        //优惠券优惠金额
//        couponDiscount = couponDiscount.setScale(4, RoundingMode.HALF_EVEN);
//        refundAmount = refundAmount.add(couponDiscount);
//        payAmount = payAmount.subtract(couponDiscount);
//        if(periodServicePrice_total.compareTo(BigDecimal.ZERO) > 0){
//            periodServicePrice_total = periodServicePrice_total.subtract(couponDiscount);
//        }
//        order.setCouponDiscountAmount(couponDiscount.setScale(2, RoundingMode.HALF_EVEN));
//        order.setServiceCharge(periodServicePrice_total.setScale(2, RoundingMode.HALF_EVEN));
//        order.setPaymentAmount(payAmount.setScale(2, RoundingMode.HALF_EVEN));
//        order.setRefundAmount(refundAmount.setScale(2, RoundingMode.HALF_EVEN));
//        order.setRefundStatus(1);
////        this.updateById(order);
//        System.err.println("----------"+JSON.toJSONString(order));
////        chargingOrder = this.getById(order.getId());
////
////        //开始将优惠券优惠的金额添加到明细中
////        BigDecimal couponDiscountAmount = order.getCouponDiscountAmount();
////        if(null != couponDiscountAmount && couponDiscountAmount.compareTo(BigDecimal.ZERO) > 0){
////            List<TChargingOrderAccountingStrategy> list = chargingOrderAccountingStrategyService.list(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>().eq(TChargingOrderAccountingStrategy::getChargingOrderId, order.getId()));
////            BigDecimal reduce = list.stream().map(TChargingOrderAccountingStrategy::getPeriodServicePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
////            for (TChargingOrderAccountingStrategy chargingOrderAccountingStrategy : list) {
////                BigDecimal periodServicePrice = chargingOrderAccountingStrategy.getPeriodServicePrice();
////                BigDecimal multiply = couponDiscountAmount.multiply(periodServicePrice.divide(reduce, new MathContext(4, RoundingMode.HALF_EVEN)));
////                periodServicePrice = periodServicePrice.subtract(multiply);
////                chargingOrderAccountingStrategy.setPeriodServicePrice(periodServicePrice.setScale(2, RoundingMode.HALF_EVEN));
////                chargingOrderAccountingStrategy.setCouponDiscountAmount(multiply.setScale(2, RoundingMode.HALF_EVEN));
////            }
//////            chargingOrderAccountingStrategyService.updateBatchById(list);
////        }
////
////        // 将枪状态重置为空闲
////        TChargingGun chargingGun = new TChargingGun();
////        chargingGun.setId(chargingOrder.getChargingGunId());
////        chargingGun.setStatus(2);
////        chargingGun.setChargingPower(BigDecimal.ZERO);
//////        chargingGunClient.updateChargingGunById(chargingGun);
////
////        //添加积分
////        TIntegralRule integralRule = integralRuleClient.getSet().getData();
////        if(null != integralRule){
////            TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData();
////            Integer num1 = JSON.parseObject(integralRule.getChargeCredit()).getInteger("num1");
////            Integer integral = chargingOrder.getServiceCharge().intValue() * num1;
////            if(null != appUser.getVipId()){
////                TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
////                Integer doubleIntegration = vip.getDoubleIntegration();
////                //双倍积分
////                if(1 == doubleIntegration){
////                    integral *= 2;
////                }
////            }
////
////            if(integral > 0){
////                TAppUserIntegralChange appUserIntegralChange = new TAppUserIntegralChange();
////                appUserIntegralChange.setAppUserId(appUser.getId());
////                appUserIntegralChange.setChangeType(2);
////                appUserIntegralChange.setHistoricalIntegral(appUser.getPoints());
////                appUser.setPoints(appUser.getPoints() + integral);
////                appUserIntegralChange.setCurrentIntegral(appUser.getPoints());
////                appUserIntegralChange.setCreateTime(LocalDateTime.now());
////                appUserIntegralChange.setOrderCode(chargingOrder.getCode());
////                appUserIntegralChange.setExtension(chargingOrder.getId().toString());
////                appUserClient.updateAppUser(appUser);
////                appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange);
////            }
////        }
////
////        //计算用户标签
////        editUserTag(chargingOrder);
////        //用户推荐奖励
////        referralReward(chargingOrder);
////
////        //开始构建退款费用
////        if(refundAmount.compareTo(BigDecimal.ZERO) > 0){
////            Integer rechargePaymentType = chargingOrder.getRechargePaymentType();
////            //构建退款明细
////            TChargingOrderRefund chargingOrderRefund = new TChargingOrderRefund();
////            chargingOrderRefund.setChargingOrderId(chargingOrder.getId());
////            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
////            chargingOrderRefund.setRefundCode("CDF" + sdf.format(new Date()) + (Double.valueOf(Math.random() * 1000).intValue()));
////            chargingOrderRefund.setRefundAmount(refundAmount);
////            chargingOrderRefund.setRefundStatus(1);
////            chargingOrderRefund.setPayType(rechargePaymentType);
////            chargingOrderRefund.setRefundStatus(1);
////            chargingOrderRefund.setCode(chargingOrder.getCode());
////            chargingOrderRefund.setRefundTitle("充电完成退款");
////            chargingOrderRefund.setRefundContent("充电完成退款");
////            chargingOrderRefund.setRefundReason("充电完成退款");
////            chargingOrderRefund.setRefundRemark("实际充电消费金额:" + chargingOrder.getPaymentAmount());
////            chargingOrderRefund.setRefundTotalAmount(refundAmount);
////            chargingOrderRefund.setPayAmount(rechargeAmount);
////            if(1 == rechargePaymentType){
////                WxPaymentRefundModel model = new WxPaymentRefundModel();
////                model.setOut_trade_no(chargingOrder.getCode());
////                model.setOut_refund_no(chargingOrderRefund.getRefundCode());
////                model.setReason("充电完成退款");
////                model.setNotify_url("/payment/wx/refund/notify");
////                WxPaymentRefundModel.RefundAmount amount = new WxPaymentRefundModel.RefundAmount();
////                amount.setRefund(refundAmount.multiply(new BigDecimal(100)).intValue());
////                amount.setTotal(rechargeAmount.multiply(new BigDecimal(100)).intValue());
////                amount.setCurrency("CNY");
////                model.setAmount(amount);
////                R<String> orderR = wxPaymentClient.refundOrderR(model);
////                if(200 == orderR.getCode()){
////                    chargingOrderRefundService.save(chargingOrderRefund);
////                }
////            }
////            if(2 == rechargePaymentType){
////                RefundReq dto = new RefundReq();
////                dto.setOutTradeNo(chargingOrder.getCode());
////                dto.setOutRequestNo(chargingOrderRefund.getCode());
////                dto.setRefundAmount(refundAmount.toString());
////                dto.setRefundReason("充电完成退款");
////                RefundResp resp = aliPaymentClient.refund(dto).getData();
////                if(null != resp){
////                    AjaxResult success = chargingOrderStartupFailureWxRefund(resp.getOutTradeNo(), resp.getTradeNo(), "SUCCESS", null);
////                    if(success.isSuccess()){
////                        chargingOrderRefundService.save(chargingOrderRefund);
////                    }
////                }
////            }
////
////        }
//    }
    
    
    @Override
@@ -2889,6 +2455,10 @@
    private TVipOrderService vipOrderService;
    @Resource
    private TVipOrderRefundService vipOrderRefundService;
    @Override
    public R payRefund(PayOrderRefundDto payOrderQueryDto) {
            if (payOrderQueryDto.getType()==1){
@@ -2946,7 +2516,6 @@
                    dto.setRefundReason("取消订单");
                    RefundResp resp = aliPaymentClient.refund(dto).getData();
                    if(null != resp){
                        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-DDTHH:mm:ss+TIMEZONE");
                        chargingOrderRefund.setRefundStatus(2);
                        chargingOrderRefund.setRefundAmount((tChargingOrder.getRefundAmount()==null? BigDecimal.valueOf(0) :tChargingOrder.getRefundAmount()).add(payOrderQueryDto.getRefundAmount()));
                        this.baseMapper.updateById(tChargingOrder);
@@ -2954,11 +2523,6 @@
                    }
                }
            }
            if (payOrderQueryDto.getType()==2){
                TShoppingOrder tChargingOrder = shoppingOrderService.getById(payOrderQueryDto.getOrderId());
@@ -3014,16 +2578,10 @@
                    dto.setRefundReason("取消订单");
                    RefundResp resp = aliPaymentClient.refund(dto).getData();
                    if(null != resp){
                        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-DDTHH:mm:ss+TIMEZONE");
                        tChargingOrder.setRefundStatus(2);
                        tChargingOrder.setRefundAmount((tChargingOrder.getRefundAmount()==null? BigDecimal.valueOf(0) :tChargingOrder.getRefundAmount()).add(payOrderQueryDto.getRefundAmount()));
                        shoppingOrderService.updateById(tChargingOrder);
                        shoppingOrderRefundService.save(chargingOrderRefund);
                    }
                }
@@ -3034,8 +2592,6 @@
            if (tChargingOrder.getPaymentAmount().compareTo(payOrderQueryDto.getRefundAmount())==-1){
                return R.fail("退款金额需小于支付金额");
            }
            TVipOrderRefund chargingOrderRefund = new TVipOrderRefund();
            chargingOrderRefund.setVipOrderId(tChargingOrder.getId());
            chargingOrderRefund.setRefundAmount(payOrderQueryDto.getRefundAmount());
@@ -3081,23 +2637,13 @@
                dto.setRefundReason("取消订单");
                RefundResp resp = aliPaymentClient.refund(dto).getData();
                if(null != resp){
                    SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-DDTHH:mm:ss+TIMEZONE");
                    tChargingOrder.setRefundStatus(2);
                    tChargingOrder.setRefundAmount((tChargingOrder.getRefundAmount()==null? BigDecimal.valueOf(0) :tChargingOrder.getRefundAmount()).add(payOrderQueryDto.getRefundAmount()));
                    vipOrderService.updateById(tChargingOrder);
                    vipOrderRefundService.save(chargingOrderRefund);
                }
            }
        }
        return R.ok();
    }