🆕 #2674【企业微信】增加家校应用健康上报部分接口

This commit is contained in:
0katekate0 2022-05-31 20:14:20 +08:00 committed by GitHub
parent 42122ce548
commit 3952fcdd33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 441 additions and 1 deletions

View File

@ -0,0 +1,57 @@
package me.chanjar.weixin.cp.api;
import lombok.NonNull;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.school.health.WxCpGetHealthReportStat;
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobIds;
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobInfo;
/**
* 企业微信家校应用 健康上报接口.
* https://developer.work.weixin.qq.com/document/path/93676
*
* @author <a href="https://github.com/0katekate0">Wang_Wong</a>
* @date: 2022/5/31 9:10
*/
public interface WxCpSchoolHealthService {
/**
* 获取健康上报使用统计
* 请求方式POSTHTTPS
* 请求地址https://qyapi.weixin.qq.com/cgi-bin/health/get_health_report_stat?access_token=ACCESS_TOKEN
*
* @param date 具体某天的使用统计最长支持获取30天前数据
* @return
* @throws WxErrorException
*/
WxCpGetHealthReportStat getHealthReportStat(@NonNull String date) throws WxErrorException;
/**
* 获取健康上报任务ID列表
* 通过此接口可以获取企业当前正在运行的上报任务ID列表
* <p>
* 请求方式POSTHTTPS
* 请求地址https://qyapi.weixin.qq.com/cgi-bin/health/get_report_jobids?access_token=ACCESS_TOKEN
*
* @param offset 分页偏移量, 默认为0
* @param limit 分页预期请求的数据量默认为100取值范围 1 ~ 100
* @return
* @throws WxErrorException
*/
WxCpGetReportJobIds getReportJobIds(Integer offset, Integer limit) throws WxErrorException;
/**
* 获取健康上报任务详情
* 通过此接口可以获取指定的健康上报任务详情
* <p>
* 请求方式POSTHTTPS
* 请求地址https://qyapi.weixin.qq.com/cgi-bin/health/get_report_job_info?access_token=ACCESS_TOKEN
*
* @param jobId 任务ID
* @param date 具体某天任务详情仅支持获取最近14天数据
* @return
* @throws WxErrorException
*/
WxCpGetReportJobInfo getReportJobInfo(@NonNull String jobId, @NonNull String date) throws WxErrorException;
}

View File

@ -400,6 +400,13 @@ public interface WxCpService extends WxService {
*/
WxCpOaService getOaService();
/**
* 获取家校应用健康上报的服务类对象
*
* @return
*/
WxCpSchoolHealthService getSchoolHealthService();
/**
* 获取直播相关接口的服务类对象
*

View File

@ -49,6 +49,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
private WxCpTagService tagService = new WxCpTagServiceImpl(this);
private WxCpAgentService agentService = new WxCpAgentServiceImpl(this);
private WxCpOaService oaService = new WxCpOaServiceImpl(this);
private WxCpSchoolHealthService schoolHealthService = new WxCpSchoolHealthServiceImpl(this);
private WxCpLivingService livingService = new WxCpLivingServiceImpl(this);
private WxCpOaAgentService oaAgentService = new WxCpOaAgentServiceImpl(this);
private WxCpOaWeDriveService oaWeDriveService = new WxCpOaWeDriveServiceImpl(this);
@ -493,6 +494,11 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
return oaService;
}
@Override
public WxCpSchoolHealthService getSchoolHealthService() {
return schoolHealthService;
}
@Override
public WxCpLivingService getLivingService() {
return livingService;

View File

@ -0,0 +1,59 @@
package me.chanjar.weixin.cp.api.impl;
import com.google.gson.JsonObject;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpSchoolHealthService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.school.health.WxCpGetHealthReportStat;
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobIds;
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobInfo;
import java.util.Optional;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.School.*;
/**
* 企业微信家校应用 健康上报接口实现类.
*
* @author <a href="https://github.com/0katekate0">Wang_Wong</a>
* @date: 2022/5/31 9:16
*/
@Slf4j
@RequiredArgsConstructor
public class WxCpSchoolHealthServiceImpl implements WxCpSchoolHealthService {
private final WxCpService cpService;
@Override
public WxCpGetHealthReportStat getHealthReportStat(@NonNull String date) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_HEALTH_REPORT_STAT);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("date", date);
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
return WxCpGetHealthReportStat.fromJson(responseContent);
}
@Override
public WxCpGetReportJobIds getReportJobIds(Integer offset, Integer limit) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_REPORT_JOBIDS);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("offset", Optional.ofNullable(offset).orElse(0));
jsonObject.addProperty("limit", Optional.ofNullable(limit).orElse(100));
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
return WxCpGetReportJobIds.fromJson(responseContent);
}
@Override
public WxCpGetReportJobInfo getReportJobInfo(@NonNull String jobId, @NonNull String date) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_REPORT_JOB_INFO);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("jobid", jobId);
jsonObject.addProperty("date", date);
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
return WxCpGetReportJobInfo.fromJson(responseContent);
}
}

View File

@ -0,0 +1,33 @@
package me.chanjar.weixin.cp.bean.school.health;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
/**
* 获取健康上报使用统计.
*
* @author Wang_Wong
*/
@Data
public class WxCpGetHealthReportStat extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625142879581L;
@SerializedName("pv")
private Integer pv;
@SerializedName("uv")
private Integer uv;
public static WxCpGetHealthReportStat fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpGetHealthReportStat.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}

View File

@ -0,0 +1,34 @@
package me.chanjar.weixin.cp.bean.school.health;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
import java.util.List;
/**
* 获取健康上报使用统计.
*
* @author Wang_Wong
*/
@Data
public class WxCpGetReportJobIds extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625142879581L;
@SerializedName("ending")
private Integer ending;
@SerializedName("jobids")
private List<String> jobIds;
public static WxCpGetReportJobIds fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpGetReportJobIds.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}

View File

@ -0,0 +1,165 @@
package me.chanjar.weixin.cp.bean.school.health;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
import java.util.List;
/**
* 获取健康上报任务详情.
*
* @author Wang_Wong
*/
@Data
public class WxCpGetReportJobInfo extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625142879581L;
@SerializedName("job_info")
private JobInfo jobInfo;
@Getter
@Setter
public static class JobInfo implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;
@SerializedName("title")
private String title;
@SerializedName("creator")
private String creator;
@SerializedName("type")
private Integer type;
@SerializedName("report_type")
private Integer reportType;
@SerializedName("skip_weekend")
private Integer skipWeekend;
@SerializedName("finish_cnt")
private Integer finishCnt;
@SerializedName("apply_range")
private ApplyRange applyRange;
@SerializedName("report_to")
private ReportTo reportTo;
@SerializedName("question_templates")
private List<QuestionTemplate> questionTemplates;
public static JobInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, JobInfo.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
@Getter
@Setter
public static class ApplyRange implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;
@SerializedName("userids")
private List<String> userIds;
@SerializedName("partyids")
private List<Integer> partyIds;
public static ApplyRange fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, ApplyRange.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
@Getter
@Setter
public static class ReportTo implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;
@SerializedName("userids")
private List<String> userIds;
public static ReportTo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, ReportTo.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
@Getter
@Setter
public static class QuestionTemplate implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;
@SerializedName("question_id")
private Integer questionId;
@SerializedName("question_type")
private Integer questionType;
@SerializedName("is_required")
private Integer isRequired;
@SerializedName("title")
private String title;
@SerializedName("option_list")
private List<OptionList> optionList;
public static QuestionTemplate fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, QuestionTemplate.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
@Getter
@Setter
public static class OptionList implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;
@SerializedName("option_id")
private Integer optionId;
@SerializedName("option_text")
private String optionText;
public static OptionList fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, OptionList.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
public static WxCpGetReportJobInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpGetReportJobInfo.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}

View File

@ -173,6 +173,12 @@ public interface WxCpApiPathConsts {
String GET_OPEN_APPROVAL_DATA = "/cgi-bin/corp/getopenapprovaldata";
}
interface School {
String GET_HEALTH_REPORT_STAT = "/cgi-bin/health/get_health_report_stat";
String GET_REPORT_JOBIDS = "/cgi-bin/health/get_report_jobids";
String GET_REPORT_JOB_INFO = "/cgi-bin/health/get_report_job_info";
}
interface Living {
String GET_LIVING_CODE = "/cgi-bin/living/get_living_code";
String GET_LIVING_INFO = "/cgi-bin/living/get_living_info?livingid=";

View File

@ -168,7 +168,14 @@ public class WxCpMsgAuditTest {
return;
}
// 拉取媒体文件
/**
* 拉取媒体文件
*
* 注意
* 1根据上面返回的文件类型拼接好存放文件的绝对路径即可此时绝对路径写入文件流来达到获取媒体文件的目的
* 2拉取完媒体文件之后此时文件已经存在绝对路径可以通过mq异步上传到对象存储
* 3比如可以上传到阿里云oss或者腾讯云cos
*/
String targetPath = path + md5Sum + suffix;
cpService.getMsgAuditService().getMediaFile(sdkFileId, null, null, 1000L, targetPath);

View File

@ -0,0 +1,66 @@
package me.chanjar.weixin.cp.api;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.school.health.WxCpGetHealthReportStat;
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobIds;
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobInfo;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.demo.WxCpDemoInMemoryConfigStorage;
import org.testng.annotations.Test;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 企业微信家校应用 健康上报接口.
* https://developer.work.weixin.qq.com/document/path/93676
*
* @author <a href="https://github.com/0katekate0">Wang_Wong</a>
* @date: 2022/5/31 9:10
*/
@Slf4j
public class WxCpSchoolHealthTest {
private static WxCpConfigStorage wxCpConfigStorage;
private static WxCpService cpService;
@Test
public void test() throws WxErrorException {
InputStream inputStream = ClassLoader.getSystemResourceAsStream("test-config.xml");
WxCpDemoInMemoryConfigStorage config = WxCpDemoInMemoryConfigStorage.fromXml(inputStream);
wxCpConfigStorage = config;
cpService = new WxCpServiceImpl();
cpService.setWxCpConfigStorage(config);
String currDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
/**
* 获取健康上报任务ID列表
* https://developer.work.weixin.qq.com/document/path/93677
*/
WxCpGetReportJobIds reportJobids = cpService.getSchoolHealthService().getReportJobIds(null, null);
log.info("返回的reportJobids为{}", reportJobids.toJson());
/**
* 获取健康上报任务详情
* https://developer.work.weixin.qq.com/document/path/93678
*/
WxCpGetReportJobInfo reportJobInfo = cpService.getSchoolHealthService().getReportJobInfo(null, currDate);
log.info("返回的reportJobInfo为{}", reportJobInfo.toJson());
/**
* 获取健康上报使用统计
* https://developer.work.weixin.qq.com/document/path/93676
*/
String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
WxCpGetHealthReportStat healthReportStat = cpService.getSchoolHealthService().getHealthReportStat(date);
log.info("返回的healthReportStat为{}", healthReportStat.toJson());
}
}