UserHoldCountController.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package com.izouma.nineth.web;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.izouma.nineth.dto.PageQuery;
  4. import com.izouma.nineth.dto.UserHoldDTO;
  5. import com.izouma.nineth.repo.UserRepo;
  6. import com.izouma.nineth.service.SysConfigService;
  7. import com.izouma.nineth.service.UserHoldCountCache;
  8. import com.izouma.nineth.service.UserHoldCountService;
  9. import com.izouma.nineth.utils.excel.ExcelUtils;
  10. import lombok.AllArgsConstructor;
  11. import org.springframework.data.domain.Page;
  12. import org.springframework.web.bind.annotation.*;
  13. import javax.servlet.http.HttpServletResponse;
  14. import java.io.IOException;
  15. import java.util.*;
  16. @RestController
  17. @RequestMapping("/userHold")
  18. @AllArgsConstructor
  19. public class UserHoldCountController {
  20. private UserHoldCountService userHoldCountService;
  21. private UserHoldCountCache userHoldCountCache;
  22. private SysConfigService sysConfigService;
  23. private UserRepo userRepo;
  24. @PostMapping("/all")
  25. public Page<UserHoldDTO> all(@RequestBody PageQuery pageQuery) {
  26. return userHoldCountService.all(pageQuery).toPage();
  27. }
  28. @GetMapping("/top")
  29. public List<UserHoldDTO> top(@RequestParam int size) {
  30. PageQuery pageQuery = new PageQuery();
  31. pageQuery.setPage(0);
  32. pageQuery.setSize(size);
  33. List<UserHoldDTO> userHoldDTOs = userHoldCountService.all(pageQuery).getContent();
  34. userHoldDTOs.sort(Comparator.comparing(UserHoldDTO::getPrice).reversed());
  35. return userHoldDTOs;
  36. }
  37. @GetMapping("/app/top")
  38. public List<UserHoldDTO> appTop() {
  39. // List<UserHoldDTO> top = top(30);
  40. // if (CollectionUtils.isEmpty(top)) {
  41. // return null;
  42. // }
  43. // top.forEach(userHoldDTO -> {
  44. // userHoldDTO.setNum(0);
  45. // userHoldDTO.setUsername(null);
  46. // userHoldDTO.setPrefixName(null);
  47. // userHoldDTO.setName(null);
  48. // userHoldDTO.setPrice(null);
  49. // userHoldDTO.setUserId(null);
  50. // });
  51. // return top;
  52. List<Long> ids = Arrays.asList(284121L,3334431L,7214320L,3872656L,1706745L,7165794L,3647585L,10586L,7292L,1338654L,6593745L,1829399L,7644L,274969L,7373L,12234L,5571296L,3273130L,3041289L,10562L,9181L,275693L,3477850L,702628L,2533638L,8157L,8683L,7632L,13716L,9188L);
  53. List<Map<String, String>> assets = userRepo.newTop(ids);
  54. JSONArray jsonArray = new JSONArray();
  55. jsonArray.addAll(assets);
  56. return jsonArray.toJavaList(UserHoldDTO.class);
  57. }
  58. @GetMapping("/excel")
  59. @ResponseBody
  60. public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
  61. List<UserHoldDTO> data = all(pageQuery).getContent();
  62. ExcelUtils.export(response, data);
  63. }
  64. @GetMapping("/refresh")
  65. public void refresh() {
  66. // 重新缓存
  67. userHoldCountCache.allUserHold();
  68. }
  69. }