|
|
@@ -6,14 +6,16 @@ import com.usky.vpp.client.VppUnClient;
|
|
|
import com.usky.vpp.client.VppUnTokenHolder;
|
|
|
import com.usky.vpp.config.VppUnProperties;
|
|
|
import com.usky.vpp.config.VppUnPropertiesRegistry;
|
|
|
-import com.usky.vpp.domain.VppCustomer;
|
|
|
import com.usky.vpp.domain.VppDrEvent;
|
|
|
import com.usky.vpp.domain.VppDrParticipation;
|
|
|
import com.usky.vpp.domain.VppRegistration;
|
|
|
-import com.usky.vpp.mapper.VppCustomerMapper;
|
|
|
+import com.usky.vpp.domain.VppResourcePoint;
|
|
|
+import com.usky.vpp.domain.VppSite;
|
|
|
import com.usky.vpp.mapper.VppDrEventMapper;
|
|
|
import com.usky.vpp.mapper.VppDrParticipationMapper;
|
|
|
import com.usky.vpp.mapper.VppRegistrationMapper;
|
|
|
+import com.usky.vpp.mapper.VppResourcePointMapper;
|
|
|
+import com.usky.vpp.mapper.VppSiteMapper;
|
|
|
import com.usky.vpp.service.VppDrEventIngestService;
|
|
|
import com.usky.vpp.service.VppUnIntegrationService;
|
|
|
import com.usky.vpp.service.VppUnReportService;
|
|
|
@@ -51,7 +53,9 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
@Autowired
|
|
|
private VppDrParticipationMapper participationMapper;
|
|
|
@Autowired
|
|
|
- private VppCustomerMapper customerMapper;
|
|
|
+ private VppSiteMapper siteMapper;
|
|
|
+ @Autowired
|
|
|
+ private VppResourcePointMapper resourcePointMapper;
|
|
|
@Autowired
|
|
|
private VppRegistrationMapper registrationMapper;
|
|
|
@Autowired
|
|
|
@@ -110,17 +114,25 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> submitParticipation(Long eventId, boolean participate) {
|
|
|
+ return submitParticipation(eventId, participate, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> submitParticipation(Long eventId, boolean participate,
|
|
|
+ List<VppDrParticipation> participations) {
|
|
|
VppUnProperties properties = currentProperties();
|
|
|
if (!properties.isOutboundActive()) {
|
|
|
return null;
|
|
|
}
|
|
|
VppDrEvent event = requireEvent(eventId);
|
|
|
String optType = participate ? "optIn" : "optOut";
|
|
|
- List<Map<String, Object>> list = participate ? buildListFromParticipations(eventId, false) : null;
|
|
|
+ List<Map<String, Object>> list = participate
|
|
|
+ ? buildListFromParticipations(eventId, false, participations) : null;
|
|
|
Map<String, Object> request = VppUnMessageBuilder.buildCreateOptRequest(
|
|
|
event.getEventId(), optType, list, properties);
|
|
|
Map<String, Object> response = unClient.post("CreateOptRequest", request, true);
|
|
|
- log.info("已向 UN 提交 CreateOptRequest eventId={} optType={}", event.getEventId(), optType);
|
|
|
+ log.info("已向 UN 提交 CreateOptRequest eventId={} optType={} listSize={}",
|
|
|
+ event.getEventId(), optType, list != null ? list.size() : 0);
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
@@ -131,7 +143,7 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
return null;
|
|
|
}
|
|
|
VppDrEvent event = requireEvent(eventId);
|
|
|
- List<Map<String, Object>> list = buildListFromParticipations(eventId, true);
|
|
|
+ List<Map<String, Object>> list = buildListFromParticipations(eventId, true, null);
|
|
|
if (list.isEmpty()) {
|
|
|
throw new BusinessException("无出清数据可上报 UN");
|
|
|
}
|
|
|
@@ -206,28 +218,93 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private List<Map<String, Object>> buildListFromParticipations(Long eventId, boolean clearing) {
|
|
|
- List<VppDrParticipation> participations = participationMapper.selectList(
|
|
|
- new LambdaQueryWrapper<VppDrParticipation>()
|
|
|
- .eq(VppDrParticipation::getEventId, eventId)
|
|
|
- .eq(VppDrParticipation::getParticipateStatus, PARTICIPATE_STATUS_ACCEPT)
|
|
|
- .eq(VppDrParticipation::getDeleteFlag, VppAuditHelper.NOT_DELETED));
|
|
|
+ private List<Map<String, Object>> buildListFromParticipations(Long eventId,
|
|
|
+ boolean clearing,
|
|
|
+ List<VppDrParticipation> provided) {
|
|
|
+ List<VppDrParticipation> participations = resolveParticipations(eventId, provided);
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
for (VppDrParticipation participation : participations) {
|
|
|
- VppCustomer customer = customerMapper.selectById(participation.getCustomerId());
|
|
|
- if (customer == null || !StringUtils.hasText(customer.getAccountNo())) {
|
|
|
- log.warn("参与记录缺少电力户号 customerId={}", participation.getCustomerId());
|
|
|
+ String accountNo = resolveSiteAccountNo(participation);
|
|
|
+ if (!StringUtils.hasText(accountNo)) {
|
|
|
+ log.warn("参与记录缺少站点电力户号 participationId={} resourceId={} customerId={}",
|
|
|
+ participation.getId(), participation.getResourceId(), participation.getCustomerId());
|
|
|
continue;
|
|
|
}
|
|
|
BigDecimal load = clearing ? participation.getClearedCapacityKw() : participation.getDeclaredCapacityKw();
|
|
|
if (load == null || load.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
continue;
|
|
|
}
|
|
|
- list.add(VppUnMessageBuilder.buildOptListItem(customer.getAccountNo(), load, "否"));
|
|
|
+ list.add(VppUnMessageBuilder.buildOptListItem(accountNo, load, "否"));
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+ /** 从站点表 vpp_site.account_no 解析电力户号。 */
|
|
|
+ private String resolveSiteAccountNo(VppDrParticipation participation) {
|
|
|
+ VppSite site = resolveSite(participation);
|
|
|
+ return site != null && StringUtils.hasText(site.getAccountNo()) ? site.getAccountNo().trim() : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private VppSite resolveSite(VppDrParticipation participation) {
|
|
|
+ if (participation == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (participation.getResourceId() != null) {
|
|
|
+ VppResourcePoint resource = resourcePointMapper.selectById(participation.getResourceId());
|
|
|
+ if (resource != null && resource.getSiteId() != null) {
|
|
|
+ return selectActiveSite(resource.getSiteId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (participation.getCustomerId() != null) {
|
|
|
+ return siteMapper.selectOne(new LambdaQueryWrapper<VppSite>()
|
|
|
+ .eq(VppSite::getCustomerId, participation.getCustomerId())
|
|
|
+ .eq(VppSite::getDeleteFlag, VppAuditHelper.NOT_DELETED)
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private VppSite selectActiveSite(Long siteId) {
|
|
|
+ if (siteId == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ VppSite site = siteMapper.selectById(siteId);
|
|
|
+ if (site == null || VppAuditHelper.isDeleted(site.getDeleteFlag())) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return site;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<VppDrParticipation> resolveParticipations(Long eventId, List<VppDrParticipation> provided) {
|
|
|
+ if (provided != null && !provided.isEmpty()) {
|
|
|
+ List<VppDrParticipation> accepted = new ArrayList<>();
|
|
|
+ for (VppDrParticipation participation : provided) {
|
|
|
+ if (participation == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!eventId.equals(participation.getEventId())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (participation.getParticipateStatus() != null
|
|
|
+ && participation.getParticipateStatus() != PARTICIPATE_STATUS_ACCEPT) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (VppAuditHelper.isDeleted(participation.getDeleteFlag())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ accepted.add(participation);
|
|
|
+ }
|
|
|
+ if (!accepted.isEmpty()) {
|
|
|
+ return accepted;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return participationMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<VppDrParticipation>()
|
|
|
+ .eq(VppDrParticipation::getEventId, eventId)
|
|
|
+ .eq(VppDrParticipation::getParticipateStatus, PARTICIPATE_STATUS_ACCEPT)
|
|
|
+ .eq(VppDrParticipation::getDeleteFlag, VppAuditHelper.NOT_DELETED));
|
|
|
+ }
|
|
|
+
|
|
|
private void persistRegistration(Map<String, Object> response) {
|
|
|
VppUnProperties properties = currentProperties();
|
|
|
String registrationId = VppUnPayloadHelper.getString(response, "registrationID", "registrationId");
|