|
|
@@ -11,21 +11,25 @@ import com.usky.vpp.domain.VppDrInvitation;
|
|
|
import com.usky.vpp.domain.VppDrParticipation;
|
|
|
import com.usky.vpp.domain.VppDrSubsidyPrediction;
|
|
|
import com.usky.vpp.domain.VppResourcePoint;
|
|
|
+import com.usky.vpp.domain.VppSite;
|
|
|
import com.usky.vpp.mapper.VppDrEventMapper;
|
|
|
import com.usky.vpp.mapper.VppDrInvitationMapper;
|
|
|
import com.usky.vpp.mapper.VppDrParticipationMapper;
|
|
|
import com.usky.vpp.mapper.VppDrSubsidyPredictionMapper;
|
|
|
import com.usky.vpp.mapper.VppResourcePointMapper;
|
|
|
+import com.usky.vpp.mapper.VppSiteMapper;
|
|
|
import com.usky.vpp.service.VppBaselineService;
|
|
|
import com.usky.vpp.service.VppDrMonitorService;
|
|
|
import com.usky.vpp.service.vo.BaselinePointVO;
|
|
|
import com.usky.vpp.service.vo.DrMonitorCurveVO;
|
|
|
import com.usky.vpp.service.vo.DrMonitorRecordVO;
|
|
|
+import com.usky.vpp.service.vo.DrMonitorSiteResourceVO;
|
|
|
import com.usky.vpp.service.vo.DrMonitorSummaryVO;
|
|
|
import com.usky.vpp.service.vo.SiteBaselineVO;
|
|
|
import com.usky.vpp.service.vo.SiteDeclaredCapacityVO;
|
|
|
import com.usky.vpp.util.VppAuditHelper;
|
|
|
import com.usky.vpp.util.VppPageHelper;
|
|
|
+import com.usky.vpp.util.VppResourceTypeHelper;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -44,6 +48,7 @@ import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
+import java.util.LinkedHashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
@@ -76,6 +81,8 @@ public class VppDrMonitorServiceImpl implements VppDrMonitorService {
|
|
|
@Autowired
|
|
|
private VppResourcePointMapper resourcePointMapper;
|
|
|
@Autowired
|
|
|
+ private VppSiteMapper siteMapper;
|
|
|
+ @Autowired
|
|
|
private VppBaselineService baselineService;
|
|
|
@Autowired
|
|
|
private VppDrSubsidyPredictionMapper subsidyPredictionMapper;
|
|
|
@@ -278,6 +285,81 @@ public class VppDrMonitorServiceImpl implements VppDrMonitorService {
|
|
|
return curve;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<DrMonitorSiteResourceVO> listEventSitePeakResources(Long eventId) {
|
|
|
+ if (eventId == null) {
|
|
|
+ throw new BusinessException("事件ID不能为空");
|
|
|
+ }
|
|
|
+ Integer tenantId = SecurityUtils.getTenantId();
|
|
|
+ VppDrEvent event = eventMapper.selectById(eventId);
|
|
|
+ if (event == null || VppAuditHelper.isDeleted(event.getDeleteFlag())) {
|
|
|
+ throw new BusinessException("需求响应事件不存在");
|
|
|
+ }
|
|
|
+ if (tenantId != null && event.getTenantId() != null && !tenantId.equals(event.getTenantId())) {
|
|
|
+ throw new BusinessException("无权操作其他租户的事件");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<VppDrInvitation> invitations = invitationMapper.selectList(new LambdaQueryWrapper<VppDrInvitation>()
|
|
|
+ .eq(VppDrInvitation::getDrEventId, eventId)
|
|
|
+ .eq(VppDrInvitation::getDeleteFlag, VppAuditHelper.NOT_DELETED)
|
|
|
+ .eq(tenantId != null, VppDrInvitation::getTenantId, tenantId));
|
|
|
+ Set<Long> siteIds = invitations.stream()
|
|
|
+ .map(VppDrInvitation::getSiteId)
|
|
|
+ .filter(id -> id != null && id > 0)
|
|
|
+ .collect(Collectors.toCollection(LinkedHashSet::new));
|
|
|
+ if (siteIds.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Long, VppSite> siteMap = siteMapper.selectList(new LambdaQueryWrapper<VppSite>()
|
|
|
+ .in(VppSite::getId, siteIds)
|
|
|
+ .eq(VppSite::getDeleteFlag, VppAuditHelper.NOT_DELETED)
|
|
|
+ .eq(tenantId != null, VppSite::getTenantId, tenantId))
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(VppSite::getId, s -> s, (a, b) -> a));
|
|
|
+
|
|
|
+ List<VppResourcePoint> peakResources = listPeakResources(new ArrayList<>(siteIds), tenantId);
|
|
|
+ Map<Long, List<VppResourcePoint>> resourcesBySite = peakResources.stream()
|
|
|
+ .filter(r -> r.getSiteId() != null)
|
|
|
+ .collect(Collectors.groupingBy(VppResourcePoint::getSiteId));
|
|
|
+
|
|
|
+ List<DrMonitorSiteResourceVO> result = new ArrayList<>();
|
|
|
+ for (Long siteId : siteIds) {
|
|
|
+ VppSite site = siteMap.get(siteId);
|
|
|
+ if (site == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ DrMonitorSiteResourceVO vo = new DrMonitorSiteResourceVO();
|
|
|
+ vo.setSiteId(site.getId());
|
|
|
+ vo.setSiteCode(site.getSiteCode());
|
|
|
+ vo.setSiteName(site.getSiteName());
|
|
|
+ List<VppResourcePoint> siteResources = resourcesBySite.getOrDefault(siteId, Collections.emptyList())
|
|
|
+ .stream()
|
|
|
+ .sorted(Comparator.comparing(VppResourcePoint::getId, Comparator.nullsLast(Long::compareTo)))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (VppResourcePoint resource : siteResources) {
|
|
|
+ vo.getResources().add(toResourceItem(resource));
|
|
|
+ }
|
|
|
+ result.add(vo);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static DrMonitorSiteResourceVO.ResourceItem toResourceItem(VppResourcePoint resource) {
|
|
|
+ DrMonitorSiteResourceVO.ResourceItem item = new DrMonitorSiteResourceVO.ResourceItem();
|
|
|
+ item.setResourceId(resource.getId());
|
|
|
+ item.setResourceCode(resource.getResourceCode());
|
|
|
+ item.setResourceName(resource.getResourceName());
|
|
|
+ item.setResourceType(resource.getResourceType());
|
|
|
+ item.setResourceTypeLabel(VppResourceTypeHelper.resourceTypeLabel(resource.getResourceType()));
|
|
|
+ item.setCapacityKw(resource.getCapacityKw());
|
|
|
+ item.setIsControl(resource.getIsControl());
|
|
|
+ item.setIsSupportPeak(resource.getIsSupportPeak());
|
|
|
+ item.setMaxUpKw(resource.getMaxUpKw());
|
|
|
+ item.setMinDownKw(resource.getMinDownKw());
|
|
|
+ return item;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 实际响应容量复用申报容量链路 {@link VppBaselineService#getSiteDeclaredCapacity},
|
|
|
* 取预估响应容量;无数据时回退邀约实际响应容量。
|