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); }