Merge remote-tracking branch 'origin/zcc'

This commit is contained in:
wangjinlei
2023-11-27 11:35:29 +08:00
6 changed files with 78 additions and 16 deletions

View File

@@ -1,11 +1,19 @@
package com.peanut.modules.book.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.Query;
import com.peanut.common.utils.R;
import com.peanut.modules.book.entity.BookEntity;
import com.peanut.modules.book.entity.BookMedicalRecordsEntity;
import com.peanut.modules.book.entity.UserEbookBuyEntity;
import com.peanut.modules.book.service.BookMedicalRecordsService;
import com.peanut.modules.book.service.BookService;
import com.peanut.modules.book.service.UserEbookBuyService;
import com.peanut.modules.book.vo.UserOrderVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
@@ -22,12 +30,46 @@ public class BookMedicalRecordsController {
@Autowired
private BookMedicalRecordsService bookMedicalRecordsService;
@Autowired
private BookService bookService;
@Autowired
private UserEbookBuyService userEbookBuyService;
/**
* 已购图书列表
*/
@RequestMapping("/userEbookBuyList")
public R userEbookBuyList(@RequestBody Map<String, Object> params){
MPJLambdaWrapper<BookEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.selectAll(BookEntity.class);
wrapper.leftJoin(UserEbookBuyEntity.class, UserEbookBuyEntity::getBookId,BookEntity::getId);
wrapper.leftJoin(BookMedicalRecordsEntity.class,BookMedicalRecordsEntity::getBookId,BookEntity::getId);
wrapper.eq(BookMedicalRecordsEntity::getDelFlag,0);
wrapper.eq(BookEntity::getDelFlag,0);
wrapper.eq(BookEntity::getState,1);
wrapper.eq(UserEbookBuyEntity::getUserId,params.get("userId"));
wrapper.groupBy(BookMedicalRecordsEntity::getBookId);
IPage<BookEntity> page = bookService.page(
new Query<BookEntity>().getPage(params),wrapper);
return R.ok().put("page", page);
}
/**
* 推荐图书列表
*/
@RequestMapping("/recommendBookList")
public R recommendBookList(@RequestBody Map<String, Object> params){
List<BookEntity> list = bookMedicalRecordsService.getBooks(params);
Page<BookEntity> page = new Page<>();
page.setRecords(list);
page.setTotal(list.size());
page.setPages((int)Math.ceil(list.size()/page.getSize()));
return R.ok().put("page", page);
}
/**
* 列表
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params){
public R list(@RequestBody Map<String, Object> params){
IPage<BookMedicalRecordsEntity> page = bookMedicalRecordsService.page(
new Query<BookMedicalRecordsEntity>().getPage(params),
new QueryWrapper<BookMedicalRecordsEntity>()
@@ -64,12 +106,6 @@ public class BookMedicalRecordsController {
@RequestMapping("/saveOrUpdate")
public R save(@RequestBody BookMedicalRecordsEntity entity){
try {
if (entity.getSort()==null){
entity.setSort(1);
}
if (entity.getDelFlag()==null){
entity.setDelFlag(0);
}
bookMedicalRecordsService.saveOrUpdate(entity);
return R.ok();
}catch (Exception e) {
@@ -82,11 +118,7 @@ public class BookMedicalRecordsController {
@RequestMapping("/del")
public R del(Integer medicalRecordsId){
try {
BookMedicalRecordsEntity entity = bookMedicalRecordsService.getOne(
new QueryWrapper<BookMedicalRecordsEntity>()
.eq("medical_records_id", medicalRecordsId));
entity.setDelFlag(1);
bookMedicalRecordsService.updateById(entity);
bookMedicalRecordsService.removeById(medicalRecordsId);
return R.ok();
}catch (Exception e) {
return R.error("删除失败:"+e.getMessage());