|
|
@@ -29,6 +29,8 @@ import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author skyline
|
|
|
@@ -40,10 +42,14 @@ import java.time.format.DateTimeFormatter;
|
|
|
public class EnNotifyServiceImpl implements EnNotifyService {
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(EnNotifyServiceImpl.class);
|
|
|
|
|
|
+ public static ConcurrentHashMap<String, Integer> equipmentStatusCache = new ConcurrentHashMap<>();
|
|
|
+
|
|
|
private final EnPlusService enPlusService;
|
|
|
|
|
|
private final ChargeOrderService chargeOrderService;
|
|
|
|
|
|
+ private final ChargeService chargeService;
|
|
|
+
|
|
|
private final AccountService accountService;
|
|
|
|
|
|
private final WalletDetailService walletDetailService;
|
|
|
@@ -64,11 +70,12 @@ public class EnNotifyServiceImpl implements EnNotifyService {
|
|
|
private String notifyEmail;
|
|
|
|
|
|
public EnNotifyServiceImpl(EnPlusService enPlusService, ChargeOrderService chargeOrderService,
|
|
|
- AccountService accountService, WalletDetailService walletDetailService,
|
|
|
+ ChargeService chargeService, AccountService accountService, WalletDetailService walletDetailService,
|
|
|
MonitorLogService monitorLogService, EquipmentInfoService equipmentInfoService,
|
|
|
UserRechargeRightsService userRechargeRightsService, OrderRechargeRightsService orderRechargeRightsService, KymCache kymCache, RedisDBChangeUtil redisDBChangeUtil) {
|
|
|
this.enPlusService = enPlusService;
|
|
|
this.chargeOrderService = chargeOrderService;
|
|
|
+ this.chargeService = chargeService;
|
|
|
this.accountService = accountService;
|
|
|
this.walletDetailService = walletDetailService;
|
|
|
this.monitorLogService = monitorLogService;
|
|
|
@@ -77,6 +84,7 @@ public class EnNotifyServiceImpl implements EnNotifyService {
|
|
|
this.orderRechargeRightsService = orderRechargeRightsService;
|
|
|
this.kymCache = kymCache;
|
|
|
this.redisDBChangeUtil = redisDBChangeUtil;
|
|
|
+ equipmentStatusCache.putAll(equipmentInfoService.list().stream().collect(Collectors.toMap(EquipmentInfo::getEquipmentId, EquipmentInfo::getServiceStatus)));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -92,15 +100,20 @@ public class EnNotifyServiceImpl implements EnNotifyService {
|
|
|
LOGGER.info("【EN+推送】收到充电桩设备状态变化推送:\n{} \n 解密数据:{}", json, data);
|
|
|
// 更新数据库,存入redis,发送邮件通知
|
|
|
var connectorStatusInfo = JSONObject.parseObject(data).getJSONObject("ConnectorStatusInfo").toJavaObject(EnConnectorStatusInfo.class);
|
|
|
+ var connectorId = connectorStatusInfo.getConnectorId();
|
|
|
+ var equipmentId = connectorId.substring(0, 16);
|
|
|
+
|
|
|
equipmentInfoService.lambdaUpdate()
|
|
|
- .eq(EquipmentInfo::getEquipmentId, connectorStatusInfo.getConnectorId().substring(0, 16))
|
|
|
+ .eq(EquipmentInfo::getEquipmentId, equipmentId)
|
|
|
.set(EquipmentInfo::getServiceStatus, connectorStatusInfo.getStatus())
|
|
|
.update();
|
|
|
|
|
|
// 切换到admin对应的db
|
|
|
redisDBChangeUtil.setDataBase(0);
|
|
|
|
|
|
- if (connectorStatusInfo.getStatus() == 0) {
|
|
|
+ var connectorStatus = connectorStatusInfo.getStatus();
|
|
|
+
|
|
|
+ if (connectorStatus == 0) {
|
|
|
LOGGER.info("充电桩设备离线:{}", connectorStatusInfo.getConnectorId());
|
|
|
// 如果设备离线,则存入redis
|
|
|
var monitorLog = new MonitorLog()
|
|
|
@@ -113,9 +126,6 @@ public class EnNotifyServiceImpl implements EnNotifyService {
|
|
|
|
|
|
// 离线设备放入队列,5分钟之后如果还未恢复则放入长时间离线设备集合中并发送提醒,上线后发送提醒
|
|
|
redisDBChangeUtil.redisTemplate.opsForZSet().add(RedisKeys.OFFLINE, connectorStatusInfo.getConnectorId(), System.currentTimeMillis() + 5 * 60 * 1000);
|
|
|
-
|
|
|
-// MailUtil.send(notifyEmail, "【设备离线通知】", "站点:%s,设备%s离线"
|
|
|
-// .formatted(kymCache.getStationName(monitorLog.getStationId()), kymCache.getShortId(monitorLog.getSn())), false);
|
|
|
} else {
|
|
|
// 先删除离线设备队列的记录,再删除离线超时队列中的记录
|
|
|
var isDelete = redisDBChangeUtil.redisTemplate.opsForZSet().remove(RedisKeys.OFFLINE, connectorStatusInfo.getConnectorId());
|
|
|
@@ -129,13 +139,19 @@ public class EnNotifyServiceImpl implements EnNotifyService {
|
|
|
.set(MonitorLog::getIsRecover, MonitorLog.IS_RECOVER_已恢复) // 设置为已恢复
|
|
|
.update();
|
|
|
}
|
|
|
-
|
|
|
if (exist != null && exist > 0) {
|
|
|
MailUtil.send(notifyEmail, "【设备上线通知】", "站点:%s,设备%s恢复上线"
|
|
|
.formatted(kymCache.getStationNameByConnectorId(connectorStatusInfo.getConnectorId()), kymCache.getShortId(connectorStatusInfo.getConnectorId())), false);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 设备状态变为空闲,校验是否有预约订单,有则清除预约订单数据。
|
|
|
+ if (connectorStatus == 1 && equipmentStatusCache.get(equipmentId) != 1) {
|
|
|
+ LOGGER.info("设备:{}状态转为空闲,清除设备预约数据...", connectorId);
|
|
|
+ chargeService.cancelBookingByConnector(connectorId);
|
|
|
+ }
|
|
|
+ equipmentStatusCache.put(equipmentId, connectorStatus);
|
|
|
+
|
|
|
return """
|
|
|
{
|
|
|
"Status":%d
|