删除搜索历史
/** * 删除历史记录 * * @param dto * @return */ @Override public ResponseResult delUserSearch(HistorySearchDto dto) { //1、检查参数 if(dto.getId() == null){ return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID); } //2、判断是否登录 ApUser user = AppThreadLocalUtil.getUser(); if(user == null){ return ResponseResult.errorResult(AppHttpCodeEnum.NEED_LOGIN); } //3、删除 mongoTemplate.remove(Query.query(Criteria.where("userId").is(user.getId()).and("id").is(dto.getId())), ApUserSearch.class); return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS); }
注:在保存用户搜索历史记录时由于是异步调用开启新线程,所以无法从ThreadLocal获得用户id