|
@@ -14,7 +14,11 @@ import com.qs.mp.user.mapper.UserCoinMapper;
|
|
import com.qs.mp.user.service.IUserCoinLogService;
|
|
import com.qs.mp.user.service.IUserCoinLogService;
|
|
import com.qs.mp.user.service.IUserCoinService;
|
|
import com.qs.mp.user.service.IUserCoinService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -89,15 +93,6 @@ public class UserCoinServiceImpl extends ServiceImpl<UserCoinMapper, UserCoin> i
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
public boolean transfer(CoinTransferParamDTO coinTransferParamDTO) {
|
|
public boolean transfer(CoinTransferParamDTO coinTransferParamDTO) {
|
|
-
|
|
|
|
- // 转赠限制规则
|
|
|
|
- // 一天:受赠人每天受赠10次,上限2000
|
|
|
|
- // 一周:受赠人每周受赠50次,上限6000
|
|
|
|
- // 每月:受赠人每月受赠100次,上限15000
|
|
|
|
- // 每季度:受赠人每季度受赠500次,上限30000
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
String LockKey = RedisLockKey.build(RedisLockKey.USER_COIN_TRANSFER_LOCK, coinTransferParamDTO.getFromUserId());
|
|
String LockKey = RedisLockKey.build(RedisLockKey.USER_COIN_TRANSFER_LOCK, coinTransferParamDTO.getFromUserId());
|
|
if (!distributedLocker.tryLock(LockKey)) {
|
|
if (!distributedLocker.tryLock(LockKey)) {
|
|
throw new ServiceException("系统繁忙,请稍后再试");
|
|
throw new ServiceException("系统繁忙,请稍后再试");
|
|
@@ -119,6 +114,7 @@ public class UserCoinServiceImpl extends ServiceImpl<UserCoinMapper, UserCoin> i
|
|
Assert.isTrue(rtn2, "增加受赠方盲豆失败,userId:" + coinTransferParamDTO.getToUserId());
|
|
Assert.isTrue(rtn2, "增加受赠方盲豆失败,userId:" + coinTransferParamDTO.getToUserId());
|
|
|
|
|
|
// 盲豆转赠日志
|
|
// 盲豆转赠日志
|
|
|
|
+ List<UserCoinLog> userCoinLogList = new ArrayList<>();
|
|
UserCoinLog userCoinFromLog = new UserCoinLog();
|
|
UserCoinLog userCoinFromLog = new UserCoinLog();
|
|
userCoinFromLog.setUserId(coinTransferParamDTO.getFromUserId());
|
|
userCoinFromLog.setUserId(coinTransferParamDTO.getFromUserId());
|
|
userCoinFromLog.setType(CoinLogTypeEnum.TRANSFER);
|
|
userCoinFromLog.setType(CoinLogTypeEnum.TRANSFER);
|
|
@@ -129,7 +125,7 @@ public class UserCoinServiceImpl extends ServiceImpl<UserCoinMapper, UserCoin> i
|
|
userCoinFromLog.setBizTime(new Date());
|
|
userCoinFromLog.setBizTime(new Date());
|
|
userCoinFromLog.setCreatedTime(new Date());
|
|
userCoinFromLog.setCreatedTime(new Date());
|
|
userCoinFromLog.setUpdatedTime(new Date());
|
|
userCoinFromLog.setUpdatedTime(new Date());
|
|
- userCoinLogService.save(userCoinFromLog);
|
|
|
|
|
|
+ userCoinLogList.add(userCoinFromLog);
|
|
|
|
|
|
UserCoinLog userCoinToLog = new UserCoinLog();
|
|
UserCoinLog userCoinToLog = new UserCoinLog();
|
|
userCoinToLog.setUserId(coinTransferParamDTO.getToUserId());
|
|
userCoinToLog.setUserId(coinTransferParamDTO.getToUserId());
|
|
@@ -141,7 +137,8 @@ public class UserCoinServiceImpl extends ServiceImpl<UserCoinMapper, UserCoin> i
|
|
userCoinToLog.setBizTime(new Date());
|
|
userCoinToLog.setBizTime(new Date());
|
|
userCoinToLog.setCreatedTime(new Date());
|
|
userCoinToLog.setCreatedTime(new Date());
|
|
userCoinToLog.setUpdatedTime(new Date());
|
|
userCoinToLog.setUpdatedTime(new Date());
|
|
- userCoinLogService.save(userCoinToLog);
|
|
|
|
|
|
+ userCoinLogList.add(userCoinToLog);
|
|
|
|
+ userCoinLogService.saveBatch(userCoinLogList);
|
|
} finally {
|
|
} finally {
|
|
distributedLocker.unlock(LockKey);
|
|
distributedLocker.unlock(LockKey);
|
|
}
|
|
}
|