🆕 #2620 【企业微信】微信客服统计管理模块增加获取「客户数据统计」企业汇总数据的接口

This commit is contained in:
zhongjun 2022-04-26 11:31:59 +08:00 committed by GitHub
parent 010c184caa
commit a685e8f3fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 192 additions and 32 deletions

View File

@ -1,23 +1,10 @@
package me.chanjar.weixin.cp.api;
import java.util.List;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountAdd;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountAddResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountDel;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountLink;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountLinkResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountListResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountUpd;
import me.chanjar.weixin.cp.bean.kf.WxCpKfCustomerBatchGetResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgListResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgSendRequest;
import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgSendResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfServiceStateResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfServiceStateTransResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfServicerListResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfServicerOpResp;
import me.chanjar.weixin.cp.bean.kf.*;
import java.util.List;
/**
* 微信客服接口
@ -188,4 +175,17 @@ public interface WxCpKfService {
*/
WxCpKfCustomerBatchGetResp customerBatchGet(List<String> externalUserIdList)
throws WxErrorException;
/**
* <pre>
* 获取客户数据统计企业汇总数据
* 通过此接口可以获取咨询会话数咨询客户数等企业汇总统计数据
* 请求方式POST(HTTPS)
* 请求地址<a href="https://qyapi.weixin.qq.com/cgi-bin/kf/get_corp_statistic?access_token=ACCESS_TOKEN">https://qyapi.weixin.qq.com/cgi-bin/kf/get_corp_statistic?access_token=ACCESS_TOKEN</a>
* 文档地址<a href="https://developer.work.weixin.qq.com/document/path/95489">https://developer.work.weixin.qq.com/document/path/95489</a>
* <pre>
* @param request 查询参数
* @return 客户数据统计-企业汇总数据
*/
WxCpKfGetCorpStatisticResp getCorpStatistic(WxCpKfGetCorpStatisticRequest request) throws WxErrorException;
}

View File

@ -4,29 +4,16 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.List;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpKfService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountAdd;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountAddResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountDel;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountLink;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountLinkResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountListResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountUpd;
import me.chanjar.weixin.cp.bean.kf.WxCpKfCustomerBatchGetResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgListResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgSendRequest;
import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgSendResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfServiceStateResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfServiceStateTransResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfServicerListResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfServicerOpResp;
import me.chanjar.weixin.cp.bean.kf.*;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.util.List;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Kf.*;
/**
@ -188,4 +175,11 @@ public class WxCpKfServiceImpl implements WxCpKfService {
return WxCpKfCustomerBatchGetResp.fromJson(responseContent);
}
@Override
public WxCpKfGetCorpStatisticResp getCorpStatistic(WxCpKfGetCorpStatisticRequest request) throws WxErrorException {
String url = cpService.getWxCpConfigStorage().getApiUrl(GET_CORP_STATISTIC);
String responseContent = cpService.post(url, GSON.toJson(request));
return WxCpKfGetCorpStatisticResp.fromJson(responseContent);
}
}

View File

@ -0,0 +1,34 @@
package me.chanjar.weixin.cp.bean.kf;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 获取客户数据统计企业汇总数据
*
* @author zhongjun
* @date 2022/4/25
**/
@NoArgsConstructor
@Data
public class WxCpKfGetCorpStatisticRequest {
/**
* 客服帐号ID不传入时返回的数据为企业维度汇总的数据
*/
@SerializedName("open_kfid")
private String openKfId;
/**
* 起始日期的时间戳填这一天的0时0分0秒否则系统自动处理为当天的0分0秒取值范围昨天至前180天
*/
@SerializedName("start_time")
private Long startTime;
/**
* 结束日期的时间戳填这一天的0时0分0秒否则系统自动处理为当天的0分0秒取值范围昨天至前180天
*/
@SerializedName("end_time")
private Long endTime;
}

View File

@ -0,0 +1,96 @@
package me.chanjar.weixin.cp.bean.kf;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.util.List;
/**
* 获取客户数据统计企业汇总数据
*
* @author zhongjun
* @date 2022/4/25
**/
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@Data
public class WxCpKfGetCorpStatisticResp extends WxCpBaseResp {
private static final long serialVersionUID = -89898989898989898L;
/**
* 统计数据列表
*/
@SerializedName("statistic_list")
private List<StatisticList> statisticList;
@NoArgsConstructor
@Data
public static class StatisticList {
/**
* 数据统计日期为当日0点的时间戳
*/
@SerializedName("stat_time")
private Long statTime;
/**
* 一天的统计数据若当天未产生任何下列统计数据或统计数据还未计算完成则不会返回此项
*/
@SerializedName("statistic")
private Statistic statistic;
}
@NoArgsConstructor
@Data
public static class Statistic {
/**
* 咨询会话数客户发过消息并分配给接待人员或智能助手的客服会话数转接不会产生新的会话
*/
@SerializedName("session_cnt")
private Integer sessionCnt;
/**
* 咨询客户数在会话中发送过消息的客户数量若客户多次咨询只计算一个客户
*/
@SerializedName("user_cnt")
private Integer customerCnt;
/**
* 咨询消息总数客户在会话中发送的消息的数量
*/
@SerializedName("customer_msg_cnt")
private Integer customerMsgCnt;
/**
* 升级服务客户数通过升级服务功能成功添加专员或加入客户群的客户数若同一个客户添加多个专员或客户群只计算一个客户在2022年3月10日以后才会有对应统计数据
*/
@SerializedName("upgrade_service_customer_cnt")
private Integer upgradeServiceCustomerCnt;
/**
* 智能回复会话数客户发过消息并分配给智能助手的咨询会话数通过API发消息或者开启智能回复功能会将客户分配给智能助手
*/
@SerializedName("ai_transfer_rate")
private Integer aiSessionReplyCnt;
/**
* 转人工率一个自然日内客户给智能助手发消息的会话中转人工的会话的占比
*/
@SerializedName("ai_transfer_rate")
private Integer aiTransferRate;
/**
* 知识命中率一个自然日内客户给智能助手发送的消息中命中知识库的占比只有在开启了智能回复原生功能并配置了知识库的情况下才会产生该项统计数据当api托管了会话分配智能回复原生功能失效若不返回代表没有向配置知识库的智能接待助手发送消息该项无法计算
*/
@SerializedName("ai_knowledge_hit_rate")
private Integer aiKnowledgeHitRate;
}
public static WxCpKfGetCorpStatisticResp fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpKfGetCorpStatisticResp.class);
}
}

View File

@ -328,6 +328,7 @@ public interface WxCpApiPathConsts {
String SEND_MSG_ON_EVENT = "/cgi-bin/kf/send_msg_on_event";
String CUSTOMER_BATCH_GET = "/cgi-bin/kf/customer/batchget";
String GET_CORP_STATISTIC = "/cgi-bin/kf/get_corp_statistic";
}

View File

@ -0,0 +1,32 @@
package me.chanjar.weixin.cp.util.json;
import com.google.gson.*;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.cp.bean.kf.WxCpKfGetCorpStatisticResp;
import java.lang.reflect.Type;
/**
* @author zhongjun
* @date 2022/4/25
**/
public class StatisticListAdapter implements JsonDeserializer<WxCpKfGetCorpStatisticResp.StatisticList> {
@Override
public WxCpKfGetCorpStatisticResp.StatisticList deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
WxCpKfGetCorpStatisticResp.StatisticList statisticList = new WxCpKfGetCorpStatisticResp.StatisticList();
JsonObject asJsonObject = jsonElement.getAsJsonObject();
statisticList.setStatTime(asJsonObject.get("stat_time").getAsLong());
JsonElement statistic = asJsonObject.get("statistic");
if (GsonHelper.isNotNull(statistic)) {
WxCpKfGetCorpStatisticResp.Statistic statisticObj = new WxCpKfGetCorpStatisticResp.Statistic();
statisticObj.setSessionCnt(statistic.getAsJsonObject().get("session_cnt").getAsInt());
statisticObj.setCustomerCnt(statistic.getAsJsonObject().get("customer_cnt").getAsInt());
statisticObj.setCustomerMsgCnt(statistic.getAsJsonObject().get("customer_msg_cnt").getAsInt());
statisticObj.setUpgradeServiceCustomerCnt(statistic.getAsJsonObject().get("upgrade_service_customer_cnt").getAsInt());
statisticObj.setAiTransferRate(statistic.getAsJsonObject().get("ai_transfer_rate").getAsInt());
statisticObj.setAiKnowledgeHitRate(statistic.getAsJsonObject().get("ai_knowledge_hit_rate").getAsInt());
}
return statisticList;
}
}

View File

@ -9,6 +9,8 @@ import me.chanjar.weixin.cp.bean.WxCpChat;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpTag;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.bean.kf.WxCpKfGetCorpStatisticResp;
import java.util.Objects;
/**
@ -27,6 +29,7 @@ public class WxCpGsonBuilder {
INSTANCE.registerTypeAdapter(WxError.class, new WxErrorAdapter());
INSTANCE.registerTypeAdapter(WxMenu.class, new WxCpMenuGsonAdapter());
INSTANCE.registerTypeAdapter(WxCpTag.class, new WxCpTagGsonAdapter());
INSTANCE.registerTypeAdapter(WxCpKfGetCorpStatisticResp.StatisticList.class, new StatisticListAdapter());
}
public static Gson create() {