1.cache thanks

main
Gary 9 months ago
parent 299f69a1d2
commit a8a7842250

@ -27,6 +27,8 @@ import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation; import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults; import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@ -64,7 +66,6 @@ import io.swagger.annotations.ApiParam;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import util.DateUtil; import util.DateUtil;
import util.IdWorker; import util.IdWorker;
import util.ScaleFilter;
import util.StringTools; import util.StringTools;
@RestController @RestController
@ -72,6 +73,7 @@ import util.StringTools;
@RequestMapping("/my") @RequestMapping("/my")
@Api(tags = "MyController") @Api(tags = "MyController")
public class MyController extends BaseController { public class MyController extends BaseController {
private static final String REDIS_KEY_THANKS = "thanks";
@Autowired @Autowired
private S3Service s3Service; private S3Service s3Service;
@Autowired @Autowired
@ -96,6 +98,9 @@ public class MyController extends BaseController {
@Autowired @Autowired
private SensitiveWordBs sensitiveWordBs; private SensitiveWordBs sensitiveWordBs;
@Autowired
private RedisTemplate redisTemplate;
public static String USER_AVATAR_DIRECTORY = "user/avatar/"; public static String USER_AVATAR_DIRECTORY = "user/avatar/";
public static String USER_FEEDBACK_IMAGE_DIRECTORY = "user/feedback/"; public static String USER_FEEDBACK_IMAGE_DIRECTORY = "user/feedback/";
@ -400,8 +405,17 @@ public class MyController extends BaseController {
@ApiOperation(value = "11.感谢", notes = "贡献者列表") @ApiOperation(value = "11.感谢", notes = "贡献者列表")
@GetMapping("/thanks") @GetMapping("/thanks")
public Result<List<UserRespDTO>> getThanks() { public Result<List<UserRespDTO>> getThanks() {
List<UserRespDTO> list=userInfoService.getThanks().stream().sorted(Comparator.comparing(u->getIndex(u))).map(user->getUserRespDTO(user, false, Collections.emptySet())).collect(Collectors.toList()); return Result.success(getThankList());
return Result.success(list); }
@SuppressWarnings("unchecked")
private List<UserRespDTO> getThankList() {
List<UserRespDTO> thanks = (List<UserRespDTO>) redisTemplate.opsForValue().get(REDIS_KEY_THANKS);
if (CollectionUtils.isEmpty(thanks)) {
thanks = userInfoService.getThanks().stream().sorted(Comparator.comparing(u->getIndex(u))).map(user->getUserRespDTO(user, false, Collections.emptySet())).collect(Collectors.toList());
redisTemplate.opsForValue().set(REDIS_KEY_THANKS, thanks);
}
return thanks;
} }
private Integer getIndex(UserInfo u) { private Integer getIndex(UserInfo u) {

@ -1,12 +1,14 @@
package com.luoo.user.dto.response; package com.luoo.user.dto.response;
import java.io.Serializable;
import java.util.List; import java.util.List;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@Data @Data
public class UserRespDTO { public class UserRespDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "ID") @ApiModelProperty(value = "ID")
private String id; private String id;
@ApiModelProperty(value = "昵称,首次注册登录,登录用户随机为“雀乐-XXXX-XXXX”游客为“游客-XXXX-XXXX”, XXXX 为2~4位中文昵称", example = "雀乐-蓉江晨玥^沙顺芊润") @ApiModelProperty(value = "昵称,首次注册登录,登录用户随机为“雀乐-XXXX-XXXX”游客为“游客-XXXX-XXXX”, XXXX 为2~4位中文昵称", example = "雀乐-蓉江晨玥^沙顺芊润")

Loading…
Cancel
Save