Explorar o código

增加用户数量任务

xueyiming hai 3 meses
pai
achega
6a21b403aa

+ 38 - 0
offline-module/src/main/java/com/tzld/piaoquan/offline/job/WeComUserDataJob.java

@@ -21,7 +21,9 @@ import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 import static com.tzld.piaoquan.growth.common.common.constant.WeComConstant.*;
@@ -229,4 +231,40 @@ public class WeComUserDataJob {
         }
         return null;
     }
+
+
+    private Map<String, Integer> getUserList(Staff staff, Long corpId, String date) {
+        Map<String, Integer> result = new HashMap<>();
+        try {
+            int count = 0;
+            int newCount = 0;
+            String cursor = "";
+            do {
+                String res = getUserDetailList(staff.getCarrierId(), cursor, corpId);
+                log.info("updateUserList res={} cursor={}", res, cursor);
+                JSONObject jsonObject = JSONObject.parseObject(res);
+                Integer errCode = jsonObject.getInteger("errcode");
+                if (errCode != 0) {
+                    log.error("updateUserList error carrierId={} cursor={}", staff.getCarrierId(), cursor);
+                    return null;
+                }
+                JSONArray externalContactList = jsonObject.getJSONArray("external_contact_list");
+                for (int i = 0; i < externalContactList.size(); i++) {
+                    JSONObject externalContact = externalContactList.getJSONObject(i).getJSONObject("external_contact");
+                    JSONObject followInfo = externalContactList.getJSONObject(i).getJSONObject("follow_info");
+                    Long createAt = followInfo.getLong("createtime");
+                    String externalUserId = externalContact.getString("external_userid");
+                }
+                String nextCursor = jsonObject.getString("next_cursor");
+                if (cursor.equals(nextCursor)) {
+                    break;
+                }
+                cursor = nextCursor;
+            } while (StringUtils.isNotEmpty(cursor));
+        } catch (IOException e) {
+            LarkRobotUtil.sendMessage("updateUser error" + e);
+            log.error("updateUser error", e);
+        }
+        return result;
+    }
 }