我的图书排序
This commit is contained in:
@@ -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<String,Object> params){
|
||||
MPJLambdaWrapper<UserEbookBuyEntity> 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<Map<String,Object>> list = p.getRecords();
|
||||
for (Map<String,Object> map:list) {
|
||||
BookReadRateEntity brr = bookReadRateService.getOne(new LambdaQueryWrapper<BookReadRateEntity>()
|
||||
.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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user