Compare commits
No commits in common. "74f977f36eba7ecab8bc3778125bd93b35fb0431" and "f4d4047b900b67dfb9c1b95067191ccdd4c5be9a" have entirely different histories.
74f977f36e
...
f4d4047b90
|
|
@ -57,18 +57,6 @@ public class RedisCache {
|
|||
}
|
||||
return value;
|
||||
}
|
||||
public <T> T get(String key, Class<T> clazz) {
|
||||
Object value = redisTemplate.opsForValue().get(key);
|
||||
if (value == null) {
|
||||
return null; // or throw an exception, depending on your requirement
|
||||
}
|
||||
if (clazz.isInstance(value)) {
|
||||
return clazz.cast(value);
|
||||
} else {
|
||||
throw new IllegalStateException("Cached value is not of expected type " + clazz);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Object get(String key) {
|
||||
return get(key, NOT_EXPIRE);
|
||||
|
|
|
|||
|
|
@ -8,13 +8,11 @@ auth:
|
|||
- /swagger-ui.html
|
||||
- /swagger-ui/**
|
||||
- /doc.html
|
||||
- /
|
||||
- /maku/t_user/login
|
||||
- /maku/t_user/updateUser
|
||||
- /maku/t_user/register
|
||||
- /maku/t_user/logout
|
||||
- /user/login
|
||||
- /maku/t_user/info
|
||||
- /maku/t_book/list/search
|
||||
- /maku/t_book/{id}
|
||||
- /user/login
|
||||
- /maku/t_shopping_trolley/aaa
|
||||
|
||||
|
|
|
|||
|
|
@ -2,14 +2,11 @@ package net.maku.maku.controller;
|
|||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.maku.framework.common.cache.RedisCache;
|
||||
import net.maku.framework.common.utils.PageResult;
|
||||
import net.maku.framework.common.utils.Result;
|
||||
import net.maku.maku.convert.TBookCommentConvert;
|
||||
import net.maku.maku.entity.TBookCommentEntity;
|
||||
import net.maku.maku.entity.TUserEntity;
|
||||
import net.maku.maku.service.TBookCommentService;
|
||||
import net.maku.maku.query.TBookCommentQuery;
|
||||
import net.maku.maku.vo.TBookCommentVO;
|
||||
|
|
@ -18,11 +15,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -37,27 +29,6 @@ import java.util.List;
|
|||
@AllArgsConstructor
|
||||
public class TBookCommentController {
|
||||
private final TBookCommentService tBookCommentService;
|
||||
private final RedisCache redisCache;
|
||||
@PostMapping("/comment")
|
||||
public Result setshoppingtrolly(HttpServletRequest request, @RequestBody TBookCommentVO vo) {
|
||||
// 首先验证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());
|
||||
// tBookCollectionService.save(userId,bookId,date);
|
||||
return Result.ok("加入购物车成功");
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
|
|
|
|||
|
|
@ -3,16 +3,11 @@ package net.maku.maku.controller;
|
|||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.maku.framework.common.cache.RedisCache;
|
||||
import net.maku.framework.common.utils.PageResult;
|
||||
import net.maku.framework.common.utils.Result;
|
||||
import net.maku.maku.convert.TBookCollectionConvert;
|
||||
import net.maku.maku.convert.TBookConvert;
|
||||
import net.maku.maku.entity.TBookEntity;
|
||||
import net.maku.maku.entity.TUserEntity;
|
||||
import net.maku.maku.service.TBookCollectionService;
|
||||
import net.maku.maku.service.TBookService;
|
||||
import net.maku.maku.query.TBookQuery;
|
||||
import net.maku.maku.vo.TBookVO;
|
||||
|
|
@ -21,11 +16,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -40,8 +30,6 @@ import java.util.List;
|
|||
@AllArgsConstructor
|
||||
public class TBookController {
|
||||
private final TBookService tBookService;
|
||||
private final RedisCache redisCache;
|
||||
private final TBookCollectionService tBookCollectionService;
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "列表")
|
||||
|
|
@ -62,45 +50,18 @@ public class TBookController {
|
|||
@GetMapping("/list/search")
|
||||
@Operation(summary = "根据书名查询书籍")
|
||||
@Parameter
|
||||
public Result<TBookEntity> getByName(@RequestParam String name){
|
||||
TBookEntity entity = tBookService.getByName(name);
|
||||
|
||||
public Result<TBookEntity> getByName(@RequestParam String bookName){
|
||||
TBookEntity entity = tBookService.getByName(bookName);
|
||||
return Result.ok(entity);
|
||||
}
|
||||
|
||||
@GetMapping("/collection")
|
||||
public Result setbookcollection(HttpServletRequest request, @RequestParam Integer bookId) {
|
||||
// 首先验证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());
|
||||
tBookCollectionService.save(userId,bookId,date);
|
||||
return Result.ok("收藏图书成功");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
@PreAuthorize("hasAuthority('maku:t_book:page')")
|
||||
public Result<PageResult<TBookVO>> page(@ParameterObject @Valid TBookQuery query){
|
||||
PageResult<TBookVO> page = tBookService.page(query);
|
||||
|
||||
return Result.ok(page);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
// @PreAuthorize("hasAuthority('maku:t_book:info')")
|
||||
|
|
@ -108,7 +69,6 @@ public class TBookController {
|
|||
TBookEntity entity = tBookService.getById(id);
|
||||
return Result.ok(TBookConvert.INSTANCE.convert(entity));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
@PreAuthorize("hasAuthority('maku:t_book:save')")
|
||||
|
|
|
|||
|
|
@ -2,14 +2,11 @@ package net.maku.maku.controller;
|
|||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.maku.framework.common.cache.RedisCache;
|
||||
import net.maku.framework.common.utils.PageResult;
|
||||
import net.maku.framework.common.utils.Result;
|
||||
import net.maku.maku.convert.TShoppingTrolleyConvert;
|
||||
import net.maku.maku.entity.TShoppingTrolleyEntity;
|
||||
import net.maku.maku.entity.TUserEntity;
|
||||
import net.maku.maku.service.TShoppingTrolleyService;
|
||||
import net.maku.maku.query.TShoppingTrolleyQuery;
|
||||
import net.maku.maku.vo.TShoppingTrolleyVO;
|
||||
|
|
@ -18,11 +15,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -36,30 +28,7 @@ import java.util.List;
|
|||
@Tag(name="")
|
||||
@AllArgsConstructor
|
||||
public class TShoppingTrolleyController {
|
||||
private final RedisCache redisCache;
|
||||
private final TShoppingTrolleyService tShoppingTrolleyService;
|
||||
@GetMapping("/aaa")
|
||||
public Result setshoppingtrolly(HttpServletRequest request, @RequestParam Integer bookId) {
|
||||
// 首先验证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());
|
||||
tShoppingTrolleyService.save(userId,bookId,date);
|
||||
return Result.ok("加入购物车成功");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
|
|
@ -72,7 +41,7 @@ public class TShoppingTrolleyController {
|
|||
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
// @PreAuthorize("hasAuthority('maku:t_shopping_trolley:info')")
|
||||
@PreAuthorize("hasAuthority('maku:t_shopping_trolley:info')")
|
||||
public Result<TShoppingTrolleyVO> get(@PathVariable("id") Long id){
|
||||
TShoppingTrolleyEntity entity = tShoppingTrolleyService.getById(id);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package net.maku.maku.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import java.util.Date;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@ import net.maku.maku.vo.TBookCollectionVO;
|
|||
import net.maku.maku.query.TBookCollectionQuery;
|
||||
import net.maku.maku.entity.TBookCollectionEntity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -25,6 +23,4 @@ public interface TBookCollectionService extends BaseService<TBookCollectionEntit
|
|||
void update(TBookCollectionVO vo);
|
||||
|
||||
void delete(List<Long> idList);
|
||||
|
||||
void save(Integer userId, Integer bookId, Date currentTime);
|
||||
}
|
||||
|
|
@ -6,7 +6,6 @@ import net.maku.maku.vo.TShoppingTrolleyVO;
|
|||
import net.maku.maku.query.TShoppingTrolleyQuery;
|
||||
import net.maku.maku.entity.TShoppingTrolleyEntity;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -24,6 +23,4 @@ public interface TShoppingTrolleyService extends BaseService<TShoppingTrolleyEnt
|
|||
void update(TShoppingTrolleyVO vo);
|
||||
|
||||
void delete(List<Long> idList);
|
||||
|
||||
void save(Integer userId, Integer bookId, Date date);
|
||||
}
|
||||
|
|
@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import net.maku.framework.common.utils.PageResult;
|
||||
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
|
||||
import net.maku.maku.convert.TBookCollectionConvert;
|
||||
|
|
@ -17,8 +16,6 @@ import net.maku.maku.service.TBookCollectionService;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -65,20 +62,4 @@ public class TBookCollectionServiceImpl extends BaseServiceImpl<TBookCollectionD
|
|||
removeByIds(idList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Integer userId, Integer bookId, Date currentTime) {
|
||||
TBookCollectionEntity entity = new TBookCollectionEntity();
|
||||
entity.setUserId(userId);
|
||||
entity.setBookId(bookId);
|
||||
entity.setCreateTime(currentTime);
|
||||
// 可以根据需要设置其它字段,例如自增id字段和lastModifiedTime字段(如果需要)
|
||||
|
||||
// 假设lastModifiedTime可以为空,可以根据需要设置
|
||||
|
||||
|
||||
// 使用 MyBatis Plus 的 save 方法保存实体
|
||||
this.save(entity);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -8,7 +8,6 @@ import lombok.AllArgsConstructor;
|
|||
import net.maku.framework.common.utils.PageResult;
|
||||
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
|
||||
import net.maku.maku.convert.TShoppingTrolleyConvert;
|
||||
import net.maku.maku.entity.TBookCollectionEntity;
|
||||
import net.maku.maku.entity.TShoppingTrolleyEntity;
|
||||
import net.maku.maku.query.TShoppingTrolleyQuery;
|
||||
import net.maku.maku.vo.TShoppingTrolleyVO;
|
||||
|
|
@ -17,7 +16,6 @@ import net.maku.maku.service.TShoppingTrolleyService;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -64,18 +62,4 @@ public class TShoppingTrolleyServiceImpl extends BaseServiceImpl<TShoppingTrolle
|
|||
removeByIds(idList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Integer userId, Integer bookId, Date currentTime) {
|
||||
TShoppingTrolleyEntity entity = new TShoppingTrolleyEntity();
|
||||
entity.setUserId(userId);
|
||||
entity.setBookId(bookId);
|
||||
entity.setCreateTime(currentTime);
|
||||
// 可以根据需要设置其它字段,例如自增id字段和lastModifiedTime字段(如果需要)
|
||||
|
||||
// 假设lastModifiedTime可以为空,可以根据需要设置
|
||||
|
||||
// 使用 MyBatis Plus 的 save 方法保存实体
|
||||
this.save(entity);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user