|
|
|
@ -27,76 +27,95 @@ import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* 热门搜索相关操作的控制器类,用于处理后台对热门搜索的各种请求,例如分页查询、获取详情、保存、修改和删除等操作。
|
|
|
|
|
* @author lgh on 2019/03/27.
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/admin/hotSearch")
|
|
|
|
|
public class HotSearchController {
|
|
|
|
|
|
|
|
|
|
// 自动注入热门搜索服务层接口,通过该接口调用具体的业务逻辑方法
|
|
|
|
|
@Autowired
|
|
|
|
|
private HotSearchService hotSearchService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页获取
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* 分页获取热门搜索信息的方法
|
|
|
|
|
* 此方法根据传入的查询条件(包括搜索内容、标题、状态等)以及分页参数,查询并返回符合条件的热门搜索信息分页结果。
|
|
|
|
|
* 只有拥有 'admin:hotSearch:page' 权限的用户才能访问此方法。
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/page")
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:hotSearch:page')")
|
|
|
|
|
public ServerResponseEntity<IPage<HotSearch>> page(HotSearch hotSearch,PageParam<HotSearch> page){
|
|
|
|
|
IPage<HotSearch> hotSearchs = hotSearchService.page(page,new LambdaQueryWrapper<HotSearch>()
|
|
|
|
|
.eq(HotSearch::getShopId, SecurityUtils.getSysUser().getShopId())
|
|
|
|
|
.like(StrUtil.isNotBlank(hotSearch.getContent()), HotSearch::getContent,hotSearch.getContent())
|
|
|
|
|
.like(StrUtil.isNotBlank(hotSearch.getTitle()), HotSearch::getTitle,hotSearch.getTitle())
|
|
|
|
|
.eq(hotSearch.getStatus()!=null, HotSearch::getStatus,hotSearch.getStatus())
|
|
|
|
|
.orderByAsc(HotSearch::getSeq)
|
|
|
|
|
);
|
|
|
|
|
return ServerResponseEntity.success(hotSearchs);
|
|
|
|
|
}
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:hotSearch:page')")
|
|
|
|
|
public ServerResponseEntity<IPage<HotSearch>> page(HotSearch hotSearch, PageParam<HotSearch> page) {
|
|
|
|
|
// 创建一个 LambdaQueryWrapper 用于构建查询条件,结合 MyBatis Plus 进行数据库查询
|
|
|
|
|
IPage<HotSearch> hotSearchs = hotSearchService.page(page, new LambdaQueryWrapper<HotSearch>()
|
|
|
|
|
// 根据当前登录用户所属店铺的 ID 进行筛选,确保只获取该店铺相关的热门搜索记录
|
|
|
|
|
.eq(HotSearch::getShopId, SecurityUtils.getSysUser().getShopId())
|
|
|
|
|
// 如果传入的热门搜索内容不为空,则模糊匹配内容字段进行查询
|
|
|
|
|
.like(StrUtil.isNotBlank(hotSearch.getContent()), HotSearch::getContent, hotSearch.getContent())
|
|
|
|
|
// 如果传入的热门搜索标题不为空,则模糊匹配标题字段进行查询
|
|
|
|
|
.like(StrUtil.isNotBlank(hotSearch.getTitle()), HotSearch::getTitle, hotSearch.getTitle())
|
|
|
|
|
// 如果传入的状态不为空,则精确匹配状态字段进行查询
|
|
|
|
|
.eq(hotSearch.getStatus()!= null, HotSearch::getStatus, hotSearch.getStatus())
|
|
|
|
|
// 按照序号字段升序排序结果,方便呈现顺序相关的展示需求
|
|
|
|
|
.orderByAsc(HotSearch::getSeq)
|
|
|
|
|
);
|
|
|
|
|
return ServerResponseEntity.success(hotSearchs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取信息
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/info/{id}")
|
|
|
|
|
public ServerResponseEntity<HotSearch> info(@PathVariable("id") Long id){
|
|
|
|
|
HotSearch hotSearch = hotSearchService.getById(id);
|
|
|
|
|
return ServerResponseEntity.success(hotSearch);
|
|
|
|
|
}
|
|
|
|
|
* 根据给定的 ID 获取热门搜索详细信息的方法
|
|
|
|
|
* 此方法接收一个热门搜索记录的 ID,通过调用服务层的方法从数据库中获取对应的详细信息,并返回给前端。
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/info/{id}")
|
|
|
|
|
public ServerResponseEntity<HotSearch> info(@PathVariable("id") Long id) {
|
|
|
|
|
// 通过服务层的 getById 方法,根据传入的 ID 获取对应的热门搜索记录
|
|
|
|
|
HotSearch hotSearch = hotSearchService.getById(id);
|
|
|
|
|
return ServerResponseEntity.success(hotSearch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:hotSearch:save')")
|
|
|
|
|
public ServerResponseEntity<Void> save(@RequestBody @Valid HotSearch hotSearch){
|
|
|
|
|
hotSearch.setRecDate(new Date());
|
|
|
|
|
hotSearch.setShopId(SecurityUtils.getSysUser().getShopId());
|
|
|
|
|
hotSearchService.save(hotSearch);
|
|
|
|
|
//清除缓存
|
|
|
|
|
hotSearchService.removeHotSearchDtoCacheByShopId(SecurityUtils.getSysUser().getShopId());
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 保存热门搜索信息的方法
|
|
|
|
|
* 此方法接收一个包含热门搜索信息的 HotSearch 对象,设置记录的创建日期以及所属店铺 ID(从当前登录用户获取),
|
|
|
|
|
* 然后调用服务层的保存方法将数据保存到数据库中,并在保存后清除对应店铺的热门搜索缓存,只有拥有 'admin:hotSearch:save' 权限的用户才能执行此操作。
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:hotSearch:save')")
|
|
|
|
|
public ServerResponseEntity<Void> save(@RequestBody @Valid HotSearch hotSearch) {
|
|
|
|
|
// 设置记录的创建日期为当前日期
|
|
|
|
|
hotSearch.setRecDate(new Date());
|
|
|
|
|
// 设置记录所属的店铺 ID,从当前登录用户的信息中获取
|
|
|
|
|
hotSearch.setShopId(SecurityUtils.getSysUser().getShopId());
|
|
|
|
|
hotSearchService.save(hotSearch);
|
|
|
|
|
// 清除对应店铺的热门搜索缓存,保证数据的一致性
|
|
|
|
|
hotSearchService.removeHotSearchDtoCacheByShopId(SecurityUtils.getSysUser().getShopId());
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改
|
|
|
|
|
*/
|
|
|
|
|
@PutMapping
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:hotSearch:update')")
|
|
|
|
|
public ServerResponseEntity<Void> update(@RequestBody @Valid HotSearch hotSearch){
|
|
|
|
|
hotSearchService.updateById(hotSearch);
|
|
|
|
|
//清除缓存
|
|
|
|
|
hotSearchService.removeHotSearchDtoCacheByShopId(SecurityUtils.getSysUser().getShopId());
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 修改热门搜索信息的方法
|
|
|
|
|
* 此方法接收一个包含更新后热门搜索信息的 HotSearch 对象,调用服务层的更新方法将数据库中的对应记录进行更新,
|
|
|
|
|
* 并在更新后清除对应店铺的热门搜索缓存,只有拥有 'admin:hotSearch:update' 权限的用户才能执行此操作。
|
|
|
|
|
*/
|
|
|
|
|
@PutMapping
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:hotSearch:update')")
|
|
|
|
|
public ServerResponseEntity<Void> update(@RequestBody @Valid HotSearch hotSearch) {
|
|
|
|
|
hotSearchService.updateById(hotSearch);
|
|
|
|
|
// 清除对应店铺的热门搜索缓存,确保缓存数据与数据库最新数据一致
|
|
|
|
|
hotSearchService.removeHotSearchDtoCacheByShopId(SecurityUtils.getSysUser().getShopId());
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除
|
|
|
|
|
*/
|
|
|
|
|
@DeleteMapping
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:hotSearch:delete')")
|
|
|
|
|
public ServerResponseEntity<Void> delete(@RequestBody List<Long> ids){
|
|
|
|
|
hotSearchService.removeByIds(ids);
|
|
|
|
|
//清除缓存
|
|
|
|
|
hotSearchService.removeHotSearchDtoCacheByShopId(SecurityUtils.getSysUser().getShopId());
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 根据给定的 ID 列表批量删除热门搜索记录的方法
|
|
|
|
|
* 此方法接收一个包含多个热门搜索记录 ID 的列表,调用服务层的删除方法从数据库中批量删除这些记录,
|
|
|
|
|
* 并在删除后清除对应店铺的热门搜索缓存,只有拥有 'admin:hotSearch:delete' 权限的用户才能执行此操作。
|
|
|
|
|
*/
|
|
|
|
|
@DeleteMapping
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:hotSearch:delete')")
|
|
|
|
|
public ServerResponseEntity<Void> delete(@RequestBody List<Long> ids) {
|
|
|
|
|
hotSearchService.removeByIds(ids);
|
|
|
|
|
// 清除对应店铺的热门搜索缓存,保证数据的准确性
|
|
|
|
|
hotSearchService.removeHotSearchDtoCacheByShopId(SecurityUtils.getSysUser().getShopId());
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
}
|