mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-12 13:39:01 +08:00
⬆️ Upgrading dependencies. spring boot 2.1.4
✨ 添加新特性。 公众号数据统计功能
This commit is contained in:
1 parent
4219161d47
commit
4e64acf8a2
5 files changed
+92
-5
No files matched your search
+11
@@ -133,4 +133,15 @@ public class WxAccountController {
|
||||
return new R<>(wxAccountService.list());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取公众号接口数据
|
||||
*
|
||||
* @param appId 公众号
|
||||
* @param interval 时间间隔
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/statistics")
|
||||
public R statistics(String appId, String interval) {
|
||||
return wxAccountService.statistics(appId, interval);
|
||||
}
|
||||
}
|
||||
+9
@@ -35,4 +35,13 @@ public interface WxAccountService extends IService<WxAccount> {
|
||||
* @return
|
||||
*/
|
||||
R generateQr(String appId);
|
||||
|
||||
/**
|
||||
* 获取公众号统计数据
|
||||
*
|
||||
* @param appId
|
||||
* @param interval
|
||||
* @return
|
||||
*/
|
||||
R statistics(String appId, String interval);
|
||||
}
|
||||
+67
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.pig4cloud.pigx.mp.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||
@@ -26,10 +27,20 @@ import com.pig4cloud.pigx.mp.mapper.WxAccountMapper;
|
||||
import com.pig4cloud.pigx.mp.service.WxAccountService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpDataCubeService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 公众号账户
|
||||
*
|
||||
@@ -66,4 +77,60 @@ public class WxAccountServiceImpl extends ServiceImpl<WxAccountMapper, WxAccount
|
||||
|
||||
return R.builder().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取公众号统计数据
|
||||
*
|
||||
* @param appId 公众号信息
|
||||
* @param interval 时间间隔
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public R statistics(String appId, String interval) {
|
||||
String[] split = interval.split(StrUtil.DASHED);
|
||||
Date start = new Date(Long.parseLong(split[0]));
|
||||
Date end = new Date(Long.parseLong(split[1]));
|
||||
|
||||
WxMpService wxMpService = WxMpConfiguration.getMpServices().get(appId);
|
||||
WxMpDataCubeService cubeService = wxMpService.getDataCubeService();
|
||||
|
||||
List<List<Object>> result = new ArrayList<>();
|
||||
try {
|
||||
// 获取累计用户数据
|
||||
List<Object> cumulateList = cubeService.getUserCumulate(start, end).stream()
|
||||
.map(WxDataCubeUserCumulate::getCumulateUser)
|
||||
.collect(Collectors.toList());
|
||||
result.add(cumulateList);
|
||||
|
||||
// 获取用户分享数据
|
||||
List<Object> shareList = cubeService.getUserShare(start, end).stream()
|
||||
.map(WxDataCubeArticleResult::getShareCount)
|
||||
.collect(Collectors.toList());
|
||||
result.add(shareList);
|
||||
|
||||
// 获取消息发送概况数据
|
||||
List<Object> upstreamList = cubeService.getUpstreamMsg(start, end).stream()
|
||||
.map(WxDataCubeMsgResult::getMsgCount)
|
||||
.collect(Collectors.toList());
|
||||
result.add(upstreamList);
|
||||
|
||||
// 获取接口调用概况数据
|
||||
List<WxDataCubeInterfaceResult> interfaceSummaryList = cubeService.getInterfaceSummary(start, end);
|
||||
List<Object> interfaceList = interfaceSummaryList.stream()
|
||||
.map(WxDataCubeInterfaceResult::getCallbackCount)
|
||||
.collect(Collectors.toList());
|
||||
result.add(interfaceList);
|
||||
|
||||
// 接口日期保存
|
||||
List<Object> dateList = interfaceSummaryList.stream()
|
||||
.map(WxDataCubeInterfaceResult::getRefDate)
|
||||
.collect(Collectors.toList());
|
||||
result.add(dateList);
|
||||
} catch (WxErrorException e) {
|
||||
log.error(" 获取公众号统计数据报错", e);
|
||||
return R.builder().code(CommonConstants.FAIL).msg("获取公众号数据失败:" + e.getError().getErrorMsg()).build();
|
||||
}
|
||||
|
||||
return R.builder().data(result).build();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user