Skip to content

Commit 6a77bc9

Browse files
committed
【企业微信】增加获取健康上报任务接口
1 parent 96efed7 commit 6a77bc9

File tree

6 files changed

+211
-10
lines changed

6 files changed

+211
-10
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpSchoolHealthService.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import lombok.NonNull;
44
import me.chanjar.weixin.common.error.WxErrorException;
55
import me.chanjar.weixin.cp.bean.school.health.WxCpGetHealthReportStat;
6-
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobids;
6+
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobIds;
7+
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobInfo;
78

89
/**
910
* 企业微信家校应用 健康上报接口.
@@ -37,6 +38,20 @@ public interface WxCpSchoolHealthService {
3738
* @return
3839
* @throws WxErrorException
3940
*/
40-
WxCpGetReportJobids getReportJobids(Integer offset, Integer limit) throws WxErrorException;
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;
4156

4257
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpSchoolHealthServiceImpl.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import me.chanjar.weixin.cp.api.WxCpSchoolHealthService;
99
import me.chanjar.weixin.cp.api.WxCpService;
1010
import me.chanjar.weixin.cp.bean.school.health.WxCpGetHealthReportStat;
11-
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobids;
11+
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobIds;
12+
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobInfo;
1213

1314
import java.util.Optional;
1415

@@ -36,13 +37,23 @@ public WxCpGetHealthReportStat getHealthReportStat(@NonNull String date) throws
3637
}
3738

3839
@Override
39-
public WxCpGetReportJobids getReportJobids(Integer offset, Integer limit) throws WxErrorException {
40+
public WxCpGetReportJobIds getReportJobIds(Integer offset, Integer limit) throws WxErrorException {
4041
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_REPORT_JOBIDS);
4142
JsonObject jsonObject = new JsonObject();
4243
jsonObject.addProperty("offset", Optional.ofNullable(offset).orElse(0));
4344
jsonObject.addProperty("limit", Optional.ofNullable(limit).orElse(100));
4445
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
45-
return WxCpGetReportJobids.fromJson(responseContent);
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);
4657
}
4758

4859
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/health/WxCpGetReportJobids.java renamed to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/health/WxCpGetReportJobIds.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @author Wang_Wong
1515
*/
1616
@Data
17-
public class WxCpGetReportJobids extends WxCpBaseResp implements Serializable {
17+
public class WxCpGetReportJobIds extends WxCpBaseResp implements Serializable {
1818
private static final long serialVersionUID = -5028321625142879581L;
1919

2020
@SerializedName("ending")
@@ -23,8 +23,8 @@ public class WxCpGetReportJobids extends WxCpBaseResp implements Serializable {
2323
@SerializedName("jobids")
2424
private List<String> jobIds;
2525

26-
public static WxCpGetReportJobids fromJson(String json) {
27-
return WxCpGsonBuilder.create().fromJson(json, WxCpGetReportJobids.class);
26+
public static WxCpGetReportJobIds fromJson(String json) {
27+
return WxCpGsonBuilder.create().fromJson(json, WxCpGetReportJobIds.class);
2828
}
2929

3030
public String toJson() {
Lines changed: 165 additions & 0 deletions
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+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ interface Oa {
176176
interface School {
177177
String GET_HEALTH_REPORT_STAT = "/cgi-bin/health/get_health_report_stat";
178178
String GET_REPORT_JOBIDS = "/cgi-bin/health/get_report_jobids";
179+
String GET_REPORT_JOB_INFO = "/cgi-bin/health/get_report_job_info";
179180
}
180181

181182
interface Living {

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpSchoolHealthTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import me.chanjar.weixin.common.error.WxErrorException;
55
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
66
import me.chanjar.weixin.cp.bean.school.health.WxCpGetHealthReportStat;
7-
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobids;
7+
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobIds;
8+
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobInfo;
89
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
910
import me.chanjar.weixin.cp.demo.WxCpDemoInMemoryConfigStorage;
1011
import org.testng.annotations.Test;
@@ -35,15 +36,23 @@ public void test() throws WxErrorException {
3536
wxCpConfigStorage = config;
3637
cpService = new WxCpServiceImpl();
3738
cpService.setWxCpConfigStorage(config);
39+
String currDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
3840

3941

4042
/**
4143
* 获取健康上报任务ID列表
4244
* https://developer.work.weixin.qq.com/document/path/93677
4345
*/
44-
WxCpGetReportJobids reportJobids = cpService.getSchoolHealthService().getReportJobids(null, null);
46+
WxCpGetReportJobIds reportJobids = cpService.getSchoolHealthService().getReportJobIds(null, null);
4547
log.info("返回的reportJobids为:{}", reportJobids.toJson());
4648

49+
/**
50+
* 获取健康上报任务详情
51+
* https://developer.work.weixin.qq.com/document/path/93678
52+
*/
53+
WxCpGetReportJobInfo reportJobInfo = cpService.getSchoolHealthService().getReportJobInfo(null, currDate);
54+
log.info("返回的reportJobInfo为:{}", reportJobInfo.toJson());
55+
4756
/**
4857
* 获取健康上报使用统计
4958
* https://developer.work.weixin.qq.com/document/path/93676

0 commit comments

Comments
 (0)