|
|
@@ -1,14 +1,11 @@
|
|
|
package com.fs.app.service;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.fs.common.constant.Constants;
|
|
|
-import com.fs.common.constant.FsConstants;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.core.redis.RedisCacheT;
|
|
|
import com.fs.common.utils.PubFun;
|
|
|
@@ -19,7 +16,7 @@ import com.fs.company.param.ExecutionContext;
|
|
|
import com.fs.company.service.*;
|
|
|
import com.fs.company.service.impl.*;
|
|
|
import com.fs.company.service.impl.call.node.AiAddWxTaskNode;
|
|
|
-import com.fs.company.service.impl.call.node.AiCallTaskNode;
|
|
|
+import com.fs.company.service.impl.call.node.AiQwAddWxTaskNode;
|
|
|
import com.fs.company.service.impl.call.node.WorkflowNodeFactory;
|
|
|
import com.fs.company.vo.CompanyWxClient4WorkFlowVO;
|
|
|
import com.fs.course.config.RedisKeyScanner;
|
|
|
@@ -39,19 +36,18 @@ import com.fs.wxcid.dto.friend.AddContactParam;
|
|
|
import com.fs.wxcid.service.FriendService;
|
|
|
import com.fs.wxcid.vo.AddContactVo;
|
|
|
import com.fs.wxwork.dto.WxAddSearchDTO;
|
|
|
-import com.fs.wxwork.dto.WxSearchContactDTO;
|
|
|
-import com.fs.wxwork.dto.WxSearchContactResp;
|
|
|
import com.fs.wxwork.dto.WxWorkResponseDTO;
|
|
|
import com.fs.wxwork.service.WxWorkService;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.redisson.api.RLock;
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
@@ -62,9 +58,13 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-@AllArgsConstructor
|
|
|
+@RequiredArgsConstructor
|
|
|
public class WxTaskService {
|
|
|
|
|
|
+
|
|
|
+ @Value("${cid-group-no:0}")
|
|
|
+ private Integer cidGroupNo;
|
|
|
+
|
|
|
private final ICompanyWxAccountService companyWxAccountService;
|
|
|
private final ISysConfigService sysConfigService;
|
|
|
private final ICompanyWxClientService companyWxClientService;
|
|
|
@@ -102,6 +102,7 @@ public class WxTaskService {
|
|
|
private final QwUserMapper qwUserMapper;
|
|
|
private final WxWorkService wxWorkService;
|
|
|
private final QwExternalContactMapper qwExternalContactMapper;
|
|
|
+ private final CompanyAiWorkflowExecLogMapper companyAiWorkflowExecLogMapper;
|
|
|
|
|
|
public void addWx(List<Long> accountIdList) {
|
|
|
log.info("==========执行加微信任务开始==========");
|
|
|
@@ -110,7 +111,7 @@ public class WxTaskService {
|
|
|
// 需要添加微信的列表
|
|
|
List<CompanyWxClient> list = companyWxClientService.getAddWxList(accountIdList,1);
|
|
|
//排除掉没到达加微步骤的人
|
|
|
- List<CompanyVoiceRoboticCallees> exList = companyVoiceRoboticCalleesMapper.selectExcludeList(list);
|
|
|
+ List<CompanyVoiceRoboticCallees> exList = companyVoiceRoboticCalleesMapper.selectExcludeList(list, 1);
|
|
|
List<CompanyVoiceRoboticCallees> collect =
|
|
|
exList.stream().filter(e -> !Constants.ADD_WX.equals(getNextTaskOptimized(e.getTaskFlow(), e.getRunTaskFlow())))
|
|
|
.collect(Collectors.toList());
|
|
|
@@ -295,7 +296,7 @@ public class WxTaskService {
|
|
|
if (vo.isSuccess()) {
|
|
|
e.setLastAddWxTime(LocalDateTime.now());
|
|
|
// todo 删除还原 以下为测试所用
|
|
|
-// e.setLastAddWxTime(LocalDateTime.now().plus(-1, ChronoUnit.DAYS));
|
|
|
+ e.setLastAddWxTime(LocalDateTime.now().plus(-1, ChronoUnit.DAYS));
|
|
|
e.setIsAddNum(e.getIsAddNum() + 1);
|
|
|
client.setIsAdd(2);
|
|
|
client.setAddTime(LocalDateTime.now());
|
|
|
@@ -826,7 +827,7 @@ public class WxTaskService {
|
|
|
*/
|
|
|
public void cidWorkflowAddWxRun() {
|
|
|
log.info("===========工作流延时任务开始扫描===========");
|
|
|
- String delayAddWxKeyPrefix = AiAddWxTaskNode.getDelayAddWxKeyPrefix(null) + "*";
|
|
|
+ String delayAddWxKeyPrefix = AiAddWxTaskNode.getDelayAddWxKeyPrefix(cidGroupNo,null) + "*";
|
|
|
Set<String> keys = redisKeyScanner.scanMatchKey(delayAddWxKeyPrefix);
|
|
|
log.info("共扫描到 {} 个待处理键", keys.size());
|
|
|
keys.parallelStream().forEach(key -> {
|
|
|
@@ -924,7 +925,38 @@ public class WxTaskService {
|
|
|
log.info("==========执行企微申请加个微结果查询任务结束==========");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 扫描企微加微工作流延时任务
|
|
|
+ */
|
|
|
+ public void cidWorkflowQwAddWxRun() {
|
|
|
+ log.info("===========企微加微工作流延时任务开始扫描===========");
|
|
|
+ String delayAddWxKeyPrefix = AiQwAddWxTaskNode.getDelayAddWxKeyPrefix(cidGroupNo,null) + "*";
|
|
|
+ Set<String> keys = redisKeyScanner.scanMatchKey(delayAddWxKeyPrefix);
|
|
|
+ log.info("企微加微共扫描到 {} 个待处理键", keys.size());
|
|
|
+ keys.parallelStream().forEach(key -> {
|
|
|
+ try {
|
|
|
+ //doExec
|
|
|
+ CompletableFuture.runAsync(()->{
|
|
|
+ try {
|
|
|
+ ExecutionContext context = redisCache2.getCacheObject(key);
|
|
|
+ context.setVariable("callRedisKey",key);
|
|
|
+ context.setVariable("callSource","qwAddWxTimer");
|
|
|
+ companyWorkflowEngine.timeDoExecute(context.getWorkflowInstanceId(),context.getCurrentNodeKey(),context.getVariables());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("处理工作流延时任务异常 - key: {}", key, e);
|
|
|
+ }
|
|
|
+ }, cidExcutor).thenRun(()->{
|
|
|
+ redisCache2.deleteObject(key);
|
|
|
+ });
|
|
|
+
|
|
|
+ } catch (Exception ex) {
|
|
|
+ log.error("处理工作流延时任务异常 - key: {}", key, ex);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ log.info("===========工作流延时任务扫描结束===========");
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取过滤后的企微客户列表
|
|
|
*/
|
|
|
@@ -932,7 +964,7 @@ public class WxTaskService {
|
|
|
List<CompanyWxClient> list = companyWxClientService.getAddWxList(accountIdList, 2);
|
|
|
|
|
|
// 排除掉没到达加微步骤的人
|
|
|
- List<CompanyVoiceRoboticCallees> excludeList = companyVoiceRoboticCalleesMapper.selectExcludeList(list);
|
|
|
+ List<CompanyVoiceRoboticCallees> excludeList = companyVoiceRoboticCalleesMapper.selectExcludeList(list,2);
|
|
|
Set<String> excludeKeys = excludeList.stream()
|
|
|
.filter(e -> !Constants.QW_ADD_WX.equals(getNextTaskOptimized(e.getTaskFlow(), e.getRunTaskFlow())))
|
|
|
.map(callee -> callee.getRoboticId() + "_" + callee.getUserId())
|