| | |
| | | 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("充电充值"); |
| | |
| | | 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(); |
| | |
| | | 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(); |
| | |
| | | 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){ |
| | |
| | | * @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(); |
| | |
| | | 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(); |
| | | } |
| | |
| | | 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()); |
| | |
| | | } |
| | | |
| | | //已充电总度数 |
| | | BigDecimal electrovalenc = strategyDetail.getElectrovalence().multiply(sharp_peak_charge).setScale(2, RoundingMode.DOWN); |
| | | BigDecimal originalServicePrice = strategyDetail.getServiceCharge().multiply(sharp_peak_charge).setScale(2, RoundingMode.DOWN); |
| | | BigDecimal electrovalenc = strategyDetail.getElectrovalence().multiply(sharp_peak_charge).setScale(2, RoundingMode.HALF_EVEN); |
| | | BigDecimal originalServicePrice = strategyDetail.getServiceCharge().multiply(sharp_peak_charge).setScale(2, RoundingMode.HALF_EVEN); |
| | | BigDecimal serviceCharge = originalServicePrice; |
| | | BigDecimal vipDiscountAmount = BigDecimal.ZERO; |
| | | //计算优惠金额 |
| | | if(null != chargingOrder.getVipDiscount()){ |
| | | vipDiscountAmount = serviceCharge.multiply(new BigDecimal(1).subtract(chargingOrder.getVipDiscount())).setScale(2, RoundingMode.DOWN); |
| | | serviceCharge = serviceCharge.multiply(chargingOrder.getVipDiscount()).setScale(2, RoundingMode.DOWN); |
| | | vipDiscountAmount = serviceCharge.multiply(new BigDecimal(1).subtract(chargingOrder.getVipDiscount())).setScale(2, RoundingMode.HALF_EVEN); |
| | | serviceCharge = serviceCharge.multiply(chargingOrder.getVipDiscount()).setScale(2, RoundingMode.HALF_EVEN); |
| | | } |
| | | chargingOrderAccountingStrategy.setChargingCapacity(sharp_peak_charge); |
| | | chargingOrderAccountingStrategy.setPeriodElectricPrice(electrovalenc.setScale(2, RoundingMode.DOWN)); |
| | | chargingOrderAccountingStrategy.setPeriodServicePrice(serviceCharge.setScale(2, RoundingMode.DOWN)); |
| | | chargingOrderAccountingStrategy.setPeriodOriginalServicePrice(originalServicePrice.setScale(2, RoundingMode.DOWN)); |
| | | chargingOrderAccountingStrategy.setVipDiscountAmount(vipDiscountAmount.setScale(2, RoundingMode.DOWN)); |
| | | chargingOrderAccountingStrategy.setPeriodElectricPrice(electrovalenc); |
| | | chargingOrderAccountingStrategy.setPeriodServicePrice(serviceCharge); |
| | | chargingOrderAccountingStrategy.setPeriodOriginalServicePrice(originalServicePrice); |
| | | chargingOrderAccountingStrategy.setVipDiscountAmount(vipDiscountAmount); |
| | | chargingOrderAccountingStrategy.setCreateTime(LocalDateTime.now()); |
| | | chargingOrderAccountingStrategyService.save(chargingOrderAccountingStrategy); |
| | | |
| | | periodElectricPrice_total = periodElectricPrice_total.add(electrovalenc.setScale(2, RoundingMode.DOWN)); |
| | | periodServicePrice_total = periodServicePrice_total.add(originalServicePrice.setScale(2, RoundingMode.DOWN)); |
| | | total = total.add(electrovalenc.add(originalServicePrice.setScale(2, RoundingMode.DOWN))); |
| | | periodElectricPrice_total = periodElectricPrice_total.add(electrovalenc); |
| | | periodServicePrice_total = periodServicePrice_total.add(originalServicePrice); |
| | | total = total.add(electrovalenc.add(originalServicePrice)); |
| | | } |
| | | |
| | | |
| | |
| | | //总金额(充值金额+会员折扣金额) |
| | | 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()); |
| | |
| | | |
| | | //服务费折扣 |
| | | discountAmount = periodServicePrice_total.multiply((new BigDecimal(1).subtract(chargingOrder.getVipDiscount()))); |
| | | periodServicePrice_total = periodServicePrice_total.multiply(chargingOrder.getVipDiscount()); |
| | | |
| | | TVip vip = vipClient.getInfo1(appUser.getVipId()).getData(); |
| | | BigDecimal maximumDeduction = vip.getMaximumDeduction(); |
| | | //普通会员有最高优惠限制 |
| | |
| | | } |
| | | } |
| | | } |
| | | //会员折扣金额 |
| | | discountAmount = discountAmount.setScale(2, 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()); |
| | | 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)); |
| | | 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.DOWN)); |
| | | order.setVipDiscountAmount(discountAmount.setScale(2, RoundingMode.DOWN)); |
| | | order.setElectrovalence(periodElectricPrice_total.setScale(2, RoundingMode.DOWN)); |
| | | order.setOrderAmount(orderAmount.setScale(2, RoundingMode.HALF_EVEN)); |
| | | order.setVipDiscountAmount(discountAmount); |
| | | 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(); |
| | |
| | | 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); |
| | | periodServicePrice_total = periodServicePrice_total.subtract(couponDiscountAmount); |
| | | couponDiscount = couponDiscountAmount; |
| | | } |
| | | |
| | | appCoupon.setStatus(2); |
| | | appCouponClient.updateAppCoupon(appCoupon); |
| | | }else{ |
| | |
| | | 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); |
| | | periodServicePrice_total = periodServicePrice_total.subtract(divide); |
| | | couponDiscount = divide; |
| | | } |
| | | |
| | | appCoupon.setStatus(2); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | order.setServiceCharge(periodServicePrice_total.setScale(2, RoundingMode.DOWN)); |
| | | order.setPaymentAmount(payAmount.setScale(2, RoundingMode.DOWN)); |
| | | order.setRefundAmount(refundAmount.setScale(2, RoundingMode.DOWN)); |
| | | //优惠券优惠金额 |
| | | couponDiscount = couponDiscount.setScale(2, 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); |
| | | 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); |
| | | chargingOrder = this.getById(order.getId()); |
| | |
| | | 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); |
| | | } |