|
@@ -7,6 +7,7 @@ import com.idiot.operationbackend.service.facade.AccountService;
|
|
|
import com.idiot.operationbackend.support.Constants;
|
|
|
import com.idiot.operationbackend.support.JsonResult;
|
|
|
import com.idiot.operationbackend.util.JwtTokenUtil;
|
|
|
+import com.idiot.operationbackend.vo.StatData;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.slf4j.Logger;
|
|
@@ -14,10 +15,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestHeader;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
@@ -25,6 +23,8 @@ import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.idiot.operationbackend.support.Constants.calcRate;
|
|
|
+
|
|
|
/**
|
|
|
* 运营星 首页
|
|
|
* @author wang xiao
|
|
@@ -52,19 +52,20 @@ public class IndexController {
|
|
|
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);
|
|
|
String beforeYesterdayStr = Constants.DATE_FORMATTER.format(LocalDate.now().plusDays(-2));
|
|
|
List<AccountFansStat> beforeYdStat = fansStatService.queryByDateAndAccIds(accountIds,beforeYesterdayStr);
|
|
|
|
|
|
logger.info("用户:{}首页概览数据计算中---ing",userId);
|
|
|
+ // 所有公众号昨日数据
|
|
|
int totalNum = ydStatData.stream().mapToInt(AccountFansStat::getTotalFansNum).sum();
|
|
|
int addNum = ydStatData.stream().mapToInt(AccountFansStat::getAddNum).sum();
|
|
|
int cancelNum = ydStatData.stream().mapToInt(AccountFansStat::getCancelNum).sum();
|
|
|
int newNum = ydStatData.stream().mapToInt(AccountFansStat::getNewNum).sum();
|
|
|
int inactiveNum = ydStatData.stream().mapToInt(AccountFansStat::getInactiveNum).sum();
|
|
|
-
|
|
|
+ // 所有公众号前日数据
|
|
|
int bfCancelNum = beforeYdStat.stream().mapToInt(AccountFansStat::getCancelNum).sum();
|
|
|
int bfAddNum = beforeYdStat.stream().mapToInt(AccountFansStat::getAddNum).sum();
|
|
|
int bfNewNum = beforeYdStat.stream().mapToInt(AccountFansStat::getNewNum).sum();
|
|
@@ -86,16 +87,27 @@ public class IndexController {
|
|
|
return ResponseEntity.ok(JsonResult.success(result));
|
|
|
}
|
|
|
|
|
|
+ @GetMapping("/single/{accountId}")
|
|
|
+ @ApiOperation(value = "查询单个公众号昨日统计数据概览")
|
|
|
+ public ResponseEntity<JsonResult<AccountFansStat>> 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);
|
|
|
+ logger.info("用户:{}查询首页单个公众号:{}数据统计概览---end",userId,accountId);
|
|
|
+ return ResponseEntity.ok(JsonResult.success(fansStat));
|
|
|
+ }
|
|
|
|
|
|
|
|
|
-
|
|
|
- private BigDecimal calcRate(int now, int before) {
|
|
|
- if (0 == before) {
|
|
|
- return BigDecimal.valueOf((now*100.0)/1.0);
|
|
|
- } else if (0 == now) {
|
|
|
- return Constants.ZERO_RATE;
|
|
|
- }else {
|
|
|
- return BigDecimal.valueOf(((now - before) * 100) / before).setScale(2);
|
|
|
- }
|
|
|
+ @GetMapping("/fansGrowth/{accountId}")
|
|
|
+ @ApiOperation(value = "查询单个公众号--粉丝增长")
|
|
|
+ public ResponseEntity<JsonResult<List<StatData>>> getFansGrowthStat (@PathVariable String accountId,
|
|
|
+ @RequestHeader String token,
|
|
|
+ @RequestParam String type,
|
|
|
+ @RequestParam(required = false) String startDate,
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
+ return null;
|
|
|
}
|
|
|
+
|
|
|
}
|