Compare commits
3 Commits
b250a8a8d3
...
0359e93c19
Author | SHA1 | Date | |
---|---|---|---|
|
0359e93c19 | ||
|
82df411a6d | ||
|
de72338f77 |
|
@ -8,15 +8,6 @@ auth:
|
||||||
- /swagger-ui.html
|
- /swagger-ui.html
|
||||||
- /swagger-ui/**
|
- /swagger-ui/**
|
||||||
- /doc.html
|
- /doc.html
|
||||||
- /maku/t_book_comment/**
|
- /maku/**
|
||||||
- /maku/t_user/**
|
|
||||||
- /maku/t_book/list/search
|
|
||||||
- /maku/t_book/{id}
|
|
||||||
- /maku/t_book/{id}
|
|
||||||
- /user/login
|
|
||||||
- /maku/t_shopping_trolley/aaa
|
|
||||||
- /maku/t_book_collection/**
|
|
||||||
- /maku/t_shopping_trolley/**
|
|
||||||
- /maku/t_collection/**
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -51,6 +51,7 @@ public class TBookController {
|
||||||
@Operation(summary = "列表")
|
@Operation(summary = "列表")
|
||||||
public Result<List<TBookEntity>> list() {
|
public Result<List<TBookEntity>> list() {
|
||||||
List<TBookEntity> list = tBookService.list();
|
List<TBookEntity> list = tBookService.list();
|
||||||
|
|
||||||
return Result.ok(list);
|
return Result.ok(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +60,7 @@ public class TBookController {
|
||||||
@Parameter
|
@Parameter
|
||||||
public Result<TBookEntity> getById(@PathVariable Long id){
|
public Result<TBookEntity> getById(@PathVariable Long id){
|
||||||
TBookEntity entity = tBookService.getById(id);
|
TBookEntity entity = tBookService.getById(id);
|
||||||
|
|
||||||
return Result.ok(entity);
|
return Result.ok(entity);
|
||||||
}
|
}
|
||||||
@GetMapping("/list/search")
|
@GetMapping("/list/search")
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.maku.maku.controller;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import net.maku.framework.common.utils.PageResult;
|
import net.maku.framework.common.utils.PageResult;
|
||||||
import net.maku.framework.common.utils.Result;
|
import net.maku.framework.common.utils.Result;
|
||||||
|
|
|
@ -2,11 +2,15 @@ package net.maku.maku.controller;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import net.maku.framework.common.cache.RedisCache;
|
||||||
import net.maku.framework.common.utils.PageResult;
|
import net.maku.framework.common.utils.PageResult;
|
||||||
import net.maku.framework.common.utils.Result;
|
import net.maku.framework.common.utils.Result;
|
||||||
import net.maku.maku.convert.TPurchaseDetailsConvert;
|
import net.maku.maku.convert.TPurchaseDetailsConvert;
|
||||||
import net.maku.maku.entity.TPurchaseDetailsEntity;
|
import net.maku.maku.entity.TPurchaseDetailsEntity;
|
||||||
|
import net.maku.maku.entity.TPurchaseEntity;
|
||||||
|
import net.maku.maku.entity.TUserEntity;
|
||||||
import net.maku.maku.service.TPurchaseDetailsService;
|
import net.maku.maku.service.TPurchaseDetailsService;
|
||||||
import net.maku.maku.query.TPurchaseDetailsQuery;
|
import net.maku.maku.query.TPurchaseDetailsQuery;
|
||||||
import net.maku.maku.vo.TPurchaseDetailsVO;
|
import net.maku.maku.vo.TPurchaseDetailsVO;
|
||||||
|
@ -29,6 +33,19 @@ import java.util.List;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class TPurchaseDetailsController {
|
public class TPurchaseDetailsController {
|
||||||
private final TPurchaseDetailsService tPurchaseDetailsService;
|
private final TPurchaseDetailsService tPurchaseDetailsService;
|
||||||
|
private final RedisCache redisCache;
|
||||||
|
@GetMapping("/buy")
|
||||||
|
@Operation(summary = "购买")
|
||||||
|
public Result<?> purchaseBook(HttpServletRequest request) {
|
||||||
|
String token = request.getHeader("token");
|
||||||
|
TUserEntity entity = (TUserEntity) redisCache.get(token);
|
||||||
|
boolean isPurchased = tPurchaseDetailsService.purchaseBook(entity);
|
||||||
|
if (isPurchased) {
|
||||||
|
return Result.ok("购买成功");
|
||||||
|
} else {
|
||||||
|
return Result.error("余额不足,请充值");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("page")
|
@GetMapping("page")
|
||||||
@Operation(summary = "分页")
|
@Operation(summary = "分页")
|
||||||
|
|
|
@ -1,29 +1,36 @@
|
||||||
package net.maku.maku.controller;
|
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.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.servlet.ServletException;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import net.maku.framework.common.cache.RedisCache;
|
import net.maku.framework.common.cache.RedisCache;
|
||||||
import net.maku.framework.common.exception.ErrorCode;
|
|
||||||
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.common.utils.Result;
|
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.convert.TUserConvert;
|
||||||
|
import net.maku.maku.entity.TBookCollectionEntity;
|
||||||
import net.maku.maku.entity.TUserEntity;
|
import net.maku.maku.entity.TUserEntity;
|
||||||
import net.maku.maku.service.TUserService;
|
import net.maku.maku.service.TUserService;
|
||||||
import net.maku.maku.query.TUserQuery;
|
import net.maku.maku.query.TUserQuery;
|
||||||
|
import net.maku.maku.vo.TBookCollectionVO;
|
||||||
import net.maku.maku.vo.TUserVO;
|
import net.maku.maku.vo.TUserVO;
|
||||||
import org.springdoc.core.annotations.ParameterObject;
|
import org.springdoc.core.annotations.ParameterObject;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static java.util.Collections.list;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
@ -37,7 +44,8 @@ import java.util.UUID;
|
||||||
public class TUserController {
|
public class TUserController {
|
||||||
private final TUserService tUserService;
|
private final TUserService tUserService;
|
||||||
private final RedisCache redisCache;
|
private final RedisCache redisCache;
|
||||||
|
private final PasswordConfig passwordEncoder;
|
||||||
|
private final TokenStoreCache tokenStoreCache;
|
||||||
|
|
||||||
@PostMapping("/register")
|
@PostMapping("/register")
|
||||||
@Operation(summary = "注册")
|
@Operation(summary = "注册")
|
||||||
|
@ -46,8 +54,14 @@ public class TUserController {
|
||||||
if (existingUser != null) {
|
if (existingUser != null) {
|
||||||
return ResponseEntity.badRequest().body(Result.error("用户名已存在"));
|
return ResponseEntity.badRequest().body(Result.error("用户名已存在"));
|
||||||
} else {
|
} else {
|
||||||
|
//明文注册
|
||||||
tUserService.save(entity);
|
tUserService.save(entity);
|
||||||
return ResponseEntity.ok(Result.ok("注册成功"));
|
return ResponseEntity.ok(Result.ok("注册成功"));
|
||||||
|
//加密注册
|
||||||
|
// String encryptedPassword = passwordEncoder.passwordEncoder().encode(entity.getPassword());
|
||||||
|
// entity.setPassword(encryptedPassword);
|
||||||
|
// tUserService.save(entity);
|
||||||
|
// return ResponseEntity.ok(Result.ok("注册成功"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,16 +69,34 @@ public class TUserController {
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
@Operation(summary = "登录")
|
@Operation(summary = "登录")
|
||||||
public Result<String> login(@RequestBody TUserEntity entity){
|
public Result<String> login(@RequestBody TUserEntity entity){
|
||||||
|
//加密登录
|
||||||
|
// TUserEntity entity1 = tUserService.findByUsername(entity.getUsername());
|
||||||
|
// if (entity1 != null) {
|
||||||
|
// // 验证密码是否匹配
|
||||||
|
// boolean isMatch = passwordEncoder.passwordEncoder().matches(entity.getPassword(), entity1.getPassword());
|
||||||
|
// if (isMatch) {
|
||||||
|
// String token = UUID.randomUUID().toString();
|
||||||
|
// redisCache.set(token, entity1);
|
||||||
|
// return Result.ok(token);
|
||||||
|
// } else {
|
||||||
|
// return Result.error("密码错误");
|
||||||
|
// }
|
||||||
|
// }else {
|
||||||
|
// return Result.error("用户不存在");
|
||||||
|
// }
|
||||||
|
|
||||||
|
//明文登录
|
||||||
TUserEntity entity1 = tUserService.login(entity);
|
TUserEntity entity1 = tUserService.login(entity);
|
||||||
if(ObjectUtils.isNotNull(entity1)){
|
if(entity1 != null) {
|
||||||
String token = UUID.randomUUID()+"";
|
String token = UUID.randomUUID().toString();
|
||||||
redisCache.set(token, entity1);
|
redisCache.set(token, entity1);
|
||||||
return Result.ok(token);
|
return Result.ok(token);
|
||||||
}else {
|
}else {
|
||||||
return Result.error("登录失败");
|
return Result.error("用户名不存在");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@PutMapping("/updateUser")
|
@PutMapping("/updateUser")
|
||||||
@Operation(summary = "修改")
|
@Operation(summary = "修改")
|
||||||
public Result<TUserVO> updateUser(@RequestBody TUserVO vo){
|
public Result<TUserVO> updateUser(@RequestBody TUserVO vo){
|
||||||
|
@ -78,45 +110,31 @@ public class TUserController {
|
||||||
public Result<TUserEntity> findByUsername(HttpServletRequest request){
|
public Result<TUserEntity> findByUsername(HttpServletRequest request){
|
||||||
String token = request.getHeader("token");
|
String token = request.getHeader("token");
|
||||||
TUserEntity entity = (TUserEntity) redisCache.get(token);
|
TUserEntity entity = (TUserEntity) redisCache.get(token);
|
||||||
if(ObjectUtils.isNull(entity)){
|
return Result.ok(entity);
|
||||||
throw new ServerException(ErrorCode.REFRESH_TOKEN_INVALID);
|
|
||||||
}
|
|
||||||
TUserEntity p = tUserService.getById(entity.getId());
|
|
||||||
redisCache.set(token, p);
|
|
||||||
return Result.ok(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/recharge")
|
@GetMapping("/recharge")
|
||||||
@Operation(summary = "充值")
|
@Operation(summary = "充值")
|
||||||
public Result<String> recharge(HttpServletRequest request,@RequestParam(value = "balance") int balance){
|
public Result<String> recharge(HttpServletRequest request,@RequestParam(value = "balance", required = false) Integer balance){
|
||||||
String token = request.getHeader("token");
|
String token = request.getHeader("token");
|
||||||
TUserEntity entity = (TUserEntity) redisCache.get(token);
|
TUserEntity entity = (TUserEntity) redisCache.get(token);
|
||||||
if(ObjectUtils.isNull(entity)){
|
PayConfig payConfig = new PayConfig();
|
||||||
throw new ServerException(ErrorCode.REFRESH_TOKEN_INVALID);
|
String orderId = payConfig.generateOrderId();
|
||||||
|
boolean paymentResult = payConfig.callPaymentService(balance);
|
||||||
|
if (paymentResult) {
|
||||||
|
double money = entity.getBalance();
|
||||||
|
entity.setBalance(money + balance);
|
||||||
|
tUserService.updateById(entity);
|
||||||
|
return Result.ok(orderId+"支付成功");
|
||||||
|
} else {
|
||||||
|
return Result.error("支付失败");
|
||||||
}
|
}
|
||||||
int money=entity.getBalance();
|
|
||||||
entity.setBalance(money+balance);
|
|
||||||
tUserService.updateById(entity);
|
|
||||||
return Result.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/userInfo")
|
|
||||||
@Operation(summary = "更新资料")
|
|
||||||
public Result<String> userInfo(HttpServletRequest request,@RequestBody TUserVO vo){
|
|
||||||
String token = request.getHeader("token");
|
|
||||||
TUserEntity tokenUser = (TUserEntity) redisCache.get(token);
|
|
||||||
TUserEntity entity = tUserService.getById(tokenUser.getId());
|
|
||||||
if(ObjectUtils.isNull(entity)){
|
|
||||||
throw new ServerException(ErrorCode.REFRESH_TOKEN_INVALID);
|
|
||||||
}
|
|
||||||
entity.setEmail(vo.getEmail());
|
|
||||||
entity.setPhone(vo.getPassword());
|
|
||||||
tUserService.updateById(entity);
|
|
||||||
return Result.ok("success");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/logout")
|
|
||||||
|
@PostMapping("/logout")
|
||||||
@Operation(summary = "退出登录")
|
@Operation(summary = "退出登录")
|
||||||
public Result<String> logout(HttpServletRequest request) {
|
public Result<String> logout(HttpServletRequest request) {
|
||||||
String token = request.getHeader("token");
|
String token = request.getHeader("token");
|
||||||
|
@ -145,6 +163,7 @@ public class TUserController {
|
||||||
|
|
||||||
return Result.ok(TUserConvert.INSTANCE.convert(entity));
|
return Result.ok(TUserConvert.INSTANCE.convert(entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@Operation(summary = "保存")
|
@Operation(summary = "保存")
|
||||||
@PreAuthorize("hasAuthority('maku:t_user:save')")
|
@PreAuthorize("hasAuthority('maku:t_user:save')")
|
||||||
|
@ -153,6 +172,7 @@ public class TUserController {
|
||||||
|
|
||||||
return Result.ok();
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@Operation(summary = "修改")
|
@Operation(summary = "修改")
|
||||||
@PreAuthorize("hasAuthority('maku:t_user:update')")
|
@PreAuthorize("hasAuthority('maku:t_user:update')")
|
||||||
|
|
|
@ -22,6 +22,8 @@ public class TPurchaseDetailsEntity {
|
||||||
|
|
||||||
private Integer bookId;
|
private Integer bookId;
|
||||||
|
|
||||||
private BigDecimal price;
|
private double price;
|
||||||
|
|
||||||
|
private double count;
|
||||||
|
|
||||||
}
|
}
|
|
@ -25,7 +25,7 @@ public class TUserEntity {
|
||||||
|
|
||||||
private String avatar;
|
private String avatar;
|
||||||
|
|
||||||
private int balance;
|
private double balance;
|
||||||
|
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.maku.maku.service;
|
||||||
|
|
||||||
import net.maku.framework.common.utils.PageResult;
|
import net.maku.framework.common.utils.PageResult;
|
||||||
import net.maku.framework.mybatis.service.BaseService;
|
import net.maku.framework.mybatis.service.BaseService;
|
||||||
|
import net.maku.maku.entity.TUserEntity;
|
||||||
import net.maku.maku.vo.TPurchaseDetailsVO;
|
import net.maku.maku.vo.TPurchaseDetailsVO;
|
||||||
import net.maku.maku.query.TPurchaseDetailsQuery;
|
import net.maku.maku.query.TPurchaseDetailsQuery;
|
||||||
import net.maku.maku.entity.TPurchaseDetailsEntity;
|
import net.maku.maku.entity.TPurchaseDetailsEntity;
|
||||||
|
@ -23,4 +24,8 @@ public interface TPurchaseDetailsService extends BaseService<TPurchaseDetailsEnt
|
||||||
void update(TPurchaseDetailsVO vo);
|
void update(TPurchaseDetailsVO vo);
|
||||||
|
|
||||||
void delete(List<Long> idList);
|
void delete(List<Long> idList);
|
||||||
|
|
||||||
|
|
||||||
|
boolean purchaseBook(TUserEntity entity);
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,6 +2,8 @@ package net.maku.maku.service;
|
||||||
|
|
||||||
import net.maku.framework.common.utils.PageResult;
|
import net.maku.framework.common.utils.PageResult;
|
||||||
import net.maku.framework.mybatis.service.BaseService;
|
import net.maku.framework.mybatis.service.BaseService;
|
||||||
|
import net.maku.maku.entity.TPurchaseDetailsEntity;
|
||||||
|
import net.maku.maku.entity.TUserEntity;
|
||||||
import net.maku.maku.vo.TPurchaseVO;
|
import net.maku.maku.vo.TPurchaseVO;
|
||||||
import net.maku.maku.query.TPurchaseQuery;
|
import net.maku.maku.query.TPurchaseQuery;
|
||||||
import net.maku.maku.entity.TPurchaseEntity;
|
import net.maku.maku.entity.TPurchaseEntity;
|
||||||
|
@ -23,4 +25,6 @@ public interface TPurchaseService extends BaseService<TPurchaseEntity> {
|
||||||
void update(TPurchaseVO vo);
|
void update(TPurchaseVO vo);
|
||||||
|
|
||||||
void delete(List<Long> idList);
|
void delete(List<Long> idList);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -28,5 +28,6 @@ public interface TUserService extends BaseService<TUserEntity> {
|
||||||
|
|
||||||
TUserVO updateUser(TUserVO vo);
|
TUserVO updateUser(TUserVO vo);
|
||||||
|
|
||||||
|
TUserEntity findByUsername(String username);
|
||||||
|
|
||||||
}
|
}
|
|
@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
|
||||||
import net.maku.framework.common.utils.PageResult;
|
import net.maku.framework.common.utils.PageResult;
|
||||||
import net.maku.framework.common.utils.Result;
|
import net.maku.framework.common.utils.Result;
|
||||||
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
|
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
|
||||||
|
@ -18,7 +17,6 @@ import net.maku.maku.service.TBookCollectionService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,9 @@ 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.TPurchaseDetailsConvert;
|
import net.maku.maku.convert.TPurchaseDetailsConvert;
|
||||||
import net.maku.maku.entity.TPurchaseDetailsEntity;
|
import net.maku.maku.entity.TPurchaseDetailsEntity;
|
||||||
|
import net.maku.maku.entity.TUserEntity;
|
||||||
import net.maku.maku.query.TPurchaseDetailsQuery;
|
import net.maku.maku.query.TPurchaseDetailsQuery;
|
||||||
|
import net.maku.maku.service.TUserService;
|
||||||
import net.maku.maku.vo.TPurchaseDetailsVO;
|
import net.maku.maku.vo.TPurchaseDetailsVO;
|
||||||
import net.maku.maku.dao.TPurchaseDetailsDao;
|
import net.maku.maku.dao.TPurchaseDetailsDao;
|
||||||
import net.maku.maku.service.TPurchaseDetailsService;
|
import net.maku.maku.service.TPurchaseDetailsService;
|
||||||
|
@ -28,6 +30,7 @@ import java.util.List;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class TPurchaseDetailsServiceImpl extends BaseServiceImpl<TPurchaseDetailsDao, TPurchaseDetailsEntity> implements TPurchaseDetailsService {
|
public class TPurchaseDetailsServiceImpl extends BaseServiceImpl<TPurchaseDetailsDao, TPurchaseDetailsEntity> implements TPurchaseDetailsService {
|
||||||
|
|
||||||
|
private final TUserService tUserService;
|
||||||
@Override
|
@Override
|
||||||
public PageResult<TPurchaseDetailsVO> page(TPurchaseDetailsQuery query) {
|
public PageResult<TPurchaseDetailsVO> page(TPurchaseDetailsQuery query) {
|
||||||
IPage<TPurchaseDetailsEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
IPage<TPurchaseDetailsEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||||
|
@ -62,4 +65,21 @@ public class TPurchaseDetailsServiceImpl extends BaseServiceImpl<TPurchaseDetail
|
||||||
removeByIds(idList);
|
removeByIds(idList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean purchaseBook(TUserEntity entity) {
|
||||||
|
LambdaQueryWrapper<TPurchaseDetailsEntity> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(TPurchaseDetailsEntity::getPurchaseId,entity.getId());
|
||||||
|
TPurchaseDetailsEntity one =getOne(wrapper);
|
||||||
|
double price = one.getPrice();
|
||||||
|
double count =one.getCount();
|
||||||
|
double balance= entity.getBalance();
|
||||||
|
if (balance>=price*count){
|
||||||
|
double newBalance = balance-price*count;
|
||||||
|
entity.setBalance(newBalance);
|
||||||
|
tUserService.updateById(entity);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -10,6 +10,7 @@ import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
|
||||||
import net.maku.maku.convert.TPurchaseConvert;
|
import net.maku.maku.convert.TPurchaseConvert;
|
||||||
import net.maku.maku.entity.TPurchaseEntity;
|
import net.maku.maku.entity.TPurchaseEntity;
|
||||||
import net.maku.maku.query.TPurchaseQuery;
|
import net.maku.maku.query.TPurchaseQuery;
|
||||||
|
import net.maku.maku.service.TUserService;
|
||||||
import net.maku.maku.vo.TPurchaseVO;
|
import net.maku.maku.vo.TPurchaseVO;
|
||||||
import net.maku.maku.dao.TPurchaseDao;
|
import net.maku.maku.dao.TPurchaseDao;
|
||||||
import net.maku.maku.service.TPurchaseService;
|
import net.maku.maku.service.TPurchaseService;
|
||||||
|
|
|
@ -17,7 +17,6 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -28,7 +27,6 @@ import java.util.UUID;
|
||||||
@Service
|
@Service
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class TUserServiceImpl extends BaseServiceImpl<TUserDao, TUserEntity> implements TUserService {
|
public class TUserServiceImpl extends BaseServiceImpl<TUserDao, TUserEntity> implements TUserService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<TUserVO> page(TUserQuery query) {
|
public PageResult<TUserVO> page(TUserQuery query) {
|
||||||
IPage<TUserEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
IPage<TUserEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||||
|
@ -85,4 +83,16 @@ public class TUserServiceImpl extends BaseServiceImpl<TUserDao, TUserEntity> imp
|
||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TUserEntity findByUsername(String username) {
|
||||||
|
LambdaQueryWrapper<TUserEntity> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(TUserEntity::getUsername,username);
|
||||||
|
TUserEntity one = getOne(wrapper);
|
||||||
|
if(ObjectUtils.isNotNull(one)) {
|
||||||
|
return one;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -3,6 +3,8 @@ spring:
|
||||||
redis:
|
redis:
|
||||||
database: 0
|
database: 0
|
||||||
host: localhost
|
host: localhost
|
||||||
|
port: 6379
|
||||||
|
password: 123456
|
||||||
#timeout: 6000ms # 连接超时时长(毫秒)
|
#timeout: 6000ms # 连接超时时长(毫秒)
|
||||||
datasource:
|
datasource:
|
||||||
dynamic:
|
dynamic:
|
||||||
|
|
|
@ -6,6 +6,8 @@ import net.maku.framework.common.excel.ExcelFinishCallBack;
|
||||||
import net.maku.framework.common.excel.LocalDateTimeConverter;
|
import net.maku.framework.common.excel.LocalDateTimeConverter;
|
||||||
import net.maku.framework.common.utils.ExcelUtils;
|
import net.maku.framework.common.utils.ExcelUtils;
|
||||||
import org.junit.jupiter.api.Test;
|
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.io.File;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
@ -18,6 +20,23 @@ import java.util.List;
|
||||||
* @author eden
|
* @author eden
|
||||||
*/
|
*/
|
||||||
public class EasyExcelTest {
|
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
|
@Test
|
||||||
public void doImport() {
|
public void doImport() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user