dos 3 kuukautta sitten
vanhempi
commit
1131a9d92c

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

@@ -21,5 +21,5 @@ public interface IAppGameBettingService extends IService<AppGameBetting> {
     /**
      * 根据日期查询投注情况
      * */
-    List<AppGameBetting> selectListByDate( Long userId, String beginTime, String endTime);
+    List<AppGameBetting> selectListByDate( Long userId, String beginTime, String endTime,Long gameId);
 }

+ 2 - 0
game-business/src/main/java/com/game/business/service/IAppUserCountService.java

@@ -12,4 +12,6 @@ public interface IAppUserCountService extends IService<AppUserCount> {
 
     public void createAppUserCount(AppUserCount appUserCount);
 
+    public void staticsUserCount(Long gameId,String dateTime);
+
 }

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

@@ -66,7 +66,7 @@ public class AppGameBettingServiceImpl extends ServiceImpl<AppGameBettingMapper,
     }
 
     @Override
-    public List<AppGameBetting> selectListByDate(Long userId, String beginTime, String endTime) {
+    public List<AppGameBetting> selectListByDate(Long userId, String beginTime, String endTime,Long gameId) {
         LambdaQueryWrapper<AppGameBetting> queryWrapper = Wrappers.lambdaQuery();;
         queryWrapper.ne(AppGameBetting::getIsWinning,0);//查询已开奖
         queryWrapper.eq(AppGameBetting::getBettingType,0);
@@ -76,6 +76,9 @@ public class AppGameBettingServiceImpl extends ServiceImpl<AppGameBettingMapper,
         if(StringUtils.isNotBlank(beginTime)){
             queryWrapper.ge(AppGameBetting::getUpdateTime,beginTime);
         }
+        if(null != gameId){
+            queryWrapper.eq(AppGameBetting::getGameId,gameId);
+        }
         if(StringUtils.isNotBlank(endTime)){
             queryWrapper.le(AppGameBetting::getUpdateTime,endTime);
         }

+ 107 - 5
game-business/src/main/java/com/game/business/service/impl/AppUserCountServiceImpl.java

@@ -1,16 +1,23 @@
 package com.game.business.service.impl;
 
+import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.game.business.domain.AppUserCount;
+import com.game.business.domain.*;
 import com.game.business.mapper.AppUserCountMapper;
-import com.game.business.service.IAppUserCountService;
+import com.game.business.service.*;
+import com.game.common.constant.finance.FinTranType1;
+import com.game.common.constant.finance.FinTranType3;
+import com.game.common.entity.KeyValue;
+import com.game.common.utils.DateUtils;
+import com.game.common.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 @Service
 public class AppUserCountServiceImpl extends ServiceImpl<AppUserCountMapper, AppUserCount> implements IAppUserCountService {
@@ -18,6 +25,27 @@ public class AppUserCountServiceImpl extends ServiceImpl<AppUserCountMapper, App
     @Autowired
     private AppUserCountMapper appUserCountMapper;
 
+    @Autowired
+    private IAppUserService appUserService;
+
+    @Autowired
+    private IAppUsersChargeService appUsersChargeService;
+
+    @Autowired
+    private IAppUsersCashrecordService appUsersCashrecordService;
+
+    @Autowired
+    private IFinTranRecordService finTranRecordService;
+
+    @Autowired
+    private IAppUserLiveDividedRecordService appUserLiveDividedRecordService;
+
+    @Autowired
+    private IAppUserGameRecordCountService appUserGameRecordCountService;
+
+    @Autowired
+    private IAppGameBettingService appGameBettingService;
+
     @Override
     public List<AppUserCount> getAppUserCount(long userId,String beginTime,String endTIme) {
         LambdaQueryWrapper<AppUserCount> queryWrapper = new LambdaQueryWrapper<AppUserCount>();
@@ -27,7 +55,7 @@ public class AppUserCountServiceImpl extends ServiceImpl<AppUserCountMapper, App
     }
 
     @Override
-    @Async
+//    @Async
     public void createAppUserCount(AppUserCount appUserCount) {
         //查询当前用户当日是否已经生成记录
         LambdaQueryWrapper<AppUserCount> queryWrapper = new LambdaQueryWrapper<>();
@@ -43,4 +71,78 @@ public class AppUserCountServiceImpl extends ServiceImpl<AppUserCountMapper, App
         }
     }
 
+    @Override
+    public void staticsUserCount(Long gameId,String dateTime) {
+        Date curDate = DateUtils.getNowDate();
+        if (StringUtils.isNotBlank(dateTime)) {
+            curDate = DateUtil.parse(dateTime, "yyyy-MM-dd");
+        } else {
+            dateTime = DateUtils.parseDateToStr("yyyy-MM-dd", curDate);
+        }
+        AppUser queryUser = new AppUser();
+        queryUser.setAgentFlag(1);
+        List<AppUser> list = appUserService.selectAppUserList(queryUser);//查询所有代理用户
+        List<AppUsersCharge> appUsersChargeList = appUsersChargeService.getChargeList(null, dateTime.concat(" 00:00:00"), dateTime.concat(" 23:59:59"));
+        List<AppUsersCashrecord> appUsersCashrecords = appUsersCashrecordService.getUserCashList(null, dateTime.concat(" 00:00:00"), dateTime.concat(" 23:59:59"));
+        List<FinTranRecord> finTranRecordList = finTranRecordService.getUserRecordList(null, dateTime.concat(" 00:00:00"), dateTime.concat(" 23:59:59"));
+        List<AppUserLiveDividedRecord> liveDividedRecordList = appUserLiveDividedRecordService.selectByDate(null, dateTime.concat(" 00:00:00"), dateTime.concat(" 23:59:59"));
+        List<AppUserGameRecordCount> gameRecordCountList = appUserGameRecordCountService.selectByDate(null, dateTime.concat(" 00:00:00"), dateTime.concat(" 23:59:59"));
+        List<AppGameBetting> gameBettingList = appGameBettingService.selectListByDate(null, dateTime.concat(" 00:00:00"), dateTime.concat(" 23:59:59"),gameId);
+        if (null != list && list.size() > 0) {
+            String finalDateTime = dateTime;
+            list.forEach(appUser -> {
+                AppUserCount appUserCount = new AppUserCount();
+                appUserCount.setUserId(appUser.getUserid());
+                appUserCount.setStrDate(finalDateTime);
+                appUserCount.setAgentUserId(appUser.getPid());
+                //充值总额
+                appUserCount.setRechargeAmount(appUsersChargeList.stream().filter(e -> e.getUid().equals(appUser.getUserid())).mapToDouble(e -> e.getMoney().doubleValue()).sum());
+                //提现金额
+                appUserCount.setWithdrawalAmount(appUsersCashrecords.stream().filter(e -> e.getUid().equals(appUser.getUserid())).mapToDouble(e -> e.getMoney().doubleValue()).sum());
+                //充值服务费/手续费
+                appUserCount.setRechargeCommission(appUsersChargeList.stream().filter(e -> e.getUid().equals(appUser.getUserid())).mapToDouble(e -> e.getPlatformService()).sum());
+                //充值赠送余额
+                appUserCount.setRechargeGive(finTranRecordList.stream().filter(e -> {
+                    return e.getUid().equals(appUser.getUserid()) &&
+                            e.getTranType1().intValue() == FinTranType1.U_Income_Coin_Balance.getType() &&
+                            e.getTranType3().intValue() == FinTranType3.CHARGE_IN_REWARD.getType();
+                }).mapToDouble(e->e.getCoinChange()).sum());
+                //提现服务费/手续费
+                appUserCount.setWithdrawalCommission(appUsersCashrecords.stream().filter(e -> e.getUid().equals(appUser.getUserid())).mapToDouble(e -> e.getService().doubleValue()).sum());
+                //直播消费金额
+                Map<String, KeyValue> type1Keys = Arrays.stream(FinTranType1.getKeyValues(1)).collect(Collectors.toMap(e -> e.a, Function.identity(), (k1, k2) -> k2)); //支出交易类型
+                Map<String, KeyValue> type3Keys = Arrays.stream(FinTranType3.getKeyValues(1)).collect(Collectors.toMap(e -> e.a, Function.identity(), (k1, k2) -> k2)); //支出交易类型
+                appUserCount.setLiveUseAmount(finTranRecordList.stream().filter(e -> {
+                    return e.getUid().equals(appUser.getUserid()) &&
+                            null != type1Keys.get(String.valueOf(e.getTranType1().intValue())) &&
+                            null != type3Keys.get(String.valueOf(e.getTranType3().intValue()));
+                }).mapToDouble(e -> dealMoney(e.getCoinChange())).sum());
+                //直播佣金
+                appUserCount.setLiveCommission(liveDividedRecordList.stream().filter(e -> e.getUserId().equals(appUser.getUserid())).mapToDouble(e -> e.getMoney().doubleValue()).sum());
+                //游戏佣金
+                appUserCount.setGameCommission(gameRecordCountList.stream().filter(e -> e.getUserId().equals(appUser.getUserid())).mapToDouble(e -> e.getCommission()).sum());
+                //游戏输
+                appUserCount.setGameLoseAmount(gameBettingList.stream().filter(
+                        e -> e.getUserId().equals(appUser.getUserid()) && e.getIsWinning().intValue() == 2
+                ).mapToDouble(e ->
+                        e.getBettingAmount()
+                ).sum());
+                //游戏赢
+                appUserCount.setGameWinAmount(gameBettingList.stream().filter(
+                        e -> e.getUserId().equals(appUser.getUserid()) && e.getIsWinning().intValue() == 1
+                ).mapToDouble(e ->
+                        e.getBettingAmount() * e.getBettingMultiple()
+                ).sum());
+                this.createAppUserCount(appUserCount);
+            });
+        }
+    }
+
+    /**
+     * 金额为负数则转为正数
+     * */
+    private double dealMoney(double money){
+        return money<0?money*-1:money;
+    }
+
 }

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

@@ -76,7 +76,7 @@ public class AppUserCountTask {
             List<FinTranRecord> finTranRecordList = finTranRecordService.getUserRecordList(null, dateTime.concat(" 00:00:00"), dateTime.concat(" 23:59:59"));
             List<AppUserLiveDividedRecord> liveDividedRecordList = appUserLiveDividedRecordService.selectByDate(null, dateTime.concat(" 00:00:00"), dateTime.concat(" 23:59:59"));
             List<AppUserGameRecordCount> gameRecordCountList = appUserGameRecordCountService.selectByDate(null, dateTime.concat(" 00:00:00"), dateTime.concat(" 23:59:59"));
-            List<AppGameBetting> gameBettingList = appGameBettingService.selectListByDate(null, dateTime.concat(" 00:00:00"), dateTime.concat(" 23:59:59"));
+            List<AppGameBetting> gameBettingList = appGameBettingService.selectListByDate(null, dateTime.concat(" 00:00:00"), dateTime.concat(" 23:59:59"),null);
             if (null != list && list.size() > 0) {
                 List<AppUserCount> appUserCountList = new ArrayList<>();
                 String finalDateTime = dateTime;