Просмотр исходного кода

互联互通对接调试:通知响应接口数据加密

skyline 1 год назад
Родитель
Сommit
347131c289

+ 22 - 41
service/src/main/java/com/kym/service/platform/impl/PlatformNotifyServiceImpl.java

@@ -7,6 +7,7 @@ import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.kym.common.utils.CommUtil;
+import com.kym.common.utils.PlatformAesUtil;
 import com.kym.common.utils.PlatformConvertUtil;
 import com.kym.entity.admin.ConnectorInfo;
 import com.kym.entity.admin.EquipmentInfo;
@@ -62,10 +63,7 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
     @Value("${kym.notify-email}")
     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.chargeOrderService = chargeOrderService;
         this.chargeService = chargeService;
@@ -96,7 +94,7 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
             redisTemplate.opsForValue().set(RedisKeys.PLATFORM_TOKEN + platformName, token, ttl, TimeUnit.SECONDS);
         }
 
-        return """
+        var params = """
                 {
                     "OperatorID":"%s",
                     "SuccStat":%d,
@@ -105,6 +103,7 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
                     "FailReason":%d
                 }
                 """.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 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();
@@ -140,12 +133,7 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
         if (connectorStatus == 0) {
             LOGGER.info("充电桩设备离线:{}", connectorStatusInfo.getConnectorId());
             // 如果设备离线,则存入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);
 
             // 离线设备放入队列,60分钟之后如果还未恢复则放入长时间离线设备集合中并发送提醒,上线后发送提醒
@@ -156,16 +144,12 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
             var exist = redisTemplate.opsForSet().remove(RedisKeys.OFFLINE_EXPIRED, connectorStatusInfo.getConnectorId());
             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();
             }
             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));
 
-        return """
+        var params = """
                 {
                     "Status":%d
                 }
                 """.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("start_time", startTime);
         chargeOrderService.update(updateWrapper);
-        return """
+        var params = """
                 {
                     "StartChargeSeq":"%s",
                     "SuccStat":%d,
                     "FailReason":%d
                 }
                 """.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));
         // 将数据库写入操作放到定时任务中
         // chargeOrderService.updateById(chargeOrder);
-        return """
+        var params = """
                 {
                     "StartChargeSeq":"%s",
                     "SuccStat":%d
                 }
                 """.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"));
             chargeOrderService.updateById(chargeOrder);
         }
-        return """
+        var params = """
                 {
                     "StartChargeSeq":"%s",
                     "SuccStat":%d,
                     "FailReason":%d
                 }
                 """.formatted(startChargeSeq, 0, 0);
+        return PlatformAesUtil.encrypt(PlatformCache.INSTANCE.getPlatformByName(platformName), params);
     }
 
     /**
@@ -308,16 +296,8 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
         // EN+平台推送重试策略是当天失败第二天再推送一次,仅此一次。EN+订单页面可以多次手动推送,所以这里要先判断订单状态,避免重复处理。
         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());
 
@@ -339,13 +319,14 @@ public class PlatformNotifyServiceImpl implements PlatformNotifyService {
             userStationService.updateUserStation(chargeOrder);
         }
 
-        return """
+        var params = """
                 {
                     "StartChargeSeq":"%s",
                     "ConnectorID":"%s",
                     "ConfirmResult":%d
                 }
                 """.formatted(startChargeSeq, chargeOrder.getConnectorId(), 0);
+        return PlatformAesUtil.encrypt(PlatformCache.INSTANCE.getPlatformByName(platformName), params);
     }