|
|
@@ -11,6 +11,7 @@ import com.fs.ad.enums.AdUploadType;
|
|
|
import com.fs.ad.service.IAdHtmlClickLogService;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.utils.PubFun;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.company.domain.Company;
|
|
|
@@ -36,6 +37,9 @@ import com.fs.his.utils.PhoneUtil;
|
|
|
import com.fs.hisStore.domain.FsUserInformationCollection;
|
|
|
import com.fs.hisStore.mapper.FsUserInformationCollectionMapper;
|
|
|
import com.fs.qw.domain.*;
|
|
|
+import com.fs.qw.dto.acquisition.AcquisitionBaseRequest;
|
|
|
+import com.fs.qw.dto.acquisition.AcquisitionRange;
|
|
|
+import com.fs.qw.dto.acquisition.AcquisitionUpdateResponse;
|
|
|
import com.fs.qw.mapper.*;
|
|
|
import com.fs.qw.param.*;
|
|
|
import com.fs.qw.param.newparam.ExternalContactPageListParam;
|
|
|
@@ -52,6 +56,7 @@ import com.fs.qw.vo.sidebar.ExternalContactInfoVO;
|
|
|
import com.fs.qw.vo.sidebar.ExternalContactQwUserVO;
|
|
|
import com.fs.qw.vo.sidebar.ExternalContactTagVO;
|
|
|
import com.fs.qwApi.Result.QwOpenidResult;
|
|
|
+import com.fs.qwApi.config.QwApiConfig;
|
|
|
import com.fs.qwApi.domain.*;
|
|
|
import com.fs.qwApi.domain.inner.*;
|
|
|
import com.fs.qwApi.param.*;
|
|
|
@@ -70,6 +75,7 @@ import com.fs.sop.service.ISopUserLogsService;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import com.fs.system.service.ISysDictTypeService;
|
|
|
import com.fs.voice.utils.StringUtil;
|
|
|
+import com.fs.wx.kf.vo.WeixinKfTokenVO;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.google.gson.Gson;
|
|
|
@@ -145,6 +151,9 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
|
|
|
@Autowired
|
|
|
QwFriendWelcomeMapper qwFriendWelcomeMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ QwAcquisitionAssistantMapper acquisitionAssistantMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
ISopUserLogsInfoService iSopUserLogsInfoService;
|
|
|
|
|
|
@@ -2279,69 +2288,6 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
|
|
|
|
|
|
QwExternalContact contact=qwExternalContact;
|
|
|
QwUser qwUser = qwUserMapper.selectQwUserByCorpIdAndUserId(corpId, userID);
|
|
|
-
|
|
|
- if (state != null && state != "") {
|
|
|
- String s = "way:" + corpId + ":";
|
|
|
- String userPhone = "up:";
|
|
|
- if (state.contains(s)) {
|
|
|
- if (welcomeCode != null && welcomeCode != "") {
|
|
|
- String substring = state.substring(state.indexOf(s) + s.length());
|
|
|
- QwContactWay qwContactWay = qwContactWayMapper.selectQwContactWayById(Long.parseLong(substring));
|
|
|
- logger.info("qwContactWay:"+qwContactWay);
|
|
|
- if (qwContactWay != null) {
|
|
|
- isWay = true;
|
|
|
- wayId = qwContactWay;
|
|
|
- if (qwContactWay.getIsWelcome() != null && qwContactWay.getIsWelcome() == 1) {
|
|
|
- Boolean isClose = true;
|
|
|
- if (wayId.getIsSpanWelcome() == 1) {
|
|
|
- ExternalContact externalContact = externalContactResult.getExternal_contact();
|
|
|
- String name = externalContact.getName();
|
|
|
- String closeWelcomeWord = wayId.getCloseWelcomeWord();
|
|
|
- if (closeWelcomeWord != null && closeWelcomeWord.length() > 0) {
|
|
|
- List<String> strings = JSON.parseArray(closeWelcomeWord, String.class);
|
|
|
- for (String string : strings) {
|
|
|
- if (name.contains(string)) {
|
|
|
- isClose = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (qwContactWay.getIsSpanWelcome() == 1 && isClose) {
|
|
|
- isSend = qwContactWayService.sendWelcomeMsg(qwContactWay, corpId, welcomeCode,qwUser,contact.getId());
|
|
|
- }
|
|
|
- }
|
|
|
- if (qwContactWay.getUserType() == 1 && qwContactWay.getIsUserLimit() == 1) {
|
|
|
- QwContactWayUser qwContactWayUser = qwContactWayUserMapper.selectQwContactWayUserByUserIdAndCompanyId(userID, corpId);
|
|
|
- if (qwContactWayUser != null) {
|
|
|
- qwContactWayUser.setDayCount(qwContactWayUser.getDayCount() - 1);
|
|
|
- qwContactWayUserMapper.updateQwContactWayUser(qwContactWayUser);
|
|
|
- if (qwContactWayUser.getDayCount() <= 0) {
|
|
|
- //超过限制
|
|
|
- qwContactWayService.updateQwContactWayBYLimit(qwContactWayUser.getWayId());
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (state.contains(userPhone)) {
|
|
|
- log.error("获客链接添加外部联系人小程序用户手机号");
|
|
|
- try {
|
|
|
- //获取手机号数据
|
|
|
- String phone = state.substring(state.indexOf(userPhone) + userPhone.length());
|
|
|
- //更新外部联系人小程序用户手机号数据
|
|
|
- QwExternalContact updateContact = new QwExternalContact();
|
|
|
- updateContact.setId(contact.getId());
|
|
|
- updateContact.setFsUserPhone(phone);
|
|
|
- qwExternalContactMapper.updateQwExternalContact(updateContact);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("获客链接添加外部联系人小程序用户手机号失败,错误信息:{}",e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
log.error("欢迎语====>isSend:{},welcomeCode:{}",isSend,welcomeCode);
|
|
|
if (isSend && welcomeCode != null && welcomeCode != "") {
|
|
|
if (qwUser != null) {
|
|
|
@@ -2440,6 +2386,172 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ logger.info("渠道活码的参数---:"+state);
|
|
|
+
|
|
|
+ if (state != null && state != "") {
|
|
|
+ String s = "way:" + corpId + ":";
|
|
|
+ String userPhone = "up:";
|
|
|
+ String linkState = "link:";
|
|
|
+ if (state.contains(s)) {
|
|
|
+ if (welcomeCode != null && welcomeCode != "") {
|
|
|
+ String substring = state.substring(state.indexOf(s) + s.length());
|
|
|
+ QwContactWay qwContactWay = qwContactWayMapper.selectQwContactWayById(Long.parseLong(substring));
|
|
|
+ logger.info("qwContactWay:"+qwContactWay);
|
|
|
+ if (qwContactWay != null) {
|
|
|
+ isWay = true;
|
|
|
+ wayId = qwContactWay;
|
|
|
+ if (qwContactWay.getIsWelcome() != null && qwContactWay.getIsWelcome() == 1) {
|
|
|
+ Boolean isClose = true;
|
|
|
+ if (wayId.getIsSpanWelcome() == 1) {
|
|
|
+ ExternalContact externalContact = externalContactResult.getExternal_contact();
|
|
|
+ String name = externalContact.getName();
|
|
|
+ String closeWelcomeWord = wayId.getCloseWelcomeWord();
|
|
|
+ if (closeWelcomeWord != null && closeWelcomeWord.length() > 0) {
|
|
|
+ List<String> strings = JSON.parseArray(closeWelcomeWord, String.class);
|
|
|
+ for (String string : strings) {
|
|
|
+ if (name.contains(string)) {
|
|
|
+ isClose = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (qwContactWay.getIsSpanWelcome() == 1 && isClose) {
|
|
|
+ isSend = qwContactWayService.sendWelcomeMsg(qwContactWay, corpId, welcomeCode,qwUser,contact.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (qwContactWay.getUserType() == 1 && qwContactWay.getIsUserLimit() == 1) {
|
|
|
+ QwContactWayUser qwContactWayUser = qwContactWayUserMapper.selectQwContactWayUserByUserIdAndCompanyId(userID, corpId);
|
|
|
+ if (qwContactWayUser != null) {
|
|
|
+ qwContactWayUser.setDayCount(qwContactWayUser.getDayCount() - 1);
|
|
|
+ qwContactWayUserMapper.updateQwContactWayUser(qwContactWayUser);
|
|
|
+ if (qwContactWayUser.getDayCount() <= 0) {
|
|
|
+ //超过限制
|
|
|
+ qwContactWayService.updateQwContactWayBYLimit(qwContactWayUser.getWayId());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (state.contains(userPhone)) {
|
|
|
+ log.error("获客链接添加外部联系人小程序用户手机号");
|
|
|
+ try {
|
|
|
+ //获取手机号数据
|
|
|
+ String phone = state.substring(state.indexOf(userPhone) + userPhone.length());
|
|
|
+ //更新外部联系人小程序用户手机号数据
|
|
|
+ QwExternalContact updateContact = new QwExternalContact();
|
|
|
+ updateContact.setId(contact.getId());
|
|
|
+ updateContact.setFsUserPhone(phone);
|
|
|
+ qwExternalContactMapper.updateQwExternalContact(updateContact);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获客链接添加外部联系人小程序用户手机号失败,错误信息:{}",e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (state.contains(linkState)){
|
|
|
+ try {
|
|
|
+ log.info("获客链接添加外部联系人");
|
|
|
+ String linkId = state.substring(state.indexOf(linkState) + linkState.length());
|
|
|
+ QwAcquisitionAssistant qwAcquisitionAssistant = acquisitionAssistantMapper.selectQwAcquisitionAssistantById(Long.valueOf(linkId));
|
|
|
+
|
|
|
+ if (qwAcquisitionAssistant != null && StringUtils.isNotBlank(qwAcquisitionAssistant.getUserLimitJson())) {
|
|
|
+ try {
|
|
|
+ String cacheKey = "qwAcquisition:" + corpId + ":" + linkId + ":" + userID;
|
|
|
+
|
|
|
+ com.alibaba.fastjson.JSONArray userLimitArray = com.alibaba.fastjson.JSON.parseArray(qwAcquisitionAssistant.getUserLimitJson());
|
|
|
+ for (int i = 0; i < userLimitArray.size(); i++) {
|
|
|
+ com.alibaba.fastjson.JSONObject userLimit = userLimitArray.getJSONObject(i);
|
|
|
+ String limitUserId = userLimit.getString("userId");
|
|
|
+ Integer limitCount = userLimit.getInteger("limitCount");
|
|
|
+ Integer qwUserId = userLimit.getInteger("qwUserId");
|
|
|
+
|
|
|
+ if (userID.equals(limitUserId)) {
|
|
|
+ Long currentCount = redisTemplate.opsForValue().increment(cacheKey, 1);
|
|
|
+
|
|
|
+ if (currentCount == null) {
|
|
|
+ currentCount = 1L;
|
|
|
+ }
|
|
|
+
|
|
|
+ long expireSeconds = getSecondsUntilMidnight();
|
|
|
+ redisTemplate.expire(cacheKey, expireSeconds, java.util.concurrent.TimeUnit.SECONDS);
|
|
|
+
|
|
|
+ if (currentCount >= limitCount) {
|
|
|
+ log.error("用户{}已达到每日添加上限{}/{}", userID, currentCount, limitCount);
|
|
|
+
|
|
|
+// redisTemplate.delete(cacheKey);
|
|
|
+
|
|
|
+ List<String> currentUserList = com.alibaba.fastjson.JSON.parseArray(qwAcquisitionAssistant.getUserList(), String.class);
|
|
|
+ if (currentUserList == null && StringUtils.isNotBlank(qwAcquisitionAssistant.getUserList())) {
|
|
|
+ currentUserList = com.alibaba.fastjson.JSON.parseArray(qwAcquisitionAssistant.getUserList(), String.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> currentQwUserTableIdList = null;
|
|
|
+ if (StringUtils.isNotBlank(qwAcquisitionAssistant.getQwUserTableIdList())) {
|
|
|
+ currentQwUserTableIdList = com.alibaba.fastjson.JSON.parseArray(qwAcquisitionAssistant.getQwUserTableIdList(), Long.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean needUpdate = false;
|
|
|
+
|
|
|
+ if (currentUserList != null && currentUserList.contains(userID)) {
|
|
|
+ currentUserList.remove(userID);
|
|
|
+ qwAcquisitionAssistant.setUserList(com.alibaba.fastjson.JSON.toJSONString(currentUserList));
|
|
|
+ needUpdate = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (currentQwUserTableIdList != null && currentQwUserTableIdList.contains(Long.valueOf(qwUserId))) {
|
|
|
+ currentQwUserTableIdList.remove(Long.valueOf(qwUserId));
|
|
|
+ qwAcquisitionAssistant.setQwUserTableIdList(com.alibaba.fastjson.JSON.toJSONString(currentQwUserTableIdList));
|
|
|
+ needUpdate = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 构建请求
|
|
|
+ QwLinkCreateParam linkCreateParam=new QwLinkCreateParam();
|
|
|
+ linkCreateParam.setLink_id(qwAcquisitionAssistant.getLinkId());
|
|
|
+
|
|
|
+ QwLinkCreateParam.Range range=new QwLinkCreateParam.Range();
|
|
|
+// range.setUser_list(currentUserList);
|
|
|
+ range.setUser_list(JSON.parseArray(qwAcquisitionAssistant.getUserList(), String.class));
|
|
|
+ linkCreateParam.setRange(range);
|
|
|
+
|
|
|
+ //调用企微API
|
|
|
+ QwResult qwResult = qwApiService.linkUpdate(linkCreateParam, corpId);
|
|
|
+ if (qwResult.getErrcode() == 0) {
|
|
|
+ if (needUpdate) {
|
|
|
+ acquisitionAssistantMapper.updateQwAcquisitionAssistant(qwAcquisitionAssistant);
|
|
|
+ log.info("已从获客链接{}的可用列表中移除用户{}", linkId, userID);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ logger.error("修改渠道活码 失败!"+linkCreateParam+":"+qwResult.getErrmsg());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+ log.info("用户{}今日已添加客户数:{}/{}", userID, currentCount, limitCount);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("处理获客链接用户限额失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("处理获客链接用户限额失败", e);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
ExternalContact externalContact = externalContactResult.getExternal_contact();
|
|
|
List<FollowUser> followUsers = externalContactResult.getFollow_user();
|
|
|
logger.info("外部联系人的情况里面0:"+userID+":"+externalUserID+":"+followUsers+":"+externalContactResult.getErrmsg());
|
|
|
@@ -2813,6 +2925,14 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private long getSecondsUntilMidnight() {
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ LocalDateTime midnight = now.toLocalDate().plusDays(1).atStartOfDay();
|
|
|
+ return java.time.Duration.between(now, midnight).getSeconds();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public void checkHaveQwSop(Set<String> combinedTagsSet,QwUser qwUser,String corpId,List<String> combinedTagsList,
|
|
|
String userID,String externalUserID,ExternalContact externalContact,QwExternalContact contact,
|
|
|
LocalDate currentDate, LocalTime localTime){
|