Skip to content

【企业微信】增加企业微信OA接口: 创建审批模板、更新审批模板 #2905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,39 @@ List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer offset,
*/
WxCpTemplateResult getTemplateDetail(@NonNull String templateId) throws WxErrorException;

/**
* 创建审批模板
* <br>
* 可以调用此接口创建审批模板。创建新模板后,管理后台及审批应用内将生成对应模板,并生效默认流程和规则配置。
* <pre>
* 文档地址: <a href="https://developer.work.weixin.qq.com/document/path/97437">https://developer.work.weixin.qq.com/document/path/97437</a>
* 权限说明
* • 仅『审批』系统应用、自建应用和代开发自建应用可调用。
* </pre>
*
* @param wxCpTemplateCreate wxCpTemplateCreate
* @return templateId
* @throws WxErrorException .
*/
String createTemplate(WxCpTemplateCreate wxCpTemplateCreate) throws WxErrorException;

/**
* 更新审批模板
* <br>
* 可调用本接口更新审批模板。更新模板后,管理后台及审批应用内将更新原模板的内容,已配置的审批流程和规则不变。
* <pre>
* 文档地址: <a href="https://developer.work.weixin.qq.com/document/path/97438">https://developer.work.weixin.qq.com/document/path/97438</a>
* 权限说明
* • 仅『审批』系统应用,自建应用和代开发自建应用可调用
* • 所有应用都可以通过本接口更新自己的模板
* • 『审批』系统应用可以修改管理员手动创建的模板
* • 自建应用和代开发自建应用不可通过本接口更新其他应用创建的模板
* </pre>
*
* @param wxCpTemplateUpdate wxCpTemplateUpdate
* @throws WxErrorException .
*/
void updateTemplate(WxCpTemplateUpdate wxCpTemplateUpdate) throws WxErrorException;

/**
* 获取打卡日报数据
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,20 @@ public WxCpTemplateResult getTemplateDetail(@NonNull String templateId) throws W
return WxCpGsonBuilder.create().fromJson(responseContent, WxCpTemplateResult.class);
}

@Override
public String createTemplate(WxCpTemplateCreate wxCpTemplateCreate) throws WxErrorException {
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(CREATE_TEMPLATE);
String responseContent = this.mainService.post(url, WxCpGsonBuilder.create().toJson(wxCpTemplateCreate));
JsonObject tmpJson = GsonParser.parse(responseContent);
return tmpJson.get("template_id").getAsString();
}

@Override
public void updateTemplate(WxCpTemplateUpdate wxCpTemplateUpdate) throws WxErrorException {
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(UPDATE_TEMPLATE);
this.mainService.post(url, WxCpGsonBuilder.create().toJson(wxCpTemplateUpdate));
}

@Override
public List<WxCpCheckinDayData> getCheckinDayData(@NonNull Date startTime, @NonNull Date endTime,
List<String> userIdList)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package me.chanjar.weixin.cp.bean.oa;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import me.chanjar.weixin.cp.bean.oa.templatedata.TemplateContent;
import me.chanjar.weixin.cp.bean.oa.templatedata.TemplateTitle;

import java.io.Serializable;
import java.util.List;

/**
* 创建审批模板
*
* @author yiyingcanfeng
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class WxCpTemplateCreate implements Serializable {
private static final long serialVersionUID = 4918111784546859769L;

@SerializedName("template_name")
private List<TemplateTitle> templateName;

@SerializedName("template_content")
private TemplateContent templateContent;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package me.chanjar.weixin.cp.bean.oa;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import me.chanjar.weixin.cp.bean.oa.templatedata.TemplateContent;
import me.chanjar.weixin.cp.bean.oa.templatedata.TemplateTitle;

import java.io.Serializable;
import java.util.List;

/**
* 更新审批模板
*
* @author yiyingcanfeng
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class WxCpTemplateUpdate implements Serializable {
private static final long serialVersionUID = 8332120725354015143L;

@SerializedName("template_id")
private String templateId;

@SerializedName("template_name")
private List<TemplateTitle> templateName;

@SerializedName("template_content")
private TemplateContent templateContent;

}
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@ interface Oa {
* The constant GET_TEMPLATE_DETAIL.
*/
String GET_TEMPLATE_DETAIL = "/cgi-bin/oa/gettemplatedetail";
/**
* The constant CREATE_TEMPLATE.
*/
String CREATE_TEMPLATE = "/cgi-bin/oa/approval/create_template";
/**
* The constant CREATE_TEMPLATE.
*/
String UPDATE_TEMPLATE = "/cgi-bin/oa/approval/update_template";
/**
* The constant APPLY_EVENT.
*/
Expand Down