5
5
import com .google .gson .JsonObject ;
6
6
import com .google .gson .JsonParser ;
7
7
import com .google .gson .reflect .TypeToken ;
8
+ import lombok .NonNull ;
8
9
import lombok .RequiredArgsConstructor ;
9
10
import me .chanjar .weixin .common .error .WxErrorException ;
10
11
import me .chanjar .weixin .cp .api .WxCpOaService ;
11
12
import me .chanjar .weixin .cp .api .WxCpService ;
12
- import me .chanjar .weixin .cp .bean .WxCpApprovalDataResult ;
13
- import me .chanjar .weixin .cp .bean .WxCpCheckinData ;
14
- import me .chanjar .weixin .cp .bean .WxCpCheckinOption ;
15
- import me .chanjar .weixin .cp .bean .WxCpDialRecord ;
16
- import me .chanjar .weixin .cp .constant .WxCpApiPathConsts ;
13
+ import me .chanjar .weixin .cp .bean .oa .*;
17
14
import me .chanjar .weixin .cp .util .json .WxCpGsonBuilder ;
18
15
19
16
import java .util .Date ;
22
19
import static me .chanjar .weixin .cp .constant .WxCpApiPathConsts .Oa .*;
23
20
24
21
/**
25
- * .
22
+ * 企业微信 OA 接口实现
26
23
*
27
24
* @author Element
28
25
* @date 2019-04-06 11:20
31
28
public class WxCpOaServiceImpl implements WxCpOaService {
32
29
private final WxCpService mainService ;
33
30
31
+ private static final int MONTH_SECONDS = 30 * 24 * 60 * 60 ;
32
+ private static final int USER_IDS_LIMIT = 100 ;
33
+
34
34
@ Override
35
35
public List <WxCpCheckinData > getCheckinData (Integer openCheckinDataType , Date startTime , Date endTime ,
36
36
List <String > userIdList ) throws WxErrorException {
37
37
if (startTime == null || endTime == null ) {
38
38
throw new RuntimeException ("starttime and endtime can't be null" );
39
39
}
40
40
41
- if (userIdList == null || userIdList .size () > 100 ) {
42
- throw new RuntimeException ("用户列表不能为空,不超过100个,若用户超过100个 ,请分批获取" );
41
+ if (userIdList == null || userIdList .size () > USER_IDS_LIMIT ) {
42
+ throw new RuntimeException ("用户列表不能为空,不超过 " + USER_IDS_LIMIT + " 个,若用户超过 " + USER_IDS_LIMIT + " 个 ,请分批获取" );
43
43
}
44
44
45
45
long endtimestamp = endTime .getTime () / 1000L ;
46
46
long starttimestamp = startTime .getTime () / 1000L ;
47
47
48
- if (endtimestamp - starttimestamp < 0 || endtimestamp - starttimestamp >= 30 * 24 * 60 * 60 ) {
48
+ if (endtimestamp - starttimestamp < 0 || endtimestamp - starttimestamp >= MONTH_SECONDS ) {
49
49
throw new RuntimeException ("获取记录时间跨度不超过一个月" );
50
50
}
51
51
@@ -79,8 +79,8 @@ public List<WxCpCheckinOption> getCheckinOption(Date datetime, List<String> user
79
79
throw new RuntimeException ("datetime can't be null" );
80
80
}
81
81
82
- if (userIdList == null || userIdList .size () > 100 ) {
83
- throw new RuntimeException ("用户列表不能为空,不超过100个,若用户超过100个 ,请分批获取" );
82
+ if (userIdList == null || userIdList .size () > USER_IDS_LIMIT ) {
83
+ throw new RuntimeException ("用户列表不能为空,不超过 " + USER_IDS_LIMIT + " 个,若用户超过 " + USER_IDS_LIMIT + " 个 ,请分批获取" );
84
84
}
85
85
86
86
JsonArray jsonArray = new JsonArray ();
@@ -104,6 +104,59 @@ public List<WxCpCheckinOption> getCheckinOption(Date datetime, List<String> user
104
104
);
105
105
}
106
106
107
+ @ Override
108
+ public WxCpApprovalInfo getApprovalInfo (@ NonNull Date startTime , @ NonNull Date endTime ,
109
+ Integer cursor , Integer size , List <WxCpApprovalInfoQueryFilter > filters ) throws WxErrorException {
110
+
111
+ if (cursor == null ) {
112
+ cursor = 0 ;
113
+ }
114
+
115
+ if (size == null ) {
116
+ size = 100 ;
117
+ }
118
+
119
+ if (size < 0 || size > 100 ) {
120
+ throw new IllegalArgumentException ("size参数错误,请使用[1-100]填充,默认100" );
121
+ }
122
+
123
+ JsonObject jsonObject = new JsonObject ();
124
+ jsonObject .addProperty ("starttime" , startTime .getTime () / 1000L );
125
+ jsonObject .addProperty ("endtime" , endTime .getTime () / 1000L );
126
+ jsonObject .addProperty ("size" , size );
127
+ jsonObject .addProperty ("cursor" , cursor );
128
+
129
+ if (filters != null && !filters .isEmpty ()) {
130
+ JsonArray filterJsonArray = new JsonArray ();
131
+ for (WxCpApprovalInfoQueryFilter filter : filters ) {
132
+ filterJsonArray .add (new JsonParser ().parse (filter .toJson ()));
133
+ }
134
+ jsonObject .add ("filters" , filterJsonArray );
135
+ }
136
+
137
+ final String url = this .mainService .getWxCpConfigStorage ().getApiUrl (GET_APPROVAL_INFO );
138
+ String responseContent = this .mainService .post (url , jsonObject .toString ());
139
+
140
+ return WxCpGsonBuilder .create ().fromJson (responseContent , WxCpApprovalInfo .class );
141
+ }
142
+
143
+ @ Override
144
+ public WxCpApprovalInfo getApprovalInfo (@ NonNull Date startTime , @ NonNull Date endTime ) throws WxErrorException {
145
+ return this .getApprovalInfo (startTime , endTime , null , null , null );
146
+ }
147
+
148
+ @ Override
149
+ public WxCpApprovalDetailResult getApprovalDetail (@ NonNull String spNo ) throws WxErrorException {
150
+
151
+ JsonObject jsonObject = new JsonObject ();
152
+ jsonObject .addProperty ("sp_no" , spNo );
153
+
154
+ final String url = this .mainService .getWxCpConfigStorage ().getApiUrl (GET_APPROVAL_DETAIL );
155
+ String responseContent = this .mainService .post (url , jsonObject .toString ());
156
+
157
+ return WxCpGsonBuilder .create ().fromJson (responseContent , WxCpApprovalDetailResult .class );
158
+ }
159
+
107
160
@ Override
108
161
public WxCpApprovalDataResult getApprovalData (Date startTime , Date endTime , Long nextSpnum ) throws WxErrorException {
109
162
JsonObject jsonObject = new JsonObject ();
@@ -139,7 +192,7 @@ public List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer
139
192
long endtimestamp = endTime .getTime () / 1000L ;
140
193
long starttimestamp = startTime .getTime () / 1000L ;
141
194
142
- if (endtimestamp - starttimestamp < 0 || endtimestamp - starttimestamp >= 30 * 24 * 60 * 60 ) {
195
+ if (endtimestamp - starttimestamp < 0 || endtimestamp - starttimestamp >= MONTH_SECONDS ) {
143
196
throw new RuntimeException ("受限于网络传输,起止时间的最大跨度为30天,如超过30天,则以结束时间为基准向前取30天进行查询" );
144
197
}
145
198
0 commit comments