|
@@ -10,18 +10,22 @@ import com.usky.vpp.domain.VppCustomer;
|
|
|
import com.usky.vpp.domain.VppDrEvaluation;
|
|
import com.usky.vpp.domain.VppDrEvaluation;
|
|
|
import com.usky.vpp.domain.VppDrEvent;
|
|
import com.usky.vpp.domain.VppDrEvent;
|
|
|
import com.usky.vpp.domain.VppDrExecution;
|
|
import com.usky.vpp.domain.VppDrExecution;
|
|
|
|
|
+import com.usky.vpp.domain.VppDrInvitation;
|
|
|
import com.usky.vpp.domain.VppDrParticipation;
|
|
import com.usky.vpp.domain.VppDrParticipation;
|
|
|
import com.usky.vpp.domain.VppDrStrategy;
|
|
import com.usky.vpp.domain.VppDrStrategy;
|
|
|
import com.usky.vpp.domain.VppDrStrategyResource;
|
|
import com.usky.vpp.domain.VppDrStrategyResource;
|
|
|
import com.usky.vpp.domain.VppResourcePoint;
|
|
import com.usky.vpp.domain.VppResourcePoint;
|
|
|
|
|
+import com.usky.vpp.domain.VppSite;
|
|
|
import com.usky.vpp.mapper.VppCustomerMapper;
|
|
import com.usky.vpp.mapper.VppCustomerMapper;
|
|
|
import com.usky.vpp.mapper.VppDrEvaluationMapper;
|
|
import com.usky.vpp.mapper.VppDrEvaluationMapper;
|
|
|
import com.usky.vpp.mapper.VppDrEventMapper;
|
|
import com.usky.vpp.mapper.VppDrEventMapper;
|
|
|
import com.usky.vpp.mapper.VppDrExecutionMapper;
|
|
import com.usky.vpp.mapper.VppDrExecutionMapper;
|
|
|
|
|
+import com.usky.vpp.mapper.VppDrInvitationMapper;
|
|
|
import com.usky.vpp.mapper.VppDrParticipationMapper;
|
|
import com.usky.vpp.mapper.VppDrParticipationMapper;
|
|
|
import com.usky.vpp.mapper.VppDrStrategyMapper;
|
|
import com.usky.vpp.mapper.VppDrStrategyMapper;
|
|
|
import com.usky.vpp.mapper.VppDrStrategyResourceMapper;
|
|
import com.usky.vpp.mapper.VppDrStrategyResourceMapper;
|
|
|
import com.usky.vpp.mapper.VppResourcePointMapper;
|
|
import com.usky.vpp.mapper.VppResourcePointMapper;
|
|
|
|
|
+import com.usky.vpp.mapper.VppSiteMapper;
|
|
|
import com.usky.vpp.service.VppDrService;
|
|
import com.usky.vpp.service.VppDrService;
|
|
|
import com.usky.vpp.service.VppDrSubsidyPredictionService;
|
|
import com.usky.vpp.service.VppDrSubsidyPredictionService;
|
|
|
import com.usky.vpp.service.VppUnIntegrationService;
|
|
import com.usky.vpp.service.VppUnIntegrationService;
|
|
@@ -40,6 +44,7 @@ import com.usky.vpp.util.VppPageHelper;
|
|
|
import com.usky.vpp.util.VppSiteResourceHelper;
|
|
import com.usky.vpp.util.VppSiteResourceHelper;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -73,6 +78,8 @@ public class VppDrServiceImpl implements VppDrService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private VppDrParticipationMapper participationMapper;
|
|
private VppDrParticipationMapper participationMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
|
|
+ private VppDrInvitationMapper invitationMapper;
|
|
|
|
|
+ @Autowired
|
|
|
private VppCustomerMapper customerMapper;
|
|
private VppCustomerMapper customerMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private VppDrStrategyMapper strategyMapper;
|
|
private VppDrStrategyMapper strategyMapper;
|
|
@@ -85,6 +92,8 @@ public class VppDrServiceImpl implements VppDrService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private VppResourcePointMapper resourcePointMapper;
|
|
private VppResourcePointMapper resourcePointMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
|
|
+ private VppSiteMapper siteMapper;
|
|
|
|
|
+ @Autowired
|
|
|
private VppSiteResourceHelper siteResourceHelper;
|
|
private VppSiteResourceHelper siteResourceHelper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private VppUnIntegrationService unIntegrationService;
|
|
private VppUnIntegrationService unIntegrationService;
|
|
@@ -311,28 +320,32 @@ public class VppDrServiceImpl implements VppDrService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (Boolean.TRUE.equals(request.getParticipate())) {
|
|
if (Boolean.TRUE.equals(request.getParticipate())) {
|
|
|
- if (request.getDeclaredCapacityKw() == null || request.getDeclaredCapacityKw().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
- throw new BusinessException("申报出清容量必须大于0");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
if (request.getResources() == null || request.getResources().isEmpty()) {
|
|
if (request.getResources() == null || request.getResources().isEmpty()) {
|
|
|
throw new BusinessException("必须选择参与资源");
|
|
throw new BusinessException("必须选择参与资源");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Map<Long, com.usky.vpp.domain.VppSite> siteMap = siteResourceHelper.loadSiteMap(
|
|
|
|
|
- request.getResources().stream()
|
|
|
|
|
- .map(r -> resourcePointMapper.selectById(r.getResourceId()))
|
|
|
|
|
- .filter(Objects::nonNull)
|
|
|
|
|
- .collect(Collectors.toList()));
|
|
|
|
|
-
|
|
|
|
|
- BigDecimal resourceDeclaredTotal = BigDecimal.ZERO;
|
|
|
|
|
|
|
+ List<VppResourcePoint> selectedResources = request.getResources().stream()
|
|
|
|
|
+ .map(r -> r.getResourceId() == null ? null : resourcePointMapper.selectById(r.getResourceId()))
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ Map<Long, com.usky.vpp.domain.VppSite> siteMap = siteResourceHelper.loadSiteMap(selectedResources);
|
|
|
|
|
+
|
|
|
|
|
+ List<VppDrInvitation> invitations = invitationMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<VppDrInvitation>()
|
|
|
|
|
+ .eq(VppDrInvitation::getDrEventId, eventId)
|
|
|
|
|
+ .eq(VppDrInvitation::getDeleteFlag, VppAuditHelper.NOT_DELETED));
|
|
|
|
|
+ Map<Long, VppDrInvitation> invitationByCustomerId = invitations.stream()
|
|
|
|
|
+ .filter(inv -> inv.getCustomerId() != null)
|
|
|
|
|
+ .collect(Collectors.toMap(VppDrInvitation::getCustomerId, inv -> inv, (a, b) -> a));
|
|
|
|
|
+ Map<Long, VppDrInvitation> invitationBySiteId = invitations.stream()
|
|
|
|
|
+ .filter(inv -> inv.getSiteId() != null)
|
|
|
|
|
+ .collect(Collectors.toMap(VppDrInvitation::getSiteId, inv -> inv, (a, b) -> a));
|
|
|
|
|
+
|
|
|
|
|
+ Map<Long, BigDecimal> declaredByResourceId = new HashMap<>();
|
|
|
for (DrParticipateRequest.DrResourceDeclare resource : request.getResources()) {
|
|
for (DrParticipateRequest.DrResourceDeclare resource : request.getResources()) {
|
|
|
if (resource.getResourceId() == null) {
|
|
if (resource.getResourceId() == null) {
|
|
|
throw new BusinessException("资源ID不能为空");
|
|
throw new BusinessException("资源ID不能为空");
|
|
|
}
|
|
}
|
|
|
- if (resource.getDeclaredCapacityKw() == null || resource.getDeclaredCapacityKw().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
- throw new BusinessException("资源申报出清容量必须大于0");
|
|
|
|
|
- }
|
|
|
|
|
VppResourcePoint rp = resourcePointMapper.selectById(resource.getResourceId());
|
|
VppResourcePoint rp = resourcePointMapper.selectById(resource.getResourceId());
|
|
|
if (rp == null || VppAuditHelper.isDeleted(rp.getDeleteFlag())) {
|
|
if (rp == null || VppAuditHelper.isDeleted(rp.getDeleteFlag())) {
|
|
|
throw new BusinessException("资源点不存在");
|
|
throw new BusinessException("资源点不存在");
|
|
@@ -344,11 +357,16 @@ public class VppDrServiceImpl implements VppDrService {
|
|
|
if (customerId == null) {
|
|
if (customerId == null) {
|
|
|
throw new BusinessException("资源点未关联客户");
|
|
throw new BusinessException("资源点未关联客户");
|
|
|
}
|
|
}
|
|
|
- resourceDeclaredTotal = resourceDeclaredTotal.add(resource.getDeclaredCapacityKw());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (resourceDeclaredTotal.compareTo(request.getDeclaredCapacityKw()) != 0) {
|
|
|
|
|
- throw new BusinessException("各资源申报出清容量之和与总申报出清容量不一致");
|
|
|
|
|
|
|
+ VppDrInvitation invitation = resolveInvitationForResource(
|
|
|
|
|
+ customerId, rp.getSiteId(), invitationByCustomerId, invitationBySiteId);
|
|
|
|
|
+ if (invitation == null) {
|
|
|
|
|
+ throw new BusinessException("资源点未关联邀约,无法申报");
|
|
|
|
|
+ }
|
|
|
|
|
+ BigDecimal declaredCapacityKw = invitation.getDeclaredCapacityKw();
|
|
|
|
|
+ if (declaredCapacityKw == null || declaredCapacityKw.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
+ throw new BusinessException("邀约申报出清容量必须大于0");
|
|
|
|
|
+ }
|
|
|
|
|
+ declaredByResourceId.put(resource.getResourceId(), declaredCapacityKw);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for (DrParticipateRequest.DrResourceDeclare resource : request.getResources()) {
|
|
for (DrParticipateRequest.DrResourceDeclare resource : request.getResources()) {
|
|
@@ -358,7 +376,7 @@ public class VppDrServiceImpl implements VppDrService {
|
|
|
participation.setCustomerId(siteResourceHelper.resolveCustomerId(rp, siteMap));
|
|
participation.setCustomerId(siteResourceHelper.resolveCustomerId(rp, siteMap));
|
|
|
participation.setResourceId(resource.getResourceId());
|
|
participation.setResourceId(resource.getResourceId());
|
|
|
participation.setParticipateStatus(PARTICIPATE_STATUS_ACCEPT);
|
|
participation.setParticipateStatus(PARTICIPATE_STATUS_ACCEPT);
|
|
|
- participation.setDeclaredCapacityKw(resource.getDeclaredCapacityKw());
|
|
|
|
|
|
|
+ participation.setDeclaredCapacityKw(declaredByResourceId.get(resource.getResourceId()));
|
|
|
participation.setDeclaredAt(LocalDateTime.now());
|
|
participation.setDeclaredAt(LocalDateTime.now());
|
|
|
VppDrParticipationHelper.refreshCompletionRate(participation);
|
|
VppDrParticipationHelper.refreshCompletionRate(participation);
|
|
|
VppAuditHelper.fillCreate(participation);
|
|
VppAuditHelper.fillCreate(participation);
|
|
@@ -385,6 +403,21 @@ public class VppDrServiceImpl implements VppDrService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private VppDrInvitation resolveInvitationForResource(Long customerId, Long siteId,
|
|
|
|
|
+ Map<Long, VppDrInvitation> invitationByCustomerId,
|
|
|
|
|
+ Map<Long, VppDrInvitation> invitationBySiteId) {
|
|
|
|
|
+ if (customerId != null) {
|
|
|
|
|
+ VppDrInvitation invitation = invitationByCustomerId.get(customerId);
|
|
|
|
|
+ if (invitation != null) {
|
|
|
|
|
+ return invitation;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (siteId != null) {
|
|
|
|
|
+ return invitationBySiteId.get(siteId);
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void clearing(Long eventId, DrClearingRequest request) {
|
|
public void clearing(Long eventId, DrClearingRequest request) {
|
|
@@ -961,6 +994,27 @@ public class VppDrServiceImpl implements VppDrService {
|
|
|
.filter(r -> !VppAuditHelper.isDeleted(r.getDeleteFlag()))
|
|
.filter(r -> !VppAuditHelper.isDeleted(r.getDeleteFlag()))
|
|
|
.collect(Collectors.toMap(VppResourcePoint::getId, r -> r, (a, b) -> a));
|
|
.collect(Collectors.toMap(VppResourcePoint::getId, r -> r, (a, b) -> a));
|
|
|
|
|
|
|
|
|
|
+ List<VppDrInvitation> invitations = invitationMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<VppDrInvitation>()
|
|
|
|
|
+ .eq(VppDrInvitation::getDrEventId, eventId)
|
|
|
|
|
+ .eq(VppDrInvitation::getDeleteFlag, VppAuditHelper.NOT_DELETED));
|
|
|
|
|
+ Map<Long, VppDrInvitation> invitationByParticipationId = invitations.stream()
|
|
|
|
|
+ .filter(inv -> inv.getParticipationId() != null)
|
|
|
|
|
+ .collect(Collectors.toMap(VppDrInvitation::getParticipationId, inv -> inv, (a, b) -> a));
|
|
|
|
|
+ Map<Long, VppDrInvitation> invitationByCustomerId = invitations.stream()
|
|
|
|
|
+ .filter(inv -> inv.getCustomerId() != null)
|
|
|
|
|
+ .collect(Collectors.toMap(VppDrInvitation::getCustomerId, inv -> inv, (a, b) -> a));
|
|
|
|
|
+
|
|
|
|
|
+ Set<Long> siteIds = invitations.stream()
|
|
|
|
|
+ .map(VppDrInvitation::getSiteId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
+ Map<Long, String> siteNameMap = siteIds.isEmpty()
|
|
|
|
|
+ ? Collections.emptyMap()
|
|
|
|
|
+ : siteMapper.selectBatchIds(siteIds).stream()
|
|
|
|
|
+ .filter(s -> !VppAuditHelper.isDeleted(s.getDeleteFlag()))
|
|
|
|
|
+ .collect(Collectors.toMap(VppSite::getId, VppSite::getSiteName, (a, b) -> a));
|
|
|
|
|
+
|
|
|
return participations.stream().map(p -> {
|
|
return participations.stream().map(p -> {
|
|
|
DrParticipationVO item = new DrParticipationVO();
|
|
DrParticipationVO item = new DrParticipationVO();
|
|
|
item.setId(p.getId());
|
|
item.setId(p.getId());
|
|
@@ -982,10 +1036,43 @@ public class VppDrServiceImpl implements VppDrService {
|
|
|
if (resource != null) {
|
|
if (resource != null) {
|
|
|
item.setResourceName(resource.getResourceName());
|
|
item.setResourceName(resource.getResourceName());
|
|
|
}
|
|
}
|
|
|
|
|
+ fillInvitationFields(item, resolveInvitation(p, invitationByParticipationId, invitationByCustomerId));
|
|
|
|
|
+ if (item.getSiteId() != null) {
|
|
|
|
|
+ item.setSiteName(siteNameMap.get(item.getSiteId()));
|
|
|
|
|
+ }
|
|
|
return item;
|
|
return item;
|
|
|
}).collect(Collectors.toList());
|
|
}).collect(Collectors.toList());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private VppDrInvitation resolveInvitation(VppDrParticipation participation,
|
|
|
|
|
+ Map<Long, VppDrInvitation> invitationByParticipationId,
|
|
|
|
|
+ Map<Long, VppDrInvitation> invitationByCustomerId) {
|
|
|
|
|
+ VppDrInvitation invitation = invitationByParticipationId.get(participation.getId());
|
|
|
|
|
+ if (invitation != null) {
|
|
|
|
|
+ return invitation;
|
|
|
|
|
+ }
|
|
|
|
|
+ return invitationByCustomerId.get(participation.getCustomerId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 将邀约表字段完整映射到参与 VO,保留既有参与记录字段不被覆盖。
|
|
|
|
|
+ */
|
|
|
|
|
+ private void fillInvitationFields(DrParticipationVO item, VppDrInvitation invitation) {
|
|
|
|
|
+ if (invitation == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ Long participationPk = item.getId();
|
|
|
|
|
+ Long customerId = item.getCustomerId();
|
|
|
|
|
+ BigDecimal declaredCapacityKw = item.getDeclaredCapacityKw();
|
|
|
|
|
+ BeanUtils.copyProperties(invitation, item);
|
|
|
|
|
+ item.setId(participationPk);
|
|
|
|
|
+ item.setInvitationId(invitation.getId());
|
|
|
|
|
+ item.setCustomerId(customerId);
|
|
|
|
|
+ if (declaredCapacityKw != null) {
|
|
|
|
|
+ item.setDeclaredCapacityKw(declaredCapacityKw);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private DrStrategyVO toStrategyVo(VppDrStrategy strategy) {
|
|
private DrStrategyVO toStrategyVo(VppDrStrategy strategy) {
|
|
|
DrStrategyVO vo = new DrStrategyVO();
|
|
DrStrategyVO vo = new DrStrategyVO();
|
|
|
vo.setId(strategy.getId());
|
|
vo.setId(strategy.getId());
|