|
|
@@ -2,13 +2,18 @@ package com.fs.his.task;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.http.HttpException;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import com.fs.common.core.domain.R;
|
|
|
+import com.fs.FSApplication;
|
|
|
+import com.fs.common.config.RedisTenantContext;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
+import com.fs.common.core.redis.RedisCacheTenant;
|
|
|
+import com.fs.common.exception.base.BaseException;
|
|
|
import com.fs.common.service.impl.SmsServiceImpl;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.SecurityUtils;
|
|
|
@@ -20,6 +25,7 @@ import com.fs.company.service.ICompanyService;
|
|
|
import com.fs.company.service.ICompanyUserService;
|
|
|
import com.fs.company.vo.QwIpadTotalVo;
|
|
|
import com.fs.company.vo.RedPacketMoneyVO;
|
|
|
+import com.fs.core.config.TenantConfigContext;
|
|
|
import com.fs.course.dto.BatchSendCourseAllDTO;
|
|
|
import com.fs.course.mapper.FsCourseRedPacketLogMapper;
|
|
|
import com.fs.course.service.IFsCourseWatchLogService;
|
|
|
@@ -33,6 +39,7 @@ import com.fs.fastGpt.domain.*;
|
|
|
import com.fs.fastGpt.mapper.FastGptChatSessionMapper;
|
|
|
import com.fs.fastGpt.mapper.FastgptChatVoiceHomoMapper;
|
|
|
import com.fs.fastGpt.service.AiHookService;
|
|
|
+import com.fs.fastGpt.service.IFastGptChatMsgService;
|
|
|
import com.fs.fastGpt.service.IFastgptEventLogTotalService;
|
|
|
import com.fs.framework.task.TenantTaskRunner;
|
|
|
import com.fs.fastgptApi.util.AudioUtils;
|
|
|
@@ -60,24 +67,35 @@ import com.fs.huifuPay.service.HuiFuService;
|
|
|
import com.fs.im.dto.*;
|
|
|
import com.fs.im.service.IImService;
|
|
|
import com.fs.im.service.OpenIMService;
|
|
|
+import com.fs.ipad.IpadSendUtils;
|
|
|
+import com.fs.ipad.vo.*;
|
|
|
import com.fs.qw.domain.QwCompany;
|
|
|
+import com.fs.qw.domain.QwExternalContact;
|
|
|
import com.fs.qw.domain.QwUser;
|
|
|
import com.fs.qw.mapper.QwRestrictionPushRecordMapper;
|
|
|
import com.fs.qw.mapper.QwUserMapper;
|
|
|
+import com.fs.qw.param.QwExternalContactAddTagParam;
|
|
|
+import com.fs.qw.param.QwExternalContactParam;
|
|
|
import com.fs.qw.service.*;
|
|
|
+import com.fs.qwApi.config.OpenQwConfig;
|
|
|
import com.fs.sop.domain.QwSopTempVoice;
|
|
|
import com.fs.sop.service.IQwSopTempVoiceService;
|
|
|
import com.fs.system.domain.SysConfig;
|
|
|
import com.fs.system.mapper.SysConfigMapper;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import com.fs.utils.OrderContextHolder;
|
|
|
+import com.fs.wxwork.dto.*;
|
|
|
+import com.fs.wxwork.service.WxWorkService;
|
|
|
+import com.fs.wxwork.service.WxWorkServiceNew;
|
|
|
import com.google.gson.Gson;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
@@ -85,11 +103,15 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.Consumer;
|
|
|
+import java.util.function.Supplier;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@@ -239,6 +261,10 @@ public class Task {
|
|
|
|
|
|
@Autowired
|
|
|
private IFsStoreOrderScrmService orderScrmService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IQwExternalContactService qwExternalContactService;
|
|
|
+
|
|
|
/**
|
|
|
* 定时任务,处理ai禁止回复之后的消息
|
|
|
*/
|
|
|
@@ -275,6 +301,316 @@ public class Task {
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
+ @Scheduled(cron = "0 0/5 * * * ?")
|
|
|
+ public void addTagByQwExtCreateTimeNew() {
|
|
|
+ if (saasTaskEnabled) {
|
|
|
+ tenantTaskRunner.runForEachTenant("addTagByQwExtCreateTime", this::addTagByQwExtCreateTime);
|
|
|
+ } else {
|
|
|
+ addTagByQwExtCreateTime();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 最美叙酱给客户打标签(其他客户关闭,临时用)
|
|
|
+ */
|
|
|
+ public void addTagByQwExtCreateTime() {
|
|
|
+ try {
|
|
|
+ Long tenantId = RedisTenantContext.getTenantId();
|
|
|
+ if(41L != tenantId) return;
|
|
|
+ QwExternalContact qwExternalContact = new QwExternalContact();
|
|
|
+ qwExternalContact.setIsReply(1);
|
|
|
+ qwExternalContact.setTagIds("etotXidAAAMrYqb-nEijbTYQs4PJDbLg");
|
|
|
+ List<QwExternalContact> qwExternalContacts = qwExternalContactService.selectQwExternalContactListBycreateTime(qwExternalContact);
|
|
|
+ if(qwExternalContacts.isEmpty()) return;
|
|
|
+ Date now = new Date();
|
|
|
+ Date oneHourAgo = new Date(now.getTime() - 10 * 60 * 60 * 1000);
|
|
|
+
|
|
|
+ List<QwExternalContact> filteredContacts = qwExternalContacts.stream()
|
|
|
+ .filter(contact -> {
|
|
|
+ if (contact.getCreateTime() == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return contact.getCreateTime().before(oneHourAgo);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (filteredContacts.isEmpty()) {
|
|
|
+ log.info("过滤后没有创建时间超过10小时的联系人");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (QwExternalContact qwExt : filteredContacts) {
|
|
|
+
|
|
|
+ QwExternalContactAddTagParam param = new QwExternalContactAddTagParam();
|
|
|
+ Long qwUserId = qwExt.getQwUserId();
|
|
|
+ if(qwUserId == null) continue;
|
|
|
+ QwUser user = qwUserService.selectQwUserById(qwUserId);
|
|
|
+
|
|
|
+
|
|
|
+ //添加需要打标签的客户
|
|
|
+ List<Long> list = new ArrayList<>();
|
|
|
+ list.add(qwExt.getId());
|
|
|
+ param.setUserIds(list);
|
|
|
+
|
|
|
+ try {
|
|
|
+ String[] split = new String[]{"etotXidAAAwBK56Zp4OmU71zH8NqlA6Q"};
|
|
|
+ param.setTagIds(Arrays.asList(split));
|
|
|
+ param.setCorpId(user.getCorpId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("标签格式错误,租户41,外部联系人id:" + qwExt.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ String url = OpenQwConfig.baseApi + "/addTag?tenantId=41";
|
|
|
+ String result = HttpUtil.createPost(url)
|
|
|
+ .body(JSON.toJSONString(param))
|
|
|
+ .execute()
|
|
|
+ .body();
|
|
|
+ System.out.println(result);
|
|
|
+ }
|
|
|
+ } catch (HttpException e) {
|
|
|
+ System.out.println("请求异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 0/1 * * * ?")
|
|
|
+ public void sendMsgByQwExtCreateTimeNew() {
|
|
|
+ if (saasTaskEnabled) {
|
|
|
+ tenantTaskRunner.runForEachTenant("sendMsgByQwExtCreateTime", this::sendMsgByQwExtCreateTime);
|
|
|
+ } else {
|
|
|
+ sendMsgByQwExtCreateTime();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ WxWorkServiceNew wxWorkService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RedisCacheTenant<Long> redisCacheLong;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFastGptChatMsgService fastGptChatMsgService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IpadSendUtils ipadSendUtils;
|
|
|
+
|
|
|
+ public void sendMsgByQwExtCreateTime() {
|
|
|
+ Long tenantId = RedisTenantContext.getTenantId();
|
|
|
+ if(41L != tenantId) return;
|
|
|
+ QwExternalContact qwExternalContact = new QwExternalContact();
|
|
|
+ qwExternalContact.setTagIds("etotXidAAAcNhR-YuTMgC9B2VxH9QU3g");
|
|
|
+ qwExternalContact.setCreateTime(new Date());
|
|
|
+ List<QwExternalContact> qwExternalContacts = qwExternalContactService.selectQwExternalContactListByCreateTimeNew(qwExternalContact);
|
|
|
+ if(qwExternalContacts.isEmpty()) return;
|
|
|
+ Date now = new Date();
|
|
|
+ Date oneHourAgo = new Date(now.getTime() - 2 * 60 * 1000);
|
|
|
+ List<QwExternalContact> filteredContacts = qwExternalContacts.stream()
|
|
|
+ .filter(contact -> {
|
|
|
+ if (contact.getCreateTime() == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return contact.getCreateTime().before(oneHourAgo);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (QwExternalContact qwExt : filteredContacts) {
|
|
|
+
|
|
|
+ QwExternalContactAddTagParam param = new QwExternalContactAddTagParam();
|
|
|
+ Long qwUserId = qwExt.getQwUserId();
|
|
|
+ if(qwUserId == null) continue;
|
|
|
+ QwUser user = qwUserService.selectQwUserById(qwUserId);
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(user.getCorpId());
|
|
|
+
|
|
|
+
|
|
|
+ FastGptChatSession fastGptChatSession = fastGptChatSessionMapper.selectFastGptChatSessionByQwExternalContactsAndUserId(qwExt.getId(), qwUserId);
|
|
|
+ if(fastGptChatSession == null){
|
|
|
+ if(qwExt.getType()!=null&&qwExt.getType()==1){
|
|
|
+ fastGptChatSession = new FastGptChatSession();
|
|
|
+ String chatId = UUID.randomUUID().toString();
|
|
|
+ fastGptChatSession.setChatId(chatId);
|
|
|
+ if(user.getFastGptRoleId() != null){
|
|
|
+ fastGptChatSession.setKfId(user.getFastGptRoleId().toString());
|
|
|
+ }
|
|
|
+ fastGptChatSession.setStatus(1);
|
|
|
+ fastGptChatSession.setRemindCount(0);
|
|
|
+ fastGptChatSession.setRemindStatus(0);
|
|
|
+ fastGptChatSession.setCreateTime(new Date());
|
|
|
+ fastGptChatSession.setQwExtId(qwExt.getId());
|
|
|
+ fastGptChatSession.setQwUserId(user.getId());
|
|
|
+ fastGptChatSession.setIsArtificial(0);
|
|
|
+ fastGptChatSession.setAvatar(qwExt.getAvatar());
|
|
|
+ fastGptChatSession.setNickName(qwExt.getName());
|
|
|
+ fastGptChatSession.setCompanyId(user.getCompanyId());
|
|
|
+ fastGptChatSession.setLastTime(new Date());
|
|
|
+ fastGptChatSession.setIsReply(0);
|
|
|
+ fastGptChatSessionMapper.insertFastGptChatSession(fastGptChatSession);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ BaseVo parentVo = new BaseVo();
|
|
|
+ assert fastGptChatSession != null;
|
|
|
+ if(fastGptChatSession.getSessionId() == null){
|
|
|
+ parentVo.setId(user.getId());
|
|
|
+ }else{
|
|
|
+ parentVo.setId(fastGptChatSession.getSessionId());
|
|
|
+ }
|
|
|
+ parentVo.setRoom(false);
|
|
|
+ parentVo.setUuid(user.getUid());
|
|
|
+ parentVo.setAgentId(qwCompany.getServerAgentId());
|
|
|
+ parentVo.setExId(qwExt.getExternalUserId());
|
|
|
+ parentVo.setServerId(user.getServerId());
|
|
|
+ parentVo.setCorpCode(parentVo.getCorpCode());
|
|
|
+ parentVo.setCorpId(parentVo.getCorpId());
|
|
|
+ parentVo.setQwUserId(user.getId());
|
|
|
+
|
|
|
+
|
|
|
+ FileVo voiceVo;
|
|
|
+ CompanyUser companyUser = companyUserMapper.selectCompanyUserById(user.getCompanyUserId());
|
|
|
+ if(companyUser == null) continue;
|
|
|
+ if("0".equals(companyUser.getSex())){
|
|
|
+ voiceVo = FileVo.builder()
|
|
|
+ .url("https://kyt-1323137866.cos.ap-chongqing.myqcloud.com/test/1.silk")
|
|
|
+ .voiceTime(36)
|
|
|
+ .build();
|
|
|
+ }else{
|
|
|
+ voiceVo = FileVo.builder()
|
|
|
+ .url("https://kyt-1323137866.cos.ap-chongqing.myqcloud.com/test/2.silk")
|
|
|
+ .voiceTime(32)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ voiceVo.setBase(parentVo);
|
|
|
+ ipadSendUtils.sendVoice(voiceVo);
|
|
|
+
|
|
|
+ String content = "本次免费领取活动真实有效,明天上午十点您准时来直播间观看并免费领取。明天开播前我会把直播链接发给您,看完直播第一时间找我登记领取,好吧哥!";
|
|
|
+ TxtVo txtVo = TxtVo.builder().content(content).build();
|
|
|
+ txtVo.setBase(parentVo);
|
|
|
+ saveQwUserMsg(fastGptChatSession,1,content,user);
|
|
|
+ ipadSendUtils.sendTxt(txtVo);
|
|
|
+
|
|
|
+ FileVo imgVo = FileVo.builder().url("https://ylrz-1323137866.cos.ap-chongqing.myqcloud.com/ylrz/20260528/eb81adca120a45dcbf7ae31e3daacd74.png").build();
|
|
|
+ imgVo.setBase(parentVo);
|
|
|
+ ipadSendUtils.sendImg(imgVo);
|
|
|
+
|
|
|
+ FileVo imgVo1 = FileVo.builder().url("https://ysy-1329817240.cos.ap-guangzhou.myqcloud.com/ysy/20260527/1ee711bf934642cba3886a5f07ac3cdd.png").build();
|
|
|
+ imgVo1.setBase(parentVo);
|
|
|
+ ipadSendUtils.sendImg(imgVo1);
|
|
|
+
|
|
|
+
|
|
|
+ //添加需要打标签的客户
|
|
|
+ List<Long> list = new ArrayList<>();
|
|
|
+ list.add(qwExt.getId());
|
|
|
+ param.setUserIds(list);
|
|
|
+
|
|
|
+ try {
|
|
|
+ String[] split = new String[]{"etotXidAAAcNhR-YuTMgC9B2VxH9QU3g"};
|
|
|
+ param.setTagIds(Arrays.asList(split));
|
|
|
+ param.setCorpId(user.getCorpId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("标签格式错误,租户41,外部联系人id:" + qwExt.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ String url = OpenQwConfig.baseApi + "/delTag?tenantId=41";
|
|
|
+ String result = HttpUtil.createPost(url)
|
|
|
+ .body(JSON.toJSONString(param))
|
|
|
+ .execute()
|
|
|
+ .body();
|
|
|
+ System.out.println(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 10 9 * * ?")
|
|
|
+ public void sendMsgByQwExtCreateTimeTwoDayNew() {
|
|
|
+ if (saasTaskEnabled) {
|
|
|
+ tenantTaskRunner.runForEachTenant("sendMsgByQwExtCreateTimeTwoDay", this::sendMsgByQwExtCreateTimeTwoDay);
|
|
|
+ } else {
|
|
|
+ sendMsgByQwExtCreateTimeTwoDay();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void sendMsgByQwExtCreateTimeTwoDay() {
|
|
|
+ Long tenantId = RedisTenantContext.getTenantId();
|
|
|
+ if(41L != tenantId) return;
|
|
|
+ // 昨天日期
|
|
|
+ Date yesterdayDate = Date.from(
|
|
|
+ LocalDate.now().minusDays(1)
|
|
|
+ .atStartOfDay(ZoneId.systemDefault())
|
|
|
+ .toInstant());
|
|
|
+
|
|
|
+ QwExternalContact qwExternalContact = new QwExternalContact();
|
|
|
+ qwExternalContact.setCreateTime(yesterdayDate);
|
|
|
+ List<QwExternalContact> qwExternalContacts = qwExternalContactService.selectQwExternalContactListByCreateTimeNew(qwExternalContact);
|
|
|
+ if(qwExternalContacts.isEmpty()) return;
|
|
|
+
|
|
|
+
|
|
|
+ for (QwExternalContact qwExt : qwExternalContacts) {
|
|
|
+ Long qwUserId = qwExt.getQwUserId();
|
|
|
+ if(qwUserId == null) continue;
|
|
|
+ QwUser user = qwUserService.selectQwUserById(qwUserId);
|
|
|
+ QwCompany qwCompany = qwCompanyService.selectQwCompanyByCorpId(user.getCorpId());
|
|
|
+ if(qwCompany == null) continue;
|
|
|
+
|
|
|
+
|
|
|
+ BaseVo parentVo = new BaseVo();
|
|
|
+ parentVo.setId(user.getId());
|
|
|
+ parentVo.setRoom(false);
|
|
|
+ parentVo.setUuid(user.getUid());
|
|
|
+ parentVo.setAgentId(qwCompany.getServerAgentId());
|
|
|
+ parentVo.setExId(qwExt.getExternalUserId());
|
|
|
+ parentVo.setServerId(user.getServerId());
|
|
|
+ parentVo.setCorpCode(parentVo.getCorpCode());
|
|
|
+ parentVo.setCorpId(parentVo.getCorpId());
|
|
|
+ parentVo.setQwUserId(user.getId());
|
|
|
+
|
|
|
+
|
|
|
+ FileVo voiceVo;
|
|
|
+ CompanyUser companyUser = companyUserMapper.selectCompanyUserById(user.getCompanyUserId());
|
|
|
+ if(companyUser == null) continue;
|
|
|
+ if("0".equals(companyUser.getSex())){
|
|
|
+ voiceVo = FileVo.builder()
|
|
|
+ .url("https://kyt-1323137866.cos.ap-chongqing.myqcloud.com/test/13.silk")
|
|
|
+ .voiceTime(19)
|
|
|
+ .build();
|
|
|
+ }else{
|
|
|
+ voiceVo = FileVo.builder()
|
|
|
+ .url("https://kyt-1323137866.cos.ap-chongqing.myqcloud.com/test/12.silk")
|
|
|
+ .voiceTime(17)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ voiceVo.setBase(parentVo);
|
|
|
+ ipadSendUtils.sendVoice(voiceVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /** 存聊天记录 **/
|
|
|
+ private void saveQwUserMsg(FastGptChatSession fastGptChatSession,Integer sendType,String content,QwUser sendUser) {
|
|
|
+ if(content.isEmpty()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ FastGptChatMsg fastGptChatMsgAi = new FastGptChatMsg();
|
|
|
+ fastGptChatMsgAi.setContent(content);
|
|
|
+ fastGptChatMsgAi.setSessionId(fastGptChatSession.getSessionId());
|
|
|
+ if(sendUser.getFastGptRoleId() != null){
|
|
|
+ fastGptChatMsgAi.setRoleId(Long.parseLong(fastGptChatSession.getKfId()));
|
|
|
+ }
|
|
|
+ fastGptChatMsgAi.setSendType(sendType);
|
|
|
+ fastGptChatMsgAi.setCompanyId(fastGptChatSession.getCompanyId());
|
|
|
+ fastGptChatMsgAi.setCompanyUserId(sendUser.getCompanyUserId());
|
|
|
+ fastGptChatMsgAi.setUserId(fastGptChatSession.getUserId());
|
|
|
+ fastGptChatMsgAi.setUserType(1);
|
|
|
+ fastGptChatMsgAi.setMsgType(1);
|
|
|
+ fastGptChatMsgAi.setStatus(0);
|
|
|
+ fastGptChatMsgAi.setAvatar(fastGptChatSession.getAvatar());
|
|
|
+ fastGptChatMsgAi.setNickName(fastGptChatSession.getNickName());
|
|
|
+ fastGptChatMsgAi.setCreateTime(new Date());
|
|
|
+ fastGptChatMsgAi.setExtId(fastGptChatSession.getQwExtId()+"");
|
|
|
+ fastGptChatMsgService.insertFastGptChatMsg(fastGptChatMsgAi);
|
|
|
+ log.info("新增消息:"+fastGptChatMsgAi);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* sop任务token消耗统计
|
|
|
*/
|