Compare commits
2 Commits
65a6d47e61
...
b250a8a8d3
Author | SHA1 | Date | |
---|---|---|---|
|
b250a8a8d3 | ||
|
a565e10dd2 |
|
@ -17,5 +17,6 @@ auth:
|
|||
- /maku/t_shopping_trolley/aaa
|
||||
- /maku/t_book_collection/**
|
||||
- /maku/t_shopping_trolley/**
|
||||
- /maku/t_collection/**
|
||||
|
||||
|
||||
|
|
|
@ -51,15 +51,10 @@ public class TBookCollectionController {
|
|||
if(ObjectUtils.isNull(entity)){
|
||||
throw new ServerException(ErrorCode.REFRESH_TOKEN_INVALID);
|
||||
}
|
||||
|
||||
|
||||
TUserEntity tUserEntity = (TUserEntity) redisCache.get(token);
|
||||
Integer userId=tUserEntity.getId();
|
||||
LocalDateTime currentTime = LocalDateTime.now();
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
|
||||
//DATE没有时区二localDateTime有时区,为了将 LocalDateTime 转换为 Date,你需要指定一个时区,因为 Date 是基于UTC的
|
||||
// 将LocalDateTime转换为ZonedDateTime,然后转换为Instant,最后转换为Date
|
||||
ZonedDateTime zdt = currentTime.atZone(zoneId);
|
||||
Date date = Date.from(zdt.toInstant());
|
||||
|
||||
|
@ -71,10 +66,8 @@ public class TBookCollectionController {
|
|||
@PreAuthorize("hasAuthority('maku:t_book_collection:page')")
|
||||
public Result<PageResult<TBookCollectionVO>> page(@ParameterObject @Valid TBookCollectionQuery query){
|
||||
PageResult<TBookCollectionVO> page = tBookCollectionService.page(query);
|
||||
|
||||
return Result.ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
@PreAuthorize("hasAuthority('maku:t_book_collection:info')")
|
||||
|
@ -110,4 +103,48 @@ public class TBookCollectionController {
|
|||
|
||||
return Result.ok();
|
||||
}
|
||||
@PostMapping("/collection")
|
||||
@Operation(summary = "收藏图书")
|
||||
public Result<String> setbookcollection(HttpServletRequest request, @RequestParam Integer bookId) {
|
||||
String token = request.getHeader("token");
|
||||
TUserEntity entity = (TUserEntity) redisCache.get(token);
|
||||
if (ObjectUtils.isNull(entity)) {
|
||||
throw new ServerException(ErrorCode.REFRESH_TOKEN_INVALID);
|
||||
}
|
||||
|
||||
Integer userId = entity.getId(); // 直接使用已经获取的用户信息
|
||||
|
||||
// Check if the book has already been collected by the user
|
||||
boolean isBookAlreadyCollected = tBookCollectionService.isBookAlreadyCollected(userId, bookId);
|
||||
if (isBookAlreadyCollected) {
|
||||
return Result.error("该书已经收藏过,不能重复收藏");
|
||||
}
|
||||
|
||||
// If not already collected, proceed with saving the collection record
|
||||
LocalDateTime currentTime = LocalDateTime.now();
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
ZonedDateTime zdt = currentTime.atZone(zoneId);
|
||||
Date date = Date.from(zdt.toInstant());
|
||||
|
||||
tBookCollectionService.save(userId, bookId, date);
|
||||
|
||||
return Result.ok("收藏图书成功");
|
||||
}
|
||||
|
||||
@GetMapping("/status")
|
||||
@Operation(summary = "收藏状态")
|
||||
public Result<String> status(HttpServletRequest request,@RequestParam Integer bookId){
|
||||
String token = request.getHeader("token");
|
||||
TUserEntity user = (TUserEntity) redisCache.get(token);
|
||||
if(ObjectUtils.isNull(user)){
|
||||
throw new ServerException(ErrorCode.REFRESH_TOKEN_INVALID);
|
||||
}
|
||||
Integer userId=user.getId();
|
||||
TBookCollectionEntity entity1 = tBookCollectionService.getByBookIdandUserId(bookId,userId);
|
||||
if(entity1 !=null&&entity1.getStatus() !=null&&entity1.getStatus()==1){
|
||||
return Result.ok("已收藏");
|
||||
}else {
|
||||
return Result.ok("未收藏");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -112,4 +112,11 @@ public class TBookCommentController {
|
|||
|
||||
return Result.ok();
|
||||
}
|
||||
@GetMapping("/list/{bookId}")
|
||||
@Operation(summary = "查看评论列表")
|
||||
public Result<List<TBookCommentEntity>> list(@PathVariable Integer bookId){
|
||||
|
||||
return Result.ok(tBookCommentService.getByBookId(bookId));
|
||||
}
|
||||
|
||||
}
|
|
@ -47,8 +47,6 @@ public class TBookController {
|
|||
private final RedisCache redisCache;
|
||||
private final TBookCollectionService tBookCollectionService;
|
||||
|
||||
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "列表")
|
||||
public Result<List<TBookEntity>> list() {
|
||||
|
@ -71,26 +69,7 @@ public class TBookController {
|
|||
return Result.ok(entity);
|
||||
}
|
||||
|
||||
@PostMapping("/collection")
|
||||
@Operation(summary = "收藏图书")
|
||||
public Result<String> setbookcollection(HttpServletRequest request, @RequestParam Integer bookId) {
|
||||
// 首先验证token的有效性,然后从Redis中获取用户信息
|
||||
String token = request.getHeader("token");
|
||||
TUserEntity entity = (TUserEntity) redisCache.get(token);
|
||||
if(ObjectUtils.isNull(entity)){
|
||||
throw new ServerException(ErrorCode.REFRESH_TOKEN_INVALID);
|
||||
}
|
||||
TUserEntity tUserEntity = (TUserEntity) redisCache.get(token);
|
||||
Integer userId=tUserEntity.getId();
|
||||
LocalDateTime currentTime = LocalDateTime.now();
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
//DATE没有时区二localDateTime有时区,为了将 LocalDateTime 转换为 Date,你需要指定一个时区,因为 Date 是基于UTC的
|
||||
// 将LocalDateTime转换为ZonedDateTime,然后转换为Instant,最后转换为Date
|
||||
ZonedDateTime zdt = currentTime.atZone(zoneId);
|
||||
Date date = Date.from(zdt.toInstant());
|
||||
tBookCollectionService.save(userId,bookId,date);
|
||||
return Result.ok("收藏图书成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -80,7 +80,6 @@ public class TShoppingTrolleyController {
|
|||
}
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
// @PreAuthorize("hasAuthority('maku:t_shopping_trolley:info')")
|
||||
public Result<TShoppingTrolleyVO> get(@PathVariable("id") Long id){
|
||||
TShoppingTrolleyEntity entity = tShoppingTrolleyService.getById(id);
|
||||
|
||||
|
|
|
@ -25,4 +25,6 @@ public class TBookCollectionEntity {
|
|||
|
||||
private Date updateTime;
|
||||
|
||||
private Integer status;
|
||||
|
||||
}
|
|
@ -26,4 +26,8 @@ public interface TBookCollectionService extends BaseService<TBookCollectionEntit
|
|||
void delete(List<Long> idList);
|
||||
|
||||
void save(Integer userId, Integer bookId, Date currentTime);
|
||||
|
||||
TBookCollectionEntity getByBookIdandUserId(Integer bookId, Integer userId);
|
||||
|
||||
boolean isBookAlreadyCollected(Integer userId, Integer bookId);
|
||||
}
|
|
@ -26,4 +26,6 @@ public interface TBookCommentService extends BaseService<TBookCommentEntity> {
|
|||
void delete(List<Long> idList);
|
||||
|
||||
void save(Integer userId, Integer bookId, String comment, Date date);
|
||||
|
||||
List<TBookCommentEntity> getByBookId(Integer bookId);
|
||||
}
|
|
@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import net.maku.framework.common.utils.PageResult;
|
||||
import net.maku.framework.common.utils.Result;
|
||||
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
|
||||
import net.maku.maku.convert.TBookCollectionConvert;
|
||||
import net.maku.maku.entity.TBookCollectionEntity;
|
||||
|
@ -72,15 +73,23 @@ public class TBookCollectionServiceImpl extends BaseServiceImpl<TBookCollectionD
|
|||
entity.setUserId(userId);
|
||||
entity.setBookId(bookId);
|
||||
entity.setCreateTime(currentTime);
|
||||
// 可以根据需要设置其它字段,例如自增id字段和lastModifiedTime字段(如果需要)
|
||||
|
||||
// 假设lastModifiedTime可以为空,可以根据需要设置
|
||||
|
||||
|
||||
// 使用 MyBatis Plus 的 save 方法保存实体
|
||||
this.save(entity);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TBookCollectionEntity getByBookIdandUserId(Integer bookId, Integer userId) {
|
||||
LambdaQueryWrapper<TBookCollectionEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(TBookCollectionEntity::getBookId, bookId);
|
||||
wrapper.eq(TBookCollectionEntity::getUserId, userId);
|
||||
|
||||
}
|
||||
return baseMapper.selectOne(wrapper);
|
||||
}
|
||||
@Override
|
||||
public boolean isBookAlreadyCollected(Integer userId, Integer bookId) {
|
||||
LambdaQueryWrapper<TBookCollectionEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(TBookCollectionEntity::getBookId, bookId);
|
||||
wrapper.eq(TBookCollectionEntity::getUserId, userId);
|
||||
return baseMapper.selectCount(wrapper) > 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,4 +75,11 @@ public class TBookCommentServiceImpl extends BaseServiceImpl<TBookCommentDao, TB
|
|||
baseMapper.insert(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TBookCommentEntity> getByBookId(Integer bookId) {
|
||||
LambdaQueryWrapper<TBookCommentEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(TBookCommentEntity::getBookId, bookId);
|
||||
return baseMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
}
|
|
@ -37,10 +37,10 @@ public class TShoppingTrolleyServiceImpl extends BaseServiceImpl<TShoppingTrolle
|
|||
return new PageResult<>(TShoppingTrolleyConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<TShoppingTrolleyEntity> getWrapper(TShoppingTrolleyQuery query){
|
||||
private LambdaQueryWrapper<TShoppingTrolleyEntity> getWrapper(TShoppingTrolleyQuery query) {
|
||||
LambdaQueryWrapper<TShoppingTrolleyEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(ObjectUtils.isNotNull(query.getUserId()), TShoppingTrolleyEntity::getUserId,query.getUserId());
|
||||
wrapper.eq(ObjectUtils.isNotNull(query.getBookId()),TShoppingTrolleyEntity::getBookId, query.getBookId());
|
||||
wrapper.eq(ObjectUtils.isNotNull(query.getUserId()), TShoppingTrolleyEntity::getUserId, query.getUserId());
|
||||
wrapper.eq(ObjectUtils.isNotNull(query.getBookId()), TShoppingTrolleyEntity::getBookId, query.getBookId());
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
@ -100,5 +100,9 @@ public class TShoppingTrolleyServiceImpl extends BaseServiceImpl<TShoppingTrolle
|
|||
return newEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -22,6 +22,8 @@ public class TBookCollectionVO implements Serializable {
|
|||
|
||||
private Integer userId;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private Integer bookId;
|
||||
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
|
|
Loading…
Reference in New Issue
Block a user