|
@@ -5,6 +5,7 @@ import com.usky.common.core.exception.BusinessException;
|
|
|
import com.usky.vpp.client.VppUnClient;
|
|
import com.usky.vpp.client.VppUnClient;
|
|
|
import com.usky.vpp.client.VppUnTokenHolder;
|
|
import com.usky.vpp.client.VppUnTokenHolder;
|
|
|
import com.usky.vpp.config.VppUnProperties;
|
|
import com.usky.vpp.config.VppUnProperties;
|
|
|
|
|
+import com.usky.vpp.config.VppUnPropertiesRegistry;
|
|
|
import com.usky.vpp.domain.VppCustomer;
|
|
import com.usky.vpp.domain.VppCustomer;
|
|
|
import com.usky.vpp.domain.VppDrEvent;
|
|
import com.usky.vpp.domain.VppDrEvent;
|
|
|
import com.usky.vpp.domain.VppDrParticipation;
|
|
import com.usky.vpp.domain.VppDrParticipation;
|
|
@@ -26,8 +27,6 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
-import javax.annotation.PostConstruct;
|
|
|
|
|
-
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -42,7 +41,7 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
private static final int PARTICIPATE_STATUS_ACCEPT = 1;
|
|
private static final int PARTICIPATE_STATUS_ACCEPT = 1;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private VppUnProperties properties;
|
|
|
|
|
|
|
+ private VppUnPropertiesRegistry propertiesRegistry;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private VppUnClient unClient;
|
|
private VppUnClient unClient;
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -60,19 +59,22 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private VppUnReportService reportService;
|
|
private VppUnReportService reportService;
|
|
|
|
|
|
|
|
- @PostConstruct
|
|
|
|
|
- public void loadRegistrationFromDb() {
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void loadPersistedRegistrationId() {
|
|
|
|
|
+ VppUnProperties properties = currentProperties();
|
|
|
if (!StringUtils.hasText(properties.getDnId()) || StringUtils.hasText(properties.getRegistrationId())) {
|
|
if (!StringUtils.hasText(properties.getDnId()) || StringUtils.hasText(properties.getRegistrationId())) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
VppRegistration registration = registrationMapper.selectOne(new LambdaQueryWrapper<VppRegistration>()
|
|
VppRegistration registration = registrationMapper.selectOne(new LambdaQueryWrapper<VppRegistration>()
|
|
|
.eq(VppRegistration::getDnId, properties.getDnId())
|
|
.eq(VppRegistration::getDnId, properties.getDnId())
|
|
|
|
|
+ .eq(VppRegistration::getTenantId, properties.getTenantId())
|
|
|
.eq(VppRegistration::getDeleteFlag, VppAuditHelper.NOT_DELETED)
|
|
.eq(VppRegistration::getDeleteFlag, VppAuditHelper.NOT_DELETED)
|
|
|
.orderByDesc(VppRegistration::getRegisteredAt)
|
|
.orderByDesc(VppRegistration::getRegisteredAt)
|
|
|
.last("LIMIT 1"));
|
|
.last("LIMIT 1"));
|
|
|
if (registration != null && StringUtils.hasText(registration.getRegistrationId())) {
|
|
if (registration != null && StringUtils.hasText(registration.getRegistrationId())) {
|
|
|
properties.setRegistrationId(registration.getRegistrationId());
|
|
properties.setRegistrationId(registration.getRegistrationId());
|
|
|
- log.info("已加载 registrationID={}", registration.getRegistrationId());
|
|
|
|
|
|
|
+ propertiesRegistry.updateRegistrationId(properties.getTenantId(), registration.getRegistrationId());
|
|
|
|
|
+ log.info("租户 {} 已从数据库加载 registrationID={}", properties.getTenantId(), registration.getRegistrationId());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -80,6 +82,7 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
public Map<String, Object> refreshToken() {
|
|
public Map<String, Object> refreshToken() {
|
|
|
ensureOutboundEnabled();
|
|
ensureOutboundEnabled();
|
|
|
tokenHolder.invalidate();
|
|
tokenHolder.invalidate();
|
|
|
|
|
+ VppUnProperties properties = currentProperties();
|
|
|
Map<String, Object> response = unClient.post("TokenRequest", VppUnMessageBuilder.buildTokenRequest(properties), false);
|
|
Map<String, Object> response = unClient.post("TokenRequest", VppUnMessageBuilder.buildTokenRequest(properties), false);
|
|
|
tokenHolder.applyTokenResponse(response);
|
|
tokenHolder.applyTokenResponse(response);
|
|
|
return response;
|
|
return response;
|
|
@@ -89,6 +92,7 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Map<String, Object> register() {
|
|
public Map<String, Object> register() {
|
|
|
ensureOutboundEnabled();
|
|
ensureOutboundEnabled();
|
|
|
|
|
+ VppUnProperties properties = currentProperties();
|
|
|
Map<String, Object> request = VppUnMessageBuilder.buildCreateRegistrationRequest(properties);
|
|
Map<String, Object> request = VppUnMessageBuilder.buildCreateRegistrationRequest(properties);
|
|
|
Map<String, Object> response = unClient.post("CreateRegistrationRequest", request, true);
|
|
Map<String, Object> response = unClient.post("CreateRegistrationRequest", request, true);
|
|
|
persistRegistration(response);
|
|
persistRegistration(response);
|
|
@@ -98,6 +102,7 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
@Override
|
|
@Override
|
|
|
public Map<String, Object> pollOnce() {
|
|
public Map<String, Object> pollOnce() {
|
|
|
ensureOutboundEnabled();
|
|
ensureOutboundEnabled();
|
|
|
|
|
+ VppUnProperties properties = currentProperties();
|
|
|
Map<String, Object> response = unClient.post("Poll", VppUnMessageBuilder.buildPollRequest(properties), true);
|
|
Map<String, Object> response = unClient.post("Poll", VppUnMessageBuilder.buildPollRequest(properties), true);
|
|
|
handlePollResponse(response);
|
|
handlePollResponse(response);
|
|
|
return response;
|
|
return response;
|
|
@@ -105,6 +110,7 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public Map<String, Object> submitParticipation(Long eventId, boolean participate) {
|
|
public Map<String, Object> submitParticipation(Long eventId, boolean participate) {
|
|
|
|
|
+ VppUnProperties properties = currentProperties();
|
|
|
if (!properties.isOutboundActive()) {
|
|
if (!properties.isOutboundActive()) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -120,6 +126,7 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public Map<String, Object> submitClearing(Long eventId) {
|
|
public Map<String, Object> submitClearing(Long eventId) {
|
|
|
|
|
+ VppUnProperties properties = currentProperties();
|
|
|
if (!properties.isOutboundActive()) {
|
|
if (!properties.isOutboundActive()) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -138,6 +145,7 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Map<String, Object> acknowledgeClearing(Long eventId) {
|
|
public Map<String, Object> acknowledgeClearing(Long eventId) {
|
|
|
|
|
+ VppUnProperties properties = currentProperties();
|
|
|
if (!properties.isOutboundActive()) {
|
|
if (!properties.isOutboundActive()) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -156,6 +164,7 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
if (response == null || response.isEmpty()) {
|
|
if (response == null || response.isEmpty()) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+ VppUnProperties properties = currentProperties();
|
|
|
String root = VppUnPayloadHelper.getString(response, "root");
|
|
String root = VppUnPayloadHelper.getString(response, "root");
|
|
|
if ("DistributeEventRequest".equals(root) || response.containsKey("events")) {
|
|
if ("DistributeEventRequest".equals(root) || response.containsKey("events")) {
|
|
|
VppDrEvent event = drEventIngestService.ingestDistributeEvent(response, "Poll-Outbound");
|
|
VppDrEvent event = drEventIngestService.ingestDistributeEvent(response, "Poll-Outbound");
|
|
@@ -166,10 +175,7 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
}
|
|
}
|
|
|
if ("ReregistrationRequest".equals(root)) {
|
|
if ("ReregistrationRequest".equals(root)) {
|
|
|
log.info("UN 要求重新注册");
|
|
log.info("UN 要求重新注册");
|
|
|
- String registrationId = VppUnPayloadHelper.getString(response, "registrationID", "registrationId");
|
|
|
|
|
- if (StringUtils.hasText(registrationId)) {
|
|
|
|
|
- properties.setRegistrationId(registrationId);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ loadPersistedRegistrationId();
|
|
|
register();
|
|
register();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -182,6 +188,10 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private VppUnProperties currentProperties() {
|
|
|
|
|
+ return propertiesRegistry.getCurrent();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void maybeAutoAckClearing(VppDrEvent event) {
|
|
private void maybeAutoAckClearing(VppDrEvent event) {
|
|
|
if (event.getEventStatus() != null && event.getEventStatus() == 1
|
|
if (event.getEventStatus() != null && event.getEventStatus() == 1
|
|
|
&& event.getClearedCapacityKw() != null
|
|
&& event.getClearedCapacityKw() != null
|
|
@@ -217,14 +227,17 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void persistRegistration(Map<String, Object> response) {
|
|
private void persistRegistration(Map<String, Object> response) {
|
|
|
|
|
+ VppUnProperties properties = currentProperties();
|
|
|
String registrationId = VppUnPayloadHelper.getString(response, "registrationID", "registrationId");
|
|
String registrationId = VppUnPayloadHelper.getString(response, "registrationID", "registrationId");
|
|
|
if (!StringUtils.hasText(registrationId)) {
|
|
if (!StringUtils.hasText(registrationId)) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
properties.setRegistrationId(registrationId);
|
|
properties.setRegistrationId(registrationId);
|
|
|
|
|
+ propertiesRegistry.updateRegistrationId(properties.getTenantId(), registrationId);
|
|
|
|
|
|
|
|
VppRegistration existing = registrationMapper.selectOne(new LambdaQueryWrapper<VppRegistration>()
|
|
VppRegistration existing = registrationMapper.selectOne(new LambdaQueryWrapper<VppRegistration>()
|
|
|
.eq(VppRegistration::getDnId, properties.getDnId())
|
|
.eq(VppRegistration::getDnId, properties.getDnId())
|
|
|
|
|
+ .eq(VppRegistration::getTenantId, properties.getTenantId())
|
|
|
.eq(VppRegistration::getDeleteFlag, VppAuditHelper.NOT_DELETED)
|
|
.eq(VppRegistration::getDeleteFlag, VppAuditHelper.NOT_DELETED)
|
|
|
.last("LIMIT 1"));
|
|
.last("LIMIT 1"));
|
|
|
if (existing == null) {
|
|
if (existing == null) {
|
|
@@ -233,6 +246,7 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
existing.setRegistrationId(registrationId);
|
|
existing.setRegistrationId(registrationId);
|
|
|
existing.setRegStatus(1);
|
|
existing.setRegStatus(1);
|
|
|
existing.setRegisteredAt(LocalDateTime.now());
|
|
existing.setRegisteredAt(LocalDateTime.now());
|
|
|
|
|
+ existing.setTenantId(properties.getTenantId());
|
|
|
VppAuditHelper.fillCreate(existing);
|
|
VppAuditHelper.fillCreate(existing);
|
|
|
registrationMapper.insert(existing);
|
|
registrationMapper.insert(existing);
|
|
|
} else {
|
|
} else {
|
|
@@ -255,8 +269,8 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void ensureOutboundEnabled() {
|
|
private void ensureOutboundEnabled() {
|
|
|
- if (!properties.isOutboundActive()) {
|
|
|
|
|
- throw new BusinessException("运管平台 outbound 未启用,请配置 vpp.un.baseUrl 与 outbound-enabled");
|
|
|
|
|
|
|
+ if (!currentProperties().isOutboundActive()) {
|
|
|
|
|
+ throw new BusinessException("运管平台 outbound 未启用,请在 vpp_tenant_config 中配置 baseUrl 与 outbound_enabled");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|