Bladeren bron

增加socket开关,修复可提现余额统计

gogs 1 maand geleden
bovenliggende
commit
e44f8c2156

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

@@ -64,7 +64,7 @@ spring:
   devtools:
     restart:
       # 热部署开关
-      enabled: true
+      enabled: false
   # redis 配置
   redis:
     # 地址
@@ -139,3 +139,6 @@ xss:
   excludes: /system/notice
   # 匹配链接
   urlPatterns: /system/*,/monitor/*,/tool/*
+
+websocket:
+  switch: false

+ 1 - 1
game-business/src/main/java/com/game/business/service/impl/FinTranRecordServiceImpl.java

@@ -356,7 +356,7 @@ public class FinTranRecordServiceImpl extends ServiceImpl<FinTranRecordMapper, F
             queryWrapper.ge(FinTranRecord::getCreateTime,beginDate);
         }
         if(null != endDate){
-            queryWrapper.le(FinTranRecord::getCreateTime,endDate);
+            queryWrapper.lt(FinTranRecord::getCreateTime,endDate);
         }
         if(null != type1){
             queryWrapper.eq(FinTranRecord::getTranType1,type1);

+ 48 - 9
game-business/src/main/java/com/game/business/task/AppUserCountTask.java

@@ -20,6 +20,7 @@ import org.springframework.stereotype.Component;
 
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -68,6 +69,11 @@ public class AppUserCountTask {
      * 统计用户前一天
      * */
     public void statistics(String dateTime){
+        String redisKey = CacheConstants.USER_STATICS_COUNT.concat("statistics");
+        if(!redisCache.redisTemplate.opsForValue().setIfAbsent(redisKey,1)){
+            log.info("停止统计用户每日直播、游戏、佣金,已在其他机器执行");
+            return;
+        }
         log.info("开始统计用户每日直播、游戏、佣金");
         try {
             Date curDate = DateUtil.offsetDay(DateUtils.getNowDate(), -1);
@@ -195,6 +201,8 @@ public class AppUserCountTask {
             }
         }catch (Exception e){
             log.info("用户每日直播、游戏、佣金统计异常:{}",e.getMessage());
+        } finally {
+            redisCache.redisTemplate.delete(redisKey);
         }
         log.info("用户每日直播、游戏、佣金统计完成");
 
@@ -204,6 +212,11 @@ public class AppUserCountTask {
      * 统计用户直播/充值 (增量更新 1分钟)
      * */
     public void statisticsLive(){
+        String redisKey = CacheConstants.USER_STATICS_COUNT.concat("statisticsLive");
+        if(!redisCache.redisTemplate.opsForValue().setIfAbsent(redisKey,1)){
+            log.info("停止增量更新用户每日直播、佣金,已在其他机器执行");
+            return;
+        }
         log.info("开始增量更新用户每日直播、佣金");
         try {
             Long userId = null;
@@ -277,6 +290,8 @@ public class AppUserCountTask {
             }
         }catch (Exception e){
             log.info("增量更新用户每日直播、佣金统计异常:{}",e.getMessage());
+        } finally {
+            redisCache.redisTemplate.delete(redisKey);
         }
         log.info("增量更新用户每日直播、佣金统计完成");
 
@@ -288,6 +303,11 @@ public class AppUserCountTask {
      * */
     @DSTransactional
     public void calculateDividends(String dateTime){
+        String redisKey = CacheConstants.USER_STATICS_COUNT.concat("calculateDividends");
+        if(!redisCache.redisTemplate.opsForValue().setIfAbsent(redisKey,1)){
+            log.info("停止每周代理分红,已在其他机器执行");
+            return;
+        }
         try {
             log.info("开始每周代理分红");
             String dateNo =  dealDividendsNew(dateTime);
@@ -307,6 +327,8 @@ public class AppUserCountTask {
             log.info("系统用户的直属下级自动发放分红完成");
         }catch (Exception e){
             log.info("每周分红失败:{}",e.getMessage());
+        }finally {
+            redisCache.redisTemplate.delete(redisKey);
         }
 
     }
@@ -525,6 +547,9 @@ public class AppUserCountTask {
      * */
     @DSTransactional
     public void calculationWithdraw(Long userId){
+        if(null != userId && userId.longValue() == -1){
+            userId = null;
+        }
         //查询所有未满足提现的充值、转账
         String chargeType3 = FinTranType3.ON_LINE_CHARGE.getType() + "," + FinTranType3.CHARGE_IN.getType()+ "," + FinTranType3.CHARGE_IN_Back.getType()
                             + "," + FinTranType3.TRANSFER_TO_TEAM_DiamondCoin.getType();
@@ -534,7 +559,7 @@ public class AppUserCountTask {
             for(Long uid:chargeMap.keySet()){
                 List<FinTranRecord> userChargeList = chargeMap.get(uid);
                 //按时间排序
-                userChargeList.stream().sorted(Comparator.comparing(FinTranRecord::getCreateTime)).collect(Collectors.toList());
+                userChargeList = userChargeList.stream().sorted(Comparator.comparing(FinTranRecord::getCreateTime)).collect(Collectors.toList());
                 Date beginDate= null;
                 Double money = 0.00;//需要满足的投注流水
                 Date endDate = new Date();
@@ -547,6 +572,8 @@ public class AppUserCountTask {
                     }
                     if(userChargeList.size() > i){
                         endDate = new Date(userChargeList.get(i).getCreateTime().getTime() - 1);
+                    }else{
+                        endDate = new Date();
                     }
                     money += tranRecord.getDiamondCoinChange();
                     //查询赠送金额
@@ -592,7 +619,7 @@ public class AppUserCountTask {
      * */
     @DSTransactional
     public void updateWithdrawAble(Long userId){
-        if(userId.longValue() == -1){
+        if(null != userId && userId.longValue() == -1){
             userId = null;
         }
         //查询所有未满足提现的充值、转账
@@ -605,19 +632,31 @@ public class AppUserCountTask {
                 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) {
-                    Date beginDate = finTranRecord.getCreateTime();
-                    Date endDate = new Date();
+                    if(null == beginDate) {
+                        beginDate = finTranRecord.getCreateTime();
+                    }
                     if (chargeList.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();
+                        }
+
                     }
-                    //查询用户这段时间流水记录
-                    List<FinTranRecord> curTranList = finTranRecordService.selectUserTran(null, null, uid, beginDate, endDate, null);
-                    withdrawAble += curTranList.stream().filter(
-                            e->FinTranType3.CASH_DIAMOND_INCOME.getType() != e.getTranType3().intValue()
-                    ).mapToDouble(FinTranRecord::getDiamondCoinChange).sum();
+                    i++;
 
                 }
+                //查询用户这段时间流水记录
+                List<FinTranRecord> curTranList = finTranRecordService.selectUserTran(null, null, uid, null, endDate, null);
+                withdrawAble += curTranList.stream().mapToDouble(FinTranRecord::getDiamondCoinChange).sum();
                 AppUser updateUser = new AppUser();
                 updateUser.setUserid(uid);
                 updateUser.setWithdrawAble(withdrawAble);

+ 6 - 2
game-business/src/main/java/com/game/business/websocket/WebSocketConnent.java

@@ -6,6 +6,7 @@ import com.game.business.config.SpringContextSetting;
 import com.game.business.util.Common;
 import com.game.business.websocket.client.*;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
 
 import javax.websocket.ContainerProvider;
 import java.net.URI;
@@ -19,6 +20,9 @@ public class WebSocketConnent {
     private int WS_CONNENT_NUM = 0;
     private int WS_CONNENT_MAX_NUM = 10;
 
+    @Value("${websocket.switch}")
+    private boolean socketSwitch;
+
 
 
     public WebSocketConnent(String WS_URL, String WS_REMARK_URL, String WS_URL_NAME){
@@ -28,7 +32,7 @@ public class WebSocketConnent {
     }
 
     public void connect() throws Exception{
-        /*while (true){
+        while (socketSwitch){
             try {
                 System.out.println("正在" + (this.WS_CONNENT_NUM == 0 ? "" : ("第" + this.WS_CONNENT_NUM + "次")) + "连接WebSocket[" + this.WS_URL_NAME + "]......");
 
@@ -77,6 +81,6 @@ public class WebSocketConnent {
                 System.out.println("连接[" + this.WS_URL_NAME + "]异常," + this.WS_CONNENT_NUM + "秒后尝试重新连接:" + e.getMessage());
                 Thread.sleep(this.WS_CONNENT_NUM * 1000);
             }
-        }*/
+        }
     }
 }

+ 5 - 0
game-common/src/main/java/com/game/common/constant/CacheConstants.java

@@ -52,4 +52,9 @@ public class CacheConstants
      */
     public static final String USER_GAME_RECORD_COUNT = "user_game_record_count:";
 
+    /**
+     * 用户统计锁
+     */
+    public static final String USER_STATICS_COUNT = "user_statics_count:";
+
 }