Browse Source

add(backend) [首页总览]

wangxiao 4 years ago
parent
commit
2582816696

+ 0 - 2
operation-backend/src/main/java/com/idiot/operationbackend/controller/AccountController.java

@@ -39,8 +39,6 @@ public class AccountController {
     private AuthUserService userService;
     private AuthUserService userService;
 
 
 
 
-
-
     @GetMapping
     @GetMapping
     @ApiOperation(value = "查询公众号列表")
     @ApiOperation(value = "查询公众号列表")
     public ResponseEntity<JsonResult<List<Account>>> list (@RequestHeader String token) {
     public ResponseEntity<JsonResult<List<Account>>> list (@RequestHeader String token) {

+ 90 - 1
operation-backend/src/main/java/com/idiot/operationbackend/controller/IndexController.java

@@ -1,12 +1,101 @@
 package com.idiot.operationbackend.controller;
 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 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
  * @author wang xiao
  * @date Created in 10:55 2020/9/15
  * @date Created in 10:55 2020/9/15
  */
  */
 @RestController
 @RestController
+@RequestMapping("/index")
+@Api(value = "IndexController", tags ="首页")
 public class IndexController {
 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);
+        }
+    }
 }
 }

+ 224 - 0
operation-backend/src/main/java/com/idiot/operationbackend/entity/AccountFansStat.java

@@ -0,0 +1,224 @@
+package com.idiot.operationbackend.entity;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+
+import java.math.BigDecimal;
+
+/**
+ * 公众号粉丝数据统计
+ * @author wang xiao
+ * @date Created in 13:57 2020/9/15
+ */
+@TableName("t_account_fans_stat")
+public class AccountFansStat {
+
+    @TableId
+    private String id;
+
+    private String accountId;
+
+    /**
+     * 新增
+     */
+    private Integer newNum;
+
+    /**
+     * 取关
+     */
+    private Integer cancelNum;
+
+    /**
+     * 活跃
+     */
+    private Integer inactiveNum;
+
+    /**
+     * 总粉丝数
+     */
+    private Integer totalFansNum;
+
+    /**
+     * 净增
+     */
+    private Integer addNum;
+
+    /**
+     * 阅读数量
+     */
+    private Integer pageReadNum;
+
+
+    /**
+     * 新增比例
+     */
+    private BigDecimal newRate;
+
+
+    /**
+     * 取关比例比例
+     */
+    private BigDecimal cancelRate;
+
+
+    /**
+     * 活跃比例
+     */
+    private BigDecimal inactiveRate;
+
+    /**
+     * 总粉丝
+     */
+    private BigDecimal totalFansRate;
+
+    /**
+     * 净增比例
+     */
+    private BigDecimal addRate;
+
+
+    /**
+     * 阅读比例
+     */
+    private BigDecimal pageReadRate;
+
+    /**
+     * 统计日期 yyyy-MM-dd
+     */
+    private String statDate;
+
+    /**
+     * 创建时间
+     */
+    private String createTime;
+
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getAccountId() {
+        return accountId;
+    }
+
+    public void setAccountId(String accountId) {
+        this.accountId = accountId;
+    }
+
+    public Integer getNewNum() {
+        return newNum;
+    }
+
+    public void setNewNum(Integer newNum) {
+        this.newNum = newNum;
+    }
+
+    public Integer getCancelNum() {
+        return cancelNum;
+    }
+
+    public void setCancelNum(Integer cancelNum) {
+        this.cancelNum = cancelNum;
+    }
+
+    public Integer getInactiveNum() {
+        return inactiveNum;
+    }
+
+    public void setInactiveNum(Integer inactiveNum) {
+        this.inactiveNum = inactiveNum;
+    }
+
+    public Integer getTotalFansNum() {
+        return totalFansNum;
+    }
+
+    public void setTotalFansNum(Integer totalFansNum) {
+        this.totalFansNum = totalFansNum;
+    }
+
+    public Integer getAddNum() {
+        return addNum;
+    }
+
+    public void setAddNum(Integer addNum) {
+        this.addNum = addNum;
+    }
+
+    public Integer getPageReadNum() {
+        return pageReadNum;
+    }
+
+    public void setPageReadNum(Integer pageReadNum) {
+        this.pageReadNum = pageReadNum;
+    }
+
+    public BigDecimal getNewRate() {
+        return newRate;
+    }
+
+    public void setNewRate(BigDecimal newRate) {
+        this.newRate = newRate;
+    }
+
+    public BigDecimal getCancelRate() {
+        return cancelRate;
+    }
+
+    public void setCancelRate(BigDecimal cancelRate) {
+        this.cancelRate = cancelRate;
+    }
+
+    public BigDecimal getInactiveRate() {
+        return inactiveRate;
+    }
+
+    public void setInactiveRate(BigDecimal inactiveRate) {
+        this.inactiveRate = inactiveRate;
+    }
+
+    public BigDecimal getTotalFansRate() {
+        return totalFansRate;
+    }
+
+    public void setTotalFansRate(BigDecimal totalFansRate) {
+        this.totalFansRate = totalFansRate;
+    }
+
+    public BigDecimal getAddRate() {
+        return addRate;
+    }
+
+    public void setAddRate(BigDecimal addRate) {
+        this.addRate = addRate;
+    }
+
+    public BigDecimal getPageReadRate() {
+        return pageReadRate;
+    }
+
+    public void setPageReadRate(BigDecimal pageReadRate) {
+        this.pageReadRate = pageReadRate;
+    }
+
+
+    public String getStatDate() {
+        return statDate;
+    }
+
+    public void setStatDate(String statDate) {
+        this.statDate = statDate;
+    }
+
+    public String getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(String createTime) {
+        this.createTime = createTime;
+    }
+}

+ 11 - 0
operation-backend/src/main/java/com/idiot/operationbackend/mappers/AccountFansStatMapper.java

@@ -0,0 +1,11 @@
+package com.idiot.operationbackend.mappers;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.idiot.operationbackend.entity.AccountFansStat;
+
+/**
+ * @author wang xiao
+ * @date Created in 14:52 2020/9/15
+ */
+public interface AccountFansStatMapper extends BaseMapper<AccountFansStat> {
+}

+ 34 - 0
operation-backend/src/main/java/com/idiot/operationbackend/service/facade/AccountFansStatService.java

@@ -0,0 +1,34 @@
+package com.idiot.operationbackend.service.facade;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.idiot.operationbackend.entity.AccountFansStat;
+
+import java.util.List;
+
+/**
+ * @author wang xiao
+ * @date Created in 14:53 2020/9/15
+ */
+public interface AccountFansStatService extends IService<AccountFansStat> {
+
+    /**
+     *  查询 公众号列表下的 粉丝统计
+     * @author wangxiao
+     * @date 15:18 2020/9/15
+     * @param accountIds
+     * @param statDate
+     * @return java.util.List<com.idiot.operationbackend.entity.AccountFansStat>
+     */
+    List<AccountFansStat> queryByDateAndAccIds(List<String> accountIds,String statDate);
+
+
+    /**
+     *  单独查询公众号列表下粉丝统计
+     * @author wangxiao
+     * @date 15:21 2020/9/15
+     * @param accountId
+     * @param statDate
+     * @return com.idiot.operationbackend.entity.AccountFansStat
+     */
+    AccountFansStat queryByDateAndAccountId(String accountId,String statDate);
+}

+ 35 - 0
operation-backend/src/main/java/com/idiot/operationbackend/service/impl/AccountFansStatServiceImpl.java

@@ -0,0 +1,35 @@
+package com.idiot.operationbackend.service.impl;
+
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.idiot.operationbackend.entity.AccountFansStat;
+import com.idiot.operationbackend.mappers.AccountFansStatMapper;
+import com.idiot.operationbackend.service.facade.AccountFansStatService;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 公众号数据统计
+ * @author wang xiao
+ * @date Created in 14:54 2020/9/15
+ */
+@Service
+public class AccountFansStatServiceImpl extends ServiceImpl<AccountFansStatMapper, AccountFansStat>
+        implements AccountFansStatService {
+
+
+    @Override
+    public List<AccountFansStat> queryByDateAndAccIds(List<String> accountIds, String statDate) {
+        return list(Wrappers.<AccountFansStat>lambdaQuery().eq(AccountFansStat::getStatDate,statDate)
+                .in(AccountFansStat::getAccountId,accountIds));
+    }
+
+
+    @Override
+    public AccountFansStat queryByDateAndAccountId(String accountId, String statDate) {
+        return getOne(Wrappers.<AccountFansStat>lambdaQuery()
+                .eq(AccountFansStat::getAccountId,accountId)
+                .eq(AccountFansStat::getStatDate,statDate));
+    }
+}

+ 7 - 1
operation-backend/src/main/java/com/idiot/operationbackend/service/impl/AccountServiceImpl.java

@@ -1,10 +1,12 @@
 package com.idiot.operationbackend.service.impl;
 package com.idiot.operationbackend.service.impl;
 
 
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.idiot.operationbackend.entity.Account;
 import com.idiot.operationbackend.entity.Account;
 import com.idiot.operationbackend.mappers.AccountMapper;
 import com.idiot.operationbackend.mappers.AccountMapper;
 import com.idiot.operationbackend.service.facade.AccountService;
 import com.idiot.operationbackend.service.facade.AccountService;
+import com.idiot.operationbackend.support.CustomException;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import java.util.List;
 import java.util.List;
@@ -40,7 +42,11 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account>
 
 
     @Override
     @Override
     public List<Account> queryAccountByUserId(String userId) {
     public List<Account> queryAccountByUserId(String userId) {
-        return list(Wrappers.<Account>lambdaQuery().eq(Account::getCreateUserId,userId));
+        List<Account> list =  list(Wrappers.<Account>lambdaQuery().eq(Account::getCreateUserId,userId));
+        if (CollectionUtils.isEmpty(list)) {
+            throw new CustomException(501,"当前暂无认证公众号,或无权查看!请前往公众号管理授权认证");
+        }
+        return list;
     }
     }
 
 
 
 

+ 4 - 0
operation-backend/src/main/java/com/idiot/operationbackend/support/Constants.java

@@ -1,5 +1,6 @@
 package com.idiot.operationbackend.support;
 package com.idiot.operationbackend.support;
 
 
+import java.math.BigDecimal;
 import java.net.URLDecoder;
 import java.net.URLDecoder;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeFormatter;
 import java.util.Locale;
 import java.util.Locale;
@@ -39,4 +40,7 @@ public class Constants {
     public static final String LOCK_SYNC_USER = "LOCK_SYNC_USER_%s";
     public static final String LOCK_SYNC_USER = "LOCK_SYNC_USER_%s";
 
 
     public static final String LOCK_SYNC_TAG = "LOCK_SYNC_TAG_%s";
     public static final String LOCK_SYNC_TAG = "LOCK_SYNC_TAG_%s";
+
+
+    public static final BigDecimal ZERO_RATE = BigDecimal.valueOf(0.00);
 }
 }

+ 14 - 13
operation-backend/src/main/resources/application-test.yml

@@ -2,19 +2,20 @@ spring:
   #  datasource
   #  datasource
   datasource:
   datasource:
     driver-class-name: com.mysql.cj.jdbc.Driver
     driver-class-name: com.mysql.cj.jdbc.Driver
-    url: jdbc:mysql://123.57.243.207:3306/db_operation?serverTimezone=UTC&characterEncoding=utf8
+    url: jdbc:mysql://192.168.1.141:3307/db_operation?serverTimezone=UTC&characterEncoding=utf8
     username: root
     username: root
-    password: HEchuTIANya1.
+    password: asdfg12345
     type: com.zaxxer.hikari.HikariDataSource
     type: com.zaxxer.hikari.HikariDataSource
     hikari:
     hikari:
       pool-name: mysqlDataSourcePool
       pool-name: mysqlDataSourcePool
       maximum-pool-size: 20
       maximum-pool-size: 20
       minimum-idle: 10
       minimum-idle: 10
-      connection-timeout: 120000
-      validation-timeout: 6000
-      idle-timeout: 60000
+      connection-timeout: 30000
+      validation-timeout: 5000
+      idle-timeout: 600000
       login-timeout: 5
       login-timeout: 5
-      max-lifetime: 60000
+      max-lifetime: 1800000
+      connection-test-query:  select  1
 #  mybatis-plus
 #  mybatis-plus
 mybatis-plus:
 mybatis-plus:
   global-config:
   global-config:
@@ -34,18 +35,18 @@ wechat:
   # 微信第三方平台 (独立部署需要自主申请)
   # 微信第三方平台 (独立部署需要自主申请)
   platform:
   platform:
     # appid
     # appid
-    appId: xxx
+    appId: wxbc8cf6d177029077
     # appsecret
     # appsecret
-    appSecret: xxxxx
+    appSecret: cad9594114c9473b5d9a697cfe154b33
     # 授权事件接收URL
     # 授权事件接收URL
-    ticketUrl: https:xxxxxx/wechat/notice
+    ticketUrl: http://luojigou.vip/wxoperate/wechat/notice
     # 加解密key
     # 加解密key
-    secret: xxxxx
+    secret: FDl8GfVXfGWwKs9LKc11xE6N2f8DM6MB8cyMm6xYsac
     # 开发平台配置token
     # 开发平台配置token
-    token: xxxxxx
+    token: eNoUNRR4e7V85KLb
     # authCallBackUrl 授权回调地址
     # authCallBackUrl 授权回调地址
-    authCallBack: https://xxxx/wechat/authCallBack
+    authCallBack: http://luojigou.vip/wxoperate/wechat/authCallBack
     # 消息接受地址
     # 消息接受地址
-    msgCallBack: https://xxxx/wechat/msgCallBack
+    msgCallBack: http://luojigou.vip/wxoperate/wechat/msgCallBack
 # 授权确认界面地址 前端界面路由地址
 # 授权确认界面地址 前端界面路由地址
 confirm-domain: https://www.xxxx
 confirm-domain: https://www.xxxx

+ 25 - 0
sql/dataBase.sql

@@ -88,5 +88,30 @@ CREATE TABLE `t_account_tag`  (
 ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin COMMENT = '公众号标签' ROW_FORMAT = Dynamic;
 ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin COMMENT = '公众号标签' ROW_FORMAT = Dynamic;
 
 
 
 
+-- ----------------------------
+-- Table structure for 公众号粉丝统计
+-- ----------------------------
+DROP TABLE IF EXISTS `t_account_fans_stat`;
+CREATE TABLE `t_account_fans_stat`  (
+  `id` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT 'id',
+  `account_id` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '公众号id',
+  `new_num` int(0) NULL DEFAULT 0 COMMENT '新增数量',
+  `cancel_num` int(0) NULL DEFAULT 0 COMMENT '取关数量',
+  `inactive_num` int(0) NULL DEFAULT 0 COMMENT '活跃数量',
+  `total_fans_num` int(0) NULL DEFAULT 0 COMMENT '总粉丝数',
+  `add_num` int(0) NULL DEFAULT 0 COMMENT '净增数量',
+  `page_read_num` int(0) NULL DEFAULT 0 COMMENT '阅读数量',
+  `new_rate` decimal(5, 2) NULL DEFAULT NULL COMMENT '新增比例',
+  `cancel_rate` decimal(5, 2) NULL DEFAULT NULL COMMENT '取关比例',
+  `inactive_rate` decimal(5, 2) NULL DEFAULT NULL COMMENT '活跃数量',
+  `total_fans_rate` decimal(5, 2) NULL DEFAULT NULL COMMENT '总粉丝比例',
+  `add_rate` decimal(5, 2) NULL DEFAULT NULL COMMENT '净增比例',
+  `page_read_rate` decimal(5, 2) NULL DEFAULT NULL COMMENT '阅读比例',
+  `stat_date` date NULL DEFAULT NULL COMMENT '统计日期',
+  `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建日期',
+  PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin COMMENT = '公众号粉丝统计' ROW_FORMAT = Dynamic;
+
+