修改TBook各个层

This commit is contained in:
hxf13 2024-07-22 15:42:29 +08:00
parent 24a9aca4cf
commit f8814cd44c
9 changed files with 52 additions and 9 deletions

View File

@ -38,13 +38,18 @@ public class AuthenticationTokenFilter extends OncePerRequestFilter {
return; return;
} }
//token 1 admin 2 user
//object
//ObjectMapper obejct admin.class user.class
// 获取登录用户信息 // 获取登录用户信息
//从redis中获取信息
UserDetail user = tokenStoreCache.getUser(accessToken); UserDetail user = tokenStoreCache.getUser(accessToken);
if (user == null) { if (user == null) {
chain.doFilter(request, response); chain.doFilter(request, response);
return; return;
} }
//存入SecurityContextHolder
// 获取用户权限信息封装到Authentication中
// 用户存在 // 用户存在
Authentication authentication = new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities()); Authentication authentication = new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities());

View File

@ -8,6 +8,7 @@ auth:
- /swagger-ui.html - /swagger-ui.html
- /swagger-ui/** - /swagger-ui/**
- /doc.html - /doc.html
- /maku/t_book_comment/**
- /maku/t_user/** - /maku/t_user/**
- /maku/t_book/list/search - /maku/t_book/list/search
- /maku/t_book/{id} - /maku/t_book/{id}

View File

@ -39,6 +39,30 @@ public class TBookCommentController {
private final TBookCommentService tBookCommentService; private final TBookCommentService tBookCommentService;
private final RedisCache redisCache; 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") @GetMapping("page")
@Operation(summary = "分页") @Operation(summary = "分页")

View File

@ -60,8 +60,8 @@ public class TBookController {
@GetMapping("/list/search") @GetMapping("/list/search")
@Operation(summary = "根据书名查询书籍") @Operation(summary = "根据书名查询书籍")
@Parameter @Parameter
public Result<TBookEntity> getByName(@RequestParam String name){ public Result<List<TBookEntity>> getByName(@RequestParam String name){
TBookEntity entity = tBookService.getByName(name); List<TBookEntity> entity = tBookService.getByName(name);
return Result.ok(entity); return Result.ok(entity);
} }

View File

@ -6,6 +6,7 @@ import net.maku.maku.vo.TBookCommentVO;
import net.maku.maku.query.TBookCommentQuery; import net.maku.maku.query.TBookCommentQuery;
import net.maku.maku.entity.TBookCommentEntity; import net.maku.maku.entity.TBookCommentEntity;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@ -23,4 +24,6 @@ public interface TBookCommentService extends BaseService<TBookCommentEntity> {
void update(TBookCommentVO vo); void update(TBookCommentVO vo);
void delete(List<Long> idList); void delete(List<Long> idList);
void save(Integer userId, Integer bookId, String comment, Date date);
} }

View File

@ -24,5 +24,7 @@ public interface TBookService extends BaseService<TBookEntity> {
void delete(List<Long> idList); void delete(List<Long> idList);
TBookEntity getByName(String bookName);
List<TBookEntity> getByName(String name);
} }

View File

@ -16,6 +16,7 @@ import net.maku.maku.service.TBookCommentService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@ -64,4 +65,14 @@ public class TBookCommentServiceImpl extends BaseServiceImpl<TBookCommentDao, TB
removeByIds(idList); 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);
}
} }

View File

@ -9,7 +9,6 @@ import net.maku.framework.common.exception.ServerException;
import net.maku.framework.common.utils.PageResult; import net.maku.framework.common.utils.PageResult;
import net.maku.framework.mybatis.service.impl.BaseServiceImpl; import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
import net.maku.maku.convert.TBookConvert; import net.maku.maku.convert.TBookConvert;
import net.maku.maku.entity.TBookCommentEntity;
import net.maku.maku.entity.TBookEntity; import net.maku.maku.entity.TBookEntity;
import net.maku.maku.query.TBookQuery; import net.maku.maku.query.TBookQuery;
import net.maku.maku.vo.TBookVO; import net.maku.maku.vo.TBookVO;
@ -66,14 +65,13 @@ public class TBookServiceImpl extends BaseServiceImpl<TBookDao, TBookEntity> imp
} }
@Override @Override
public TBookEntity getByName(String bookName) { public List<TBookEntity> getByName(String bookName) {
LambdaQueryWrapper<TBookEntity> wrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<TBookEntity> wrapper = Wrappers.lambdaQuery();
wrapper.eq(TBookEntity::getBookName, bookName); wrapper.eq(TBookEntity::getBookName, bookName);
TBookEntity tBookEntity = baseMapper.selectOne(wrapper); List<TBookEntity> tBookEntity = baseMapper.selectList(wrapper);
if (ObjectUtil.isNull(tBookEntity)){ if (ObjectUtil.isNull(tBookEntity)){
throw new ServerException("没有找到书籍"); throw new ServerException("没有找到书籍");
} }
tBookEntity.setBookCover("obhhi");
return tBookEntity; return tBookEntity;
} }

View File

@ -3,7 +3,6 @@ spring:
redis: redis:
database: 0 database: 0
host: localhost host: localhost
port: 6379
#timeout: 6000ms # 连接超时时长(毫秒) #timeout: 6000ms # 连接超时时长(毫秒)
datasource: datasource:
dynamic: dynamic: