| | |
| | | package com.ruoyi.order.service.impl; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import com.ruoyi.order.api.dto.SettlementConfirmAdd; |
| | | import com.ruoyi.order.api.feignClient.AccountingStrategyDetailOrderClient; |
| | | import com.ruoyi.order.api.feignClient.AccountingStrategyOrderClient; |
| | | import com.ruoyi.order.api.feignClient.ChargingOrderAccountingStrategyClient; |
| | | import com.ruoyi.order.api.model.*; |
| | | import com.ruoyi.order.api.query.ChargingOrderQuery; |
| | | import com.ruoyi.order.api.query.SettlementListQuery; |
| | | import com.ruoyi.order.api.query.UploadRealTimeMonitoringDataQuery; |
| | | import com.ruoyi.order.api.vo.*; |
| | | import com.ruoyi.order.api.vo.SecurityDetection; |
| | | import com.ruoyi.order.api.vo.PlatformStopChargingReplyVO; |
| | | import com.ruoyi.order.dto.*; |
| | | import com.ruoyi.order.mapper.TChargingOrderMapper; |
| | | import com.ruoyi.order.mapper.TSettlementConfirmMapper; |
| | |
| | | import com.ruoyi.payment.api.model.WxPaymentRefundModel; |
| | | import com.ruoyi.payment.api.vo.*; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import com.sun.org.apache.bcel.internal.generic.NEW; |
| | | import io.seata.spring.annotation.GlobalTransactional; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | electrovalence = electrovalence.setScale(2, RoundingMode.HALF_EVEN); |
| | | discountAmount = discountAmount.setScale(2, RoundingMode.HALF_EVEN); |
| | | chargingOrder.setChargeAmount(electrovalence); |
| | | chargingOrder.setVipDiscountAmount(discountAmount); |
| | | this.updateById(chargingOrder); |
| | |
| | | //使用订单id作为逻辑卡号 |
| | | platformStartCharging.setCard_number(chargingOrder.getId().toString()); |
| | | platformStartCharging.setAccount_balance(electrovalence); |
| | | |
| | | System.err.println("-------------------远程调起开始充电请求-------------------"); |
| | | System.err.println(platformStartCharging.toString()); |
| | | |
| | | log.error(chargingOrder.getCode() + ":-------------------远程调起开始充电请求-------------------"); |
| | | log.error(platformStartCharging.toString()); |
| | | |
| | | sendMessageClient.platformStartCharging(platformStartCharging); |
| | | //异步线程检测远程启动的应答结果。如果失败,则需要全额退款 |
| | |
| | | } |
| | | |
| | | List<PlatformStartChargingReply> data = platformStartChargingReplyClient.getPlatformStartChargingReply(code).getData(); |
| | | System.err.println(code + ":-------------------开始检查调起充电结果-------------------"); |
| | | System.err.println(data.toString()); |
| | | log.error(code + ":-------------------开始检查调起充电结果-------------------"); |
| | | log.error(data.toString()); |
| | | if(data.size() != 0){ |
| | | PlatformStartChargingReply platformStartChargingReply = data.get(1); |
| | | Integer startup_result = platformStartChargingReply.getStartup_result(); |
| | |
| | | redisService.setCacheObject(key, preChargeCheck1, 24L, TimeUnit.HOURS); |
| | | return true; |
| | | }else{ |
| | | log.error(code + ":未上传开启充电结果........"); |
| | | log.error(code + ":-------------------未上传开启充电结果-------------------"); |
| | | |
| | | Integer counter = boot_failed_map.get(code); |
| | | PreChargeCheck preChargeCheck1 = redisService.getCacheObject(key); |
| | |
| | | * @param securityDetection |
| | | */ |
| | | @Override |
| | | public void securityDetection(SecurityDetection securityDetection){ |
| | | public void securityDetection(SecurityDetectionVO securityDetection){ |
| | | GetChargingGunByCode code = new GetChargingGunByCode(); |
| | | code.setCharging_pile_code(securityDetection.getCharging_pile_code()); |
| | | code.setCharging_gun_code(securityDetection.getCharging_gun_code()); |
| | |
| | | * @param message |
| | | */ |
| | | @Override |
| | | public void startChargeSuccessfully(PlatformStartChargingReplyMessage message) { |
| | | public void startChargeSuccessfully(PlatformStartChargingReplyMessageVO message) { |
| | | Integer startup_result = message.getStartup_result(); |
| | | Integer failure_cause = message.getFailure_cause(); |
| | | TChargingOrder order = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, message.getTransaction_serial_number())); |
| | |
| | | preChargeCheck1.setInsulationTesting(true); |
| | | preChargeCheck1.setSecureConnectionDetection(preChargeCheck1.getSecureConnectionDetection()); |
| | | preChargeCheck1.setStartupSuccess(1); |
| | | redisService.setCacheObject("AQJC_" + order.getChargingGunId(), preChargeCheck1, 24L, TimeUnit.HOURS); |
| | | } |
| | | if(0 == startup_result){ |
| | | //启动失败 |
| | |
| | | order.setStatus(3); |
| | | order.setStartTime(LocalDateTime.now()); |
| | | } |
| | | redisService.setCacheObject("AQJC_" + order.getChargingGunId(), preChargeCheck1, 24L, TimeUnit.HOURS); |
| | | this.updateById(order); |
| | | } |
| | | |
| | |
| | | * @param code |
| | | */ |
| | | public void refund(String code){ |
| | | log.error(code + ":-------------------充电启动失败,执行退款-------------------"); |
| | | TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, code)); |
| | | if(chargingOrder.getStatus() == 2){ |
| | | Integer rechargePaymentType = chargingOrder.getRechargePaymentType(); |
| | |
| | | public AjaxResult stopCharging(String id) { |
| | | TChargingOrder chargingOrder = this.getById(id); |
| | | Integer status = chargingOrder.getStatus(); |
| | | if(status != 3){ |
| | | return AjaxResult.error("还未开始充电"); |
| | | } |
| | | if(status == 4 || status == 5){ |
| | | return AjaxResult.error("不能重复操作"); |
| | | } |
| | | chargingOrder.setEndTime(LocalDateTime.now()); |
| | | chargingOrder.setStatus(4); |
| | | chargingOrder.setEndMode(1); |
| | | this.updateById(chargingOrder); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | String code1 = chargingOrder.getCode(); |
| | | |
| | | //异步线程处理停机 |
| | | ExecutorService cachedThreadPool = Executors.newFixedThreadPool(1); |
| | |
| | | platformStopCharging.setCharging_pile_code(chargingPile.getCode()); |
| | | platformStopCharging.setCharging_gun_code(chargingGun.getCode()); |
| | | sendMessageClient.platformStopCharging(platformStopCharging); |
| | | log.error(code1 + ":-------------------远程停止充电请求-------------------"); |
| | | log.error(platformStopCharging.toString()); |
| | | //开始查询停机应答,成功后开始计费费用 |
| | | for (int i = 0; i < 60; i++) { |
| | | GetPlatformStopChargingReply query = new GetPlatformStopChargingReply(); |
| | | query.setCharging_gun_code(chargingGun.getCode()); |
| | | query.setCharging_pile_code(chargingPile.getCode()); |
| | | query.setEnd_time(chargingOrder.getEndTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | PlatformStopChargingReply reply = platformStopChargingReplyClient.getPlatformStopChargingReply(query).getData(); |
| | | log.error(code1 + ":-------------------查询远程停止充电应答-------------------"); |
| | | log.error(reply.toString()); |
| | | if(null == reply){ |
| | | try { |
| | | Thread.sleep(1000); |
| | |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | |
| | | TChargingOrder chargingOrder1 = this.getById(id); |
| | | if(chargingOrder1.getStatus() != 3){ |
| | | break; |
| | | } |
| | | |
| | | if(0 == reply.getStop_result()){ |
| | | String failure_cause = ""; |
| | | switch (reply.getFailure_cause()){ |
| | |
| | | failure_cause = "其他"; |
| | | break; |
| | | } |
| | | log.error("停机失败:订单号:{},失败原因:{}", chargingOrder.getCode(), failure_cause); |
| | | throw new RuntimeException(failure_cause); |
| | | log.error(code1 + ":停机失败:订单号:{},失败原因:{}", chargingOrder.getCode(), failure_cause); |
| | | try { |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | // 将枪状态重置为空闲 |
| | |
| | | chargingGunClient.updateChargingGunById(chargingGun); |
| | | //计算费用,处理退款 |
| | | endCharge(chargingOrder); |
| | | log.error(code1 + ":-------------------远程停止充电请求成功-------------------"); |
| | | break; |
| | | } |
| | | }); |
| | |
| | | |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 停止充电应答结果处理 |
| | | * @param platformStopChargingReply |
| | | */ |
| | | @Override |
| | | public void terminateSuccessfulResponse(PlatformStopChargingReplyVO platformStopChargingReply){ |
| | | GetChargingGunByCode code = new GetChargingGunByCode(); |
| | | code.setCharging_gun_code(platformStopChargingReply.getCharging_gun_code()); |
| | | code.setCharging_pile_code(platformStopChargingReply.getCharging_pile_code()); |
| | | TChargingGun chargingGun = chargingGunClient.getChargingGunByCode(code).getData(); |
| | | TChargingOrder order = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getChargingGunId, chargingGun.getId()) |
| | | .orderByDesc(TChargingOrder::getEndTime).eq(TChargingOrder::getRechargePaymentStatus, 2).last(" limit 0, 1")); |
| | | if(null != order && order.getStatus() != 3){ |
| | | return; |
| | | } |
| | | String code1 = order.getCode(); |
| | | if(0 == platformStopChargingReply.getStop_result()){ |
| | | String failure_cause = ""; |
| | | switch (platformStopChargingReply.getFailure_cause()){ |
| | | case 0: |
| | | failure_cause = "无"; |
| | | break; |
| | | case 1: |
| | | failure_cause = "设备编号不匹配"; |
| | | break; |
| | | case 2: |
| | | failure_cause = "枪未处于充电状态"; |
| | | break; |
| | | case 3: |
| | | failure_cause = "其他"; |
| | | break; |
| | | } |
| | | log.error(code1 + ":停机失败:订单号:{},失败原因:{}", order.getCode(), failure_cause); |
| | | return; |
| | | } |
| | | |
| | | // 将枪状态重置为空闲 |
| | | chargingGun.setStatus(2); |
| | | chargingGunClient.updateChargingGunById(chargingGun); |
| | | //计算费用,处理退款 |
| | | endCharge(order); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 手动结束后的费用计算和退款逻辑 |
| | | */ |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> usersDay1() { |
| | | return this.baseMapper.usersDay1(); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> usersByQuery(ChargingStatisticsQueryDto statisticsQueryDto) { |
| | | return this.baseMapper.usersByQuery(statisticsQueryDto); |
| | | } |
| | |
| | | |
| | | @Resource |
| | | private TShoppingOrderService shoppingOrderService; |
| | | @Resource |
| | | private TShoppingOrderRefundService shoppingOrderRefundService; |
| | | @Override |
| | | public R payRefund(PayOrderRefundDto payOrderQueryDto) { |
| | | if (payOrderQueryDto.getType()==1){ |
| | |
| | | model.setAmount(amount); |
| | | R<String> orderR = wxPaymentClient.refundOrderR(model); |
| | | if(200 == orderR.getCode()){ |
| | | tChargingOrder.setRefundStatus(2); |
| | | tChargingOrder.setRefundAmount((tChargingOrder.getRefundAmount()==null? BigDecimal.valueOf(0) :tChargingOrder.getRefundAmount()).add(payOrderQueryDto.getRefundAmount())); |
| | | this.baseMapper.updateById(tChargingOrder); |
| | | chargingOrderRefundService.save(chargingOrderRefund); |
| | | } |
| | | } |
| | |
| | | RefundResp resp = aliPaymentClient.refund(dto).getData(); |
| | | if(null != resp){ |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-DDTHH:mm:ss+TIMEZONE"); |
| | | tChargingOrder.setRefundStatus(2); |
| | | tChargingOrder.setRefundAmount((tChargingOrder.getRefundAmount()==null? BigDecimal.valueOf(0) :tChargingOrder.getRefundAmount()).add(payOrderQueryDto.getRefundAmount())); |
| | | this.baseMapper.updateById(tChargingOrder); |
| | | chargingOrderRefundService.save(chargingOrderRefund); |
| | | |
| | | } |
| | |
| | | } |
| | | if (payOrderQueryDto.getType()==2){ |
| | | TShoppingOrder tChargingOrder = shoppingOrderService.getById(payOrderQueryDto.getOrderId()); |
| | | TChargingOrderRefund chargingOrderRefund = new TChargingOrderRefund(); |
| | | chargingOrderRefund.setChargingOrderId(tChargingOrder.getId()); |
| | | TShoppingOrderRefund chargingOrderRefund = new TShoppingOrderRefund(); |
| | | chargingOrderRefund.setShoppingOrderId(tChargingOrder.getId()); |
| | | chargingOrderRefund.setRefundAmount(payOrderQueryDto.getRefundAmount()); |
| | | chargingOrderRefund.setRefundStatus(1); |
| | | chargingOrderRefund.setPayType(tChargingOrder.getPaymentType()); |
| | |
| | | model.setAmount(amount); |
| | | R<String> orderR = wxPaymentClient.refundOrderR(model); |
| | | if(200 == orderR.getCode()){ |
| | | chargingOrderRefundService.save(chargingOrderRefund); |
| | | tChargingOrder.setRefundStatus(2); |
| | | tChargingOrder.setRefundAmount((tChargingOrder.getRefundAmount()==null? BigDecimal.valueOf(0) :tChargingOrder.getRefundAmount()).add(payOrderQueryDto.getRefundAmount())); |
| | | shoppingOrderService.updateById(tChargingOrder); |
| | | shoppingOrderRefundService.save(chargingOrderRefund); |
| | | } |
| | | } |
| | | |
| | |
| | | RefundResp resp = aliPaymentClient.refund(dto).getData(); |
| | | if(null != resp){ |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-DDTHH:mm:ss+TIMEZONE"); |
| | | chargingOrderRefundService.save(chargingOrderRefund); |
| | | |
| | | tChargingOrder.setRefundStatus(2); |
| | | tChargingOrder.setRefundAmount((tChargingOrder.getRefundAmount()==null? BigDecimal.valueOf(0) :tChargingOrder.getRefundAmount()).add(payOrderQueryDto.getRefundAmount())); |
| | | shoppingOrderService.updateById(tChargingOrder); |
| | | |
| | | shoppingOrderRefundService.save(chargingOrderRefund); |
| | | |
| | | } |
| | | } |
| | |
| | | return this.baseMapper.countAllUserData(); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> needElec1(List<Integer> siteIds, ChargingStatisticsQueryDto statisticsQueryDto) { |
| | | return this.baseMapper.needElec1(siteIds,statisticsQueryDto); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | // String format = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日HH:mm:ss")); |
| | | // String format1 = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日HH:mm:ss")); |