Skip to content

Commit bb8c82d

Browse files
authored
🆕 #2689【企业微信】增加获取用户填写答案的接口
1 parent 508d053 commit bb8c82d

File tree

5 files changed

+144
-0
lines changed

5 files changed

+144
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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.WxCpGetReportAnswer;
67
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobIds;
78
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobInfo;
89

@@ -54,4 +55,20 @@ public interface WxCpSchoolHealthService {
5455
*/
5556
WxCpGetReportJobInfo getReportJobInfo(@NonNull String jobId, @NonNull String date) throws WxErrorException;
5657

58+
/**
59+
* 获取用户填写答案
60+
* 通过此接口可以获取指定的健康上报任务详情。
61+
* <p>
62+
* 请求方式:POST(HTTPS)
63+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/health/get_report_answer?access_token=ACCESS_TOKEN
64+
*
65+
* @param jobId
66+
* @param date
67+
* @param offset
68+
* @param limit
69+
* @return
70+
* @throws WxErrorException
71+
*/
72+
WxCpGetReportAnswer getReportAnswer(@NonNull String jobId, @NonNull String date, Integer offset, Integer limit) throws WxErrorException;
73+
5774
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
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.WxCpGetReportAnswer;
1112
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobIds;
1213
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobInfo;
1314

@@ -56,4 +57,20 @@ public WxCpGetReportJobInfo getReportJobInfo(@NonNull String jobId, @NonNull Str
5657
return WxCpGetReportJobInfo.fromJson(responseContent);
5758
}
5859

60+
@Override
61+
public WxCpGetReportAnswer getReportAnswer(@NonNull String jobId, @NonNull String date, Integer offset, Integer limit) throws WxErrorException {
62+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_REPORT_ANSWER);
63+
JsonObject jsonObject = new JsonObject();
64+
jsonObject.addProperty("jobid", jobId);
65+
jsonObject.addProperty("date", date);
66+
if (offset != null) {
67+
jsonObject.addProperty("offset", offset);
68+
}
69+
if (limit != null) {
70+
jsonObject.addProperty("limit", limit);
71+
}
72+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
73+
return WxCpGetReportAnswer.fromJson(responseContent);
74+
}
75+
5976
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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 WxCpGetReportAnswer extends WxCpBaseResp implements Serializable {
20+
private static final long serialVersionUID = -5028321625142879581L;
21+
22+
@SerializedName("answers")
23+
private List<Answer> answers;
24+
25+
@Getter
26+
@Setter
27+
public static class Answer implements Serializable {
28+
private static final long serialVersionUID = -5696099236344075582L;
29+
30+
@SerializedName("userid")
31+
private String userId;
32+
33+
@SerializedName("id_type")
34+
private Integer idType;
35+
36+
@SerializedName("report_time")
37+
private Long reportTime;
38+
39+
@SerializedName("student_userid")
40+
private String studentUserId;
41+
42+
@SerializedName("parent_userid")
43+
private String parentUserId;
44+
45+
@SerializedName("report_values")
46+
private List<ReportValue> reportValues;
47+
48+
public static Answer fromJson(String json) {
49+
return WxCpGsonBuilder.create().fromJson(json, Answer.class);
50+
}
51+
52+
public String toJson() {
53+
return WxCpGsonBuilder.create().toJson(this);
54+
}
55+
56+
}
57+
58+
@Getter
59+
@Setter
60+
public static class ReportValue implements Serializable {
61+
private static final long serialVersionUID = -5696099236344075582L;
62+
63+
@SerializedName("question_id")
64+
private Integer questionId;
65+
66+
@SerializedName("single_chose")
67+
private Integer singleChose;
68+
69+
@SerializedName("multi_choice")
70+
private List<Integer> multiChoice;
71+
72+
@SerializedName("text")
73+
private String text;
74+
75+
@SerializedName("fileid")
76+
private List<String> fileId;
77+
78+
public static ReportValue fromJson(String json) {
79+
return WxCpGsonBuilder.create().fromJson(json, ReportValue.class);
80+
}
81+
82+
public String toJson() {
83+
return WxCpGsonBuilder.create().toJson(this);
84+
}
85+
86+
}
87+
88+
public static WxCpGetReportAnswer fromJson(String json) {
89+
return WxCpGsonBuilder.create().fromJson(json, WxCpGetReportAnswer.class);
90+
}
91+
92+
public String toJson() {
93+
return WxCpGsonBuilder.create().toJson(this);
94+
}
95+
96+
}

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
@@ -177,6 +177,7 @@ 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";
179179
String GET_REPORT_JOB_INFO = "/cgi-bin/health/get_report_job_info";
180+
String GET_REPORT_ANSWER = "/cgi-bin/health/get_report_answer";
180181

181182
String GET_TEACHER_CUSTOMIZE_HEALTH_INFO = "/cgi-bin/school/user/get_teacher_customize_health_info";
182183
String GET_STUDENT_CUSTOMIZE_HEALTH_INFO = "/cgi-bin/school/user/get_student_customize_health_info";

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
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.WxCpGetReportAnswer;
78
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobIds;
89
import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobInfo;
910
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
@@ -39,6 +40,18 @@ public void test() throws WxErrorException {
3940
String currDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
4041

4142

43+
// Test
44+
String reportAnswerStr = "{\"errcode\":0,\"errmsg\":\"ok\",\"answers\":[{\"id_type\":1,\"userid\":\"userid2\",\"report_time\":123456789,\"report_values\":[{\"question_id\":1,\"single_choice\":2},{\"question_id\":2,\"text\":\"广东省广州市\"},{\"question_id\":3,\"multi_choice\":[1,3]},{\"question_id\":4,\"fileid\":[\"XXXXXXX\"]}]},{\"id_type\":2,\"student_userid\":\"student_userid1\",\"parent_userid\":\"parent_userid1\",\"report_time\":123456789,\"report_values\":[{\"question_id\":1,\"single_choice\":1},{\"question_id\":2,\"text\":\"广东省深圳市\"},{\"question_id\":3,\"multi_choice\":[1,2,3]},{\"question_id\":4,\"fileid\":[\"XXXXXXX\"]}]}]}";
45+
WxCpGetReportAnswer getReportAnswer = WxCpGetReportAnswer.fromJson(reportAnswerStr);
46+
log.info("获取对应的getReportAnswer:{}", getReportAnswer.toJson());
47+
48+
/**
49+
* 获取用户填写答案
50+
* https://developer.work.weixin.qq.com/document/path/93679
51+
*/
52+
WxCpGetReportAnswer reportAnswer = cpService.getSchoolHealthService().getReportAnswer("xxxx", currDate, null, null);
53+
log.info("返回的reportAnswer为:{}", reportAnswer.toJson());
54+
4255
/**
4356
* 获取健康上报任务ID列表
4457
* https://developer.work.weixin.qq.com/document/path/93677

0 commit comments

Comments
 (0)