diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java index ff60b352d..68cbc3950 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java @@ -213,6 +213,39 @@ public interface WxCpOaService { */ WxCpTemplateResult getTemplateDetail(@NonNull String templateId) throws WxErrorException; + /** + * 创建审批模板 + *
+ * 可以调用此接口创建审批模板。创建新模板后,管理后台及审批应用内将生成对应模板,并生效默认流程和规则配置。 + *
+   *  文档地址: https://developer.work.weixin.qq.com/document/path/97437
+   *  权限说明
+   * • 仅『审批』系统应用、自建应用和代开发自建应用可调用。
+   * 
+ * + * @param wxCpTemplateCreate wxCpTemplateCreate + * @return templateId + * @throws WxErrorException . + */ + String createTemplate(WxCpTemplateCreate wxCpTemplateCreate) throws WxErrorException; + + /** + * 更新审批模板 + *
+ * 可调用本接口更新审批模板。更新模板后,管理后台及审批应用内将更新原模板的内容,已配置的审批流程和规则不变。 + *
+   *  文档地址: https://developer.work.weixin.qq.com/document/path/97438
+   *  权限说明
+   * • 仅『审批』系统应用,自建应用和代开发自建应用可调用
+   * • 所有应用都可以通过本接口更新自己的模板
+   * • 『审批』系统应用可以修改管理员手动创建的模板
+   * • 自建应用和代开发自建应用不可通过本接口更新其他应用创建的模板
+   * 
+ * + * @param wxCpTemplateUpdate wxCpTemplateUpdate + * @throws WxErrorException . + */ + void updateTemplate(WxCpTemplateUpdate wxCpTemplateUpdate) throws WxErrorException; /** * 获取打卡日报数据 diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java index 289968757..6fc618661 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java @@ -259,6 +259,20 @@ public class WxCpOaServiceImpl implements WxCpOaService { 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 getCheckinDayData(@NonNull Date startTime, @NonNull Date endTime, List userIdList) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/WxCpTemplateCreate.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/WxCpTemplateCreate.java new file mode 100644 index 000000000..79c1ad6d7 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/WxCpTemplateCreate.java @@ -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 templateName; + + @SerializedName("template_content") + private TemplateContent templateContent; + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/WxCpTemplateUpdate.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/WxCpTemplateUpdate.java new file mode 100644 index 000000000..555caf490 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/WxCpTemplateUpdate.java @@ -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 templateName; + + @SerializedName("template_content") + private TemplateContent templateContent; + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java index 4038562e2..7baf48e71 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java @@ -289,6 +289,14 @@ public interface WxCpApiPathConsts { * 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. */