🎨 修改列表接口统一返回 PageInfo 对象

This commit is contained in:
ronger 2022-07-22 21:52:31 +08:00
parent 64421a2bfa
commit 15e82e3ded
12 changed files with 75 additions and 163 deletions

View File

@ -114,7 +114,7 @@ public class LuceneSearchController {
} }
articles.addAll(articleDTOList); articles.addAll(articleDTOList);
PageInfo<ArticleDTO> pageInfo = new PageInfo<>(articles); PageInfo<ArticleDTO> pageInfo = new PageInfo<>(articles);
return GlobalResultGenerator.genSuccessResult(Utils.getArticlesGlobalResult(pageInfo)); return GlobalResultGenerator.genSuccessResult(pageInfo);
} }
/** /**
@ -156,7 +156,7 @@ public class LuceneSearchController {
} }
users.addAll(userDTOList); users.addAll(userDTOList);
PageInfo<UserDTO> pageInfo = new PageInfo<>(users); PageInfo<UserDTO> pageInfo = new PageInfo<>(users);
return GlobalResultGenerator.genSuccessResult(Utils.getUserGlobalResult(pageInfo)); return GlobalResultGenerator.genSuccessResult(pageInfo);
} }
/** /**
@ -198,6 +198,6 @@ public class LuceneSearchController {
} }
portfolios.addAll(portfolioDTOList); portfolios.addAll(portfolioDTOList);
PageInfo<PortfolioDTO> pageInfo = new PageInfo<>(portfolios); PageInfo<PortfolioDTO> pageInfo = new PageInfo<>(portfolios);
return GlobalResultGenerator.genSuccessResult(Utils.getPortfolioGlobalResult(pageInfo)); return GlobalResultGenerator.genSuccessResult(pageInfo);
} }
} }

View File

@ -40,17 +40,15 @@ public class AdminController {
private ArticleService articleService; private ArticleService articleService;
@Resource @Resource
private CommentService commentService; private CommentService commentService;
@Resource
private ProductService productService;
@GetMapping("/users") @GetMapping("/users")
public GlobalResult<Map<String, Object>> users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, UserSearchDTO searchDTO){ public GlobalResult<PageInfo<UserInfoDTO>> users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, UserSearchDTO searchDTO){
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<UserInfoDTO> list = userService.findUsers(searchDTO); List<UserInfoDTO> list = userService.findUsers(searchDTO);
PageInfo<UserInfoDTO> pageInfo = new PageInfo<>(list); PageInfo<UserInfoDTO> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<String, Object>(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("users", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/user/{idUser}/role") @GetMapping("/user/{idUser}/role")
@ -60,15 +58,11 @@ public class AdminController {
} }
@GetMapping("/roles") @GetMapping("/roles")
public GlobalResult<Map<String, Object>> roles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){ public GlobalResult<PageInfo<Role>> roles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<Role> list = roleService.findAll(); List<Role> list = roleService.findAll();
PageInfo<Role> pageInfo = new PageInfo<>(list); PageInfo<Role> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<String, Object>(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("roles", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
@PatchMapping("/user/update-role") @PatchMapping("/user/update-role")
@ -102,15 +96,11 @@ public class AdminController {
} }
@GetMapping("/topics") @GetMapping("/topics")
public GlobalResult<Map<String, Object>> topics(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){ public GlobalResult<PageInfo<Topic>> topics(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<Topic> list = topicService.findAll(); List<Topic> list = topicService.findAll();
PageInfo<Topic> pageInfo = new PageInfo<>(list); PageInfo<Topic> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<>(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("topics", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/topic/{topicUri}") @GetMapping("/topic/{topicUri}")
@ -138,17 +128,13 @@ public class AdminController {
} }
@GetMapping("/topic/unbind-topic-tags") @GetMapping("/topic/unbind-topic-tags")
public GlobalResult unbindTopicTags(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, HttpServletRequest request){ public GlobalResult<PageInfo<Tag>> unbindTopicTags(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, HttpServletRequest request){
Integer idTopic = Integer.valueOf(request.getParameter("idTopic")); Integer idTopic = Integer.valueOf(request.getParameter("idTopic"));
String tagTitle = request.getParameter("tagTitle"); String tagTitle = request.getParameter("tagTitle");
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<Tag> list = topicService.findUnbindTagsById(idTopic, tagTitle); List<Tag> list = topicService.findUnbindTagsById(idTopic, tagTitle);
PageInfo<Tag> pageInfo = new PageInfo<>(list); PageInfo<Tag> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<>(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("tags", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
@PostMapping("/topic/bind-topic-tag") @PostMapping("/topic/bind-topic-tag")
@ -176,19 +162,15 @@ public class AdminController {
} }
@GetMapping("/tags") @GetMapping("/tags")
public GlobalResult<Map<String, Object>> tags(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){ public GlobalResult<PageInfo<Tag>> tags(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<Tag> list = tagService.findAll(); List<Tag> list = tagService.findAll();
PageInfo<Tag> pageInfo = new PageInfo<>(list); PageInfo<Tag> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<>(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("tags", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
@DeleteMapping("/tag/clean-unused") @DeleteMapping("/tag/clean-unused")
public GlobalResult<Map<String, Object>> cleanUnusedTag(){ public GlobalResult cleanUnusedTag(){
Map map = tagService.cleanUnusedTag(); Map map = tagService.cleanUnusedTag();
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(map);
} }
@ -212,39 +194,35 @@ public class AdminController {
} }
@GetMapping("/special-days") @GetMapping("/special-days")
public GlobalResult<Map> specialDays(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) { public GlobalResult<PageInfo<SpecialDay>> specialDays(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<SpecialDay> list = specialDayService.findAll(); List<SpecialDay> list = specialDayService.findAll();
PageInfo<SpecialDay> pageInfo = new PageInfo<>(list); PageInfo<SpecialDay> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<>(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("specialDays", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/articles") @GetMapping("/articles")
public GlobalResult<Map> articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, ArticleSearchDTO articleSearchDTO) { public GlobalResult<PageInfo<ArticleDTO>> articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, ArticleSearchDTO articleSearchDTO) {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<ArticleDTO> list = articleService.findArticles(articleSearchDTO); List<ArticleDTO> list = articleService.findArticles(articleSearchDTO);
PageInfo<ArticleDTO> pageInfo = new PageInfo<>(list); PageInfo<ArticleDTO> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<>(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("articles", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/comments") @GetMapping("/comments")
public GlobalResult<Map> comments(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) { public GlobalResult<PageInfo<CommentDTO>> comments(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<CommentDTO> list = commentService.findComments(); List<CommentDTO> list = commentService.findComments();
PageInfo<CommentDTO> pageInfo = new PageInfo<>(list); PageInfo<CommentDTO> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<>(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("comments", pageInfo.getList()); }
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination); @GetMapping("/products")
return GlobalResultGenerator.genSuccessResult(map); public GlobalResult<PageInfo<ProductDTO>> products(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) {
PageHelper.startPage(page, rows);
List<ProductDTO> list = productService.findProducts();
PageInfo<ProductDTO> pageInfo = new PageInfo<>(list);
return GlobalResultGenerator.genSuccessResult(pageInfo);
} }

View File

@ -32,15 +32,11 @@ public class AdminCurrencyRuleController {
private CurrencyRuleService currencyRuleService; private CurrencyRuleService currencyRuleService;
@GetMapping("/list") @GetMapping("/list")
public GlobalResult list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "20") Integer rows, HttpServletRequest request) { public GlobalResult<PageInfo<TransactionRecordDTO>> list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "20") Integer rows, HttpServletRequest request) {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<CurrencyRule> list = currencyRuleService.findAll(); List<CurrencyRule> list = currencyRuleService.findAll();
Map map = new HashMap(2);
PageInfo<TransactionRecordDTO> pageInfo = new PageInfo(list); PageInfo<TransactionRecordDTO> pageInfo = new PageInfo(list);
map.put("rules", pageInfo.getList()); return GlobalResultGenerator.genSuccessResult(pageInfo);
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
} }

View File

@ -49,41 +49,26 @@ public class DashboardController {
} }
@GetMapping("/new-users") @GetMapping("/new-users")
public GlobalResult newUsers(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) { public GlobalResult<PageInfo<UserInfoDTO>> newUsers(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<UserInfoDTO> list = dashboardService.newUsers(); List<UserInfoDTO> list = dashboardService.newUsers();
PageInfo<UserInfoDTO> pageInfo = new PageInfo<>(list); PageInfo<UserInfoDTO> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<String, Object>(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("users", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/new-bank-accounts") @GetMapping("/new-bank-accounts")
public GlobalResult newBankAccounts(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) { public GlobalResult<PageInfo<BankAccountDTO>> newBankAccounts(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<BankAccountDTO> list = dashboardService.newBankAccounts(); List<BankAccountDTO> list = dashboardService.newBankAccounts();
PageInfo<BankAccountDTO> pageInfo = new PageInfo(list); PageInfo<BankAccountDTO> pageInfo = new PageInfo(list);
Map map = new HashMap(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("bankAccounts", pageInfo.getList());
Map pagination = new HashMap(4);
pagination.put("pageSize", pageInfo.getPageSize());
pagination.put("total", pageInfo.getTotal());
pagination.put("currentPage", pageInfo.getPageNum());
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/new-articles") @GetMapping("/new-articles")
public GlobalResult newArticles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) { public GlobalResult<PageInfo<ArticleDTO>> newArticles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<ArticleDTO> list = dashboardService.newArticles(); List<ArticleDTO> list = dashboardService.newArticles();
PageInfo<ArticleDTO> pageInfo = new PageInfo<>(list); PageInfo<ArticleDTO> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<>(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("articles", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
} }

View File

@ -28,39 +28,28 @@ public class BankAccountController {
private BankAccountService bankAccountService; private BankAccountService bankAccountService;
@GetMapping("/list") @GetMapping("/list")
public GlobalResult banks(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, BankAccountSearchDTO bankAccountSearchDTO) { public GlobalResult<PageInfo<BankAccountDTO>> banks(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, BankAccountSearchDTO bankAccountSearchDTO) {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<BankAccountDTO> list = bankAccountService.findBankAccounts(bankAccountSearchDTO); List<BankAccountDTO> list = bankAccountService.findBankAccounts(bankAccountSearchDTO);
PageInfo<BankAccountDTO> pageInfo = new PageInfo(list); PageInfo<BankAccountDTO> pageInfo = new PageInfo(list);
Map map = new HashMap(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("bankAccounts", pageInfo.getList());
Map pagination = new HashMap(4);
pagination.put("pageSize", pageInfo.getPageSize());
pagination.put("total", pageInfo.getTotal());
pagination.put("currentPage", pageInfo.getPageNum());
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/{idUser}") @GetMapping("/{idUser}")
public GlobalResult detail(@PathVariable Long idUser) { public GlobalResult<BankAccountDTO> detail(@PathVariable Long idUser) {
BankAccountDTO bankAccount = bankAccountService.findBankAccountByIdUser(idUser); BankAccountDTO bankAccount = bankAccountService.findBankAccountByIdUser(idUser);
return GlobalResultGenerator.genSuccessResult(bankAccount); return GlobalResultGenerator.genSuccessResult(bankAccount);
} }
@GetMapping("/transaction-records") @GetMapping("/transaction-records")
public GlobalResult transactionRecords(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "20") Integer rows, HttpServletRequest request) { public GlobalResult<PageInfo<TransactionRecordDTO>> transactionRecords(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "20") Integer rows, HttpServletRequest request) {
String bankAccount = request.getParameter("bankAccount"); String bankAccount = request.getParameter("bankAccount");
String startDate = request.getParameter("startDate"); String startDate = request.getParameter("startDate");
String endDate = request.getParameter("endDate"); String endDate = request.getParameter("endDate");
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<TransactionRecordDTO> list = bankAccountService.findUserTransactionRecords(bankAccount, startDate, endDate); List<TransactionRecordDTO> list = bankAccountService.findUserTransactionRecords(bankAccount, startDate, endDate);
PageInfo<TransactionRecordDTO> pageInfo = new PageInfo(list); PageInfo<TransactionRecordDTO> pageInfo = new PageInfo(list);
Map map = new HashMap(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("records", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
} }

View File

@ -30,15 +30,11 @@ public class BankController {
private BankService bankService; private BankService bankService;
@GetMapping("/list") @GetMapping("/list")
public GlobalResult banks(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) { public GlobalResult<PageInfo<BankDTO>> banks(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<BankDTO> list = bankService.findBanks(); List<BankDTO> list = bankService.findBanks();
PageInfo<BankDTO> pageInfo = new PageInfo(list); PageInfo<BankDTO> pageInfo = new PageInfo(list);
Map map = new HashMap(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("banks", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
} }

View File

@ -33,14 +33,14 @@ public class WalletController {
@GetMapping("/{idUser}") @GetMapping("/{idUser}")
@SecurityInterceptor @SecurityInterceptor
public GlobalResult detail(@PathVariable Long idUser) { public GlobalResult<BankAccountDTO> detail(@PathVariable Long idUser) {
BankAccountDTO bankAccount = bankAccountService.findBankAccountByIdUser(idUser); BankAccountDTO bankAccount = bankAccountService.findBankAccountByIdUser(idUser);
return GlobalResultGenerator.genSuccessResult(bankAccount); return GlobalResultGenerator.genSuccessResult(bankAccount);
} }
@GetMapping("/transaction-records") @GetMapping("/transaction-records")
@SecurityInterceptor @SecurityInterceptor
public GlobalResult transactionRecords(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "20") Integer rows, HttpServletRequest request) { public GlobalResult<PageInfo<TransactionRecordDTO>> transactionRecords(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "20") Integer rows, HttpServletRequest request) {
String idUser = request.getParameter("idUser"); String idUser = request.getParameter("idUser");
String startDate = request.getParameter("startDate"); String startDate = request.getParameter("startDate");
String endDate = request.getParameter("endDate"); String endDate = request.getParameter("endDate");
@ -48,10 +48,6 @@ public class WalletController {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<TransactionRecordDTO> list = bankAccountService.findUserTransactionRecords(bankAccount.getBankAccount(), startDate, endDate); List<TransactionRecordDTO> list = bankAccountService.findUserTransactionRecords(bankAccount.getBankAccount(), startDate, endDate);
PageInfo<TransactionRecordDTO> pageInfo = new PageInfo(list); PageInfo<TransactionRecordDTO> pageInfo = new PageInfo(list);
Map map = new HashMap(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("records", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
} }

View File

@ -87,21 +87,19 @@ public class CommonApiController {
@GetMapping("/articles") @GetMapping("/articles")
@VisitLogger @VisitLogger
public GlobalResult<Map> articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, ArticleSearchDTO searchDTO) { public GlobalResult<PageInfo<ArticleDTO>> articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, ArticleSearchDTO searchDTO) {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<ArticleDTO> list = articleService.findArticles(searchDTO); List<ArticleDTO> list = articleService.findArticles(searchDTO);
PageInfo<ArticleDTO> pageInfo = new PageInfo(list); PageInfo<ArticleDTO> pageInfo = new PageInfo(list);
Map map = Utils.getArticlesGlobalResult(pageInfo); return GlobalResultGenerator.genSuccessResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/announcements") @GetMapping("/announcements")
public GlobalResult<Map> announcements(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "5") Integer rows) { public GlobalResult<PageInfo<ArticleDTO>> announcements(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "5") Integer rows) {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<ArticleDTO> list = articleService.findAnnouncements(); List<ArticleDTO> list = articleService.findAnnouncements();
PageInfo<ArticleDTO> pageInfo = new PageInfo(list); PageInfo<ArticleDTO> pageInfo = new PageInfo(list);
Map map = Utils.getArticlesGlobalResult(pageInfo); return GlobalResultGenerator.genSuccessResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/article/{id}") @GetMapping("/article/{id}")
@ -127,36 +125,27 @@ public class CommonApiController {
} }
@GetMapping("/portfolio/{id}/articles") @GetMapping("/portfolio/{id}/articles")
public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @PathVariable Long id) { public GlobalResult<PageInfo<ArticleDTO>> articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @PathVariable Long id) {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<ArticleDTO> list = articleService.findArticlesByIdPortfolio(id); List<ArticleDTO> list = articleService.findArticlesByIdPortfolio(id);
PageInfo<ArticleDTO> pageInfo = new PageInfo(list); PageInfo<ArticleDTO> pageInfo = new PageInfo(list);
Map map = Utils.getArticlesGlobalResult(pageInfo); return GlobalResultGenerator.genSuccessResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/portfolios") @GetMapping("/portfolios")
public GlobalResult portfolios(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows) { public GlobalResult<PageInfo<PortfolioDTO>> portfolios(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows) {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<PortfolioDTO> list = portfolioService.findPortfolios(); List<PortfolioDTO> list = portfolioService.findPortfolios();
PageInfo<PortfolioDTO> pageInfo = new PageInfo(list); PageInfo<PortfolioDTO> pageInfo = new PageInfo(list);
Map map = new HashMap(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("portfolios", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/products") @GetMapping("/products")
public GlobalResult products(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows) { public GlobalResult<PageInfo<ProductDTO>> products(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows) {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<ProductDTO> list = productService.findProducts(); List<ProductDTO> list = productService.findProducts();
PageInfo<ProductDTO> pageInfo = new PageInfo(list); PageInfo<ProductDTO> pageInfo = new PageInfo(list);
Map map = new HashMap(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("products", pageInfo.getList());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/product/{id}") @GetMapping("/product/{id}")

View File

@ -31,7 +31,7 @@ public class NotificationController {
private NotificationService notificationService; private NotificationService notificationService;
@GetMapping("/all") @GetMapping("/all")
public GlobalResult notifications(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException { public GlobalResult<PageInfo<NotificationDTO>> notifications(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException {
User user = UserUtils.getCurrentUserByToken(); User user = UserUtils.getCurrentUserByToken();
if (Objects.isNull(user)) { if (Objects.isNull(user)) {
throw new BaseApiException(ErrorCode.TOKEN_); throw new BaseApiException(ErrorCode.TOKEN_);
@ -39,12 +39,11 @@ public class NotificationController {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<NotificationDTO> list = notificationService.findNotifications(user.getIdUser()); List<NotificationDTO> list = notificationService.findNotifications(user.getIdUser());
PageInfo<NotificationDTO> pageInfo = new PageInfo(list); PageInfo<NotificationDTO> pageInfo = new PageInfo(list);
Map map = Utils.getNotificationDTOsGlobalResult(pageInfo); return GlobalResultGenerator.genSuccessResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/unread") @GetMapping("/unread")
public GlobalResult unreadNotification(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException { public GlobalResult<PageInfo<Notification>> unreadNotification(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException {
User user = UserUtils.getCurrentUserByToken(); User user = UserUtils.getCurrentUserByToken();
if (Objects.isNull(user)) { if (Objects.isNull(user)) {
throw new BaseApiException(ErrorCode.TOKEN_); throw new BaseApiException(ErrorCode.TOKEN_);
@ -52,8 +51,7 @@ public class NotificationController {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<Notification> list = notificationService.findUnreadNotifications(user.getIdUser()); List<Notification> list = notificationService.findUnreadNotifications(user.getIdUser());
PageInfo<Notification> pageInfo = new PageInfo(list); PageInfo<Notification> pageInfo = new PageInfo(list);
Map map = Utils.getNotificationsGlobalResult(pageInfo); return GlobalResultGenerator.genSuccessResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);
} }
@PutMapping("/read/{id}") @PutMapping("/read/{id}")

View File

@ -28,12 +28,11 @@ public class TagController {
private TagService tagService; private TagService tagService;
@GetMapping("/{name}") @GetMapping("/{name}")
public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @PathVariable String name){ public GlobalResult<PageInfo<ArticleDTO>> articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @PathVariable String name){
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<ArticleDTO> list = articleService.findArticlesByTagName(name); List<ArticleDTO> list = articleService.findArticlesByTagName(name);
PageInfo<ArticleDTO> pageInfo = new PageInfo(list); PageInfo<ArticleDTO> pageInfo = new PageInfo(list);
Map map = Utils.getArticlesGlobalResult(pageInfo); return GlobalResultGenerator.genSuccessResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/tags") @GetMapping("/tags")

View File

@ -35,11 +35,10 @@ public class TopicController {
@GetMapping("/{name}") @GetMapping("/{name}")
@VisitLogger @VisitLogger
public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @PathVariable String name){ public GlobalResult<PageInfo<ArticleDTO>> articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @PathVariable String name){
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<ArticleDTO> list = articleService.findArticlesByTopicUri(name); List<ArticleDTO> list = articleService.findArticlesByTopicUri(name);
PageInfo<ArticleDTO> pageInfo = new PageInfo(list); PageInfo<ArticleDTO> pageInfo = new PageInfo(list);
Map map = Utils.getArticlesGlobalResult(pageInfo); return GlobalResultGenerator.genSuccessResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);
} }
} }

View File

@ -45,7 +45,7 @@ public class UserController {
} }
@GetMapping("/{account}/articles") @GetMapping("/{account}/articles")
public GlobalResult userArticles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String account){ public GlobalResult<PageInfo<ArticleDTO>> userArticles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String account){
UserDTO userDTO = userService.findUserDTOByAccount(account); UserDTO userDTO = userService.findUserDTOByAccount(account);
if (userDTO == null){ if (userDTO == null){
return GlobalResultGenerator.genErrorResult("用户不存在!"); return GlobalResultGenerator.genErrorResult("用户不存在!");
@ -53,12 +53,11 @@ public class UserController {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<ArticleDTO> list = articleService.findUserArticlesByIdUser(userDTO.getIdUser()); List<ArticleDTO> list = articleService.findUserArticlesByIdUser(userDTO.getIdUser());
PageInfo<ArticleDTO> pageInfo = new PageInfo(list); PageInfo<ArticleDTO> pageInfo = new PageInfo(list);
Map map = Utils.getArticlesGlobalResult(pageInfo); return GlobalResultGenerator.genSuccessResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/{account}/portfolios") @GetMapping("/{account}/portfolios")
public GlobalResult userPortfolios(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String account){ public GlobalResult<PageInfo<PortfolioDTO>> userPortfolios(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String account){
UserDTO userDTO = userService.findUserDTOByAccount(account); UserDTO userDTO = userService.findUserDTOByAccount(account);
if (userDTO == null){ if (userDTO == null){
return GlobalResultGenerator.genErrorResult("用户不存在!"); return GlobalResultGenerator.genErrorResult("用户不存在!");
@ -66,15 +65,11 @@ public class UserController {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<PortfolioDTO> list = portfolioService.findUserPortfoliosByUser(userDTO); List<PortfolioDTO> list = portfolioService.findUserPortfoliosByUser(userDTO);
PageInfo<PortfolioDTO> pageInfo = new PageInfo(list); PageInfo<PortfolioDTO> pageInfo = new PageInfo(list);
Map map = new HashMap(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("portfolios", list);
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/{account}/followers") @GetMapping("/{account}/followers")
public GlobalResult userFollowers(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String account){ public GlobalResult<PageInfo<UserDTO>> userFollowers(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String account){
UserDTO userDTO = userService.findUserDTOByAccount(account); UserDTO userDTO = userService.findUserDTOByAccount(account);
if (userDTO == null){ if (userDTO == null){
return GlobalResultGenerator.genErrorResult("用户不存在!"); return GlobalResultGenerator.genErrorResult("用户不存在!");
@ -82,15 +77,11 @@ public class UserController {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<UserDTO> list = followService.findUserFollowersByUser(userDTO); List<UserDTO> list = followService.findUserFollowersByUser(userDTO);
PageInfo<UserDTO> pageInfo = new PageInfo(list); PageInfo<UserDTO> pageInfo = new PageInfo(list);
Map map = new HashMap(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("users", list);
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/{account}/followings") @GetMapping("/{account}/followings")
public GlobalResult userFollowings(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String account){ public GlobalResult<PageInfo<UserDTO>> userFollowings(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String account){
UserDTO userDTO = userService.findUserDTOByAccount(account); UserDTO userDTO = userService.findUserDTOByAccount(account);
if (userDTO == null){ if (userDTO == null){
return GlobalResultGenerator.genErrorResult("用户不存在!"); return GlobalResultGenerator.genErrorResult("用户不存在!");
@ -98,15 +89,11 @@ public class UserController {
PageHelper.startPage(page, rows); PageHelper.startPage(page, rows);
List<UserDTO> list = followService.findUserFollowingsByUser(userDTO); List<UserDTO> list = followService.findUserFollowingsByUser(userDTO);
PageInfo<UserDTO> pageInfo = new PageInfo(list); PageInfo<UserDTO> pageInfo = new PageInfo(list);
Map map = new HashMap(2); return GlobalResultGenerator.genSuccessResult(pageInfo);
map.put("users", list);
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/{account}/user-extend") @GetMapping("/{account}/user-extend")
public GlobalResult userExtend(@PathVariable String account) { public GlobalResult<UserExtend> userExtend(@PathVariable String account) {
UserExtend userExtend = userService.selectUserExtendByAccount(account); UserExtend userExtend = userService.selectUserExtendByAccount(account);
return GlobalResultGenerator.genSuccessResult(userExtend); return GlobalResultGenerator.genSuccessResult(userExtend);
} }