parent
45512694b6
commit
102c9c4a38
|
@ -0,0 +1,12 @@
|
|||
package com.guwan.backend;
|
||||
|
||||
import com.guwan.backend.entity.BookOfUser;
|
||||
import com.guwan.backend.enums.ReadStatus;
|
||||
|
||||
public class Demo {
|
||||
public static void main(String[] args) {
|
||||
BookOfUser bookOfUser = new BookOfUser();
|
||||
bookOfUser.setReadStatus(ReadStatus.yes);
|
||||
System.out.println("bookOfUser = " + bookOfUser);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@ package com.guwan.backend.controller;
|
|||
|
||||
import com.guwan.backend.common.Result;
|
||||
import com.guwan.backend.entity.BookContent;
|
||||
import com.guwan.backend.mongodb.EveryReadDetailOfMongodb;
|
||||
import com.guwan.backend.mongodb.EveryReadDetailOfMongodbService;
|
||||
import com.guwan.backend.mongodb.User;
|
||||
import com.guwan.backend.mongodb.MongodbUserService;
|
||||
import com.guwan.backend.service.BookContentService;
|
||||
|
@ -15,6 +17,7 @@ import org.springframework.http.ResponseEntity;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.ws.rs.POST;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -36,6 +39,8 @@ public class CommonController {
|
|||
|
||||
private final MongodbUserService mongodbUserService;
|
||||
|
||||
private final EveryReadDetailOfMongodbService everyReadDetailOfMongodbService;
|
||||
|
||||
@PostMapping("/uploadFile")
|
||||
public Result<String> uploadFile(String bucketName, MultipartFile file){
|
||||
return Result.success(minioUtil.getUrl(minioUtil.getFileUrl
|
||||
|
@ -223,5 +228,27 @@ public class CommonController {
|
|||
}
|
||||
|
||||
|
||||
@PostMapping("/everyRead")
|
||||
public Result everyRead(@RequestBody EveryReadDetailOfMongodb everyReadDetailOfMongodb){
|
||||
|
||||
|
||||
everyReadDetailOfMongodbService.save(everyReadDetailOfMongodb);
|
||||
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@GetMapping("/getUserOneTotalTime")
|
||||
public Result getUserOneTotalTime(@RequestParam Long userId){
|
||||
|
||||
|
||||
//return Result.success();
|
||||
|
||||
// everyReadDetailOfMongodbService.getUserOneTotalTime(userId);
|
||||
|
||||
return Result.success(everyReadDetailOfMongodbService.getUserOneTotalTime(userId));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,33 @@
|
|||
package com.guwan.backend.entity;
|
||||
|
||||
import com.guwan.backend.enums.Evaluate;
|
||||
import com.guwan.backend.enums.ReadStatus;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BookOfUser {
|
||||
|
||||
private Long UserId;
|
||||
|
||||
private Long bookId;
|
||||
/**
|
||||
* 对该书的直观评价(好看 一般 不好看)
|
||||
*/
|
||||
private Evaluate evaluate;
|
||||
|
||||
private String evaluate;
|
||||
/**
|
||||
* 阅读状态
|
||||
*/
|
||||
private ReadStatus readStatus;
|
||||
|
||||
/**
|
||||
* 评语
|
||||
*/
|
||||
private String comment;
|
||||
|
||||
/**
|
||||
* 累计阅读时间
|
||||
*/
|
||||
private Long cumulativeReadingTime;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package com.guwan.backend.enums;
|
||||
|
||||
public enum Evaluate {
|
||||
yes("好看", 1), normal("一般", 2), no("不行", 3);
|
||||
// 成员变量
|
||||
private String name;
|
||||
private int index;
|
||||
// 构造方法
|
||||
private Evaluate(String name, int index) {
|
||||
this.name = name;
|
||||
this.index = index;
|
||||
}
|
||||
// 普通方法
|
||||
public static String getName(int index) {
|
||||
for (Evaluate c : Evaluate.values()) {
|
||||
if (c.getIndex() == index) {
|
||||
return c.name;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// get set 方法
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.guwan.backend.enums;
|
||||
|
||||
public enum ReadStatus {
|
||||
yes("在读", 1), normal("未读", 2), no("想读", 3);
|
||||
// 成员变量
|
||||
private String name;
|
||||
private int index;
|
||||
// 构造方法
|
||||
private ReadStatus(String name, int index) {
|
||||
this.name = name;
|
||||
this.index = index;
|
||||
}
|
||||
// 普通方法
|
||||
public static String getName(int index) {
|
||||
for (ReadStatus c : ReadStatus.values()) {
|
||||
if (c.getIndex() == index) {
|
||||
return c.name;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// get set 方法
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,17 @@
|
|||
package com.guwan.backend.mongodb;
|
||||
|
||||
import com.mongoplus.annotation.ID;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class EveryReadDetailOfMongodb {
|
||||
|
||||
private Long UserId;
|
||||
@ID //使用ID注解,标注此字段为MongoDB的_id,或者继承BaseModelID类
|
||||
private String id;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private Long bookId;
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package com.guwan.backend.mongodb;
|
||||
|
||||
import com.mongoplus.service.IService;
|
||||
|
||||
public interface EveryReadDetailOfMongodbService extends IService<EveryReadDetailOfMongodb> {
|
||||
|
||||
Long getUserOneTotalTime(Long userId);
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.guwan.backend.mongodb;
|
||||
|
||||
import com.mongoplus.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.mongoplus.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class EveryReadDetailOfMongodbServiceImpl extends ServiceImpl<EveryReadDetailOfMongodb> implements EveryReadDetailOfMongodbService {
|
||||
|
||||
@Override
|
||||
public Long getUserOneTotalTime(Long userId) {
|
||||
List<EveryReadDetailOfMongodb> list = this.list(new LambdaQueryChainWrapper<>(this.getBaseMapper(), EveryReadDetailOfMongodb.class)
|
||||
.eq(EveryReadDetailOfMongodb::getUserId, userId));
|
||||
|
||||
log.debug("list: {}", list);
|
||||
|
||||
Long total = 0L;
|
||||
for (EveryReadDetailOfMongodb everyReadDetailOfMongodb : list) {
|
||||
LocalDateTime startTime = everyReadDetailOfMongodb.getStartTime();
|
||||
LocalDateTime endTime = everyReadDetailOfMongodb.getEndTime();
|
||||
Duration duration = Duration.between(startTime, endTime);
|
||||
total += duration.getSeconds();
|
||||
}
|
||||
|
||||
return total;
|
||||
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||
import com.guwan.backend.entity.Book;
|
||||
import com.guwan.backend.mapper.BookMapper;
|
||||
import com.guwan.backend.service.BookService;
|
||||
import com.mongoplus.conditions.query.LambdaQueryChainWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -21,6 +22,12 @@ public class BookServiceImpl implements BookService {
|
|||
@Override
|
||||
@Transactional
|
||||
public Book addBook(Book book) {
|
||||
|
||||
|
||||
// new LambdaQueryWrapper<>()
|
||||
|
||||
// new LambdaQueryChainWrapper<>()
|
||||
|
||||
bookMapper.insert(book);
|
||||
return book;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue