| | |
| | | |
| | | //计数器 |
| | | private Map<String, Integer> boot_failed_map = new HashMap<>(); |
| | | |
| | | @Resource |
| | | private OperatorClient operatorClient; |
| | | |
| | | |
| | | |
| | |
| | | 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); |
| | |
| | | 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(); |
| | | //构建退款明细 |
| | |
| | | public Long countCar(List<String> brands) { |
| | | return this.baseMapper.countCar(brands); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 添加三方平台充电订单数据 |
| | | * @param chargingGunId |
| | | */ |
| | | @Override |
| | | public R addTripartitePlatformOrder(Integer chargingGunId, String operatorId, Integer rechargePaymentType, BigDecimal paymentAmount, String startChargeSeq) { |
| | | //检查当前枪是否是正在使用中 |
| | | TChargingOrder one = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getChargingGunId, chargingGunId) |
| | | .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(); |
| | | TChargingPile chargingPile = chargingPileClient.getChargingPileById(tChargingGun.getChargingPileId()).getData(); |
| | | chargingOrder.setSiteId(tChargingGun.getSiteId()); |
| | | chargingOrder.setChargingPileId(tChargingGun.getChargingPileId()); |
| | | chargingOrder.setChargingGunId(chargingGunId); |
| | | chargingOrder.setRechargePaymentType(rechargePaymentType); |
| | | chargingOrder.setRechargePaymentStatus(2); |
| | | chargingOrder.setRechargeAmount(paymentAmount); |
| | | chargingOrder.setVipDiscountAmount(BigDecimal.ZERO); |
| | | chargingOrder.setOrderSource(2); |
| | | Operator operator = operatorClient.getOperator(operatorId).getData(); |
| | | chargingOrder.setOperatorId(operator.getId()); |
| | | chargingOrder.setAppUserId(operator.getId().longValue()); |
| | | chargingOrder.setTripartitePlatformName(operator.getName()); |
| | | chargingOrder.setStartChargeSeq(startChargeSeq); |
| | | 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); |
| | | 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); |
| | | |
| | | 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(); |
| | | } |
| | | } |