diff --git a/backend/src/main/java/com/banben/modules/analysis/service/impl/AnalysisServiceImpl.java b/backend/src/main/java/com/banben/modules/analysis/service/impl/AnalysisServiceImpl.java index 4962a0f..e0a11e2 100644 --- a/backend/src/main/java/com/banben/modules/analysis/service/impl/AnalysisServiceImpl.java +++ b/backend/src/main/java/com/banben/modules/analysis/service/impl/AnalysisServiceImpl.java @@ -126,14 +126,49 @@ public class AnalysisServiceImpl implements AnalysisService { @Override public List hotKeywords(int limit) { + int top = Math.max(1, limit); + // 热词 = 检索日志真实检索词 + 元数据关键词(库内真实数据),合并累计 + Map merged = new LinkedHashMap<>(); + QueryWrapper wrapper = new QueryWrapper<>(); wrapper.select("keyword AS name", "COUNT(*) AS cnt") .isNotNull("keyword") .ne("keyword", "") .groupBy("keyword") .orderByDesc("cnt") - .last("limit " + Math.max(1, limit)); - return toFacets(searchLogMapper.selectMaps(wrapper)); + .last("limit " + top * 3); + for (Map m : searchLogMapper.selectMaps(wrapper)) { + Object name = m.get("name"); + if (name == null) { + continue; + } + String word = String.valueOf(name).trim(); + if (!word.isEmpty()) { + merged.merge(word, toLong(m.get("cnt")), Long::sum); + } + } + + // 元数据关键词按分号/逗号拆分后的高频词(补充检索日志条数不足时的词云展示) + try { + for (Map m : resourceMapper.splitKeywordCounts(top * 3)) { + Object name = m.get("name"); + if (name == null) { + continue; + } + String word = String.valueOf(name).trim(); + if (!word.isEmpty()) { + merged.merge(word, toLong(m.get("cnt")), Long::sum); + } + } + } catch (Exception e) { + // 拆分统计失败时退化为仅检索日志热词 + } + + return merged.entrySet().stream() + .sorted(Map.Entry.comparingByValue().reversed()) + .limit(top) + .map(e -> new FacetItem(e.getKey(), e.getValue())) + .toList(); } @Override diff --git a/backend/src/main/java/com/banben/modules/deposit/controller/DepositController.java b/backend/src/main/java/com/banben/modules/deposit/controller/DepositController.java index 7449900..56e5a20 100644 --- a/backend/src/main/java/com/banben/modules/deposit/controller/DepositController.java +++ b/backend/src/main/java/com/banben/modules/deposit/controller/DepositController.java @@ -1,7 +1,10 @@ package com.banben.modules.deposit.controller; +import com.banben.common.BusinessException; import com.banben.common.PageResult; import com.banben.common.Result; +import com.banben.modules.auth.context.UserContext; +import com.banben.modules.auth.context.LoginUser; import com.banben.modules.deposit.dto.DepositQuery; import com.banben.modules.deposit.entity.DepositRecord; import com.banben.modules.deposit.service.DepositService; @@ -30,31 +33,43 @@ public class DepositController { return Result.success(depositService.submit(record)); } - @Operation(summary = "管理端查看呈缴列表") + @Operation(summary = "管理端查看呈缴列表(仅管理员)") @GetMapping("/page") public Result> page(DepositQuery query) { + requireAdmin(); return Result.success(depositService.pageQuery(query)); } - @Operation(summary = "管理端查看呈缴详情") + @Operation(summary = "管理端查看呈缴详情(仅管理员)") @GetMapping("/{id}") public Result detail(@PathVariable Long id) { + requireAdmin(); return Result.success(depositService.getById(id)); } - @Operation(summary = "管理端接收呈缴") + @Operation(summary = "管理端接收呈缴(仅管理员)") @PostMapping("/{id}/accept") public Result accept(@PathVariable Long id, @RequestParam(required = false) String auditRemark) { + requireAdmin(); depositService.audit(id, true, auditRemark); return Result.success(); } - @Operation(summary = "管理端退回呈缴") + @Operation(summary = "管理端退回呈缴(仅管理员)") @PostMapping("/{id}/reject") public Result reject(@PathVariable Long id, @RequestParam(required = false) String auditRemark) { + requireAdmin(); depositService.audit(id, false, auditRemark); return Result.success(); } + + /** 管理端接口统一校验:仅管理员可访问(提交呈缴不受限) */ + private void requireAdmin() { + LoginUser user = UserContext.get(); + if (user == null || !"ADMIN".equalsIgnoreCase(user.role())) { + throw new BusinessException("仅管理员可执行该操作"); + } + } } diff --git a/backend/src/main/java/com/banben/modules/resource/mapper/VersionResourceMapper.java b/backend/src/main/java/com/banben/modules/resource/mapper/VersionResourceMapper.java index e9265b5..dbc06f9 100644 --- a/backend/src/main/java/com/banben/modules/resource/mapper/VersionResourceMapper.java +++ b/backend/src/main/java/com/banben/modules/resource/mapper/VersionResourceMapper.java @@ -3,10 +3,26 @@ package com.banben.modules.resource.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.banben.modules.resource.entity.VersionResource; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; +import java.util.Map; /** * 版本资源 Mapper。 */ @Mapper public interface VersionResourceMapper extends BaseMapper { + + /** + * 元数据关键词热度:按分号/逗号/顿号/空白拆分 keywords 列后分组统计。 + * 用于检索热词词云(与检索日志热词合并展示,均为库内真实数据)。 + */ + @Select("SELECT k AS name, COUNT(*) AS cnt FROM (" + + " SELECT regexp_split_to_table(keywords, '[;;,,、\\s]+') AS k" + + " FROM version_resource" + + " WHERE deleted = 0 AND keywords IS NOT NULL AND keywords <> ''" + + ") t WHERE k <> '' GROUP BY k ORDER BY cnt DESC LIMIT #{limit}") + List> splitKeywordCounts(@Param("limit") int limit); } diff --git a/backend/src/main/java/com/banben/modules/search/dto/SearchQuery.java b/backend/src/main/java/com/banben/modules/search/dto/SearchQuery.java index 40e8834..4efd1b0 100644 --- a/backend/src/main/java/com/banben/modules/search/dto/SearchQuery.java +++ b/backend/src/main/java/com/banben/modules/search/dto/SearchQuery.java @@ -49,9 +49,15 @@ public class SearchQuery { @Schema(description = "媒体类型:纸质/电子") private String mediaType; + @Schema(description = "语种分组:chi 中文文献 / foreign 外文文献(首页前置筛选用)") + private String languageGroup; + @Schema(description = "来源馆(多选)") private List sourceLibraries; + @Schema(description = "来源馆(单选,左侧「来源院校」分面点选用)") + private String sourceLibrary; + /** ---------------- 限定出版时段 ---------------- */ @Schema(description = "出版年份起(含)", example = "2000") private String publishYearStart; diff --git a/backend/src/main/java/com/banben/modules/search/service/impl/SearchServiceImpl.java b/backend/src/main/java/com/banben/modules/search/service/impl/SearchServiceImpl.java index 348c447..1501c44 100644 --- a/backend/src/main/java/com/banben/modules/search/service/impl/SearchServiceImpl.java +++ b/backend/src/main/java/com/banben/modules/search/service/impl/SearchServiceImpl.java @@ -5,6 +5,8 @@ import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.banben.common.PageResult; +import com.banben.modules.admin.entity.SensitiveWord; +import com.banben.modules.admin.mapper.SensitiveWordMapper; import com.banben.modules.resource.entity.VersionResource; import com.banben.modules.resource.mapper.VersionResourceMapper; import com.banben.modules.search.dto.SearchQuery; @@ -45,11 +47,26 @@ public class SearchServiceImpl implements SearchService { private final VersionResourceMapper resourceMapper; private final SearchLogMapper searchLogMapper; private final ClcCategoryMapper clcCategoryMapper; + private final SensitiveWordMapper sensitiveWordMapper; @Override public SearchResultVO search(SearchQuery query, String userIp) { long start = System.currentTimeMillis(); + // 敏感词拦截:检索词命中敏感词库时直接屏蔽结果(facets 一并置空) + if (hitsSensitive(query)) { + SearchResultVO vo = new SearchResultVO(); + vo.setPage(PageResult.of(List.of(), 0, query.getCurrent(), query.getSize())); + vo.setMediaTypeFacets(List.of()); + vo.setSourceLibraryFacets(List.of()); + vo.setClcFacets(List.of()); + vo.setYearStats(List.of()); + vo.setSensitiveBlocked(true); + vo.setCostMs(System.currentTimeMillis() - start); + saveSearchLog(query, userIp, 0, vo.getCostMs().intValue()); + return vo; + } + QueryWrapper wrapper = buildWrapper(query); applyOrder(wrapper, query); @@ -58,6 +75,21 @@ public class SearchServiceImpl implements SearchService { SearchResultVO vo = new SearchResultVO(); vo.setPage(PageResult.of(page.getRecords(), page.getTotal(), page.getCurrent(), page.getSize())); + + // 命中但被屏蔽/下架而不展示的记录数(含管理状态口径的总数 - 实际可见总数)。 + // 仅在带检索条件时统计:空词全量浏览(刷新/首页进入)不提示 + if (hasCondition(query)) { + try { + long withMasked = resourceMapper.selectCount( + buildWrapper(query, false, null, true)); + if (withMasked > page.getTotal()) { + vo.setMaskedCount(withMasked - page.getTotal()); + } + } catch (Exception e) { + log.warn("统计被屏蔽命中数失败:{}", e.getMessage()); + } + } + vo.setMediaTypeFacets(facet(query, "media_type")); vo.setSourceLibraryFacets(facet(query, "source_library")); vo.setClcFacets(clcFacet(query)); @@ -123,21 +155,66 @@ public class SearchServiceImpl implements SearchService { // ==================== 内部方法 ==================== /** - * 构造查询条件(多途径 / 多类型 / 多来源 / 多精度 / 限定出版时段)。 + * 敏感词拦截:检索词(综合/题名/责任者/出版者/ISBN/CDOI 任一途径)命中敏感词库即屏蔽。 + * + *

敏感词表不存在或查询异常时不拦截(降级为正常检索),避免影响可用性。

*/ - private QueryWrapper buildWrapper(SearchQuery q) { - return buildWrapper(q, false); + private boolean hitsSensitive(SearchQuery q) { + String text = StrUtil.nullToEmpty(q.getKeyword()) + "\n" + + StrUtil.nullToEmpty(q.getTitle()) + "\n" + + StrUtil.nullToEmpty(q.getAuthor()) + "\n" + + StrUtil.nullToEmpty(q.getPublisher()) + "\n" + + StrUtil.nullToEmpty(q.getIsbn()) + "\n" + + StrUtil.nullToEmpty(q.getCdoi()); + if (text.isBlank()) { + return false; + } + try { + for (SensitiveWord sw : sensitiveWordMapper.selectList(null)) { + String word = sw.getWord(); + if (StrUtil.isNotBlank(word) && text.contains(word)) { + return true; + } + } + } catch (Exception e) { + log.warn("敏感词检查失败,本次不拦截:{}", e.getMessage()); + } + return false; } /** - * @param excludeClc true 时忽略查询条件里的中图分类号,用于中图法分面统计, - * 保证选中某个大类后其余大类的导航数量仍然可见 + * 是否带有任意检索/筛选条件(区别于空词全量浏览)。 */ + private boolean hasCondition(SearchQuery q) { + return StrUtil.isNotBlank(q.getKeyword()) || StrUtil.isNotBlank(q.getTitle()) + || StrUtil.isNotBlank(q.getAuthor()) || StrUtil.isNotBlank(q.getPublisher()) + || StrUtil.isNotBlank(q.getIsbn()) || StrUtil.isNotBlank(q.getCdoi()) + || StrUtil.isNotBlank(q.getClcCode()) || CollectionUtil.isNotEmpty(q.getClcCodes()) + || StrUtil.isNotBlank(q.getMediaType()) || StrUtil.isNotBlank(q.getLanguageGroup()) + || StrUtil.isNotBlank(q.getSourceLibrary()) || CollectionUtil.isNotEmpty(q.getSourceLibraries()) + || StrUtil.isNotBlank(q.getPublishYearStart()) || StrUtil.isNotBlank(q.getPublishYearEnd()); + } + + /** + * 构造查询条件(多途径 / 多类型 / 多来源 / 多精度 / 限定出版时段)。 + */ + private QueryWrapper buildWrapper(SearchQuery q) { + return buildWrapper(q, false, null, false); + } + private QueryWrapper buildWrapper(SearchQuery q, boolean excludeClc) { + return buildWrapper(q, excludeClc, null, false); + } + + private QueryWrapper buildWrapper(SearchQuery q, boolean excludeClc, + String excludeColumn, boolean includeMasked) { QueryWrapper w = new QueryWrapper<>(); w.eq("deleted", 0); // 后台处置过的记录不进检索(元数据与索引屏蔽/下架):0正常 1屏蔽 2下架 - w.and(x -> x.isNull("manage_status").or().eq("manage_status", 0)); + // includeMasked=true 时忽略该过滤,用于统计「命中但被隐藏」的记录数 + if (!includeMasked) { + w.and(x -> x.isNull("manage_status").or().eq("manage_status", 0)); + } // 综合关键词:题名 / 责任者 / 关键词 / 摘要 / 出版者 // 多词检索:空格分词,词与词之间 OR(命中任一词即返回) @@ -181,12 +258,23 @@ public class SearchServiceImpl implements SearchService { } }); } - if (StrUtil.isNotBlank(q.getMediaType())) { + if (StrUtil.isNotBlank(q.getMediaType()) && !"media_type".equals(excludeColumn)) { w.eq("media_type", q.getMediaType()); } + // 语种分组:中文文献含 chi/zh/中文(库内有少量中文写法的脏数据); + // 外文文献 = 不在中文集合内(NULL 语种视为未知,两侧都不计入外文组) + if ("chi".equalsIgnoreCase(q.getLanguageGroup())) { + w.in("language", List.of("chi", "zh", "中文")); + } else if ("foreign".equalsIgnoreCase(q.getLanguageGroup())) { + w.notIn("language", List.of("chi", "zh", "中文")); + } if (CollectionUtil.isNotEmpty(q.getSourceLibraries())) { w.in("source_library", q.getSourceLibraries()); } + // 来源院校分面单选(前端点选传单数字段) + if (StrUtil.isNotBlank(q.getSourceLibrary()) && !"source_library".equals(excludeColumn)) { + w.eq("source_library", q.getSourceLibrary().trim()); + } if (StrUtil.isNotBlank(q.getPublishYearStart())) { w.ge("publish_year", q.getPublishYearStart().trim()); } @@ -268,7 +356,9 @@ public class SearchServiceImpl implements SearchService { * @param column 参与分组的列(media_type / source_library / clc_code) */ private List facet(SearchQuery query, String column) { - QueryWrapper w = buildWrapper(query); + // 统计该列分面时排除列自身的过滤条件:选中「电子」后, + // 「资源类型」分组里纸质等其它选项仍应显示数量、可点击切换 + QueryWrapper w = buildWrapper(query, false, column, false); w.select(column + " AS name", "COUNT(*) AS cnt") .isNotNull(column) .ne(column, "") diff --git a/backend/src/main/java/com/banben/modules/search/vo/SearchResultVO.java b/backend/src/main/java/com/banben/modules/search/vo/SearchResultVO.java index be262bf..56e7086 100644 --- a/backend/src/main/java/com/banben/modules/search/vo/SearchResultVO.java +++ b/backend/src/main/java/com/banben/modules/search/vo/SearchResultVO.java @@ -33,4 +33,10 @@ public class SearchResultVO { @Schema(description = "检索耗时(ms)") private Long costMs; + + @Schema(description = "检索词命中敏感词库,结果已被屏蔽") + private Boolean sensitiveBlocked; + + @Schema(description = "命中但被屏蔽/下架而不展示的记录数") + private Long maskedCount; } diff --git a/backend/src/main/java/com/banben/modules/special/controller/SpecialController.java b/backend/src/main/java/com/banben/modules/special/controller/SpecialController.java index 9c4103c..f725e0c 100644 --- a/backend/src/main/java/com/banben/modules/special/controller/SpecialController.java +++ b/backend/src/main/java/com/banben/modules/special/controller/SpecialController.java @@ -1,5 +1,6 @@ package com.banben.modules.special.controller; +import com.banben.common.PageResult; import com.banben.common.Result; import com.banben.modules.special.dto.SpecialRecommendVO; import com.banben.modules.special.entity.SpecialResource; @@ -31,6 +32,14 @@ public class SpecialController { return Result.success(specialService.recommend(limit)); } + @Operation(summary = "特藏推荐分页列表") + @GetMapping("/recommend/page") + public Result> recommendPage( + @RequestParam(defaultValue = "1") long current, + @RequestParam(defaultValue = "10") long size) { + return Result.success(specialService.recommendPage(current, size)); + } + @Operation(summary = "特藏细览") @GetMapping("/{id}") public Result detail(@PathVariable Long id) { diff --git a/backend/src/main/java/com/banben/modules/special/service/SpecialService.java b/backend/src/main/java/com/banben/modules/special/service/SpecialService.java index 7e90f21..15ae74d 100644 --- a/backend/src/main/java/com/banben/modules/special/service/SpecialService.java +++ b/backend/src/main/java/com/banben/modules/special/service/SpecialService.java @@ -1,6 +1,7 @@ package com.banben.modules.special.service; import com.baomidou.mybatisplus.extension.service.IService; +import com.banben.common.PageResult; import com.banben.modules.special.dto.SpecialRecommendVO; import com.banben.modules.special.entity.SpecialResource; @@ -16,6 +17,12 @@ public interface SpecialService extends IService { */ List recommend(int limit); + /** + * 特藏推荐分页:先 version_resource(is_special=1,update_time 倒序), + * 后 special_resource(status=1,sort_no 正序),跨两段按同一顺序分页。 + */ + PageResult recommendPage(long current, long size); + /** * 管理端列表(special_resource 手工维护数据)。 */ diff --git a/backend/src/main/java/com/banben/modules/special/service/impl/SpecialServiceImpl.java b/backend/src/main/java/com/banben/modules/special/service/impl/SpecialServiceImpl.java index 924a773..f1b8998 100644 --- a/backend/src/main/java/com/banben/modules/special/service/impl/SpecialServiceImpl.java +++ b/backend/src/main/java/com/banben/modules/special/service/impl/SpecialServiceImpl.java @@ -2,6 +2,7 @@ package com.banben.modules.special.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.banben.common.PageResult; import com.banben.modules.resource.entity.VersionResource; import com.banben.modules.resource.mapper.VersionResourceMapper; import com.banben.modules.special.dto.SpecialRecommendVO; @@ -47,19 +48,7 @@ public class SpecialServiceImpl extends ServiceImpl { - SpecialRecommendVO vo = new SpecialRecommendVO(); - vo.setId(r.getId()); - vo.setTitle(r.getTitle()); - vo.setNote(r.getNote()); - vo.setAuthor(r.getAuthor()); - vo.setPublishYear(r.getPublishYear()); - vo.setFulltextUrl(r.getFulltextUrl()); - // version_resource 无封面与电子版字段,下载地址用全文地址兜底 - vo.setEbookUrl(r.getFulltextUrl()); - vo.setSource("VERSION"); - result.add(vo); - }); + versionResourceMapper.selectList(wrapper).forEach(r -> result.add(toVersionVO(r))); } catch (Exception e) { // is_special 字段未迁移时查询会失败,此处降级为只展示手工维护的特藏 log.warn("查询 version_resource 特藏记录失败,仅展示 special_resource:{}", e.getMessage()); @@ -68,27 +57,96 @@ public class SpecialServiceImpl extends ServiceImpl 0) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(SpecialResource::getStatus, 1) - .orderByAsc(SpecialResource::getSortNo) - .orderByDesc(SpecialResource::getCreateTime) - .last("limit " + remain); - - this.list(wrapper).forEach(s -> { - SpecialRecommendVO vo = new SpecialRecommendVO(); - vo.setId(s.getId()); - vo.setTitle(s.getName()); - vo.setNote(s.getSummary()); - vo.setCoverUrl(s.getCoverUrl()); - vo.setEbookUrl(s.getEbookUrl()); - vo.setSource("MANUAL"); - result.add(vo); - }); + result.addAll(listManual(0, remain)); } return result; } + @Override + public PageResult recommendPage(long current, long size) { + long pageNo = Math.max(1, current); + long pageSize = Math.max(1, size); + long offset = (pageNo - 1) * pageSize; + + // 各段总数(version_resource 段查询失败时按 0 处理,降级为纯手工特藏) + long countA = 0; + try { + countA = versionResourceMapper.selectCount( + new LambdaQueryWrapper().eq(VersionResource::getIsSpecial, 1)); + } catch (Exception e) { + log.warn("统计 version_resource 特藏记录失败:{}", e.getMessage()); + } + long countB = this.count(new LambdaQueryWrapper() + .eq(SpecialResource::getStatus, 1)); + long total = countA + countB; + + List records = new ArrayList<>(); + long remain = pageSize; + if (offset < countA) { + // 当前页从 version_resource 段开始,取完不够再从 special_resource 段补 + long takeA = Math.min(remain, countA - offset); + try { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(VersionResource::getIsSpecial, 1) + .orderByDesc(VersionResource::getUpdateTime) + .last("limit " + takeA + " offset " + offset); + versionResourceMapper.selectList(wrapper).forEach(r -> records.add(toVersionVO(r))); + } catch (Exception e) { + log.warn("查询 version_resource 特藏分页失败:{}", e.getMessage()); + } + remain -= records.size(); + } + + if (remain > 0) { + // 页首已越过 version_resource 段时,需跳过 (offset - countA) 条手工特藏 + long skipB = Math.max(0, offset - countA); + records.addAll(listManual(skipB, remain)); + } + + return PageResult.of(records, total, pageNo, pageSize); + } + + /** + * 查询手工特藏(special_resource):跳过 skip 条、取 n 条,sort_no 正序。 + */ + private List listManual(long skip, long n) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SpecialResource::getStatus, 1) + .orderByAsc(SpecialResource::getSortNo) + .orderByDesc(SpecialResource::getCreateTime) + .last("limit " + n + " offset " + skip); + + List result = new ArrayList<>(); + this.list(wrapper).forEach(s -> result.add(toManualVO(s))); + return result; + } + + private SpecialRecommendVO toVersionVO(VersionResource r) { + SpecialRecommendVO vo = new SpecialRecommendVO(); + vo.setId(r.getId()); + vo.setTitle(r.getTitle()); + vo.setNote(r.getNote()); + vo.setAuthor(r.getAuthor()); + vo.setPublishYear(r.getPublishYear()); + vo.setFulltextUrl(r.getFulltextUrl()); + // version_resource 无封面与电子版字段,下载地址用全文地址兜底 + vo.setEbookUrl(r.getFulltextUrl()); + vo.setSource("VERSION"); + return vo; + } + + private SpecialRecommendVO toManualVO(SpecialResource s) { + SpecialRecommendVO vo = new SpecialRecommendVO(); + vo.setId(s.getId()); + vo.setTitle(s.getName()); + vo.setNote(s.getSummary()); + vo.setCoverUrl(s.getCoverUrl()); + vo.setEbookUrl(s.getEbookUrl()); + vo.setSource("MANUAL"); + return vo; + } + @Override public List adminList() { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); diff --git a/backend/src/main/resources/db/schema-v2.sql b/backend/src/main/resources/db/schema-v2.sql index 4dcad68..6a1f469 100644 --- a/backend/src/main/resources/db/schema-v2.sql +++ b/backend/src/main/resources/db/schema-v2.sql @@ -110,3 +110,16 @@ VALUES (3, '地方志专题特藏', '区域地方志书版本资源合集,支持按地域检索。', '地方志', NULL, NULL, 3, 1, 0), (4, '红色文献特藏', '革命历史文献版本资源专题,含珍贵影印本。', '红色文献', NULL, NULL, 4, 1, 0) ON CONFLICT (id) DO NOTHING; + +-- ---------------- 特藏样例数据(军事专题,id 11 起) ---------------- +INSERT INTO special_resource (id, name, summary, category, cover_url, ebook_url, sort_no, status, deleted) +VALUES +(11, '军事历史文献特藏', '近代战争史料、作战文书与战史稿本的数字化版本资源,含战役总结、阵中日记、部队沿革等原始文献的影印与全文影像。', '军事文献', NULL, 'http://cdio.example.org/fulltext/special-0011', 11, 1, 0), +(12, '军事教材与条令教范特藏', '军队院校历年教材、条令条例与演习想定汇编,含内部讲义、教学参考图册与实兵演习方案,支持按兵种与年度浏览。', '军事教材', NULL, 'http://cdio.example.org/fulltext/special-0012', 12, 1, 0), +(13, '古兵书与武经七书特藏', '《武经七书》及历代兵家典籍的明清刻本影印,附校勘记、题解与今译对照,含稀见兵书抄本与批校本。', '兵书古籍', NULL, 'http://cdio.example.org/fulltext/special-0013', 13, 1, 0), +(14, '军事舆图与作战要图特藏', '历代军事舆图、作战要图与地形图的数字化资源,含行军路线图、要塞布防图与沙盘图,支持按地域、年代与比例尺浏览。', '军事舆图', NULL, 'http://cdio.example.org/fulltext/special-0014', 14, 1, 0), +(15, '军事影像与口述史特藏', '战地摄影、纪实影像与参战人员口述史资料,含录音转写稿、时间线整理与人物索引,可配合战史文献对照研读。', '军事影像', NULL, 'http://cdio.example.org/fulltext/special-0015', 15, 1, 0), +(16, '军事科技与兵器图册特藏', '装备技术手册、兵器图册与性能数据的版本资源合集,含多版本对照、结构化参数表与构造图解,供装备教学与研究使用。', '军事科技', NULL, 'http://cdio.example.org/fulltext/special-0016', 16, 1, 0) +ON CONFLICT (id) DO NOTHING; + +SELECT setval('special_resource_id_seq', GREATEST(COALESCE((SELECT MAX(id) FROM special_resource), 0), 1), true); diff --git a/frontend/src/api/resource.ts b/frontend/src/api/resource.ts index 2a6d3a7..842bbea 100644 --- a/frontend/src/api/resource.ts +++ b/frontend/src/api/resource.ts @@ -20,6 +20,8 @@ export interface VersionResource { taskYear?: string sourceLibrary?: string sourceLibraryAddr?: string + /** 来源资源库名 */ + sourceRepo?: string fulltextUrl?: string otherTitle?: string author?: string diff --git a/frontend/src/api/search.ts b/frontend/src/api/search.ts index 3ac172b..4b6c554 100644 --- a/frontend/src/api/search.ts +++ b/frontend/src/api/search.ts @@ -19,7 +19,11 @@ export interface SearchQuery extends ResourceQuery { cdoi?: string /** 多个中图分类号,前方一致,任一命中即可(中图法树导航点选部类时传其下所有大类) */ clcCodes?: string[] + /** 语种分组:chi 中文文献 / foreign 外文文献(首页前置筛选用) */ + languageGroup?: 'chi' | 'foreign' sourceLibraries?: string[] + /** 来源馆(单选,左侧「来源院校」分面点选用) */ + sourceLibrary?: string publishYearStart?: string publishYearEnd?: string matchType?: 'EQ' | 'LEFT' | 'RIGHT' | 'LIKE' @@ -47,6 +51,10 @@ export interface SearchResultVO { clcFacets: FacetItem[] yearStats: YearStat[] costMs: number + /** 检索词命中敏感词库,结果已被屏蔽 */ + sensitiveBlocked?: boolean + /** 命中但被屏蔽/下架而不展示的记录数 */ + maskedCount?: number } /** 统一检索(初级检索) */ diff --git a/frontend/src/api/special.ts b/frontend/src/api/special.ts index 176c01b..68f15b2 100644 --- a/frontend/src/api/special.ts +++ b/frontend/src/api/special.ts @@ -1,4 +1,5 @@ import request from './request' +import type { PageResult } from './types' /** * 特藏推荐展示项 @@ -32,6 +33,16 @@ export function getRecommend(limit = 8) { return request.get('/special/recommend', { params: { limit } }) } +/** 特藏推荐分页列表 */ +export function pageRecommend(params: { current: number; size: number }) { + return request.get>('/special/recommend/page', { params }) +} + +/** 特藏细览(special_resource 手工特藏表,查不到时 data 为 null) */ +export function getSpecialDetail(id: number) { + return request.get(`/special/${id}`) +} + export interface SpecialResource { id?: number name: string diff --git a/frontend/src/views/Dashboard.vue b/frontend/src/views/Dashboard.vue index 7762e11..7d87b88 100644 --- a/frontend/src/views/Dashboard.vue +++ b/frontend/src/views/Dashboard.vue @@ -106,11 +106,21 @@ const fieldToSearchField: Record = { 出版机构: '出版社' } +/** 前置筛选 → 检索参数:纸质/电子单勾才限媒体类型,中文/外文单勾才限语种组(同时勾选 = 不限) */ function doSearch() { - router.push({ - path: '/search', - query: { keyword: keyword.value, field: fieldToSearchField[field.value] || '综合' } - }) + const q: Record = { + keyword: keyword.value, + field: fieldToSearchField[field.value] || '综合' + } + const media = types.value.filter((t) => t === '纸质图书' || t === '电子图书') + if (media.length === 1) { + q.mediaType = media[0] === '纸质图书' ? '纸质' : '电子' + } + const lang = types.value.filter((t) => t === '中文文献' || t === '外文文献') + if (lang.length === 1) { + q.languageGroup = lang[0] === '中文文献' ? 'chi' : 'foreign' + } + router.push({ path: '/search', query: q }) } onMounted(() => { diff --git a/frontend/src/views/admin/AdminView.vue b/frontend/src/views/admin/AdminView.vue index 8b86bcd..ffc9737 100644 --- a/frontend/src/views/admin/AdminView.vue +++ b/frontend/src/views/admin/AdminView.vue @@ -26,6 +26,13 @@ import { type SensitiveHit, type SensitiveWord, } from '@/api/admin' +import { + acceptDeposit, + pageDeposit, + rejectDeposit, + type DepositQuery, + type DepositRecord +} from '@/api/deposit' // ==================== 敏感词库 ==================== const wordQuery = reactive({ current: 1, size: 10, keyword: '' }) @@ -370,12 +377,57 @@ async function resetFields() { ElMessage.success('已恢复默认配置') } +// ==================== 呈缴管理 ==================== +const depositLoading = ref(false) +const depositList = ref([]) +const depositTotal = ref(0) +const depositQuery = reactive({ current: 1, size: 20, orgName: '', status: '' }) + +async function fetchDeposits() { + depositLoading.value = true + try { + const res = await pageDeposit(depositQuery) + depositList.value = res.records || [] + depositTotal.value = res.total || 0 + } finally { + depositLoading.value = false + } +} + +async function handleDepositAudit(row: DepositRecord, accepted: boolean) { + const { value } = await ElMessageBox.prompt( + accepted ? '确认接收该呈缴?' : '请输入退回原因', + accepted ? '接收确认' : '退回', + { inputPlaceholder: '审核意见(可选)', confirmButtonText: '确定', cancelButtonText: '取消' } + ) + if (accepted) { + await acceptDeposit(row.id as number, value) + } else { + await rejectDeposit(row.id as number, value) + } + ElMessage.success('操作成功') + fetchDeposits() +} + +function depositStatusTag(status?: string) { + if (status === 'ACCEPTED') return 'success' + if (status === 'REJECTED') return 'danger' + return 'warning' +} + +function depositStatusText(status?: string) { + if (status === 'ACCEPTED') return '已接收' + if (status === 'REJECTED') return '已退回' + return '待审核' +} + onMounted(() => { fetchWords() fetchHits() fetchNodes() fetchStats() fetchFields() + fetchDeposits() }) @@ -627,6 +679,68 @@ onMounted(() => { + + + +
+ + + + + + + 查询 +
+ + + + + + + + + + + + + + + + + + +
diff --git a/frontend/src/views/deposit/DepositView.vue b/frontend/src/views/deposit/DepositView.vue index e254cfb..0563416 100644 --- a/frontend/src/views/deposit/DepositView.vue +++ b/frontend/src/views/deposit/DepositView.vue @@ -1,18 +1,8 @@ - - diff --git a/frontend/src/views/search/HotWords.vue b/frontend/src/views/search/HotWords.vue index 93cfaa0..596c815 100644 --- a/frontend/src/views/search/HotWords.vue +++ b/frontend/src/views/search/HotWords.vue @@ -9,44 +9,17 @@ const router = useRouter() const loading = ref(false) const list = ref([]) -/** 书籍类补充热词(value 即词云权重,数值越大字号越大) */ -const bookWords: FacetItem[] = [ - { name: '雕版印刷', value: 80 }, - { name: '活字本', value: 70 }, - { name: '四库全书', value: 65 }, - { name: '永乐大典', value: 60 }, - { name: '稿抄校本', value: 55 }, - { name: '家谱方志', value: 50 }, - { name: '中华再造善本', value: 45 }, - { name: '敦煌遗书', value: 40 }, - { name: '版本鉴定', value: 38 }, - { name: '金石拓片', value: 36 }, - { name: '丛书集成', value: 34 }, - { name: '汲古阁', value: 32 }, - { name: '诗文集', value: 30 }, - { name: '线装书', value: 28 }, - { name: '藏书楼', value: 26 }, - { name: '批校本', value: 24 }, - { name: '蝴蝶装', value: 22 }, - { name: '藏书印', value: 20 }, - { name: '经折装', value: 18 }, - { name: '孤本', value: 16 }, - { name: '天一阁', value: 16 }, - { name: '政书', value: 14 }, - { name: '舆图', value: 14 }, - { name: '题跋', value: 12 }, - { name: '珍本', value: 12 }, - { name: '类书', value: 10 }, - { name: '书院', value: 10 } -] +/** 词云数据:全部来自后端真实统计(检索日志 + 元数据关键词),value 为热度 */ +const cloudWords = computed<[string, number][]>(() => + list.value.map((k) => [k.name, Number(k.value) || 1]) +) -/** 真实热词权重最高(版本、古籍等),其后接书籍类热词 */ -const cloudWords = computed<[string, number][]>(() => { - const api = [...list.value].sort((a, b) => b.value - a.value) - const seen = new Set(api.map((k) => k.name)) - const out: [string, number][] = api.map((k, i) => [k.name, Math.max(80, 120 - i * 10)]) - bookWords.filter((w) => !seen.has(w.name)).forEach((w) => out.push([w.name, w.value])) - return out +/** 热度值域(字号归一化用) */ +const weightRange = computed(() => { + const vals = cloudWords.value.map((w) => w[1]) + const max = Math.max(...vals, 1) + const min = Math.min(...vals, max) + return { min, max } }) const totalCount = computed(() => @@ -58,7 +31,6 @@ const cloudRef = ref(null) const stageRef = ref(null) const FONT_FAMILY = '"Microsoft YaHei", "PingFang SC", sans-serif' -const MAX_WEIGHT = 120 function render() { const host = cloudRef.value @@ -68,12 +40,13 @@ function render() { // 重新生成:先清空上一次渲染出的 span host.innerHTML = '' + // 字号按真实热度归一化:最高热度约 61px,最低约 18px + const { min, max } = weightRange.value WordCloud.stop() WordCloud(host, { list: cloudWords.value.slice(), gridSize: 9, - // 权重 120 → 约 61px,权重 10 → 约 20px - weightFactor: (size: number) => 17 + 44 * (size / MAX_WEIGHT), + weightFactor: (size: number) => (min === max ? 32 : 18 + 43 * ((size - min) / (max - min))), fontFamily: FONT_FAMILY, fontWeight: 'bold', color: (word: string) => cloudColor(word), @@ -152,7 +125,7 @@ function go(keyword: string) {
{{ cloudWords.length }} 个热词 - 累计检索 {{ totalCount }} 次 + 累计热度 {{ totalCount }}
diff --git a/frontend/src/views/search/SearchView.vue b/frontend/src/views/search/SearchView.vue index 682a9bd..10a01a8 100644 --- a/frontend/src/views/search/SearchView.vue +++ b/frontend/src/views/search/SearchView.vue @@ -17,6 +17,8 @@ const costMs = ref(0) const mediaFacets = ref([]) const libraryFacets = ref([]) const clcFacets = ref([]) +/** 命中但被屏蔽/下架而不展示的记录数 */ +const maskedCount = ref(0) /** 中图法分类树(部类 -> 大类 -> 类目),带当前检索条件下的命中数量 */ const clcNodes = ref([]) @@ -138,9 +140,13 @@ async function doSearch() { rows.value = res.page?.records || [] total.value = res.page?.total || 0 costMs.value = res.costMs || 0 + maskedCount.value = res.maskedCount || 0 mediaFacets.value = res.mediaTypeFacets || [] libraryFacets.value = res.sourceLibraryFacets || [] clcFacets.value = res.clcFacets || [] + if (res.sensitiveBlocked) { + ElMessage.warning('检索词命中敏感词库,结果已被屏蔽') + } } finally { loading.value = false } @@ -176,6 +182,13 @@ function clearClc() { doSearch() } +/** 清除前置筛选条件(媒体类型 / 语种分组) */ +function clearCond(key: 'mediaType' | 'languageGroup') { + query[key] = undefined + query.current = 1 + doSearch() +} + /** 点选中图法节点:部类传其下所有大类号,大类/类目传自身号(前方一致) */ function pickClc(node: ClcNode, codes: string[]) { const same = selectedClc.value === node.code @@ -344,6 +357,19 @@ async function openDetail(row: VersionResource) { similar.value = await getSimilar(row.id as number, 6) } +/** + * 来源资源库原始细览页地址:按来源库地址 + 加工编号拼接。 + * 演示规则为 http://{来源库地址}/resource/{加工编号},无来源库地址时回退全文地址。 + */ +function originalUrl(r: VersionResource): string { + if (r.sourceLibraryAddr && r.processNo) { + const addr = r.sourceLibraryAddr.trim() + const base = addr.startsWith('http') ? addr : `http://${addr}` + return `${base}/resource/${encodeURIComponent(r.processNo.trim())}` + } + return r.fulltextUrl || '' +} + onMounted(() => { const kw = route.query.keyword as string const f = route.query.field as string @@ -351,6 +377,15 @@ onMounted(() => { if (f && fields.includes(f)) { field.value = f } + // 主页「前置筛选」勾选带来的条件:媒体类型 + 语种分组 + const mt = route.query.mediaType as string + if (mt === '纸质' || mt === '电子') { + query.mediaType = mt + } + const lg = route.query.languageGroup as string + if (lg === 'chi' || lg === 'foreign') { + query.languageGroup = lg + } // 检索条件为空时也执行检索 → 后端返回全部版本资源 input.value = kw || '' fetchListFields() @@ -405,7 +440,16 @@ watch(
-
共 {{ total }} 条,耗时 {{ costMs }} ms
+
+ 共 {{ total }} 条,耗时 {{ costMs }} ms + + 已隐藏 {{ maskedCount }} 条被屏蔽/下架的记录 + + {{ query.mediaType }} + + {{ query.languageGroup === 'chi' ? '中文文献' : '外文文献' }} + +
{{ detail.mediaType || '-' }} {{ detail.clcCode || '-' }} {{ detail.sourceLibrary || '-' }} + {{ detail.sourceRepo || '-' }} {{ detail.keywords || '-' }} {{ detail.summary || '-' }} + +
+ + {{ detail.sourceRepo ? `进入${detail.sourceRepo}原始页` : '查看来源库原始页' }} + + 暂无来源库地址 下载全文 暂无全文地址
+ +
相似文献推荐
-
{{ s.title }}
+
+ {{ s.title }} + {{ s.author }} + {{ s.publishYear }} +
@@ -587,6 +649,7 @@ watch( margin-bottom: 10px; .count { font-size: 13px; color: #6b7280; } + .cond-tag { margin-left: 8px; } .ops { display: flex; align-items: center; gap: 10px; } } @@ -695,5 +758,36 @@ watch( :deep(.el-pagination__jump) { margin-left: 12px; } } .dt { margin: 0 0 12px; font-size: 17px; } -.sim-item { font-size: 13px; padding: 6px 0; border-bottom: 1px dashed #eee; cursor: pointer; } +/* 相似文献推荐条目:题名 + 责任者/年份,整行可点 */ +.sim-item { + display: flex; + align-items: baseline; + gap: 10px; + font-size: 13px; + padding: 7px 4px; + border-bottom: 1px dashed #eee; + cursor: pointer; + border-radius: 4px; + transition: background 0.2s; + + &:hover { + background: var(--brand-light, #f3f7f4); + .sim-t { color: var(--brand-primary); } + } + + .sim-t { + flex: 1; + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-weight: 600; + } + + .sim-meta { + flex: none; + color: #8b93a1; + font-size: 12px; + } +} diff --git a/frontend/src/views/special/SpecialView.vue b/frontend/src/views/special/SpecialView.vue index 7e9ce3c..918d750 100644 --- a/frontend/src/views/special/SpecialView.vue +++ b/frontend/src/views/special/SpecialView.vue @@ -1,16 +1,26 @@