修改TBook各个层
This commit is contained in:
parent
24a9aca4cf
commit
f8814cd44c
|
@ -38,13 +38,18 @@ public class AuthenticationTokenFilter extends OncePerRequestFilter {
|
|||
return;
|
||||
}
|
||||
|
||||
//token 1 admin 2 user
|
||||
//object
|
||||
//ObjectMapper obejct admin.class user.class
|
||||
// 获取登录用户信息
|
||||
//从redis中获取信息
|
||||
UserDetail user = tokenStoreCache.getUser(accessToken);
|
||||
if (user == null) {
|
||||
chain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
|
||||
//存入SecurityContextHolder
|
||||
// 获取用户权限信息封装到Authentication中
|
||||
// 用户存在
|
||||
Authentication authentication = new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities());
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ auth:
|
|||
- /swagger-ui.html
|
||||
- /swagger-ui/**
|
||||
- /doc.html
|
||||
- /maku/t_book_comment/**
|
||||
- /maku/t_user/**
|
||||
- /maku/t_book/list/search
|
||||
- /maku/t_book/{id}
|
||||
|
|
|
@ -39,6 +39,30 @@ public class TBookCommentController {
|
|||
private final TBookCommentService tBookCommentService;
|
||||
private final RedisCache redisCache;
|
||||
|
||||
@PostMapping("/manout")
|
||||
@Operation(summary = "评论")
|
||||
public Result setbookcomment(HttpServletRequest request, @RequestParam Integer bookId,@RequestParam String comment) {
|
||||
// 首先验证token的有效性,然后从Redis中获取用户信息
|
||||
String token = request.getHeader("token");
|
||||
if(token==null || token.isEmpty()){
|
||||
return Result.error("token is error");
|
||||
}
|
||||
|
||||
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());
|
||||
tBookCommentService.save(userId,bookId,comment,date);
|
||||
return Result.ok("评论成功");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
|
|
|
@ -60,8 +60,8 @@ public class TBookController {
|
|||
@GetMapping("/list/search")
|
||||
@Operation(summary = "根据书名查询书籍")
|
||||
@Parameter
|
||||
public Result<TBookEntity> getByName(@RequestParam String name){
|
||||
TBookEntity entity = tBookService.getByName(name);
|
||||
public Result<List<TBookEntity>> getByName(@RequestParam String name){
|
||||
List<TBookEntity> entity = tBookService.getByName(name);
|
||||
return Result.ok(entity);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import net.maku.maku.vo.TBookCommentVO;
|
|||
import net.maku.maku.query.TBookCommentQuery;
|
||||
import net.maku.maku.entity.TBookCommentEntity;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -23,4 +24,6 @@ public interface TBookCommentService extends BaseService<TBookCommentEntity> {
|
|||
void update(TBookCommentVO vo);
|
||||
|
||||
void delete(List<Long> idList);
|
||||
|
||||
void save(Integer userId, Integer bookId, String comment, Date date);
|
||||
}
|
|
@ -24,5 +24,7 @@ public interface TBookService extends BaseService<TBookEntity> {
|
|||
|
||||
void delete(List<Long> idList);
|
||||
|
||||
TBookEntity getByName(String bookName);
|
||||
|
||||
List<TBookEntity> getByName(String name);
|
||||
|
||||
}
|
|
@ -16,6 +16,7 @@ import net.maku.maku.service.TBookCommentService;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -64,4 +65,14 @@ public class TBookCommentServiceImpl extends BaseServiceImpl<TBookCommentDao, TB
|
|||
removeByIds(idList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Integer userId, Integer bookId, String comment, Date date) {
|
||||
TBookCommentEntity entity = new TBookCommentEntity();
|
||||
entity.setUserId(userId);
|
||||
entity.setBookId(bookId);
|
||||
entity.setComment(comment);
|
||||
entity.setCreateTime(date);
|
||||
baseMapper.insert(entity);
|
||||
}
|
||||
|
||||
}
|
|
@ -9,7 +9,6 @@ import net.maku.framework.common.exception.ServerException;
|
|||
import net.maku.framework.common.utils.PageResult;
|
||||
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
|
||||
import net.maku.maku.convert.TBookConvert;
|
||||
import net.maku.maku.entity.TBookCommentEntity;
|
||||
import net.maku.maku.entity.TBookEntity;
|
||||
import net.maku.maku.query.TBookQuery;
|
||||
import net.maku.maku.vo.TBookVO;
|
||||
|
@ -66,14 +65,13 @@ public class TBookServiceImpl extends BaseServiceImpl<TBookDao, TBookEntity> imp
|
|||
}
|
||||
|
||||
@Override
|
||||
public TBookEntity getByName(String bookName) {
|
||||
public List<TBookEntity> getByName(String bookName) {
|
||||
LambdaQueryWrapper<TBookEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(TBookEntity::getBookName, bookName);
|
||||
TBookEntity tBookEntity = baseMapper.selectOne(wrapper);
|
||||
List<TBookEntity> tBookEntity = baseMapper.selectList(wrapper);
|
||||
if (ObjectUtil.isNull(tBookEntity)){
|
||||
throw new ServerException("没有找到书籍");
|
||||
}
|
||||
tBookEntity.setBookCover("obhhi");
|
||||
return tBookEntity;
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ spring:
|
|||
redis:
|
||||
database: 0
|
||||
host: localhost
|
||||
port: 6379
|
||||
#timeout: 6000ms # 连接超时时长(毫秒)
|
||||
datasource:
|
||||
dynamic:
|
||||
|
|
Loading…
Reference in New Issue
Block a user