Commit d6de233a47ecff1665119682e1b7ef809ae54eb8

Authored by YunaiV
1 parent d0934510

mp:完成公众号的数据统计前端界面

Showing 15 changed files with 274 additions and 162 deletions
yudao-module-mp/yudao-module-mp-api/src/main/java/cn/iocoder/yudao/module/mp/enums/ErrorCodeConstants.java
@@ -18,6 +18,7 @@ public interface ErrorCodeConstants { @@ -18,6 +18,7 @@ public interface ErrorCodeConstants {
18 ErrorCode STATISTICS_GET_USER_SUMMARY_FAIL = new ErrorCode(1006001000, "获取用户增减数据失败,原因:{}"); 18 ErrorCode STATISTICS_GET_USER_SUMMARY_FAIL = new ErrorCode(1006001000, "获取用户增减数据失败,原因:{}");
19 ErrorCode STATISTICS_GET_USER_CUMULATE_FAIL = new ErrorCode(1006001001, "获得用户累计数据失败,原因:{}"); 19 ErrorCode STATISTICS_GET_USER_CUMULATE_FAIL = new ErrorCode(1006001001, "获得用户累计数据失败,原因:{}");
20 ErrorCode STATISTICS_GET_UPSTREAM_MESSAGE_FAIL = new ErrorCode(1006001002, "获得消息发送概况数据失败,原因:{}"); 20 ErrorCode STATISTICS_GET_UPSTREAM_MESSAGE_FAIL = new ErrorCode(1006001002, "获得消息发送概况数据失败,原因:{}");
  21 + ErrorCode STATISTICS_GET_INTERFACE_SUMMARY_FAIL = new ErrorCode(1006001003, "获得接口分析数据失败,原因:{}");
21 22
22 // TODO 要处理下 23 // TODO 要处理下
23 ErrorCode COMMON_NOT_EXISTS = new ErrorCode(1006001002, "用户不存在"); 24 ErrorCode COMMON_NOT_EXISTS = new ErrorCode(1006001002, "用户不存在");
yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/account/MpAccountController.java
@@ -2,10 +2,7 @@ package cn.iocoder.yudao.module.mp.controller.admin.account; @@ -2,10 +2,7 @@ package cn.iocoder.yudao.module.mp.controller.admin.account;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 -import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountCreateReqVO;  
6 -import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountPageReqVO;  
7 -import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountRespVO;  
8 -import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountUpdateReqVO; 5 +import cn.iocoder.yudao.module.mp.controller.admin.account.vo.*;
9 import cn.iocoder.yudao.module.mp.convert.account.MpAccountConvert; 6 import cn.iocoder.yudao.module.mp.convert.account.MpAccountConvert;
10 import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO; 7 import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO;
11 import cn.iocoder.yudao.module.mp.service.account.MpAccountService; 8 import cn.iocoder.yudao.module.mp.service.account.MpAccountService;
@@ -18,6 +15,7 @@ import org.springframework.web.bind.annotation.*; @@ -18,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
18 15
19 import javax.annotation.Resource; 16 import javax.annotation.Resource;
20 import javax.validation.Valid; 17 import javax.validation.Valid;
  18 +import java.util.List;
21 19
22 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 20 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
23 21
@@ -71,6 +69,14 @@ public class MpAccountController { @@ -71,6 +69,14 @@ public class MpAccountController {
71 return success(MpAccountConvert.INSTANCE.convertPage(pageResult)); 69 return success(MpAccountConvert.INSTANCE.convertPage(pageResult));
72 } 70 }
73 71
  72 + @GetMapping("/list-all-simple")
  73 + @ApiOperation(value = "获取公众号账号精简信息列表")
  74 + @PreAuthorize("@ss.hasPermission('mp:account:query')")
  75 + public CommonResult<List<MpAccountSimpleRespVO>> getSimpleAccounts() {
  76 + List<MpAccountDO> list = mpAccountService.getAccountList();
  77 + return success(MpAccountConvert.INSTANCE.convertList02(list));
  78 + }
  79 +
74 @PutMapping("/generate-qr-code") 80 @PutMapping("/generate-qr-code")
75 @ApiOperation("生成公众号二维码") 81 @ApiOperation("生成公众号二维码")
76 @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) 82 @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/account/vo/MpAccountSimpleRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mp.controller.admin.account.vo;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import lombok.Data;
  6 +
  7 +@ApiModel("管理后台 - 公众号账号精简信息 Response VO")
  8 +@Data
  9 +public class MpAccountSimpleRespVO {
  10 +
  11 + @ApiModelProperty(value = "编号", required = true, example = "1024")
  12 + private Long id;
  13 +
  14 + @ApiModelProperty(value = "公众号名称", required = true, example = "芋道源码")
  15 + private String name;
  16 +
  17 +}
yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/statistics/MpStatisticsController.java
1 package cn.iocoder.yudao.module.mp.controller.admin.statistics; 1 package cn.iocoder.yudao.module.mp.controller.admin.statistics;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 -import cn.iocoder.yudao.module.mp.controller.admin.statistics.vo.MpStatisticsGetReqVO;  
5 -import cn.iocoder.yudao.module.mp.controller.admin.statistics.vo.MpStatisticsUpstreamMessageRespVO;  
6 -import cn.iocoder.yudao.module.mp.controller.admin.statistics.vo.MpStatisticsUserCumulateRespVO;  
7 -import cn.iocoder.yudao.module.mp.controller.admin.statistics.vo.MpStatisticsUserSummaryRespVO; 4 +import cn.iocoder.yudao.module.mp.controller.admin.statistics.vo.*;
8 import cn.iocoder.yudao.module.mp.convert.statistics.MpStatisticsConvert; 5 import cn.iocoder.yudao.module.mp.convert.statistics.MpStatisticsConvert;
9 import cn.iocoder.yudao.module.mp.service.statistics.MpStatisticsService; 6 import cn.iocoder.yudao.module.mp.service.statistics.MpStatisticsService;
10 import io.swagger.annotations.Api; 7 import io.swagger.annotations.Api;
11 import io.swagger.annotations.ApiOperation; 8 import io.swagger.annotations.ApiOperation;
  9 +import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult;
12 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult; 10 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult;
13 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate; 11 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
14 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary; 12 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
@@ -59,4 +57,12 @@ public class MpStatisticsController { @@ -59,4 +57,12 @@ public class MpStatisticsController {
59 return success(MpStatisticsConvert.INSTANCE.convertList03(list)); 57 return success(MpStatisticsConvert.INSTANCE.convertList03(list));
60 } 58 }
61 59
  60 + @GetMapping("/interface-summary")
  61 + @ApiOperation("获取消息发送概况数据")
  62 + @PreAuthorize("@ss.hasPermission('mp:statistics:query')")
  63 + public CommonResult<List<MpStatisticsInterfaceSummaryRespVO>> getInterfaceSummary(MpStatisticsGetReqVO getReqVO) {
  64 + List<WxDataCubeInterfaceResult> list = mpStatisticsService.getInterfaceSummary(
  65 + getReqVO.getAccountId(), getReqVO.getDate());
  66 + return success(MpStatisticsConvert.INSTANCE.convertList04(list));
  67 + }
62 } 68 }
yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/statistics/vo/MpStatisticsInterfaceSummaryRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mp.controller.admin.statistics.vo;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import lombok.Data;
  6 +
  7 +import java.util.Date;
  8 +
  9 +@ApiModel("管理后台 - 某一天的接口分析数据 Response VO")
  10 +@Data
  11 +public class MpStatisticsInterfaceSummaryRespVO {
  12 +
  13 + @ApiModelProperty(value = "日期", required = true)
  14 + private Date refDate;
  15 +
  16 + @ApiModelProperty(value = "通过服务器配置地址获得消息后,被动回复用户消息的次数", required = true, example = "10")
  17 + private Integer callbackCount;
  18 +
  19 + @ApiModelProperty(value = "上述动作的失败次数", required = true, example = "20")
  20 + private Integer failCount;
  21 +
  22 + @ApiModelProperty(value = "总耗时,除以 callback_count 即为平均耗时", required = true, example = "30")
  23 + private Integer totalTimeCost;
  24 +
  25 + @ApiModelProperty(value = "最大耗时", required = true, example = "40")
  26 + private Integer maxTimeCost;
  27 +
  28 +}
yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/account/MpAccountConvert.java
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.mp.convert.account; @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.mp.convert.account;
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountCreateReqVO; 4 import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountCreateReqVO;
5 import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountRespVO; 5 import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountRespVO;
  6 +import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountSimpleRespVO;
6 import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountUpdateReqVO; 7 import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountUpdateReqVO;
7 import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO; 8 import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO;
8 import org.mapstruct.Mapper; 9 import org.mapstruct.Mapper;
@@ -25,4 +26,6 @@ public interface MpAccountConvert { @@ -25,4 +26,6 @@ public interface MpAccountConvert {
25 26
26 PageResult<MpAccountRespVO> convertPage(PageResult<MpAccountDO> page); 27 PageResult<MpAccountRespVO> convertPage(PageResult<MpAccountDO> page);
27 28
  29 + List<MpAccountSimpleRespVO> convertList02(List<MpAccountDO> list);
  30 +
28 } 31 }
yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/statistics/MpStatisticsConvert.java
1 package cn.iocoder.yudao.module.mp.convert.statistics; 1 package cn.iocoder.yudao.module.mp.convert.statistics;
2 2
  3 +import cn.iocoder.yudao.module.mp.controller.admin.statistics.vo.MpStatisticsInterfaceSummaryRespVO;
3 import cn.iocoder.yudao.module.mp.controller.admin.statistics.vo.MpStatisticsUpstreamMessageRespVO; 4 import cn.iocoder.yudao.module.mp.controller.admin.statistics.vo.MpStatisticsUpstreamMessageRespVO;
4 import cn.iocoder.yudao.module.mp.controller.admin.statistics.vo.MpStatisticsUserCumulateRespVO; 5 import cn.iocoder.yudao.module.mp.controller.admin.statistics.vo.MpStatisticsUserCumulateRespVO;
5 import cn.iocoder.yudao.module.mp.controller.admin.statistics.vo.MpStatisticsUserSummaryRespVO; 6 import cn.iocoder.yudao.module.mp.controller.admin.statistics.vo.MpStatisticsUserSummaryRespVO;
  7 +import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult;
6 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult; 8 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult;
7 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate; 9 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
8 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary; 10 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
@@ -31,4 +33,8 @@ public interface MpStatisticsConvert { @@ -31,4 +33,8 @@ public interface MpStatisticsConvert {
31 }) 33 })
32 MpStatisticsUpstreamMessageRespVO convert(WxDataCubeMsgResult bean); 34 MpStatisticsUpstreamMessageRespVO convert(WxDataCubeMsgResult bean);
33 35
  36 + List<MpStatisticsInterfaceSummaryRespVO> convertList04(List<WxDataCubeInterfaceResult> list);
  37 +
  38 + @Mapping(source = "refDate", target = "refDate", dateFormat = "yyyy-MM-dd")
  39 + MpStatisticsInterfaceSummaryRespVO convert(WxDataCubeInterfaceResult bean);
34 } 40 }
yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/account/MpAccountService.java
@@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountUpdateReq @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountUpdateReq
7 import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO; 7 import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO;
8 8
9 import javax.validation.Valid; 9 import javax.validation.Valid;
  10 +import java.util.List;
10 11
11 /** 12 /**
12 * 公众号账号 Service 接口 13 * 公众号账号 Service 接口
@@ -67,6 +68,13 @@ public interface MpAccountService { @@ -67,6 +68,13 @@ public interface MpAccountService {
67 PageResult<MpAccountDO> getAccountPage(MpAccountPageReqVO pageReqVO); 68 PageResult<MpAccountDO> getAccountPage(MpAccountPageReqVO pageReqVO);
68 69
69 /** 70 /**
  71 + * 获得公众号账号列表
  72 + *
  73 + * @return 公众号账号列表
  74 + */
  75 + List<MpAccountDO> getAccountList();
  76 +
  77 + /**
70 * 生成公众号账号的二维码 78 * 生成公众号账号的二维码
71 * 79 *
72 * @param id 编号 80 * @param id 编号
yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/account/MpAccountServiceImpl.java
@@ -156,6 +156,11 @@ public class MpAccountServiceImpl implements MpAccountService { @@ -156,6 +156,11 @@ public class MpAccountServiceImpl implements MpAccountService {
156 } 156 }
157 157
158 @Override 158 @Override
  159 + public List<MpAccountDO> getAccountList() {
  160 + return mpAccountMapper.selectList();
  161 + }
  162 +
  163 + @Override
159 public void generateAccountQrCode(Long id) { 164 public void generateAccountQrCode(Long id) {
160 // 校验存在 165 // 校验存在
161 MpAccountDO account = validateAccountExists(id); 166 MpAccountDO account = validateAccountExists(id);
yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/statistics/MpStatisticsService.java
1 package cn.iocoder.yudao.module.mp.service.statistics; 1 package cn.iocoder.yudao.module.mp.service.statistics;
2 2
  3 +import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult;
3 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult; 4 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult;
4 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate; 5 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
5 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary; 6 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
@@ -41,4 +42,13 @@ public interface MpStatisticsService { @@ -41,4 +42,13 @@ public interface MpStatisticsService {
41 */ 42 */
42 List<WxDataCubeMsgResult> getUpstreamMessage(Long accountId, LocalDateTime[] date); 43 List<WxDataCubeMsgResult> getUpstreamMessage(Long accountId, LocalDateTime[] date);
43 44
  45 + /**
  46 + * 获取接口分析数据
  47 + *
  48 + * @param accountId 公众号账号编号
  49 + * @param date 时间区间
  50 + * @return 接口分析数据
  51 + */
  52 + List<WxDataCubeInterfaceResult> getInterfaceSummary(Long accountId, LocalDateTime[] date);
  53 +
44 } 54 }
yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/statistics/MpStatisticsServiceImpl.java
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil; @@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
4 import cn.iocoder.yudao.module.mp.framework.mp.core.MpServiceFactory; 4 import cn.iocoder.yudao.module.mp.framework.mp.core.MpServiceFactory;
5 import me.chanjar.weixin.common.error.WxErrorException; 5 import me.chanjar.weixin.common.error.WxErrorException;
6 import me.chanjar.weixin.mp.api.WxMpService; 6 import me.chanjar.weixin.mp.api.WxMpService;
  7 +import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult;
7 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult; 8 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult;
8 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate; 9 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
9 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary; 10 import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
@@ -62,4 +63,15 @@ public class MpStatisticsServiceImpl implements MpStatisticsService { @@ -62,4 +63,15 @@ public class MpStatisticsServiceImpl implements MpStatisticsService {
62 } 63 }
63 } 64 }
64 65
  66 + @Override
  67 + public List<WxDataCubeInterfaceResult> getInterfaceSummary(Long accountId, LocalDateTime[] date) {
  68 + WxMpService mpService = mpServiceFactory.getRequiredMpService(accountId);
  69 + try {
  70 + return mpService.getDataCubeService().getInterfaceSummary(
  71 + DateUtil.date(date[0]), DateUtil.date(date[1]));
  72 + } catch (WxErrorException e) {
  73 + throw exception(STATISTICS_GET_INTERFACE_SUMMARY_FAIL, e.getError().getErrorMsg());
  74 + }
  75 + }
  76 +
65 } 77 }
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/vo/user/UserSimpleRespVO.java
@@ -6,7 +6,7 @@ import lombok.AllArgsConstructor; @@ -6,7 +6,7 @@ import lombok.AllArgsConstructor;
6 import lombok.Data; 6 import lombok.Data;
7 import lombok.NoArgsConstructor; 7 import lombok.NoArgsConstructor;
8 8
9 -@ApiModel("用户精简信息 Response VO") 9 +@ApiModel("管理后台 - 用户精简信息 Response VO")
10 @Data 10 @Data
11 @NoArgsConstructor 11 @NoArgsConstructor
12 @AllArgsConstructor 12 @AllArgsConstructor
yudao-ui-admin/src/api/mp/account.js
@@ -43,6 +43,14 @@ export function getAccountPage(query) { @@ -43,6 +43,14 @@ export function getAccountPage(query) {
43 }) 43 })
44 } 44 }
45 45
  46 +// 获取公众号账号精简信息列表
  47 +export function getSimpleAccounts() {
  48 + return request({
  49 + url: '/mp/account/list-all-simple',
  50 + method: 'get',
  51 + })
  52 +}
  53 +
46 // 生成公众号二维码 54 // 生成公众号二维码
47 export function generateAccountQrCode(id) { 55 export function generateAccountQrCode(id) {
48 return request({ 56 return request({
yudao-ui-admin/src/api/mp/statistics.js
@@ -26,3 +26,12 @@ export function getUserCumulate(query) { @@ -26,3 +26,12 @@ export function getUserCumulate(query) {
26 params: query 26 params: query
27 }) 27 })
28 } 28 }
  29 +
  30 +// 获得接口分析数据
  31 +export function getInterfaceSummary(query) {
  32 + return request({
  33 + url: '/mp/statistics/interface-summary',
  34 + method: 'get',
  35 + params: query
  36 + })
  37 +}
yudao-ui-admin/src/views/mp/statistics/index.vue
1 <template> 1 <template>
2 <div class="app-container"> 2 <div class="app-container">
3 - <el-card class="box-card">  
4 - <div slot="header" class="clearfix">  
5 - <span class="demonstration">时间范围</span> 3 + <!-- 搜索工作栏 -->
  4 + <el-form ref="queryForm" size="small" :inline="true" label-width="68px">
  5 + <el-form-item label="公众号" prop="accountId">
  6 + <el-select v-model="accountId" @change="getSummary">
  7 + <el-option v-for="item in accounts" :key="parseInt(item.id)" :label="item.name" :value="parseInt(item.id)" />
  8 + </el-select>
  9 + </el-form-item>
  10 + <el-form-item label="时间范围" prop="date">
6 <el-date-picker v-model="date" style="width: 260px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" 11 <el-date-picker v-model="date" style="width: 260px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
7 range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" 12 range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
8 :picker-options="datePickerOptions" :default-time="['00:00:00', '23:59:59']" 13 :picker-options="datePickerOptions" :default-time="['00:00:00', '23:59:59']"
9 - @change="changeDate" > 14 + @change="getSummary">
10 </el-date-picker> 15 </el-date-picker>
11 - </div>  
12 -<!-- <el-row>-->  
13 -<!-- <el-col :span="12">-->  
14 -<!-- <div id="interfaceSummaryChart" :style="{width: '80%', height: '500px'}"></div>-->  
15 -<!-- </el-col>-->  
16 -<!-- <el-col :span="12">-->  
17 -<!-- <div id="interfaceSummaryChart2" :style="{width: '80%', height: '500px'}"></div>-->  
18 -<!-- </el-col>-->  
19 -<!-- </el-row>--> 16 + </el-form-item>
  17 + </el-form>
20 18
21 - <el-row>  
22 - <el-col :span="12" class="card-box">  
23 - <el-card>  
24 - <div slot="header">  
25 - <span>用户增减数据</span>  
26 - </div>  
27 - <div class="el-table el-table--enable-row-hover el-table--medium">  
28 - <div ref="userSummaryChart" style="height: 420px" />  
29 - </div>  
30 - </el-card>  
31 - </el-col>  
32 - <el-col :span="12" class="card-box">  
33 - <el-card>  
34 - <div slot="header">  
35 - <span>累计用户数据</span>  
36 - </div>  
37 - <div class="el-table el-table--enable-row-hover el-table--medium">  
38 - <div ref="userCumulateChart" style="height: 420px" />  
39 - </div>  
40 - </el-card>  
41 - </el-col>  
42 - <el-col :span="12" class="card-box">  
43 - <el-card>  
44 - <div slot="header">  
45 - <span>消息概况数据</span>  
46 - </div>  
47 - <div class="el-table el-table--enable-row-hover el-table--medium">  
48 - <div ref="upstreamMessageChart" style="height: 420px" />  
49 - </div>  
50 - </el-card>  
51 - </el-col>  
52 - </el-row>  
53 - </el-card> 19 + <!-- 图表 -->
  20 + <el-row>
  21 + <el-col :span="12" class="card-box">
  22 + <el-card>
  23 + <div slot="header">
  24 + <span>用户增减数据</span>
  25 + </div>
  26 + <div class="el-table el-table--enable-row-hover el-table--medium">
  27 + <div ref="userSummaryChart" style="height: 420px" />
  28 + </div>
  29 + </el-card>
  30 + </el-col>
  31 + <el-col :span="12" class="card-box">
  32 + <el-card>
  33 + <div slot="header">
  34 + <span>累计用户数据</span>
  35 + </div>
  36 + <div class="el-table el-table--enable-row-hover el-table--medium">
  37 + <div ref="userCumulateChart" style="height: 420px" />
  38 + </div>
  39 + </el-card>
  40 + </el-col>
  41 + <el-col :span="12" class="card-box">
  42 + <el-card>
  43 + <div slot="header">
  44 + <span>消息概况数据</span>
  45 + </div>
  46 + <div class="el-table el-table--enable-row-hover el-table--medium">
  47 + <div ref="upstreamMessageChart" style="height: 420px" />
  48 + </div>
  49 + </el-card>
  50 + </el-col>
  51 + <el-col :span="12" class="card-box">
  52 + <el-card>
  53 + <div slot="header">
  54 + <span>接口分析数据</span>
  55 + </div>
  56 + <div class="el-table el-table--enable-row-hover el-table--medium">
  57 + <div ref="interfaceSummaryChart" style="height: 420px" />
  58 + </div>
  59 + </el-card>
  60 + </el-col>
  61 + </el-row>
54 </div> 62 </div>
55 </template> 63 </template>
56 64
57 <script> 65 <script>
58 // 引入基本模板 66 // 引入基本模板
59 import * as echarts from 'echarts' 67 import * as echarts from 'echarts'
60 -  
61 // 引入柱状图组件 68 // 引入柱状图组件
62 require('echarts/lib/chart/bar') 69 require('echarts/lib/chart/bar')
63 // 引入柱拆线组件 70 // 引入柱拆线组件
@@ -67,9 +74,10 @@ require(&#39;echarts/lib/component/tooltip&#39;) @@ -67,9 +74,10 @@ require(&#39;echarts/lib/component/tooltip&#39;)
67 require('echarts/lib/component/title') 74 require('echarts/lib/component/title')
68 require('echarts/lib/component/legend') 75 require('echarts/lib/component/legend')
69 76
70 -import {getInterfaceSummary, getUserSummary, getUserCumulate, getUpstreamMessage} from '@/api/mp/statistics' 77 +import { getInterfaceSummary, getUserSummary, getUserCumulate, getUpstreamMessage} from '@/api/mp/statistics'
71 import { datePickerOptions } from "@/utils/constants"; 78 import { datePickerOptions } from "@/utils/constants";
72 import {addTime, beginOfDay, betweenDay, endOfDay, formatDate} from "@/utils/dateUtils"; 79 import {addTime, beginOfDay, betweenDay, endOfDay, formatDate} from "@/utils/dateUtils";
  80 +import {getSimpleAccounts} from "@/api/mp/account";
73 81
74 export default { 82 export default {
75 name: 'mpStatistics', 83 name: 'mpStatistics',
@@ -77,7 +85,8 @@ export default { @@ -77,7 +85,8 @@ export default {
77 return { 85 return {
78 date : [beginOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24 * 7)), // -7 天 86 date : [beginOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24 * 7)), // -7 天
79 endOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24))], // -1 天 87 endOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24))], // -1 天
80 - accountId: 1, 88 + accountId: undefined,
  89 + accounts: [],
81 90
82 xAxisDate: [], // X 轴的日期范围 91 xAxisDate: [], // X 轴的日期范围
83 userSummaryOption: { // 用户增减数据 92 userSummaryOption: { // 用户增减数据
@@ -170,25 +179,78 @@ export default { @@ -170,25 +179,78 @@ export default {
170 data: [] // 用户发送条数的数据 179 data: [] // 用户发送条数的数据
171 }] 180 }]
172 }, 181 },
  182 + interfaceSummaryOption: { // 接口分析况数据
  183 + color: ['#67C23A', '#e5323e', '#E6A23C', '#409EFF'],
  184 + legend: {
  185 + data: ['被动回复用户消息的次数','失败次数', '最大耗时','总耗时']
  186 + },
  187 + tooltip: {},
  188 + xAxis: {
  189 + data: [] // X 轴的日期范围
  190 + },
  191 + yAxis: {},
  192 + series: [{
  193 + name: '被动回复用户消息的次数',
  194 + type: 'bar',
  195 + label: {
  196 + normal: {
  197 + show: true
  198 + }
  199 + },
  200 + barGap: 0,
  201 + data: [] // 被动回复用户消息的次数的数据
  202 + }, {
  203 + name: '失败次数',
  204 + type: 'bar',
  205 + label: {
  206 + normal: {
  207 + show: true
  208 + }
  209 + },
  210 + data: [] // 失败次数的数据
  211 + }, {
  212 + name: '最大耗时',
  213 + type: 'bar',
  214 + label: {
  215 + normal: {
  216 + show: true
  217 + }
  218 + },
  219 + data: [] // 最大耗时的数据
  220 + }, {
  221 + name: '总耗时',
  222 + type: 'bar',
  223 + label: {
  224 + normal: {
  225 + show: true
  226 + }
  227 + },
  228 + data: [] // 总耗时的数据
  229 + }]
  230 + },
173 231
174 // 静态变量 232 // 静态变量
175 datePickerOptions: datePickerOptions, 233 datePickerOptions: datePickerOptions,
176 } 234 }
177 }, 235 },
178 created() { 236 created() {
179 -  
180 - },  
181 - mounted: function() {  
182 - this.getSummary()  
183 - },  
184 - computed: {  
185 - 237 + getSimpleAccounts().then(response => {
  238 + this.accounts = response.data;
  239 + // 默认选中第一个
  240 + if (this.accounts.length > 0) {
  241 + this.accountId = this.accounts[0].id;
  242 + }
  243 + // 加载数据
  244 + this.getSummary();
  245 + })
186 }, 246 },
187 methods: { 247 methods: {
188 - changeDate() {  
189 - this.getSummary()  
190 - },  
191 getSummary() { 248 getSummary() {
  249 + // 如果没有选中公众号账号,则进行提示。
  250 + if (!this.accountId) {
  251 + this.$message.error('未选中公众号,无法统计数据')
  252 + return false
  253 + }
192 // 必须选择 7 天内,因为公众号有时间跨度限制为 7 254 // 必须选择 7 天内,因为公众号有时间跨度限制为 7
193 if (betweenDay(this.date[0], this.date[1]) >= 7) { 255 if (betweenDay(this.date[0], this.date[1]) >= 7) {
194 this.$message.error('时间间隔 7 天以内,请重新选择') 256 this.$message.error('时间间隔 7 天以内,请重新选择')
@@ -204,93 +266,7 @@ export default { @@ -204,93 +266,7 @@ export default {
204 this.initUserSummaryChart(); 266 this.initUserSummaryChart();
205 this.initUserCumulateChart(); 267 this.initUserCumulateChart();
206 this.initUpstreamMessageChart(); 268 this.initUpstreamMessageChart();
207 - //  
208 - // //获取接口数据  
209 - // getInterfaceSummary({  
210 - // startDate: this.startDate,  
211 - // endDate: this.endDate  
212 - // }).then(response => {  
213 - // response.data.forEach((item, index, arr) => {  
214 - // this.$set(this.seriesData1, index, item.callbackCount)  
215 - // this.$set(this.seriesData2, index, item.maxTimeCost)  
216 - // this.$set(this.seriesData3, index, item.totalTimeCost)  
217 - // this.$set(this.seriesData4, index, item.failCount)  
218 - // })  
219 - // // 基于准备好的dom,初始化echarts实例  
220 - // let interfaceSummaryChart = echarts.init(document.getElementById('interfaceSummaryChart'))  
221 - // // 绘制图表  
222 - // interfaceSummaryChart.setOption({  
223 - // title: { text: '接口分析数据' },  
224 - // color: ['#67C23A', '#e5323e'],  
225 - // legend: {  
226 - // data: ['被动回复用户消息的次数','失败次数']  
227 - // },  
228 - // tooltip: {},  
229 - // xAxis: {  
230 - // data: this.xAxisData  
231 - // },  
232 - // yAxis: {},  
233 - // series: [{  
234 - // name: '被动回复用户消息的次数',  
235 - // type: 'bar',  
236 - // label: {  
237 - // normal: {  
238 - // show: true  
239 - // }  
240 - // },  
241 - // barGap: 0,  
242 - // data: this.seriesData1  
243 - // },  
244 - // {  
245 - // name: '失败次数',  
246 - // type: 'bar',  
247 - // label: {  
248 - // normal: {  
249 - // show: true  
250 - // }  
251 - // },  
252 - // data: this.seriesData4  
253 - // }]  
254 - // })  
255 - //  
256 - // // 基于准备好的dom,初始化echarts实例  
257 - // let interfaceSummaryChart2 = echarts.init(document.getElementById('interfaceSummaryChart2'))  
258 - // // 绘制图表  
259 - // interfaceSummaryChart2.setOption({  
260 - // title: { text: '接口分析数据' },  
261 - // color: ['#E6A23C', '#409EFF'],  
262 - // legend: {  
263 - // data: ['最大耗时','总耗时']  
264 - // },  
265 - // tooltip: {},  
266 - // xAxis: {  
267 - // data: this.xAxisData  
268 - // },  
269 - // yAxis: {},  
270 - // series: [  
271 - // {  
272 - // name: '最大耗时',  
273 - // type: 'bar',  
274 - // label: {  
275 - // normal: {  
276 - // show: true  
277 - // }  
278 - // },  
279 - // data: this.seriesData2  
280 - // },  
281 - // {  
282 - // name: '总耗时',  
283 - // type: 'bar',  
284 - // label: {  
285 - // normal: {  
286 - // show: true  
287 - // }  
288 - // },  
289 - // data: this.seriesData3  
290 - // }]  
291 - // })  
292 - // }).catch(() => {  
293 - // }) 269 + this.interfaceSummaryChart();
294 }, 270 },
295 initUserSummaryChart() { 271 initUserSummaryChart() {
296 this.userSummaryOption.xAxis.data = []; 272 this.userSummaryOption.xAxis.data = [];
@@ -356,14 +332,31 @@ export default { @@ -356,14 +332,31 @@ export default {
356 const upstreamMessageChart = echarts.init(this.$refs.upstreamMessageChart); 332 const upstreamMessageChart = echarts.init(this.$refs.upstreamMessageChart);
357 upstreamMessageChart.setOption(this.upstreamMessageOption); 333 upstreamMessageChart.setOption(this.upstreamMessageOption);
358 }).catch(() => {}) 334 }).catch(() => {})
  335 + },
  336 + interfaceSummaryChart() {
  337 + this.interfaceSummaryOption.xAxis.data = [];
  338 + this.interfaceSummaryOption.series[0].data = [];
  339 + this.interfaceSummaryOption.series[1].data = [];
  340 + this.interfaceSummaryOption.series[2].data = [];
  341 + this.interfaceSummaryOption.series[3].data = [];
  342 + // 发起请求
  343 + getInterfaceSummary({
  344 + accountId: this.accountId,
  345 + date: [formatDate(this.date[0], 'yyyy-MM-dd HH:mm:ss'), formatDate(this.date[1], 'yyyy-MM-dd HH:mm:ss'),]
  346 + }).then(response => {
  347 + this.interfaceSummaryOption.xAxis.data = this.xAxisDate;
  348 + // 处理数据
  349 + response.data.forEach((item, index) => {
  350 + this.interfaceSummaryOption.series[0].data[index] = item.callbackCount;
  351 + this.interfaceSummaryOption.series[1].data[index] = item.failCount;
  352 + this.interfaceSummaryOption.series[2].data[index] = item.maxTimeCost;
  353 + this.interfaceSummaryOption.series[3].data[index] = item.totalTimeCost;
  354 + })
  355 + // 绘制图表
  356 + const interfaceSummaryChart = echarts.init(this.$refs.interfaceSummaryChart);
  357 + interfaceSummaryChart.setOption(this.interfaceSummaryOption);
  358 + }).catch(() => {})
359 } 359 }
360 } 360 }
361 } 361 }
362 </script> 362 </script>
363 -  
364 -<style lang="scss" scoped>  
365 -.demonstration{  
366 - font-size: 15px;  
367 - margin-right: 10px;  
368 -}  
369 -</style>