From 20d1626cfd4294cd31934514b2a38468c540e8b6 Mon Sep 17 00:00:00 2001 From: 0katekate0 <1960779692@qq.com> Date: Thu, 9 Jun 2022 16:51:56 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E3=80=91=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=A1=AB=E5=86=99=E7=AD=94=E6=A1=88=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cp/api/WxCpSchoolHealthService.java | 17 ++++ .../api/impl/WxCpSchoolHealthServiceImpl.java | 17 ++++ .../school/health/WxCpGetReportAnswer.java | 96 +++++++++++++++++++ .../weixin/cp/constant/WxCpApiPathConsts.java | 1 + .../weixin/cp/api/WxCpSchoolHealthTest.java | 13 +++ 5 files changed, 144 insertions(+) create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/health/WxCpGetReportAnswer.java diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpSchoolHealthService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpSchoolHealthService.java index 0d852e74b1..76233046d3 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpSchoolHealthService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpSchoolHealthService.java @@ -3,6 +3,7 @@ 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.WxCpGetReportAnswer; import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobIds; import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobInfo; @@ -54,4 +55,20 @@ public interface WxCpSchoolHealthService { */ WxCpGetReportJobInfo getReportJobInfo(@NonNull String jobId, @NonNull String date) throws WxErrorException; + /** + * 获取用户填写答案 + * 通过此接口可以获取指定的健康上报任务详情。 + *

+ * 请求方式:POST(HTTPS) + * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/health/get_report_answer?access_token=ACCESS_TOKEN + * + * @param jobId + * @param date + * @param offset + * @param limit + * @return + * @throws WxErrorException + */ + WxCpGetReportAnswer getReportAnswer(@NonNull String jobId, @NonNull String date, Integer offset, Integer limit) throws WxErrorException; + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpSchoolHealthServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpSchoolHealthServiceImpl.java index bee4bf0306..ff1119cc1a 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpSchoolHealthServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpSchoolHealthServiceImpl.java @@ -8,6 +8,7 @@ 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.WxCpGetReportAnswer; import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobIds; import me.chanjar.weixin.cp.bean.school.health.WxCpGetReportJobInfo; @@ -56,4 +57,20 @@ public WxCpGetReportJobInfo getReportJobInfo(@NonNull String jobId, @NonNull Str return WxCpGetReportJobInfo.fromJson(responseContent); } + @Override + public WxCpGetReportAnswer getReportAnswer(@NonNull String jobId, @NonNull String date, Integer offset, Integer limit) throws WxErrorException { + String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_REPORT_ANSWER); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("jobid", jobId); + jsonObject.addProperty("date", date); + if (offset != null) { + jsonObject.addProperty("offset", offset); + } + if (limit != null) { + jsonObject.addProperty("limit", limit); + } + String responseContent = this.cpService.post(apiUrl, jsonObject.toString()); + return WxCpGetReportAnswer.fromJson(responseContent); + } + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/health/WxCpGetReportAnswer.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/health/WxCpGetReportAnswer.java new file mode 100644 index 0000000000..a016ad1ef4 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/health/WxCpGetReportAnswer.java @@ -0,0 +1,96 @@ +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 WxCpGetReportAnswer extends WxCpBaseResp implements Serializable { + private static final long serialVersionUID = -5028321625142879581L; + + @SerializedName("answers") + private List answers; + + @Getter + @Setter + public static class Answer implements Serializable { + private static final long serialVersionUID = -5696099236344075582L; + + @SerializedName("userid") + private String userId; + + @SerializedName("id_type") + private Integer idType; + + @SerializedName("report_time") + private Long reportTime; + + @SerializedName("student_userid") + private String studentUserId; + + @SerializedName("parent_userid") + private String parentUserId; + + @SerializedName("report_values") + private List reportValues; + + public static Answer fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, Answer.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + + } + + @Getter + @Setter + public static class ReportValue implements Serializable { + private static final long serialVersionUID = -5696099236344075582L; + + @SerializedName("question_id") + private Integer questionId; + + @SerializedName("single_chose") + private Integer singleChose; + + @SerializedName("multi_choice") + private List multiChoice; + + @SerializedName("text") + private String text; + + @SerializedName("fileid") + private List fileId; + + public static ReportValue fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, ReportValue.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + + } + + public static WxCpGetReportAnswer fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpGetReportAnswer.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java index a9528929fd..8ea37c36a8 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java @@ -177,6 +177,7 @@ 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"; + String GET_REPORT_ANSWER = "/cgi-bin/health/get_report_answer"; String GET_TEACHER_CUSTOMIZE_HEALTH_INFO = "/cgi-bin/school/user/get_teacher_customize_health_info"; String GET_STUDENT_CUSTOMIZE_HEALTH_INFO = "/cgi-bin/school/user/get_student_customize_health_info"; diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpSchoolHealthTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpSchoolHealthTest.java index 2ed24719bd..5e7469ddf8 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpSchoolHealthTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpSchoolHealthTest.java @@ -4,6 +4,7 @@ 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.WxCpGetReportAnswer; 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; @@ -39,6 +40,18 @@ public void test() throws WxErrorException { String currDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); + // Test + 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\"]}]}]}"; + WxCpGetReportAnswer getReportAnswer = WxCpGetReportAnswer.fromJson(reportAnswerStr); + log.info("获取对应的getReportAnswer:{}", getReportAnswer.toJson()); + + /** + * 获取用户填写答案 + * https://developer.work.weixin.qq.com/document/path/93679 + */ + WxCpGetReportAnswer reportAnswer = cpService.getSchoolHealthService().getReportAnswer("xxxx", currDate, null, null); + log.info("返回的reportAnswer为:{}", reportAnswer.toJson()); + /** * 获取健康上报任务ID列表 * https://developer.work.weixin.qq.com/document/path/93677