dos hace 2 meses
padre
commit
b930ddf064

+ 1 - 1
game-admin/src/main/resources/application.yml

@@ -146,4 +146,4 @@ websocket:
 
 #定时任务开关
 task:
-  switch: false
+  switch: true

+ 89 - 52
game-business/src/main/java/com/game/business/task/AppUserCountTask.java

@@ -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;
+
 
     /**
      * 统计用户前一天
@@ -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);
+        }
+    }
 }

+ 2 - 0
game-ui/src/views/business/lottery/index.vue

@@ -154,6 +154,8 @@
             type="text"
             icon="el-icon-edit"
             @click="handleLeakInfo(scope.row)"
+            v-if="scope.row.isLottery == 0
+"
           >开奖</el-button>
           <el-button
             size="mini"