|
@@ -20,6 +20,8 @@ import com.game.common.utils.DateUtils;
|
|
|
import com.game.common.utils.StringUtils;
|
|
|
import com.game.system.service.ISysConfigService;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
+import org.redisson.api.RLock;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
@@ -76,6 +78,9 @@ public class AppUserCountTask {
|
|
|
@Value("${task.switch}")
|
|
|
private Boolean taskSwitch;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedissonClient redissonClient;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 统计用户前一天
|
|
@@ -644,7 +649,7 @@ public class AppUserCountTask {
|
|
|
//查询是否有该时间段以外的开奖
|
|
|
int count = appGameBettingService.selectBettingCount(userId,beginDate,endDate);
|
|
|
//资产为0 则充值两倍流水条件设为已作废
|
|
|
- if(null != appUser && appUser.getDiamondCoin().doubleValue() < 1 && count < 1){
|
|
|
+ if(null != appUser && appUser.getDiamondCoin().doubleValue() <= 0 && count < 1){
|
|
|
//更新为已满足提现
|
|
|
// userChargeList.forEach(e->{
|
|
|
/*FinTranRecord updateTran = new FinTranRecord();
|
|
@@ -659,7 +664,7 @@ public class AppUserCountTask {
|
|
|
}else{
|
|
|
//查询本次充值到下次充值期间资产除去返佣后是否已归零
|
|
|
double amount = finTranRecordService.sumUserRechareTran(userId,beginDate,endDate);
|
|
|
- if(amount < 1 && count < 1){
|
|
|
+ if(amount <= 0 && count < 1){
|
|
|
/* FinTranRecord updateTran = new FinTranRecord();
|
|
|
updateTran.setId(tranRecord.getId());
|
|
|
updateTran.setWithdrawFlag(2);
|
|
@@ -714,60 +719,38 @@ public class AppUserCountTask {
|
|
|
if(null != chargeList && chargeList.size() > 0){
|
|
|
Map<Long, List<FinTranRecord>> chargeMap = chargeList.stream().collect(Collectors.groupingBy(FinTranRecord::getUid));
|
|
|
for(Long uid : chargeMap.keySet()) {
|
|
|
- int i = 1;
|
|
|
- double withdrawAble = 0;
|
|
|
- List<FinTranRecord> tranRecordList = chargeMap.get(uid);
|
|
|
- tranRecordList = tranRecordList.stream().sorted(Comparator.comparing(FinTranRecord::getCreateTime)).collect(Collectors.toList());
|
|
|
- Date beginDate = null;
|
|
|
- Date endDate = null;
|
|
|
- for (FinTranRecord finTranRecord : tranRecordList) {
|
|
|
- if(null == beginDate) {
|
|
|
- beginDate = finTranRecord.getCreateTime();
|
|
|
- }
|
|
|
- if (tranRecordList.size() > i) {
|
|
|
- endDate = new Date(chargeList.get(i).getCreateTime().getTime() - 1);
|
|
|
- }else{
|
|
|
- //查询用户是否还有未满足提现的充值
|
|
|
- List<FinTranRecord> curChargeList = finTranRecordService.selectUserTran(FinTranType1.U_Income_Coin_Balance.getType(),chargeType3,finTranRecord.getUid(),finTranRecord.getCreateTime(),null,0);
|
|
|
- if(null != curChargeList && curChargeList.size() > 0){
|
|
|
- endDate = curChargeList.get(0).getCreateTime();
|
|
|
- }else{
|
|
|
- endDate = new Date();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- i++;
|
|
|
-
|
|
|
- }
|
|
|
- //查询用户这段时间流水记录
|
|
|
- /*List<FinTranRecord> curTranList = finTranRecordService.selectUserTran(null, null, uid, null, endDate, null);
|
|
|
- withdrawAble += curTranList.stream().filter(e->FinTranType3.CONSUM_GAME_ANCHOR_WITHDRAW.getType()!=e.getTranType3().intValue()).mapToDouble(FinTranRecord::getDiamondCoinChange).sum();*/
|
|
|
- withdrawAble = finTranRecordService.sumUserTran(null, null, uid, null, endDate, null);
|
|
|
- AppUser updateUser = new AppUser();
|
|
|
- updateUser.setUserid(uid);
|
|
|
- updateUser.setWithdrawAble(withdrawAble);
|
|
|
- appUserService.updateAppUser(updateUser);
|
|
|
- log.info("用户{},可提现额度{}",uid,withdrawAble);
|
|
|
- //清除用户缓存
|
|
|
- redisCache.deleteObject("U:UserInfo:".concat(String.valueOf(uid)));
|
|
|
+ dealWithdraw(uid,chargeMap,chargeList,chargeType3);
|
|
|
}
|
|
|
}else if(null != userId){
|
|
|
- //查询所有未满足提现的充值、转账
|
|
|
- List<FinTranRecord> notchargeList = finTranRecordService.selectUserTran(FinTranType1.U_Income_Coin_Balance.getType(),chargeType3,userId,null,null,0);
|
|
|
- if(null != notchargeList && notchargeList.size() > 0) {
|
|
|
- log.info("用户{},有为满足提现订单,停止更新可提现余额",userId);
|
|
|
- }else{
|
|
|
- //查询用户这段时间流水记录
|
|
|
- /* List<FinTranRecord> curTranList = finTranRecordService.selectUserTran(null, null, userId, null, null, null);
|
|
|
- double withdrawAble = curTranList.stream().filter(e->FinTranType3.CONSUM_GAME_ANCHOR_WITHDRAW.getType()!=e.getTranType3().intValue()).mapToDouble(FinTranRecord::getDiamondCoinChange).sum();*/
|
|
|
- double withdrawAble = finTranRecordService.sumUserTran(null, null, userId, null, null, null);
|
|
|
- AppUser updateUser = new AppUser();
|
|
|
- updateUser.setUserid(userId);
|
|
|
- updateUser.setWithdrawAble(withdrawAble);
|
|
|
- appUserService.updateAppUser(updateUser);
|
|
|
- log.info("用户{},可提现额度{}",userId,withdrawAble);
|
|
|
- //清除用户缓存
|
|
|
- redisCache.deleteObject("U:UserInfo:".concat(String.valueOf(userId)));
|
|
|
+ RLock rLock = redissonClient.getLock("app_user_amount_".concat(String.valueOf(userId)));
|
|
|
+ boolean tryLock = false;
|
|
|
+ try {
|
|
|
+ tryLock = rLock.tryLock(20,10, TimeUnit.SECONDS);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ log.info("更新用户可提现余额失败:{}",e);
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ if(tryLock){
|
|
|
+ //查询所有未满足提现的充值、转账
|
|
|
+ List<FinTranRecord> notchargeList = finTranRecordService.selectUserTran(FinTranType1.U_Income_Coin_Balance.getType(),chargeType3,userId,null,null,0);
|
|
|
+ if(null != notchargeList && notchargeList.size() > 0) {
|
|
|
+ log.info("用户{},有为满足提现订单,停止更新可提现余额",userId);
|
|
|
+ }else{
|
|
|
+ //查询用户这段时间流水记录
|
|
|
+ /* List<FinTranRecord> curTranList = finTranRecordService.selectUserTran(null, null, userId, null, null, null);
|
|
|
+ double withdrawAble = curTranList.stream().filter(e->FinTranType3.CONSUM_GAME_ANCHOR_WITHDRAW.getType()!=e.getTranType3().intValue()).mapToDouble(FinTranRecord::getDiamondCoinChange).sum();*/
|
|
|
+ double withdrawAble = finTranRecordService.sumUserTran(null, null, userId, null, null, null);
|
|
|
+ AppUser updateUser = new AppUser();
|
|
|
+ updateUser.setUserid(userId);
|
|
|
+ updateUser.setWithdrawAble(withdrawAble);
|
|
|
+ appUserService.updateAppUser(updateUser);
|
|
|
+ log.info("用户{},可提现额度{}",userId,withdrawAble);
|
|
|
+ //清除用户缓存
|
|
|
+ redisCache.deleteObject("U:UserInfo:".concat(String.valueOf(userId)));
|
|
|
+ if(null != rLock){
|
|
|
+ rLock.unlock();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -813,4 +796,58 @@ public class AppUserCountTask {
|
|
|
// userChargeList.clear();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void dealWithdraw(Long uid,Map<Long, List<FinTranRecord>> chargeMap,List<FinTranRecord> chargeList,String chargeType3){
|
|
|
+ RLock rLock = redissonClient.getLock("app_user_amount_".concat(String.valueOf(uid)));
|
|
|
+ boolean tryLock = false;
|
|
|
+ try {
|
|
|
+ tryLock = rLock.tryLock(10,10, TimeUnit.SECONDS);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ log.info("更新提现余额失败: {}",e);
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ if(tryLock) {
|
|
|
+ int i = 1;
|
|
|
+ double withdrawAble = 0;
|
|
|
+ List<FinTranRecord> tranRecordList = chargeMap.get(uid);
|
|
|
+ tranRecordList = tranRecordList.stream().sorted(Comparator.comparing(FinTranRecord::getCreateTime)).collect(Collectors.toList());
|
|
|
+ Date beginDate = null;
|
|
|
+ Date endDate = null;
|
|
|
+ for (FinTranRecord finTranRecord : tranRecordList) {
|
|
|
+ if (null == beginDate) {
|
|
|
+ beginDate = finTranRecord.getCreateTime();
|
|
|
+ }
|
|
|
+ if (tranRecordList.size() > i) {
|
|
|
+ endDate = new Date(chargeList.get(i).getCreateTime().getTime() - 1);
|
|
|
+ } else {
|
|
|
+ //查询用户是否还有未满足提现的充值
|
|
|
+ List<FinTranRecord> curChargeList = finTranRecordService.selectUserTran(FinTranType1.U_Income_Coin_Balance.getType(), chargeType3, finTranRecord.getUid(), finTranRecord.getCreateTime(), null, 0);
|
|
|
+ if (null != curChargeList && curChargeList.size() > 0) {
|
|
|
+ endDate = curChargeList.get(0).getCreateTime();
|
|
|
+ } else {
|
|
|
+ endDate = new Date();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+
|
|
|
+ }
|
|
|
+ //查询用户这段时间流水记录
|
|
|
+ /*List<FinTranRecord> curTranList = finTranRecordService.selectUserTran(null, null, uid, null, endDate, null);
|
|
|
+ withdrawAble += curTranList.stream().filter(e->FinTranType3.CONSUM_GAME_ANCHOR_WITHDRAW.getType()!=e.getTranType3().intValue()).mapToDouble(FinTranRecord::getDiamondCoinChange).sum();*/
|
|
|
+ withdrawAble = finTranRecordService.sumUserTran(null, null, uid, null, endDate, null);
|
|
|
+ AppUser updateUser = new AppUser();
|
|
|
+ updateUser.setUserid(uid);
|
|
|
+ updateUser.setWithdrawAble(withdrawAble);
|
|
|
+ appUserService.updateAppUser(updateUser);
|
|
|
+ log.info("用户{},可提现额度{}", uid, withdrawAble);
|
|
|
+ //清除用户缓存
|
|
|
+ redisCache.deleteObject("U:UserInfo:".concat(String.valueOf(uid)));
|
|
|
+ if(null != rLock){
|
|
|
+ rLock.unlock();
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ dealWithdraw(uid,chargeMap,chargeList,chargeType3);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|