|
@@ -15,6 +15,7 @@ import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -79,9 +80,14 @@ public class AccountStatServiceImpl extends ServiceImpl<AccountStatMapper, Accou
|
|
|
totalNum = jsonArrayTotal.getJSONObject(0).getInteger("cumulate_user");
|
|
|
|
|
|
// 昨日和前日 数据
|
|
|
+ // fixme 查询次数过多可以放在 观察者模式中异步执行(先看时间后期优化)
|
|
|
List<AccountStat> statData = baseMapper.selectByDateAndAccId(accountId,yesterday,beforeDay);
|
|
|
// 昨日活跃数量
|
|
|
long inactiveNum = inactiveFansNum(accountId,yesterday);
|
|
|
+ // 7天
|
|
|
+ long sevenInactiveNum = inactiveSevenFansNum(accountId,yesterday);
|
|
|
+ // 15 天
|
|
|
+ long fifteenInactiveNum = inactiveSevenFansNum(accountId,yesterday);
|
|
|
AccountStat ydData = statData.stream().filter(e->yesterday.equals(e.getStatDate())).findFirst().orElseGet(AccountStat::new);
|
|
|
addNum = newNum-cancelNum;
|
|
|
ydData.setTotalFansNum(totalNum);
|
|
@@ -91,7 +97,8 @@ public class AccountStatServiceImpl extends ServiceImpl<AccountStatMapper, Accou
|
|
|
ydData.setAccountId(accountId);
|
|
|
ydData.setAddNum(addNum);
|
|
|
ydData.setInactiveNum(inactiveNum);
|
|
|
-
|
|
|
+ ydData.setSevenNum(sevenInactiveNum);
|
|
|
+ ydData.setFifteenNum(fifteenInactiveNum);
|
|
|
statData.stream().filter(e->beforeDay.equals(e.getStatDate())).findFirst().map(e->{
|
|
|
ydData.setAddRate(Constants.calcRate(ydData.getAddNum(), e.getAddNum()));
|
|
|
ydData.setNewRate(Constants.calcRate(ydData.getNewNum(), e.getNewNum()));
|
|
@@ -107,12 +114,33 @@ public class AccountStatServiceImpl extends ServiceImpl<AccountStatMapper, Accou
|
|
|
|
|
|
@Override
|
|
|
public int inactiveFansNum(String accountId, String statDate) {
|
|
|
- LocalDate localDate = LocalDate.parse(statDate,Constants.DATE_FORMATTER);
|
|
|
- long start = localDate.atTime(LocalTime.of(0,0,0)).toInstant(Constants.DEFAULT_ZONE).getEpochSecond();
|
|
|
- long end = localDate.atTime(LocalTime.of(23,59,59)).toInstant(Constants.DEFAULT_ZONE).getEpochSecond();
|
|
|
+ LocalDateTime localDate = Constants.toLocalDateTime(statDate);
|
|
|
+ long start = localDate.toEpochSecond(Constants.DEFAULT_ZONE);
|
|
|
+ long end = localDate.plusDays(1).toEpochSecond(Constants.DEFAULT_ZONE);
|
|
|
return actionStatService.countInactiveFansNum(accountId,start,end);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public int inactiveSevenFansNum(String accountId, String statDate) {
|
|
|
+ LocalDateTime localDate = Constants.toLocalDateTime(statDate);
|
|
|
+ long start = localDate.plusDays(-7).toEpochSecond(Constants.DEFAULT_ZONE);
|
|
|
+ long end = localDate.toEpochSecond(Constants.DEFAULT_ZONE);
|
|
|
+ return actionStatService.countInactiveFansNum(accountId,start,end);
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public int inactiveFifteenFansNum(String accountId, String statDate) {
|
|
|
+ LocalDateTime localDate = Constants.toLocalDateTime(statDate);
|
|
|
+ long start = localDate.plusDays(-15).toEpochSecond(Constants.DEFAULT_ZONE);
|
|
|
+ long end = localDate.toEpochSecond(Constants.DEFAULT_ZONE);
|
|
|
+ return actionStatService.countInactiveFansNum(accountId,start,end);
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<AccountStat> queryAccountStatByDate(String accountId, String startDate, String endDate) {
|
|
|
+ return list(Wrappers.<AccountStat>lambdaQuery()
|
|
|
+ .eq(AccountStat::getAccountId,accountId)
|
|
|
+ .ge(AccountStat::getStatDate,startDate)
|
|
|
+ .le(AccountStat::getStatDate,endDate));
|
|
|
+ }
|
|
|
}
|