From 8236caa8042288fcb9b584c21d6157f713183626 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期四, 13 二月 2025 16:36:01 +0800 Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/mx_charging_pile --- ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java | 415 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 325 insertions(+), 90 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 d599596..122a6b8 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; @@ -142,7 +143,7 @@ private UploadRealTimeMonitoringDataClient uploadRealTimeMonitoringDataClient; @Resource - private ChargingHandshakeClient chargingHandshakeClient; + private TCECClient tcecClient; @Resource private SendMessageClient sendMessageClient; @@ -203,6 +204,12 @@ //计数器 private Map<String, Integer> boot_failed_map = new HashMap<>(); + + @Resource + private OperatorClient operatorClient; + + @Resource + private TransactionRecordClient transactionRecordClient; @@ -273,6 +280,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); @@ -456,6 +465,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()); @@ -466,7 +481,7 @@ chargingOrder.setRechargeAmount(addChargingOrder.getPaymentAmount()); chargingOrder.setAppCouponId(addChargingOrder.getAppUserCouponId()); chargingOrder.setVipDiscountAmount(BigDecimal.ZERO); - chargingOrder.setOrderSource(0); + chargingOrder.setOrderSource(1); chargingOrder.setTitle("【充电桩充电】" + chargingPile.getNumber() + "号桩/" + tChargingGun.getCode() + "号枪"); Site site = siteClient.getSiteByIds(Arrays.asList(tChargingGun.getSiteId())).getData().get(0); @@ -746,6 +761,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); @@ -776,6 +795,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; } } @@ -835,9 +858,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()); + } } /** @@ -847,7 +885,7 @@ public void refund(String code){ log.info(code + ":-------------------充电启动失败,执行退款-------------------"); TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, code)); - if(chargingOrder.getStatus() == 2){ + if(chargingOrder.getOrderSource() == 1 && chargingOrder.getStatus() == 2){ Integer rechargePaymentType = chargingOrder.getRechargePaymentType(); BigDecimal rechargeAmount = chargingOrder.getRechargeAmount(); //构建退款明细 @@ -1005,7 +1043,6 @@ chargingOrder.setStatus(4); chargingOrder.setEndMode(1); this.updateById(chargingOrder); - String code1 = order.getCode(); TChargingGun chargingGun = chargingGunClient.getChargingGunById(order.getChargingGunId()).getData(); //异步线程处理停机 @@ -1020,6 +1057,11 @@ log.info(code1 + ":-------------------远程停止充电请求-------------------"); log.info(platformStopCharging.toString()); }); + //推送三方平台 + if(2 == order.getOrderSource()){ + tcecClient.notificationEquipChargeStatus(order.getStartChargeSeq(), order.getOperatorId()); + } + return AjaxResult.success(); } @@ -1320,6 +1362,8 @@ if (tAppUserCar!=null){ chargingOrderVO.setLicensePlate(tAppUserCar.getLicensePlate()); } + }else{ + chargingOrderVO.setLicensePlate(chargingOrderVO.getPlateNum()); } } @@ -1589,6 +1633,8 @@ chargingOrderListVO.setLicensePlate(data4.get(0).getLicensePlate()); } } + }else{ + chargingOrderListVO.setLicensePlate(chargingOrderListVO.getPlateNum()); } chargingOrderListVO.setPhone(data3.getPhone()); } @@ -1866,7 +1912,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()); @@ -1915,7 +1965,7 @@ chargingOrder.setChargingCapacity(query.getCharging_degree()); chargingOrder.setElectricity(query.getCharging_degree()); chargingOrder.setTotalElectricity(new BigDecimal(100 - query.getSoc())); - BmsDemandAndChargerExportation data = bmsDemandAndChargerExportationClient.getBmsDemandAndChargerExportation(chargingOrder.getCode()).getData(); + BmsDemandAndChargerExportation data = bmsDemandAndChargerExportationClient.getBmsDemandAndChargerExportation(chargingOrder1.getCode()).getData(); if(null != data){ chargingOrder.setNeedElec(data.getBms_current_requirements()); } @@ -2277,6 +2327,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){ @@ -2298,91 +2356,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); + } + } + + } } return R.ok(); } @@ -2678,11 +2742,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; @@ -3541,4 +3601,179 @@ public Long countCar(List<String> brands) { return this.baseMapper.countCar(brands); } + + + /** + * 添加三方平台充电订单数据 + * @param query + */ + @Override + public R addTripartitePlatformOrder(AddTripartitePlatformOrder query) { + //检查当前枪是否是正在使用中 + 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(query.getChargingGunId()).getData(); + TChargingPile chargingPile = chargingPileClient.getChargingPileById(tChargingGun.getChargingPileId()).getData(); + chargingOrder.setSiteId(tChargingGun.getSiteId()); + chargingOrder.setChargingPileId(tChargingGun.getChargingPileId()); + chargingOrder.setChargingGunId(query.getChargingGunId()); + chargingOrder.setRechargePaymentType(query.getRechargePaymentType()); + chargingOrder.setRechargePaymentStatus(2); + chargingOrder.setRechargeAmount(query.getPaymentAmount()); + chargingOrder.setVipDiscountAmount(BigDecimal.ZERO); + chargingOrder.setOrderSource(2); + Operator operator = operatorClient.getOperator(query.getOperatorId()).getData(); + chargingOrder.setOperatorId(operator.getId()); + chargingOrder.setAppUserId(operator.getId().longValue()); + chargingOrder.setTripartitePlatformName(operator.getName()); + 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()); + chargingOrder.setChargeAmount(chargingOrder.getRechargeAmount()); + chargingOrder.setVipDiscountAmount(BigDecimal.ZERO); + this.save(chargingOrder); + + Integer accountingStrategyId = tChargingGun.getAccountingStrategyId(); + if(null == accountingStrategyId){ + Site site = siteClient.getSiteByIds(Arrays.asList(tChargingGun.getSiteId())).getData().get(0); + //查询站点上面的计费策略 + accountingStrategyId = site.getAccountingStrategyId(); + } + TAccountingStrategy accountingStrategy = accountingStrategyClient.getAccountingStrategyById(accountingStrategyId).getData(); + + //添加订单的计费策略 + List<TAccountingStrategyDetail> strategyDetailList = accountingStrategyDetailClient.getListByAccountingStrategyId(accountingStrategyId).getData(); + AccountingStrategyOrder accountingStrategyOrder = new AccountingStrategyOrder(); + BeanUtils.copyProperties(accountingStrategy, accountingStrategyOrder); + accountingStrategyOrder.setChargingOrderId(chargingOrder.getId()); + accountingStrategyOrderService.save(accountingStrategyOrder); + List<AccountingStrategyDetailOrder> list1 = new ArrayList<>(); + for (TAccountingStrategyDetail tAccountingStrategyDetail : strategyDetailList) { + AccountingStrategyDetailOrder accountingStrategyDetailOrder = new AccountingStrategyDetailOrder(); + BeanUtils.copyProperties(tAccountingStrategyDetail, accountingStrategyDetailOrder); + accountingStrategyDetailOrder.setChargingOrderId(chargingOrder.getId()); + list1.add(accountingStrategyDetailOrder); + } + accountingStrategyDetailOrderService.saveBatch(list1); + + + //添加安全检测数据到缓存中,每步安全检测完成后需要更新缓存数据 + PreChargeCheck preChargeCheck = new PreChargeCheck(); + preChargeCheck.setElectronicLockLock(false); + preChargeCheck.setInsulationTesting(false); + preChargeCheck.setSecureConnectionDetection(false); + preChargeCheck.setStartupSuccess(1); + String key = "AQJC_" + chargingOrder.getChargingGunId(); + redisService.setCacheObject(key, preChargeCheck, 24L, TimeUnit.HOURS); + + BigDecimal rechargeAmount = chargingOrder.getRechargeAmount(); + //调用远程启动充电消息 + PlatformStartCharging platformStartCharging = new PlatformStartCharging(); + platformStartCharging.setTransaction_serial_number(chargingOrder.getCode()); + platformStartCharging.setCharging_pile_code(chargingPile.getCode()); + platformStartCharging.setCharging_gun_code(tChargingGun.getCode()); + //使用订单id作为逻辑卡号 + platformStartCharging.setCard_number(chargingOrder.getId().toString()); + platformStartCharging.setAccount_balance(rechargeAmount); + log.info(chargingOrder.getCode() + ":-------------------远程调起开始充电请求-------------------" + platformStartCharging.toString()); + sendMessageClient.platformStartCharging(platformStartCharging); + //异步线程检测远程启动的应答结果。如果失败,则需要全额退款 + Long id = chargingOrder.getId(); + //执行5分钟的定时任务检测 + ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + scheduler.scheduleAtFixedRate(()->{ + if(timingDetection(id)){ + scheduler.shutdown(); + } + }, 5, 1, TimeUnit.SECONDS); + + //推送三方平台订单状态 + tcecClient.notificationEquipChargeStatus(chargingOrder.getStartChargeSeq(), chargingOrder.getOperatorId()); + return R.ok(); + } + + + /** + * 三方平台停止充电操作 + * @param startChargeSeq + * @return + */ + @Override + public R tripartitePlatformStopCharge(String startChargeSeq) { + TChargingOrder order = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getStartChargeSeq, startChargeSeq)); + Integer status = order.getStatus(); + if(status != 3){ + return R.fail("还未开始充电"); + } + if(status == 4 || status == 5){ + return R.fail("不能重复操作"); + } + TChargingOrder chargingOrder = new TChargingOrder(); + chargingOrder.setId(order.getId()); + chargingOrder.setAppUserId(order.getOperatorId().longValue()); + chargingOrder.setEndTime(LocalDateTime.now()); + chargingOrder.setStatus(4); + chargingOrder.setEndMode(1); + this.updateById(chargingOrder); + + tcecClient.notificationEquipChargeStatus(order.getStartChargeSeq(), order.getOperatorId()); + + String code1 = order.getCode(); + TChargingGun chargingGun = chargingGunClient.getChargingGunById(order.getChargingGunId()).getData(); + //异步线程处理停机 + ExecutorService cachedThreadPool = Executors.newFixedThreadPool(1); + cachedThreadPool.execute(()->{ + //调用硬件停止充电,停止成功后开始计算费用退款 + TChargingPile chargingPile = chargingPileClient.getChargingPileById(order.getChargingPileId()).getData(); + PlatformStopCharging platformStopCharging = new PlatformStopCharging(); + platformStopCharging.setCharging_pile_code(chargingPile.getCode()); + platformStopCharging.setCharging_gun_code(chargingGun.getCode()); + sendMessageClient.platformStopCharging(platformStopCharging); + log.info(code1 + ":-------------------远程停止充电请求-------------------"); + log.info(platformStopCharging.toString()); + }); + return R.ok(); + } + + + /** + * 获取充电后没有扣除费用的数据 + * @return + */ + @Override + public R getNotPaymentChargingOrder() { + List<TChargingOrder> list = this.list(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getPaymentAmount, 0) + .ne(TChargingOrder::getElectricity, 0).in(TChargingOrder::getStatus, Arrays.asList(4, 5))); + List<Map<String, Object>> mapList = new ArrayList<>(); + for (TChargingOrder order : list) { + TransactionRecord transactionRecord = transactionRecordClient.findTransactionRecord(order.getCode()).getData(); + Map<String, Object> map = new HashMap<>(); + map.put("order", order); + map.put("transactionRecord", transactionRecord); + mapList.add(map); + } + return R.ok(mapList); + } } -- Gitblit v1.7.1