From 4c62b64cc158ed07f18ae7060dae71f9d1e3d9fd Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期一, 10 二月 2025 13:57:37 +0800 Subject: [PATCH] 修改bug --- ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java | 263 +++++++++++++++++++++++++++++++++------------------- 1 files changed, 166 insertions(+), 97 deletions(-) diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java index d30ab60..9e68b8c 100644 --- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java +++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java @@ -32,6 +32,7 @@ import com.ruoyi.integration.api.feignClient.*; import com.ruoyi.integration.api.model.*; import com.ruoyi.integration.api.vo.GetPlatformStopChargingReply; +import com.ruoyi.integration.api.vo.StartChargeResult; import com.ruoyi.order.api.dto.SettlementConfirmAdd; import com.ruoyi.order.api.feignClient.AccountingStrategyDetailOrderClient; import com.ruoyi.order.api.feignClient.AccountingStrategyOrderClient; @@ -141,7 +142,7 @@ private UploadRealTimeMonitoringDataClient uploadRealTimeMonitoringDataClient; @Resource - private ChargingHandshakeClient chargingHandshakeClient; + private TCECClient tcecClient; @Resource private SendMessageClient sendMessageClient; @@ -275,6 +276,8 @@ }else{ myChargingOrderInfo.setLicensePlate("无"); } + }else{ + myChargingOrderInfo.setLicensePlate(chargingOrder.getPlateNum()); } myChargingOrderInfo.setStartTime(chargingOrder.getStartTime().atZone(ZoneId.systemDefault()).toInstant().getEpochSecond() * 1000); myChargingOrderInfo.setEndTime(chargingOrder.getEndTime().atZone(ZoneId.systemDefault()).toInstant().getEpochSecond() * 1000); @@ -458,6 +461,12 @@ chargingOrder.setOrderClassification(1); chargingOrder.setAppUserId(userId); chargingOrder.setAppUserCarId(addChargingOrder.getAppUserCarId()); + if(null != addChargingOrder.getAppUserCarId()){ + TAppUserCar userCar = appUserCarClient.getCarById(addChargingOrder.getAppUserCarId().toString()).getData(); + if(null != userCar){ + chargingOrder.setPlateNum(userCar.getLicensePlate()); + } + } TChargingGun tChargingGun = chargingGunClient.getChargingGunById(addChargingOrder.getId()).getData(); TChargingPile chargingPile = chargingPileClient.getChargingPileById(tChargingGun.getChargingPileId()).getData(); chargingOrder.setSiteId(tChargingGun.getSiteId()); @@ -747,6 +756,10 @@ } this.updateById(order); redisService.setCacheObject(key, preChargeCheck1, 24L, TimeUnit.HOURS); + //推送三方平台订单状态 + if(2 == chargingOrder.getOrderSource()){ + tcecClient.notificationEquipChargeStatus(chargingOrder.getStartChargeSeq(), chargingOrder.getOperatorId()); + } return true; }else{ Integer counter = boot_failed_map.get(code); @@ -777,6 +790,10 @@ order.setEndMode(0); this.updateById(order); redisService.setCacheObject(key, preChargeCheck1, 24L, TimeUnit.HOURS); + //推送三方平台订单状态 + if(2 == chargingOrder.getOrderSource()){ + tcecClient.notificationEquipChargeStatus(chargingOrder.getStartChargeSeq(), chargingOrder.getOperatorId()); + } return true; } } @@ -836,9 +853,24 @@ TChargingGun chargingGun = chargingGunClient.getChargingGunById(order.getChargingGunId()).getData(); chargingGun.setStatus(4); chargingGunClient.updateChargingGunById(chargingGun); + //推送状态给三方平台 + tcecClient.pushChargingGunStatus(chargingGun.getId(), chargingGun.getStatus()); } redisService.setCacheObject("AQJC_" + order.getChargingGunId(), preChargeCheck1, 24L, TimeUnit.HOURS); this.updateById(order); + //推送三方平台启动充电结果 + if(2 == order.getOrderSource()){ + StartChargeResult result = new StartChargeResult(); + result.setStartChargeSeq(order.getStartChargeSeq()); + result.setStartChargeSeqStat(3 == order.getStatus() ? 2 : 4); + result.setConnectorID(order.getChargingGunId().toString()); + result.setStartTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); + Operator operator = operatorClient.getOperatorById(order.getOperatorId()).getData(); + result.setOperatorID(operator.getOperatorId()); + tcecClient.notificationStartChargeResult(result); + + tcecClient.notificationEquipChargeStatus(order.getStartChargeSeq(), order.getOperatorId()); + } } /** @@ -1003,7 +1035,6 @@ chargingOrder.setStatus(4); chargingOrder.setEndMode(1); this.updateById(chargingOrder); - String code1 = order.getCode(); TChargingGun chargingGun = chargingGunClient.getChargingGunById(order.getChargingGunId()).getData(); //异步线程处理停机 @@ -1018,6 +1049,11 @@ log.info(code1 + ":-------------------远程停止充电请求-------------------"); log.info(platformStopCharging.toString()); }); + //推送三方平台 + if(2 == order.getOrderSource()){ + tcecClient.notificationEquipChargeStatus(order.getStartChargeSeq(), order.getOperatorId()); + } + return AjaxResult.success(); } @@ -1313,6 +1349,8 @@ if (!data1.isEmpty()){ chargingOrderVO.setLicensePlate(data1.get(0).getLicensePlate()); } + }else{ + chargingOrderVO.setLicensePlate(chargingOrderVO.getPlateNum()); } } @@ -1580,6 +1618,8 @@ chargingOrderListVO.setLicensePlate(data4.get(0).getLicensePlate()); } } + }else{ + chargingOrderListVO.setLicensePlate(chargingOrderListVO.getPlateNum()); } chargingOrderListVO.setPhone(data3.getPhone()); } @@ -1849,7 +1889,11 @@ if (chargingOrder.getAppUserCarId()!=null){ List<TAppUserCar> data3 = appUserCarClient.getCarByIds(Collections.singletonList(chargingOrder.getAppUserCarId())).getData(); - if (data3!=null && !data3.isEmpty())chargingOrderListInfoVO.setLicensePlate(data3.get(0).getLicensePlate()); + if (data3!=null && !data3.isEmpty()) { + chargingOrderListInfoVO.setLicensePlate(data3.get(0).getLicensePlate()); + } + }else{ + chargingOrderListInfoVO.setLicensePlate(chargingOrder.getPlateNum()); } chargingOrderListInfoVO.setStartTime(chargingOrder.getStartTime()); chargingOrderListInfoVO.setEndTime(chargingOrder.getEndTime()); @@ -2256,6 +2300,14 @@ this.updateById(order); chargingOrder = this.getById(order.getId()); + //推送三方平台 + if(2 == chargingOrder.getOrderSource()){ + tcecClient.notificationEquipChargeStatus(chargingOrder.getStartChargeSeq(), chargingOrder.getOperatorId()); + tcecClient.notificationStopChargeResult(chargingOrder.getStartChargeSeq(), chargingOrder.getChargingGunId().toString(), + chargingOrder.getOperatorId()); + tcecClient.notificationChargeOrderInfo(chargingOrder.getStartChargeSeq(), chargingOrder.getOperatorId()); + } + //开始将优惠券优惠的金额添加到明细中 BigDecimal couponDiscountAmount = order.getCouponDiscountAmount(); if(null != couponDiscountAmount && couponDiscountAmount.compareTo(BigDecimal.ZERO) > 0){ @@ -2277,91 +2329,97 @@ chargingGun.setStatus(2); chargingGun.setChargingPower(BigDecimal.ZERO); chargingGunClient.updateChargingGunById(chargingGun); + //推送状态给三方平台 + if(2 == chargingOrder.getOrderSource()){ + tcecClient.pushChargingGunStatus(chargingGun.getId(), chargingGun.getStatus()); + } //添加积分 - 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(1 == chargingOrder.getOrderSource()){ + 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); } } - 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); - - //开始构建退款费用 - refundAmount = refundAmount.setScale(2, RoundingMode.HALF_EVEN); - 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.getRefundCode()); - dto.setRefundAmount(refundAmount.toString()); - dto.setRefundReason("充电完成退款"); - RefundResp resp = aliPaymentClient.refund(dto).getData(); - if(null != resp){ - chargingOrderRefundService.save(chargingOrderRefund); - this.chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null); - } - } + //计算用户标签 + editUserTag(chargingOrder); + //用户推荐奖励 + referralReward(chargingOrder); + //开始构建退款费用 + refundAmount = refundAmount.setScale(2, RoundingMode.HALF_EVEN); + 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.getRefundCode()); + dto.setRefundAmount(refundAmount.toString()); + dto.setRefundReason("充电完成退款"); + RefundResp resp = aliPaymentClient.refund(dto).getData(); + if(null != resp){ + chargingOrderRefundService.save(chargingOrderRefund); + this.chargingOrderStartupFailureWxRefund(chargingOrderRefund.getRefundCode(), resp.getTradeNo(), "SUCCESS", null); + } + } + + } } } @@ -3112,11 +3170,7 @@ */ @Override public TChargingOrder getChargingOrderByLicensePlate(GetChargingOrderByLicensePlate query) { - TAppUserCar appUserCar = appUserCarClient.getAppUserCarByLicensePlate(query.getLicensePlate()).getData(); - if(null == appUserCar){ - return null; - } - TChargingOrder one = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getAppUserCarId, appUserCar.getId()) + TChargingOrder one = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getPlateNum, query.getLicensePlate()) .eq(TChargingOrder::getDelFlag, 0).between(TChargingOrder::getStartTime, query.getStartTime(), LocalDateTime.now()) .eq(TChargingOrder::getRechargePaymentStatus, 2).in(TChargingOrder::getStatus, Arrays.asList(4, 5))); return one; @@ -3981,39 +4035,49 @@ /** * 添加三方平台充电订单数据 - * @param chargingGunId + * @param query */ @Override - public R addTripartitePlatformOrder(Integer chargingGunId, String operatorId, Integer rechargePaymentType, BigDecimal paymentAmount, String startChargeSeq) { + public R addTripartitePlatformOrder(AddTripartitePlatformOrder query) { //检查当前枪是否是正在使用中 - TChargingOrder one = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getChargingGunId, chargingGunId) + TChargingOrder one = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getChargingGunId, query.getChargingGunId()) .in(TChargingOrder::getStatus, Arrays.asList(1, 2, 3)).eq(TChargingOrder::getDelFlag, 0)); if(null != one){ return R.fail("充电枪正在充电中,启动失败"); } - //构建新的待支付订单 + //构建订单数据 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); TChargingOrder chargingOrder = new TChargingOrder(); String code = "CD" + Double.valueOf(Math.random() * 1000).intValue() + sdf.format(new Date()); chargingOrder.setCode(code); chargingOrder.setOrderType(1); chargingOrder.setOrderClassification(1); - TChargingGun tChargingGun = chargingGunClient.getChargingGunById(chargingGunId).getData(); + TChargingGun tChargingGun = chargingGunClient.getChargingGunById(query.getChargingGunId()).getData(); TChargingPile chargingPile = chargingPileClient.getChargingPileById(tChargingGun.getChargingPileId()).getData(); chargingOrder.setSiteId(tChargingGun.getSiteId()); chargingOrder.setChargingPileId(tChargingGun.getChargingPileId()); - chargingOrder.setChargingGunId(chargingGunId); - chargingOrder.setRechargePaymentType(rechargePaymentType); + chargingOrder.setChargingGunId(query.getChargingGunId()); + chargingOrder.setRechargePaymentType(query.getRechargePaymentType()); chargingOrder.setRechargePaymentStatus(2); - chargingOrder.setRechargeAmount(paymentAmount); + chargingOrder.setRechargeAmount(query.getPaymentAmount()); chargingOrder.setVipDiscountAmount(BigDecimal.ZERO); chargingOrder.setOrderSource(2); - Operator operator = operatorClient.getOperator(operatorId).getData(); + Operator operator = operatorClient.getOperator(query.getOperatorId()).getData(); chargingOrder.setOperatorId(operator.getId()); chargingOrder.setAppUserId(operator.getId().longValue()); chargingOrder.setTripartitePlatformName(operator.getName()); - chargingOrder.setStartChargeSeq(startChargeSeq); + chargingOrder.setStartChargeSeq(query.getStartChargeSeq()); + //车辆信息 + if(StringUtils.hasLength(query.getPlateNum())){ + TAppUserCar appUserCar = appUserCarClient.getAppUserCarByLicensePlate(query.getPlateNum()).getData(); + if(null != appUserCar){ + chargingOrder.setAppUserCarId(appUserCar.getId()); + } + chargingOrder.setPlateNum(query.getPlateNum()); + } + + chargingOrder.setTitle("【充电桩充电】" + chargingPile.getNumber() + "号桩/" + tChargingGun.getCode() + "号枪"); chargingOrder.setStatus(2); chargingOrder.setPayTime(LocalDateTime.now()); @@ -4074,6 +4138,9 @@ scheduler.shutdown(); } }, 5, 1, TimeUnit.SECONDS); + + //推送三方平台订单状态 + tcecClient.notificationEquipChargeStatus(chargingOrder.getStartChargeSeq(), chargingOrder.getOperatorId()); return R.ok(); } @@ -4101,6 +4168,8 @@ chargingOrder.setEndMode(1); this.updateById(chargingOrder); + tcecClient.notificationEquipChargeStatus(order.getStartChargeSeq(), order.getOperatorId()); + String code1 = order.getCode(); TChargingGun chargingGun = chargingGunClient.getChargingGunById(order.getChargingGunId()).getData(); //异步线程处理停机 -- Gitblit v1.7.1