From 690d1ae926d0e7834520200a9834dfab75b9b64b Mon Sep 17 00:00:00 2001 From: mediabot-pt <295750538+mediabot-pt@users.noreply.github.com> Date: Tue, 30 Jun 2026 09:07:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=AB=99=E7=82=B9=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=97=B6=E8=87=AA=E5=8A=A8=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E5=B7=B2=E6=9C=89=E7=AB=99=E7=82=B9(URL/=E5=90=8D=E7=A7=B0),?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E5=88=99=E5=85=B3=E8=81=94=E5=90=A6=E5=88=99?= =?UTF-8?q?=E6=96=B0=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/par/core/service/SiteService.java | 6 ++- .../core/service/impl/SiteServiceImpl.java | 54 +++++++++++++++++-- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/par-core/src/main/java/com/par/core/service/SiteService.java b/par-core/src/main/java/com/par/core/service/SiteService.java index 46bb654..a1f5dcc 100644 --- a/par-core/src/main/java/com/par/core/service/SiteService.java +++ b/par-core/src/main/java/com/par/core/service/SiteService.java @@ -33,9 +33,11 @@ public interface SiteService { String iconUrl, String siteType, Long submitterId); /** - * 提交站点信息反馈 → 写入 site_submissions 审核表 + * 提交站点信息反馈 → 写入 site_changes 审核表。 + * 自动匹配已有站点(按名称/URL),匹配到则关联,否则新建。 + * @param suggestedSiteId 建议的 siteId,为 null 时自动从名称生成 */ - void submitSiteInfo(String siteId, String status, List names, + void submitSiteInfo(String suggestedSiteId, String status, List names, List urls, String notes, Long submitterId); /** diff --git a/par-core/src/main/java/com/par/core/service/impl/SiteServiceImpl.java b/par-core/src/main/java/com/par/core/service/impl/SiteServiceImpl.java index 32f364a..a5063b1 100644 --- a/par-core/src/main/java/com/par/core/service/impl/SiteServiceImpl.java +++ b/par-core/src/main/java/com/par/core/service/impl/SiteServiceImpl.java @@ -124,8 +124,11 @@ public class SiteServiceImpl implements SiteService { } @Override - public void submitSiteInfo(String siteId, String status, List names, + public void submitSiteInfo(String suggestedSiteId, String status, List names, List urls, String notes, Long submitterId) { + // 尝试匹配已有站点 + String resolvedSiteId = resolveSiteId(suggestedSiteId, names, urls); + Map raw = new LinkedHashMap<>(); raw.put("names", names != null ? names : List.of()); raw.put("urls", urls != null ? urls : List.of()); @@ -133,7 +136,7 @@ public class SiteServiceImpl implements SiteService { raw.put("siteStatus", status != null ? status : "正常"); SiteChange entry = new SiteChange(); - entry.setSiteId(siteId); + entry.setSiteId(resolvedSiteId); entry.setSubmitterId(submitterId); entry.setStatus("pending"); try { @@ -142,7 +145,52 @@ public class SiteServiceImpl implements SiteService { throw new RuntimeException("序列化变更数据失败", e); } changeMapper.insert(entry); - log.info("站点变更提交: siteId={} changeId={}", siteId, entry.getId()); + log.info("站点变更提交: siteId={} changeId={} matched={}", + resolvedSiteId, entry.getId(), !resolvedSiteId.equals(suggestedSiteId == null ? "" : suggestedSiteId)); + } + + /** + * 匹配已有站点:先按 URL 域名匹配 → 再按名称匹配 → 都不匹配则用建议的 siteId 或自动生成。 + */ + private String resolveSiteId(String suggested, List names, List urls) { + // 1. URL 匹配:提取域名,去重后对比 + if (urls != null) { + for (String u : urls) { + try { + String host = new java.net.URI(u).getHost(); + if (host != null) { + Site match = siteMapper.selectOne( + new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper() + .like(Site::getUrlsJson, host) + .eq(Site::getDeleted, 0)); + if (match != null) { + log.info("URL 匹配到已有站点: {} → {}", u, match.getSiteId()); + return match.getSiteId(); + } + } + } catch (Exception ignored) {} + } + } + + // 2. 名称匹配(不区分大小写) + if (names != null) { + for (String n : names) { + Site match = siteMapper.selectOne( + new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper() + .like(Site::getNamesJson, n) + .eq(Site::getDeleted, 0)); + if (match != null) { + log.info("名称匹配到已有站点: {} → {}", n, match.getSiteId()); + return match.getSiteId(); + } + } + } + + // 3. 用建议值或从名称自动生成 + if (suggested != null && !suggested.isBlank()) return suggested; + + String firstName = (names != null && !names.isEmpty()) ? names.get(0) : "unknown"; + return firstName.toLowerCase().replaceAll("[^a-z0-9.-]", ""); } @Override