| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.api.feignClient.AppUserCarClient; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | |
| | | import com.ruoyi.account.api.model.TAppUserCar; |
| | | import com.ruoyi.account.api.model.TAppUserVipDetail; |
| | | import com.ruoyi.account.api.vo.GetAppUserVipDetail; |
| | | import com.ruoyi.chargingPile.api.feignClient.AccountingStrategyDetailClient; |
| | | import com.ruoyi.chargingPile.api.feignClient.ChargingGunClient; |
| | | import com.ruoyi.chargingPile.api.feignClient.ChargingPileClient; |
| | | import com.ruoyi.chargingPile.api.feignClient.SiteClient; |
| | | import com.ruoyi.chargingPile.api.model.Site; |
| | | import com.ruoyi.chargingPile.api.model.TAccountingStrategyDetail; |
| | | import com.ruoyi.chargingPile.api.model.TChargingGun; |
| | | import com.ruoyi.chargingPile.api.model.TChargingPile; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.dto.ChargingOrderGroup; |
| | | import com.ruoyi.common.core.dto.ChargingPercentProvinceDto; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.core.web.page.BasePage; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.integration.api.feignClient.ChargingHandshakeClient; |
| | | import com.ruoyi.integration.api.feignClient.PlatformStartChargingReplyClient; |
| | | import com.ruoyi.integration.api.feignClient.SendMessageClient; |
| | | import com.ruoyi.integration.api.feignClient.UploadRealTimeMonitoringDataClient; |
| | | import com.ruoyi.integration.api.model.ChargingHandshake; |
| | | import com.ruoyi.integration.api.model.PlatformStartCharging; |
| | | import com.ruoyi.integration.api.model.PlatformStartChargingReply; |
| | | import com.ruoyi.integration.api.model.UploadRealTimeMonitoringData; |
| | | import com.ruoyi.order.api.model.TChargingOrder; |
| | | import com.ruoyi.order.api.model.TChargingOrderAccountingStrategy; |
| | | import com.ruoyi.order.api.model.TChargingOrderRefund; |
| | | import com.ruoyi.order.api.model.TOrderEvaluate; |
| | | import com.ruoyi.order.api.model.*; |
| | | import com.ruoyi.order.api.query.ChargingOrderQuery; |
| | | import com.ruoyi.order.api.query.UploadRealTimeMonitoringDataQuery; |
| | | import com.ruoyi.order.api.vo.ChargingOrderListVO; |
| | | import com.ruoyi.order.api.vo.ChargingOrderTimeVO; |
| | | import com.ruoyi.order.api.vo.ChargingOrderVO; |
| | | import com.ruoyi.order.api.vo.TCharingOrderVO; |
| | | import com.ruoyi.order.dto.*; |
| | | import com.ruoyi.order.mapper.TChargingOrderMapper; |
| | | import com.ruoyi.order.service.TChargingOrderAccountingStrategyService; |
| | | import com.ruoyi.order.service.TChargingOrderRefundService; |
| | | import com.ruoyi.order.service.TChargingOrderService; |
| | | import com.ruoyi.order.service.TOrderEvaluateService; |
| | | import com.ruoyi.other.api.domain.TCoupon; |
| | | import com.ruoyi.other.api.domain.TGoods; |
| | | import com.ruoyi.order.vo.ChargingOrderListInfoVO; |
| | | import com.ruoyi.payment.api.feignClient.AliPaymentClient; |
| | | import com.ruoyi.payment.api.feignClient.WxPaymentClient; |
| | | import com.ruoyi.payment.api.model.RefundReq; |
| | | import com.ruoyi.payment.api.model.RefundResp; |
| | | import com.ruoyi.payment.api.model.WxPaymentRefundModel; |
| | | import com.ruoyi.payment.api.vo.*; |
| | | import io.seata.spring.annotation.GlobalTransactional; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneOffset; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.util.concurrent.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private AppUserCarClient appUserCarClient; |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | |
| | | |
| | | @Resource |
| | | private ChargingPileClient chargingPileClient; |
| | | |
| | | |
| | | @Resource |
| | | private TChargingOrderAccountingStrategyService chargingOrderAccountingStrategyService; |
| | | |
| | |
| | | @Resource |
| | | private AliPaymentClient aliPaymentClient; |
| | | |
| | | @Resource |
| | | private ChargingPileClient chargingPileClient; |
| | | |
| | | |
| | | |
| | | |
| | | @Resource |
| | | private AppUserVipDetailClient appUserVipDetailClient; |
| | |
| | | |
| | | @Resource |
| | | private ChargingHandshakeClient chargingHandshakeClient; |
| | | |
| | | |
| | | @Resource |
| | | private SendMessageClient sendMessageClient; |
| | | |
| | | |
| | | @Resource |
| | | private TOrderEvaluateService orderEvaluateService; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @Resource |
| | | private AccountingStrategyDetailClient accountingStrategyDetailClient; |
| | | |
| | | @Resource |
| | | private PlatformStartChargingReplyClient platformStartChargingReplyClient; |
| | | |
| | | @Resource |
| | | private TChargingOrderRefundService chargingOrderRefundService; |
| | | |
| | | //计数器 |
| | | private Map<String, Integer> counter_map = new HashMap<>(); |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取小程序充电记录列表数据 |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @GlobalTransactional(rollbackFor = Exception.class) |
| | | public AjaxResult chargingOrderCallback(Integer paymentType, String out_trade_no, String transaction_id, String attach) { |
| | | TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, out_trade_no)); |
| | | if(chargingOrder.getRechargePaymentStatus() == 2){ |
| | |
| | | } |
| | | chargingOrder.setRechargePaymentStatus(2); |
| | | chargingOrder.setRechargeSerialNumber(transaction_id); |
| | | chargingOrder.setStatus(2); |
| | | this.updateById(chargingOrder); |
| | | |
| | | //添加安全检测数据到缓存中,每步安全检测完成后需要更新缓存数据 |
| | | 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); |
| | | |
| | | //根据当前充值的金额和计费模板算出充电的金额 |
| | | BigDecimal rechargeAmount = chargingOrder.getRechargeAmount(); |
| | | //计算充电金额,会员需要将折扣金额加入到充电总金额中 |
| | | |
| | | // TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData(); |
| | | // if(){ |
| | | // appUser.getVipId() |
| | | // } |
| | | // |
| | | // |
| | | // //调用远程启动充电消息 |
| | | // PlatformStartCharging platformStartCharging = new PlatformStartCharging(); |
| | | // platformStartCharging.setTransaction_serial_number(chargingOrder.getCode()); |
| | | // platformStartCharging.setCharging_pile_code(); |
| | | // platformStartCharging.setCharging_gun_code(); |
| | | // platformStartCharging.setCard_number(); |
| | | // platformStartCharging.setAccount_balance() |
| | | // sendMessageClient.platformStartCharging(platformStartCharging); |
| | | TChargingGun chargingGun = chargingGunClient.getChargingGunById(chargingOrder.getChargingGunId()).getData(); |
| | | TAccountingStrategyDetail strategyDetail = accountingStrategyDetailClient.getNowData(chargingGun.getAccountingStrategyId()).getData(); |
| | | //总单价 |
| | | BigDecimal totalUnitPrice = strategyDetail.getServiceCharge().add(strategyDetail.getElectrovalence()); |
| | | //计算能充电的度数 |
| | | BigDecimal degrees = rechargeAmount.divide(totalUnitPrice); |
| | | //计算电费金额和服务费 |
| | | BigDecimal serviceCharge = strategyDetail.getServiceCharge().multiply(degrees); |
| | | BigDecimal electrovalence = strategyDetail.getElectrovalence().multiply(degrees); |
| | | |
| | | //再处理会员折扣 |
| | | BigDecimal discount = BigDecimal.ZERO; |
| | | TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData(); |
| | | if(null != appUser.getVipId()){ |
| | | GetAppUserVipDetail getAppUserVipDetail = new GetAppUserVipDetail(); |
| | | getAppUserVipDetail.setAppUserId(chargingOrder.getAppUserId()); |
| | | getAppUserVipDetail.setVipId(appUser.getVipId()); |
| | | TAppUserVipDetail data = appUserVipDetailClient.getAppUserVipDetail(getAppUserVipDetail).getData(); |
| | | if(data.getChargeNum() > 0){ |
| | | discount = serviceCharge.multiply(data.getDiscount().divide(new BigDecimal(10))); |
| | | data.setChargeNum(data.getChargeNum() - 1); |
| | | appUserVipDetailClient.updateAppUserVipDetail(data); |
| | | } |
| | | } |
| | | electrovalence = electrovalence.add(discount); |
| | | |
| | | |
| | | TChargingPile chargingPile = chargingPileClient.getChargingPileById(chargingGun.getChargingPileId()).getData(); |
| | | //调用远程启动充电消息 |
| | | PlatformStartCharging platformStartCharging = new PlatformStartCharging(); |
| | | platformStartCharging.setTransaction_serial_number(chargingOrder.getCode()); |
| | | platformStartCharging.setCharging_pile_code(chargingPile.getCode()); |
| | | platformStartCharging.setCharging_gun_code(chargingGun.getCode()); |
| | | //使用订单id作为逻辑卡号 |
| | | platformStartCharging.setCard_number(chargingOrder.getId().toString()); |
| | | platformStartCharging.setAccount_balance(electrovalence); |
| | | sendMessageClient.platformStartCharging(platformStartCharging); |
| | | //异步线程检测远程启动的应答结果。如果失败,则需要全额退款 |
| | | String code = chargingOrder.getCode(); |
| | | //执行5分钟的定时任务检测 |
| | | ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); |
| | | scheduler.scheduleAtFixedRate(()->{ |
| | | List<PlatformStartChargingReply> data = platformStartChargingReplyClient.getPlatformStartChargingReply(code).getData(); |
| | | if(data.size() != 0){ |
| | | PlatformStartChargingReply platformStartChargingReply = data.get(1); |
| | | Integer startup_result = platformStartChargingReply.getStartup_result(); |
| | | Integer failure_cause = platformStartChargingReply.getFailure_cause(); |
| | | Integer counter = counter_map.get(code); |
| | | PreChargeCheck preChargeCheck1 = redisService.getCacheObject(key); |
| | | //状态为5的时候,硬件会间隔60秒后再次检测,依然未插枪,则不启动充电 |
| | | //因这里是间隔5秒执行检测,所以累计次数在30次以上 |
| | | if(failure_cause == 5 && null == counter || counter < 35){ |
| | | counter++; |
| | | counter_map.put(code, counter); |
| | | //启动失败 |
| | | preChargeCheck1.setStartupSuccess(3); |
| | | preChargeCheck1.setFailureCause(failure_cause); |
| | | redisService.setCacheObject(key, preChargeCheck1); |
| | | return; |
| | | } |
| | | //清除计时器中的无效数据 |
| | | counter_map.remove(code); |
| | | //开始处理退款 |
| | | TChargingOrder order = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, code)); |
| | | if(0 == startup_result){ |
| | | //启动失败 |
| | | preChargeCheck1.setStartupSuccess(3); |
| | | preChargeCheck1.setFailureCause(failure_cause); |
| | | //启动失败后取消订单,退款操作 |
| | | refund(code); |
| | | order.setStatus(5); |
| | | order.setEndMode(0); |
| | | }else{ |
| | | preChargeCheck1.setStartupSuccess(2); |
| | | order.setStatus(3); |
| | | order.setStartTime(LocalDateTime.now()); |
| | | } |
| | | this.updateById(order); |
| | | redisService.setCacheObject(key, preChargeCheck1); |
| | | //提前结束定时任务 |
| | | scheduler.shutdown(); |
| | | } |
| | | }, 5, 300, TimeUnit.SECONDS); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 启动失败后的退款,取消订单 |
| | | * @param code |
| | | */ |
| | | public void refund(String code){ |
| | | TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, code)); |
| | | if(chargingOrder.getStatus() == 2){ |
| | | Integer rechargePaymentType = chargingOrder.getRechargePaymentType(); |
| | | BigDecimal rechargeAmount = chargingOrder.getRechargeAmount(); |
| | | //构建退款明细 |
| | | TChargingOrderRefund chargingOrderRefund = new TChargingOrderRefund(); |
| | | chargingOrderRefund.setChargingOrderId(chargingOrder.getId()); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | chargingOrderRefund.setRefundCode("CDF" + sdf.format(new Date()) + (Math.random() * 1000)); |
| | | chargingOrderRefund.setRefundAmount(rechargeAmount); |
| | | chargingOrderRefund.setRefundStatus(1); |
| | | chargingOrderRefund.setPayType(rechargePaymentType); |
| | | chargingOrderRefund.setRefundStatus(1); |
| | | chargingOrderRefund.setCode(code); |
| | | chargingOrderRefund.setRefundTitle("充电失败"); |
| | | chargingOrderRefund.setRefundContent("充电失败"); |
| | | chargingOrderRefund.setRefundReason("充电失败"); |
| | | chargingOrderRefund.setRefundRemark("全额退款"); |
| | | chargingOrderRefund.setRefundTotalAmount(rechargeAmount); |
| | | 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("http://127.0.0.1:9000/order/t-charging-order/chargingOrderStartupFailureWxRefund"); |
| | | WxPaymentRefundModel.RefundAmount amount = new WxPaymentRefundModel.RefundAmount(); |
| | | amount.setRefund(rechargeAmount.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.getCode()); |
| | | dto.setRefundAmount(rechargeAmount.toString()); |
| | | dto.setRefundReason("充电失败,取消充电订单"); |
| | | RefundResp resp = aliPaymentClient.refund(dto).getData(); |
| | | if(null != resp){ |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-DDTHH:mm:ss+TIMEZONE"); |
| | | AjaxResult success = chargingOrderStartupFailureWxRefund(resp.getOutTradeNo(), resp.getTradeNo(), "SUCCESS", sdf1.format(new Date())); |
| | | if(success.isSuccess()){ |
| | | chargingOrderRefundService.save(chargingOrderRefund); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 启动失败后微信退款的回调处理 |
| | | * @param out_refund_no |
| | | * @param refund_id |
| | | * @param tradeState |
| | | * @param success_time |
| | | * @return |
| | | */ |
| | | public AjaxResult chargingOrderStartupFailureWxRefund(String out_refund_no, String refund_id, String tradeState, String success_time){ |
| | | if("SUCCESS".equals(tradeState)){ |
| | | TChargingOrderRefund one = chargingOrderRefundService.getOne(new LambdaQueryWrapper<TChargingOrderRefund>().eq(TChargingOrderRefund::getRefundCode, out_refund_no)); |
| | | one.setRefundSerialNumber(refund_id); |
| | | one.setRefundStatus(2); |
| | | one.setRefundTime(LocalDateTime.parse(success_time, DateTimeFormatter.ofPattern("yyyy-MM-DDTHH:mm:ss+TIMEZONE"))); |
| | | chargingOrderRefundService.updateById(one); |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取充电中的详情 |
| | | * @param id |
| | |
| | | chargingDetails.setName(site.getName() + "-" + chargingPile.getName()); |
| | | chargingDetails.setCode(one.getCode()); |
| | | chargingDetails.setStatus(one.getStatus()); |
| | | chargingDetails.setChargingCost(one.getResidualAmount()); |
| | | UploadRealTimeMonitoringData data = uploadRealTimeMonitoringDataClient.chargingOrderInfo(one.getCode()).getData(); |
| | | if(null != data){ |
| | | chargingDetails.setChargeCurrent(data.getOutput_current()); |
| | |
| | | chargingDetails.setRemainingChargeTime(data.getTime_remaining()); |
| | | chargingDetails.setChargedDegrees(data.getCharging_degree()); |
| | | chargingDetails.setChargedTime(data.getCumulative_charging_time()); |
| | | chargingDetails.setChargingCost(data.getPaid_amount()); |
| | | } |
| | | ChargingHandshake chargingHandshake = chargingHandshakeClient.getDataByOrderCode(one.getCode()).getData(); |
| | | if(null != chargingHandshake && null != data && null != one.getAppUserCarId()){ |
| | |
| | | chargingOrder.setEndMode(1); |
| | | this.updateById(chargingOrder); |
| | | //调用硬件停止充电,停止成功后开始计算费用退款 |
| | | |
| | | |
| | | |
| | | // todo 待完善 |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | public void endCharge(){ |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public TCharingOrderVO chargingOrder(ChargingOrderQuery dto) { |
| | |
| | | BigDecimal electronicMoney = new BigDecimal("0"); |
| | | BigDecimal serviceMoney = new BigDecimal("0"); |
| | | for (ChargingOrderVO chargingOrderVO : list) { |
| | | TChargingGun data3 = chargingGunClient.getChargingGunById(chargingOrderVO.getChargingGunId()).getData(); |
| | | TChargingPile data2 = chargingPileClient.getChargingPileById(chargingOrderVO.getChargingPileId()).getData(); |
| | | if (data2!=null && data3!=null){ |
| | | chargingOrderVO.setTerminalName(data2.getName()+"-"+data3.getName()); |
| | | |
| | | } |
| | | if (chargingOrderVO.getChargingCapacity()!=null){ |
| | | total = total.add(chargingOrderVO.getChargingCapacity()); |
| | | } |
| | |
| | | BigDecimal electronicMoney1 = new BigDecimal("0"); |
| | | // 单个订单累计服务费 |
| | | BigDecimal serviceMoney1 = new BigDecimal("0"); |
| | | LocalDateTime startTime = chargingOrderVO.getStartTime(); |
| | | LocalDateTime endTime = chargingOrderVO.getEndTime(); |
| | | // 计算时间差 秒 充电时长 |
| | | if (startTime!=null && endTime!=null){ |
| | | long between = ChronoUnit.SECONDS.between(startTime, endTime); |
| | | chargingOrderVO.setChargingSecond(between); |
| | | time += between; |
| | | } |
| | | UploadRealTimeMonitoringData data5 = uploadRealTimeMonitoringDataClient.chargingOrderInfo(chargingOrderVO.getCode()).getData(); |
| | | chargingOrderVO.setChargingSecond(data5.getTime_remaining()*60L); |
| | | // 总收入 |
| | | if (chargingOrderVO.getRefundStatus() !=null && chargingOrderVO.getRefundStatus() == 2){ |
| | | income = income.add(chargingOrderVO.getPaymentAmount().subtract(chargingOrderVO.getRefundAmount())); |
| | |
| | | |
| | | return R.ok(pageInfo); |
| | | } |
| | | |
| | | @Override |
| | | public List<ChargingOrderGroup> chargingOrderGroup(ChargingPercentProvinceDto chargingPercentProvinceDto) { |
| | | |
| | | return this.baseMapper.chargingOrderGroup(chargingPercentProvinceDto); |
| | | } |
| | | |
| | | @Override |
| | | public List<SixChargingDto> charge(LocalDate sixBefore, List<Integer> siteIds) { |
| | | return this.baseMapper.charge(sixBefore,siteIds); |
| | | } |
| | | |
| | | @Override |
| | | public List<SixCircleDto> circle(List<Integer> siteIds,LocalDate sixBefore) { |
| | | return this.baseMapper.circle(siteIds,sixBefore); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, BigDecimal> countAll(LocalDate sixBefore) { |
| | | return this.baseMapper.countAll(sixBefore); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, BigDecimal>> getSumByType(List<Long> chargingOrderIds) { |
| | | return this.baseMapper.getSumByType(chargingOrderIds); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, BigDecimal>> getDateData(List<Long> chargingOrderIds) { |
| | | return this.baseMapper.getDateData(chargingOrderIds); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, BigDecimal>> getWeekData(List<Long> chargingOrderIds) { |
| | | return this.baseMapper.getWeekData(chargingOrderIds); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, BigDecimal>> getMonthData(List<Long> chargingOrderIds) { |
| | | return this.baseMapper.getMonthData(chargingOrderIds); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, BigDecimal>> getYearData(List<Long> chargingOrderIds) { |
| | | return this.baseMapper.getYearData(chargingOrderIds); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public ChargingOrderTimeVO chargingList(ChargingListQuery dto) { |
| | | String startTime1 = null; |
| | | String startTime2 = null; |
| | | String endTime1 = null; |
| | | String endTime2 = null; |
| | | |
| | | if (StringUtils.hasLength(dto.getStartTime())){ |
| | | String[] split = dto.getStartTime().split(" - "); |
| | | startTime1 = split[0]; |
| | | startTime2 = split[1]; |
| | | } |
| | | if (StringUtils.hasLength(dto.getEndTime())){ |
| | | String[] split = dto.getEndTime().split(" - "); |
| | | endTime1 = split[0]; |
| | | endTime2 = split[1]; |
| | | } |
| | | ChargingOrderTimeVO chargingOrderTimeVO = new ChargingOrderTimeVO(); |
| | | |
| | | |
| | | PageInfo<ChargingOrderListVO> pageInfo = new PageInfo<>(dto.getPageCurr(),dto.getPageSize()); |
| | | List<ChargingOrderListVO> list = this.baseMapper.chargingList(pageInfo,dto,startTime1,startTime2,endTime1,endTime2); |
| | | for (ChargingOrderListVO chargingOrderListVO : list) { |
| | | chargingOrderListVO.setUid(chargingOrderListVO.getId()+""); |
| | | List<Integer> integers = new ArrayList<>(); |
| | | integers.add(chargingOrderListVO.getSiteId()); |
| | | List<Site> data = siteClient.getSiteByIds(integers).getData(); |
| | | if (!data.isEmpty()) { |
| | | chargingOrderListVO.setSiteName(data.get(0).getName()); |
| | | } |
| | | TChargingGun data1 = chargingGunClient.getChargingGunById(chargingOrderListVO.getChargingGunId()).getData(); |
| | | TChargingPile data2 = chargingPileClient.getChargingPileById(chargingOrderListVO.getChargingPileId()).getData(); |
| | | if (data2 != null && data1 != null) { |
| | | chargingOrderListVO.setTerminalName(data2.getName() + "-" + data1.getName()); |
| | | } |
| | | // 获取充电时间 |
| | | UploadRealTimeMonitoringData data5 = uploadRealTimeMonitoringDataClient.chargingOrderInfo(chargingOrderListVO.getCode()).getData(); |
| | | if (data5!=null){ |
| | | if (data5.getTime_remaining()!=null){ |
| | | chargingOrderListVO.setChargingSecond(data5.getTime_remaining()*60L); |
| | | |
| | | } |
| | | } |
| | | // 获取开始SOC 结束soc |
| | | List<UploadRealTimeMonitoringData> data6 = uploadRealTimeMonitoringDataClient.getDataByOrderCode(chargingOrderListVO.getCode()).getData(); |
| | | if (!data6.isEmpty()){ |
| | | // 第一条数据soc为开始 最后一条数据soc为结束soc |
| | | chargingOrderListVO.setStartSoc(data6.get(0).getSoc().toString()); |
| | | chargingOrderListVO.setEndSoc(data6.get(data6.size()-1).getSoc().toString()); |
| | | } |
| | | TAppUser data3 = appUserClient.getUserById(chargingOrderListVO.getAppUserId()).getData(); |
| | | List<Long> carId = new ArrayList<>(); |
| | | if (chargingOrderListVO.getAppUserCarId() != null) { |
| | | carId.add(chargingOrderListVO.getAppUserCarId()); |
| | | List<TAppUserCar> data4 = appUserCarClient.getCarByIds(carId).getData(); |
| | | if (!data4.isEmpty()) chargingOrderListVO.setLicensePlate(data4.get(0).getLicensePlate()); |
| | | } |
| | | if (data3 != null) chargingOrderListVO.setPhone(data3.getPhone()); |
| | | List<TChargingOrderAccountingStrategy> list2 = chargingOrderAccountingStrategyService.lambdaQuery() |
| | | .eq(TChargingOrderAccountingStrategy::getChargingOrderId, chargingOrderListVO.getId()).list(); |
| | | // 尖峰平谷充电量 度数 |
| | | BigDecimal jian = new BigDecimal("0"); |
| | | BigDecimal feng = new BigDecimal("0"); |
| | | BigDecimal ping = new BigDecimal("0"); |
| | | BigDecimal gu = new BigDecimal("0"); |
| | | BigDecimal total = new BigDecimal("0"); |
| | | for (TChargingOrderAccountingStrategy temp : list2) { |
| | | switch (temp.getType()) { |
| | | case 1: |
| | | jian = jian.add(temp.getChargingCapacity()); |
| | | break; |
| | | case 2: |
| | | feng = feng.add(temp.getChargingCapacity()); |
| | | break; |
| | | case 3: |
| | | ping = ping.add(temp.getChargingCapacity()); |
| | | break; |
| | | case 4: |
| | | gu = gu.add(temp.getChargingCapacity()); |
| | | break; |
| | | } |
| | | } |
| | | total = total.add(jian).add(feng).add(ping).add(gu); |
| | | chargingOrderListVO.setElectronicProportion( |
| | | jian.divide(total,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))+"%(尖)/" |
| | | +feng.divide(total,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))+"%(峰)/" |
| | | +ping.divide(total,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))+"%(平)/" |
| | | +gu.divide(total,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))+"%(谷)"); |
| | | } |
| | | // 不分页 |
| | | List<ChargingOrderListVO> list1 = this.baseMapper.chargingList1(dto,startTime1,startTime2,endTime1,endTime2); |
| | | chargingOrderTimeVO.setOrderCount(list1.size()); |
| | | // 计算充电总度数 |
| | | BigDecimal electronic = new BigDecimal("0"); |
| | | // 支付金额 |
| | | BigDecimal paymentAmount = new BigDecimal("0"); |
| | | // 电费 |
| | | BigDecimal electrovalence = new BigDecimal("0"); |
| | | // 服务费 |
| | | BigDecimal serviceCharge = new BigDecimal("0"); |
| | | // 尖峰平谷充电到账 |
| | | BigDecimal jianElectronic = new BigDecimal("0"); |
| | | BigDecimal fengElectronic = new BigDecimal("0"); |
| | | BigDecimal pingElectronic = new BigDecimal("0"); |
| | | BigDecimal guElectronic = new BigDecimal("0"); |
| | | // 尖峰平谷服务费 |
| | | BigDecimal jianService = new BigDecimal("0"); |
| | | BigDecimal fengService = new BigDecimal("0"); |
| | | BigDecimal pingService = new BigDecimal("0"); |
| | | BigDecimal guService = new BigDecimal("0"); |
| | | // 尖峰平谷充电量 度数 |
| | | BigDecimal jian = new BigDecimal("0"); |
| | | BigDecimal feng = new BigDecimal("0"); |
| | | BigDecimal ping = new BigDecimal("0"); |
| | | BigDecimal gu = new BigDecimal("0"); |
| | | for (ChargingOrderListVO chargingOrderListVO : list1) { |
| | | electronic = electronic.add(chargingOrderListVO.getChargingCapacity()); |
| | | paymentAmount = paymentAmount.add(chargingOrderListVO.getPaymentAmount()); |
| | | electrovalence = electrovalence.add(chargingOrderListVO.getElectrovalence()); |
| | | serviceCharge = serviceCharge.add(chargingOrderListVO.getServiceCharge()); |
| | | List<TChargingOrderAccountingStrategy> list2 = chargingOrderAccountingStrategyService.lambdaQuery() |
| | | .eq(TChargingOrderAccountingStrategy::getChargingOrderId, chargingOrderListVO.getId()).list(); |
| | | for (TChargingOrderAccountingStrategy temp : list2) { |
| | | switch (temp.getType()){ |
| | | case 1: |
| | | jian = jian.add(temp.getChargingCapacity()); |
| | | jianElectronic = jianElectronic.add(temp.getChargingCapacity()); |
| | | jianService = jianService.add(temp.getChargingCapacity()); |
| | | break; |
| | | case 2: |
| | | feng = feng.add(temp.getChargingCapacity()); |
| | | fengElectronic = fengElectronic.add(temp.getChargingCapacity()); |
| | | fengService = fengService.add(temp.getChargingCapacity()); |
| | | break; |
| | | case 3: |
| | | ping = ping.add(temp.getChargingCapacity()); |
| | | pingElectronic = pingElectronic.add(temp.getChargingCapacity()); |
| | | pingService = pingService.add(temp.getChargingCapacity()); |
| | | break; |
| | | case 4: |
| | | gu = gu.add(temp.getChargingCapacity()); |
| | | guElectronic = guElectronic.add(temp.getChargingCapacity()); |
| | | guService = guService.add(temp.getChargingCapacity()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | chargingOrderTimeVO.setChargingCapacity(electronic); |
| | | chargingOrderTimeVO.setPaymentAmount(paymentAmount); |
| | | chargingOrderTimeVO.setElectrovalence(electrovalence); |
| | | chargingOrderTimeVO.setServiceCharge(serviceCharge); |
| | | // 计算尖峰平谷充电量占比 |
| | | BigDecimal add = jianElectronic.add(fengElectronic).add(pingElectronic).add(guElectronic); |
| | | // 计算尖峰平谷服务费占比 |
| | | BigDecimal add1 = jianService.add(fengService).add(pingService).add(guService); |
| | | // 计算尖峰平谷充电到账占比 |
| | | BigDecimal add2 = jian.add(feng).add(ping).add(gu); |
| | | chargingOrderTimeVO.setCapacityProportion(jianElectronic+"度/"+fengElectronic+"度/"+pingElectronic+"度/"+guElectronic+"度-" |
| | | +jianElectronic.divide(add,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))+"%/" |
| | | +fengElectronic.divide(add,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))+"%/" |
| | | +pingElectronic.divide(add,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))+"%/" |
| | | +guElectronic.divide(add,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))+"%"); |
| | | chargingOrderTimeVO.setServiceProportion(jianService+"元/"+fengService+"元/"+pingService+"元/"+guService+"元-" |
| | | +jianService.divide(add1,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))+"%/" |
| | | +fengService.divide(add1,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))+"%/" |
| | | +pingService.divide(add1,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))+"%/" |
| | | +guService.divide(add1,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))+"%"); |
| | | chargingOrderTimeVO.setElectronicProportion(jian+"元/"+feng+"元/"+ping+"元/"+gu+"元-" |
| | | +jian.divide(add2,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))+"%/" |
| | | +feng.divide(add2,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))+"%/" |
| | | +ping.divide(add2,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))+"%/" |
| | | +gu.divide(add2,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"))+"%"); |
| | | chargingOrderTimeVO.setList(pageInfo); |
| | | return chargingOrderTimeVO; |
| | | } |
| | | |
| | | @Override |
| | | public ChargingOrderListInfoVO chargingInfo(String uid) { |
| | | TChargingOrder chargingOrder= this.getById(uid); |
| | | |
| | | ChargingOrderListInfoVO chargingOrderListInfoVO = new ChargingOrderListInfoVO(); |
| | | chargingOrderListInfoVO.setCode(chargingOrder.getCode()); |
| | | List<Site> data = siteClient.getSiteByIds(Arrays.asList(chargingOrder.getSiteId())).getData(); |
| | | if (!data.isEmpty()){ |
| | | chargingOrderListInfoVO.setSiteName(data.get(0).getName()); |
| | | chargingOrderListInfoVO.setSiteAddress(data.get(0).getAddress()); |
| | | } |
| | | TChargingGun data1 = chargingGunClient.getChargingGunById(chargingOrder.getChargingGunId()).getData(); |
| | | TChargingPile data2 = chargingPileClient.getChargingPileById(data1.getChargingPileId()).getData(); |
| | | |
| | | if (data1!=null){ |
| | | chargingOrderListInfoVO.setGunCode(data1.getCode()); |
| | | chargingOrderListInfoVO.setTerminalName(data2.getName()+data1.getName()); |
| | | } |
| | | chargingOrderListInfoVO.setEndMode(chargingOrder.getEndMode()); |
| | | // todo 周一完善 |
| | | // 获取开始SOC 结束soc |
| | | List<UploadRealTimeMonitoringData> data6 = uploadRealTimeMonitoringDataClient.getDataByOrderCode(chargingOrder.getCode()).getData(); |
| | | if (!data6.isEmpty()){ |
| | | // 第一条数据soc为开始 最后一条数据soc为结束soc |
| | | chargingOrderListInfoVO.setStartSoc(data6.get(0).getSoc().toString()); |
| | | chargingOrderListInfoVO.setEndSoc(data6.get(data6.size()-1).getSoc().toString()); |
| | | chargingOrderListInfoVO.setChargingCapacity(data6.get(data6.size()-1).getCharging_degree()); |
| | | chargingOrderListInfoVO.setChargingSecond(data6.get(data6.size()-1).getCumulative_charging_time()*60+""); |
| | | |
| | | } |
| | | if (chargingOrder.getAppUserCarId()!=null){ |
| | | List<TAppUserCar> data3 = appUserCarClient.getCarByIds(Collections.singletonList(chargingOrder.getAppUserCarId())).getData(); |
| | | if (!data3.isEmpty())chargingOrderListInfoVO.setLicensePlate(data3.get(0).getLicensePlate()); |
| | | } |
| | | chargingOrderListInfoVO.setStartTime(chargingOrder.getStartTime()); |
| | | chargingOrderListInfoVO.setEndTime(chargingOrder.getEndTime()); |
| | | chargingOrderListInfoVO.setId(chargingOrder.getId()); |
| | | chargingOrderListInfoVO.setUid(chargingOrder.getId().toString()); |
| | | chargingOrderListInfoVO.setList(data6); |
| | | chargingOrderListInfoVO.setCouponDiscountAmount(chargingOrder.getCouponDiscountAmount()); |
| | | chargingOrderListInfoVO.setVipDiscountAmount(chargingOrder.getVipDiscountAmount()); |
| | | chargingOrderListInfoVO.setSharingAmount(chargingOrder.getSharingAmount()); |
| | | chargingOrderListInfoVO.setCommissionAmount(chargingOrder.getCommissionAmount()); |
| | | // 查询费用明细列表 |
| | | List<TChargingOrderAccountingStrategy> list = chargingOrderAccountingStrategyService.lambdaQuery() |
| | | .eq(TChargingOrderAccountingStrategy::getChargingOrderId, chargingOrder.getId()) |
| | | .list(); |
| | | chargingOrderListInfoVO.setList1(list); |
| | | return chargingOrderListInfoVO; |
| | | } |
| | | |
| | | /** |
| | | * 处理充电订单实时监控数据相关的业务逻辑 |
| | | * @param query |
| | | */ |
| | | @Override |
| | | public void chargeMonitoring(UploadRealTimeMonitoringDataQuery query) { |
| | | // todo 需完善 |
| | | } |
| | | } |