@@ -70,23 +70,62 @@ public WxCpKfAccountLinkResp getAccountLink(WxCpKfAccountLink link) throws WxErr
7070
7171 @ Override
7272 public WxCpKfServicerOpResp addServicer (String openKfid , List <String > userIdList ) throws WxErrorException {
73- return servicerOp (openKfid , userIdList , SERVICER_ADD );
73+ return servicerOp (openKfid , userIdList , null , SERVICER_ADD );
74+ }
75+
76+ @ Override
77+ public WxCpKfServicerOpResp addServicer (String openKfId , List <String > userIdList , List <String > departmentIdList ) throws WxErrorException {
78+ validateParameters (SERVICER_ADD , userIdList , departmentIdList );
79+ return servicerOp (openKfId , userIdList , departmentIdList , SERVICER_ADD );
7480 }
7581
7682 @ Override
7783 public WxCpKfServicerOpResp delServicer (String openKfid , List <String > userIdList ) throws WxErrorException {
78- return servicerOp (openKfid , userIdList , SERVICER_DEL );
84+ return servicerOp (openKfid , userIdList , null , SERVICER_DEL );
7985 }
8086
81- private WxCpKfServicerOpResp servicerOp (String openKfid , List <String > userIdList , String uri ) throws WxErrorException {
87+ @ Override
88+ public WxCpKfServicerOpResp delServicer (String openKfid , List <String > userIdList , List <String > departmentIdList ) throws WxErrorException {
89+ validateParameters (SERVICER_DEL , userIdList , departmentIdList );
90+ return servicerOp (openKfid , userIdList , departmentIdList , SERVICER_DEL );
91+ }
92+
93+ private void validateParameters (String uri , List <String > userIdList , List <String > departmentIdList ) {
94+ if ((userIdList == null || userIdList .isEmpty ()) && (departmentIdList == null || departmentIdList .isEmpty ())) {
95+ throw new IllegalArgumentException ("userid_list和department_id_list至少需要填其中一个" );
96+ }
97+ if (SERVICER_DEL .equals (uri )) {
98+ if (userIdList != null && userIdList .size () > 100 ) {
99+ throw new IllegalArgumentException ("可填充个数:0 ~ 100。超过100个需分批调用。" );
100+ }
101+ if (departmentIdList != null && departmentIdList .size () > 100 ) {
102+ throw new IllegalArgumentException ("可填充个数:0 ~ 100。超过100个需分批调用。" );
103+ }
104+ } else {
105+ if (userIdList != null && userIdList .size () > 100 ) {
106+ throw new IllegalArgumentException ("可填充个数:0 ~ 100。超过100个需分批调用。" );
107+ }
108+ if (departmentIdList != null && departmentIdList .size () > 20 ) {
109+ throw new IllegalArgumentException ("可填充个数:0 ~ 20。" );
110+ }
111+ }
112+ }
113+
114+ private WxCpKfServicerOpResp servicerOp (String openKfid , List <String > userIdList , List <String > departmentIdList , String uri ) throws WxErrorException {
82115 String url = cpService .getWxCpConfigStorage ().getApiUrl (uri );
83116
84117 JsonObject json = new JsonObject ();
85118 json .addProperty ("open_kfid" , openKfid );
86- JsonArray userIdArray = new JsonArray ();
87- userIdList .forEach (userIdArray ::add );
88- json .add ("userid_list" , userIdArray );
89-
119+ if (userIdList != null && !userIdList .isEmpty ()) {
120+ JsonArray userIdArray = new JsonArray ();
121+ userIdList .forEach (userIdArray ::add );
122+ json .add ("userid_list" , userIdArray );
123+ }
124+ if (departmentIdList != null && !departmentIdList .isEmpty ()) {
125+ JsonArray departmentIdArray = new JsonArray ();
126+ departmentIdList .forEach (departmentIdArray ::add );
127+ json .add ("department_id_list" , departmentIdArray );
128+ }
90129 String responseContent = cpService .post (url , json .toString ());
91130 return WxCpKfServicerOpResp .fromJson (responseContent );
92131 }
0 commit comments