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);
|
}
|
}
|