Skip to content

Commit f67c2e3

Browse files
committed
feat(cp): add wedoc smartsheet server APIs
1 parent 25a880a commit f67c2e3

File tree

7 files changed

+790
-5
lines changed

7 files changed

+790
-5
lines changed

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

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,150 @@ public interface WxCpOaWeDocService {
246246
*/
247247
WxCpBaseResp smartSheetModifyAuth(@NonNull WxCpDocSmartSheetModifyAuthRequest request) throws WxErrorException;
248248

249+
/**
250+
* 获取智能表格工作表信息.
251+
*
252+
* @param request 智能表格请求
253+
* @return 智能表格工作表信息
254+
* @throws WxErrorException the wx error exception
255+
*/
256+
WxCpDocSmartSheetResult smartSheetGetSheet(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException;
257+
258+
/**
259+
* 新增智能表格工作表.
260+
*
261+
* @param request 智能表格请求
262+
* @return 智能表格工作表信息
263+
* @throws WxErrorException the wx error exception
264+
*/
265+
WxCpDocSmartSheetResult smartSheetAddSheet(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException;
266+
267+
/**
268+
* 删除智能表格工作表.
269+
*
270+
* @param request 智能表格请求
271+
* @return wx cp base resp
272+
* @throws WxErrorException the wx error exception
273+
*/
274+
WxCpBaseResp smartSheetDeleteSheet(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException;
275+
276+
/**
277+
* 更新智能表格工作表.
278+
*
279+
* @param request 智能表格请求
280+
* @return wx cp base resp
281+
* @throws WxErrorException the wx error exception
282+
*/
283+
WxCpBaseResp smartSheetUpdateSheet(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException;
284+
285+
/**
286+
* 获取智能表格视图.
287+
*
288+
* @param request 智能表格请求
289+
* @return 智能表格视图
290+
* @throws WxErrorException the wx error exception
291+
*/
292+
WxCpDocSmartSheetResult smartSheetGetViews(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException;
293+
294+
/**
295+
* 新增智能表格视图.
296+
*
297+
* @param request 智能表格请求
298+
* @return 智能表格视图
299+
* @throws WxErrorException the wx error exception
300+
*/
301+
WxCpDocSmartSheetResult smartSheetAddView(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException;
302+
303+
/**
304+
* 删除智能表格视图.
305+
*
306+
* @param request 智能表格请求
307+
* @return wx cp base resp
308+
* @throws WxErrorException the wx error exception
309+
*/
310+
WxCpBaseResp smartSheetDeleteViews(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException;
311+
312+
/**
313+
* 更新智能表格视图.
314+
*
315+
* @param request 智能表格请求
316+
* @return wx cp base resp
317+
* @throws WxErrorException the wx error exception
318+
*/
319+
WxCpBaseResp smartSheetUpdateView(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException;
320+
321+
/**
322+
* 获取智能表格字段.
323+
*
324+
* @param request 智能表格请求
325+
* @return 智能表格字段
326+
* @throws WxErrorException the wx error exception
327+
*/
328+
WxCpDocSmartSheetResult smartSheetGetFields(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException;
329+
330+
/**
331+
* 新增智能表格字段.
332+
*
333+
* @param request 智能表格请求
334+
* @return 智能表格字段
335+
* @throws WxErrorException the wx error exception
336+
*/
337+
WxCpDocSmartSheetResult smartSheetAddFields(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException;
338+
339+
/**
340+
* 删除智能表格字段.
341+
*
342+
* @param request 智能表格请求
343+
* @return wx cp base resp
344+
* @throws WxErrorException the wx error exception
345+
*/
346+
WxCpBaseResp smartSheetDeleteFields(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException;
347+
348+
/**
349+
* 更新智能表格字段.
350+
*
351+
* @param request 智能表格请求
352+
* @return wx cp base resp
353+
* @throws WxErrorException the wx error exception
354+
*/
355+
WxCpBaseResp smartSheetUpdateFields(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException;
356+
357+
/**
358+
* 获取智能表格记录.
359+
*
360+
* @param request 智能表格请求
361+
* @return 智能表格记录
362+
* @throws WxErrorException the wx error exception
363+
*/
364+
WxCpDocSmartSheetResult smartSheetGetRecords(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException;
365+
366+
/**
367+
* 新增智能表格记录.
368+
*
369+
* @param request 智能表格请求
370+
* @return 智能表格记录
371+
* @throws WxErrorException the wx error exception
372+
*/
373+
WxCpDocSmartSheetResult smartSheetAddRecords(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException;
374+
375+
/**
376+
* 删除智能表格记录.
377+
*
378+
* @param request 智能表格请求
379+
* @return wx cp base resp
380+
* @throws WxErrorException the wx error exception
381+
*/
382+
WxCpBaseResp smartSheetDeleteRecords(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException;
383+
384+
/**
385+
* 更新智能表格记录.
386+
*
387+
* @param request 智能表格请求
388+
* @return wx cp base resp
389+
* @throws WxErrorException the wx error exception
390+
*/
391+
WxCpBaseResp smartSheetUpdateRecords(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException;
392+
249393
/**
250394
* 创建收集表
251395
* 该接口用于创建收集表。

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

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,118 @@ public WxCpBaseResp smartSheetModifyAuth(@NonNull WxCpDocSmartSheetModifyAuthReq
155155
return WxCpBaseResp.fromJson(responseContent);
156156
}
157157

158+
@Override
159+
public WxCpDocSmartSheetResult smartSheetGetSheet(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException {
160+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SMARTSHEET_GET_SHEET);
161+
String responseContent = this.cpService.post(apiUrl, request.toJson());
162+
return WxCpDocSmartSheetResult.fromJson(responseContent);
163+
}
164+
165+
@Override
166+
public WxCpDocSmartSheetResult smartSheetAddSheet(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException {
167+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SMARTSHEET_ADD_SHEET);
168+
String responseContent = this.cpService.post(apiUrl, request.toJson());
169+
return WxCpDocSmartSheetResult.fromJson(responseContent);
170+
}
171+
172+
@Override
173+
public WxCpBaseResp smartSheetDeleteSheet(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException {
174+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SMARTSHEET_DELETE_SHEET);
175+
String responseContent = this.cpService.post(apiUrl, request.toJson());
176+
return WxCpBaseResp.fromJson(responseContent);
177+
}
178+
179+
@Override
180+
public WxCpBaseResp smartSheetUpdateSheet(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException {
181+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SMARTSHEET_UPDATE_SHEET);
182+
String responseContent = this.cpService.post(apiUrl, request.toJson());
183+
return WxCpBaseResp.fromJson(responseContent);
184+
}
185+
186+
@Override
187+
public WxCpDocSmartSheetResult smartSheetGetViews(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException {
188+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SMARTSHEET_GET_VIEWS);
189+
String responseContent = this.cpService.post(apiUrl, request.toJson());
190+
return WxCpDocSmartSheetResult.fromJson(responseContent);
191+
}
192+
193+
@Override
194+
public WxCpDocSmartSheetResult smartSheetAddView(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException {
195+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SMARTSHEET_ADD_VIEW);
196+
String responseContent = this.cpService.post(apiUrl, request.toJson());
197+
return WxCpDocSmartSheetResult.fromJson(responseContent);
198+
}
199+
200+
@Override
201+
public WxCpBaseResp smartSheetDeleteViews(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException {
202+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SMARTSHEET_DELETE_VIEWS);
203+
String responseContent = this.cpService.post(apiUrl, request.toJson());
204+
return WxCpBaseResp.fromJson(responseContent);
205+
}
206+
207+
@Override
208+
public WxCpBaseResp smartSheetUpdateView(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException {
209+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SMARTSHEET_UPDATE_VIEW);
210+
String responseContent = this.cpService.post(apiUrl, request.toJson());
211+
return WxCpBaseResp.fromJson(responseContent);
212+
}
213+
214+
@Override
215+
public WxCpDocSmartSheetResult smartSheetGetFields(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException {
216+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SMARTSHEET_GET_FIELDS);
217+
String responseContent = this.cpService.post(apiUrl, request.toJson());
218+
return WxCpDocSmartSheetResult.fromJson(responseContent);
219+
}
220+
221+
@Override
222+
public WxCpDocSmartSheetResult smartSheetAddFields(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException {
223+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SMARTSHEET_ADD_FIELDS);
224+
String responseContent = this.cpService.post(apiUrl, request.toJson());
225+
return WxCpDocSmartSheetResult.fromJson(responseContent);
226+
}
227+
228+
@Override
229+
public WxCpBaseResp smartSheetDeleteFields(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException {
230+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SMARTSHEET_DELETE_FIELDS);
231+
String responseContent = this.cpService.post(apiUrl, request.toJson());
232+
return WxCpBaseResp.fromJson(responseContent);
233+
}
234+
235+
@Override
236+
public WxCpBaseResp smartSheetUpdateFields(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException {
237+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SMARTSHEET_UPDATE_FIELDS);
238+
String responseContent = this.cpService.post(apiUrl, request.toJson());
239+
return WxCpBaseResp.fromJson(responseContent);
240+
}
241+
242+
@Override
243+
public WxCpDocSmartSheetResult smartSheetGetRecords(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException {
244+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SMARTSHEET_GET_RECORDS);
245+
String responseContent = this.cpService.post(apiUrl, request.toJson());
246+
return WxCpDocSmartSheetResult.fromJson(responseContent);
247+
}
248+
249+
@Override
250+
public WxCpDocSmartSheetResult smartSheetAddRecords(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException {
251+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SMARTSHEET_ADD_RECORDS);
252+
String responseContent = this.cpService.post(apiUrl, request.toJson());
253+
return WxCpDocSmartSheetResult.fromJson(responseContent);
254+
}
255+
256+
@Override
257+
public WxCpBaseResp smartSheetDeleteRecords(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException {
258+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SMARTSHEET_DELETE_RECORDS);
259+
String responseContent = this.cpService.post(apiUrl, request.toJson());
260+
return WxCpBaseResp.fromJson(responseContent);
261+
}
262+
263+
@Override
264+
public WxCpBaseResp smartSheetUpdateRecords(@NonNull WxCpDocSmartSheetRequest request) throws WxErrorException {
265+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_SMARTSHEET_UPDATE_RECORDS);
266+
String responseContent = this.cpService.post(apiUrl, request.toJson());
267+
return WxCpBaseResp.fromJson(responseContent);
268+
}
269+
158270
@Override
159271
public WxCpFormCreateResult formCreate(@NonNull WxCpFormCreateRequest request) throws WxErrorException {
160272
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_CREATE_FORM);
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package me.chanjar.weixin.cp.bean.oa.doc;
2+
3+
import com.google.gson.JsonArray;
4+
import com.google.gson.JsonElement;
5+
import com.google.gson.JsonObject;
6+
import com.google.gson.annotations.SerializedName;
7+
import lombok.AllArgsConstructor;
8+
import lombok.Builder;
9+
import lombok.Data;
10+
import lombok.NoArgsConstructor;
11+
import lombok.experimental.Accessors;
12+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
13+
14+
import java.io.Serializable;
15+
import java.util.Map;
16+
17+
/**
18+
* 智能表格通用请求.
19+
*/
20+
@Data
21+
@Builder
22+
@NoArgsConstructor
23+
@AllArgsConstructor
24+
@Accessors(chain = true)
25+
public class WxCpDocSmartSheetRequest implements Serializable {
26+
private static final long serialVersionUID = -2713485192832296951L;
27+
28+
@SerializedName("docid")
29+
private String docId;
30+
31+
@SerializedName("sheet_id")
32+
private String sheetId;
33+
34+
@SerializedName("view_id")
35+
private String viewId;
36+
37+
/**
38+
* 透传扩展参数,便于兼容 properties、views、fields、records 等结构。
39+
*/
40+
private transient JsonObject extra;
41+
42+
public static WxCpDocSmartSheetRequest fromJson(String json) {
43+
return WxCpGsonBuilder.create().fromJson(json, WxCpDocSmartSheetRequest.class);
44+
}
45+
46+
public String toJson() {
47+
JsonObject jsonObject = new JsonObject();
48+
jsonObject.addProperty("docid", this.docId);
49+
if (this.sheetId != null) {
50+
jsonObject.addProperty("sheet_id", this.sheetId);
51+
}
52+
if (this.viewId != null) {
53+
jsonObject.addProperty("view_id", this.viewId);
54+
}
55+
if (this.extra != null) {
56+
for (Map.Entry<String, JsonElement> entry : this.extra.entrySet()) {
57+
jsonObject.add(entry.getKey(), entry.getValue());
58+
}
59+
}
60+
return WxCpGsonBuilder.create().toJson(jsonObject);
61+
}
62+
63+
public WxCpDocSmartSheetRequest addExtra(String key, String value) {
64+
ensureExtra().addProperty(key, value);
65+
return this;
66+
}
67+
68+
public WxCpDocSmartSheetRequest addExtra(String key, Number value) {
69+
ensureExtra().addProperty(key, value);
70+
return this;
71+
}
72+
73+
public WxCpDocSmartSheetRequest addExtra(String key, Boolean value) {
74+
ensureExtra().addProperty(key, value);
75+
return this;
76+
}
77+
78+
public WxCpDocSmartSheetRequest addExtra(String key, JsonElement value) {
79+
ensureExtra().add(key, value);
80+
return this;
81+
}
82+
83+
public WxCpDocSmartSheetRequest addExtraArrayItem(String key, JsonElement value) {
84+
JsonArray jsonArray = this.extra != null && this.extra.has(key) && this.extra.get(key).isJsonArray()
85+
? this.extra.getAsJsonArray(key)
86+
: new JsonArray();
87+
jsonArray.add(value);
88+
ensureExtra().add(key, jsonArray);
89+
return this;
90+
}
91+
92+
private JsonObject ensureExtra() {
93+
if (this.extra == null) {
94+
this.extra = new JsonObject();
95+
}
96+
return this.extra;
97+
}
98+
}

0 commit comments

Comments
 (0)