feat(cp): complete WeDoc OA APIs and align form share/statistic compatibility#3926
feat(cp): complete WeDoc OA APIs and align form share/statistic compatibility#3926lyfuci wants to merge 7 commits intobinarywang:developfrom
Conversation
🤖 Augment PR SummarySummary: This PR expands the WeCom (企业微信) CP OA “WeDoc” integration to cover missing document, collect-form, admin, and smartsheet APIs, and updates compatibility for share/statistic payloads. Changes:
Technical Notes: New endpoints are wired via additional 🤖 Was this summary useful? React with 👍 or 👎 |
| @Override | ||
| public List<WxCpFormStatistic> formStatistic(@NonNull List<WxCpFormStatisticRequest> requests) throws WxErrorException { | ||
| String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_GET_FORM_STATISTIC); | ||
| String responseContent = this.cpService.post(apiUrl, WxCpFormStatisticRequest.toJson(requests)); |
There was a problem hiding this comment.
Note that cpService.post(...) validates responses by parsing them as a WxError JSON object; if get_form_statistic returns a top-level JSON array (as implied by WxCpFormStatistic.listFromJson), the call may fail during error parsing before reaching this deserialization.
Severity: high
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
| * 收集表统计结果. | ||
| */ | ||
| @Data | ||
| public class WxCpFormStatistic extends WxCpBaseResp implements Serializable { |
4c447e5 to
2095378
Compare
There was a problem hiding this comment.
Pull request overview
本次 PR 主要补全企业微信 OA 效率工具(WeDoc)相关能力,在 weixin-java-cp 模块中新增/完善文档、收集表、文档管理员与智能表格(smartsheet)相关的 API、路径常量与请求/响应模型,并通过新增的 Service/JSON 单元测试覆盖关键序列化与路径调用行为。
Changes:
- 补齐 WeDoc OA API:新增 doc/form/admin/smartsheet 场景的请求/响应 bean,并在
WxCpOaWeDocService/WxCpOaWeDocServiceImpl中补充对应方法实现 - 更新
WxCpApiPathConsts.Oa,补充 WeDoc 相关 API 路径常量 - 新增
WxCpOaWeDocServiceImplTest与WxCpOaWeDocJsonTest,覆盖路径路由与 JSON 协议(含 form_statistic 数组协议与 doc_share formid 兼容)
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDocService.java | 扩展 WeDoc OA 对外接口:新增 doc 权限/编辑/图片上传、admin、smartsheet、form 等方法,并保留 formStatistic 单请求兼容封装 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDocServiceImpl.java | 实现新增的 WeDoc OA API 调用逻辑(post/upload + bean 序列化/反序列化) |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java | 在顶层 WxCpService 暴露 getOaWeDocService() |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java | 注入并返回 WxCpOaWeDocService 实例 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java | 补充 WeDoc doc/form/admin/smartsheet 相关 API Path 常量 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocAuthInfo.java | 新增文档权限信息响应模型 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocModifyJoinRuleRequest.java | 新增修改文档查看规则请求模型 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocModifyMemberRequest.java | 新增修改文档通知范围/权限请求模型 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocModifySaftySettingRequest.java | 新增修改文档安全设置请求模型 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocShareRequest.java | 新增 doc_share 请求模型(兼容 docid/formid 二选一) |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocGetDataRequest.java | 新增获取文档数据请求模型(extra 透传) |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocData.java | 新增获取文档内容数据响应模型(content/doc_content 兼容) |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocModifyRequest.java | 新增编辑文档内容请求模型(requests + extra 透传) |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocImageUploadResult.java | 新增文档图片上传响应模型(url/image_url 兼容) |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocAdminRequest.java | 新增文档高级功能账号请求模型(支持 userid/open_userid + extra 透传) |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocAdminListResult.java | 新增文档高级功能账号列表响应模型 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocSmartSheetAuthRequest.java | 新增获取 smartsheet 权限请求模型 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocSmartSheetModifyAuthRequest.java | 新增修改 smartsheet 权限请求模型 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocSmartSheetAuth.java | 新增 smartsheet 权限响应模型(auth_info/field_auth/record_auth 兼容) |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocSmartSheetRequest.java | 新增 smartsheet 通用请求模型(properties/views/fields/records 等 extra 透传) |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocSmartSheetResult.java | 新增 smartsheet 通用响应模型(多字段命名兼容 + effective getter) |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpFormInfo.java | 新增收集表信息模型(题目/设置/范围等结构) |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpFormCreateRequest.java | 新增创建收集表请求模型 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpFormCreateResult.java | 新增创建收集表响应模型 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpFormModifyRequest.java | 新增编辑收集表请求模型 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpFormInfoResult.java | 新增获取收集表信息响应模型 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpFormStatisticRequest.java | 新增收集表统计请求模型(支持数组序列化) |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpFormStatistic.java | 新增收集表统计响应模型(submit/unfill 列表等字段) |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpFormAnswerRequest.java | 新增收集表答案请求模型 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpFormAnswer.java | 新增收集表答案响应模型(reply 多种类型结构) |
| weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDocServiceImplTest.java | 新增 WeDoc Service 实现测试:校验 API Path 路由与请求体协议 |
| weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpOaWeDocJsonTest.java | 新增 WeDoc JSON 测试:校验新 bean 的 toJson/fromJson 兼容性 |
| * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/mod_doc_safty_setting?access_token=ACCESS_TOKEN | ||
| * | ||
| * @param request 修改文档安全设置请求 | ||
| * @return wx cp base resp | ||
| * @throws WxErrorException the wx error exception | ||
| */ | ||
| WxCpBaseResp docModifySaftySetting(@NonNull WxCpDocModifySaftySettingRequest request) throws WxErrorException; | ||
|
|
||
| /** |
There was a problem hiding this comment.
docModifySaftySetting/WxCpDocModifySaftySettingRequest/常量 WEDOC_MOD_DOC_SAFTY_SETTING 中的 “Safty” 属于拼写错误(应为 “Safety”)。这些名称属于对外 API(接口方法与 public bean 类名),建议尽早更正为 Safety(endpoint path 仍保持 .../mod_doc_safty_setting 不变),以避免后续长期背负错误命名;如担心兼容性,可保留旧方法/类作为 @Deprecated 别名。
| * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/mod_doc_safty_setting?access_token=ACCESS_TOKEN | |
| * | |
| * @param request 修改文档安全设置请求 | |
| * @return wx cp base resp | |
| * @throws WxErrorException the wx error exception | |
| */ | |
| WxCpBaseResp docModifySaftySetting(@NonNull WxCpDocModifySaftySettingRequest request) throws WxErrorException; | |
| /** | |
| * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/mod_doc_safty_setting?access_token=ACCESS_TOKEN | |
| * <p> | |
| * 推荐改用 {@link #docModifySafetySetting(WxCpDocModifySaftySettingRequest)}。 | |
| * | |
| * @param request 修改文档安全设置请求 | |
| * @return wx cp base resp | |
| * @throws WxErrorException the wx error exception | |
| * @deprecated 方法名中 {@code Safty} 为拼写错误,请使用 {@link #docModifySafetySetting(WxCpDocModifySaftySettingRequest)}。 | |
| */ | |
| @Deprecated | |
| WxCpBaseResp docModifySaftySetting(@NonNull WxCpDocModifySaftySettingRequest request) throws WxErrorException; | |
| /** | |
| * 修改文档安全设置 | |
| * 该接口用于修改文档、表格、智能表格的安全设置。 | |
| * <p> | |
| * 请求方式:POST(HTTPS) | |
| * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/mod_doc_safty_setting?access_token=ACCESS_TOKEN | |
| * | |
| * @param request 修改文档安全设置请求 | |
| * @return wx cp base resp | |
| * @throws WxErrorException the wx error exception | |
| */ | |
| WxCpBaseResp docModifySafetySetting(@NonNull WxCpDocModifySaftySettingRequest request) throws WxErrorException; | |
| /** |
| + "\"form_info\":{" | ||
| + "\"formid\":\"FORMID1\"," | ||
| + "\"form_title\":\"api创建的收集表\"," | ||
| + "\"form_question\":{\"items\":[{\"question_id\":1,\"title\":\"问题1\",\"pos\":1,\"status\":1,\"reply_type\":1,\"must_reply\":true}]}," | ||
| + "\"form_setting\":{\"fill_out_auth\":1,\"max_fill_cnt\":2}," |
There was a problem hiding this comment.
该处 JSON 字符串拼接行过长,超过项目 Checkstyle 的 120 字符限制(google_checks.xml 的 LineLength max=120),会导致 mvn checkstyle:check 失败。建议将长 JSON 片段拆分为多行/提取为常量,或用更短的片段组合。
| when(cpService.post(eq("https://api.test/spreadsheet/batch_update"), anyString())) | ||
| .thenReturn("{\"add_sheet_response\":{\"properties\":{\"sheet_id\":\"sheet2\",\"title\":\"Sheet A\",\"row_count\":20,\"column_count\":5}},\"update_range_response\":{\"updated_cells\":2}}"); | ||
| when(cpService.post(eq("https://api.test/spreadsheet/get_sheet_properties"), anyString())) | ||
| .thenReturn("{\"errcode\":0,\"errmsg\":\"ok\",\"properties\":[{\"sheet_id\":\"sheet1\",\"title\":\"Sheet A\",\"row_count\":20,\"column_count\":5}]}"); | ||
| when(cpService.post(eq("https://api.test/spreadsheet/get_sheet_range_data"), anyString())) | ||
| .thenReturn("{\"errcode\":0,\"errmsg\":\"ok\",\"grid_data\":{\"start_row\":0,\"start_column\":0,\"rows\":[{\"values\":[{\"cell_value\":{\"text\":\"hello\"}}]}]}}"); |
There was a problem hiding this comment.
这里的 thenReturn("{...}") JSON 字符串在单行内过长,超过项目 Checkstyle 的 120 字符限制(google_checks.xml 的 LineLength max=120),会导致 mvn checkstyle:check 失败。建议把返回 JSON 拆分为多段字符串拼接/提取为常量,或改成多行拼接以缩短单行长度(同文件内其他类似长 JSON 也需要一并处理)。
Summary
WxCpOaWeDocServiceImplTestandWxCpOaWeDocJsonTestCompatibility and protocol updates
doc_sharecompatibility forformidthroughWxCpDocShareRequestform_statisticwith the official array request/response protocolformStatistic(WxCpFormStatisticRequest)on top of the array-based implementationValidation
developand added targeted service/json tests for the new WeDoc OA coverage./others/mvnw -pl weixin-java-cp -Dtest=WxCpOaWeDocServiceImplTest,WxCpOaWeDocJsonTest testJAVA_HOMEis not configured, so the new tests could not be executed here