You've already forked FrameTour-BE
feat(puzzle): 实现拼图模板缓存功能
- 集成 PuzzleRepository 缓存层替代直接数据库查询 - 在 PriceBiz 中使用缓存查询拼图模板数据 - 在 AppTemplateController 中添加景区模板封面URL批量获取接口 - 在 PuzzleTemplateServiceImpl 中实现模板增改时的缓存清理逻辑 - 在 FaceServiceImpl 中使用缓存查询拼图模板 - 优化模板查询性能并减少数据库压力
This commit is contained in:
@@ -56,6 +56,11 @@ public class PuzzleTemplateServiceImpl implements IPuzzleTemplateService {
|
||||
entity.setDeleted(0);
|
||||
templateMapper.insert(entity);
|
||||
|
||||
// 清除景区模板列表缓存
|
||||
if (entity.getScenicId() != null) {
|
||||
puzzleRepository.clearTemplateByScenicCache(entity.getScenicId());
|
||||
}
|
||||
|
||||
log.info("拼图模板创建成功: id={}, code={}", entity.getId(), entity.getCode());
|
||||
return entity.getId();
|
||||
}
|
||||
@@ -71,8 +76,11 @@ public class PuzzleTemplateServiceImpl implements IPuzzleTemplateService {
|
||||
throw new IllegalArgumentException("模板不存在: " + id);
|
||||
}
|
||||
|
||||
// 如果修改了编码,检查新编码是否已存在
|
||||
// 记录旧值
|
||||
String oldCode = existing.getCode();
|
||||
Long oldScenicId = existing.getScenicId();
|
||||
|
||||
// 如果修改了编码,检查新编码是否已存在
|
||||
if (request.getCode() != null && !request.getCode().equals(existing.getCode())) {
|
||||
int count = templateMapper.countByCode(request.getCode(), id);
|
||||
if (count > 0) {
|
||||
@@ -85,12 +93,18 @@ public class PuzzleTemplateServiceImpl implements IPuzzleTemplateService {
|
||||
entity.setId(id);
|
||||
templateMapper.update(entity);
|
||||
|
||||
// 清除缓存(如果修改了code,需要同时清除新旧code的缓存)
|
||||
// 清除缓存
|
||||
puzzleRepository.clearTemplateCache(id, oldCode);
|
||||
if (request.getCode() != null && !request.getCode().equals(oldCode)) {
|
||||
puzzleRepository.clearTemplateCache(null, request.getCode());
|
||||
}
|
||||
|
||||
// 如果 scenicId 变更,清除新旧两个景区的缓存
|
||||
Long newScenicId = request.getScenicId();
|
||||
if (newScenicId != null && !newScenicId.equals(oldScenicId)) {
|
||||
puzzleRepository.clearTemplateByScenicCache(newScenicId);
|
||||
}
|
||||
|
||||
log.info("拼图模板更新成功: id={}", id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user