|
@@ -7,6 +7,7 @@ import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.kym.common.utils.CommUtil;
|
|
import com.kym.common.utils.CommUtil;
|
|
|
|
|
+import com.kym.common.utils.PlatformAesUtil;
|
|
|
import com.kym.common.utils.PlatformConvertUtil;
|
|
import com.kym.common.utils.PlatformConvertUtil;
|
|
|
import com.kym.entity.admin.ConnectorInfo;
|
|
import com.kym.entity.admin.ConnectorInfo;
|
|
|
import com.kym.entity.admin.EquipmentInfo;
|
|
import com.kym.entity.admin.EquipmentInfo;
|
|
@@ -62,10 +63,7 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
|
|
|
@Value("${kym.notify-email}")
|
|
@Value("${kym.notify-email}")
|
|
|
private String notifyEmail;
|
|
private String notifyEmail;
|
|
|
|
|
|
|
|
- public PlatformNotifyServiceImpl(PlatformApiService enPlusService, ChargeOrderService chargeOrderService,
|
|
|
|
|
- ChargeService chargeService, AccountService accountService, WalletDetailService walletDetailService,
|
|
|
|
|
- MonitorLogService monitorLogService, EquipmentInfoService equipmentInfoService,
|
|
|
|
|
- ConnectorInfoService connectorInfoService, StringRedisTemplate redisTemplate, UserStationService userStationService) {
|
|
|
|
|
|
|
+ public PlatformNotifyServiceImpl(PlatformApiService enPlusService, ChargeOrderService chargeOrderService, ChargeService chargeService, AccountService accountService, WalletDetailService walletDetailService, MonitorLogService monitorLogService, EquipmentInfoService equipmentInfoService, ConnectorInfoService connectorInfoService, StringRedisTemplate redisTemplate, UserStationService userStationService) {
|
|
|
this.enPlusService = enPlusService;
|
|
this.enPlusService = enPlusService;
|
|
|
this.chargeOrderService = chargeOrderService;
|
|
this.chargeOrderService = chargeOrderService;
|
|
|
this.chargeService = chargeService;
|
|
this.chargeService = chargeService;
|
|
@@ -96,7 +94,7 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
|
|
|
redisTemplate.opsForValue().set(RedisKeys.PLATFORM_TOKEN + platformName, token, ttl, TimeUnit.SECONDS);
|
|
redisTemplate.opsForValue().set(RedisKeys.PLATFORM_TOKEN + platformName, token, ttl, TimeUnit.SECONDS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return """
|
|
|
|
|
|
|
+ var params = """
|
|
|
{
|
|
{
|
|
|
"OperatorID":"%s",
|
|
"OperatorID":"%s",
|
|
|
"SuccStat":%d,
|
|
"SuccStat":%d,
|
|
@@ -105,6 +103,7 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
|
|
|
"FailReason":%d
|
|
"FailReason":%d
|
|
|
}
|
|
}
|
|
|
""".formatted(platform.getOperatorId(), 0, token, ttl, 0);
|
|
""".formatted(platform.getOperatorId(), 0, token, ttl, 0);
|
|
|
|
|
+ return PlatformAesUtil.encrypt(platform, params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -124,15 +123,9 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
|
|
|
var connectorId = PlatformConvertUtil.parse2LocalConnectorId(connectorStatusInfo.getConnectorId());
|
|
var connectorId = PlatformConvertUtil.parse2LocalConnectorId(connectorStatusInfo.getConnectorId());
|
|
|
var equipmentId = connectorId.substring(0, 16);
|
|
var equipmentId = connectorId.substring(0, 16);
|
|
|
|
|
|
|
|
- equipmentInfoService.lambdaUpdate()
|
|
|
|
|
- .eq(EquipmentInfo::getEquipmentId, equipmentId)
|
|
|
|
|
- .set(EquipmentInfo::getServiceStatus, connectorStatusInfo.getStatus())
|
|
|
|
|
- .update();
|
|
|
|
|
|
|
+ equipmentInfoService.lambdaUpdate().eq(EquipmentInfo::getEquipmentId, equipmentId).set(EquipmentInfo::getServiceStatus, connectorStatusInfo.getStatus()).update();
|
|
|
|
|
|
|
|
- connectorInfoService.lambdaUpdate()
|
|
|
|
|
- .eq(ConnectorInfo::getConnectorId, connectorId)
|
|
|
|
|
- .set(ConnectorInfo::getStatus, connectorStatusInfo.getStatus())
|
|
|
|
|
- .update();
|
|
|
|
|
|
|
+ connectorInfoService.lambdaUpdate().eq(ConnectorInfo::getConnectorId, connectorId).set(ConnectorInfo::getStatus, connectorStatusInfo.getStatus()).update();
|
|
|
|
|
|
|
|
|
|
|
|
|
var connectorStatus = connectorStatusInfo.getStatus();
|
|
var connectorStatus = connectorStatusInfo.getStatus();
|
|
@@ -140,12 +133,7 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
|
|
|
if (connectorStatus == 0) {
|
|
if (connectorStatus == 0) {
|
|
|
LOGGER.info("充电桩设备离线:{}", connectorStatusInfo.getConnectorId());
|
|
LOGGER.info("充电桩设备离线:{}", connectorStatusInfo.getConnectorId());
|
|
|
// 如果设备离线,则存入redis
|
|
// 如果设备离线,则存入redis
|
|
|
- var monitorLog = new MonitorLog()
|
|
|
|
|
- .setStationId(KymCache.INSTANCE.getStationIdByEquipmentIdOrConnectorId(connectorStatusInfo.getConnectorId()))
|
|
|
|
|
- .setSn(connectorStatusInfo.getConnectorId())
|
|
|
|
|
- .setOfflineTime(LocalDateTime.now())
|
|
|
|
|
- .setType(2)
|
|
|
|
|
- .setOfflineStatus(connectorStatusInfo.getStatus());
|
|
|
|
|
|
|
+ var monitorLog = new MonitorLog().setStationId(KymCache.INSTANCE.getStationIdByEquipmentIdOrConnectorId(connectorStatusInfo.getConnectorId())).setSn(connectorStatusInfo.getConnectorId()).setOfflineTime(LocalDateTime.now()).setType(2).setOfflineStatus(connectorStatusInfo.getStatus());
|
|
|
monitorLogService.save(monitorLog);
|
|
monitorLogService.save(monitorLog);
|
|
|
|
|
|
|
|
// 离线设备放入队列,60分钟之后如果还未恢复则放入长时间离线设备集合中并发送提醒,上线后发送提醒
|
|
// 离线设备放入队列,60分钟之后如果还未恢复则放入长时间离线设备集合中并发送提醒,上线后发送提醒
|
|
@@ -156,16 +144,12 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
|
|
|
var exist = redisTemplate.opsForSet().remove(RedisKeys.OFFLINE_EXPIRED, connectorStatusInfo.getConnectorId());
|
|
var exist = redisTemplate.opsForSet().remove(RedisKeys.OFFLINE_EXPIRED, connectorStatusInfo.getConnectorId());
|
|
|
if ((isDelete != null && isDelete > 0) || (exist != null && exist > 0)) {
|
|
if ((isDelete != null && isDelete > 0) || (exist != null && exist > 0)) {
|
|
|
// 更新设备监控表
|
|
// 更新设备监控表
|
|
|
- monitorLogService.lambdaUpdate()
|
|
|
|
|
- .eq(MonitorLog::getSn, connectorStatusInfo.getConnectorId())
|
|
|
|
|
- .eq(MonitorLog::getIsRecover, MonitorLog.IS_RECOVER_未恢复) // 未恢复的记录
|
|
|
|
|
- .set(MonitorLog::getRecoverTime, LocalDateTime.now())
|
|
|
|
|
- .set(MonitorLog::getIsRecover, MonitorLog.IS_RECOVER_已恢复) // 设置为已恢复
|
|
|
|
|
|
|
+ monitorLogService.lambdaUpdate().eq(MonitorLog::getSn, connectorStatusInfo.getConnectorId()).eq(MonitorLog::getIsRecover, MonitorLog.IS_RECOVER_未恢复) // 未恢复的记录
|
|
|
|
|
+ .set(MonitorLog::getRecoverTime, LocalDateTime.now()).set(MonitorLog::getIsRecover, MonitorLog.IS_RECOVER_已恢复) // 设置为已恢复
|
|
|
.update();
|
|
.update();
|
|
|
}
|
|
}
|
|
|
if (exist != null && exist > 0) {
|
|
if (exist != null && exist > 0) {
|
|
|
- MailUtil.send(notifyEmail, "【设备上线通知】", "站点:%s,设备%s恢复上线"
|
|
|
|
|
- .formatted(KymCache.INSTANCE.getStationNameByConnectorId(connectorStatusInfo.getConnectorId()), KymCache.INSTANCE.getShortIdByEquipmentIdOrConnectorId(connectorStatusInfo.getConnectorId())), false);
|
|
|
|
|
|
|
+ MailUtil.send(notifyEmail, "【设备上线通知】", "站点:%s,设备%s恢复上线".formatted(KymCache.INSTANCE.getStationNameByConnectorId(connectorStatusInfo.getConnectorId()), KymCache.INSTANCE.getShortIdByEquipmentIdOrConnectorId(connectorStatusInfo.getConnectorId())), false);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -176,11 +160,12 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
|
|
|
}
|
|
}
|
|
|
KymCache.INSTANCE.putConnectorId2Status(Map.of(connectorId, connectorStatus));
|
|
KymCache.INSTANCE.putConnectorId2Status(Map.of(connectorId, connectorStatus));
|
|
|
|
|
|
|
|
- return """
|
|
|
|
|
|
|
+ var params = """
|
|
|
{
|
|
{
|
|
|
"Status":%d
|
|
"Status":%d
|
|
|
}
|
|
}
|
|
|
""".formatted(0);
|
|
""".formatted(0);
|
|
|
|
|
+ return PlatformAesUtil.encrypt(PlatformCache.INSTANCE.getPlatformByName(platformName), params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -211,13 +196,14 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
|
|
|
updateWrapper.set("charge_status", startChargeSeqStat);
|
|
updateWrapper.set("charge_status", startChargeSeqStat);
|
|
|
updateWrapper.set("start_time", startTime);
|
|
updateWrapper.set("start_time", startTime);
|
|
|
chargeOrderService.update(updateWrapper);
|
|
chargeOrderService.update(updateWrapper);
|
|
|
- return """
|
|
|
|
|
|
|
+ var params = """
|
|
|
{
|
|
{
|
|
|
"StartChargeSeq":"%s",
|
|
"StartChargeSeq":"%s",
|
|
|
"SuccStat":%d,
|
|
"SuccStat":%d,
|
|
|
"FailReason":%d
|
|
"FailReason":%d
|
|
|
}
|
|
}
|
|
|
""".formatted(startChargeSeq, 0, 0);
|
|
""".formatted(startChargeSeq, 0, 0);
|
|
|
|
|
+ return PlatformAesUtil.encrypt(PlatformCache.INSTANCE.getPlatformByName(platformName), params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -250,12 +236,13 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
|
|
|
redisTemplate.opsForHash().put(RedisKeys.CHARGE_ORDER_EQUIP_CHARGE_STATUS, startChargeSeq, JSONObject.toJSONString(chargeOrder));
|
|
redisTemplate.opsForHash().put(RedisKeys.CHARGE_ORDER_EQUIP_CHARGE_STATUS, startChargeSeq, JSONObject.toJSONString(chargeOrder));
|
|
|
// 将数据库写入操作放到定时任务中
|
|
// 将数据库写入操作放到定时任务中
|
|
|
// chargeOrderService.updateById(chargeOrder);
|
|
// chargeOrderService.updateById(chargeOrder);
|
|
|
- return """
|
|
|
|
|
|
|
+ var params = """
|
|
|
{
|
|
{
|
|
|
"StartChargeSeq":"%s",
|
|
"StartChargeSeq":"%s",
|
|
|
"SuccStat":%d
|
|
"SuccStat":%d
|
|
|
}
|
|
}
|
|
|
""".formatted(startChargeSeq, 0);
|
|
""".formatted(startChargeSeq, 0);
|
|
|
|
|
+ return PlatformAesUtil.encrypt(PlatformCache.INSTANCE.getPlatformByName(platformName), params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -277,13 +264,14 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
|
|
|
chargeOrder.setChargeStatus(data.getIntValue("StartChargeSeqStat"));
|
|
chargeOrder.setChargeStatus(data.getIntValue("StartChargeSeqStat"));
|
|
|
chargeOrderService.updateById(chargeOrder);
|
|
chargeOrderService.updateById(chargeOrder);
|
|
|
}
|
|
}
|
|
|
- return """
|
|
|
|
|
|
|
+ var params = """
|
|
|
{
|
|
{
|
|
|
"StartChargeSeq":"%s",
|
|
"StartChargeSeq":"%s",
|
|
|
"SuccStat":%d,
|
|
"SuccStat":%d,
|
|
|
"FailReason":%d
|
|
"FailReason":%d
|
|
|
}
|
|
}
|
|
|
""".formatted(startChargeSeq, 0, 0);
|
|
""".formatted(startChargeSeq, 0, 0);
|
|
|
|
|
+ return PlatformAesUtil.encrypt(PlatformCache.INSTANCE.getPlatformByName(platformName), params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -308,16 +296,8 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
|
|
|
// EN+平台推送重试策略是当天失败第二天再推送一次,仅此一次。EN+订单页面可以多次手动推送,所以这里要先判断订单状态,避免重复处理。
|
|
// EN+平台推送重试策略是当天失败第二天再推送一次,仅此一次。EN+订单页面可以多次手动推送,所以这里要先判断订单状态,避免重复处理。
|
|
|
if (chargeOrder.getChargeStatus() != ChargeOrder.CHARGE_STATUS_已结束 || chargeOrder.getOrderStatus() != ChargeOrder.ORDER_STATUS_成功) {
|
|
if (chargeOrder.getChargeStatus() != ChargeOrder.CHARGE_STATUS_已结束 || chargeOrder.getOrderStatus() != ChargeOrder.ORDER_STATUS_成功) {
|
|
|
// 更新订单信息
|
|
// 更新订单信息
|
|
|
- chargeOrder
|
|
|
|
|
- .setStartTime(LocalDateTime.parse(data.getString("StartTime"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
|
|
|
|
|
- .setEndTime(LocalDateTime.parse(data.getString("EndTime"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
|
|
|
|
|
- .setTotalPower(data.getDoubleValue("TotalPower"))
|
|
|
|
|
- .setElecMoney((int) Math.round(data.getDouble("TotalElecMoney") * 100))
|
|
|
|
|
- .setServiceMoney((int) Math.round(data.getDoubleValue("TotalSeviceMoney") * 100)) // 这里文档service单词错误,按文档填写
|
|
|
|
|
- .setTotalMoney((int) Math.round(data.getDoubleValue("TotalMoney") * 100))
|
|
|
|
|
- .setStopReason(data.getIntValue("StopReason"))
|
|
|
|
|
- .setSumPeriod(data.getIntValue("SumPeriod"))
|
|
|
|
|
- .setChargeDetail(data.getString("ChargeDetails"))
|
|
|
|
|
|
|
+ chargeOrder.setStartTime(LocalDateTime.parse(data.getString("StartTime"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))).setEndTime(LocalDateTime.parse(data.getString("EndTime"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))).setTotalPower(data.getDoubleValue("TotalPower")).setElecMoney((int) Math.round(data.getDouble("TotalElecMoney") * 100)).setServiceMoney((int) Math.round(data.getDoubleValue("TotalSeviceMoney") * 100)) // 这里文档service单词错误,按文档填写
|
|
|
|
|
+ .setTotalMoney((int) Math.round(data.getDoubleValue("TotalMoney") * 100)).setStopReason(data.getIntValue("StopReason")).setSumPeriod(data.getIntValue("SumPeriod")).setChargeDetail(data.getString("ChargeDetails"))
|
|
|
// 实付金额初始化为订单总金额
|
|
// 实付金额初始化为订单总金额
|
|
|
.setPayAmount(chargeOrder.getTotalMoney());
|
|
.setPayAmount(chargeOrder.getTotalMoney());
|
|
|
|
|
|
|
@@ -339,13 +319,14 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
|
|
|
userStationService.updateUserStation(chargeOrder);
|
|
userStationService.updateUserStation(chargeOrder);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return """
|
|
|
|
|
|
|
+ var params = """
|
|
|
{
|
|
{
|
|
|
"StartChargeSeq":"%s",
|
|
"StartChargeSeq":"%s",
|
|
|
"ConnectorID":"%s",
|
|
"ConnectorID":"%s",
|
|
|
"ConfirmResult":%d
|
|
"ConfirmResult":%d
|
|
|
}
|
|
}
|
|
|
""".formatted(startChargeSeq, chargeOrder.getConnectorId(), 0);
|
|
""".formatted(startChargeSeq, chargeOrder.getConnectorId(), 0);
|
|
|
|
|
+ return PlatformAesUtil.encrypt(PlatformCache.INSTANCE.getPlatformByName(platformName), params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|