Ver Fonte

优化事件、邀约响应和参与对应的已中标状态

james há 1 dia atrás
pai
commit
8e15201761

+ 2 - 2
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/constant/VppDrEventStatus.java

@@ -7,8 +7,8 @@ package com.usky.vpp.constant;
 public final class VppDrEventStatus {
 
     public static final int PENDING = 0;
-    public static final int DECLARED = 1;
-    public static final int DECLARE_COMPLETED = 2;
+    public static final int DECLARE_COMPLETED = 1;
+    public static final int AWARDED = 2;
     public static final int EXECUTING = 3;
     public static final int ENDED = 4;
     public static final int CANCELLED = 5;

+ 1 - 1
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/domain/VppDrEvent.java

@@ -60,7 +60,7 @@ public class VppDrEvent implements Serializable {
     /** 下浮系数(必填) */
     @TableField("floating_coefficient")
     private BigDecimal floatingCoefficient;
-    /** 0待参与 1申报完成 3执行中 4已结束 5已取消 6末位分拆 */
+    /** 0待参与 1申报完成 2 已中标 3执行中 4已结束 5已取消 6末位分拆 */
     @TableField("event_status")
     private Integer eventStatus;
     @TableField("raw_payload")

+ 5 - 2
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/service/VppUnDrSyncService.java

@@ -16,7 +16,10 @@ public interface VppUnDrSyncService {
     void syncOptContent(VppDrEvent event, List<Map<String, Object>> optList, boolean clearing);
 
     /**
-     * 解析 DistributeEventRequest.target.resources[],同步申报/出清量
+     * 解析 DistributeEventRequest.target.resources[],同步申报/出清量,并按站点更新邀约 response_status
+     *
+     * @param responseStatus 与 vpp_dr_event.event_status 一致,写入 vpp_dr_invitation.response_status
      */
-    void syncTargetResources(VppDrEvent event, List<Map<String, Object>> resources, boolean clearing);
+    void syncTargetResources(VppDrEvent event, List<Map<String, Object>> resources, boolean clearing,
+                             Integer responseStatus);
 }

+ 11 - 10
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/service/impl/VppDrEventIngestServiceImpl.java

@@ -36,7 +36,8 @@ public class VppDrEventIngestServiceImpl implements VppDrEventIngestService {
     private static final Logger log = LoggerFactory.getLogger(VppDrEventIngestServiceImpl.class);
 
     private static final int EVENT_STATUS_PENDING = VppDrEventStatus.PENDING;
-    private static final int EVENT_STATUS_DECLARED = VppDrEventStatus.DECLARED;
+    private static final int EVENT_STATUS_DECLARE_COMPLETED = VppDrEventStatus.DECLARE_COMPLETED;
+    private static final int EVENT_STATUS_AWARDED = VppDrEventStatus.AWARDED;
     private static final int EVENT_STATUS_EXECUTING = VppDrEventStatus.EXECUTING;
     private static final int EVENT_STATUS_ENDED = VppDrEventStatus.ENDED;
     private static final int EVENT_STATUS_CANCELLED = VppDrEventStatus.CANCELLED;
@@ -99,7 +100,7 @@ public class VppDrEventIngestServiceImpl implements VppDrEventIngestService {
             }
         }
         if (event.getEventStatus() == null || event.getEventStatus() == EVENT_STATUS_PENDING) {
-            event.setEventStatus(EVENT_STATUS_DECLARED);
+            event.setEventStatus(EVENT_STATUS_DECLARE_COMPLETED);
         }
         VppAuditHelper.fillUpdate(event);
         eventMapper.updateById(event);
@@ -134,7 +135,7 @@ public class VppDrEventIngestServiceImpl implements VppDrEventIngestService {
                 ? (List<Map<String, Object>>) body.get("list") : null;
         if (list != null && !list.isEmpty()) {
             unDrSyncService.syncOptContent(event, list, false);
-            event.setEventStatus(EVENT_STATUS_DECLARED);
+            event.setEventStatus(EVENT_STATUS_DECLARE_COMPLETED);
         }
         VppAuditHelper.fillUpdate(event);
         eventMapper.updateById(event);
@@ -147,7 +148,7 @@ public class VppDrEventIngestServiceImpl implements VppDrEventIngestService {
     public VppDrEvent acknowledgeClearingPublicity(String platformEventId, Map<String, Object> body, String source) {
         VppDrEvent event = requireEvent(platformEventId);
         event.setRawPayload(toJson(body));
-        if (event.getEventStatus() == null || event.getEventStatus() <= EVENT_STATUS_DECLARED) {
+        if (event.getEventStatus() == null || event.getEventStatus() <= EVENT_STATUS_DECLARE_COMPLETED) {
             event.setEventStatus(EVENT_STATUS_EXECUTING);
         }
         executionBootstrapService.ensureExecutions(event);
@@ -208,8 +209,8 @@ public class VppDrEventIngestServiceImpl implements VppDrEventIngestService {
                 event.setEventStatus(EVENT_STATUS_PENDING);
                 break;
             case DECLARE_FEEDBACK:
-                event.setEventStatus(EVENT_STATUS_DECLARED);
-                unDrSyncService.syncTargetResources(event, resources, false);
+                event.setEventStatus(EVENT_STATUS_DECLARE_COMPLETED);
+                unDrSyncService.syncTargetResources(event, resources, false, EVENT_STATUS_DECLARE_COMPLETED);
                 break;
             case SPLIT_NOTICE:
                 event.setEventStatus(EVENT_STATUS_SPLITTING);
@@ -217,16 +218,16 @@ public class VppDrEventIngestServiceImpl implements VppDrEventIngestService {
 //                deleteEventParticipations(event);
                 break;
             case SPLIT_RESULT:
-                event.setEventStatus(EVENT_STATUS_DECLARED);
-                unDrSyncService.syncTargetResources(event, resources, true);
+                event.setEventStatus(EVENT_STATUS_DECLARE_COMPLETED);
+                unDrSyncService.syncTargetResources(event, resources, true, EVENT_STATUS_DECLARE_COMPLETED);
                 break;
             case CLEARING_PUBLICITY:
                 BigDecimal cleared = VppUnEventParser.sumResourceLoadKw(resources, true);
                 if (cleared.compareTo(BigDecimal.ZERO) > 0) {
                     event.setClearedCapacityKw(cleared);
                 }
-                unDrSyncService.syncTargetResources(event, resources, true);
-                event.setEventStatus(EVENT_STATUS_DECLARED);
+                unDrSyncService.syncTargetResources(event, resources, true, EVENT_STATUS_AWARDED);
+                event.setEventStatus(EVENT_STATUS_AWARDED);
                 break;
             default:
                 break;

+ 2 - 2
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/service/impl/VppDrInvitationServiceImpl.java

@@ -61,7 +61,7 @@ public class VppDrInvitationServiceImpl implements VppDrInvitationService {
 
     /** 与事件状态一致:0待参与 1已申报 2申报完成 3执行中 4已结束 5已取消 */
     private static final int RESPONSE_PENDING = VppDrEventStatus.PENDING;
-    private static final int RESPONSE_DECLARED = VppDrEventStatus.DECLARED;
+    private static final int EVENT_STATUS_DECLARE_COMPLETED = VppDrEventStatus.DECLARE_COMPLETED;
     private static final int RESPONSE_CANCELLED = VppDrEventStatus.CANCELLED;
 
     private static final int SMS_NOT_SENT = 0;
@@ -298,7 +298,7 @@ public class VppDrInvitationServiceImpl implements VppDrInvitationService {
             invitation.setParticipationId(participation.getId());
             invitation.setDeclaredCapacityKw(declared);
             invitation.setReplyStatus(REPLY_ACCEPT);
-            invitation.setResponseStatus(RESPONSE_DECLARED);
+            invitation.setResponseStatus(EVENT_STATUS_DECLARE_COMPLETED);
 //            syncParticipationToUn(invitation.getDrEventId(), true, Collections.singletonList(participation));
 
         } else {

+ 9 - 9
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/service/impl/VppDrServiceImpl.java

@@ -62,7 +62,7 @@ public class VppDrServiceImpl implements VppDrService {
     private static final Logger log = LoggerFactory.getLogger(VppDrServiceImpl.class);
 
     private static final int EVENT_STATUS_PENDING = VppDrEventStatus.PENDING;
-    private static final int EVENT_STATUS_DECLARED = VppDrEventStatus.DECLARED;
+    private static final int EVENT_STATUS_DECLARE_COMPLETED = VppDrEventStatus.DECLARE_COMPLETED;
     private static final int EVENT_STATUS_EXECUTING = VppDrEventStatus.EXECUTING;
     private static final int EVENT_STATUS_ENDED = VppDrEventStatus.ENDED;
     private static final int EVENT_STATUS_CANCELLED = VppDrEventStatus.CANCELLED;
@@ -218,9 +218,9 @@ public class VppDrServiceImpl implements VppDrService {
         if (request.getEventStatus() == null) {
             throw new BusinessException("事件状态不能为空");
         }
-        if (request.getEventStatus() != EVENT_STATUS_DECLARED) {
-            throw new BusinessException("仅允许将事件从待参与改为已申报");
-        }
+//        if (request.getEventStatus() != EVENT_STATUS_DECLARED) {
+//            throw new BusinessException("仅允许将事件从待参与改为已申报");
+//        }
 
         VppDrEvent event = requireEvent(request.getId());
         Integer tenantId = SecurityUtils.getTenantId();
@@ -231,11 +231,11 @@ public class VppDrServiceImpl implements VppDrService {
             throw new BusinessException("仅待参与状态的事件可改为已申报");
         }
 
-        event.setEventStatus(EVENT_STATUS_DECLARED);
+        event.setEventStatus(EVENT_STATUS_DECLARE_COMPLETED);
         VppAuditHelper.fillUpdate(event);
         eventMapper.updateById(event);
         for (VppDrInvitation invitation : loadEventInvitations(event.getId())) {
-            invitation.setResponseStatus(EVENT_STATUS_DECLARED);
+            invitation.setResponseStatus(EVENT_STATUS_DECLARE_COMPLETED);
             if (invitation.getTenantId() == null) {
                 invitation.setTenantId(event.getTenantId() != null ? event.getTenantId() : tenantId);
             }
@@ -405,7 +405,7 @@ public class VppDrServiceImpl implements VppDrService {
 //
 //            }
 
-            event.setEventStatus(EVENT_STATUS_DECLARED);
+            event.setEventStatus(EVENT_STATUS_DECLARE_COMPLETED);
             VppAuditHelper.fillUpdate(event);
             eventMapper.updateById(event);
             syncParticipationToUn(eventId, request.getParticipate(), savedParticipations);
@@ -452,7 +452,7 @@ public class VppDrServiceImpl implements VppDrService {
             }
             if (participate) {
                 invitation.setReplyStatus(REPLY_ACCEPT);
-                invitation.setResponseStatus(EVENT_STATUS_DECLARED);
+                invitation.setResponseStatus(EVENT_STATUS_DECLARE_COMPLETED);
                 if (invitation.getParticipationId() == null && invitation.getCustomerId() != null) {
                     Long participationId = participationIdByCustomer.get(invitation.getCustomerId());
                     if (participationId != null) {
@@ -761,7 +761,7 @@ public class VppDrServiceImpl implements VppDrService {
     @Transactional(rollbackFor = Exception.class)
     public void acknowledgeClearing(Long eventId) {
         VppDrEvent event = requireEvent(eventId);
-        if (event.getEventStatus() != EVENT_STATUS_DECLARED) {
+        if (event.getEventStatus() != EVENT_STATUS_DECLARE_COMPLETED) {
             throw new BusinessException("当前状态不允许确认出清公示");
         }
         unIntegrationService.acknowledgeClearing(eventId);

+ 41 - 6
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/service/impl/VppUnDrSyncServiceImpl.java

@@ -3,10 +3,12 @@ package com.usky.vpp.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.usky.vpp.domain.VppCustomer;
 import com.usky.vpp.domain.VppDrEvent;
+import com.usky.vpp.domain.VppDrInvitation;
 import com.usky.vpp.domain.VppDrParticipation;
 import com.usky.vpp.domain.VppResourcePoint;
 import com.usky.vpp.domain.VppSite;
 import com.usky.vpp.mapper.VppCustomerMapper;
+import com.usky.vpp.mapper.VppDrInvitationMapper;
 import com.usky.vpp.mapper.VppDrParticipationMapper;
 import com.usky.vpp.mapper.VppResourcePointMapper;
 import com.usky.vpp.mapper.VppSiteMapper;
@@ -37,6 +39,8 @@ public class VppUnDrSyncServiceImpl implements VppUnDrSyncService {
     private VppResourcePointMapper resourcePointMapper;
     @Autowired
     private VppDrParticipationMapper participationMapper;
+    @Autowired
+    private VppDrInvitationMapper invitationMapper;
 
     @Override
     public void syncOptContent(VppDrEvent event, List<Map<String, Object>> optList, boolean clearing) {
@@ -44,30 +48,34 @@ public class VppUnDrSyncServiceImpl implements VppUnDrSyncService {
             return;
         }
         for (Map<String, Object> item : optList) {
-            syncOne(event, item, clearing);
+            syncOne(event, item, clearing, null);
         }
     }
 
     @Override
-    public void syncTargetResources(VppDrEvent event, List<Map<String, Object>> resources, boolean clearing) {
+    public void syncTargetResources(VppDrEvent event, List<Map<String, Object>> resources, boolean clearing,
+                                    Integer responseStatus) {
         if (event == null || resources == null || resources.isEmpty()) {
             return;
         }
         for (Map<String, Object> resource : resources) {
-            syncOne(event, resource, clearing);
+            syncOne(event, resource, clearing, responseStatus);
         }
     }
 
-    private void syncOne(VppDrEvent event, Map<String, Object> item, boolean clearing) {
+    private void syncOne(VppDrEvent event, Map<String, Object> item, boolean clearing, Integer responseStatus) {
         String account = VppUnPayloadHelper.getString(item, "account");
         if (!StringUtils.hasText(account)) {
             return;
         }
         BigDecimal load = resolveLoadKw(item);
-        if (load == null) {
-            return;
+        if (load != null) {
+            syncParticipation(event, account, load, clearing);
         }
+        updateInvitationResponseStatus(event, account, responseStatus);
+    }
 
+    private void syncParticipation(VppDrEvent event, String account, BigDecimal load, boolean clearing) {
         VppCustomer customer = customerMapper.selectOne(new LambdaQueryWrapper<VppCustomer>()
                 .eq(VppCustomer::getAccountNo, account)
                 .eq(VppCustomer::getDeleteFlag, VppAuditHelper.NOT_DELETED)
@@ -122,6 +130,33 @@ public class VppUnDrSyncServiceImpl implements VppUnDrSyncService {
         }
     }
 
+    private void updateInvitationResponseStatus(VppDrEvent event, String account, Integer responseStatus) {
+        if (event == null || event.getId() == null || responseStatus == null || !StringUtils.hasText(account)) {
+            return;
+        }
+        VppSite site = siteMapper.selectOne(new LambdaQueryWrapper<VppSite>()
+                .eq(VppSite::getAccountNo, account.trim())
+                .eq(VppSite::getDeleteFlag, VppAuditHelper.NOT_DELETED)
+                .last("LIMIT 1"));
+        if (site == null || site.getId() == null) {
+            return;
+        }
+        VppDrInvitation invitation = invitationMapper.selectOne(new LambdaQueryWrapper<VppDrInvitation>()
+                .eq(VppDrInvitation::getDrEventId, event.getId())
+                .eq(VppDrInvitation::getSiteId, site.getId())
+                .eq(VppDrInvitation::getDeleteFlag, VppAuditHelper.NOT_DELETED)
+                .last("LIMIT 1"));
+        if (invitation == null) {
+            return;
+        }
+        invitation.setResponseStatus(responseStatus);
+        if(responseStatus == 2){
+            invitation.setIsWinningBid(1);
+        }
+        VppAuditHelper.fillUpdate(invitation);
+        invitationMapper.updateById(invitation);
+    }
+
     private BigDecimal resolveLoadKw(Map<String, Object> item) {
         BigDecimal load = VppUnPayloadHelper.getDecimal(item, "load");
         if (load != null) {

+ 3 - 1
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/service/impl/VppUnIntegrationServiceImpl.java

@@ -234,7 +234,9 @@ public class VppUnIntegrationServiceImpl implements VppUnIntegrationService {
             if (load == null || load.compareTo(BigDecimal.ZERO) <= 0) {
                 continue;
             }
-            list.add(VppUnMessageBuilder.buildOptListItem(accountNo, load, "否"));
+            list.add(clearing
+                    ? VppUnMessageBuilder.buildCqListItem(accountNo, load)
+                    : VppUnMessageBuilder.buildOptListItem(accountNo, load, "否"));
         }
         return list;
     }

+ 18 - 5
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/util/VppUnMessageBuilder.java

@@ -65,17 +65,23 @@ public final class VppUnMessageBuilder {
         return req;
     }
 
+    private static final int CREATE_CQ_REQUEST_CODE = 6206;
+
     public static Map<String, Object> buildCreateCqRequest(String eventId, String optType,
                                                            List<Map<String, Object>> list,
                                                            VppUnProperties properties) {
-        Map<String, Object> req = buildBaseRequest("CreateCqRequest", properties);
-        req.put("eventID", eventId);
+        Map<String, Object> req = new LinkedHashMap<>();
         req.put("optType", optType != null ? optType : "optIn");
+        req.put("eventID", eventId);
+        req.put("code", CREATE_CQ_REQUEST_CODE);
+        req.put("requestID", UUID.randomUUID().toString());
+        req.put("root", "CreateCqRequest");
         req.put("createdDateTime", CREATED_DATE_TIME.format(LocalDateTime.now()));
         req.put("priceDownCoeff", properties.getPriceDownCoeff());
-        if (list != null) {
-            req.put("list", list);
-        }
+        req.put("description", "");
+        req.put("dnID", properties.getDnId());
+        req.put("list", list != null ? list : new ArrayList<>());
+        req.put("version", 1);
         return req;
     }
 
@@ -286,6 +292,13 @@ public final class VppUnMessageBuilder {
         return StringUtils.hasText(id) ? id : fallback;
     }
 
+    public static Map<String, Object> buildCqListItem(String account, BigDecimal loadKw) {
+        Map<String, Object> item = new LinkedHashMap<>();
+        item.put("load", loadKw != null ? loadKw.stripTrailingZeros().toPlainString() : "0");
+        item.put("account", account);
+        return item;
+    }
+
     public static Map<String, Object> buildOptListItem(String account, BigDecimal loadKw, String needZk) {
         Map<String, Object> item = new LinkedHashMap<>();
         item.put("account", account);

+ 1 - 0
service-vpp/service-vpp-biz/src/main/resources/un-samples/create-cq-request.json

@@ -6,6 +6,7 @@
   "root": "CreateCqRequest",
   "createdDateTime": "2025-11-27 13:34:00",
   "priceDownCoeff": "0.8",
+  "description": "",
   "dnID": "10010103000052",
   "list": [
     { "load": "10000", "account": "3101330499683" },