|
|
@@ -2,6 +2,7 @@ package com.kym.service.enplus.impl;
|
|
|
|
|
|
import cn.hutool.extra.mail.MailUtil;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.kym.entity.admin.MonitorLog;
|
|
|
import com.kym.entity.common.RedisKeys;
|
|
|
@@ -17,6 +18,7 @@ import com.kym.service.miniapp.WalletDetailService;
|
|
|
import com.kym.service.utils.KymCache;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -49,6 +51,9 @@ public class EnNotifyServiceImpl implements EnNotifyService {
|
|
|
|
|
|
private final RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
+ @Value("${kym.notify-email}")
|
|
|
+ private String notifyEmail;
|
|
|
+
|
|
|
public EnNotifyServiceImpl(EnPlusService enPlusService, ChargeOrderService chargeOrderService, AccountService accountService, WalletDetailService walletDetailService, MonitorLogService monitorLogService, KymCache kymCache, RedisTemplate<String, String> redisTemplate) {
|
|
|
this.enPlusService = enPlusService;
|
|
|
this.chargeOrderService = chargeOrderService;
|
|
|
@@ -60,7 +65,6 @@ public class EnNotifyServiceImpl implements EnNotifyService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* EN+ 充电站设备状态变化推送
|
|
|
*
|
|
|
@@ -68,6 +72,7 @@ public class EnNotifyServiceImpl implements EnNotifyService {
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
+ @DS("db-admin")
|
|
|
public String handleNotificationStationStatus(JSONObject json) {
|
|
|
// TODO: 2023-08-30 注意!!!EN+分布式事务BUG导致无法接收到离线状态(0)的推送,待对方解决后再开发测试
|
|
|
var data = enPlusService.signValidation(json);
|
|
|
@@ -84,18 +89,21 @@ public class EnNotifyServiceImpl implements EnNotifyService {
|
|
|
.setOfflineStatus(connectorStatusInfo.getStatus());
|
|
|
monitorLogService.save(monitorLog);
|
|
|
redisTemplate.opsForValue().set(RedisKeys.OFFLINE.concat(connectorStatusInfo.getConnectorId()), "", 1, TimeUnit.DAYS);
|
|
|
- MailUtil.send("skyline@kuaiyuman.cn", "通知", "站点:%s,设备%s离线".formatted(monitorLog.getStationId(), monitorLog.getSn()), false);
|
|
|
+ MailUtil.send(notifyEmail, "【设备离线通知】", "站点:%s,设备%s离线"
|
|
|
+ .formatted(kymCache.getStationName(monitorLog.getStationId()), kymCache.getShortId(monitorLog.getSn())), false);
|
|
|
} else {
|
|
|
// 查询redis是否有记录,则是之前离线的机器上线了,有就删除并更新数据库恢复时间
|
|
|
var exist = redisTemplate.hasKey(RedisKeys.OFFLINE.concat(connectorStatusInfo.getConnectorId()));
|
|
|
if (Boolean.TRUE.equals(exist)) {
|
|
|
monitorLogService.lambdaUpdate()
|
|
|
.eq(MonitorLog::getSn, connectorStatusInfo.getConnectorId())
|
|
|
- .eq(MonitorLog::getIsRecover, 0) // 未恢复的记录
|
|
|
+ .eq(MonitorLog::getIsRecover, MonitorLog.IS_RECOVER_未恢复) // 未恢复的记录
|
|
|
.set(MonitorLog::getRecoverTime, LocalDateTime.now())
|
|
|
- .set(MonitorLog::getIsRecover, 1) // 设置为已恢复
|
|
|
+ .set(MonitorLog::getIsRecover, MonitorLog.IS_RECOVER_已恢复) // 设置为已恢复
|
|
|
.update();
|
|
|
redisTemplate.delete(RedisKeys.OFFLINE.concat(connectorStatusInfo.getConnectorId()));
|
|
|
+ MailUtil.send(notifyEmail, "【设备上线通知】", "站点:%s,设备%s恢复上线"
|
|
|
+ .formatted(kymCache.getStationNameByConnectorId(connectorStatusInfo.getConnectorId()), kymCache.getShortId(connectorStatusInfo.getConnectorId())), false);
|
|
|
}
|
|
|
}
|
|
|
|