fix: 上传风险规则后同步更新站点快照,解决状态仍显示未发布的问题
1. 后端 RiskRuleServiceImpl:将 updateSnapshotsByType 从异步事件改为同步调用 snapshotService.updateSnapshot 2. 前端 RiskRules.vue:上传按钮成功后调用 fetchSnapshotStatus 刷新状态标签
This commit is contained in:
@@ -3,13 +3,12 @@ package com.par.core.service.impl;
|
|||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.par.core.entity.RiskRule;
|
import com.par.core.entity.RiskRule;
|
||||||
import com.par.core.event.SnapshotUpdateEvent;
|
|
||||||
import com.par.core.mapper.RiskRuleMapper;
|
import com.par.core.mapper.RiskRuleMapper;
|
||||||
import com.par.core.service.ManifestVersionService;
|
import com.par.core.service.ManifestVersionService;
|
||||||
import com.par.core.service.RiskRuleService;
|
import com.par.core.service.RiskRuleService;
|
||||||
|
import com.par.core.service.SiteSnapshotService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -23,7 +22,7 @@ public class RiskRuleServiceImpl implements RiskRuleService {
|
|||||||
private final RiskRuleMapper mapper;
|
private final RiskRuleMapper mapper;
|
||||||
private final com.par.core.storage.CachedStorageService storageService;
|
private final com.par.core.storage.CachedStorageService storageService;
|
||||||
private final com.par.core.service.SiteService siteService;
|
private final com.par.core.service.SiteService siteService;
|
||||||
private final ApplicationEventPublisher eventPublisher;
|
private final SiteSnapshotService snapshotService;
|
||||||
private static final ObjectMapper om = new ObjectMapper();
|
private static final ObjectMapper om = new ObjectMapper();
|
||||||
|
|
||||||
private RiskRule findByIdentifier(String identifier) {
|
private RiskRule findByIdentifier(String identifier) {
|
||||||
@@ -116,17 +115,21 @@ public class RiskRuleServiceImpl implements RiskRuleService {
|
|||||||
updateSnapshotsByType(siteType);
|
updateSnapshotsByType(siteType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 触发同类型下所有站点的快照更新 */
|
/** 同步更新同类型下所有站点的快照 */
|
||||||
private void updateSnapshotsByType(String siteType) {
|
private void updateSnapshotsByType(String siteType) {
|
||||||
try {
|
try {
|
||||||
var sites = siteService.listAllSites().stream()
|
var sites = siteService.listAllSites().stream()
|
||||||
.filter(s -> s.getSiteType() != null && siteType.equals(s.getSiteType().getValue()))
|
.filter(s -> s.getSiteType() != null && siteType.equals(s.getSiteType().getValue()))
|
||||||
.toList();
|
.toList();
|
||||||
for (var site : sites) {
|
for (var site : sites) {
|
||||||
eventPublisher.publishEvent(new SnapshotUpdateEvent(site.getSiteId()));
|
try {
|
||||||
|
snapshotService.updateSnapshot(site.getSiteId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("快照更新失败 siteId={}: {}", site.getSiteId(), e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("批量快照更新事件发布失败 siteType={}: {}", siteType, e.getMessage());
|
log.warn("批量快照更新失败 siteType={}: {}", siteType, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -497,6 +497,7 @@ const uploadRules = async () => {
|
|||||||
try {
|
try {
|
||||||
await api.raw.post('/risk-rules/'+editType.value+'/upload', { rules: parsed.value })
|
await api.raw.post('/risk-rules/'+editType.value+'/upload', { rules: parsed.value })
|
||||||
ElMessage.success('已上传')
|
ElMessage.success('已上传')
|
||||||
|
fetchSnapshotStatus()
|
||||||
} catch { ElMessage.error('上传失败') }
|
} catch { ElMessage.error('上传失败') }
|
||||||
finally { uploading.value = false }
|
finally { uploading.value = false }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user