|
@@ -276,19 +276,10 @@ public class BookServiceImpl implements BookService {
|
|
|
.example()
|
|
|
);
|
|
|
if (consume == null) { // 没有购买记录
|
|
|
- User user = getUserById(bookContentVO.getUserId());
|
|
|
+ User user = cacheService.getUserByIdCache(bookContentVO.getUserId());
|
|
|
//查询免费看点
|
|
|
- RechargeExample example = RechargeExample.newAndCreateCriteria()
|
|
|
- .andUserIdEqualTo(bookContentVO.getUserId())
|
|
|
- .andFreeEndtimeGreaterThan(DateUtils.getNow())
|
|
|
- .andRemainFreeKandianGreaterThan(0)
|
|
|
- .example();
|
|
|
- example.orderBy(Recharge.Column.freeEndtime.desc());
|
|
|
- List<Recharge> freeRecharges = rechargeMapper.selectByExample(example);
|
|
|
- Integer freeCount = 0;
|
|
|
- if (freeRecharges != null) {
|
|
|
- freeCount = freeRecharges.stream().mapToInt(x -> x.getFreeKandian()).sum();
|
|
|
- }
|
|
|
+ List<Recharge> freeRecharges = getFreeCharges(bookContentVO.getUserId());
|
|
|
+ int freeCount = getFreeCountFromCharges(freeRecharges);
|
|
|
//免费是否足够
|
|
|
if (freeCount > book.getPrice()) {
|
|
|
//扣除一部分免费的
|
|
@@ -326,7 +317,7 @@ public class BookServiceImpl implements BookService {
|
|
|
// 更新到 user
|
|
|
int i = userMapper.updateUserKandian(user, kandian, 0, DateUtils.getNow());
|
|
|
checkUpdate(i);
|
|
|
- cacheService.deleteUserByIdCache(user.getId());
|
|
|
+ cacheService.updateUserByIdCache(user.getId());
|
|
|
|
|
|
} else {
|
|
|
return Result.failure(ResultCode.NOMONEY);
|
|
@@ -344,6 +335,25 @@ public class BookServiceImpl implements BookService {
|
|
|
return Result.byObject(content);
|
|
|
}
|
|
|
|
|
|
+ public int getFreeCountFromCharges(List<Recharge> freeRecharges) {
|
|
|
+ Integer freeCount = 0;
|
|
|
+ if (freeRecharges != null) {
|
|
|
+ freeCount = freeRecharges.stream().mapToInt(x -> x.getFreeKandian()).sum();
|
|
|
+ }
|
|
|
+ return freeCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Recharge> getFreeCharges(Long userId) {
|
|
|
+ RechargeExample example = RechargeExample.newAndCreateCriteria()
|
|
|
+ .andUserIdEqualTo(userId)
|
|
|
+ .andFreeEndtimeGreaterThan(DateUtils.getNow())
|
|
|
+ .andRemainFreeKandianGreaterThan(0)
|
|
|
+ .example();
|
|
|
+ example.orderBy(Recharge.Column.freeEndtime.desc());
|
|
|
+ List<Recharge> freeRecharges = rechargeMapper.selectByExample(example);
|
|
|
+ return freeRecharges;
|
|
|
+ }
|
|
|
+
|
|
|
@Autowired
|
|
|
private ApplicationEventPublisher applicationEventPublisher;
|
|
|
|
|
@@ -681,7 +691,7 @@ public class BookServiceImpl implements BookService {
|
|
|
}
|
|
|
|
|
|
public User getUserById(Long id) {
|
|
|
- return cacheService.getUserByIdCache(id);
|
|
|
+ return userMapper.selectByPrimaryKey(id);
|
|
|
}
|
|
|
|
|
|
private String getUserKey(Long id) {
|