Kaynağa Gözat

fix 重整用户标签

zoujiajian 2 yıl önce
ebeveyn
işleme
173889a91d

+ 16 - 1
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpEventActionServiceImpl.java

@@ -591,10 +591,17 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 		relation.setWxCorpId(wxCorpId);
 		if (relation.getId() == null) relationMapper.insert(relation);
 		else relationMapper.updateById(relation);
-		corpUserTagMapper.delete(Wrappers.lambdaQuery(CorpUserTag.class).eq(CorpUserTag::getRelationId, relation.getId()));
 
+		List<CorpUserTag> corpUserTags = Optional.ofNullable(corpUserTagMapper.selectList(Wrappers.lambdaQuery(CorpUserTag.class)
+				.eq(CorpUserTag::getRelationId, relation.getId()))).orElse(new ArrayList<>());
+		List<String> exists_tagIds = corpUserTags.stream().map(CorpUserTag::getTagId).collect(Collectors.toList());
 		//存储用户标签
 		Stream.of(followedUser.getTags()).forEach((tag) -> {
+			//相同标签
+			if (CollUtil.isNotEmpty(exists_tagIds) && exists_tagIds.contains(tag.getTagId())) {
+				exists_tagIds.remove(tag.getTagId());
+				return;
+			}
 			CorpUserTag corpUserTag = new CorpUserTag();
 			corpUserTag.setRelationId(relation.getId());
 			corpUserTag.setGroupName(tag.getGroupName());
@@ -603,6 +610,14 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 			corpUserTag.setType(tag.getType());
 			corpUserTagMapper.insert(corpUserTag);
 		});
+
+		//存在被删除的标签
+		if (CollUtil.isNotEmpty(exists_tagIds)) {
+			corpUserTagMapper.delete(Wrappers.lambdaQuery(CorpUserTag.class)
+					.in(CorpUserTag::getTagId, exists_tagIds)
+					.eq(CorpUserTag::getRelationId, relation.getId()));
+		}
+
 		//同步企业微信 银河用户id
 		Optional.ofNullable(corpUserMapper.setCorpUserUserId(relation.getCorpUserId()))
 				.ifPresent(corpUser -> {