|
@@ -1,12 +1,101 @@
|
|
|
package com.idiot.operationbackend.controller;
|
|
|
|
|
|
+import com.idiot.operationbackend.entity.Account;
|
|
|
+import com.idiot.operationbackend.entity.AccountFansStat;
|
|
|
+import com.idiot.operationbackend.service.facade.AccountFansStatService;
|
|
|
+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 io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.slf4j.Logger;
|
|
|
+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 java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
- *
|
|
|
+ * 运营星 首页
|
|
|
* @author wang xiao
|
|
|
* @date Created in 10:55 2020/9/15
|
|
|
*/
|
|
|
@RestController
|
|
|
+@RequestMapping("/index")
|
|
|
+@Api(value = "IndexController", tags ="首页")
|
|
|
public class IndexController {
|
|
|
+
|
|
|
+
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(IndexController.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AccountService accountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AccountFansStatService fansStatService;
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/summary")
|
|
|
+ @ApiOperation(value = "查询公众号昨日统计数据概览")
|
|
|
+ public ResponseEntity<JsonResult<AccountFansStat>> 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);
|
|
|
+ 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();
|
|
|
+ int bfInactiveNum = beforeYdStat.stream().mapToInt(AccountFansStat::getInactiveNum).sum();
|
|
|
+ int bfTotalNum = beforeYdStat.stream().mapToInt(AccountFansStat::getTotalFansNum).sum();
|
|
|
+
|
|
|
+ AccountFansStat result = new AccountFansStat();
|
|
|
+ result.setAddNum(addNum);
|
|
|
+ result.setNewNum(newNum);
|
|
|
+ result.setCancelNum(cancelNum);
|
|
|
+ result.setInactiveNum(inactiveNum);
|
|
|
+ result.setTotalFansNum(totalNum);
|
|
|
+ result.setAddRate(calcRate(addNum,bfAddNum));
|
|
|
+ result.setCancelRate(calcRate(cancelNum,bfCancelNum));
|
|
|
+ result.setNewRate(calcRate(newNum,bfNewNum));
|
|
|
+ result.setInactiveRate(calcRate(inactiveNum,bfInactiveNum));
|
|
|
+ result.setTotalFansRate(calcRate(totalNum,bfTotalNum));
|
|
|
+ logger.info("用户:{}查询首页数据统计概览---end",userId);
|
|
|
+ return ResponseEntity.ok(JsonResult.success(result));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|