|
@@ -7,8 +7,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.game.business.domain.*;
|
|
|
import com.game.business.mapper.AppUserCountMapper;
|
|
|
import com.game.business.service.*;
|
|
|
+import com.game.common.constant.CacheConstants;
|
|
|
import com.game.common.constant.finance.FinTranType1;
|
|
|
import com.game.common.constant.finance.FinTranType3;
|
|
|
+import com.game.common.core.redis.RedisCache;
|
|
|
import com.game.common.entity.KeyValue;
|
|
|
import com.game.common.utils.DateUtils;
|
|
|
import com.game.common.utils.StringUtils;
|
|
@@ -55,6 +57,9 @@ public class AppUserCountServiceImpl extends ServiceImpl<AppUserCountMapper, App
|
|
|
@Autowired
|
|
|
private IAppUserAgentService appUserAgentService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
@Override
|
|
|
public List<AppUserCount> getAppUserCount(long userId,String beginTime,String endTIme) {
|
|
|
LambdaQueryWrapper<AppUserCount> queryWrapper = new LambdaQueryWrapper<AppUserCount>();
|
|
@@ -184,7 +189,7 @@ public class AppUserCountServiceImpl extends ServiceImpl<AppUserCountMapper, App
|
|
|
if(null == appUserCount || null == appUserCount.getUpdateTime()) {
|
|
|
return DateUtil.beginOfDay(DateUtils.getNowDate());
|
|
|
}
|
|
|
- return DateUtil.offsetMillisecond(appUserCount.getUpdateTime(), 1);
|
|
|
+ return DateUtil.offsetSecond(appUserCount.getUpdateTime(), 1);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -193,45 +198,80 @@ public class AppUserCountServiceImpl extends ServiceImpl<AppUserCountMapper, App
|
|
|
@Override
|
|
|
public Date selectLastDate() {
|
|
|
LambdaQueryWrapper<AppUserCount> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.orderByDesc(AppUserCount::getUpdateTime);
|
|
|
+ queryWrapper.orderByDesc(AppUserCount::getCountTime);
|
|
|
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);
|
|
|
+ return DateUtil.offsetSecond(appUserCount.getCountTime(), 1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 查询最后更新时间
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public Date selectGameLastDate(Long userId) {
|
|
|
+ LambdaQueryWrapper<AppUserCount> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.orderByDesc(AppUserCount::getGameCountTime);
|
|
|
+ queryWrapper.eq(AppUserCount::getUserId,userId);
|
|
|
+ queryWrapper.last("limit 1");
|
|
|
+ AppUserCount appUserCount = appUserCountMapper.selectOne(queryWrapper);
|
|
|
+ if(null == appUserCount || null == appUserCount.getGameCountTime()) {
|
|
|
+ return DateUtil.beginOfDay(DateUtils.getNowDate());
|
|
|
+ }
|
|
|
+ return appUserCount.getGameCountTime();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void staticsUserBetting(AppGameBetting appGameBetting,List<AppGameCommission> gameRateList) {
|
|
|
- Date curDate = DateUtils.getNowDate();
|
|
|
- String dateTime = DateUtils.parseDateToStr("yyyy-MM-dd", curDate);
|
|
|
+ synchronized (CacheConstants.USER_GAME_RECORD_COUNT.concat(String.valueOf(appGameBetting.getGameId())).concat(appGameBetting.getGameDate())) {
|
|
|
+ Date curDate = DateUtils.getNowDate();
|
|
|
+ String dateTime = DateUtils.parseDateToStr("yyyy-MM-dd", curDate);
|
|
|
+
|
|
|
+ userIds.add(appGameBetting.getUserId());
|
|
|
+ userIds = userIds.stream().distinct().collect(Collectors.toList());*/
|
|
|
+
|
|
|
|
|
|
- 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(gameRateList.stream().filter(e->e.getUserId().equals(userId)).map(AppGameCommission::getPid).collect(Collectors.toList()).get(0));
|
|
|
- appUserCount.setUpdateTime(finalCurDate);
|
|
|
- if(null != gameRecordCountList && gameRecordCountList.size() > 0) {
|
|
|
-
|
|
|
- appUserCount.setGameCommission(gameRecordCountList.stream().filter(e -> e.getUserId().equals(userId)).mapToDouble(e -> e.getCommission()).sum());
|
|
|
- }
|
|
|
-
|
|
|
- if(userId.equals(appGameBetting.getUserId()) && appGameBetting.getBettingType().intValue() == 0) {
|
|
|
- appUserCount.setGameBetting(appGameBetting.getBettingAmount());
|
|
|
- }
|
|
|
- this.createAppUserCount(appUserCount);
|
|
|
- });
|
|
|
-
|
|
|
- appUserCountDividendService.reloadCache(null,userIds);
|
|
|
+ if (null != gameRateList && gameRateList.size() > 0) {
|
|
|
+
|
|
|
+ String finalDateTime = dateTime;
|
|
|
+ Date finalCurDate = curDate;
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
+ gameRateList.forEach(gameRate -> {
|
|
|
+ Long userId = gameRate.getUserId();
|
|
|
+
|
|
|
+ Date updateTime = this.selectGameLastDate(userId);
|
|
|
+ if (!DateUtil.format(updateTime, "yyyy-MM-dd").equals(DateUtil.format(finalCurDate, "yyyy-MM-dd"))) {
|
|
|
+
|
|
|
+ updateTime = DateUtil.beginOfDay(finalCurDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<AppUserGameRecordCount> gameRecordCountList = appUserGameRecordCountService.selectByDate(userId, DateUtil.format(updateTime, "yyyy-MM-dd HH:mm:ss"), DateUtil.format(finalCurDate, "yyyy-MM-dd HH:mm:ss"), gameRate.getGameId(), appGameBetting.getGameDate());
|
|
|
+ userIds.add(userId);
|
|
|
+ AppUserCount appUserCount = new AppUserCount();
|
|
|
+ appUserCount.setUserId(userId);
|
|
|
+ appUserCount.setStrDate(finalDateTime);
|
|
|
+ appUserCount.setAgentUserId(gameRateList.stream().filter(e -> e.getUserId().equals(userId)).map(AppGameCommission::getPid).collect(Collectors.toList()).get(0));
|
|
|
+ appUserCount.setUpdateTime(finalCurDate);
|
|
|
+ appUserCount.setGameCountTime(finalCurDate);
|
|
|
+ if (null != gameRecordCountList && gameRecordCountList.size() > 0) {
|
|
|
+
|
|
|
+ Map<String, Double> map = redisCache.getCacheMap(CacheConstants.USER_GAME_RECORD_COUNT.concat(String.valueOf(userId)));
|
|
|
+ appUserCount.setGameCommission(gameRecordCountList.stream().filter(e -> {
|
|
|
+ return null == map || null == map.get(String.valueOf(e.getId()));
|
|
|
+ }).mapToDouble(e -> e.getCommission()).sum());
|
|
|
+ setGameCache(gameRecordCountList);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (userId.equals(appGameBetting.getUserId()) && appGameBetting.getBettingType().intValue() == 0) {
|
|
|
+ appUserCount.setGameBetting(appGameBetting.getBettingAmount());
|
|
|
+ }
|
|
|
+ this.createAppUserCount(appUserCount);
|
|
|
+ });
|
|
|
+
|
|
|
+ appUserCountDividendService.reloadCache(null, userIds);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -248,6 +288,16 @@ public class AppUserCountServiceImpl extends ServiceImpl<AppUserCountMapper, App
|
|
|
return appUserCountMapper.selectList(queryWrapper);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void setGameCache(List<AppUserGameRecordCount> gameRecordCountList) {
|
|
|
+ if(null != gameRecordCountList && gameRecordCountList.size() > 0) {
|
|
|
+ gameRecordCountList.forEach(e->{
|
|
|
+
|
|
|
+ redisCache.setCacheMapValue(CacheConstants.USER_GAME_RECORD_COUNT.concat(String.valueOf(e.getUserId())),String.valueOf(e.getId()),e.getCommission());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* 金额为负数则转为正数
|
|
|
* */
|
|
@@ -255,4 +305,6 @@ public class AppUserCountServiceImpl extends ServiceImpl<AppUserCountMapper, App
|
|
|
return money<0?money*-1:money;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
}
|