Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【企业微信】增加获取用户填写答案接口 #2689

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

/**
* 获取用户填写答案
* 通过此接口可以获取指定的健康上报任务详情。
* <p>
* 请求方式: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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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<Answer> 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<ReportValue> 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<Integer> multiChoice;

@SerializedName("text")
private String text;

@SerializedName("fileid")
private List<String> 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down