Files
jsowell-charger-web/jsowell-quartz/src/main/java/com/jsowell/quartz/task/JsowellTask.java

225 lines
7.8 KiB
Java
Raw Normal View History

2023-03-04 16:29:55 +08:00
package com.jsowell.quartz.task;
2025-01-15 09:05:55 +08:00
import com.google.common.collect.Lists;
2023-07-17 16:44:04 +08:00
import com.jsowell.common.constant.CacheConstants;
2023-06-05 17:06:07 +08:00
import com.jsowell.common.constant.Constants;
2023-07-17 16:44:04 +08:00
import com.jsowell.common.core.redis.RedisCache;
2025-01-15 09:05:55 +08:00
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
2023-03-04 16:29:55 +08:00
import com.jsowell.common.util.DateUtils;
2023-03-25 16:01:54 +08:00
import com.jsowell.common.util.StringUtils;
2023-07-14 14:33:48 +08:00
import com.jsowell.pile.domain.OrderBasicInfo;
2023-07-26 19:41:13 +08:00
import com.jsowell.pile.domain.PileMerchantInfo;
2023-06-05 17:06:07 +08:00
import com.jsowell.pile.domain.PileStationInfo;
import com.jsowell.pile.domain.ykcCommond.PublishPileBillingTemplateCommand;
import com.jsowell.pile.domain.ykcCommond.StartChargingCommand;
2023-07-26 19:41:13 +08:00
import com.jsowell.pile.service.*;
2025-01-15 09:05:55 +08:00
import com.jsowell.pile.vo.base.StationInfoVO;
2023-03-25 15:47:09 +08:00
import com.jsowell.pile.vo.web.BillingTemplateVO;
2023-07-17 16:44:04 +08:00
import com.jsowell.thirdparty.amap.service.AMapService;
2025-01-15 09:05:55 +08:00
import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService;
import com.jsowell.thirdparty.platform.service.impl.GuiZhouPlatformServiceImpl;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
2023-03-25 11:10:15 +08:00
import org.apache.commons.collections4.CollectionUtils;
2023-03-04 16:29:55 +08:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
2025-01-15 09:05:55 +08:00
import org.springframework.beans.factory.annotation.Qualifier;
2023-03-04 16:29:55 +08:00
import org.springframework.stereotype.Component;
2023-03-25 16:01:54 +08:00
import java.math.BigDecimal;
2023-07-14 10:56:45 +08:00
import java.time.LocalDate;
2023-03-25 11:10:15 +08:00
import java.time.LocalDateTime;
2023-03-04 16:29:55 +08:00
import java.util.Date;
2023-03-25 11:10:15 +08:00
import java.util.List;
2023-07-17 16:44:04 +08:00
import java.util.Set;
2025-01-15 09:05:55 +08:00
import java.util.stream.Collectors;
2023-03-04 16:29:55 +08:00
@Component("jsowellTask")
public class JsowellTask {
private final Logger log = LoggerFactory.getLogger(JsowellTask.class);
@Autowired
2024-01-06 15:13:50 +08:00
private OrderBasicInfoService orderBasicInfoService;
2023-03-04 16:29:55 +08:00
2023-03-25 15:47:09 +08:00
@Autowired
2024-01-06 15:20:28 +08:00
private PileBillingTemplateService pileBillingTemplateService;
2023-03-25 15:47:09 +08:00
@Autowired
2023-03-25 16:01:54 +08:00
private YKCPushCommandService ykcPushCommandService;
2023-03-25 15:47:09 +08:00
2023-07-26 19:41:13 +08:00
@Autowired
2024-01-06 15:20:28 +08:00
private PileMerchantInfoService pileMerchantInfoService;
2023-07-26 19:41:13 +08:00
2023-06-05 17:06:07 +08:00
@Autowired
2024-01-06 15:20:28 +08:00
private PileStationInfoService pileStationInfoService;
2023-06-05 17:06:07 +08:00
2023-07-17 16:44:04 +08:00
@Autowired
private RedisCache redisCache;
@Autowired
private AMapService aMapService;
2023-08-26 18:19:23 +08:00
@Autowired
2024-01-06 15:20:28 +08:00
private SettleOrderReportService settleOrderReportService;
2023-08-26 18:19:23 +08:00
2025-01-15 09:05:55 +08:00
@Autowired
private ThirdPartyStationRelationService thirdPartyStationRelationService;
2023-03-04 16:29:55 +08:00
/**
* 关闭15分钟未支付的订单
* close15MinutesOfUnpaidOrders
*/
public void close15MinutesOfUnpaidOrders() {
// log.info("关闭15分钟未支付的订单");
orderBasicInfoService.close15MinutesOfUnpaidOrders();
}
/**
* 关闭启动失败的订单
* 订单支付成功在15分钟内未启动
*/
public void closeStartFailedOrder() {
// 查询出最近2天支付成功并且订单状态为未启动的订单
String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addDays(new Date(), -2));
String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date());
orderBasicInfoService.closeStartFailedOrder(startTime, endTime);
}
2023-03-25 11:10:15 +08:00
/**
* 查询预约充电的订单并启动
*/
public void appointmentOrderStart() {
// 查询出 已支付 设置预约充电 未启动 的订单
LocalDateTime now = LocalDateTime.now();
2024-05-21 18:11:01 +08:00
List<OrderBasicInfo> list = orderBasicInfoService.getReservedOrder(now);
2023-03-25 11:10:15 +08:00
if (CollectionUtils.isEmpty(list)) {
return;
}
2023-03-25 16:53:08 +08:00
log.info("待启动充电订单:{}", list);
2023-03-25 15:47:09 +08:00
for (OrderBasicInfo orderInfo : list) {
2023-03-29 13:45:10 +08:00
// 下发充电桩设置指令
2023-03-25 15:47:09 +08:00
String pileSn = orderInfo.getPileSn();
// 发送启动充电指令前,再次下发计费模板
BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(pileSn);
if (billingTemplateVO != null) {
2023-03-25 16:01:54 +08:00
PublishPileBillingTemplateCommand command = PublishPileBillingTemplateCommand.builder()
.billingTemplateVO(billingTemplateVO)
.pileSn(pileSn)
.build();
ykcPushCommandService.pushPublishPileBillingTemplate(command);
2023-03-25 15:47:09 +08:00
}
// 发送启动指令
2023-03-25 16:01:54 +08:00
String connectorCode = orderInfo.getConnectorCode();
String transactionCode = orderInfo.getTransactionCode();
BigDecimal payAmount = orderInfo.getPayAmount();
if (StringUtils.isEmpty(pileSn) || StringUtils.isEmpty(connectorCode)) {
log.warn("appointmentOrderStart-远程启动充电, 充电桩编号和枪口号不能为空");
return;
}
log.info("appointmentOrderStart 远程启动充电, 桩号:{}, 枪口号:{}", pileSn, connectorCode);
StartChargingCommand startChargingCommand = StartChargingCommand.builder()
.pileSn(pileSn)
.connectorCode(connectorCode)
.transactionCode(transactionCode)
.chargeAmount(payAmount)
.build();
ykcPushCommandService.pushStartChargingCommand(startChargingCommand);
2023-03-25 11:10:15 +08:00
}
}
2023-06-05 17:06:07 +08:00
/**
* 计算站点订单报表
* jsowellTask.calculateTheSiteOrdersReport()
*/
public void calculateTheSiteOrdersReport() {
// 查询出所有站点
PileStationInfo pileStationInfo = new PileStationInfo();
pileStationInfo.setDelFlag(Constants.ZERO);
2024-03-13 14:35:11 +08:00
// 查询未删除的站点列表
2023-06-05 17:06:07 +08:00
List<PileStationInfo> list = pileStationInfoService.selectPileStationInfoList(pileStationInfo);
if (CollectionUtils.isEmpty(list)) {
return;
}
2023-07-14 10:56:45 +08:00
LocalDate yesterday = LocalDate.now().plusDays(-1);
2023-06-05 17:06:07 +08:00
// 计算每个站点前一天的报表
for (PileStationInfo stationInfo : list) {
try {
2023-08-26 18:19:23 +08:00
settleOrderReportService.generateDailyOrderReports(stationInfo.getId() + "", yesterday.toString());
2023-06-05 17:06:07 +08:00
} catch (Exception e) {
log.error("计算站点订单报表 发生异常 stationId:{}", stationInfo.getId(), e);
}
}
}
2023-07-17 16:44:04 +08:00
/**
* 站点的枪口数据推送到高德
2023-07-17 16:59:10 +08:00
* jsowellTask.pushToAMap()
2023-07-17 16:44:04 +08:00
*/
public void pushToAMap() {
Set<String> stationIds = redisCache.getCacheSet(CacheConstants.PUSH_STATION_CONNECTOR);
if (CollectionUtils.isEmpty(stationIds)) {
return;
}
log.info("推送到高德的stationId:{}", stationIds);
2023-07-18 11:11:23 +08:00
for (String stationId : stationIds) {
try {
aMapService.pushChargingDeviceDynamics(stationId);
} catch (Exception e) {
log.error("推送到高德error", e);
}
}
2023-07-18 11:15:36 +08:00
// 删除缓存
redisCache.deleteObject(CacheConstants.PUSH_STATION_CONNECTOR);
2023-07-17 16:44:04 +08:00
}
2023-07-26 19:41:13 +08:00
2025-01-15 09:05:55 +08:00
/**
* 贵州省平台推送充电站实时功率
*/
public void pushStationRealTimePowerInfo(){
// 查询出要推送的站点(贵州、)
String thirdPartyType = ThirdPlatformTypeEnum.GUI_ZHOU_PLATFORM.getTypeCode();
List<StationInfoVO> stationInfoVOS = thirdPartyStationRelationService.selectStationList(thirdPartyType);
List<String> stationIdList = stationInfoVOS.stream()
.map(StationInfoVO::getStationId)
.collect(Collectors.toList());
GuiZhouPlatformServiceImpl guiZhouPlatformService = new GuiZhouPlatformServiceImpl();
guiZhouPlatformService.notificationPowerInfo(stationIdList);
}
2023-07-26 19:41:13 +08:00
/**
* 定时任务处理订单分账
* jsowellTask.processOrderSplitting()
*/
public void processOrderSplitting() {
// 查询运营商列表
List<PileMerchantInfo> pileMerchantInfos = pileMerchantInfoService.selectPileMerchantInfoList(null);
if (CollectionUtils.isEmpty(pileMerchantInfos)) {
log.info("定时任务,处理订单分账, 未查询到运营商列表,直接返回");
return;
}
// 获取日期
2023-07-31 13:51:41 +08:00
LocalDate yesterday = LocalDate.now().plusDays(-1);
2023-07-31 16:53:49 +08:00
// 设置挡板8月1号之后的订单按照实际进行分账
2023-07-31 16:56:19 +08:00
LocalDateTime now = LocalDateTime.now();
LocalDateTime dateTime = LocalDateTime.of(2023, 8, 2, 0, 0, 0);
if (now.isBefore(dateTime)) {
log.info("当前时间:{}早于:{}, 不进行分账处理", DateUtils.formatDateTime(now), DateUtils.formatDateTime(dateTime));
2023-07-31 16:53:49 +08:00
return;
}
2023-07-26 19:41:13 +08:00
// 调分账方法
pileMerchantInfos.parallelStream().forEach(merchant -> {
2024-09-09 15:58:12 +08:00
try {
orderBasicInfoService.orderSplittingOperations(merchant.getId()+"", yesterday.toString());
} catch (Exception e) {
2024-09-09 15:59:14 +08:00
log.error("处理订单分账异常, merchantId:{}", merchant.getId(), e);
2024-09-09 15:58:12 +08:00
}
2023-07-26 19:41:13 +08:00
});
}
2023-03-04 16:29:55 +08:00
}