| | |
| | | package com.ruoyi.order.util.task; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson2.util.UUIDUtils; |
| | | import com.alibaba.nacos.common.utils.UuidUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.chargingPile.api.feignClient.SiteClient; |
| | | import com.ruoyi.chargingPile.api.model.Site; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.integration.api.feignClient.UploadRealTimeMonitoringDataClient; |
| | | import com.ruoyi.integration.api.model.TransactionRecord; |
| | | import com.ruoyi.integration.api.model.UploadRealTimeMonitoringData; |
| | | import com.ruoyi.order.api.model.TChargingBill; |
| | | import com.ruoyi.order.api.model.TChargingOrder; |
| | | import com.ruoyi.order.api.model.TChargingOrderRefund; |
| | | import com.ruoyi.order.api.vo.TransactionRecordMessageVO; |
| | | import com.ruoyi.order.service.TChargingBillService; |
| | | import com.ruoyi.order.service.TChargingOrderRefundService; |
| | | import com.ruoyi.order.service.TChargingOrderService; |
| | | import com.ruoyi.order.util.mongodb.service.TransactionRecordService; |
| | | import com.ruoyi.order.util.mongodb.service.UploadRealTimeMonitoringDataService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.logging.log4j.core.util.UuidUtil; |
| | | import org.apache.poi.util.StringUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.web.context.WebServerInitializedEvent; |
| | | import org.springframework.context.ApplicationListener; |
| | |
| | | * @author zhibing.pu |
| | | * @date 2023/7/11 8:39 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class TaskUtil implements ApplicationListener<WebServerInitializedEvent> { |
| | | |
| | |
| | | @Resource |
| | | private TChargingOrderService chargingOrderService; |
| | | |
| | | @Resource |
| | | private TChargingOrderRefundService chargingOrderRefundService; |
| | | |
| | | @Resource |
| | | private UploadRealTimeMonitoringDataService uploadRealTimeMonitoringDataService; |
| | | |
| | | @Resource |
| | | private TransactionRecordService transactionRecordService; |
| | | |
| | | private Integer port = null; |
| | | |
| | | |
| | | //十分钟循环执行的定时任务 |
| | | @Scheduled(fixedRate = 1000 * 60 * 10) |
| | | public void taskTenMinutes() { |
| | | if(null != port && port == 5400){ |
| | | List<TChargingOrder> failedStartupOrder = chargingOrderService.findFailedStartupOrder(); |
| | | log.info("定时任务执行,查询到启动失败的订单数量:{}", failedStartupOrder.size()); |
| | | for (TChargingOrder order : failedStartupOrder) { |
| | | //查询是否有充电信息 |
| | | List<UploadRealTimeMonitoringData> dataByOrderCode = uploadRealTimeMonitoringDataService.getDataByOrderCode(order.getCode()); |
| | | log.info("充电实时数据:{}", JSON.toJSONString(dataByOrderCode)); |
| | | //没有充电数据,则执行退款 |
| | | if(null == dataByOrderCode || dataByOrderCode.isEmpty()){ |
| | | log.info("定时任务执行,查询到启动失败的订单,执行退款:{}", order.getCode()); |
| | | chargingOrderService.refund(order.getCode()); |
| | | int num = 0; |
| | | while (true){ |
| | | TChargingOrderRefund one = chargingOrderRefundService.getOne(new LambdaQueryWrapper<TChargingOrderRefund>().eq(TChargingOrderRefund::getChargingOrderId, order.getId())); |
| | | if(null != one && 2 == one.getRefundStatus()){ |
| | | order.setStatus(-1); |
| | | chargingOrderService.updateById(order); |
| | | break; |
| | | } |
| | | try { |
| | | Thread.sleep(5000); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | num++; |
| | | if(num > 10){ |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //处理退款中的数据 |
| | | List<TChargingOrder> stoppedOrder = chargingOrderService.findStoppedOrder(); |
| | | log.info("定时任务执行,查询到停止中的订单数量:{}", stoppedOrder.size()); |
| | | for (TChargingOrder order : stoppedOrder) { |
| | | TransactionRecord one = transactionRecordService.findOne(order.getCode()); |
| | | if(null != one){ |
| | | log.info("定时任务执行,查询到停止中的订单账单数据:{}", JSON.toJSONString(one)); |
| | | TransactionRecordMessageVO vo = new TransactionRecordMessageVO(); |
| | | BeanUtils.copyProperties(one, vo); |
| | | R r = chargingOrderService.endChargeBillingCharge(vo); |
| | | log.info("定时任务执行,停止中的订单处理结果:{}", JSON.toJSONString(r)); |
| | | } |
| | | } |
| | | //处理状态为充电中,但硬件已完成的订单 |
| | | List<TChargingOrder> chargingOrder = chargingOrderService.findChargingOrder(); |
| | | log.info("定时任务执行,查询到充电中的订单数量:{}", chargingOrder.size()); |
| | | for (TChargingOrder order : chargingOrder) { |
| | | TransactionRecord one = transactionRecordService.findOne(order.getCode()); |
| | | if(null != one && StringUtils.isNotEmpty(one.getResult())){ |
| | | log.info("定时任务执行,查询到充电中的订单账单数据:{}", JSON.toJSONString(one)); |
| | | TransactionRecordMessageVO vo = new TransactionRecordMessageVO(); |
| | | BeanUtils.copyProperties(one, vo); |
| | | R r = chargingOrderService.endChargeBillingCharge(vo); |
| | | log.info("定时任务执行,充电中的订单处理结果:{}", JSON.toJSONString(r)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | @Scheduled(cron = "0 0 0 2 * ?") |
| | | public void taskMonth() { |