You've already forked FrameTour-BE
- 集成 PuzzleRepository 缓存层替代直接数据库查询 - 在 PriceBiz 中使用缓存查询拼图模板数据 - 在 AppTemplateController 中添加景区模板封面URL批量获取接口 - 在 PuzzleTemplateServiceImpl 中实现模板增改时的缓存清理逻辑 - 在 FaceServiceImpl 中使用缓存查询拼图模板 - 优化模板查询性能并减少数据库压力
87 lines
2.9 KiB
Java
87 lines
2.9 KiB
Java
package com.ycwl.basic.controller.mobile;
|
|
|
|
import com.ycwl.basic.model.pc.template.resp.TemplateRespVO;
|
|
import com.ycwl.basic.puzzle.entity.PuzzleTemplateEntity;
|
|
import com.ycwl.basic.puzzle.repository.PuzzleRepository;
|
|
import com.ycwl.basic.repository.TemplateRepository;
|
|
import com.ycwl.basic.utils.ApiResponse;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
/**
|
|
* 移动端模板接口
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/api/mobile/template/v1")
|
|
@RequiredArgsConstructor
|
|
public class AppTemplateController {
|
|
|
|
private final TemplateRepository templateRepository;
|
|
private final PuzzleRepository puzzleRepository;
|
|
|
|
/**
|
|
* 根据模板ID获取封面URL
|
|
*
|
|
* @param templateId 模板ID
|
|
* @return 模板封面URL
|
|
*/
|
|
@GetMapping("/cover/{templateId}")
|
|
public ApiResponse<String> getTemplateCoverUrl(@PathVariable("templateId") Long templateId) {
|
|
if (templateId == null) {
|
|
return ApiResponse.fail("模板ID不能为空");
|
|
}
|
|
|
|
TemplateRespVO template = templateRepository.getTemplate(templateId);
|
|
if (template == null) {
|
|
return ApiResponse.fail("未找到对应的模板");
|
|
}
|
|
|
|
String coverUrl = template.getCoverUrl();
|
|
if (coverUrl == null || coverUrl.isEmpty()) {
|
|
return ApiResponse.fail("该模板没有封面地址");
|
|
}
|
|
|
|
return ApiResponse.success(coverUrl);
|
|
}
|
|
|
|
/**
|
|
* 根据景区ID获取所有模板封面URL列表(用于前端预缓存)
|
|
*
|
|
* @param scenicId 景区ID
|
|
* @return 模板封面URL列表
|
|
*/
|
|
@GetMapping("/scenic/{scenicId}/covers")
|
|
public ApiResponse<List<String>> getScenicTemplateCoverUrls(@PathVariable("scenicId") Long scenicId) {
|
|
if (scenicId == null) {
|
|
return ApiResponse.fail("景区ID不能为空");
|
|
}
|
|
|
|
List<String> coverUrls = new ArrayList<>();
|
|
|
|
// 获取普通模板封面
|
|
List<TemplateRespVO> templateList = templateRepository.getTemplateListByScenicId(scenicId);
|
|
templateList.stream()
|
|
.map(TemplateRespVO::getCoverUrl)
|
|
.filter(Objects::nonNull)
|
|
.filter(url -> !url.isEmpty())
|
|
.forEach(coverUrls::add);
|
|
|
|
// 获取拼图模板封面(使用缓存)
|
|
List<PuzzleTemplateEntity> puzzleTemplateList = puzzleRepository.listTemplateByScenic(scenicId);
|
|
puzzleTemplateList.stream()
|
|
.map(PuzzleTemplateEntity::getCoverImage)
|
|
.filter(Objects::nonNull)
|
|
.filter(url -> !url.isEmpty())
|
|
.forEach(coverUrls::add);
|
|
|
|
return ApiResponse.success(coverUrls);
|
|
}
|
|
}
|