|
@@ -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.WeComStaffService;
|
|
|
import com.tzld.piaoquan.growth.common.service.WeComUserService;
|
|
|
import com.tzld.piaoquan.growth.common.utils.DateUtil;
|
|
|
import com.tzld.piaoquan.growth.common.utils.LarkRobotUtil;
|
|
@@ -19,6 +20,7 @@ import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -60,6 +62,9 @@ public class WeComUserDataJob {
|
|
|
@Autowired
|
|
|
private UserWithTagMapper userWithTagMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private WeComStaffService weComStaffService;
|
|
|
+
|
|
|
@XxlJob("updateStaffWithUserJob")
|
|
|
public ReturnT<String> updateStaffWithUser(String param) {
|
|
|
XxlJobParam xxlJobParam = new XxlJobParam();
|
|
@@ -348,34 +353,45 @@ public class WeComUserDataJob {
|
|
|
for (String externalUserId : existExternalUserIds) {
|
|
|
JSONObject userDetail = weComUserService.getUserDetail(externalUserId, corp.getId());
|
|
|
JSONObject externalContact = userDetail.getJSONObject("external_contact");
|
|
|
- JSONObject followInfo = userDetail.getJSONObject("follow_info");
|
|
|
- Long createAt = followInfo.getLong("createtime");
|
|
|
- JSONArray tagIds = followInfo.getJSONArray("tag_id");
|
|
|
- if (!tagIds.isEmpty()) {
|
|
|
- List<String> tagIdList = tagIds.toJavaList(String.class);
|
|
|
- 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);
|
|
|
- if (userId == null) {
|
|
|
- userId = addUser(externalContact, corp.getId(), externalUserId, createAt, staff.getId());
|
|
|
+ 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);
|
|
|
+ if (userId == null) {
|
|
|
+ userId = addUser(externalContact, corp.getId(), externalUserId, createAt, staff.getId());
|
|
|
+ }
|
|
|
+ Tag tag = tags.get(0);
|
|
|
+ UserWithTag userWithTag = new UserWithTag();
|
|
|
+ userWithTag.setUserId(userId);
|
|
|
+ userWithTag.setTagId(tag.getId());
|
|
|
+ addUserWithTag(userWithTag);
|
|
|
}
|
|
|
- Tag tag = tags.get(0);
|
|
|
- UserWithTag userWithTag = new UserWithTag();
|
|
|
- userWithTag.setUserId(userId);
|
|
|
- userWithTag.setTagId(tag.getId());
|
|
|
- addUserWithTag(userWithTag);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- LarkRobotUtil.sendMessage("insertStaffWithUserJob error" + e);
|
|
|
+// LarkRobotUtil.sendMessage("insertStaffWithUserJob error" + e);
|
|
|
log.error("insertStaffWithUserJob error", e);
|
|
|
}
|
|
|
|