Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
me.chanjar.weixin.mp.api.impl.WxMpDataCubeServiceImpl Maven / Gradle / Ivy
package me.chanjar.weixin.mp.api.impl;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
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.*;
import me.chanjar.weixin.mp.enums.WxMpApiUrl;
import org.apache.commons.lang3.time.FastDateFormat;
import java.text.Format;
import java.util.Date;
import java.util.List;
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.DataCube.*;
/**
* Created by Binary Wang on 2016/8/23.
*
* @author binarywang (https://github.com/binarywang)
*/
@RequiredArgsConstructor
public class WxMpDataCubeServiceImpl implements WxMpDataCubeService {
private final Format dateFormat = FastDateFormat.getInstance("yyyy-MM-dd");
private final WxMpService wxMpService;
@Override
public List getUserSummary(Date beginDate, Date endDate) throws WxErrorException {
String responseContent = this.wxMpService.post(GET_USER_SUMMARY, buildParams(beginDate, endDate));
return WxDataCubeUserSummary.fromJson(responseContent);
}
@Override
public List getUserCumulate(Date beginDate, Date endDate) throws WxErrorException {
String responseContent = this.wxMpService.post(GET_USER_CUMULATE, buildParams(beginDate, endDate));
return WxDataCubeUserCumulate.fromJson(responseContent);
}
@Override
public List getArticleSummary(Date beginDate, Date endDate) throws WxErrorException {
return this.getArticleResults(GET_ARTICLE_SUMMARY, beginDate, endDate);
}
@Override
public List getArticleTotal(Date beginDate, Date endDate) throws WxErrorException {
String responseContent = this.wxMpService.post(GET_ARTICLE_TOTAL, buildParams(beginDate, endDate));
return WxDataCubeArticleTotal.fromJson(responseContent);
}
@Override
public List getUserRead(Date beginDate, Date endDate) throws WxErrorException {
return this.getArticleResults(GET_USER_READ, beginDate, endDate);
}
@Override
public List getUserReadHour(Date beginDate, Date endDate) throws WxErrorException {
return this.getArticleResults(GET_USER_READ_HOUR, beginDate, endDate);
}
@Override
public List getUserShare(Date beginDate, Date endDate) throws WxErrorException {
return this.getArticleResults(GET_USER_SHARE, beginDate, endDate);
}
@Override
public List getUserShareHour(Date beginDate, Date endDate) throws WxErrorException {
return this.getArticleResults(GET_USER_SHARE_HOUR, beginDate, endDate);
}
private List getArticleResults(WxMpApiUrl url, Date beginDate, Date endDate) throws WxErrorException {
String responseContent = this.wxMpService.post(url, buildParams(beginDate, endDate));
return WxDataCubeArticleResult.fromJson(responseContent);
}
@Override
public List getUpstreamMsg(Date beginDate, Date endDate) throws WxErrorException {
return this.getUpstreamMsg(GET_UPSTREAM_MSG, beginDate, endDate);
}
@Override
public List getUpstreamMsgHour(Date beginDate, Date endDate) throws WxErrorException {
return this.getUpstreamMsg(GET_UPSTREAM_MSG_HOUR, beginDate, endDate);
}
@Override
public List getUpstreamMsgWeek(Date beginDate, Date endDate) throws WxErrorException {
return this.getUpstreamMsg(GET_UPSTREAM_MSG_WEEK, beginDate, endDate);
}
@Override
public List getUpstreamMsgMonth(Date beginDate, Date endDate) throws WxErrorException {
return this.getUpstreamMsg(GET_UPSTREAM_MSG_MONTH, beginDate, endDate);
}
@Override
public List getUpstreamMsgDist(Date beginDate, Date endDate) throws WxErrorException {
return this.getUpstreamMsg(GET_UPSTREAM_MSG_DIST, beginDate, endDate);
}
@Override
public List getUpstreamMsgDistWeek(Date beginDate, Date endDate) throws WxErrorException {
return this.getUpstreamMsg(GET_UPSTREAM_MSG_DIST_WEEK, beginDate, endDate);
}
@Override
public List getUpstreamMsgDistMonth(Date beginDate, Date endDate) throws WxErrorException {
return this.getUpstreamMsg(GET_UPSTREAM_MSG_DIST_MONTH, beginDate, endDate);
}
private List getUpstreamMsg(WxMpApiUrl url, Date beginDate, Date endDate) throws WxErrorException {
String responseContent = this.wxMpService.post(url, buildParams(beginDate, endDate));
return WxDataCubeMsgResult.fromJson(responseContent);
}
@Override
public List getInterfaceSummary(Date beginDate, Date endDate) throws WxErrorException {
String responseContent = this.wxMpService.post(GET_INTERFACE_SUMMARY, buildParams(beginDate, endDate));
return WxDataCubeInterfaceResult.fromJson(responseContent);
}
private String buildParams(Date beginDate, Date endDate) {
JsonObject param = new JsonObject();
param.addProperty("begin_date", this.dateFormat.format(beginDate));
param.addProperty("end_date", this.dateFormat.format(endDate));
return param.toString();
}
@Override
public List getInterfaceSummaryHour(Date beginDate, Date endDate) throws WxErrorException {
String responseContent = this.wxMpService.post(GET_INTERFACE_SUMMARY_HOUR, buildParams(beginDate, endDate));
return WxDataCubeInterfaceResult.fromJson(responseContent);
}
}