Skip to content

Commit

Permalink
::new #1344 企业微信增加新的审批接口: “批量获取审批单号”及“获取审批申请详情”
Browse files Browse the repository at this point in the history
  • Loading branch information
forfuns authored and binarywang committed Jan 3, 2020
1 parent aad2e5b commit 2f84da5
Show file tree
Hide file tree
Showing 24 changed files with 843 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package me.chanjar.weixin.cp.api;

import lombok.NonNull;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpApprovalDataResult;
import me.chanjar.weixin.cp.bean.WxCpCheckinData;
import me.chanjar.weixin.cp.bean.WxCpCheckinOption;
import me.chanjar.weixin.cp.bean.WxCpDialRecord;
import me.chanjar.weixin.cp.bean.oa.*;

import java.util.Date;
import java.util.List;
Expand All @@ -30,7 +28,8 @@ public interface WxCpOaService {
* @return 打卡数据列表
* @throws WxErrorException 异常
*/
List<WxCpCheckinData> getCheckinData(Integer openCheckinDataType, Date startTime, Date endTime, List<String> userIdList) throws WxErrorException;
List<WxCpCheckinData> getCheckinData(Integer openCheckinDataType, Date startTime, Date endTime,
List<String> userIdList) throws WxErrorException;

/**
* <pre>
Expand All @@ -41,24 +40,88 @@ public interface WxCpOaService {
* @param datetime 需要获取规则的当天日期
* @param userIdList 需要获取打卡规则的用户列表
* @return 打卡规则列表
* @throws WxErrorException 异常
* @throws WxErrorException
*/
List<WxCpCheckinOption> getCheckinOption(Date datetime, List<String> userIdList) throws WxErrorException;

/**
* <pre>
* 获取审批数据
*
* 批量获取审批单号
*
* 审批应用及有权限的自建应用,可通过Secret调用本接口,以获取企业一段时间内企业微信“审批应用”单据的审批编号,支持按模板类型、申请人、部门、申请单审批状态等条件筛选。
* 自建应用调用此接口,需在“管理后台-应用管理-审批-API-审批数据权限”中,授权应用允许提交审批单据。
*
* 一次拉取调用最多拉取100个审批记录,可以通过多次拉取的方式来满足需求,但调用频率不可超过600次/分。
*
* API doc : https://work.weixin.qq.com/api/doc/90000/90135/91816
* </pre>
*
* @param startTime 开始时间
* @param endTime 结束时间
* @param cursor 分页查询游标,默认为0,后续使用返回的next_cursor进行分页拉取
* @param size 一次请求拉取审批单数量,默认值为100,上限值为100
* @param filters 筛选条件,可对批量拉取的审批申请设置约束条件,支持设置多个条件,nullable
* @return WxCpApprovalInfo
* @throws WxErrorException
*/
WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime, Integer cursor, Integer size,
List<WxCpApprovalInfoQueryFilter> filters) throws WxErrorException;

/**
* short method
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return WxCpApprovalInfo
* @throws WxErrorException
* @see me.chanjar.weixin.cp.api.WxCpOaService#getApprovalInfo
*/
WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime) throws WxErrorException;

/**
* <pre>
* 获取审批申请详情
*
* 企业可通过审批应用或自建应用Secret调用本接口,根据审批单号查询企业微信“审批应用”的审批申请详情。
*
* API Doc : https://work.weixin.qq.com/api/doc/90000/90135/91983
* </pre>
*
* @param spNo 审批单编号。
* @return WxCpApprovaldetail
* @throws WxErrorException
*/
WxCpApprovalDetailResult getApprovalDetail(@NonNull String spNo) throws WxErrorException;

/**
* <pre>
* 获取审批数据 (已过期, 请使用"批量获取审批单号" && "获取审批申请详情")
* 通过本接口来获取公司一段时间内的审批记录。一次拉取调用最多拉取10000个审批记录,可以通过多次拉取的方式来满足需求,但调用频率不可超过600次/分。
* API doc : https://work.weixin.qq.com/api/doc#90000/90135/91530
* </pre>
*
* @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
*/
@Deprecated
WxCpApprovalDataResult getApprovalData(Date startTime, Date endTime, Long nextSpnum) throws WxErrorException;

List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer offset, Integer limit) throws WxErrorException;
/**
* 获取公费电话拨打记录
*
* @param startTime 查询的起始时间戳
* @param endTime 查询的结束时间戳
* @param offset 分页查询的偏移量
* @param limit 分页查询的每页大小,默认为100条,如该参数大于100则按100处理
* @return
* @throws WxErrorException
*/
List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer offset,
Integer limit) throws WxErrorException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpOaService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpApprovalDataResult;
import me.chanjar.weixin.cp.bean.WxCpCheckinData;
import me.chanjar.weixin.cp.bean.WxCpCheckinOption;
import me.chanjar.weixin.cp.bean.WxCpDialRecord;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import me.chanjar.weixin.cp.bean.oa.*;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.util.Date;
Expand All @@ -22,7 +19,7 @@
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.*;

/**
* .
* 企业微信 OA 接口实现
*
* @author Element
* @date 2019-04-06 11:20
Expand All @@ -31,21 +28,24 @@
public class WxCpOaServiceImpl implements WxCpOaService {
private final WxCpService mainService;

private static final int MONTH_SECONDS = 30 * 24 * 60 * 60;
private static final int USER_IDS_LIMIT = 100;

@Override
public List<WxCpCheckinData> getCheckinData(Integer openCheckinDataType, Date startTime, Date endTime,
List<String> userIdList) throws WxErrorException {
if (startTime == null || endTime == null) {
throw new RuntimeException("starttime and endtime can't be null");
}

if (userIdList == null || userIdList.size() > 100) {
throw new RuntimeException("用户列表不能为空,不超过100个,若用户超过100个,请分批获取");
if (userIdList == null || userIdList.size() > USER_IDS_LIMIT) {
throw new RuntimeException("用户列表不能为空,不超过 " + USER_IDS_LIMIT + " 个,若用户超过 " + USER_IDS_LIMIT + " 个,请分批获取");
}

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

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

Expand Down Expand Up @@ -79,8 +79,8 @@ public List<WxCpCheckinOption> getCheckinOption(Date datetime, List<String> user
throw new RuntimeException("datetime can't be null");
}

if (userIdList == null || userIdList.size() > 100) {
throw new RuntimeException("用户列表不能为空,不超过100个,若用户超过100个,请分批获取");
if (userIdList == null || userIdList.size() > USER_IDS_LIMIT) {
throw new RuntimeException("用户列表不能为空,不超过 " + USER_IDS_LIMIT + " 个,若用户超过 " + USER_IDS_LIMIT + " 个,请分批获取");
}

JsonArray jsonArray = new JsonArray();
Expand All @@ -104,6 +104,59 @@ public List<WxCpCheckinOption> getCheckinOption(Date datetime, List<String> user
);
}

@Override
public WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime,
Integer cursor, Integer size, List<WxCpApprovalInfoQueryFilter> filters) throws WxErrorException {

if (cursor == null) {
cursor = 0;
}

if (size == null) {
size = 100;
}

if (size < 0 || size > 100) {
throw new IllegalArgumentException("size参数错误,请使用[1-100]填充,默认100");
}

JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("starttime", startTime.getTime() / 1000L);
jsonObject.addProperty("endtime", endTime.getTime() / 1000L);
jsonObject.addProperty("size", size);
jsonObject.addProperty("cursor", cursor);

if (filters != null && !filters.isEmpty()) {
JsonArray filterJsonArray = new JsonArray();
for (WxCpApprovalInfoQueryFilter filter : filters) {
filterJsonArray.add(new JsonParser().parse(filter.toJson()));
}
jsonObject.add("filters", filterJsonArray);
}

final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_APPROVAL_INFO);
String responseContent = this.mainService.post(url, jsonObject.toString());

return WxCpGsonBuilder.create().fromJson(responseContent, WxCpApprovalInfo.class);
}

@Override
public WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime) throws WxErrorException {
return this.getApprovalInfo(startTime, endTime, null, null, null);
}

@Override
public WxCpApprovalDetailResult getApprovalDetail(@NonNull String spNo) throws WxErrorException {

JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("sp_no", spNo);

final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_APPROVAL_DETAIL);
String responseContent = this.mainService.post(url, jsonObject.toString());

return WxCpGsonBuilder.create().fromJson(responseContent, WxCpApprovalDetailResult.class);
}

@Override
public WxCpApprovalDataResult getApprovalData(Date startTime, Date endTime, Long nextSpnum) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
Expand Down Expand Up @@ -139,7 +192,7 @@ public List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer
long endtimestamp = endTime.getTime() / 1000L;
long starttimestamp = startTime.getTime() / 1000L;

if (endtimestamp - starttimestamp < 0 || endtimestamp - starttimestamp >= 30 * 24 * 60 * 60) {
if (endtimestamp - starttimestamp < 0 || endtimestamp - starttimestamp >= MONTH_SECONDS) {
throw new RuntimeException("受限于网络传输,起止时间的最大跨度为30天,如超过30天,则以结束时间为基准向前取30天进行查询");
}

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

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

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

/**
* 审批申请数据
*
* @author element
*/
@Data
public class WxCpApprovalApplyData implements Serializable {

private static final long serialVersionUID = 4061352949894274704L;

private List<Content> contents;

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

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

import java.io.Serializable;

/**
* 申请人信息
* @author element
*/
@Data
public class WxCpApprovalApplyer extends WxCpOperator implements Serializable {

private static final long serialVersionUID = -8974662568286821271L;

/**
* 申请人所在部门id
*/
@SerializedName("partyid")
private String partyId;

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

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

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

/**
* 审批申请备注信息
*
* @author element
*/
@Data
public class WxCpApprovalComment implements Serializable {

private static final long serialVersionUID = -5430367411926856292L;

/**
* 备注人信息
*/
private WxCpOperator commentUserInfo;

/**
* 备注提交时间戳,Unix时间戳
*/
@SerializedName("commenttime")
private Long commentTime;

/**
* 备注id
*/
@SerializedName("commentid")
private String commentId;

/**
* 备注文本内容
*/
@SerializedName("commentcontent")
private String commentContent;

/**
* 备注附件id,可能有多个
*/
@SerializedName("media_id")
private List<String> mediaIds;

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

import com.google.gson.annotations.SerializedName;
import lombok.Data;
Expand All @@ -12,6 +12,7 @@
* @author Element
* @date 2019-04-06 14:36
*/
@Deprecated
@Data
public class WxCpApprovalDataResult implements Serializable {
private static final long serialVersionUID = -1046940445840716590L;
Expand Down
Loading

0 comments on commit 2f84da5

Please sign in to comment.