|
|
@@ -1,10 +1,13 @@
|
|
|
package com.cyksj.service.corp.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
@@ -13,9 +16,7 @@ import com.cyksj.common.util.corp.WxCryptUtil;
|
|
|
import com.cyksj.config.corp.WeChatCorpFactory;
|
|
|
import com.cyksj.config.corp.YHLXWxCorpConfig;
|
|
|
import com.cyksj.dto.CorpOauth2UserInfo;
|
|
|
-import com.cyksj.mapper.corp.CorpCustomerAcquistionCallbackMapper;
|
|
|
-import com.cyksj.mapper.corp.CorpFollowMapper;
|
|
|
-import com.cyksj.mapper.corp.CorpUserPayIntentionMapper;
|
|
|
+import com.cyksj.mapper.corp.*;
|
|
|
import com.cyksj.model.dto.WxCorpEncryptDto;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.request.corp.Attachments;
|
|
|
@@ -43,6 +44,7 @@ import java.io.File;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
/*
|
|
|
*项目名: netflix
|
|
|
@@ -82,6 +84,15 @@ public class CorpServiceImpl implements CorpService {
|
|
|
@Autowired
|
|
|
private CorpUserPayIntentionMapper corpUserPayIntentionMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CorpUserMapper corpUserMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CorpUserTagMapper corpUserTagMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CorpUserFollowRelationMapper corpUserFollowRelationMapper;
|
|
|
+
|
|
|
@PostConstruct
|
|
|
private void init() {
|
|
|
corpMessageRouter = new CorpMessageRouter(this)
|
|
|
@@ -382,8 +393,59 @@ public class CorpServiceImpl implements CorpService {
|
|
|
corpUserPayIntentionMapper.insert(corpUserPayIntention);
|
|
|
} catch (DuplicateKeyException e) {
|
|
|
}
|
|
|
+ } else {
|
|
|
+ corpUserPayIntentionMapper.updateById(corpUserPayIntention);
|
|
|
+ }
|
|
|
+ //将所属意向标签组不属于该标签的全删除
|
|
|
+ //并打上对应标签
|
|
|
+ CorpUserPayIntention.Intention intention = CorpUserPayIntention.Intention.values()[corpUserPayIntention.getIntention()];
|
|
|
+ String tagName = intention.getTagName();
|
|
|
+ String tagId = intention.getTagId();
|
|
|
+
|
|
|
+ List<CorpUserTag> corpUserTags = corpUserTagMapper.selectIntentionUserTag(Constant.EP_INTENTION_GROUP_NAME);
|
|
|
+ //是否存在对应标签
|
|
|
+ AtomicBoolean isExistIntentionTag = new AtomicBoolean(false);
|
|
|
+ if (CollUtil.isNotEmpty(corpUserTags)) {
|
|
|
+ //删除之前的意向标签
|
|
|
+ corpUserTags.forEach(userTag -> {
|
|
|
+ if (!StrUtil.equals(userTag.getTagId(), tagId)) {
|
|
|
+ try {
|
|
|
+ wxCorpOps.markTag(userTag.getExternalUserId(), userTag.getFollowId(), null, new String[]{userTag.getTagId()});
|
|
|
+ corpUserTagMapper.deleteById(userTag.getId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (!isExistIntentionTag.get()) {
|
|
|
+ isExistIntentionTag.set(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!isExistIntentionTag.get()) {
|
|
|
+ insertUserIntentionTag(corpUserPayIntention, tagId, tagName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void insertUserIntentionTag(CorpUserPayIntention corpUserPayIntention, String tagId, String tagName) {
|
|
|
+ CorpUserFollowRelation corpUserFollowRelation = corpUserFollowRelationMapper.getCorpUserFollowRelation(corpUserPayIntention.getUnionId(), corpUserPayIntention.getFollowId());
|
|
|
+ if (corpUserFollowRelation == null) {
|
|
|
return;
|
|
|
}
|
|
|
- corpUserPayIntentionMapper.updateById(corpUserPayIntention);
|
|
|
+ String externalUserId = corpUserFollowRelation.getCorpUserId();
|
|
|
+ String followId = corpUserFollowRelation.getFollowId();
|
|
|
+ try {
|
|
|
+ wxCorpOps.markTag(externalUserId, followId, new String[]{tagId}, null);
|
|
|
+ //新增用户标签
|
|
|
+ CorpUserTag corpUserTag = new CorpUserTag();
|
|
|
+ corpUserTag.setRelationId(corpUserFollowRelation.getId());
|
|
|
+ corpUserTag.setGroupName(Constant.EP_INTENTION_GROUP_NAME);
|
|
|
+ corpUserTag.setTagId(tagId);
|
|
|
+ corpUserTag.setTagName(tagName);
|
|
|
+ corpUserTag.setType(1);
|
|
|
+ corpUserTagMapper.insert(corpUserTag);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("新增用户意向标签错误:{}", StringUtil.getErrorText(e));
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|