BAOLH
2026-11-10 4d730af0447c686133130d0116a0fa3dd82c2dca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package me.zhengjie.modules.weixin.cp.api.impl;
 
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.zhengjie.modules.weixin.cp.api.WxCpOaWeDocSmartsheetService;
import me.zhengjie.modules.weixin.cp.bean.smartsheet.constant.WxCpSmartSheetApiPathConsts;
import me.zhengjie.modules.weixin.cp.bean.smartsheet.field.*;
import me.zhengjie.modules.weixin.cp.bean.smartsheet.record.*;
import me.zhengjie.modules.weixin.cp.bean.smartsheet.sheet.*;
import me.zhengjie.modules.weixin.cp.bean.smartsheet.view.*;
import org.springframework.stereotype.Component;
 
import java.util.List;
 
@Slf4j
@RequiredArgsConstructor
@Component
public class WxCpOaWeDocSmartsheetServiceImpl implements WxCpOaWeDocSmartsheetService {
 
    private final WxCpService cpService;
    
    @Override
    public WxCpSheetCreateData sheetCreate(@NonNull WxCpSheetCreateRequest request) throws WxErrorException {
        String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WxCpSmartSheetApiPathConsts.Sheet.ADD_SHEET);
        String responseContent = this.cpService.post(apiUrl, request.toJson());
        return WxCpSheetCreateData.fromJson(responseContent);
    }
 
    @Override
    public WxCpBaseResp sheetDelete(String docId, String sheetId) throws WxErrorException {
        String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WxCpSmartSheetApiPathConsts.Sheet.DELETE_SHEET);
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("docid", docId);
        jsonObject.addProperty("sheet_id", sheetId);
        String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
        return WxCpBaseResp.fromJson(responseContent);
    }
 
    @Override
    public WxCpBaseResp sheetEdit(@NonNull WxCpSheetEditRequest request) throws WxErrorException {
        String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WxCpSmartSheetApiPathConsts.Sheet.UPDATE_SHEET);
        String responseContent = this.cpService.post(apiUrl, request.toJson());
        return WxCpBaseResp.fromJson(responseContent);
    }
 
    @Override
    public WxCpSheetInfo sheetInfo(@NonNull WxCpSheetQueryRequest request) throws WxErrorException {
        String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WxCpSmartSheetApiPathConsts.Sheet.GET_SHEET);
        String responseContent = this.cpService.post(apiUrl, request.toJson());
        return WxCpSheetInfo.fromJson(responseContent);
    }
 
    @Override
    public WxCpViewCreateData viewCreate(@NonNull WxCpViewCreateRequest request) throws WxErrorException {
        String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WxCpSmartSheetApiPathConsts.View.ADD_VIEW);
        String responseContent = this.cpService.post(apiUrl, request.toJson());
        return WxCpViewCreateData.fromJson(responseContent);
    }
 
    @Override
    public WxCpBaseResp viewDelete(String docId, String sheetId, List<String> viewIds) throws WxErrorException {
        String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WxCpSmartSheetApiPathConsts.View.DELETE_VIEW);
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("docid", docId);
        jsonObject.addProperty("sheet_id", sheetId);
        JsonArray jsonArray = viewIds.stream().collect(JsonArray::new, JsonArray::add, JsonArray::addAll);
        jsonObject.add("view_ids", jsonArray);
        String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
        return WxCpBaseResp.fromJson(responseContent);
    }
 
    @Override
    public WxCpBaseResp viewEdit(@NonNull WxCpViewEditRequest request) throws WxErrorException {
        String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WxCpSmartSheetApiPathConsts.View.UPDATE_VIEW);
        String responseContent = this.cpService.post(apiUrl, request.toJson());
        return WxCpBaseResp.fromJson(responseContent);
    }
 
    @Override
    public WxCpViewInfo viewInfo(@NonNull WxCpViewQueryRequest request) throws WxErrorException {
        String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WxCpSmartSheetApiPathConsts.View.GET_VIEW);
        String responseContent = this.cpService.post(apiUrl, request.toJson());
        return WxCpViewInfo.fromJson(responseContent);
    }
 
    @Override
    public WxCpFieldCreateData fieldCreate(@NonNull WxCpFieldCreateRequest request) throws WxErrorException {
        String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WxCpSmartSheetApiPathConsts.Field.ADD_FIELD);
        String responseContent = this.cpService.post(apiUrl, request.toJson());
        return WxCpFieldCreateData.fromJson(responseContent);
    }
 
    @Override
    public WxCpBaseResp fieldDelete(String docId, String sheetId, List<String> fieldIds) throws WxErrorException {
        String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WxCpSmartSheetApiPathConsts.Field.DELETE_FIELD);
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("docid", docId);
        jsonObject.addProperty("sheet_id", sheetId);
        JsonArray jsonArray = fieldIds.stream().collect(JsonArray::new, JsonArray::add, JsonArray::addAll);
        jsonObject.add("field_ids", jsonArray);
        String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
        return WxCpBaseResp.fromJson(responseContent);
    }
 
    @Override
    public WxCpFieldEditData fieldEdit(@NonNull WxCpFieldEditRequest request) throws WxErrorException {
        String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WxCpSmartSheetApiPathConsts.Field.UPDATE_FIELD);
        String responseContent = this.cpService.post(apiUrl, request.toJson());
        return WxCpFieldEditData.fromJson(responseContent);
    }
 
    @Override
    public WxCpFieldInfo fieldInfo(@NonNull WxCpFieldQueryRequest request) throws WxErrorException {
        String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WxCpSmartSheetApiPathConsts.Field.GET_FIELD);
        String responseContent = this.cpService.post(apiUrl, request.toJson());
        return WxCpFieldInfo.fromJson(responseContent);
    }
 
    @Override
    public WxCpRecordCreateData recordCreate(@NonNull WxCpRecordCreateRequest request) throws WxErrorException {
        String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WxCpSmartSheetApiPathConsts.Record.ADD_RECORD);
        String responseContent = this.cpService.post(apiUrl, request.toJson());
        return WxCpRecordCreateData.fromJson(responseContent);
    }
 
    @Override
    public WxCpBaseResp recordDelete(String docId, String sheetId, List<String> recordIds) throws WxErrorException {
        String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WxCpSmartSheetApiPathConsts.Record.DELETE_RECORD);
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("docid", docId);
        jsonObject.addProperty("sheet_id", sheetId);
        JsonArray jsonArray = recordIds.stream().collect(JsonArray::new, JsonArray::add, JsonArray::addAll);
        jsonObject.add("record_ids", jsonArray);
        String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
        return WxCpBaseResp.fromJson(responseContent);
    }
 
    @Override
    public WxCpRecordEditData recordEdit(@NonNull WxCpRecordEditRequest request) throws WxErrorException {
        String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WxCpSmartSheetApiPathConsts.Record.UPDATE_RECORD);
        String responseContent = this.cpService.post(apiUrl, request.toJson());
        return WxCpRecordEditData.fromJson(responseContent);
    }
 
    @Override
    public WxCpRecordInfo recordInfo(@NonNull WxCpRecordQueryRequest request) throws WxErrorException {
        String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WxCpSmartSheetApiPathConsts.Record.GET_RECORD);
        String responseContent = this.cpService.post(apiUrl, request.toJson());
        return WxCpRecordInfo.fromJson(responseContent);
    }
}