无关风月
2024-11-05 472fc1b5980db8cd69c77a5c1bcb8aded3d3b3a6
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -524,7 +524,7 @@
      if(2 == addChargingOrder.getPaymentType()){
         AliPaymentReq req = new AliPaymentReq();
         req.setOutTradeNo(chargingOrder.getCode());
         req.setTotalAmount(chargingOrder.getPaymentAmount().toString());
         req.setTotalAmount(addChargingOrder.getPaymentAmount().toString());
         req.setSubject("充电充值");
         req.setBuyerOpenId(appUser.getAliOpenid());
         req.setBody("充电充值");
@@ -671,7 +671,7 @@
      platformStartCharging.setCard_number(chargingOrder.getId().toString());
      platformStartCharging.setAccount_balance(account_balance);
      
      log.error(chargingOrder.getCode() + ":-------------------远程调起开始充电请求-------------------" + platformStartCharging.toString());
      log.info(chargingOrder.getCode() + ":-------------------远程调起开始充电请求-------------------" + platformStartCharging.toString());
      sendMessageClient.platformStartCharging(platformStartCharging);
      //异步线程检测远程启动的应答结果。如果失败,则需要全额退款
      Long id = chargingOrder.getId();
@@ -699,7 +699,7 @@
      String code = chargingOrder.getCode();
      String key = "AQJC_" + chargingOrder.getChargingGunId();
      List<PlatformStartChargingReply> data = platformStartChargingReplyClient.getPlatformStartChargingReply(code).getData();
      log.error(code + ":-------------------开始检查调起充电结果-------------------" + data.toString());
      log.info(code + ":-------------------开始检查调起充电结果-------------------" + data.toString());
      if(data.size() != 0){
         PlatformStartChargingReply platformStartChargingReply = data.get(1);
         Integer startup_result = platformStartChargingReply.getStartup_result();
@@ -741,7 +741,7 @@
         return true;
      }else{
         Integer counter = boot_failed_map.get(code);
         log.error(code + ":-------------------未上传开启充电结果-------------------" + counter);
         log.info(code + ":-------------------未上传开启充电结果-------------------" + counter);
         PreChargeCheck preChargeCheck1 = redisService.getCacheObject(key);
         //5分钟内未启动成功,退回金额。
         if(null == counter || counter < 300){
@@ -837,7 +837,7 @@
    * @param code
    */
   public void refund(String code){
      log.error(code + ":-------------------充电启动失败,执行退款-------------------");
      log.info(code + ":-------------------充电启动失败,执行退款-------------------");
      TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, code));
      if(chargingOrder.getStatus() == 2){
         Integer rechargePaymentType = chargingOrder.getRechargePaymentType();
@@ -1007,8 +1007,8 @@
         platformStopCharging.setCharging_pile_code(chargingPile.getCode());
         platformStopCharging.setCharging_gun_code(chargingGun.getCode());
         sendMessageClient.platformStopCharging(platformStopCharging);
         log.error(code1 + ":-------------------远程停止充电请求-------------------");
         log.error(platformStopCharging.toString());
         log.info(code1 + ":-------------------远程停止充电请求-------------------");
         log.info(platformStopCharging.toString());
      });
      return AjaxResult.success();
   }
@@ -1163,7 +1163,7 @@
               failure_cause = "其他";
               break;
         }
         log.error(code1 + ":停机失败:订单号:{},失败原因:{}", order.getCode(), failure_cause);
         log.info(code1 + ":停机失败:订单号:{},失败原因:{}", order.getCode(), failure_cause);
      }else{
         TChargingOrder chargingOrder = new TChargingOrder();
         chargingOrder.setId(order.getId());
@@ -1987,15 +1987,18 @@
            }
         }
      }
      //会员折扣金额
      discountAmount = discountAmount.setScale(2, RoundingMode.DOWN);
      payAmount = payAmount.subtract(discountAmount);
      
      TChargingOrder order = new TChargingOrder();
      order.setId(chargingOrder.getId());
      order.setAppUserId(chargingOrder.getAppUserId());
      if(null != chargingOrder.getEndMode() && chargingOrder.getEndMode() == 2){
         order.setEndMode(refundAmount.compareTo(BigDecimal.ZERO) > 0 ? 2 : 3);
      }
      if(null == chargingOrder.getEndMode()){
      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.DOWN));
@@ -2003,12 +2006,13 @@
      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.DOWN));
      order.setVipDiscountAmount(discountAmount.setScale(2, RoundingMode.DOWN));
      order.setVipDiscountAmount(discountAmount);
      order.setElectrovalence(periodElectricPrice_total.setScale(2, RoundingMode.DOWN));
      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();
@@ -2021,17 +2025,12 @@
               BigDecimal couponDiscountAmount = tCoupon.getDiscountAmount();
               //如果优惠金额大于服务费金额,以服务费作为最大限制
               if(periodServicePrice_total.compareTo(couponDiscountAmount) < 0){
                  refundAmount = refundAmount.add(periodServicePrice_total);
                  order.setCouponDiscountAmount(periodServicePrice_total);
                  payAmount = payAmount.subtract(periodServicePrice_total);
                  couponDiscount = periodServicePrice_total;
                  periodServicePrice_total = BigDecimal.ZERO;
               }else{
                  refundAmount = refundAmount.add(couponDiscountAmount);
                  order.setCouponDiscountAmount(couponDiscountAmount);
                  payAmount = payAmount.subtract(couponDiscountAmount);
                  couponDiscount = couponDiscountAmount;
                  periodServicePrice_total = periodServicePrice_total.subtract(couponDiscountAmount);
               }
               appCoupon.setStatus(2);
               appCouponClient.updateAppCoupon(appCoupon);
            }else{
@@ -2048,14 +2047,10 @@
               divide = divide.compareTo(tCoupon.getMaximumDiscountAmount()) > 0 ? tCoupon.getMaximumDiscountAmount() : divide;
               //如果优惠金额大于服务费金额,以服务费作为最大限制
               if(periodServicePrice_total.compareTo(divide) < 0){
                  refundAmount = refundAmount.add(periodServicePrice_total);
                  order.setCouponDiscountAmount(periodServicePrice_total);
                  payAmount = payAmount.subtract(periodServicePrice_total);
                  couponDiscount = periodServicePrice_total;
                  periodServicePrice_total = BigDecimal.ZERO;
               }else{
                  refundAmount = refundAmount.add(divide);
                  order.setCouponDiscountAmount(divide);
                  payAmount = payAmount.subtract(divide);
                  couponDiscount = divide;
                  periodServicePrice_total = periodServicePrice_total.subtract(divide);
               }
               
@@ -2068,7 +2063,11 @@
            }
         }
      }
      //优惠券优惠金额
      couponDiscount = couponDiscount.setScale(2, RoundingMode.DOWN);
      refundAmount = refundAmount.add(couponDiscount);
      payAmount = payAmount.subtract(couponDiscount);
      order.setCouponDiscountAmount(couponDiscount);
      order.setServiceCharge(periodServicePrice_total.setScale(2, RoundingMode.DOWN));
      order.setPaymentAmount(payAmount.setScale(2, RoundingMode.DOWN));
      order.setRefundAmount(refundAmount.setScale(2, RoundingMode.DOWN));
@@ -2085,8 +2084,8 @@
            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.DOWN));
            chargingOrderAccountingStrategy.setCouponDiscountAmount(multiply.setScale(2, RoundingMode.DOWN));
            chargingOrderAccountingStrategy.setPeriodServicePrice(periodServicePrice.setScale(2, RoundingMode.HALF_EVEN));
            chargingOrderAccountingStrategy.setCouponDiscountAmount(multiply.setScale(2, RoundingMode.HALF_EVEN));
         }
         chargingOrderAccountingStrategyService.updateBatchById(list);
      }