|
@@ -1,6 +1,7 @@
|
|
|
package com.idiot.operationbackend.controller;
|
|
|
|
|
|
import com.idiot.operationbackend.entity.Account;
|
|
|
+import com.idiot.operationbackend.entity.AccountFans;
|
|
|
import com.idiot.operationbackend.entity.AccountFansStat;
|
|
|
import com.idiot.operationbackend.entity.FansActionStat;
|
|
|
import com.idiot.operationbackend.service.facade.AccountFansService;
|
|
@@ -11,7 +12,8 @@ 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.StatData;
|
|
|
+import com.idiot.operationbackend.vo.GeneralStatData;
|
|
|
+
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.slf4j.Logger;
|
|
@@ -129,8 +131,8 @@ public class IndexController {
|
|
|
public ResponseEntity<JsonResult<Map<String,Object>>> getFansGrowthStat (@PathVariable String accountId,
|
|
|
@RequestHeader String token,
|
|
|
@RequestParam String type,
|
|
|
- @RequestParam(required = false) String startDate,
|
|
|
- @RequestParam(required = false) String endDate) {
|
|
|
+ @RequestParam String startDate,
|
|
|
+ @RequestParam String endDate) {
|
|
|
String userId = JwtTokenUtil.getUserId(token);
|
|
|
if (!checkDate(startDate,endDate)){
|
|
|
throw new CustomException(500,"请选择开始和结束时间!");
|
|
@@ -141,17 +143,17 @@ public class IndexController {
|
|
|
LocalDate start = LocalDate.parse(startDate);
|
|
|
LocalDate end= LocalDate.parse(endDate);
|
|
|
long days = end.toEpochDay() - start.toEpochDay();
|
|
|
- List<StatData> statDataList = queryFansGrowthStatData(accountId, type, start, end);
|
|
|
+ List<GeneralStatData> statDataList = queryFansGrowthStatData(accountId, type, start, end);
|
|
|
long newNum =0;
|
|
|
long addNum =0;
|
|
|
long inactiveNum =0;
|
|
|
long cancelNum =0;
|
|
|
BigDecimal ave =BigDecimal.ZERO;
|
|
|
if (CollectionUtils.isEmpty(statDataList)) {
|
|
|
- newNum = statDataList.parallelStream().mapToLong(StatData::getNewNum).sum();
|
|
|
- addNum = statDataList.parallelStream().mapToLong(StatData::getAddNum).sum();
|
|
|
- inactiveNum = statDataList.parallelStream().mapToLong(StatData::getInactiveNum).sum();
|
|
|
- cancelNum = statDataList.parallelStream().mapToLong(StatData::getCancelNum).sum();
|
|
|
+ newNum = statDataList.parallelStream().mapToLong(GeneralStatData::getNewNum).sum();
|
|
|
+ addNum = statDataList.parallelStream().mapToLong(GeneralStatData::getAddNum).sum();
|
|
|
+ inactiveNum = statDataList.parallelStream().mapToLong(GeneralStatData::getInactiveNum).sum();
|
|
|
+ cancelNum = statDataList.parallelStream().mapToLong(GeneralStatData::getCancelNum).sum();
|
|
|
if (days == 0){
|
|
|
days = 1;
|
|
|
}
|
|
@@ -168,6 +170,31 @@ public class IndexController {
|
|
|
return ResponseEntity.ok(JsonResult.success(result));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @GetMapping("/fansProperty/{accountId}")
|
|
|
+ @ApiOperation(value = "查询单个公众号--粉丝属性")
|
|
|
+ public ResponseEntity<JsonResult<Map<String,Object>>> getFansPropertyStat(
|
|
|
+ @RequestHeader String token,
|
|
|
+ @PathVariable String accountId,
|
|
|
+ @RequestParam(required = false) String startDate,
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
+ String userId = JwtTokenUtil.getUserId(token);
|
|
|
+ logger.info("用户:{}查询首页单个公众号:{}属性,startDate:{},endDate:{} --->start",userId,accountId,startDate,endDate);
|
|
|
+ List<AccountFans> accountFans;
|
|
|
+ Map<String,Object> result = new HashMap<>(4);
|
|
|
+ if (!StringUtils.isEmpty(startDate) && !StringUtils.isEmpty(endDate) ){
|
|
|
+ accountFans = fansService.queryFansByDateAndDate(accountId,startDate,endDate);
|
|
|
+ }else {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.info("用户:{}查询首页单个公众号:{}属性,startDate:{},endDate:{} --->end",userId,accountId,startDate,endDate);
|
|
|
+ return null;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 统计粉丝数据 好难受写不出完美的代码
|
|
|
* @author wangxiao
|
|
@@ -178,9 +205,9 @@ public class IndexController {
|
|
|
* @param endDate
|
|
|
* @return java.util.List<com.idiot.operationbackend.vo.StatData>
|
|
|
*/
|
|
|
- private List<StatData> queryFansGrowthStatData(String accountId, String type, LocalDate startDate, LocalDate endDate) {
|
|
|
-
|
|
|
+ private List<GeneralStatData> queryFansGrowthStatData(String accountId, String type, LocalDate startDate, LocalDate endDate) {
|
|
|
|
|
|
+ // 粉丝增长数据 因为能选择今天 需要在 用户动作分析里面取数据。或者一小时分析一次数据
|
|
|
long disValue = 0;
|
|
|
if (HOUR.equals(type)) {
|
|
|
disValue = 7200;
|
|
@@ -202,8 +229,8 @@ public class IndexController {
|
|
|
}
|
|
|
long start = startLocalDate.toEpochSecond(Constants.DEFAULT_ZONE);
|
|
|
long end = endLocalDate.toEpochSecond(Constants.DEFAULT_ZONE);
|
|
|
- List<StatData> statDataList = new ArrayList<>();
|
|
|
- StatData statData = null;
|
|
|
+ List<GeneralStatData> statDataList = new ArrayList<>();
|
|
|
+ GeneralStatData statData = null;
|
|
|
List<FansActionStat> tempStatList = null;
|
|
|
while (start<=end){
|
|
|
long finalStart = start;
|
|
@@ -224,7 +251,7 @@ public class IndexController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 统计
|
|
|
+ * 统计 粉丝增长 时间段
|
|
|
* @author wangxiao
|
|
|
* @date 16:45 2020/9/16
|
|
|
* @param fansActionStats
|
|
@@ -233,11 +260,11 @@ public class IndexController {
|
|
|
* @param type
|
|
|
* @return com.idiot.operationbackend.vo.StatData
|
|
|
*/
|
|
|
- private StatData countStatData (List<FansActionStat> fansActionStats,long start,long end,String type) {
|
|
|
+ private GeneralStatData countStatData (List<FansActionStat> fansActionStats, long start, long end, String type) {
|
|
|
|
|
|
LocalDateTime startDateTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(start),Constants.DEFAULT_ZONE);
|
|
|
LocalDateTime endDateTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(end),Constants.DEFAULT_ZONE);
|
|
|
- StatData statData = new StatData();
|
|
|
+ GeneralStatData statData = new GeneralStatData();
|
|
|
long newNum = 0;
|
|
|
long cancelNum = 0;
|
|
|
long inactiveNum = 0;
|
|
@@ -267,6 +294,49 @@ public class IndexController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 统计粉丝属性
|
|
|
+ * @author wangxiao
|
|
|
+ * @date 18:57 2020/9/16
|
|
|
+ * @param fans
|
|
|
+ * @param map
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ private void statFansProperty(List<AccountFans> fans,Map<String,Object> map) {
|
|
|
+ long totalFansNum = 0;
|
|
|
+ long manNum = 0;
|
|
|
+ BigDecimal manRate = BigDecimal.ZERO;
|
|
|
+ long womanNum = 0;
|
|
|
+ BigDecimal womanRate = BigDecimal.ZERO;
|
|
|
+ Map<String,Long> subscribeScene = null;
|
|
|
+ if (!CollectionUtils.isEmpty(fans)) {
|
|
|
+ totalFansNum = fans.size();
|
|
|
+ manNum = fans.parallelStream().filter(e->1==e.getSex()).count();
|
|
|
+ womanNum = fans.parallelStream().filter(e->2==e.getSex()).count();
|
|
|
+ manRate = BigDecimal.valueOf((manNum*100)/totalFansNum).setScale(2);
|
|
|
+ womanRate = BigDecimal.valueOf((womanNum*100)/totalFansNum).setScale(2);
|
|
|
+ subscribeScene = fans.stream().collect(Collectors.groupingBy(AccountFans::getSubscribeScene,Collectors.reducing(0L,accountFans -> 1L,Long::sum)));
|
|
|
+ }
|
|
|
+ Map<String,Object> base = new HashMap<>(6);
|
|
|
+ base.put("totalFansNum",totalFansNum);
|
|
|
+ base.put("manNum",manNum);
|
|
|
+ base.put("womanNum",womanNum);
|
|
|
+ base.put("manRate",manRate);
|
|
|
+ base.put("womanRate",womanRate);
|
|
|
+ map.put("base",base);
|
|
|
+ Map<String,Object> sex = new HashMap<>(4);
|
|
|
+ sex.put("manNum",manNum);
|
|
|
+ sex.put("womanNum",womanNum);
|
|
|
+ sex.put("manRate",manRate);
|
|
|
+ sex.put("womanRate",womanRate);
|
|
|
+ map.put("sex",sex);
|
|
|
+ map.put("subscribeScene",subscribeScene);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|