Skip to content

feat(cp): complete WeDoc OA APIs and align form share/statistic compatibility#3926

Open
lyfuci wants to merge 8 commits intobinarywang:developfrom
lyfuci:feat/wecom-wedoc-oa-apis
Open

feat(cp): complete WeDoc OA APIs and align form share/statistic compatibility#3926
lyfuci wants to merge 8 commits intobinarywang:developfrom
lyfuci:feat/wecom-wedoc-oa-apis

Conversation

@lyfuci
Copy link

@lyfuci lyfuci commented Mar 12, 2026

Summary

  • add the missing WeDoc OA service methods, API paths, and request/response beans for doc, form, doc admin, and smartsheet server scenarios
  • cover the newly added doc/form/admin/smartsheet flows with WxCpOaWeDocServiceImplTest and WxCpOaWeDocJsonTest

Compatibility and protocol updates

  • add doc_share compatibility for formid through WxCpDocShareRequest
  • align form_statistic with the official array request/response protocol
  • keep the single-request compatibility wrapper formStatistic(WxCpFormStatisticRequest) on top of the array-based implementation

Validation

  • verified the branch diff against develop and added targeted service/json tests for the new WeDoc OA coverage
  • attempted to run ./others/mvnw -pl weixin-java-cp -Dtest=WxCpOaWeDocServiceImplTest,WxCpOaWeDocJsonTest test
  • the local run is currently blocked in this environment because JAVA_HOME is not configured, so the new tests could not be executed here

@augmentcode
Copy link

augmentcode bot commented Mar 12, 2026

🤖 Augment PR Summary

Summary: 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:

  • Adds a large set of new WeDoc OA service methods (doc auth/permissions, content read/modify, image upload, admin management, smartsheet auth + CRUD, collect form CRUD, statistics, and answers)
  • Introduces new request/response beans to model the newly supported endpoints, with helper JSON (de)serialization and some compatibility accessors (e.g., effective content/url/auth fields)
  • Extends WxCpService / BaseWxCpServiceImpl to expose getOaWeDocService()
  • Aligns doc_share to support formid via WxCpDocShareRequest
  • Aligns form_statistic to an official array-based request/response protocol while keeping a single-request wrapper for backward convenience
  • Adds targeted unit tests for the new service methods and JSON contracts (WxCpOaWeDocServiceImplTest, WxCpOaWeDocJsonTest)

Technical Notes: New endpoints are wired via additional WxCpApiPathConsts.Oa constants and implemented using existing post/upload abstractions in WxCpService.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

@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));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

* 收集表统计结果.
*/
@Data
public class WxCpFormStatistic extends WxCpBaseResp implements Serializable {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the statistic array elements don’t include errcode, extending WxCpBaseResp can leave errcode null and make success() throw an NPE due to unboxing.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@lyfuci lyfuci force-pushed the feat/wecom-wedoc-oa-apis branch from 4c447e5 to 2095378 Compare March 12, 2026 02:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 路径常量
  • 新增 WxCpOaWeDocServiceImplTestWxCpOaWeDocJsonTest,覆盖路径路由与 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 兼容性

Comment on lines +143 to 151
* 请求地址: 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;

/**
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docModifySaftySetting/WxCpDocModifySaftySettingRequest/常量 WEDOC_MOD_DOC_SAFTY_SETTING 中的 “Safty” 属于拼写错误(应为 “Safety”)。这些名称属于对外 API(接口方法与 public bean 类名),建议尽早更正为 Safety(endpoint path 仍保持 .../mod_doc_safty_setting 不变),以避免后续长期背负错误命名;如担心兼容性,可保留旧方法/类作为 @Deprecated 别名。

Suggested change
* 请求地址: 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>
* 请求方式POSTHTTPS
* 请求地址: 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;
/**

Copilot uses AI. Check for mistakes.
Comment on lines +159 to +163
+ "\"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},"
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该处 JSON 字符串拼接行过长,超过项目 Checkstyle 的 120 字符限制(google_checks.xmlLineLength max=120),会导致 mvn checkstyle:check 失败。建议将长 JSON 片段拆分为多行/提取为常量,或用更短的片段组合。

Copilot uses AI. Check for mistakes.
Comment on lines +71 to +76
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\"}}]}]}}");
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 thenReturn("{...}") JSON 字符串在单行内过长,超过项目 Checkstyle 的 120 字符限制(google_checks.xmlLineLength max=120),会导致 mvn checkstyle:check 失败。建议把返回 JSON 拆分为多段字符串拼接/提取为常量,或改成多行拼接以缩短单行长度(同文件内其他类似长 JSON 也需要一并处理)。

Copilot uses AI. Check for mistakes.
- Wrap form_statistic response in WxCpFormStatisticResult to fix JSON
  array parsing issue with cpService.post() (high severity)
- Remove WxCpBaseResp inheritance from WxCpFormStatistic to prevent
  NPE on success() when errcode is absent (medium severity)
- Rename Safty -> Safety: add WxCpDocModifySafetySettingRequest and
  WEDOC_MOD_DOC_SAFETY_SETTING with @deprecated aliases for old names
- Break long lines in test files to satisfy checkstyle 120-char limit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants