From c2f33b7f1dd84bb085f08d47602cf57b28d43e08 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Fri, 29 Nov 2024 13:20:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=91=E7=9A=84=E5=9B=BE=E4=B9=A6=E6=8E=92?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bookAbroad/controller/HomeController.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/peanut/modules/bookAbroad/controller/HomeController.java b/src/main/java/com/peanut/modules/bookAbroad/controller/HomeController.java index b1037afc..af3b4c5f 100644 --- a/src/main/java/com/peanut/modules/bookAbroad/controller/HomeController.java +++ b/src/main/java/com/peanut/modules/bookAbroad/controller/HomeController.java @@ -3,6 +3,7 @@ package com.peanut.modules.bookAbroad.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.yulichang.wrapper.MPJLambdaWrapper; +import com.peanut.common.utils.DateUtil; import com.peanut.common.utils.R; import com.peanut.common.utils.ShiroUtils; import com.peanut.modules.book.service.*; @@ -10,6 +11,7 @@ import com.peanut.modules.common.entity.*; import com.peanut.modules.master.service.BookAbroadToLableService; import com.peanut.modules.bookAbroad.service.BookAbroadLableService; import lombok.extern.slf4j.Slf4j; +import org.apache.http.client.utils.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -44,15 +46,23 @@ public class HomeController { @RequestMapping("/getMyBooks") public R getMyBooks(@RequestBody Map params){ MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); - wrapper.leftJoin(BookReadRateEntity.class,BookReadRateEntity::getBookId,UserEbookBuyEntity::getBookId); wrapper.leftJoin(BookEntity.class,BookEntity::getId,UserEbookBuyEntity::getBookId); wrapper.eq(UserEbookBuyEntity::getUserId,ShiroUtils.getUId()); wrapper.select(BookEntity::getId,BookEntity::getName,BookEntity::getImages); - wrapper.select(BookReadRateEntity::getPrecent); - wrapper.orderByDesc(BookReadRateEntity::getUpdateTime); wrapper.groupBy(UserEbookBuyEntity::getBookId); Page p = userEbookBuyService.pageMaps(new Page<>( Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),wrapper); + List> list = p.getRecords(); + for (Map map:list) { + BookReadRateEntity brr = bookReadRateService.getOne(new LambdaQueryWrapper() + .eq(BookReadRateEntity::getUserId, ShiroUtils.getUId()) + .eq(BookReadRateEntity::getBookId,map.get("id"))); + map.put("precent",brr==null?"0":brr.getPrecent()==null?"0":brr.getPrecent()); + map.put("sort",brr==null?0:brr.getUpdateTime()==null?0:brr.getUpdateTime().getTime()); + } + list.stream().sorted((map1,map2)->{ + return Long.compare((Long) map2.get("sort"),(Long) map2.get("sort")); + }).collect(Collectors.toList()); return R.ok().put("page",p); }