|
@@ -2,6 +2,7 @@ package com.game.business.service.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.game.business.domain.*;
|
|
|
import com.game.business.mapper.AppUserCountMapper;
|
|
@@ -14,10 +15,12 @@ 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 org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.Date;
|
|
|
|
|
|
@Service
|
|
|
public class AppUserCountServiceImpl extends ServiceImpl<AppUserCountMapper, AppUserCount> implements IAppUserCountService {
|
|
@@ -54,8 +57,14 @@ public class AppUserCountServiceImpl extends ServiceImpl<AppUserCountMapper, App
|
|
|
return appUserCountMapper.selectList(queryWrapper);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<AppUserCount> getAppUserCountNew(long userId, String beginTime, String endTIme) {
|
|
|
+ return appUserCountMapper.selectTeamUserCount(userId,beginTime,endTIme);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
|
|
|
+ @Transactional
|
|
|
public void createAppUserCount(AppUserCount appUserCount) {
|
|
|
|
|
|
LambdaQueryWrapper<AppUserCount> queryWrapper = new LambdaQueryWrapper<>();
|
|
@@ -64,72 +73,86 @@ public class AppUserCountServiceImpl extends ServiceImpl<AppUserCountMapper, App
|
|
|
AppUserCount userCount = appUserCountMapper.selectOne(queryWrapper);
|
|
|
int res = 0;
|
|
|
if(userCount==null) {
|
|
|
+ appUserCount.setCreateTime(new Date());
|
|
|
+ appUserCount.setUpdateTime(new Date());
|
|
|
res = appUserCountMapper.insert(appUserCount);
|
|
|
}else{
|
|
|
appUserCount.setId(userCount.getId());
|
|
|
+
|
|
|
+ appUserCount.setUpdateTime(new Date());
|
|
|
+ }*/
|
|
|
+ if(!appUserCount.isUpdate()) {
|
|
|
+
|
|
|
+ if (appUserCount.getRechargeAmount() != null) {
|
|
|
+ appUserCount.setRechargeAmount(userCount.getRechargeAmount() + appUserCount.getRechargeAmount());
|
|
|
+ }
|
|
|
+ if (appUserCount.getRechargeCommission() != null) {
|
|
|
+ appUserCount.setRechargeCommission(userCount.getRechargeCommission() + appUserCount.getRechargeCommission());
|
|
|
+ }
|
|
|
+ if (appUserCount.getRechargeGive() != null) {
|
|
|
+ appUserCount.setRechargeGive(userCount.getRechargeGive() + appUserCount.getRechargeGive());
|
|
|
+ }
|
|
|
+ if (appUserCount.getWithdrawalCommission() != null) {
|
|
|
+ appUserCount.setWithdrawalAmount(userCount.getWithdrawalAmount() + appUserCount.getWithdrawalAmount());
|
|
|
+ }
|
|
|
+ if (appUserCount.getWithdrawalCommission() != null) {
|
|
|
+ appUserCount.setWithdrawalCommission(userCount.getWithdrawalCommission() + appUserCount.getWithdrawalCommission());
|
|
|
+ }
|
|
|
+ if (appUserCount.getLiveUseAmount() != null) {
|
|
|
+ appUserCount.setLiveUseAmount(userCount.getLiveUseAmount() + appUserCount.getLiveUseAmount());
|
|
|
+ }
|
|
|
+ if (appUserCount.getLiveCommission() != null) {
|
|
|
+ appUserCount.setLiveCommission(userCount.getLiveCommission() + appUserCount.getLiveCommission());
|
|
|
+ }
|
|
|
+ if (appUserCount.getGameWinAmount() != null) {
|
|
|
+ appUserCount.setGameWinAmount(userCount.getGameWinAmount() + appUserCount.getGameWinAmount());
|
|
|
+ }
|
|
|
+ if (appUserCount.getGameLoseAmount() != null) {
|
|
|
+ appUserCount.setGameLoseAmount(userCount.getGameLoseAmount() + appUserCount.getGameLoseAmount());
|
|
|
+ }
|
|
|
+ if (appUserCount.getGameCommission() != null) {
|
|
|
+ appUserCount.setGameCommission(userCount.getGameCommission() + appUserCount.getGameCommission());
|
|
|
+ }
|
|
|
+ }
|
|
|
res = appUserCountMapper.updateById(appUserCount);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void staticsUserCount(Long gameId,String dateTime) {
|
|
|
+ public void staticsUserCount(Long gameId,String dateTime,String gameDate) {
|
|
|
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"),null);
|
|
|
- if (null != list && list.size() > 0) {
|
|
|
+
|
|
|
+
|
|
|
+ String lastDateStr = DateUtil.format(lastDate,"yyyy-MM-dd HH:mm:ss");
|
|
|
+ if(!dateTime.equals(DateUtil.format(lastDate,"yyyy-MM-dd"))){
|
|
|
+ lastDateStr = DateUtil.format(curDate, "yyyy-MM-dd").concat(" 00:00:00");
|
|
|
+ }
|
|
|
+ String endTimeStr = DateUtil.format(curDate,"yyyy-MM-dd HH:mm:ss");*/
|
|
|
+ List<AppGameBetting> gameBettingList = appGameBettingService.selectListByDate(null, null, null,gameId,gameDate);
|
|
|
+ if (null != gameBettingList && gameBettingList.size() > 0) {
|
|
|
String finalDateTime = dateTime;
|
|
|
- list.forEach(appUser -> {
|
|
|
+ Date finalCurDate = curDate;
|
|
|
+ List<Long> userIds = gameBettingList.stream().map(AppGameBetting::getUserId).distinct().collect(Collectors.toList());
|
|
|
+ userIds.forEach(userId -> {
|
|
|
AppUserCount appUserCount = new AppUserCount();
|
|
|
- appUserCount.setUserId(appUser.getUserid());
|
|
|
+ appUserCount.setUserId(userId);
|
|
|
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.setAgentUserId(userId);
|
|
|
+ appUserCount.setUpdateTime(finalCurDate);
|
|
|
|
|
|
appUserCount.setGameLoseAmount(gameBettingList.stream().filter(
|
|
|
- e -> e.getUserId().equals(appUser.getUserid()) && e.getIsWinning().intValue() == 2
|
|
|
+ e -> e.getUserId().equals(userId) && e.getIsWinning().intValue() == 2
|
|
|
).mapToDouble(e ->
|
|
|
e.getBettingAmount()
|
|
|
).sum());
|
|
|
|
|
|
appUserCount.setGameWinAmount(gameBettingList.stream().filter(
|
|
|
- e -> e.getUserId().equals(appUser.getUserid()) && e.getIsWinning().intValue() == 1
|
|
|
+ e -> e.getUserId().equals(userId) && e.getIsWinning().intValue() == 1
|
|
|
).mapToDouble(e ->
|
|
|
e.getBettingAmount() * e.getBettingMultiple()
|
|
|
).sum());
|
|
@@ -138,6 +161,62 @@ public class AppUserCountServiceImpl extends ServiceImpl<AppUserCountMapper, App
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Date selectLastUpdateDate() {
|
|
|
+ LambdaQueryWrapper<AppUserCount> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.orderByDesc(AppUserCount::getUpdateTime);
|
|
|
+ queryWrapper.last("limit 1");
|
|
|
+ AppUserCount appUserCount = appUserCountMapper.selectOne(queryWrapper);
|
|
|
+ if(null == appUserCount || null == appUserCount.getUpdateTime()) {
|
|
|
+ return DateUtil.beginOfDay(DateUtils.getNowDate());
|
|
|
+ }
|
|
|
+ return DateUtil.offsetMillisecond(appUserCount.getUpdateTime(), 1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 查询最后更新时间
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public Date selectLastDate() {
|
|
|
+ LambdaQueryWrapper<AppUserCount> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.orderByDesc(AppUserCount::getUpdateTime);
|
|
|
+ queryWrapper.last("limit 1");
|
|
|
+ AppUserCount appUserCount = appUserCountMapper.selectOne(queryWrapper);
|
|
|
+ if(null == appUserCount || null == appUserCount.getCountTime()) {
|
|
|
+ return DateUtil.beginOfDay(DateUtils.getNowDate());
|
|
|
+ }
|
|
|
+ return DateUtil.offsetMillisecond(appUserCount.getCountTime(), 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void staticsUserBetting(AppGameBetting appGameBetting,List<AppGameCommission> gameRateList) {
|
|
|
+ Date curDate = DateUtils.getNowDate();
|
|
|
+ String dateTime = DateUtils.parseDateToStr("yyyy-MM-dd", curDate);
|
|
|
+
|
|
|
+ List<AppUserGameRecordCount> gameRecordCountList = appUserGameRecordCountService.selectByDate(null, null, null,appGameBetting.getGameId(),appGameBetting.getGameDate());
|
|
|
+ if (null != gameRateList && gameRateList.size() > 0) {
|
|
|
+ List<Long> userIds = gameRateList.stream().map(AppGameCommission::getUserId).collect(Collectors.toList());
|
|
|
+ userIds.add(appGameBetting.getUserId());
|
|
|
+ userIds = userIds.stream().distinct().collect(Collectors.toList());
|
|
|
+ String finalDateTime = dateTime;
|
|
|
+ Date finalCurDate = curDate;
|
|
|
+ userIds.forEach(userId -> {
|
|
|
+ AppUserCount appUserCount = new AppUserCount();
|
|
|
+ appUserCount.setUserId(userId);
|
|
|
+ appUserCount.setStrDate(finalDateTime);
|
|
|
+ appUserCount.setAgentUserId(userId);
|
|
|
+ appUserCount.setUpdateTime(finalCurDate);
|
|
|
+
|
|
|
+ appUserCount.setGameCommission(gameRecordCountList.stream().filter(e -> e.getUserId().equals(userId)).mapToDouble(e -> e.getCommission()).sum());
|
|
|
+
|
|
|
+ if(userId.equals(appGameBetting.getUserId())) {
|
|
|
+ appUserCount.setGameBetting(appGameBetting.getBettingAmount());
|
|
|
+ }
|
|
|
+ this.createAppUserCount(appUserCount);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* 金额为负数则转为正数
|
|
|
* */
|