package com.izouma.nineth.web; import com.alibaba.fastjson.JSONArray; import com.izouma.nineth.dto.PageQuery; import com.izouma.nineth.dto.UserHoldDTO; import com.izouma.nineth.repo.UserRepo; import com.izouma.nineth.service.SysConfigService; import com.izouma.nineth.service.UserHoldCountCache; import com.izouma.nineth.service.UserHoldCountService; import com.izouma.nineth.utils.excel.ExcelUtils; import lombok.AllArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.*; @RestController @RequestMapping("/userHold") @AllArgsConstructor public class UserHoldCountController { private UserHoldCountService userHoldCountService; private UserHoldCountCache userHoldCountCache; private SysConfigService sysConfigService; private UserRepo userRepo; @PostMapping("/all") public Page all(@RequestBody PageQuery pageQuery) { return userHoldCountService.all(pageQuery).toPage(); } @GetMapping("/top") public List top(@RequestParam int size) { PageQuery pageQuery = new PageQuery(); pageQuery.setPage(0); pageQuery.setSize(size); List userHoldDTOs = userHoldCountService.all(pageQuery).getContent(); userHoldDTOs.sort(Comparator.comparing(UserHoldDTO::getPrice).reversed()); return userHoldDTOs; } @GetMapping("/app/top") public List appTop() { // List top = top(30); // if (CollectionUtils.isEmpty(top)) { // return null; // } // top.forEach(userHoldDTO -> { // userHoldDTO.setNum(0); // userHoldDTO.setUsername(null); // userHoldDTO.setPrefixName(null); // userHoldDTO.setName(null); // userHoldDTO.setPrice(null); // userHoldDTO.setUserId(null); // }); // return top; List 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); List> assets = userRepo.newTop(ids); JSONArray jsonArray = new JSONArray(); jsonArray.addAll(assets); return jsonArray.toJavaList(UserHoldDTO.class); } @GetMapping("/excel") @ResponseBody public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException { List data = all(pageQuery).getContent(); ExcelUtils.export(response, data); } @GetMapping("/refresh") public void refresh() { // 重新缓存 userHoldCountCache.allUserHold(); } }