|
@@ -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);
|