|
@@ -5,6 +5,9 @@ import cn.hutool.core.date.DateUtil;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.zhipu.oapi.ClientV4;
|
|
|
|
+import com.zhipu.oapi.Constants;
|
|
|
|
+import com.zhipu.oapi.service.v4.model.*;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -20,7 +23,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description: okki_shop_wechat_group_msg
|
|
* @Description: okki_shop_wechat_group_msg
|
|
@@ -38,7 +43,7 @@ public class OkkiShopWechatGroupMsgServiceImpl extends ServiceImpl<OkkiShopWecha
|
|
@Value("${OKKI.CLIENT_SECRET}")
|
|
@Value("${OKKI.CLIENT_SECRET}")
|
|
private String CLIENT_SECRET;
|
|
private String CLIENT_SECRET;
|
|
|
|
|
|
- @Autowired
|
|
|
|
|
|
+ @Resource
|
|
private OkkiShopWechatGroupMsgMapper okkiShopWechatGroupMsgMapper;
|
|
private OkkiShopWechatGroupMsgMapper okkiShopWechatGroupMsgMapper;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -328,66 +333,74 @@ public class OkkiShopWechatGroupMsgServiceImpl extends ServiceImpl<OkkiShopWecha
|
|
}
|
|
}
|
|
for (int i = 0; i < wechatNoReplySiteList.size(); i++) {
|
|
for (int i = 0; i < wechatNoReplySiteList.size(); i++) {
|
|
int finalI = i;
|
|
int finalI = i;
|
|
-// ThreadPoolUtil.execute(() -> {
|
|
|
|
- OkkiShopWechatGroupMsg okkiShopWechatGroupMsg = wechatNoReplySiteList.get(finalI);
|
|
|
|
- if (allSiteMapBySiteId.containsKey(okkiShopWechatGroupMsg.getSiteId())) {
|
|
|
|
- JSONObject jsonObject = allSiteMapBySiteId.get(okkiShopWechatGroupMsg.getSiteId());
|
|
|
|
-
|
|
|
|
- String currentSiteId = okkiShopWechatGroupMsg.getSiteId().toString();
|
|
|
|
- String companyName = jsonObject.getString("companyName");
|
|
|
|
- String zhName = jsonObject.getString("zhName");
|
|
|
|
- String feiShuGroupId = jsonObject.getString("feiShuGroupId");
|
|
|
|
- String userId = jsonObject.getString("userId");
|
|
|
|
-
|
|
|
|
- log.info("开始处理 第{}个 通知客服发送告警提醒,站点ID:{},公司名称:{},客服:{},feiShuGroupId:{}",
|
|
|
|
- finalI + 1, currentSiteId, companyName, zhName, feiShuGroupId);
|
|
|
|
-
|
|
|
|
- String msgType = "remindCustomerMsg";
|
|
|
|
- String exceptionMsg = "";
|
|
|
|
- String msgText = "";
|
|
|
|
- if (days != null) {
|
|
|
|
|
|
+ ThreadPoolUtil.execute(() -> {
|
|
|
|
+ OkkiShopWechatGroupMsg okkiShopWechatGroupMsg = wechatNoReplySiteList.get(finalI);
|
|
|
|
+ if (allSiteMapBySiteId.containsKey(okkiShopWechatGroupMsg.getSiteId())) {
|
|
|
|
+ JSONObject jsonObject = allSiteMapBySiteId.get(okkiShopWechatGroupMsg.getSiteId());
|
|
|
|
+
|
|
|
|
+ String currentSiteId = okkiShopWechatGroupMsg.getSiteId().toString();
|
|
|
|
+ String companyName = jsonObject.getString("companyName");
|
|
|
|
+ String zhName = jsonObject.getString("zhName");
|
|
|
|
+ String feiShuGroupId = jsonObject.getString("feiShuGroupId");
|
|
|
|
+ String userId = jsonObject.getString("userId");
|
|
|
|
+
|
|
|
|
+ String aiAnswerContent = getZhiPuAIContent(currentSiteId);
|
|
|
|
+ log.info("aiAnswerContent:{}", aiAnswerContent);
|
|
|
|
+ String isReplyCustomerText = aiAnswerContent.contains("无需回复") ? "无需回复" : "需要回复";
|
|
|
|
+ if ("需要回复".equals(isReplyCustomerText)) {
|
|
|
|
+ log.info("开始处理 第{}个 通知客服发送告警提醒,站点ID:{},公司名称:{},客服:{},feiShuGroupId:{}",
|
|
|
|
+ finalI + 1, currentSiteId, companyName, zhName, feiShuGroupId);
|
|
|
|
+
|
|
|
|
+ String msgType = "remindCustomerMsg";
|
|
|
|
+ String exceptionMsg = "";
|
|
|
|
+ String msgText = "";
|
|
|
|
+ if (days != null) {
|
|
// msgText = "我们注意到【" + companyName + "】的企业微信群已连续" + days + "天没有消息更新。最后一条消息的记录时间为" + DateUtil.format(okkiShopWechatGroupMsg.getMsgTime(), DatePattern.CHINESE_DATE_TIME_FORMATTER) + "。为了确保我们服务的高效性,请大家保持微信群内消息的畅通。特别是当收到客户提问或寻求帮助时,请务必及时回应,以提升我们的服务质量和效率。感谢配合!";
|
|
// msgText = "我们注意到【" + companyName + "】的企业微信群已连续" + days + "天没有消息更新。最后一条消息的记录时间为" + DateUtil.format(okkiShopWechatGroupMsg.getMsgTime(), DatePattern.CHINESE_DATE_TIME_FORMATTER) + "。为了确保我们服务的高效性,请大家保持微信群内消息的畅通。特别是当收到客户提问或寻求帮助时,请务必及时回应,以提升我们的服务质量和效率。感谢配合!";
|
|
- exceptionMsg = "已连续" + days + "天没有消息更新";
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (hours != null) {
|
|
|
|
- String hourStr = hours + "小时";
|
|
|
|
- if (hours == 0.5) {
|
|
|
|
- hourStr = "30分钟";
|
|
|
|
- }
|
|
|
|
|
|
+ exceptionMsg = "已连续" + days + "天没有消息更新";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (hours != null) {
|
|
|
|
+ String hourStr = hours + "小时";
|
|
|
|
+ if (hours == 0.5) {
|
|
|
|
+ hourStr = "30分钟";
|
|
|
|
+ }
|
|
// msgText = "我们注意到【" + companyName + "】的企业微信群中,客户发送的消息已超过" + hourStr + "未得到回复。最后一条消息的记录时间为" + DateUtil.format(okkiShopWechatGroupMsg.getMsgTime(), DatePattern.CHINESE_DATE_TIME_FORMATTER) + "。请及时回复客户消息,以确保服务的及时性和质量!";
|
|
// msgText = "我们注意到【" + companyName + "】的企业微信群中,客户发送的消息已超过" + hourStr + "未得到回复。最后一条消息的记录时间为" + DateUtil.format(okkiShopWechatGroupMsg.getMsgTime(), DatePattern.CHINESE_DATE_TIME_FORMATTER) + "。请及时回复客户消息,以确保服务的及时性和质量!";
|
|
- exceptionMsg = "未回复客户消息超过" + hourStr;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
|
- sb.append("<b>Production:###OKKI建站企微群异常通知</b> ");
|
|
|
|
- sb.append("\n");
|
|
|
|
- sb.append("<b>企业名称:</b> ").append(companyName);
|
|
|
|
- sb.append("\n");
|
|
|
|
- sb.append("<b>Client Id:</b> ").append(okkiShopWechatGroupMsg.getClientId());
|
|
|
|
- sb.append("\n");
|
|
|
|
- sb.append("<b>异常类型:</b> ").append(exceptionMsg);
|
|
|
|
- sb.append("\n");
|
|
|
|
- sb.append("<b>商家套餐:</b> ").append(okkiShopWechatGroupMsg.getTcName());
|
|
|
|
- sb.append("\n");
|
|
|
|
- sb.append("<b>服务顾问:</b> ").append(zhName);
|
|
|
|
- sb.append("\n");
|
|
|
|
-
|
|
|
|
- String content = "请看企微群消息";
|
|
|
|
- if ("text".equals(okkiShopWechatGroupMsg.getMsgType())) {
|
|
|
|
- content = okkiShopWechatGroupMsg.getContent();
|
|
|
|
- }
|
|
|
|
- sb.append("<b>最后一条消息:</b> ").append(content);
|
|
|
|
- msgText = sb.toString();
|
|
|
|
- log.info("msgText:{}", msgText);
|
|
|
|
-
|
|
|
|
- // todo 测试使用
|
|
|
|
-// feiShuGroupId = "oc_184b7dbca30579372652f5cef04ae645";
|
|
|
|
- if (StringUtils.isNotBlank(feiShuGroupId)) {
|
|
|
|
- feiShuCommonService.sendKfRemindMsg(feiShuGroupId, msgText, userId, msgType);
|
|
|
|
|
|
+ exceptionMsg = "未回复客户消息超过" + hourStr;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
+ sb.append("<b>Production:###OKKI建站企微群异常通知</b> ");
|
|
|
|
+ sb.append("\n");
|
|
|
|
+ sb.append("<b>企业名称:</b> ").append(companyName);
|
|
|
|
+ sb.append("\n");
|
|
|
|
+ sb.append("<b>Client Id:</b> ").append(okkiShopWechatGroupMsg.getClientId());
|
|
|
|
+ sb.append("\n");
|
|
|
|
+ sb.append("<b>异常类型:</b> ").append(exceptionMsg);
|
|
|
|
+ sb.append("\n");
|
|
|
|
+ sb.append("<b>商家套餐:</b> ").append(okkiShopWechatGroupMsg.getTcName());
|
|
|
|
+ sb.append("\n");
|
|
|
|
+ sb.append("<b>服务顾问:</b> ").append(zhName);
|
|
|
|
+ sb.append("\n");
|
|
|
|
+
|
|
|
|
+ String content = "请看企微群消息";
|
|
|
|
+ if ("text".equals(okkiShopWechatGroupMsg.getMsgType())) {
|
|
|
|
+ content = okkiShopWechatGroupMsg.getContent();
|
|
|
|
+ }
|
|
|
|
+ sb.append("<b>最后一条消息:</b> ").append(content);
|
|
|
|
+ sb.append("\n");
|
|
|
|
+ sb.append("<b>分析建议:</b> ").append(aiAnswerContent);
|
|
|
|
+ sb.append("\n");
|
|
|
|
+ msgText = sb.toString();
|
|
|
|
+ log.info("msgText:{}", msgText);
|
|
|
|
+
|
|
|
|
+ // todo 测试使用
|
|
|
|
+ feiShuGroupId = "oc_184b7dbca30579372652f5cef04ae645";
|
|
|
|
+ if (StringUtils.isNotBlank(feiShuGroupId)) {
|
|
|
|
+ feiShuCommonService.sendKfRemindMsg(feiShuGroupId, msgText, userId, msgType);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
-// });
|
|
|
|
|
|
+ });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -461,4 +474,70 @@ public class OkkiShopWechatGroupMsgServiceImpl extends ServiceImpl<OkkiShopWecha
|
|
return HttpClientUtil.doGet(replaceUrl);
|
|
return HttpClientUtil.doGet(replaceUrl);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取最新一条消息
|
|
|
|
+ *
|
|
|
|
+ * @param siteId
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<OkkiShopWechatGroupMsg> getLatestWechatMsgList(String siteId) {
|
|
|
|
+ List<OkkiShopWechatGroupMsg> wechatNoReplySiteList = okkiShopWechatGroupMsgMapper.getLatestWechatMsgList(siteId);
|
|
|
|
+// log.info("一共有:{}个站点,超过 {}小时没有回复企业微信群消息", wechatNoReplySiteList.size());
|
|
|
|
+ log.info("wechatNoReplySiteList:{}", FastJsonUtil.toJSONString(wechatNoReplySiteList));
|
|
|
|
+
|
|
|
|
+ return wechatNoReplySiteList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取AI回复
|
|
|
|
+ *
|
|
|
|
+ * @param siteId
|
|
|
|
+ */
|
|
|
|
+ public String getZhiPuAIContent(String siteId) {
|
|
|
|
+ List<OkkiShopWechatGroupMsg> shopWechatGroupMsgList = okkiShopWechatGroupMsgMapper.getLatestWechatMsgList(siteId);
|
|
|
|
+ shopWechatGroupMsgList.sort(Comparator.comparing(OkkiShopWechatGroupMsg::getMsgTime));
|
|
|
|
+ log.info("shopWechatGroupMsgList:{}", FastJsonUtil.toJSONString(shopWechatGroupMsgList));
|
|
|
|
+
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
+ shopWechatGroupMsgList.forEach(c -> {
|
|
|
|
+ sb.append("发送内容:")
|
|
|
|
+ .append(c.getContent()).append(",")
|
|
|
|
+ .append("发送时间:")
|
|
|
|
+ .append(DateUtil.format(c.getMsgTime(), DatePattern.CHINESE_DATE_TIME_FORMATTER))
|
|
|
|
+ .append("\n");
|
|
|
|
+ });
|
|
|
|
+ log.info("sb:{}", sb.toString());
|
|
|
|
+
|
|
|
|
+ List<ChatMessage> messages = new ArrayList<>();
|
|
|
|
+ ChatMessage systemChatMessage = new ChatMessage(ChatMessageRole.SYSTEM.value(), "#角色 作为情感、心理学和社会学领域的专家,你可以通过聊天记录中的语言和情感线索判断是否需要进一步回复。" +
|
|
|
|
+ "如果需要回复,请回答继续回复;否则请回答无需回复;请提供建议为什么需要这样做。");
|
|
|
|
+ messages.add(systemChatMessage);
|
|
|
|
+
|
|
|
|
+ String promot = sb.toString();
|
|
|
|
+ ChatMessage userChatMessage = new ChatMessage(ChatMessageRole.USER.value(), promot);
|
|
|
|
+ messages.add(userChatMessage);
|
|
|
|
+
|
|
|
|
+ ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest.builder()
|
|
|
|
+ .model(Constants.ModelChatGLM4)
|
|
|
|
+ .stream(Boolean.FALSE)
|
|
|
|
+ .invokeMethod(Constants.invokeMethod)
|
|
|
|
+ .messages(messages)
|
|
|
|
+ .build();
|
|
|
|
+
|
|
|
|
+ ClientV4 client = new ClientV4.Builder("3e1dc0e5cee1a8f0cc7b1fd01e5276c0.ueEh44nuymbAbUle")
|
|
|
|
+ .networkConfig(900, 300, 300, 300, TimeUnit.SECONDS)
|
|
|
|
+ .connectionPool(new okhttp3.ConnectionPool(8, 1, TimeUnit.SECONDS))
|
|
|
|
+ .build();
|
|
|
|
+
|
|
|
|
+ ModelApiResponse invokeModelApiResp = client.invokeModelApi(chatCompletionRequest);
|
|
|
|
+ log.info("model output: {}", FastJsonUtil.toJSONString(invokeModelApiResp));
|
|
|
|
+
|
|
|
|
+ String answerText = "";
|
|
|
|
+ if (invokeModelApiResp.isSuccess()) {
|
|
|
|
+ List<Choice> choices = invokeModelApiResp.getData().getChoices();
|
|
|
|
+ answerText = choices.get(0).getMessage().getContent().toString();
|
|
|
|
+ }
|
|
|
|
+ log.info("answerText:{}", answerText);
|
|
|
|
+ return answerText;
|
|
|
|
+ }
|
|
}
|
|
}
|