提交支付1.0版本
This commit is contained in:
commit
de72338f77
|
@ -8,12 +8,6 @@ auth:
|
|||
- /swagger-ui.html
|
||||
- /swagger-ui/**
|
||||
- /doc.html
|
||||
- /maku/t_book_comment/**
|
||||
- /maku/t_user/**
|
||||
- /maku/t_book/list/search
|
||||
- /maku/t_book/{id}
|
||||
- /maku/t_book/{id}
|
||||
- /user/login
|
||||
- /maku/t_shopping_trolley/aaa
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package net.maku.maku.config;
|
||||
|
||||
public class PayConfig {
|
||||
public String generateOrderId() {
|
||||
// 随机生成订单ID的逻辑
|
||||
return "ORDER" + (int) (Math.random() * 1000000000);
|
||||
}
|
||||
|
||||
public boolean callPaymentService(Integer balance) {
|
||||
// 调用支付服务的逻辑
|
||||
if (balance == null || balance <= 0) {
|
||||
// 如果金额无效,则支付失败
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(100000000); // 模拟网络延迟或支付处理时间
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
}
|
||||
//假设一直模拟成功
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -47,6 +47,7 @@ public class TBookController {
|
|||
@Operation(summary = "列表")
|
||||
public Result<List<TBookEntity>> list() {
|
||||
List<TBookEntity> list = tBookService.list();
|
||||
|
||||
return Result.ok(list);
|
||||
}
|
||||
|
||||
|
@ -55,6 +56,7 @@ public class TBookController {
|
|||
@Parameter
|
||||
public Result<TBookEntity> getById(@PathVariable Long id){
|
||||
TBookEntity entity = tBookService.getById(id);
|
||||
|
||||
return Result.ok(entity);
|
||||
}
|
||||
@GetMapping("/list/search")
|
||||
|
@ -67,25 +69,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("收藏图书成功");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -30,6 +30,8 @@ import java.util.List;
|
|||
public class TPurchaseController {
|
||||
private final TPurchaseService tPurchaseService;
|
||||
|
||||
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
@PreAuthorize("hasAuthority('maku:t_purchase:page')")
|
||||
|
|
|
@ -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("加入购物车成功");
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package net.maku.maku.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
@ -8,19 +8,29 @@ 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.framework.security.cache.TokenStoreCache;
|
||||
import net.maku.framework.security.config.PasswordConfig;
|
||||
import net.maku.maku.config.PayConfig;
|
||||
import net.maku.maku.convert.TUserConvert;
|
||||
import net.maku.maku.entity.TBookCollectionEntity;
|
||||
import net.maku.maku.entity.TUserEntity;
|
||||
import net.maku.maku.service.TUserService;
|
||||
import net.maku.maku.query.TUserQuery;
|
||||
import net.maku.maku.vo.TBookCollectionVO;
|
||||
import net.maku.maku.vo.TUserVO;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static java.util.Collections.list;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
@ -34,7 +44,8 @@ import java.util.UUID;
|
|||
public class TUserController {
|
||||
private final TUserService tUserService;
|
||||
private final RedisCache redisCache;
|
||||
|
||||
private final PasswordConfig passwordEncoder;
|
||||
private final TokenStoreCache tokenStoreCache;
|
||||
|
||||
@PostMapping("/register")
|
||||
@Operation(summary = "注册")
|
||||
|
@ -53,12 +64,14 @@ public class TUserController {
|
|||
@Operation(summary = "登录")
|
||||
public Result<String> login(@RequestBody TUserEntity entity){
|
||||
TUserEntity entity1 = tUserService.login(entity);
|
||||
if(ObjectUtils.isNotNull(entity1)){
|
||||
String token = UUID.randomUUID()+"";
|
||||
// 验证密码是否匹配
|
||||
boolean isMatch = passwordEncoder.passwordEncoder().matches(entity1.getPassword(), entity.getPassword());
|
||||
if (isMatch) {
|
||||
String token = UUID.randomUUID().toString();
|
||||
redisCache.set(token, entity1);
|
||||
return Result.ok(token);
|
||||
}else {
|
||||
return Result.error("登录失败");
|
||||
} else {
|
||||
return Result.error("密码错误");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,17 +94,26 @@ public class TUserController {
|
|||
|
||||
@GetMapping("/recharge")
|
||||
@Operation(summary = "充值")
|
||||
public Result<String> recharge(HttpServletRequest request,@RequestParam(value = "balance",required =false) int balance){
|
||||
public Result<String> recharge(HttpServletRequest request,@RequestParam(value = "balance", required = false) Integer balance){
|
||||
String token = request.getHeader("token");
|
||||
TUserEntity entity = (TUserEntity) redisCache.get(token);;
|
||||
int money=entity.getBalance();
|
||||
entity.setBalance(money+balance);
|
||||
tUserService.updateById(entity);
|
||||
return Result.ok();
|
||||
TUserEntity entity = (TUserEntity) redisCache.get(token);
|
||||
PayConfig payConfig = new PayConfig();
|
||||
String orderId = payConfig.generateOrderId();
|
||||
boolean paymentResult = payConfig.callPaymentService(balance);
|
||||
if (paymentResult) {
|
||||
int money = entity.getBalance();
|
||||
entity.setBalance(money + balance);
|
||||
tUserService.updateById(entity);
|
||||
return Result.ok(orderId+"支付成功");
|
||||
} else {
|
||||
return Result.error("支付失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/logout")
|
||||
|
||||
@PostMapping("/logout")
|
||||
@Operation(summary = "退出登录")
|
||||
public Result<String> logout(HttpServletRequest request) {
|
||||
String token = request.getHeader("token");
|
||||
|
@ -120,6 +142,7 @@ public class TUserController {
|
|||
|
||||
return Result.ok(TUserConvert.INSTANCE.convert(entity));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
@PreAuthorize("hasAuthority('maku:t_user:save')")
|
||||
|
@ -128,6 +151,7 @@ public class TUserController {
|
|||
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "修改")
|
||||
@PreAuthorize("hasAuthority('maku:t_user:update')")
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
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;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
}
|
|
@ -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,7 +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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,6 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -28,7 +27,6 @@ import java.util.UUID;
|
|||
@Service
|
||||
@AllArgsConstructor
|
||||
public class TUserServiceImpl extends BaseServiceImpl<TUserDao, TUserEntity> implements TUserService {
|
||||
|
||||
@Override
|
||||
public PageResult<TUserVO> page(TUserQuery query) {
|
||||
IPage<TUserEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||
|
@ -85,4 +83,7 @@ public class TUserServiceImpl extends BaseServiceImpl<TUserDao, TUserEntity> imp
|
|||
return vo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -24,6 +24,8 @@ public class TShoppingTrolleyVO implements Serializable {
|
|||
|
||||
private Integer bookId;
|
||||
|
||||
private Integer number;
|
||||
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date createTime;
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ import net.maku.framework.common.excel.ExcelFinishCallBack;
|
|||
import net.maku.framework.common.excel.LocalDateTimeConverter;
|
||||
import net.maku.framework.common.utils.ExcelUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -18,6 +20,23 @@ import java.util.List;
|
|||
* @author eden
|
||||
*/
|
||||
public class EasyExcelTest {
|
||||
@Test
|
||||
void IDcTest(){
|
||||
int randomPart = (int) (Math.random() * 1000000000);
|
||||
System.out.println(randomPart);
|
||||
}
|
||||
|
||||
@Test
|
||||
void bcTest(){
|
||||
PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
String rawpassword = "123456";
|
||||
String encode = passwordEncoder.encode(rawpassword);
|
||||
|
||||
System.out.println(rawpassword);
|
||||
System.out.println(encode);
|
||||
System.out.println(passwordEncoder.matches(rawpassword, encode));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doImport() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user