|
@@ -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;
|
|
@@ -18,6 +19,7 @@ import org.springframework.stereotype.Service;
|
|
|
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 {
|
|
@@ -64,9 +66,47 @@ 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());
|
|
|
+ if(null == appUserCount.getUpdateTime()) {
|
|
|
+ appUserCount.setUpdateTime(new Date());
|
|
|
+ }
|
|
|
+ if(!appUserCount.isUpdate()) {
|
|
|
+
|
|
|
+ if (appUserCount.getRechargeAmount() > 0) {
|
|
|
+ appUserCount.setRechargeAmount(userCount.getRechargeAmount() + appUserCount.getRechargeAmount());
|
|
|
+ }
|
|
|
+ if (appUserCount.getRechargeCommission() > 0) {
|
|
|
+ appUserCount.setRechargeCommission(userCount.getRechargeCommission() + appUserCount.getRechargeCommission());
|
|
|
+ }
|
|
|
+ if (appUserCount.getRechargeGive() > 0) {
|
|
|
+ appUserCount.setRechargeGive(userCount.getRechargeGive() + appUserCount.getRechargeGive());
|
|
|
+ }
|
|
|
+ if (appUserCount.getWithdrawalCommission() > 0) {
|
|
|
+ appUserCount.setWithdrawalAmount(userCount.getWithdrawalAmount() + appUserCount.getWithdrawalAmount());
|
|
|
+ }
|
|
|
+ if (appUserCount.getWithdrawalCommission() > 0) {
|
|
|
+ appUserCount.setWithdrawalCommission(userCount.getWithdrawalCommission() + appUserCount.getWithdrawalCommission());
|
|
|
+ }
|
|
|
+ if (appUserCount.getLiveUseAmount() > 0) {
|
|
|
+ appUserCount.setLiveUseAmount(userCount.getLiveUseAmount() + appUserCount.getLiveUseAmount());
|
|
|
+ }
|
|
|
+ if (appUserCount.getLiveCommission() > 0) {
|
|
|
+ appUserCount.setLiveCommission(userCount.getLiveCommission() + appUserCount.getLiveCommission());
|
|
|
+ }
|
|
|
+ if (appUserCount.getGameWinAmount() > 0) {
|
|
|
+ appUserCount.setGameWinAmount(userCount.getGameWinAmount() + appUserCount.getGameWinAmount());
|
|
|
+ }
|
|
|
+ if (appUserCount.getGameLoseAmount() > 0) {
|
|
|
+ appUserCount.setGameLoseAmount(userCount.getGameLoseAmount() + appUserCount.getGameLoseAmount());
|
|
|
+ }
|
|
|
+ if (appUserCount.getGameCommission() > 0) {
|
|
|
+ appUserCount.setGameCommission(userCount.getGameCommission() + appUserCount.getGameCommission());
|
|
|
+ }
|
|
|
+ }
|
|
|
res = appUserCountMapper.updateById(appUserCount);
|
|
|
}
|
|
|
}
|
|
@@ -79,46 +119,27 @@ public class AppUserCountServiceImpl extends ServiceImpl<AppUserCountMapper, App
|
|
|
} else {
|
|
|
dateTime = DateUtils.parseDateToStr("yyyy-MM-dd", curDate);
|
|
|
}
|
|
|
+
|
|
|
+ Date lastDate = this.selectLastUpdateDate();
|
|
|
+ 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");
|
|
|
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);
|
|
|
+ List<AppUserGameRecordCount> gameRecordCountList = appUserGameRecordCountService.selectByDate(null, lastDateStr, endTimeStr);
|
|
|
+ List<AppGameBetting> gameBettingList = appGameBettingService.selectListByDate(null, lastDateStr, endTimeStr,null);
|
|
|
if (null != list && list.size() > 0) {
|
|
|
String finalDateTime = dateTime;
|
|
|
+ Date finalCurDate = curDate;
|
|
|
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.setUpdateTime(finalCurDate);
|
|
|
|
|
|
appUserCount.setGameCommission(gameRecordCountList.stream().filter(e -> e.getUserId().equals(appUser.getUserid())).mapToDouble(e -> e.getCommission()).sum());
|
|
|
|
|
@@ -138,6 +159,33 @@ 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);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* 金额为负数则转为正数
|
|
|
* */
|