|
@@ -4,14 +4,19 @@ import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
|
|
import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
|
|
import com.tzld.piaoquan.wecom.model.po.User;
|
|
import com.tzld.piaoquan.wecom.model.po.User;
|
|
|
|
+import com.tzld.piaoquan.wecom.model.po.UserExample;
|
|
import com.tzld.piaoquan.wecom.utils.HttpClientUtil;
|
|
import com.tzld.piaoquan.wecom.utils.HttpClientUtil;
|
|
import com.tzld.piaoquan.wecom.utils.HttpPoolClient;
|
|
import com.tzld.piaoquan.wecom.utils.HttpPoolClient;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@Component
|
|
@Component
|
|
@@ -19,9 +24,13 @@ public class WeComUserDataJob {
|
|
|
|
|
|
String GET_USER_URL = "https://open.weibanzhushou.com/open-api/external_user/list";
|
|
String GET_USER_URL = "https://open.weibanzhushou.com/open-api/external_user/list";
|
|
|
|
|
|
|
|
+ String UPDATE_USER_URL = "https://open.weibanzhushou.com/open-api/external_user/update/list";
|
|
|
|
+
|
|
|
|
+ String ACCESS_TOKEN = "38969e430219e6b18f88792184a37b11";
|
|
|
|
+
|
|
private static final HttpPoolClient httpPoolClientDefault = HttpClientUtil.create(30000, 30000, 2000, 5000, 5, 30000);
|
|
private static final HttpPoolClient httpPoolClientDefault = HttpClientUtil.create(30000, 30000, 2000, 5000, 5, 30000);
|
|
|
|
|
|
- final int size = 30;
|
|
|
|
|
|
+ final int size = 100;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private UserMapper userMapper;
|
|
private UserMapper userMapper;
|
|
@@ -29,11 +38,11 @@ public class WeComUserDataJob {
|
|
public void insertAllUser() {
|
|
public void insertAllUser() {
|
|
Long endTime = System.currentTimeMillis() / 1000;
|
|
Long endTime = System.currentTimeMillis() / 1000;
|
|
int sum = 0;
|
|
int sum = 0;
|
|
- for (int i = 0; i < 5; i++) {
|
|
|
|
|
|
+ for (int i = 0; i < 1000; i++) {
|
|
String res = null;
|
|
String res = null;
|
|
try {
|
|
try {
|
|
//TODO accessToken 暂时写死 后续增加接口刷新和存储
|
|
//TODO accessToken 暂时写死 后续增加接口刷新和存储
|
|
- res = getUser("12c11f5504cecdc89210070ccfd72461", size, i * size, 1720540800L, endTime);
|
|
|
|
|
|
+ res = getUser(ACCESS_TOKEN, size, i * size, 1720540800L, endTime);
|
|
//TODO 记录查询数据 info日志
|
|
//TODO 记录查询数据 info日志
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
//TODO 记录异常日志 记录起止时间和页数 startTime endTime i
|
|
//TODO 记录异常日志 记录起止时间和页数 startTime endTime i
|
|
@@ -51,10 +60,14 @@ public class WeComUserDataJob {
|
|
User user = jsonArray.getJSONObject(j).toJavaObject(User.class);
|
|
User user = jsonArray.getJSONObject(j).toJavaObject(User.class);
|
|
user.setExternalUserId3rdParty(id);
|
|
user.setExternalUserId3rdParty(id);
|
|
//TODO 记录对象数据 info日志
|
|
//TODO 记录对象数据 info日志
|
|
- int insert = userMapper.insert(user);
|
|
|
|
- if (insert <= 0) {
|
|
|
|
- //TODO 异常日志
|
|
|
|
- continue;
|
|
|
|
|
|
+ try {
|
|
|
|
+ int insert = userMapper.insert(user);
|
|
|
|
+ if (insert <= 0) {
|
|
|
|
+ //TODO 异常日志
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ //TODO 打印异常日志
|
|
}
|
|
}
|
|
sum++;
|
|
sum++;
|
|
}
|
|
}
|
|
@@ -66,8 +79,6 @@ public class WeComUserDataJob {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public String getUser(String accessToken, Integer limit, Integer offset, Long startTime, Long endTime) throws IOException {
|
|
public String getUser(String accessToken, Integer limit, Integer offset, Long startTime, Long endTime) throws IOException {
|
|
@@ -78,4 +89,68 @@ public class WeComUserDataJob {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ public void updateUser() {
|
|
|
|
+ Long endTime = System.currentTimeMillis() / 1000;
|
|
|
|
+ int sum = 0;
|
|
|
|
+ for (int i = 0; i < 1000; i++) {
|
|
|
|
+ String res = null;
|
|
|
|
+ try {
|
|
|
|
+ //TODO accessToken 暂时写死 后续增加接口刷新和存储
|
|
|
|
+ res = getUpdateUser(ACCESS_TOKEN, size, i * size, 1726821389L, endTime);
|
|
|
|
+ //TODO 记录查询数据 info日志
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ //TODO 记录异常日志 记录起止时间和页数 startTime endTime i
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ if (ObjectUtils.isEmpty(res)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
|
+ Integer total = (Integer) jsonObject.get("total");
|
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("external_user_list");
|
|
|
|
+ for (int j = 0; j < jsonArray.size(); j++) {
|
|
|
|
+ String id = (String) jsonArray.getJSONObject(j).get("id");
|
|
|
|
+ jsonArray.getJSONObject(j).put("id", null);
|
|
|
|
+ User user = jsonArray.getJSONObject(j).toJavaObject(User.class);
|
|
|
|
+ user.setExternalUserId3rdParty(id);
|
|
|
|
+ UserExample example = new UserExample();
|
|
|
|
+ example.createCriteria().andExternalUserId3rdPartyEqualTo(user.getExternalUserId3rdParty());
|
|
|
|
+ List<User> list = userMapper.selectByExample(example);
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
+ //没有用户,走插入逻辑
|
|
|
|
+ int insert = userMapper.insert(user);
|
|
|
|
+ if (insert <= 0) {
|
|
|
|
+ //TODO 异常日志
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ User oldUser = list.get(0);
|
|
|
|
+ user.setId(oldUser.getId());
|
|
|
|
+ int update = userMapper.updateByPrimaryKeySelective(user);
|
|
|
|
+ if (update < 0) {
|
|
|
|
+ //TODO 异常日志
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ sum++;
|
|
|
|
+ if (jsonArray.size() < size) {
|
|
|
|
+ if (total != null && total > sum) {
|
|
|
|
+ //TODO 输出异常 插入数量不足
|
|
|
|
+ System.out.println("插入数量不足");
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String getUpdateUser(String accessToken, Integer limit, Integer offset, Long startTime, Long endTime) throws IOException {
|
|
|
|
+ String url = UPDATE_USER_URL
|
|
|
|
+ + "?access_token=" + accessToken
|
|
|
|
+ + "&limit=" + limit + "&offset=" + offset + "&start_update_time=" + startTime + "&end_update_time=" + endTime
|
|
|
|
+ + "&source=external_user";
|
|
|
|
+ return httpPoolClientDefault.get(url);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|