|
@@ -7,6 +7,7 @@ import com.tzld.piaoquan.growth.common.dao.mapper.*;
|
|
|
import com.tzld.piaoquan.growth.common.model.bo.XxlJobParam;
|
|
|
import com.tzld.piaoquan.growth.common.model.po.*;
|
|
|
import com.tzld.piaoquan.growth.common.service.WeComAccessTokenService;
|
|
|
+import com.tzld.piaoquan.growth.common.service.WeComSendService;
|
|
|
import com.tzld.piaoquan.growth.common.service.WeComStaffService;
|
|
|
import com.tzld.piaoquan.growth.common.service.WeComUserService;
|
|
|
import com.tzld.piaoquan.growth.common.utils.DateUtil;
|
|
@@ -65,6 +66,9 @@ public class WeComUserDataJob {
|
|
|
@Autowired
|
|
|
private WeComStaffService weComStaffService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private WeComSendService weComSendService;
|
|
|
+
|
|
|
|
|
|
@XxlJob("updateStaffWithUserJob")
|
|
|
public ReturnT<String> updateStaffWithUser(String param) {
|
|
@@ -181,7 +185,11 @@ public class WeComUserDataJob {
|
|
|
if (StringUtils.isNotEmpty(cursor)) {
|
|
|
param.put("cursor", cursor);
|
|
|
}
|
|
|
- return httpPoolClient.post(url, param.toJSONString());
|
|
|
+ if (corpId == 1L) {
|
|
|
+ return httpPoolClient.post(url, param.toJSONString());
|
|
|
+ } else {
|
|
|
+ return weComSendService.sendPost(url, param.toJSONString());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@XxlJob("insertStaffWithUserJob")
|
|
@@ -237,7 +245,12 @@ public class WeComUserDataJob {
|
|
|
public List<String> getUserList(String userId, Long corpId) throws IOException {
|
|
|
String weComAccessToken = weComAccessTokenService.getWeComAccessToken(corpId);
|
|
|
String url = String.format(GET_WE_COM_EXTERNAL_CONTACT_LIST + "?access_token=%s&userid=%s", weComAccessToken, userId);
|
|
|
- String res = httpPoolClient.get(url);
|
|
|
+ String res;
|
|
|
+ if (corpId == 1L) {
|
|
|
+ res = httpPoolClient.get(url);
|
|
|
+ } else {
|
|
|
+ res = weComSendService.sendGet(url);
|
|
|
+ }
|
|
|
JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
Integer errcode = jsonObject.getInteger("errcode");
|
|
|
if (errcode == 0) {
|
|
@@ -248,6 +261,7 @@ public class WeComUserDataJob {
|
|
|
|
|
|
@XxlJob("statisticsUserCountJob")
|
|
|
public ReturnT<String> statisticsUserCount(String param) {
|
|
|
+ refreshTag();
|
|
|
StaffExample staffExample = new StaffExample();
|
|
|
List<Staff> staffList = staffMapper.selectByExample(staffExample);
|
|
|
String date;
|
|
@@ -345,116 +359,121 @@ public class WeComUserDataJob {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- @XxlJob("getUserTagJob")
|
|
|
- public ReturnT<String> getUserTag(String param) {
|
|
|
+// @XxlJob("getUserTagJob")
|
|
|
+// public ReturnT<String> getUserTag(String param) {
|
|
|
+// try {
|
|
|
+// refreshTag();
|
|
|
+// XxlJobParam xxlJobParam = new XxlJobParam();
|
|
|
+// if (StringUtils.isNotEmpty(param)) {
|
|
|
+// xxlJobParam = JSONObject.parseObject(param, XxlJobParam.class);
|
|
|
+// }
|
|
|
+// CorpExample corpExample = new CorpExample();
|
|
|
+// CorpExample.Criteria corpCriteria = corpExample.createCriteria();
|
|
|
+// if (xxlJobParam.getCorpId() != null) {
|
|
|
+// corpCriteria.andIdEqualTo(xxlJobParam.getCorpId());
|
|
|
+// }
|
|
|
+// List<Corp> corps = corpMapper.selectByExample(corpExample);
|
|
|
+// for (Corp corp : corps) {
|
|
|
+// StaffExample staffExample = new StaffExample();
|
|
|
+// StaffExample.Criteria staffCriteria = staffExample.createCriteria();
|
|
|
+// staffCriteria.andCorpIdEqualTo(corp.getId());
|
|
|
+// List<Long> staffIds = new ArrayList<>();
|
|
|
+// if (xxlJobParam.getStaffId() != null) {
|
|
|
+// staffIds.add(xxlJobParam.getStaffId());
|
|
|
+// }
|
|
|
+// if (!CollectionUtils.isEmpty(xxlJobParam.getStaffIds())) {
|
|
|
+// staffIds.addAll(xxlJobParam.getStaffIds());
|
|
|
+// }
|
|
|
+// if (!CollectionUtils.isEmpty(staffIds)) {
|
|
|
+// staffCriteria.andIdIn(staffIds);
|
|
|
+// }
|
|
|
+// List<Staff> staffList = staffMapper.selectByExample(staffExample);
|
|
|
+// for (Staff staff : staffList) {
|
|
|
+// List<String> existExternalUserIds = getUserList(staff.getCarrierId(), corp.getId());
|
|
|
+// for (String externalUserId : existExternalUserIds) {
|
|
|
+// JSONObject userDetail = weComUserService.getUserDetail(externalUserId, corp.getId());
|
|
|
+// JSONObject externalContact = userDetail.getJSONObject("external_contact");
|
|
|
+// JSONArray followUserList = userDetail.getJSONArray("follow_user");
|
|
|
+// Long createAt = null;
|
|
|
+// for (int i = 0; i < followUserList.size(); i++) {
|
|
|
+// JSONObject followUser = followUserList.getJSONObject(i);
|
|
|
+// if (createAt == null) {
|
|
|
+// createAt = followUser.getLong("createtime");
|
|
|
+// } else {
|
|
|
+// createAt = Math.min(createAt, followUser.getLong("createtime"));
|
|
|
+// }
|
|
|
+// JSONArray tagIds = followUser.getJSONArray("tags");
|
|
|
+// if (!CollectionUtils.isEmpty(tagIds)) {
|
|
|
+// List<String> tagIdList = new ArrayList<>();
|
|
|
+// for (int j = 0; j < tagIds.size(); j++) {
|
|
|
+// JSONObject jsonObject = tagIds.getJSONObject(j);
|
|
|
+// tagIdList.add(jsonObject.getString("tag_id"));
|
|
|
+// }
|
|
|
+// for (String tagId : tagIdList) {
|
|
|
+// TagExample example = new TagExample();
|
|
|
+// example.createCriteria().andTagIdEqualTo(tagId);
|
|
|
+// List<Tag> tags = tagMapper.selectByExample(example);
|
|
|
+// if (!CollectionUtils.isEmpty(tags)) {
|
|
|
+// Long userId = weComUserMapper.selectIdByExternalUserId(externalUserId);
|
|
|
+// userId = addAndUpdateUser(externalContact, corp.getId(), externalUserId,
|
|
|
+// createAt, staff.getId(), userId);
|
|
|
+// Tag tag = tags.get(0);
|
|
|
+// UserWithTag userWithTag = new UserWithTag();
|
|
|
+// userWithTag.setUserId(userId);
|
|
|
+// userWithTag.setTagId(tag.getId());
|
|
|
+// weComUserService.addUserWithTag(userWithTag);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("getUserTag error", e);
|
|
|
+// }
|
|
|
+//
|
|
|
+// return ReturnT.SUCCESS;
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ public void refreshTag() {
|
|
|
try {
|
|
|
- refreshTag();
|
|
|
- XxlJobParam xxlJobParam = new XxlJobParam();
|
|
|
- if (StringUtils.isNotEmpty(param)) {
|
|
|
- xxlJobParam = JSONObject.parseObject(param, XxlJobParam.class);
|
|
|
- }
|
|
|
- CorpExample corpExample = new CorpExample();
|
|
|
- CorpExample.Criteria corpCriteria = corpExample.createCriteria();
|
|
|
- if (xxlJobParam.getCorpId() != null) {
|
|
|
- corpCriteria.andIdEqualTo(xxlJobParam.getCorpId());
|
|
|
- }
|
|
|
- List<Corp> corps = corpMapper.selectByExample(corpExample);
|
|
|
- for (Corp corp : corps) {
|
|
|
- StaffExample staffExample = new StaffExample();
|
|
|
- StaffExample.Criteria staffCriteria = staffExample.createCriteria();
|
|
|
- staffCriteria.andCorpIdEqualTo(corp.getId());
|
|
|
- List<Long> staffIds = new ArrayList<>();
|
|
|
- if (xxlJobParam.getStaffId() != null) {
|
|
|
- staffIds.add(xxlJobParam.getStaffId());
|
|
|
- }
|
|
|
- if (!CollectionUtils.isEmpty(xxlJobParam.getStaffIds())) {
|
|
|
- staffIds.addAll(xxlJobParam.getStaffIds());
|
|
|
- }
|
|
|
- if (!CollectionUtils.isEmpty(staffIds)) {
|
|
|
- staffCriteria.andIdIn(staffIds);
|
|
|
- }
|
|
|
- List<Staff> staffList = staffMapper.selectByExample(staffExample);
|
|
|
- for (Staff staff : staffList) {
|
|
|
- List<String> existExternalUserIds = getUserList(staff.getCarrierId(), corp.getId());
|
|
|
- for (String externalUserId : existExternalUserIds) {
|
|
|
- JSONObject userDetail = weComUserService.getUserDetail(externalUserId, corp.getId());
|
|
|
- JSONObject externalContact = userDetail.getJSONObject("external_contact");
|
|
|
- JSONArray followUserList = userDetail.getJSONArray("follow_user");
|
|
|
- Long createAt = null;
|
|
|
- for (int i = 0; i < followUserList.size(); i++) {
|
|
|
- JSONObject followUser = followUserList.getJSONObject(i);
|
|
|
- if (createAt == null) {
|
|
|
- createAt = followUser.getLong("createtime");
|
|
|
- } else {
|
|
|
- createAt = Math.min(createAt, followUser.getLong("createtime"));
|
|
|
- }
|
|
|
- JSONArray tagIds = followUser.getJSONArray("tags");
|
|
|
- if (!CollectionUtils.isEmpty(tagIds)) {
|
|
|
- List<String> tagIdList = new ArrayList<>();
|
|
|
- for (int j = 0; j < tagIds.size(); j++) {
|
|
|
- JSONObject jsonObject = tagIds.getJSONObject(j);
|
|
|
- tagIdList.add(jsonObject.getString("tag_id"));
|
|
|
- }
|
|
|
- for (String tagId : tagIdList) {
|
|
|
- TagExample example = new TagExample();
|
|
|
- example.createCriteria().andTagIdEqualTo(tagId);
|
|
|
- List<Tag> tags = tagMapper.selectByExample(example);
|
|
|
- if (!CollectionUtils.isEmpty(tags)) {
|
|
|
- Long userId = weComUserMapper.selectIdByExternalUserId(externalUserId);
|
|
|
- userId = addAndUpdateUser(externalContact, corp.getId(), externalUserId,
|
|
|
- createAt, staff.getId(), userId);
|
|
|
- Tag tag = tags.get(0);
|
|
|
- UserWithTag userWithTag = new UserWithTag();
|
|
|
- userWithTag.setUserId(userId);
|
|
|
- userWithTag.setTagId(tag.getId());
|
|
|
- weComUserService.addUserWithTag(userWithTag);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ String weComAccessToken = weComAccessTokenService.getWeComAccessToken(1L);
|
|
|
+ String url = String.format(POST_CORP_TAG_LIST + "?access_token=%s", weComAccessToken);
|
|
|
+ String res = httpPoolClient.post(url);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ Integer errcode = jsonObject.getInteger("errcode");
|
|
|
+ if (errcode == 0) {
|
|
|
+ JSONArray tagGroup = jsonObject.getJSONArray("tag_group");
|
|
|
+ if (!tagGroup.isEmpty()) {
|
|
|
+ for (int i = 0; i < tagGroup.size(); i++) {
|
|
|
+ JSONObject tagGroupJSONObject = tagGroup.getJSONObject(i);
|
|
|
+ String groupId = tagGroupJSONObject.getString("group_id");
|
|
|
+ String groupName = tagGroupJSONObject.getString("group_name");
|
|
|
+ JSONArray tags = tagGroupJSONObject.getJSONArray("tag");
|
|
|
+ if (tags.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (int j = 0; j < tags.size(); j++) {
|
|
|
+ JSONObject tagsJSONObject = tags.getJSONObject(j);
|
|
|
+ String tagId = tagsJSONObject.getString("id");
|
|
|
+ String tagName = tagsJSONObject.getString("name");
|
|
|
+ Tag tag = new Tag();
|
|
|
+ tag.setTagGroupId(groupId);
|
|
|
+ tag.setTagGroupName(groupName);
|
|
|
+ tag.setTagId(tagId);
|
|
|
+ tag.setTagName(tagName);
|
|
|
+ addAndUpdateTag(tag);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- log.error("getUserTag error", e);
|
|
|
+ log.error("refreshTag error", e);
|
|
|
}
|
|
|
|
|
|
- return ReturnT.SUCCESS;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public void refreshTag() throws IOException {
|
|
|
- String weComAccessToken = weComAccessTokenService.getWeComAccessToken(1L);
|
|
|
- String url = String.format(POST_CORP_TAG_LIST + "?access_token=%s", weComAccessToken);
|
|
|
- String res = httpPoolClient.post(url);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
- Integer errcode = jsonObject.getInteger("errcode");
|
|
|
- if (errcode == 0) {
|
|
|
- JSONArray tagGroup = jsonObject.getJSONArray("tag_group");
|
|
|
- if (!tagGroup.isEmpty()) {
|
|
|
- for (int i = 0; i < tagGroup.size(); i++) {
|
|
|
- JSONObject tagGroupJSONObject = tagGroup.getJSONObject(i);
|
|
|
- String groupId = tagGroupJSONObject.getString("group_id");
|
|
|
- String groupName = tagGroupJSONObject.getString("group_name");
|
|
|
- JSONArray tags = tagGroupJSONObject.getJSONArray("tag");
|
|
|
- if (tags.isEmpty()) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- for (int j = 0; j < tags.size(); j++) {
|
|
|
- JSONObject tagsJSONObject = tags.getJSONObject(j);
|
|
|
- String tagId = tagsJSONObject.getString("id");
|
|
|
- String tagName = tagsJSONObject.getString("name");
|
|
|
- Tag tag = new Tag();
|
|
|
- tag.setTagGroupId(groupId);
|
|
|
- tag.setTagGroupName(groupName);
|
|
|
- tag.setTagId(tagId);
|
|
|
- tag.setTagName(tagName);
|
|
|
- addAndUpdateTag(tag);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
private void addAndUpdateTag(Tag tag) {
|