feat: 新增呈缴管理功能与检索筛选优化
This commit is contained in:
+37
-2
@@ -126,14 +126,49 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||
|
||||
@Override
|
||||
public List<FacetItem> hotKeywords(int limit) {
|
||||
int top = Math.max(1, limit);
|
||||
// 热词 = 检索日志真实检索词 + 元数据关键词(库内真实数据),合并累计
|
||||
Map<String, Long> merged = new LinkedHashMap<>();
|
||||
|
||||
QueryWrapper<SearchLog> 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<String, Object> 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<String, Object> 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.<String, Long>comparingByValue().reversed())
|
||||
.limit(top)
|
||||
.map(e -> new FacetItem(e.getKey(), e.getValue()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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<PageResult<DepositRecord>> page(DepositQuery query) {
|
||||
requireAdmin();
|
||||
return Result.success(depositService.pageQuery(query));
|
||||
}
|
||||
|
||||
@Operation(summary = "管理端查看呈缴详情")
|
||||
@Operation(summary = "管理端查看呈缴详情(仅管理员)")
|
||||
@GetMapping("/{id}")
|
||||
public Result<DepositRecord> detail(@PathVariable Long id) {
|
||||
requireAdmin();
|
||||
return Result.success(depositService.getById(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "管理端接收呈缴")
|
||||
@Operation(summary = "管理端接收呈缴(仅管理员)")
|
||||
@PostMapping("/{id}/accept")
|
||||
public Result<Void> 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<Void> 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("仅管理员可执行该操作");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<VersionResource> {
|
||||
|
||||
/**
|
||||
* 元数据关键词热度:按分号/逗号/顿号/空白拆分 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<Map<String, Object>> splitKeywordCounts(@Param("limit") int limit);
|
||||
}
|
||||
|
||||
@@ -49,9 +49,15 @@ public class SearchQuery {
|
||||
@Schema(description = "媒体类型:纸质/电子")
|
||||
private String mediaType;
|
||||
|
||||
@Schema(description = "语种分组:chi 中文文献 / foreign 外文文献(首页前置筛选用)")
|
||||
private String languageGroup;
|
||||
|
||||
@Schema(description = "来源馆(多选)")
|
||||
private List<String> sourceLibraries;
|
||||
|
||||
@Schema(description = "来源馆(单选,左侧「来源院校」分面点选用)")
|
||||
private String sourceLibrary;
|
||||
|
||||
/** ---------------- 限定出版时段 ---------------- */
|
||||
@Schema(description = "出版年份起(含)", example = "2000")
|
||||
private String publishYearStart;
|
||||
|
||||
+98
-8
@@ -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<VersionResource> 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 任一途径)命中敏感词库即屏蔽。
|
||||
*
|
||||
* <p>敏感词表不存在或查询异常时不拦截(降级为正常检索),避免影响可用性。</p>
|
||||
*/
|
||||
private QueryWrapper<VersionResource> 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<VersionResource> buildWrapper(SearchQuery q) {
|
||||
return buildWrapper(q, false, null, false);
|
||||
}
|
||||
|
||||
private QueryWrapper<VersionResource> buildWrapper(SearchQuery q, boolean excludeClc) {
|
||||
return buildWrapper(q, excludeClc, null, false);
|
||||
}
|
||||
|
||||
private QueryWrapper<VersionResource> buildWrapper(SearchQuery q, boolean excludeClc,
|
||||
String excludeColumn, boolean includeMasked) {
|
||||
QueryWrapper<VersionResource> 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<FacetItem> facet(SearchQuery query, String column) {
|
||||
QueryWrapper<VersionResource> w = buildWrapper(query);
|
||||
// 统计该列分面时排除列自身的过滤条件:选中「电子」后,
|
||||
// 「资源类型」分组里纸质等其它选项仍应显示数量、可点击切换
|
||||
QueryWrapper<VersionResource> w = buildWrapper(query, false, column, false);
|
||||
w.select(column + " AS name", "COUNT(*) AS cnt")
|
||||
.isNotNull(column)
|
||||
.ne(column, "")
|
||||
|
||||
@@ -33,4 +33,10 @@ public class SearchResultVO {
|
||||
|
||||
@Schema(description = "检索耗时(ms)")
|
||||
private Long costMs;
|
||||
|
||||
@Schema(description = "检索词命中敏感词库,结果已被屏蔽")
|
||||
private Boolean sensitiveBlocked;
|
||||
|
||||
@Schema(description = "命中但被屏蔽/下架而不展示的记录数")
|
||||
private Long maskedCount;
|
||||
}
|
||||
|
||||
@@ -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<PageResult<SpecialRecommendVO>> recommendPage(
|
||||
@RequestParam(defaultValue = "1") long current,
|
||||
@RequestParam(defaultValue = "10") long size) {
|
||||
return Result.success(specialService.recommendPage(current, size));
|
||||
}
|
||||
|
||||
@Operation(summary = "特藏细览")
|
||||
@GetMapping("/{id}")
|
||||
public Result<SpecialResource> detail(@PathVariable Long id) {
|
||||
|
||||
@@ -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<SpecialResource> {
|
||||
*/
|
||||
List<SpecialRecommendVO> recommend(int limit);
|
||||
|
||||
/**
|
||||
* 特藏推荐分页:先 version_resource(is_special=1,update_time 倒序),
|
||||
* 后 special_resource(status=1,sort_no 正序),跨两段按同一顺序分页。
|
||||
*/
|
||||
PageResult<SpecialRecommendVO> recommendPage(long current, long size);
|
||||
|
||||
/**
|
||||
* 管理端列表(special_resource 手工维护数据)。
|
||||
*/
|
||||
|
||||
+87
-29
@@ -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<SpecialResourceMapper, Speci
|
||||
.orderByDesc(VersionResource::getUpdateTime)
|
||||
.last("limit " + size);
|
||||
|
||||
versionResourceMapper.selectList(wrapper).forEach(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");
|
||||
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<SpecialResourceMapper, Speci
|
||||
// 2) special_resource 手工维护的特藏(补齐剩余条数)
|
||||
int remain = size - result.size();
|
||||
if (remain > 0) {
|
||||
LambdaQueryWrapper<SpecialResource> 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<SpecialRecommendVO> 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<VersionResource>().eq(VersionResource::getIsSpecial, 1));
|
||||
} catch (Exception e) {
|
||||
log.warn("统计 version_resource 特藏记录失败:{}", e.getMessage());
|
||||
}
|
||||
long countB = this.count(new LambdaQueryWrapper<SpecialResource>()
|
||||
.eq(SpecialResource::getStatus, 1));
|
||||
long total = countA + countB;
|
||||
|
||||
List<SpecialRecommendVO> records = new ArrayList<>();
|
||||
long remain = pageSize;
|
||||
if (offset < countA) {
|
||||
// 当前页从 version_resource 段开始,取完不够再从 special_resource 段补
|
||||
long takeA = Math.min(remain, countA - offset);
|
||||
try {
|
||||
LambdaQueryWrapper<VersionResource> 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<SpecialRecommendVO> listManual(long skip, long n) {
|
||||
LambdaQueryWrapper<SpecialResource> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SpecialResource::getStatus, 1)
|
||||
.orderByAsc(SpecialResource::getSortNo)
|
||||
.orderByDesc(SpecialResource::getCreateTime)
|
||||
.last("limit " + n + " offset " + skip);
|
||||
|
||||
List<SpecialRecommendVO> 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<SpecialResource> adminList() {
|
||||
LambdaQueryWrapper<SpecialResource> wrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user