Skip to content

Commit 3952fcd

Browse files
authored
🆕 #2674【企业微信】增加家校应用健康上报部分接口
1 parent 42122ce commit 3952fcd

File tree

10 files changed

+441
-1
lines changed

10 files changed

+441
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package me.chanjar.weixin.cp.api;
2+
3+
import lombok.NonNull;
4+
import me.chanjar.weixin.common.error.WxErrorException;
5+
import me.chanjar.weixin.cp.bean.school.health.WxCpGetHealthReportStat;
6+
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobIds;
7+
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobInfo;
8+
9+
/**
10+
* 企业微信家校应用 健康上报接口.
11+
* https://developer.work.weixin.qq.com/document/path/93676
12+
*
13+
* @author <a href="https://github.com/0katekate0">Wang_Wong</a>
14+
* @date: 2022/5/31 9:10
15+
*/
16+
public interface WxCpSchoolHealthService {
17+
18+
/**
19+
* 获取健康上报使用统计
20+
* 请求方式:POST(HTTPS)
21+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/health/get_health_report_stat?access_token=ACCESS_TOKEN
22+
*
23+
* @param date 具体某天的使用统计,最长支持获取30天前数据
24+
* @return
25+
* @throws WxErrorException
26+
*/
27+
WxCpGetHealthReportStat getHealthReportStat(@NonNull String date) throws WxErrorException;
28+
29+
/**
30+
* 获取健康上报任务ID列表
31+
* 通过此接口可以获取企业当前正在运行的上报任务ID列表。
32+
* <p>
33+
* 请求方式:POST(HTTPS)
34+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/health/get_report_jobids?access_token=ACCESS_TOKEN
35+
*
36+
* @param offset 否 分页,偏移量, 默认为0
37+
* @param limit 否 分页,预期请求的数据量,默认为100,取值范围 1 ~ 100
38+
* @return
39+
* @throws WxErrorException
40+
*/
41+
WxCpGetReportJobIds getReportJobIds(Integer offset, Integer limit) throws WxErrorException;
42+
43+
/**
44+
* 获取健康上报任务详情
45+
* 通过此接口可以获取指定的健康上报任务详情。
46+
* <p>
47+
* 请求方式:POST(HTTPS)
48+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/health/get_report_job_info?access_token=ACCESS_TOKEN
49+
*
50+
* @param jobId 是 任务ID
51+
* @param date 是 具体某天任务详情,仅支持获取最近14天数据
52+
* @return
53+
* @throws WxErrorException
54+
*/
55+
WxCpGetReportJobInfo getReportJobInfo(@NonNull String jobId, @NonNull String date) throws WxErrorException;
56+
57+
}

Diff for: weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java

+7
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,13 @@ public interface WxCpService extends WxService {
400400
*/
401401
WxCpOaService getOaService();
402402

403+
/**
404+
* 获取家校应用健康上报的服务类对象
405+
*
406+
* @return
407+
*/
408+
WxCpSchoolHealthService getSchoolHealthService();
409+
403410
/**
404411
* 获取直播相关接口的服务类对象
405412
*

Diff for: weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
4949
private WxCpTagService tagService = new WxCpTagServiceImpl(this);
5050
private WxCpAgentService agentService = new WxCpAgentServiceImpl(this);
5151
private WxCpOaService oaService = new WxCpOaServiceImpl(this);
52+
private WxCpSchoolHealthService schoolHealthService = new WxCpSchoolHealthServiceImpl(this);
5253
private WxCpLivingService livingService = new WxCpLivingServiceImpl(this);
5354
private WxCpOaAgentService oaAgentService = new WxCpOaAgentServiceImpl(this);
5455
private WxCpOaWeDriveService oaWeDriveService = new WxCpOaWeDriveServiceImpl(this);
@@ -493,6 +494,11 @@ public WxCpOaService getOaService() {
493494
return oaService;
494495
}
495496

497+
@Override
498+
public WxCpSchoolHealthService getSchoolHealthService() {
499+
return schoolHealthService;
500+
}
501+
496502
@Override
497503
public WxCpLivingService getLivingService() {
498504
return livingService;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package me.chanjar.weixin.cp.api.impl;
2+
3+
import com.google.gson.JsonObject;
4+
import lombok.NonNull;
5+
import lombok.RequiredArgsConstructor;
6+
import lombok.extern.slf4j.Slf4j;
7+
import me.chanjar.weixin.common.error.WxErrorException;
8+
import me.chanjar.weixin.cp.api.WxCpSchoolHealthService;
9+
import me.chanjar.weixin.cp.api.WxCpService;
10+
import me.chanjar.weixin.cp.bean.school.health.WxCpGetHealthReportStat;
11+
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobIds;
12+
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobInfo;
13+
14+
import java.util.Optional;
15+
16+
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.School.*;
17+
18+
/**
19+
* 企业微信家校应用 健康上报接口实现类.
20+
*
21+
* @author <a href="https://github.com/0katekate0">Wang_Wong</a>
22+
* @date: 2022/5/31 9:16
23+
*/
24+
@Slf4j
25+
@RequiredArgsConstructor
26+
public class WxCpSchoolHealthServiceImpl implements WxCpSchoolHealthService {
27+
28+
private final WxCpService cpService;
29+
30+
@Override
31+
public WxCpGetHealthReportStat getHealthReportStat(@NonNull String date) throws WxErrorException {
32+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_HEALTH_REPORT_STAT);
33+
JsonObject jsonObject = new JsonObject();
34+
jsonObject.addProperty("date", date);
35+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
36+
return WxCpGetHealthReportStat.fromJson(responseContent);
37+
}
38+
39+
@Override
40+
public WxCpGetReportJobIds getReportJobIds(Integer offset, Integer limit) throws WxErrorException {
41+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_REPORT_JOBIDS);
42+
JsonObject jsonObject = new JsonObject();
43+
jsonObject.addProperty("offset", Optional.ofNullable(offset).orElse(0));
44+
jsonObject.addProperty("limit", Optional.ofNullable(limit).orElse(100));
45+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
46+
return WxCpGetReportJobIds.fromJson(responseContent);
47+
}
48+
49+
@Override
50+
public WxCpGetReportJobInfo getReportJobInfo(@NonNull String jobId, @NonNull String date) throws WxErrorException {
51+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_REPORT_JOB_INFO);
52+
JsonObject jsonObject = new JsonObject();
53+
jsonObject.addProperty("jobid", jobId);
54+
jsonObject.addProperty("date", date);
55+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
56+
return WxCpGetReportJobInfo.fromJson(responseContent);
57+
}
58+
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package me.chanjar.weixin.cp.bean.school.health;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
6+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
7+
8+
import java.io.Serializable;
9+
10+
/**
11+
* 获取健康上报使用统计.
12+
*
13+
* @author Wang_Wong
14+
*/
15+
@Data
16+
public class WxCpGetHealthReportStat extends WxCpBaseResp implements Serializable {
17+
private static final long serialVersionUID = -5028321625142879581L;
18+
19+
@SerializedName("pv")
20+
private Integer pv;
21+
22+
@SerializedName("uv")
23+
private Integer uv;
24+
25+
public static WxCpGetHealthReportStat fromJson(String json) {
26+
return WxCpGsonBuilder.create().fromJson(json, WxCpGetHealthReportStat.class);
27+
}
28+
29+
public String toJson() {
30+
return WxCpGsonBuilder.create().toJson(this);
31+
}
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package me.chanjar.weixin.cp.bean.school.health;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
6+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
7+
8+
import java.io.Serializable;
9+
import java.util.List;
10+
11+
/**
12+
* 获取健康上报使用统计.
13+
*
14+
* @author Wang_Wong
15+
*/
16+
@Data
17+
public class WxCpGetReportJobIds extends WxCpBaseResp implements Serializable {
18+
private static final long serialVersionUID = -5028321625142879581L;
19+
20+
@SerializedName("ending")
21+
private Integer ending;
22+
23+
@SerializedName("jobids")
24+
private List<String> jobIds;
25+
26+
public static WxCpGetReportJobIds fromJson(String json) {
27+
return WxCpGsonBuilder.create().fromJson(json, WxCpGetReportJobIds.class);
28+
}
29+
30+
public String toJson() {
31+
return WxCpGsonBuilder.create().toJson(this);
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package me.chanjar.weixin.cp.bean.school.health;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
8+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
9+
10+
import java.io.Serializable;
11+
import java.util.List;
12+
13+
/**
14+
* 获取健康上报任务详情.
15+
*
16+
* @author Wang_Wong
17+
*/
18+
@Data
19+
public class WxCpGetReportJobInfo extends WxCpBaseResp implements Serializable {
20+
private static final long serialVersionUID = -5028321625142879581L;
21+
22+
@SerializedName("job_info")
23+
private JobInfo jobInfo;
24+
25+
@Getter
26+
@Setter
27+
public static class JobInfo implements Serializable {
28+
private static final long serialVersionUID = -5696099236344075582L;
29+
30+
@SerializedName("title")
31+
private String title;
32+
33+
@SerializedName("creator")
34+
private String creator;
35+
36+
@SerializedName("type")
37+
private Integer type;
38+
39+
@SerializedName("report_type")
40+
private Integer reportType;
41+
42+
@SerializedName("skip_weekend")
43+
private Integer skipWeekend;
44+
45+
@SerializedName("finish_cnt")
46+
private Integer finishCnt;
47+
48+
@SerializedName("apply_range")
49+
private ApplyRange applyRange;
50+
51+
@SerializedName("report_to")
52+
private ReportTo reportTo;
53+
54+
@SerializedName("question_templates")
55+
private List<QuestionTemplate> questionTemplates;
56+
57+
public static JobInfo fromJson(String json) {
58+
return WxCpGsonBuilder.create().fromJson(json, JobInfo.class);
59+
}
60+
61+
public String toJson() {
62+
return WxCpGsonBuilder.create().toJson(this);
63+
}
64+
65+
}
66+
67+
@Getter
68+
@Setter
69+
public static class ApplyRange implements Serializable {
70+
private static final long serialVersionUID = -5696099236344075582L;
71+
72+
@SerializedName("userids")
73+
private List<String> userIds;
74+
75+
@SerializedName("partyids")
76+
private List<Integer> partyIds;
77+
78+
public static ApplyRange fromJson(String json) {
79+
return WxCpGsonBuilder.create().fromJson(json, ApplyRange.class);
80+
}
81+
82+
public String toJson() {
83+
return WxCpGsonBuilder.create().toJson(this);
84+
}
85+
86+
}
87+
88+
@Getter
89+
@Setter
90+
public static class ReportTo implements Serializable {
91+
private static final long serialVersionUID = -5696099236344075582L;
92+
93+
@SerializedName("userids")
94+
private List<String> userIds;
95+
96+
public static ReportTo fromJson(String json) {
97+
return WxCpGsonBuilder.create().fromJson(json, ReportTo.class);
98+
}
99+
100+
public String toJson() {
101+
return WxCpGsonBuilder.create().toJson(this);
102+
}
103+
104+
}
105+
106+
@Getter
107+
@Setter
108+
public static class QuestionTemplate implements Serializable {
109+
private static final long serialVersionUID = -5696099236344075582L;
110+
111+
@SerializedName("question_id")
112+
private Integer questionId;
113+
114+
@SerializedName("question_type")
115+
private Integer questionType;
116+
117+
@SerializedName("is_required")
118+
private Integer isRequired;
119+
120+
@SerializedName("title")
121+
private String title;
122+
123+
@SerializedName("option_list")
124+
private List<OptionList> optionList;
125+
126+
public static QuestionTemplate fromJson(String json) {
127+
return WxCpGsonBuilder.create().fromJson(json, QuestionTemplate.class);
128+
}
129+
130+
public String toJson() {
131+
return WxCpGsonBuilder.create().toJson(this);
132+
}
133+
134+
}
135+
136+
@Getter
137+
@Setter
138+
public static class OptionList implements Serializable {
139+
private static final long serialVersionUID = -5696099236344075582L;
140+
141+
@SerializedName("option_id")
142+
private Integer optionId;
143+
144+
@SerializedName("option_text")
145+
private String optionText;
146+
147+
public static OptionList fromJson(String json) {
148+
return WxCpGsonBuilder.create().fromJson(json, OptionList.class);
149+
}
150+
151+
public String toJson() {
152+
return WxCpGsonBuilder.create().toJson(this);
153+
}
154+
155+
}
156+
157+
public static WxCpGetReportJobInfo fromJson(String json) {
158+
return WxCpGsonBuilder.create().fromJson(json, WxCpGetReportJobInfo.class);
159+
}
160+
161+
public String toJson() {
162+
return WxCpGsonBuilder.create().toJson(this);
163+
}
164+
165+
}

Diff for: weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

+6
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ interface Oa {
173173
String GET_OPEN_APPROVAL_DATA = "/cgi-bin/corp/getopenapprovaldata";
174174
}
175175

176+
interface School {
177+
String GET_HEALTH_REPORT_STAT = "/cgi-bin/health/get_health_report_stat";
178+
String GET_REPORT_JOBIDS = "/cgi-bin/health/get_report_jobids";
179+
String GET_REPORT_JOB_INFO = "/cgi-bin/health/get_report_job_info";
180+
}
181+
176182
interface Living {
177183
String GET_LIVING_CODE = "/cgi-bin/living/get_living_code";
178184
String GET_LIVING_INFO = "/cgi-bin/living/get_living_info?livingid=";

0 commit comments

Comments
 (0)