|
@@ -27,11 +27,11 @@ import com.fs.fastgptApi.service.Impl.AudioServiceImpl;
|
|
|
import com.fs.fastgptApi.util.AiImgUtil;
|
|
|
import com.fs.fastgptApi.vo.AudioVO;
|
|
|
import com.fs.qw.domain.*;
|
|
|
-import com.fs.qw.mapper.QwCompanyMapper;
|
|
|
-import com.fs.qw.mapper.QwExternalContactInfoMapper;
|
|
|
-import com.fs.qw.mapper.QwExternalContactMapper;
|
|
|
-import com.fs.qw.mapper.QwUserMapper;
|
|
|
+import com.fs.qw.mapper.*;
|
|
|
+import com.fs.qw.param.QwAutoTagsRulesTags;
|
|
|
import com.fs.qw.service.*;
|
|
|
+import com.fs.qwApi.domain.QwResult;
|
|
|
+import com.fs.qwApi.param.QwEditUserTagParam;
|
|
|
import com.fs.qwApi.param.QwSendMsgParam;
|
|
|
import com.fs.qwApi.service.QwApiService;
|
|
|
import com.fs.qwHookApi.param.QwHookSendMsgParam;
|
|
@@ -39,9 +39,11 @@ import com.fs.qwHookApi.vo.QwHookMsgVO;
|
|
|
import com.fs.qwHookApi.vo.QwHookVO;
|
|
|
import com.fs.sop.domain.QwSopLogs;
|
|
|
import com.fs.sop.mapper.QwSopLogsMapper;
|
|
|
+import com.fs.voice.utils.StringUtil;
|
|
|
import com.fs.wxwork.dto.*;
|
|
|
import com.fs.wxwork.service.WxWorkService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
@@ -49,6 +51,10 @@ import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
+import java.time.DayOfWeek;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.regex.Matcher;
|
|
@@ -76,12 +82,20 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
QwApiService qwApiService;
|
|
|
@Autowired
|
|
|
QwCompanyMapper qwCompanyMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IQwExternalErrRetryService errRetryService;
|
|
|
+ @Autowired
|
|
|
+ QwAutoTagsMapper qwAutoTagsMapper;
|
|
|
@Autowired
|
|
|
FsCourseWatchLogMapper fsCourseWatchLogMapper;
|
|
|
@Autowired
|
|
|
FsUserCourseVideoMapper fsUserCourseVideoMapper;
|
|
|
@Autowired
|
|
|
FsCourseWatchLogMapper watchLogMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ QwAutoTagsLogsMapper qwAutoTagsLogsMapper;
|
|
|
@Autowired
|
|
|
IQwJsApiService qwGetJsapiTicketService;
|
|
|
@Autowired
|
|
@@ -391,6 +405,13 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
}
|
|
|
//存聊天记录
|
|
|
addSaveAiMsg(2,2,contentKh,user,fastGptChatSession.getSessionId(),role.getRoleId(),qwExternalContacts,fastGptChatSession.getUserId(),result.getUsage().prompt_tokens,result.getUsage().completion_tokens,token);
|
|
|
+ Integer replyOne = redisCache.getCacheObject("reply:" + fastGptChatSession.getSessionId());
|
|
|
+ if (replyOne == 1){
|
|
|
+ QwUser qwUser = qwUserService.selectQwUserByQwUserId(String.valueOf(fastGptChatSession.getQwUserId()));
|
|
|
+ if (ObjectUtils.isNotEmpty(qwUser)&&ObjectUtils.isNotEmpty(qwUser.getIpadStatus())&&qwUser.getIpadStatus() == 1){
|
|
|
+ addQwAutoTags(qwUser,qwExternalContacts.getUserId(),qwExternalContacts.getExternalUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
if (!content.isEmpty()){
|
|
|
addSaveAiMsg(1,2,content,user,fastGptChatSession.getSessionId(),role.getRoleId(),qwExternalContacts,fastGptChatSession.getUserId(),null,null,null);
|
|
|
//从fastgpt_chat_artificial_words表中查询所有转人工文本
|
|
@@ -461,6 +482,112 @@ public class AiHookServiceImpl implements AiHookService {
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 增加标签
|
|
|
+ *
|
|
|
+ * @param qwUser
|
|
|
+ * @param userID
|
|
|
+ * @param externalUserID
|
|
|
+ */
|
|
|
+ private void addQwAutoTags(QwUser qwUser, String userID, String externalUserID) {
|
|
|
+ QwExternalContact qwExternalContact = qwExternalContactMapper.selectQwExternalByExternalIdAndCompanyIdToIdAndFs(
|
|
|
+ externalUserID, userID, qwUser.getCorpId());
|
|
|
+
|
|
|
+ QwEditUserTagParam qwEditUserTagParam = new QwEditUserTagParam();
|
|
|
+ qwEditUserTagParam.setUserid(userID);
|
|
|
+ qwEditUserTagParam.setExternal_userid(externalUserID);
|
|
|
+
|
|
|
+ QwAutoTags qwAutoTags = qwAutoTagsMapper.selectQwAutoReplyTagsByIdJSON(qwUser.getCorpId(), qwUser.getId());
|
|
|
+ if (qwAutoTags == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<String> combinedTagsSet = new HashSet<>();
|
|
|
+ Set<String> timeSlotMatchedTags = new HashSet<>();
|
|
|
+ String tagRemark = null;
|
|
|
+ boolean isMatch = false;
|
|
|
+
|
|
|
+ QwAutoTagsLogs qwAutoTagsLogs = new QwAutoTagsLogs();
|
|
|
+ qwAutoTagsLogs.setAutoTagId(qwAutoTags.getId());
|
|
|
+ qwAutoTagsLogs.setType(3L);
|
|
|
+ qwAutoTagsLogs.setQwUserid(qwUser.getId());
|
|
|
+ qwAutoTagsLogs.setExternalUserId(externalUserID);
|
|
|
+
|
|
|
+ List<QwAutoTagsRulesTags> rulesList = JSON.parseArray(qwAutoTags.getRulesTags(), QwAutoTagsRulesTags.class);
|
|
|
+
|
|
|
+ LocalDate todayDate = LocalDate.now();
|
|
|
+ DayOfWeek today = todayDate.getDayOfWeek();
|
|
|
+ int todayIndex = today.getValue();
|
|
|
+ LocalTime now = LocalTime.now();
|
|
|
+
|
|
|
+ for (QwAutoTagsRulesTags rule : rulesList) {
|
|
|
+ if (!rule.getWeek().contains(todayIndex)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ LocalTime start = LocalTime.parse(rule.getStartTime());
|
|
|
+ LocalTime end = LocalTime.parse("24:00".equals(rule.getEndTime()) ? "23:59:59" : rule.getEndTime());
|
|
|
+
|
|
|
+ if (now.isBefore(start) || now.isAfter(end)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ combinedTagsSet.addAll(rule.getTags());
|
|
|
+ timeSlotMatchedTags.addAll(rule.getTags());
|
|
|
+ isMatch = true;
|
|
|
+
|
|
|
+ if (rule.getIsDay() != null && rule.getIsDay() == 1) {
|
|
|
+ tagRemark = todayDate.format(DateTimeFormatter.ofPattern("yyMMdd")).substring(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StringUtil.strIsNullOrEmpty(rule.getRemarks())) {
|
|
|
+ tagRemark = (tagRemark == null ? "" : tagRemark + "-") + rule.getRemarks();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!isMatch) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> tagsToAdd = new ArrayList<>(combinedTagsSet);
|
|
|
+ qwEditUserTagParam.setAdd_tag(tagsToAdd);
|
|
|
+
|
|
|
+ qwAutoTagsLogs.setEffectiveRules(JSON.toJSONString(new ArrayList<>(timeSlotMatchedTags)));
|
|
|
+ qwAutoTagsLogs.setAddTime(new Date());
|
|
|
+ qwAutoTagsLogs.setCompanyId(qwUser.getCompanyId());
|
|
|
+ qwAutoTagsLogs.setCorpId(qwUser.getCorpId());
|
|
|
+
|
|
|
+ QwResult qwResult = qwApiService.editUserTag(qwEditUserTagParam, qwUser.getCorpId());
|
|
|
+ log.info("自动添加标签的状态: {}|{}|qwEditUserTagParam--{}",
|
|
|
+ qwResult.getErrcode(), qwResult.getErrmsg(), qwEditUserTagParam);
|
|
|
+
|
|
|
+ if (qwResult.getErrcode() == 0) {
|
|
|
+ qwExternalContact.setTagIds(JSON.toJSONString(tagsToAdd));
|
|
|
+ qwAutoTagsLogsMapper.insertOrUpdateQwAutoTagsLogs(qwAutoTagsLogs);
|
|
|
+ } else if (qwResult.getErrcode() == 45035) {
|
|
|
+ insertQwExternalErrRetryTool(
|
|
|
+ qwUser.getCorpId(),
|
|
|
+ JSON.toJSONString(qwEditUserTagParam),
|
|
|
+ 1,
|
|
|
+ qwResult.getErrmsg());
|
|
|
+ log.info("自动添加标签添加失败-已加入补偿机制中: {}", qwEditUserTagParam);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void insertQwExternalErrRetryTool(String corpId,String params,Integer retryState,String msg) {
|
|
|
+
|
|
|
+ QwExternalErrRetry errRetry=new QwExternalErrRetry();
|
|
|
+ errRetry.setTakeState(1);
|
|
|
+ errRetry.setCorpId(corpId);
|
|
|
+ errRetry.setRetryState(retryState);
|
|
|
+ errRetry.setRetryType(2);
|
|
|
+ errRetry.setRetryParams(JSON.toJSONString(params));
|
|
|
+ errRetry.setRetryNum(0);
|
|
|
+ errRetry.setCreateTime(new Date());
|
|
|
+ errRetry.setMark(msg);
|
|
|
+
|
|
|
+ errRetryService.insertQwExternalErrRetry(errRetry);
|
|
|
+
|
|
|
+ }
|
|
|
private void sendAiVoiceMsg(String content, Long sendId , String uuid,Long serverId,QwUser user) {
|
|
|
if (content == null || content.trim().isEmpty()){
|
|
|
System.out.println("输出为空格");
|