Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
85cd31247c
|
@ -14,6 +14,6 @@ auth:
|
|||
- /maku/t_book/{id}
|
||||
- /maku/t_book/{id}
|
||||
- /user/login
|
||||
- /maku/t_shopping_trolley/aaa
|
||||
- /maku/t_shopping_trolley/**
|
||||
|
||||
|
||||
|
|
|
@ -67,25 +67,22 @@ public class TBookController {
|
|||
|
||||
@PostMapping("/collection")
|
||||
@Operation(summary = "收藏图书")
|
||||
public Result setbookcollection(HttpServletRequest request, @RequestParam Integer bookId) {
|
||||
public Result<String> 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("收藏图书成功");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -63,13 +63,16 @@ public class TShoppingTrolleyController {
|
|||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
@PreAuthorize("hasAuthority('maku:t_shopping_trolley:page')")
|
||||
public Result<PageResult<TShoppingTrolleyVO>> page(@ParameterObject @Valid TShoppingTrolleyQuery query){
|
||||
PageResult<TShoppingTrolleyVO> page = tShoppingTrolleyService.page(query);
|
||||
|
||||
return Result.ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "列表")
|
||||
public Result<List<TShoppingTrolleyEntity>> list(){
|
||||
return Result.ok(tShoppingTrolleyService.list());
|
||||
}
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
// @PreAuthorize("hasAuthority('maku:t_shopping_trolley:info')")
|
||||
|
@ -78,7 +81,6 @@ public class TShoppingTrolleyController {
|
|||
|
||||
return Result.ok(TShoppingTrolleyConvert.INSTANCE.convert(entity));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
@PreAuthorize("hasAuthority('maku:t_shopping_trolley:save')")
|
||||
|
@ -87,7 +89,6 @@ public class TShoppingTrolleyController {
|
|||
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "修改")
|
||||
@PreAuthorize("hasAuthority('maku:t_shopping_trolley:update')")
|
||||
|
@ -100,9 +101,15 @@ public class TShoppingTrolleyController {
|
|||
@DeleteMapping
|
||||
@Operation(summary = "删除")
|
||||
@PreAuthorize("hasAuthority('maku:t_shopping_trolley:delete')")
|
||||
public Result<String> delete(@RequestBody List<Long> idList){
|
||||
public Result<String> delete( @RequestBody List<Long> idList){
|
||||
tShoppingTrolleyService.delete(idList);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "添加购物车")
|
||||
public Result<String> add(@RequestBody TShoppingTrolleyEntity entity){
|
||||
tShoppingTrolleyService.add(entity);
|
||||
return Result.ok("加入购物车成功");
|
||||
}
|
||||
}
|
|
@ -62,7 +62,6 @@ public class TUserController {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@PutMapping("/updateUser")
|
||||
@Operation(summary = "修改")
|
||||
public Result<TUserVO> updateUser(@RequestBody TUserVO vo){
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package net.maku.maku.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import net.maku.framework.mybatis.entity.BaseEntity;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author 阿沐 babamu@126.com
|
||||
* @since 1.0.0 2024-07-16
|
||||
|
|
|
@ -22,6 +22,8 @@ public class TShoppingTrolleyEntity {
|
|||
|
||||
private Integer bookId;
|
||||
|
||||
private Integer number;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private Date updateTime;
|
||||
|
|
|
@ -26,4 +26,7 @@ public interface TShoppingTrolleyService extends BaseService<TShoppingTrolleyEnt
|
|||
void delete(List<Long> idList);
|
||||
|
||||
void save(Integer userId, Integer bookId, Date date);
|
||||
|
||||
|
||||
TShoppingTrolleyEntity add(TShoppingTrolleyEntity entity);
|
||||
}
|
|
@ -28,4 +28,5 @@ public interface TUserService extends BaseService<TUserEntity> {
|
|||
|
||||
TUserVO updateUser(TUserVO vo);
|
||||
|
||||
|
||||
}
|
|
@ -73,7 +73,6 @@ public class TBookServiceImpl extends BaseServiceImpl<TBookDao, TBookEntity> imp
|
|||
throw new ServerException("没有找到书籍");
|
||||
}
|
||||
return tBookEntity;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -6,9 +6,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.AllArgsConstructor;
|
||||
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.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;
|
||||
|
@ -78,4 +78,27 @@ public class TShoppingTrolleyServiceImpl extends BaseServiceImpl<TShoppingTrolle
|
|||
this.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TShoppingTrolleyEntity add(TShoppingTrolleyEntity entity) {
|
||||
LambdaQueryWrapper<TShoppingTrolleyEntity> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TShoppingTrolleyEntity::getUserId, entity.getUserId());
|
||||
TShoppingTrolleyEntity existingEntity = baseMapper.selectOne(queryWrapper);
|
||||
if (existingEntity != null) {
|
||||
Integer number = existingEntity.getNumber();
|
||||
if (number != null) {
|
||||
existingEntity.setNumber(number + 1);
|
||||
} else {
|
||||
existingEntity.setNumber(1);
|
||||
}
|
||||
baseMapper.updateById(existingEntity);
|
||||
return existingEntity;
|
||||
} else {
|
||||
TShoppingTrolleyEntity newEntity = new TShoppingTrolleyEntity();
|
||||
newEntity.setUserId(entity.getUserId());
|
||||
newEntity.setNumber(1);
|
||||
baseMapper.insert(newEntity);
|
||||
return newEntity;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -24,6 +24,8 @@ public class TShoppingTrolleyVO implements Serializable {
|
|||
|
||||
private Integer bookId;
|
||||
|
||||
private Integer number;
|
||||
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date createTime;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user