|
@@ -408,6 +408,9 @@ public class WeComUserServiceImpl implements WeComUserService {
|
|
|
}
|
|
|
|
|
|
private boolean addWeComTag(Tag tag, WeComUser weComUser) {
|
|
|
+ if (tag == null || weComUser == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
try {
|
|
|
String accessToken = weComAccessTokenService.getWeComAccessToken(weComUser.getCorpId());
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
@@ -436,10 +439,17 @@ public class WeComUserServiceImpl implements WeComUserService {
|
|
|
public boolean addUserWithTag(UserWithTag userWithTag) {
|
|
|
try {
|
|
|
UserWithTagExample userWithTagExample = new UserWithTagExample();
|
|
|
- userWithTagExample.createCriteria().andUserIdEqualTo(userWithTag.getUserId()).andTagIdEqualTo(userWithTag.getTagId());
|
|
|
- long l = userWithTagMapper.countByExample(userWithTagExample);
|
|
|
- if (l == 0) {
|
|
|
+ userWithTagExample.createCriteria().andUserIdEqualTo(userWithTag.getUserId())
|
|
|
+ .andTagIdEqualTo(userWithTag.getTagId());
|
|
|
+ List<UserWithTag> userWithTags = userWithTagMapper.selectByExample(userWithTagExample);
|
|
|
+ if (CollectionUtils.isEmpty(userWithTags)) {
|
|
|
userWithTagMapper.insertSelective(userWithTag);
|
|
|
+ } else {
|
|
|
+ UserWithTag userWithTag1 = userWithTags.get(0);
|
|
|
+ if (userWithTag1.getIsDelete() == 1) {
|
|
|
+ userWithTag1.setIsDelete(0);
|
|
|
+ userWithTagMapper.updateByPrimaryKeySelective(userWithTag1);
|
|
|
+ }
|
|
|
}
|
|
|
return true;
|
|
|
} catch (Exception e) {
|
|
@@ -447,4 +457,58 @@ public class WeComUserServiceImpl implements WeComUserService {
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ public boolean delAllUserTag(Long userId) {
|
|
|
+ try {
|
|
|
+ UserWithTagExample userWithTagExample = new UserWithTagExample();
|
|
|
+ userWithTagExample.createCriteria().andUserIdEqualTo(userId).andStatusEqualTo(1);
|
|
|
+ UserWithTag record = new UserWithTag();
|
|
|
+ record.setIsDelete(1);
|
|
|
+ userWithTagMapper.updateByExampleSelective(record, userWithTagExample);
|
|
|
+ return true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("addUserWithTag error", e);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateUserWithTag(Long userId, List<String> tagIdList) {
|
|
|
+ try {
|
|
|
+ TagExample example = new TagExample();
|
|
|
+ example.createCriteria().andTagIdIn(tagIdList).andIsDeleteEqualTo(0);
|
|
|
+ List<Tag> tags = tagMapper.selectByExample(example);
|
|
|
+ List<Long> tagIds = tags.stream().map(Tag::getId).collect(Collectors.toList());
|
|
|
+ UserWithTagExample userWithTagExample = new UserWithTagExample();
|
|
|
+ userWithTagExample.createCriteria().andUserIdEqualTo(userId).andIsDeleteEqualTo(0);
|
|
|
+ List<UserWithTag> userWithTags = userWithTagMapper.selectByExample(userWithTagExample);
|
|
|
+ List<Long> userTagIds = userWithTags.stream().map(UserWithTag::getTagId).collect(Collectors.toList());
|
|
|
+ userTagIds.removeAll(tagIds);
|
|
|
+ if (!CollectionUtils.isEmpty(userTagIds)) {
|
|
|
+ List<UserWithTag> collect = userWithTags.stream()
|
|
|
+ .filter(f -> userTagIds.contains(f.getTagId())).collect(Collectors.toList());
|
|
|
+ for (UserWithTag userWithTag : collect) {
|
|
|
+ if (userWithTag.getStatus() == 2) {
|
|
|
+ WeComUser weComUser = weComUserMapper.selectByPrimaryKey(userWithTag.getUserId());
|
|
|
+ Tag tag = tagMapper.selectByPrimaryKey(userWithTag.getTagId());
|
|
|
+ addWeComTag(tag, weComUser);
|
|
|
+ } else {
|
|
|
+ userWithTag.setIsDelete(1);
|
|
|
+ userWithTagMapper.updateByPrimaryKeySelective(userWithTag);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Long> hasUserTagIds = userWithTags.stream().map(UserWithTag::getTagId).collect(Collectors.toList());
|
|
|
+ tagIds.removeAll(hasUserTagIds);
|
|
|
+ if (!CollectionUtils.isEmpty(tagIds)) {
|
|
|
+ for (Long tagId : tagIds) {
|
|
|
+ UserWithTag userWithTag = new UserWithTag();
|
|
|
+ userWithTag.setTagId(tagId);
|
|
|
+ userWithTag.setUserId(userId);
|
|
|
+ addUserWithTag(userWithTag);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("updateUserWithTag error", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|