|
@@ -1,11 +1,10 @@
|
|
|
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.AccountStat;
|
|
|
import com.idiot.operationbackend.entity.FansActionStat;
|
|
|
import com.idiot.operationbackend.service.facade.AccountFansService;
|
|
|
-import com.idiot.operationbackend.service.facade.AccountFansStatService;
|
|
|
+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.support.Constants;
|
|
@@ -14,6 +13,7 @@ import com.idiot.operationbackend.support.JsonResult;
|
|
|
import com.idiot.operationbackend.util.JwtTokenUtil;
|
|
|
import com.idiot.operationbackend.vo.GeneralStatData;
|
|
|
|
|
|
+import com.idiot.operationbackend.vo.NumberStatData;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.slf4j.Logger;
|
|
@@ -29,7 +29,6 @@ import java.math.BigDecimal;
|
|
|
import java.time.Instant;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.time.LocalTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -60,7 +59,7 @@ public class IndexController {
|
|
|
private AccountService accountService;
|
|
|
|
|
|
@Autowired
|
|
|
- private AccountFansStatService fansStatService;
|
|
|
+ private AccountStatService accountStatService;
|
|
|
|
|
|
@Autowired
|
|
|
private AccountFansService fansService;
|
|
@@ -73,32 +72,32 @@ public class IndexController {
|
|
|
|
|
|
@GetMapping("/summary")
|
|
|
@ApiOperation(value = "查询公众号昨日统计数据概览")
|
|
|
- public ResponseEntity<JsonResult<AccountFansStat>> getFansStat (@RequestHeader String token) {
|
|
|
+ public ResponseEntity<JsonResult<AccountStat>> getFansStat (@RequestHeader String token) {
|
|
|
String userId = JwtTokenUtil.getUserId(token);
|
|
|
logger.info("用户:{}查询首页数据统计概览---start",userId);
|
|
|
List<Account> accounts = accountService.queryAccountByUserId(userId);
|
|
|
List<String> accountIds = accounts.stream().map(Account::getId).collect(Collectors.toList());
|
|
|
// 查询数据 不知道怎么优化
|
|
|
String yesterdayStr = Constants.DATE_FORMATTER.format(LocalDate.now().plusDays(-1));
|
|
|
- List<AccountFansStat> ydStatData = fansStatService.queryByDateAndAccIds(accountIds,yesterdayStr);
|
|
|
+ List<AccountStat> ydStatData = accountStatService.queryByDateAndAccIds(accountIds,yesterdayStr);
|
|
|
String beforeYesterdayStr = Constants.DATE_FORMATTER.format(LocalDate.now().plusDays(-2));
|
|
|
- List<AccountFansStat> beforeYdStat = fansStatService.queryByDateAndAccIds(accountIds,beforeYesterdayStr);
|
|
|
+ List<AccountStat> beforeYdStat = accountStatService.queryByDateAndAccIds(accountIds,beforeYesterdayStr);
|
|
|
|
|
|
logger.info("用户:{}首页概览数据计算中---ing",userId);
|
|
|
// 所有公众号昨日数据
|
|
|
- long totalNum = ydStatData.stream().mapToLong(AccountFansStat::getTotalFansNum).sum();
|
|
|
- long addNum = ydStatData.stream().mapToLong(AccountFansStat::getAddNum).sum();
|
|
|
- long cancelNum = ydStatData.stream().mapToLong(AccountFansStat::getCancelNum).sum();
|
|
|
- long newNum = ydStatData.stream().mapToLong(AccountFansStat::getNewNum).sum();
|
|
|
- long inactiveNum = ydStatData.stream().mapToLong(AccountFansStat::getInactiveNum).sum();
|
|
|
+ long totalNum = ydStatData.stream().mapToLong(AccountStat::getTotalFansNum).sum();
|
|
|
+ long addNum = ydStatData.stream().mapToLong(AccountStat::getAddNum).sum();
|
|
|
+ long cancelNum = ydStatData.stream().mapToLong(AccountStat::getCancelNum).sum();
|
|
|
+ long newNum = ydStatData.stream().mapToLong(AccountStat::getNewNum).sum();
|
|
|
+ long inactiveNum = ydStatData.stream().mapToLong(AccountStat::getInactiveNum).sum();
|
|
|
// 所有公众号前日数据
|
|
|
- long bfCancelNum = beforeYdStat.stream().mapToLong(AccountFansStat::getCancelNum).sum();
|
|
|
- long bfAddNum = beforeYdStat.stream().mapToLong(AccountFansStat::getAddNum).sum();
|
|
|
- long bfNewNum = beforeYdStat.stream().mapToLong(AccountFansStat::getNewNum).sum();
|
|
|
- long bfInactiveNum = beforeYdStat.stream().mapToLong(AccountFansStat::getInactiveNum).sum();
|
|
|
- long bfTotalNum = beforeYdStat.stream().mapToLong(AccountFansStat::getTotalFansNum).sum();
|
|
|
+ long bfCancelNum = beforeYdStat.stream().mapToLong(AccountStat::getCancelNum).sum();
|
|
|
+ long bfAddNum = beforeYdStat.stream().mapToLong(AccountStat::getAddNum).sum();
|
|
|
+ long bfNewNum = beforeYdStat.stream().mapToLong(AccountStat::getNewNum).sum();
|
|
|
+ long bfInactiveNum = beforeYdStat.stream().mapToLong(AccountStat::getInactiveNum).sum();
|
|
|
+ long bfTotalNum = beforeYdStat.stream().mapToLong(AccountStat::getTotalFansNum).sum();
|
|
|
|
|
|
- AccountFansStat result = new AccountFansStat();
|
|
|
+ AccountStat result = new AccountStat();
|
|
|
result.setAddNum(addNum);
|
|
|
result.setNewNum(newNum);
|
|
|
result.setCancelNum(cancelNum);
|
|
@@ -115,18 +114,18 @@ public class IndexController {
|
|
|
|
|
|
@GetMapping("/single/{accountId}")
|
|
|
@ApiOperation(value = "查询单个公众号昨日统计数据概览")
|
|
|
- public ResponseEntity<JsonResult<AccountFansStat>> getSingleFansStat (@RequestHeader String token,
|
|
|
+ public ResponseEntity<JsonResult<AccountStat>> getSingleFansStat (@RequestHeader String token,
|
|
|
@PathVariable String accountId) {
|
|
|
String userId = JwtTokenUtil.getUserId(token);
|
|
|
logger.info("用户:{}查询首页单个公众号:{}数据统计概览---start",userId,accountId);
|
|
|
String yesterdayStr = Constants.DATE_FORMATTER.format(LocalDate.now().plusDays(-1));
|
|
|
- AccountFansStat fansStat = fansStatService.queryByDateAndAccountId(accountId,yesterdayStr);
|
|
|
+ AccountStat fansStat = accountStatService.queryByDateAndAccountId(accountId,yesterdayStr);
|
|
|
logger.info("用户:{}查询首页单个公众号:{}数据统计概览---end",userId,accountId);
|
|
|
return ResponseEntity.ok(JsonResult.success(fansStat));
|
|
|
}
|
|
|
|
|
|
|
|
|
- @GetMapping("/fansGrowth/{accountId}")
|
|
|
+ @GetMapping("/growth/{accountId}")
|
|
|
@ApiOperation(value = "查询单个公众号--粉丝增长")
|
|
|
public ResponseEntity<JsonResult<Map<String,Object>>> getFansGrowthStat (@PathVariable String accountId,
|
|
|
@RequestHeader String token,
|
|
@@ -171,7 +170,7 @@ public class IndexController {
|
|
|
}
|
|
|
|
|
|
|
|
|
- @GetMapping("/fansProperty/{accountId}")
|
|
|
+ @GetMapping("/property/{accountId}")
|
|
|
@ApiOperation(value = "查询单个公众号--粉丝属性")
|
|
|
public ResponseEntity<JsonResult<Map<String,Object>>> getFansPropertyStat(
|
|
|
@RequestHeader String token,
|
|
@@ -179,22 +178,32 @@ public class IndexController {
|
|
|
@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;
|
|
|
+ logger.info("用户:{}查询首页单个公众号:{}粉丝属性,startDate:{},endDate:{} --->start",userId,accountId,startDate,endDate);
|
|
|
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;
|
|
|
+ List<NumberStatData> numberStatData = fansService.statByFansProperty(accountId,startDate,endDate);
|
|
|
+ statFansProperty(numberStatData,result);
|
|
|
+ logger.info("用户:{}查询首页单个公众号:{}粉丝属性,startDate:{},endDate:{} --->end",userId,accountId,startDate,endDate);
|
|
|
+ return ResponseEntity.ok(JsonResult.success(result));
|
|
|
+ }
|
|
|
|
|
|
+ @GetMapping("/inactive/{accountId}")
|
|
|
+ @ApiOperation(value = "查询单个公众号--粉丝活跃度")
|
|
|
+ public ResponseEntity<JsonResult<Map<String,Object>>> getFansInactiveStat(@RequestHeader String token,
|
|
|
+ @PathVariable String accountId,
|
|
|
+ @RequestParam String startDate,
|
|
|
+ @RequestParam String endDate) {
|
|
|
+ String userId = JwtTokenUtil.getUserId(token);
|
|
|
+ logger.info("用户:{}查询首页单个公众号:{}粉丝活跃度,startDate:{},endDate:{} --->start",userId,accountId,startDate,endDate);
|
|
|
+ Map<String,Object> result = new HashMap<>(4);
|
|
|
+ List<NumberStatData> numberStatData = fansService.statByFansProperty(accountId,startDate,endDate);
|
|
|
+ statFansProperty(numberStatData,result);
|
|
|
+ logger.info("用户:{}查询首页单个公众号:{}粉丝活跃度,startDate:{},endDate:{} --->end",userId,accountId,startDate,endDate);
|
|
|
+ return ResponseEntity.ok(JsonResult.success(result));
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 统计粉丝数据 好难受写不出完美的代码
|
|
|
* @author wangxiao
|
|
@@ -221,8 +230,8 @@ public class IndexController {
|
|
|
}else {
|
|
|
throw new CustomException(500,"请你选择正确的时间统计类型!");
|
|
|
}
|
|
|
- LocalDateTime startLocalDate = startDate.atTime(LocalTime.of(0,0,0));
|
|
|
- LocalDateTime endLocalDate = endDate.plusDays(1).atTime(LocalTime.of(0,0,0));
|
|
|
+ LocalDateTime startLocalDate = startDate.atTime(Constants.DEFAULT_TIME);
|
|
|
+ LocalDateTime endLocalDate = endDate.plusDays(1).atTime(Constants.DEFAULT_TIME);
|
|
|
List<FansActionStat> fansActionStats = actionStatService.queryFansActionStat(accountId,startLocalDate,endLocalDate);
|
|
|
if (CollectionUtils.isEmpty(fansActionStats)) {
|
|
|
throw new CustomException(500,"暂无数据!");
|
|
@@ -298,40 +307,15 @@ public class IndexController {
|
|
|
* 统计粉丝属性
|
|
|
* @author wangxiao
|
|
|
* @date 18:57 2020/9/16
|
|
|
- * @param fans
|
|
|
+ * @param fansData
|
|
|
* @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);
|
|
|
-
|
|
|
+ private void statFansProperty(List<NumberStatData> fansData,Map<String,Object> map) {
|
|
|
+ if (!CollectionUtils.isEmpty(fansData)) {
|
|
|
+ Map<String,List<NumberStatData>> numData = fansData.stream().collect(Collectors.groupingBy(NumberStatData::getType));
|
|
|
+ map.putAll(numData);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|