瀏覽代碼

Changes 增加消息提醒规则

cyan 1 月之前
父節點
當前提交
4ba517dd00

+ 0 - 79
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/site/controller/ShopApiController.java

@@ -1,9 +1,5 @@
 package org.jeecg.modules.okki.site.controller;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.zhipu.oapi.ClientV4;
-import com.zhipu.oapi.Constants;
-import com.zhipu.oapi.service.v4.model.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.http.HttpHeaders;
@@ -20,11 +16,6 @@ import org.jeecg.modules.okki.site.service.IOkkiSiteService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
 /**
  * @Description: 站点
  * @Author: Jack
@@ -180,74 +171,4 @@ public class ShopApiController {
         return Result.ok();
     }
 
-    @RequestMapping("/test")
-    public Result<?> test() throws JsonProcessingException {
-        List<ChatMessage> messages = new ArrayList<>();
-        ChatMessage systemChatMessage = new ChatMessage(ChatMessageRole.SYSTEM.value(), "#角色 你是一位情感、心理学和社会学领域的专家,专注于情感分析。通过对话中的语言和情感线索,你能够深入洞察对话者的心理活动,捕捉他们的情感波动、内在需求和潜在动机。不仅如此,你还可以分析对话中的社会互动模式,揭示人际关系中的权力动态、依赖性或冲突源。无论是提供情感支持、改善人际沟通,还是帮助理解复杂的心理状态,你都能通过精准的情感解读,为我提供全面的分析与建议。");
-        messages.add(systemChatMessage);
-
-        String promot = "Mick(SEM优化专员) 9-13 11:18:29\n" +
-                "@Anne☆英   您好,这边给您准备了一份广告部署表,里面帮您整理了产品列表,每日预算以及投放地区的内容,麻烦您看一下是否符合我们推广的预期。如果有问题也欢迎与我们沟通修改。\n" +
-                "\n" +
-                "Mick(SEM优化专员) 9-13 11:18:42\n" +
-                "[文件:2-Google ads部署表.xls]\n" +
-                "\n" +
-                "Anne☆英@微信@微信联系人 9-13 11:21:08\n" +
-                "好的,我们先看看\n" +
-                "\n" +
-                "Anne☆英@微信@微信联系人 9-13 11:26:51\n" +
-                "@王佳恒 你好,就是这一组吗?\n" +
-                "\n" +
-                "Mick(SEM优化专员) 9-13 11:27:47\n" +
-                "嗯嗯对的\n" +
-                "\n" +
-                "Mick(SEM优化专员) 9-13 11:27:58\n" +
-                "目前给您整理了一个广告大类的内容\n" +
-                "\n" +
-                "Anne☆英@微信@微信联系人 9-13 11:33:52\n" +
-                "不行哦,这几个Google图片搜出来的,几乎100%与我们要做的产品不相关\n" +
-                "\n" +
-                "Anne☆英@微信@微信联系人 9-13 11:41:30\n" +
-                "standup pouch 也不行,这个词零售属性更强,不符合我们定位的B端客户\n" +
-                "\n" +
-                "Anne☆英@微信@微信联系人 9-13 11:43:21\n" +
-                "@王佳恒  你有没有keywords everywhere?\n" +
-                "\n" +
-                "Anne☆英@微信@微信联系人 9-13 11:44:19\n" +
-                "如果有,帮忙查一下: eight side-sealed bag 和quad seal bag 的 volume(搜索量)和CPC (点击花费)\n" +
-                "\n" +
-                "Anne☆英@微信@微信联系人 9-13 11:50:26\n" +
-                "另外,你直接拿我们网站上这个作为这个广告组的着陆页,也不合适吧?着陆页觉得客户是否询盘,不是应该好好设计一下吗?";
-        ChatMessage userChatMessage = new ChatMessage(ChatMessageRole.USER.value(), promot);
-        messages.add(userChatMessage);
-
-        log.info("messages:{}", FastJsonUtil.toJSONString(messages));
-
-        HashMap<String, Object> extraJson = new HashMap<>();
-        extraJson.put("temperature", 0.5);
-        extraJson.put("max_tokens", 3);
-
-        ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest.builder()
-                .model(Constants.ModelChatGLM4)
-                .stream(Boolean.FALSE)
-                .invokeMethod(Constants.invokeMethod)
-                .messages(messages)
-                .build();
-
-        ClientV4 client = new ClientV4.Builder("3e1dc0e5cee1a8f0cc7b1fd01e5276c0.ueEh44nuymbAbUle")
-                .networkConfig(300, 100, 100, 100, TimeUnit.SECONDS)
-                .connectionPool(new okhttp3.ConnectionPool(8, 1, TimeUnit.SECONDS))
-                .build();
-
-        ModelApiResponse invokeModelApiResp = client.invokeModelApi(chatCompletionRequest);
-        log.info("model output: {}", FastJsonUtil.toJSONString(invokeModelApiResp));
-
-        String text = "";
-        if (invokeModelApiResp.isSuccess()) {
-            List<Choice> choices = invokeModelApiResp.getData().getChoices();
-            text = choices.get(0).getMessage().getContent().toString();
-        }
-        return Result.OK("OK", text);
-    }
-
 }

+ 2 - 2
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/wechatgroup/job/ReminderCustomerWechatGroupMsgJob.java

@@ -57,10 +57,10 @@ public class ReminderCustomerWechatGroupMsgJob implements Job {
             boolean isAfterHours = okCommonService.isAfterHours(date);
 //            log.info("isAfterHours:{}", isAfterHours);
             if (isAfterHours) {
-                okkiShopWechatGroupMsgService.getNoReplyCustomerMsgByHours(null, days, "afterHour");
+                okkiShopWechatGroupMsgService.getNoReplyCustomerMsgByHours(this.parameter, days, "afterHour");
             }
         } else {
-            okkiShopWechatGroupMsgService.getNoReplyCustomerMsgByHours(null, days, "restDay");
+            okkiShopWechatGroupMsgService.getNoReplyCustomerMsgByHours(this.parameter, days, "restDay");
         }
         long end = System.currentTimeMillis();
         log.info("请求发送 未回复客户消息给建站客服-普通定时任务 NoReplyWechatGroupMsgJob !结束,耗时:{}s", (end - start) / 1000);

+ 8 - 0
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/wechatgroup/mapper/OkkiShopWechatGroupMsgMapper.java

@@ -40,4 +40,12 @@ public interface OkkiShopWechatGroupMsgMapper extends BaseMapper<OkkiShopWechatG
      * @return
      */
     public List<OkkiShopWechatGroupMsg> getWechatNoReplySiteByHours(String siteId, Integer days, Double hours, List<String> enNames);
+
+    /**
+     * 获取站点最新消息
+     *
+     * @param siteId
+     * @return
+     */
+    public List<OkkiShopWechatGroupMsg> getLatestWechatMsgList(String siteId);
 }

+ 17 - 0
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/wechatgroup/mapper/xml/OkkiShopWechatGroupMsgMapper.xml

@@ -58,6 +58,9 @@
         ) t2 ON t1.site_id = t2.site_id AND t1.seq = t2.seq
         INNER JOIN ( SELECT site_id,tc_name FROM `okki_site` ) t3 ON t1.site_id = t3.site_id
         WHERE
+        <if test="siteId != null and siteId != ''">
+            t1.site_id = #{siteId} and
+        </if>
         <if test="days != null">
             <![CDATA[ t1.msg_time < NOW() - INTERVAL #{days} DAY ]]>
         </if>
@@ -72,4 +75,18 @@
         </if>
         AND t1.from_id NOT LIKE '%@xiaoman.cn';
     </select>
+
+    <select id="getLatestWechatMsgList" resultType="org.jeecg.modules.okki.wechatgroup.entity.OkkiShopWechatGroupMsg">
+        SELECT
+            t1.content,
+            t1.msg_time
+        FROM
+            `okki_shop_wechat_group_msg` t1
+        WHERE
+        <if test="siteId != null and siteId != ''">
+            t1.site_id = #{siteId} and
+        </if>
+            t1.msg_type = 'text'
+        ORDER BY t1.msg_time desc LIMIT 10
+    </select>
 </mapper>

+ 8 - 1
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/wechatgroup/service/IOkkiShopWechatGroupMsgService.java

@@ -35,7 +35,7 @@ public interface IOkkiShopWechatGroupMsgService extends IService<OkkiShopWechatG
      * @param siteId
      * @param type
      */
-    public void getNoReplyCustomerMsgByHours(String siteId, Integer days,  String type);
+    public void getNoReplyCustomerMsgByHours(String siteId, Integer days, String type);
 
     /**
      * 检测机器人或用户是否在群中
@@ -48,4 +48,11 @@ public interface IOkkiShopWechatGroupMsgService extends IService<OkkiShopWechatG
      * @return
      */
     public Map<String, Object> todayCheckWorkDay();
+
+    /**
+     * 获取最新一条消息
+     *
+     * @param siteId
+     */
+    public List<OkkiShopWechatGroupMsg> getLatestWechatMsgList(String siteId);
 }

+ 137 - 58
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/wechatgroup/service/impl/OkkiShopWechatGroupMsgServiceImpl.java

@@ -5,6 +5,9 @@ import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 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 org.apache.commons.collections4.CollectionUtils;
 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.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @Description: okki_shop_wechat_group_msg
@@ -38,7 +43,7 @@ public class OkkiShopWechatGroupMsgServiceImpl extends ServiceImpl<OkkiShopWecha
     @Value("${OKKI.CLIENT_SECRET}")
     private String CLIENT_SECRET;
 
-    @Autowired
+    @Resource
     private OkkiShopWechatGroupMsgMapper okkiShopWechatGroupMsgMapper;
 
     @Autowired
@@ -328,66 +333,74 @@ public class OkkiShopWechatGroupMsgServiceImpl extends ServiceImpl<OkkiShopWecha
         }
         for (int i = 0; i < wechatNoReplySiteList.size(); 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) + "。为了确保我们服务的高效性,请大家保持微信群内消息的畅通。特别是当收到客户提问或寻求帮助时,请务必及时回应,以提升我们的服务质量和效率。感谢配合!";
-                    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) + "。请及时回复客户消息,以确保服务的及时性和质量!";
-                    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);
     }
 
+    /**
+     * 获取最新一条消息
+     *
+     * @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;
+    }
 }