Skip to content

Commit

Permalink
🆕 #1641 企业微信增加OA提交审批申请的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Jul 18, 2020
1 parent 3b8c66a commit f6f4b89
Show file tree
Hide file tree
Showing 13 changed files with 352 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1069,10 +1069,26 @@ public enum WxCpErrorMsgEnum {
* 获取打卡记录时间间隔超限;保证开始时间大于0 且结束时间大于 0 且结束时间大于开始时间,且间隔少于93天.
*/
CODE_301024(301024, "获取打卡记录时间间隔超限;保证开始时间大于0 且结束时间大于 0 且结束时间大于开始时间,且间隔少于93天"),
/**
* 提交审批单请求参数错误
*/
CODE_301025(301025,"提交审批单请求参数错误"),
/**
* 不允许更新该用户的userid.
*/
CODE_301036(301036, "不允许更新该用户的userid"),
/**
* 无审批应用权限,或者提单者不在审批应用/自建应用的可见范围
*/
CODE_301055(301055,"无审批应用权限,或者提单者不在审批应用/自建应用的可见范围"),
/**
* 审批应用已停用
*/
CODE_301056(301056,"审批应用已停用"),
/**
* 通用错误码,提交审批单内部接口失败
*/
CODE_301057(301057,"通用错误码,提交审批单内部接口失败"),
/**
* 批量导入任务的文件中userid有重复.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@
*/
public interface WxCpOaService {

/**
* <pre>提交审批申请
* 调试工具
* 企业可通过审批应用或自建应用Secret调用本接口,代应用可见范围内员工在企业微信“审批应用”内提交指定类型的审批申请。
*
* 请求方式:POST(HTTPS)
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/oa/applyevent?access_token=ACCESS_TOKEN
* 文档地址:https://work.weixin.qq.com/api/doc/90000/90135/91853
* </pre>
*
* @param request 请求
* @return 表单提交成功后,返回的表单编号
* @throws WxErrorException .
*/
String apply(WxCpOaApplyEventRequest request) throws WxErrorException;

/**
* <pre>
* 获取打卡数据
Expand All @@ -40,7 +56,7 @@ List<WxCpCheckinData> getCheckinData(Integer openCheckinDataType, Date startTime
* @param datetime 需要获取规则的当天日期
* @param userIdList 需要获取打卡规则的用户列表
* @return 打卡规则列表
* @throws WxErrorException
* @throws WxErrorException .
*/
List<WxCpCheckinOption> getCheckinOption(Date datetime, List<String> userIdList) throws WxErrorException;

Expand All @@ -63,7 +79,7 @@ List<WxCpCheckinData> getCheckinData(Integer openCheckinDataType, Date startTime
* @param size 一次请求拉取审批单数量,默认值为100,上限值为100
* @param filters 筛选条件,可对批量拉取的审批申请设置约束条件,支持设置多个条件,nullable
* @return WxCpApprovalInfo
* @throws WxErrorException
* @throws WxErrorException .
*/
WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime, Integer cursor, Integer size,
List<WxCpApprovalInfoQueryFilter> filters) throws WxErrorException;
Expand All @@ -74,7 +90,7 @@ WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime,
* @param startTime 开始时间
* @param endTime 结束时间
* @return WxCpApprovalInfo
* @throws WxErrorException
* @throws WxErrorException .
* @see me.chanjar.weixin.cp.api.WxCpOaService#getApprovalInfo
*/
WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime) throws WxErrorException;
Expand All @@ -90,7 +106,7 @@ WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime,
*
* @param spNo 审批单编号。
* @return WxCpApprovaldetail
* @throws WxErrorException
* @throws WxErrorException .
*/
WxCpApprovalDetailResult getApprovalDetail(@NonNull String spNo) throws WxErrorException;

Expand All @@ -104,7 +120,7 @@ WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime,
* @param startTime 获取审批记录的开始时间
* @param endTime 获取审批记录的结束时间
* @param nextSpnum 第一个拉取的审批单号,不填从该时间段的第一个审批单拉取
* @throws WxErrorException
* @throws WxErrorException .
* @see me.chanjar.weixin.cp.api.WxCpOaService#getApprovalInfo
* @see me.chanjar.weixin.cp.api.WxCpOaService#getApprovalDetail
*/
Expand All @@ -118,18 +134,19 @@ WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime,
* @param endTime 查询的结束时间戳
* @param offset 分页查询的偏移量
* @param limit 分页查询的每页大小,默认为100条,如该参数大于100则按100处理
* @return
* @throws WxErrorException
* @return .
* @throws WxErrorException .
*/
List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer offset,
Integer limit) throws WxErrorException;

/**
* 获取审批模板详情
*
* @param templateId 模板ID
* @return
* @throws WxErrorException
* @return .
* @throws WxErrorException .
*/
WxCpTemplateResult getTemplateDetail(@NonNull String templateId)throws WxErrorException;
WxCpTemplateResult getTemplateDetail(@NonNull String templateId) throws WxErrorException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public class WxCpOaServiceImpl implements WxCpOaService {
private static final int MONTH_SECONDS = 30 * 24 * 60 * 60;
private static final int USER_IDS_LIMIT = 100;

@Override
public String apply(WxCpOaApplyEventRequest request) throws WxErrorException {
String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(APPLY_EVENT),
request.toJson());
return GsonParser.parse(responseContent).get("sp_no").getAsString();
}

@Override
public List<WxCpCheckinData> getCheckinData(Integer openCheckinDataType, Date startTime, Date endTime,
List<String> userIdList) throws WxErrorException {
Expand All @@ -42,19 +49,19 @@ public List<WxCpCheckinData> getCheckinData(Integer openCheckinDataType, Date st
throw new RuntimeException("用户列表不能为空,不超过 " + USER_IDS_LIMIT + " 个,若用户超过 " + USER_IDS_LIMIT + " 个,请分批获取");
}

long endtimestamp = endTime.getTime() / 1000L;
long starttimestamp = startTime.getTime() / 1000L;
long endTimestamp = endTime.getTime() / 1000L;
long startTimestamp = startTime.getTime() / 1000L;

if (endtimestamp - starttimestamp < 0 || endtimestamp - starttimestamp >= MONTH_SECONDS) {
if (endTimestamp - startTimestamp < 0 || endTimestamp - startTimestamp >= MONTH_SECONDS) {
throw new RuntimeException("获取记录时间跨度不超过一个月");
}

JsonObject jsonObject = new JsonObject();
JsonArray jsonArray = new JsonArray();

jsonObject.addProperty("opencheckindatatype", openCheckinDataType);
jsonObject.addProperty("starttime", starttimestamp);
jsonObject.addProperty("endtime", endtimestamp);
jsonObject.addProperty("starttime", startTimestamp);
jsonObject.addProperty("endtime", endTimestamp);

for (String userid : userIdList) {
jsonArray.add(userid);
Expand Down Expand Up @@ -213,9 +220,9 @@ public List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer
@Override
public WxCpTemplateResult getTemplateDetail(@NonNull String templateId) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("template_id",templateId);
jsonObject.addProperty("template_id", templateId);
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_TEMPLATE_DETAIL);
String responseContent = this.mainService.post(url, jsonObject.toString());
return WxCpGsonBuilder.create().fromJson(responseContent,WxCpTemplateResult.class);
return WxCpGsonBuilder.create().fromJson(responseContent, WxCpTemplateResult.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package me.chanjar.weixin.cp.bean.oa;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.experimental.Accessors;
import me.chanjar.weixin.cp.bean.oa.WxCpOaApplyEventRequest;

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

/**
* 摘要行信息,用于定义某一行摘要显示的内容.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-07-19
*/
@Data
@Accessors(chain = true)
public class SummaryInfo implements Serializable {
private static final long serialVersionUID = 8262265774851382414L;
/**
* 摘要行信息,用于定义某一行摘要显示的内容
*/
@SerializedName("summary_info")
private List<SummaryInfoData> summaryInfoData;

@Data
@Accessors(chain = true)
public static class SummaryInfoData implements Serializable {
private static final long serialVersionUID = 5314161929610113856L;
/**
* 摘要行显示文字,用于记录列表和消息通知的显示,不要超过20个字符
*/
private String text;

/**
* 摘要行显示语言
*/
private String lang;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author element
*/
@Data
public class WxCpApprovalApplyer extends WxCpOperator implements Serializable {
public class WxCpApprovalApplier extends WxCpOperator implements Serializable {

private static final long serialVersionUID = -8974662568286821271L;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.chanjar.weixin.cp.bean.oa;

import lombok.Data;
import me.chanjar.weixin.cp.bean.oa.applydata.Content;
import me.chanjar.weixin.cp.bean.oa.applydata.ApplyDataContent;

import java.io.Serializable;
import java.util.List;
Expand All @@ -16,6 +16,6 @@ public class WxCpApprovalApplyData implements Serializable {

private static final long serialVersionUID = 4061352949894274704L;

private List<Content> contents;
private List<ApplyDataContent> contents;

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class WxCpApprovalDetail implements Serializable {
* 申请人信息
*/
@SerializedName("applyer")
private WxCpApprovalApplyer applier;
private WxCpApprovalApplier applier;

/**
* 审批流程信息,可能有多个审批节点
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package me.chanjar.weixin.cp.bean.oa;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.experimental.Accessors;
import me.chanjar.weixin.cp.bean.oa.applydata.ApplyDataContent;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

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

/**
* 提交审批申请 请求对象类.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-07-18
*/
@Data
@Accessors(chain = true)
public class WxCpOaApplyEventRequest implements Serializable {
private static final long serialVersionUID = 3362660678938569341L;

/**
* 申请人userid,此审批申请将以此员工身份提交,申请人需在应用可见范围内
*/
@SerializedName("creator_userid")
private String creatorUserId;

/**
* 模板id。可在“获取审批申请详情”、“审批状态变化回调通知”中获得,也可在审批模板的模板编辑页面链接中获得。暂不支持通过接口提交[打卡补卡][调班]模板审批单。
*/
@SerializedName("template_id")
private String templateId;

/**
* 审批人模式:0-通过接口指定审批人、抄送人(此时approver、notifyer等参数可用); 1-使用此模板在管理后台设置的审批流程,支持条件审批。默认为0
*/
@SerializedName("use_template_approver")
private Integer useTemplateApprover;

/**
* 审批流程信息,用于指定审批申请的审批流程,支持单人审批、多人会签、多人或签,可能有多个审批节点,仅use_template_approver为0时生效。
*/
@SerializedName("approver")
private List<Approver> approvers;

/**
* 抄送人节点userid列表,仅use_template_approver为0时生效。
*/
@SerializedName("notifyer")
private String[] notifiers;

/**
* 抄送方式:1-提单时抄送(默认值); 2-单据通过后抄送;3-提单和单据通过后抄送。仅use_template_approver为0时生效。
*/
@SerializedName("notify_type")
private Integer notifyType;

/**
* 审批申请数据,可定义审批申请中各个控件的值,其中必填项必须有值,选填项可为空,数据结构同“获取审批申请详情”接口返回值中同名参数“apply_data”
*/
@SerializedName("apply_data")
private ApplyData applyData;

/**
* 摘要信息,用于显示在审批通知卡片、审批列表的摘要信息,最多3行
*/
@SerializedName("summary_list")
private List<SummaryInfo> summaryList;

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

@Data
@Accessors(chain = true)
public static class Approver implements Serializable {
private static final long serialVersionUID = 7625206971546930988L;

/**
* 节点审批方式:1-或签;2-会签,仅在节点为多人审批时有效
*/
private Integer attr;

/**
* 审批节点审批人userid列表,若为多人会签、多人或签,需填写每个人的userid
*/
@SerializedName("userid")
private String[] userIds;
}

@Data
@Accessors(chain = true)
public static class ApplyData implements Serializable {
private static final long serialVersionUID = -2462732405265306981L;

/**
* 审批申请数据,可定义审批申请中各个控件的值,其中必填项必须有值,选填项可为空,
* 数据结构同“获取审批申请详情”接口返回值中同名参数“apply_data”
*/
@SerializedName("contents")
private List<ApplyDataContent> contents;
}

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

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.experimental.Accessors;

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

/**
* @author element
*/
@Data
@Accessors(chain = true)
public class ApplyDataContent implements Serializable {
private static final long serialVersionUID = 8456821731930526935L;
/**
* 控件类型:Text-文本;Textarea-多行文本;Number-数字;Money-金额;Date-日期/日期+时间;
* Selector-单选/多选;;Contact-成员/部门;Tips-说明文字;File-附件;Table-明细;
*/
private String control;

/**
* 控件id:控件的唯一id,可通过“获取审批模板详情”接口获取
*/
private String id;

@SerializedName("title")
private List<ContentTitle> titles;

/**
* 控件值 ,需在此为申请人在各个控件中填写内容不同控件有不同的赋值参数,具体说明详见附录。模板配置的控件属性为必填时,对应value值需要有值。
*/
private ContentValue value;
}
Loading

0 comments on commit f6f4b89

Please sign in to comment.