|
@@ -2,18 +2,18 @@ package com.idiot.operationbackend.controller;
|
|
|
|
|
|
import com.idiot.operationbackend.entity.Account;
|
|
|
import com.idiot.operationbackend.entity.AccountStat;
|
|
|
+import com.idiot.operationbackend.entity.ArticleStat;
|
|
|
import com.idiot.operationbackend.entity.FansActionStat;
|
|
|
-import com.idiot.operationbackend.service.facade.AccountFansService;
|
|
|
-import com.idiot.operationbackend.service.facade.AccountStatService;
|
|
|
-import com.idiot.operationbackend.service.facade.AccountService;
|
|
|
-import com.idiot.operationbackend.service.facade.FansActionStatService;
|
|
|
+import com.idiot.operationbackend.service.facade.*;
|
|
|
import com.idiot.operationbackend.support.Constants;
|
|
|
import com.idiot.operationbackend.support.CustomException;
|
|
|
import com.idiot.operationbackend.support.JsonResult;
|
|
|
import com.idiot.operationbackend.util.JwtTokenUtil;
|
|
|
+import com.idiot.operationbackend.vo.ArticleStatData;
|
|
|
import com.idiot.operationbackend.vo.GeneralStatData;
|
|
|
|
|
|
import com.idiot.operationbackend.vo.NumberStatData;
|
|
|
+import com.idiot.operationbackend.vo.RemainStatData;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.slf4j.Logger;
|
|
@@ -67,6 +67,9 @@ public class IndexController {
|
|
|
@Autowired
|
|
|
private FansActionStatService actionStatService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ArticleStatService articleStatService;
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -193,7 +196,9 @@ public class IndexController {
|
|
|
@RequestParam String startDate,
|
|
|
@RequestParam String endDate) {
|
|
|
String userId = JwtTokenUtil.getUserId(token);
|
|
|
- checkDate(startDate,endDate);
|
|
|
+ if (!checkDate(startDate,endDate)){
|
|
|
+ throw new CustomException(500,"请选择查询时间范围!");
|
|
|
+ }
|
|
|
logger.info("用户:{}查询首页单个公众号:{}粉丝活跃度,startDate:{},endDate:{} --->start",userId,accountId,startDate,endDate);
|
|
|
List<AccountStat> accountStats = accountStatService.queryAccountStatByDate(accountId,startDate,endDate);
|
|
|
logger.info("用户:{}查询首页单个公众号:{}粉丝活跃度,startDate:{},endDate:{} --->end",userId,accountId,startDate,endDate);
|
|
@@ -201,6 +206,50 @@ public class IndexController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @GetMapping("/remain/{accountId}")
|
|
|
+ @ApiOperation(value = "查询单个公众号--粉丝忠诚度")
|
|
|
+ public ResponseEntity<JsonResult<List<RemainStatData>>> getFansRemainStat(@RequestHeader String token,
|
|
|
+ @PathVariable String accountId,
|
|
|
+ @RequestParam String date) {
|
|
|
+ String userId = JwtTokenUtil.getUserId(token);
|
|
|
+ if (StringUtils.isEmpty(date)){
|
|
|
+ throw new CustomException(500,"请选择查询时间!");
|
|
|
+ }
|
|
|
+ LocalDateTime endDate = Constants.toLocalDateTime(date);
|
|
|
+ LocalDateTime startDate = Constants.toLocalDateTime(date).plusDays(-7);
|
|
|
+ logger.info("用户:{}查询首页单个公众号:{}粉丝忠诚度,date:{} --->start",userId,accountId,date);
|
|
|
+ List<AccountStat> accountStats = accountStatService.queryAccountStatByDate(accountId,startDate,endDate);
|
|
|
+ List<RemainStatData> remainStatData = statFansRemainData(accountStats);
|
|
|
+ if (Objects.isNull(remainStatData)) {
|
|
|
+ remainStatData = new ArrayList<>();
|
|
|
+ }
|
|
|
+ logger.info("用户:{}查询首页单个公众号:{}粉丝忠诚度,date:{} --->end",userId,accountId,date);
|
|
|
+ return ResponseEntity.ok(JsonResult.success(remainStatData));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/articles/{accountId}")
|
|
|
+ @ApiOperation(value = "查询单个公众号--图文影响力")
|
|
|
+ public ResponseEntity<JsonResult<List<ArticleStatData>>> getFansPageStat(@RequestHeader String token,
|
|
|
+ @PathVariable String accountId,
|
|
|
+ @RequestParam String startDate,
|
|
|
+ @RequestParam String endDate) {
|
|
|
+ String userId = JwtTokenUtil.getUserId(token);
|
|
|
+ if (!checkDate(startDate,endDate)){
|
|
|
+ throw new CustomException(500,"请选择查询时间!");
|
|
|
+ }
|
|
|
+ logger.info("用户:{}查询首页单个公众号:{}图文影响力,startDate:{},endDate:{} --->start",userId,accountId,startDate,endDate);
|
|
|
+ List<ArticleStat> articleStats = articleStatService.queryArticleStatByDate(accountId,startDate,endDate);
|
|
|
+ List<ArticleStatData> articleStatData = statArticleData(articleStats);
|
|
|
+ if (CollectionUtils.isEmpty(articleStatData)){
|
|
|
+ articleStatData = new ArrayList<>();
|
|
|
+ }
|
|
|
+ logger.info("用户:{}查询首页单个公众号:{}图文影响力,startDate:{},endDate:{} --->start",userId,accountId,startDate,endDate);
|
|
|
+ return ResponseEntity.ok(JsonResult.success(articleStatData));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -266,6 +315,8 @@ public class IndexController {
|
|
|
return !(StringUtils.isEmpty(start) | StringUtils.isEmpty(end));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 统计 粉丝增长 时间段
|
|
|
* @author wangxiao
|
|
@@ -327,8 +378,90 @@ public class IndexController {
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 统计留存粉丝
|
|
|
+ * @author wangxiao
|
|
|
+ * @date 14:22 2020/9/17
|
|
|
+ * @param accountStats
|
|
|
+ * @return java.util.List<com.idiot.operationbackend.vo.RemainStatData>
|
|
|
+ */
|
|
|
+ private List<RemainStatData> statFansRemainData(List<AccountStat> accountStats) {
|
|
|
+ if (CollectionUtils.isEmpty(accountStats)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ int size = accountStats.size();
|
|
|
+ List<RemainStatData> remainStatDataList = new ArrayList<>(size);
|
|
|
+ String statDate = null;
|
|
|
+ Long newNum = null;
|
|
|
+ Long totalNum = null;
|
|
|
+ RemainStatData remain = null;
|
|
|
+ for (AccountStat temp : accountStats) {
|
|
|
+ statDate = temp.getStatDate();
|
|
|
+ newNum = temp.getNewNum();
|
|
|
+ totalNum = temp.getTotalFansNum();
|
|
|
+ remain = new RemainStatData(statDate,newNum);
|
|
|
+ remain.setDay1Num(calcRemain(accountStats,totalNum,statDate,1));
|
|
|
+ remain.setDay2Num(calcRemain(accountStats,totalNum,statDate,2));
|
|
|
+ remain.setDay3Num(calcRemain(accountStats,totalNum,statDate,3));
|
|
|
+ remain.setDay4Num(calcRemain(accountStats,totalNum,statDate,4));
|
|
|
+ remain.setDay5Num(calcRemain(accountStats,totalNum,statDate,5));
|
|
|
+ remain.setDay6Num(calcRemain(accountStats,totalNum,statDate,6));
|
|
|
+ remain.setDay7Num(calcRemain(accountStats,totalNum,statDate,7));
|
|
|
+ remainStatDataList.add(remain);
|
|
|
+ }
|
|
|
+ return remainStatDataList;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 计算留存数
|
|
|
+ * @author wangxiao
|
|
|
+ * @date 14:35 2020/9/17
|
|
|
+ * @param accountStats 数组
|
|
|
+ * @param nowTotal 当前总数
|
|
|
+ * @param targetIndex 几天前下表
|
|
|
+ * @param nowStatDate 当前统计日期
|
|
|
+ * @return long
|
|
|
+ */
|
|
|
+ private long calcRemain (List<AccountStat> accountStats,long nowTotal,String nowStatDate,int targetIndex) {
|
|
|
+ long remainNum;
|
|
|
+ LocalDate nowDate = LocalDate.parse(nowStatDate,Constants.DATE_FORMATTER);
|
|
|
+ String targetStatDate = nowDate.plusDays(-targetIndex).format(Constants.DATE_FORMATTER);
|
|
|
+ remainNum = accountStats.stream()
|
|
|
+ .filter(e->targetStatDate.equals(e.getStatDate()))
|
|
|
+ .findAny().map(e->e.getTotalFansNum()-nowTotal)
|
|
|
+ .orElse(0L);
|
|
|
+ return remainNum;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 统计图文影响力
|
|
|
+ * @author wangxiao
|
|
|
+ * @date 16:06 2020/9/17
|
|
|
+ * @param articleStats
|
|
|
+ * @return java.util.List<com.idiot.operationbackend.vo.ArticleStatData>
|
|
|
+ */
|
|
|
+ private List<ArticleStatData> statArticleData (List<ArticleStat> articleStats) {
|
|
|
+ if (CollectionUtils.isEmpty(articleStats)){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Map<String,List<ArticleStat>> temp = articleStats.stream().collect(Collectors.groupingBy(ArticleStat::getStatDate));
|
|
|
+ List<ArticleStatData> articleStatData = new ArrayList<>(temp.size());
|
|
|
+ List<ArticleStat> var = null;
|
|
|
+ ArticleStatData result = null;
|
|
|
+ for (Map.Entry<String,List<ArticleStat>> entry : temp.entrySet()) {
|
|
|
+ var = entry.getValue();
|
|
|
+ result = new ArticleStatData(entry.getKey(),var);
|
|
|
+ result.setShareUser(var.stream().mapToLong(ArticleStat::getShareUser).sum());
|
|
|
+ result.setShareCount(var.stream().mapToLong(ArticleStat::getShareCount).sum());
|
|
|
+ result.setAddToFavCount(var.stream().mapToLong(ArticleStat::getAddToFavCount).sum());
|
|
|
+ result.setAddToFavUser(var.stream().mapToLong(ArticleStat::getAddToFavUser).sum());
|
|
|
+ result.setIntPageReadCount(var.stream().mapToLong(ArticleStat::getIntPageReadCount).sum());
|
|
|
+ result.setIntPageReadUser(var.stream().mapToLong(ArticleStat::getIntPageReadUser).sum());
|
|
|
+ result.setOriPageReadCount(var.stream().mapToLong(ArticleStat::getOriPageReadCount).sum());
|
|
|
+ result.setOriPageReadUser(var.stream().mapToLong(ArticleStat::getOriPageReadUser).sum());
|
|
|
+ articleStatData.add(result);
|
|
|
+ }
|
|
|
+ return articleStatData;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|