|
@@ -7,14 +7,16 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.idiot.operationbackend.entity.AccountFansStat;
|
|
|
import com.idiot.operationbackend.mappers.AccountFansStatMapper;
|
|
|
import com.idiot.operationbackend.service.facade.AccountFansStatService;
|
|
|
+import com.idiot.operationbackend.service.facade.FansActionStatService;
|
|
|
import com.idiot.operationbackend.service.facade.WeChatService;
|
|
|
import com.idiot.operationbackend.support.Constants;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import javax.servlet.http.Cookie;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.time.ZoneOffset;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -32,6 +34,10 @@ public class AccountFansStatServiceImpl extends ServiceImpl<AccountFansStatMappe
|
|
|
private WeChatService weChatService;
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FansActionStatService actionStatService;
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public List<AccountFansStat> queryByDateAndAccIds(List<String> accountIds, String statDate) {
|
|
|
return list(Wrappers.<AccountFansStat>lambdaQuery().eq(AccountFansStat::getStatDate,statDate)
|
|
@@ -51,12 +57,14 @@ public class AccountFansStatServiceImpl extends ServiceImpl<AccountFansStatMappe
|
|
|
@Async("asyncExecutor")
|
|
|
public void statAccountFansData(String accountId) {
|
|
|
String yesterday = Constants.DATE_FORMATTER.format(LocalDate.now().plusDays(-1));
|
|
|
+ String beforeDay = Constants.DATE_FORMATTER.format(LocalDate.now().plusDays(-2));
|
|
|
String jsonStr = weChatService.getFansSunmmary(accountId,yesterday,yesterday);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(jsonStr);
|
|
|
JSONArray jsonArray = jsonObject.getJSONArray("list");
|
|
|
int size = jsonArray.size();
|
|
|
int newNum = 0;
|
|
|
int cancelNum = 0;
|
|
|
+ int addNum = 0;
|
|
|
JSONObject tempObject = null;
|
|
|
// 昨日增减
|
|
|
for (int i = 0; i < size; i++) {
|
|
@@ -74,9 +82,41 @@ public class AccountFansStatServiceImpl extends ServiceImpl<AccountFansStatMappe
|
|
|
tempObject = jsonArray.getJSONObject(i);
|
|
|
totalNum += tempObject.getInteger("cumulate_user");
|
|
|
}
|
|
|
+ // 昨日和前日 数据
|
|
|
+ List<AccountFansStat> statData = baseMapper.selectByDateAndAccId(accountId,yesterday,beforeDay);
|
|
|
+ // 昨日活跃数量
|
|
|
+ int inactiveNum = inactiveFansNum(accountId,yesterday);
|
|
|
+ AccountFansStat ydData = statData.stream().filter(e->yesterday.equals(e.getStatDate())).findFirst().orElseGet(AccountFansStat::new);
|
|
|
+ addNum = newNum-cancelNum;
|
|
|
+ ydData.setTotalFansNum(totalNum);
|
|
|
+ ydData.setNewNum(newNum);
|
|
|
+ ydData.setCancelNum(cancelNum);
|
|
|
+ ydData.setStatDate(yesterday);
|
|
|
+ ydData.setAccountId(accountId);
|
|
|
+ ydData.setAddNum(addNum);
|
|
|
+ ydData.setInactiveNum(inactiveNum);
|
|
|
+
|
|
|
+ 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()));
|
|
|
+ ydData.setCancelRate(Constants.calcRate(ydData.getCancelNum(), e.getCancelNum()));
|
|
|
+ ydData.setInactiveRate(Constants.calcRate(ydData.getInactiveNum(), e.getInactiveNum()));
|
|
|
+ ydData.setPageReadRate(Constants.calcRate(ydData.getPageReadNum(),e.getPageReadNum()));
|
|
|
+ ydData.setInactiveRate(Constants.calcRate(ydData.getInactiveNum(),e.getInactiveNum()));
|
|
|
+ return e;
|
|
|
+ });
|
|
|
+ saveOrUpdate(ydData);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
-
|
|
|
+ @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();
|
|
|
+ return actionStatService.countInactiveFansNum(accountId,start,end);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
}
|