duhongyu před 1 měsícem
rodič
revize
3117f7acab

+ 57 - 69
ltrq-api/src/main/java/api/controller/call/CallLogController.java

@@ -67,61 +67,24 @@ public class CallLogController extends BaseController {
67 67
         qw.eq(input.getCallType() != null && input.getCallType() > 0, CallLog::getCallType, input.getCallType());
68 68
         qw.ge(!StringHelper.isEmpty(input.getStartTime()) , CallLog::getCreateTime, input.getStartTime());
69 69
         qw.le(!StringHelper.isEmpty(input.getEndTime()) , CallLog::getCreateTime, input.getEndTime());
70
-//        if (isNote.equals("1"))
71
-//        {
72
-//            qw.and(wq -> {
73
-//                wq.eq(CallLog::getNote,1);
74
-//                wq.or().isNull(CallLog::getNote).eq(CallLog::getCallType,2);
75
-//            });
76
-//           // qw.eq(CallLog::getNote, 1).or().isNull(CallLog::getNote);
77
-//        }
78
-//        if (Objects.equals(input.getNote(), "1"))
79
-//        {
80
-//            qw.and(wq -> {
81
-//                wq.eq(CallLog::getNote,1);
82
-//                wq.or().isNull(CallLog::getNote).eq(CallLog::getCallType,2);
83
-//            });
84
-//        } else if (Objects.equals(input.getNote(), "2")) {
85
-//            qw.eq(CallLog::getNote,2);
86
-//        }
87
-
88
-
89
-//        qw.le(input.getHangupTime() != null, CallLog::getCreateTime, input.getHangupTime());
90
-//        qw.ge(input.getAnswerTime() != null, CallLog::getCreateTime, input.getAnswerTime());
91
-
92
-
93
-
94 70
         qw.eq(input.getIsAnswer() != null , CallLog::getIsAnswer, input.getIsAnswer());
95 71
         qw.eq(input.getOpType() != null , CallLog::getOpType, input.getOpType());
96 72
         qw.eq(input.getMyd() != null , CallLog::getMyd, input.getMyd());
97 73
         qw.eq(!StringHelper.isEmpty(input.getWorkordercode()), CallLog::getWorkordercode, input.getWorkordercode());
98 74
         if (!StringHelper.isEmpty(input.getPhone())) {
99
-
100
-            qw.and(wq -> {
101
-                wq.and(innerWq -> {
102
-                    innerWq.like(CallLog::getCallee, input.getPhone())
103
-                            .eq(CallLog::getCallType, 2);
104
-                }).or(innerWq -> {
105
-                    innerWq.like(CallLog::getCaller, input.getPhone())
106
-                            .eq(CallLog::getCallType, 1);
107
-                });
108
-            });
109
-
110
-
111
-
75
+            qw.and(wq ->
76
+                    wq.like(CallLog::getCallee, input.getPhone()).eq(CallLog::getCallType, 2)
77
+                            .or()
78
+                            .like(CallLog::getCaller, input.getPhone()).eq(CallLog::getCallType, 1)
79
+            );
112 80
         }
113 81
 
114
-
115
-
116
-        if (!StringHelper.isEmpty(input.getAgent()))
117
-        {
118
-            qw.and(wq->{
119
-                wq.eq(CallLog::getCallerAgent, input.getAgent())
120
-                        .eq( CallLog::getCallType,2);
121
-            }) .or() .or(wq->{
122
-                wq.eq(CallLog::getCalleeAgent, input.getAgent())
123
-                        .eq( CallLog::getCallType,1);
124
-            });
82
+        if (!StringHelper.isEmpty(input.getAgent())) {
83
+            qw.and(wq ->
84
+                    wq.eq(CallLog::getCallerAgent, input.getAgent()).eq(CallLog::getCallType, 2)
85
+                            .or()
86
+                            .eq(CallLog::getCalleeAgent, input.getAgent()).eq(CallLog::getCallType, 1)
87
+            );
125 88
         }
126 89
         if (input.getSortOrder()!=null&&input.getSortOrder()>0)
127 90
         {
@@ -192,7 +155,7 @@ public class CallLogController extends BaseController {
192 155
     @ApiOperation("导出Excel")
193 156
     @Log(title = "导出excel", businessType = BusinessType.EXPORT)
194 157
     @PostMapping("/exportExcel")
195
-    public void ExportExcel(CallLog input) {
158
+    public void ExportExcel(CallInput input) {
196 159
         LambdaQueryWrapper<CallLog> qw = new LambdaQueryWrapper<>();
197 160
         qw.eq(input.getActionId() != null && input.getActionId() > 0, CallLog::getActionId, input.getActionId());
198 161
         qw.eq(!StringHelper.isEmpty(input.getCallerAgent()), CallLog::getCallerAgent, input.getCallerAgent());
@@ -201,30 +164,55 @@ public class CallLogController extends BaseController {
201 164
         qw.eq(!StringHelper.isEmpty(input.getCalleeAgent()), CallLog::getCalleeAgent, input.getCalleeAgent());
202 165
         qw.like(!StringHelper.isEmpty(input.getCallee()), CallLog::getCallee, input.getCallee());
203 166
         qw.eq(!StringHelper.isEmpty(input.getGroupNo()), CallLog::getGroupNo, input.getGroupNo());
204
-        qw.eq(input.getCallType() != null , CallLog::getCallType, input.getCallType());
205
-        qw.ge(input.getCreateTime() != null , CallLog::getCreateTime, input.getCreateTime());
206
-        qw.le(input.getHangupTime() != null , CallLog::getCreateTime, input.getHangupTime());
167
+        qw.eq(input.getCallType() != null && input.getCallType() > 0, CallLog::getCallType, input.getCallType());
168
+        qw.ge(!StringHelper.isEmpty(input.getStartTime()) , CallLog::getCreateTime, input.getStartTime());
169
+        qw.le(!StringHelper.isEmpty(input.getEndTime()) , CallLog::getCreateTime, input.getEndTime());
207 170
         qw.eq(input.getIsAnswer() != null , CallLog::getIsAnswer, input.getIsAnswer());
208 171
         qw.eq(input.getOpType() != null , CallLog::getOpType, input.getOpType());
209 172
         qw.eq(input.getMyd() != null , CallLog::getMyd, input.getMyd());
210
-//        if (isNote.equals("1"))
211
-//        {
212
-//            qw.and(wq -> {
213
-//                wq.eq(CallLog::getNote,1);
214
-//                wq.or().isNull(CallLog::getNote).eq(CallLog::getCallType,2);
215
-//            });
216
-//            // qw.eq(CallLog::getNote, 1).or().isNull(CallLog::getNote);
217
-//        }
218
-//        if (Objects.equals(input.getNote(), "1"))
219
-//        {
220
-//            qw.and(wq -> {
221
-//                wq.eq(CallLog::getNote,1);
222
-//                wq.or().isNull(CallLog::getNote).eq(CallLog::getCallType,2);
223
-//            });
224
-//        } else if (Objects.equals(input.getNote(), "2")) {
225
-//            qw.eq(CallLog::getNote,2);
226
-//        }
227 173
         qw.eq(!StringHelper.isEmpty(input.getWorkordercode()), CallLog::getWorkordercode, input.getWorkordercode());
174
+        if (!StringHelper.isEmpty(input.getPhone())) {
175
+
176
+            qw.and(wq -> {
177
+                wq.and(innerWq -> {
178
+                    innerWq.like(CallLog::getCallee, input.getPhone())
179
+                            .eq(CallLog::getCallType, 2);
180
+                }).or(innerWq -> {
181
+                    innerWq.like(CallLog::getCaller, input.getPhone())
182
+                            .eq(CallLog::getCallType, 1);
183
+                });
184
+            });
185
+        }
186
+        if (!StringHelper.isEmpty(input.getAgent()))
187
+        {
188
+            qw.and(wq->{
189
+                wq.eq(CallLog::getCallerAgent, input.getAgent())
190
+                        .eq( CallLog::getCallType,2);
191
+            }) .or() .or(wq->{
192
+                wq.eq(CallLog::getCalleeAgent, input.getAgent())
193
+                        .eq( CallLog::getCallType,1);
194
+            });
195
+        }
196
+        if (input.getSortOrder()!=null&&input.getSortOrder()>0)
197
+        {
198
+            if(input.getSortOrder()==2)
199
+            {
200
+                qw.orderByAsc(CallLog::getId);
201
+            } else if (input.getSortOrder()==3) {
202
+                qw.last("ORDER BY TIMESTAMPDIFF(SECOND, answer_time, hangup_time) DESC ");
203
+            }
204
+            else if (input.getSortOrder()==4) {
205
+                qw.last("ORDER BY TIMESTAMPDIFF(SECOND, answer_time, hangup_time) ASC ");
206
+            }
207
+            else
208
+            {
209
+                qw.orderByDesc(CallLog::getId);
210
+            }
211
+        }
212
+        else
213
+        {
214
+            qw.orderByDesc(CallLog::getId);
215
+        }
228 216
         qw.orderByDesc(CallLog::getId);
229 217
         var list=calllogService.getList(qw);
230 218
         List<CallLogExportView>  callLogView=  JSON.parseArray(JSON.toJSONString(list),CallLogExportView.class);

+ 1 - 1
ltrq-api/src/main/java/api/controller/docking/DockingController.java

@@ -146,7 +146,7 @@ public class DockingController extends BaseController {
146 146
                 "\"url\":\"http://192.168.16.31:8301/enesysapi/rest/v1/charging/querypayrecord\",\"method\":" +
147 147
                 "\"GET\"},{\"name\":\"抄表记录查询\",\"url\":" +
148 148
                 "\"http://192.168.16.38:8303/eslinkapi/mc/queryMeterReadRecordHistories\",\"method\":\"POST\"}," +
149
-                "{\"name\":\"欠费记录查询\",\"url\":\"http://192.168.16.31:8301/enesysapi/rest/v1/charging/queryowefee\"," +
149
+                "{\"name\":\"欠费记录查询\",\"url\":\"http://192.168.16.31:8301/enesysapi/rest/v1/charging/queryowefeeForLanTian\"," +
150 150
                 "\"method\":\"GET\"},{\"name\":\"表具信息查询\"," +
151 151
                 "\"url\":\"http://192.168.16.38:8303/eslinkapi/workorder/user/queryMeterBasicInfo\",\"method\":\"POST\"}," +
152 152
                 "{\"name\":\"安检记录查询\",\"url\":\"http://192.168.16.30:8193/mobileapi/mobileSe/querySeOrder\",\"method\":\"POST\"}," +

+ 29 - 15
ltrq-api/src/main/java/api/controller/rasa/RasaKnowledgeController.java

@@ -166,6 +166,7 @@ public class RasaKnowledgeController extends BaseController {
166 166
     @ApiOperation("添加知识库")
167 167
     @Log(title = "添加知识库",businessType = BusinessType.INSERT)
168 168
     @GetMapping("/AddDify/{id}")
169
+    @Anonymous
169 170
     public AjaxResult AddDify(@PathVariable long id) throws Exception {
170 171
         var dify=difyAssistantService.getEntity(id);
171 172
        return Success("", rasaknowledgeService.datasets(dify));
@@ -194,23 +195,25 @@ public class RasaKnowledgeController extends BaseController {
194 195
                 CompletableFuture.supplyAsync(() -> {
195 196
                 try
196 197
                  {
197
-                     var SerialNumber=rasaKnowledgeMapper.selectSerialNumber();
198
-                     if (SerialNumber!=null)
199
-                     {
200
-                         SerialNumber=SerialNumber+1;
201
-                     }
202
-                     else
203
-                     {
204
-                         SerialNumber=170L;
205
-                     }
206
-                     model.setSerialNumber(SerialNumber);
207 198
                      if ( StringHelper.isEmpty(model.getRecordingPath()))
208 199
                      {
209
-                         String filePath=TtsHelper.TextToSpeechRasa(model.getContent().replaceAll("<[^>]+>", ""),SerialNumber.toString());
200
+                         var SerialNumber=rasaKnowledgeMapper.selectSerialNumber();
201
+                         if (SerialNumber!=null&&SerialNumber>=10000L)
202
+                         {
203
+                             SerialNumber=SerialNumber+1;
204
+                         }
205
+                         else
206
+                         {
207
+                             SerialNumber=10000L;
208
+                         }
209
+                         model.setSerialNumber(SerialNumber);
210
+                         String filePath=TtsHelper.TextToSpeechRasa(
211
+                         model.getContent().replaceAll("<[^>]+>", ""),SerialNumber.toString());
210 212
                          model.setRecordingPath(filePath);
211 213
                          rasaknowledgeService.GetPath(filePath);
212 214
                          rasaknowledgeService.update(model);
213 215
                      }
216
+
214 217
                      if(model.getReviewStatus()==3)
215 218
                      {
216 219
                          rasaknowledgeService.DelDatasets(model);
@@ -259,6 +262,7 @@ public class RasaKnowledgeController extends BaseController {
259 262
         for(RasaKnowledge item:list)
260 263
         {
261 264
             item.setReviewStatus(1L);
265
+            item.setToExamine(1L);
262 266
             item.setCreateBy(CurrentUser().getUserName());
263 267
             item.setClassId(classId);
264 268
         }
@@ -370,13 +374,23 @@ public class RasaKnowledgeController extends BaseController {
370 374
         {
371 375
             input.setToExamine(0L);
372 376
         }
373
-        if (StringHelper.isNotEmpty(input.getRecordingPath()))
377
+
378
+        if (input.getRecordingPath()!=null)
374 379
         {
375
-            if (model.getRecordingPath().equals(input.getRecordingPath()))
380
+            String FileUrls = configService.getConfigValue("FilesUrl");
381
+            if (input.getRecordingPath().contains(FileUrls))
382
+            {
383
+                input.setRecordingPath(input.getRecordingPath().replace(FileUrls,""));
384
+            }
385
+            if (StringHelper.isNotEmpty(input.getRecordingPath()))
376 386
             {
377
-                input.setRecordingPath("");
387
+                if (model.getRecordingPath().equals(input.getRecordingPath()))
388
+                {
389
+                    input.setRecordingPath("");
390
+                }
378 391
             }
379 392
         }
393
+
380 394
         if (containsHtmlTags(input.getContent()))
381 395
         {
382 396
             input.setIsPlainText(2L);
@@ -401,7 +415,7 @@ public class RasaKnowledgeController extends BaseController {
401 415
     @DeleteMapping("/{ids}")
402 416
     public AjaxResult delete(@PathVariable List<Long> ids)  {
403 417
         LambdaUpdateWrapper<RasaKnowledge> qw=new LambdaUpdateWrapper<>();
404
-        qw.set(RasaKnowledge::getToExamine,0);
418
+        qw.set(RasaKnowledge::getToExamine,1);
405 419
         qw.set(RasaKnowledge::getReviewStatus,3);
406 420
         qw.in(RasaKnowledge::getId,ids);
407 421
         boolean result = rasaknowledgeService.updateBatch(qw);

+ 3 - 3
ltrq-entity/src/main/java/api/entity/view/rasa/KnowledgeExcel.java

@@ -6,9 +6,9 @@ import lombok.Data;
6 6
 @Data
7 7
 public class KnowledgeExcel {
8 8
 
9
-    /** 名称 */
10
-    @ApiModelProperty("类别")
11
-    private String type;
9
+//    /** 名称 */
10
+//    @ApiModelProperty("类别")
11
+//    private String type;
12 12
     /** 内容 */
13 13
     @ApiModelProperty("意图")
14 14
     private String intention;

+ 1 - 1
ltrq-mapper/src/main/resources/mapper/report/ReportMapper.xml

@@ -242,7 +242,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
242 242
 		SELECT  `callee_agent` userCode, (SELECT `nick_name` FROM `sys_user` WHERE `user_name` COLLATE utf8mb4_general_ci=a.`callee_agent`
243 243
 		LIMIT 1 )  userName ,
244 244
 		COUNT(1) ldCount,
245
-		SUM(CASE `is_answer` WHEN  1 THEN 1 ELSE 0  END ) answer,
245
+		SUM(CASE WHEN `is_answer` and TIMESTAMPDIFF(SECOND, answer_time, hangup_time)>=20   THEN 1 ELSE 0  END ) answer,
246 246
 		SUM(CASE `is_answer` WHEN 0 THEN 1 ELSE 0  END ) noAnswer,
247 247
 		SUM(CASE `is_answer` WHEN  1 THEN TIMESTAMPDIFF(SECOND, answer_time, hangup_time) ELSE 0  END ) allAnswerTime,
248 248
 -- 		SUM(CASE WHEN `myd`>0  and `myd` <![CDATA[<]]> 3 THEN 1 ELSE 0  END ) satisfied,

+ 4 - 2
ltrq-service/src/main/java/api/service/dify/impl/DifyAssistantServiceImpl.java

@@ -111,7 +111,8 @@ public class DifyAssistantServiceImpl extends BaseServiceImpl<DifyAssistantMappe
111 111
                 String line;
112 112
                 try {
113 113
                     while ((line = reader.readLine()) != null) {
114
-                        if (line.startsWith("data: {\"event\": \"message\"") ||line.startsWith("data: {\"event\": \"message_end\"")) {
114
+                       if (line.startsWith("data: {\"event\":\"message\"") ||line.startsWith("data: {\"event\":\"message_end\"")) {
115
+                     //   if (line.startsWith("data: {\"event\": \"message\"") ||line.startsWith("data: {\"event\": \"message_end\"")) {
115 116
                             writer.write(unicodeToString(line)+"\n");
116 117
                             // sseEmitter.send(unicodeToString(line)); // 实时发送单条结果
117 118
                             System.out.println(unicodeToString(line));
@@ -238,7 +239,8 @@ public class DifyAssistantServiceImpl extends BaseServiceImpl<DifyAssistantMappe
238 239
                 String line;
239 240
                 try {
240 241
                     while ((line = reader.readLine()) != null) {
241
-                        if (line.startsWith("data: {\"event\": \"workflow_finished\"")) {
242
+                        if (line.startsWith("data: {\"event\":\"workflow_finished\"")) {
243
+                     // if (line.startsWith("data: {\"event\": \"workflow_finished\"")) {
242 244
                             writer.write(unicodeToString(line)+"\n");
243 245
                             // sseEmitter.send(unicodeToString(line)); // 实时发送单条结果
244 246
                             System.out.println(unicodeToString(line));

+ 1 - 3
ltrq-service/src/main/java/api/service/order/impl/OrderBaseServiceImpl.java

@@ -47,11 +47,9 @@ public class OrderBaseServiceImpl extends BaseServiceImpl<OrderBaseMapper, Order
47 47
     ));
48 48
     private final MilvusClientHelper milvusClient= new MilvusClientHelper();
49 49
 
50
-    // 添加历史工单
50
+    // 添加
51 51
     @Override
52 52
     public  void historicalOrders(OrderBase order) {
53
-        // workOrderMap.put(order.getId(), order);
54
-
55 53
         String text = order.getContent() + " " + order.getContent();
56 54
         List<String> words = preprocess(text);
57 55
         float[] vector = vectorize(words);

+ 2 - 0
ltrq-service/src/main/java/api/service/rasa/IRasaKnowledgeService.java

@@ -11,5 +11,7 @@ public interface IRasaKnowledgeService extends IBaseService<RasaKnowledge> {
11 11
 
12 12
     String GetPath(String filePath);
13 13
 
14
+
15
+
14 16
     Boolean DelDatasets(RasaKnowledge doc) throws Exception;
15 17
 }

+ 17 - 5
ltrq-service/src/main/java/api/service/rasa/impl/RasaKnowledgeServiceImpl.java

@@ -9,6 +9,7 @@ import api.service.BaseServiceImpl;
9 9
 import api.util.helper.HttpHelper;
10 10
 import api.util.helper.SpringHelper;
11 11
 import api.util.helper.StringHelper;
12
+import com.alibaba.fastjson2.JSON;
12 13
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
13 14
 import com.fasterxml.jackson.databind.JsonNode;
14 15
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -20,6 +21,8 @@ import org.springframework.transaction.annotation.Transactional;
20 21
 
21 22
 import java.io.File;
22 23
 import java.util.Arrays;
24
+import java.util.HashMap;
25
+import java.util.Map;
23 26
 import java.util.Objects;
24 27
 import java.util.regex.Matcher;
25 28
 import java.util.regex.Pattern;
@@ -160,10 +163,10 @@ public class RasaKnowledgeServiceImpl extends BaseServiceImpl<RasaKnowledgeMappe
160 163
                 {
161 164
                     if (StringHelper.isNotEmpty(difyId))
162 165
                     {
163
-                        String apiUrl = dify.getUrl()+"/datasets/"+dify.getDifyId()+"/documents/"+dify.getDocumentId()+"/segments/"+doc .getDifyId();
166
+                        String apiUrl = dify.getUrl()+"/datasets/"+dify.getDifyId()+"/documents/"+dify.getDocumentId()+"/segments/"+difyId;
164 167
                         String apiKey = dify.getSecretKey(); // 替换为实际API密钥
165 168
                         // 2. 创建JSON请求体
166
-                        String jsonBody = "{\"segment\": {\"content\": \""+content+"\",\"answer\": \"\", \"keywords\": [], \"enabled\": false}}";
169
+                        String jsonBody = "{\"segment\": {\"content\": \""+content+"\",\"answer\": \"\", \"keywords\": [], \"enabled\": true}}";
167 170
                          HttpHelper.DifyHttpPost(apiUrl,apiKey,jsonBody);
168 171
                     }
169 172
                     else
@@ -177,9 +180,16 @@ public class RasaKnowledgeServiceImpl extends BaseServiceImpl<RasaKnowledgeMappe
177 180
                         try {
178 181
                             JsonNode rootNode = objectMapper.readTree(json);
179 182
                             String id = rootNode.path("data").get(0).path("id").asText();
180
-                            if (StringHelper.isNotEmpty(dify.getDifyId()))
183
+                            if (doc .getDifyId()!=null)
181 184
                             {
182
-                                doc.setDifyId(doc .getDifyId()+","+dify.getCode()+id);
185
+                                if (StringHelper.isNotEmpty(dify.getDifyId()))
186
+                                {
187
+                                    doc.setDifyId(doc .getDifyId()+","+dify.getCode()+id);
188
+                                }
189
+                                else
190
+                                {
191
+                                    doc.setDifyId(dify.getCode()+id);
192
+                                }
183 193
                             }
184 194
                             else
185 195
                             {
@@ -244,6 +254,9 @@ public class RasaKnowledgeServiceImpl extends BaseServiceImpl<RasaKnowledgeMappe
244 254
         }
245 255
 
246 256
     }
257
+
258
+
259
+
247 260
     @Data
248 261
     private  static class AjaxResult {
249 262
         private String state;
@@ -290,7 +303,6 @@ public class RasaKnowledgeServiceImpl extends BaseServiceImpl<RasaKnowledgeMappe
290 303
                 String apiUrl = dify.getUrl()+"/datasets/"+dify.getDifyId()+"/documents/"+dify.getDocumentId()+"/segments/"+difyId;
291 304
                 if (StringHelper.isNotEmpty(doc.getDifyId()))
292 305
                 {
293
-                    apiUrl=apiUrl+"/"+doc.getDifyId();
294 306
                     String apiKey = dify.getSecretKey(); // 替换为实际API密钥
295 307
                     return  HttpHelper.DifyHttpDelete(apiUrl,apiKey,"");
296 308
                 }

+ 160 - 127
ltrq-service/src/main/java/api/service/websocket/WebSocket.java

@@ -63,7 +63,9 @@ public class WebSocket {
63 63
     private static Map<String, Integer> servicers = new HashMap<>();// 客服状态(1:空闲,2:忙碌)
64 64
     private static Map<String, Integer> customers = new HashMap<>();// 客户来源
65 65
 
66
-    private static Map<String, String> conversation = new HashMap<>();// 历史聊天消息id
66
+    //private static Map<String, String> conversation = new HashMap<>();// 历史聊天消息id
67
+
68
+    private static Map<String, Map<String, Object>> conversations = new HashMap<>();// 历史聊天消息id
67 69
     private static Map<String, String> khkfs = new HashMap<>(); // 客户-客服映射关系
68 70
 
69 71
     /**
@@ -529,150 +531,181 @@ public class WebSocket {
529 531
         message.setCreateTime(new Date());
530 532
 
531 533
         String content = "";
532
-        if ("text".equals(msgType)) {
533
-            content = map.get("Content");
534
-            message.setMsgContent(content);
535
-        }
536
-        else if ("image".equals(msgType) || "voice".equals(msgType)) {
537
-            String mediaId=map.get("MediaId");
538
-            message.setMsgMediaid(mediaId);
539
-            String fn = System.currentTimeMillis()+".";
540
-            String fileName = fn + "jpg";
541
-            if ("voice".equals(msgType)) {
542
-                message.setMsgFormat(map.get("Format"));
543
-                fileName = fn + map.get("Format");
544
-            }
545
-            //下载临时素材
546
-            try {
547
-                String path = "files/online/" + DateHelper.getDate();
548
-                File pFile = new File(path);
549
-                if (!pFile.exists()) pFile.mkdirs();
550
-                String filePath = pFile.getAbsolutePath() + "/" + fileName;
551
-                File lFile = new File(filePath);
552
-                if (!lFile.exists()) lFile.createNewFile();
553
-                File file = webSocket.wxMpService.getMaterialService().mediaDownload(mediaId);
554
-                InputStream inputStream = new FileInputStream(file);
555
-                byte[] buffer = new byte[1024];
556
-                FileOutputStream outputStream = new FileOutputStream(lFile);
557
-                int length;
558
-                while ((length = inputStream.read(buffer)) > 0) {
559
-                    outputStream.write(buffer, 0, length);
560
-                }
561
-                inputStream.close();
562
-                outputStream.close();
563
-                message.setMsgFile(path + "/" + fileName);
564
-                content = path + "/" + fileName;
565
-            } catch (WxErrorException e) {
566
-                log.error("下载文件失败", e);
567
-                throw new RuntimeException(e);
568
-            } catch (IOException e) {
569
-                log.error("下载文件失败", e);
570
-                throw new RuntimeException(e);
571
-            }
572
-        }
573
-
574
-        if (!customers.containsKey(sendUser)) {
575
-            customers.put(sendUser, 2);
576
-            addCustomer(sendUser,2,null);
577
-        };
578
-
579
-        String kf = khkfs.get(sendUser);
580
-        if(content.contains("人工"))
534
+        if (!"event".equals(msgType))
581 535
         {
582
-
583
-
584
-            if (StringHelper.isEmpty(kf)||servicers.get(kf)==2) {
585
-                kf = servicerQueue.poll();
586
-                if (!StringHelper.isEmpty(kf)) {
587
-                    servicerQueue.add(kf);
588
-                    khkfs.put(sendUser, kf);
589
-                    WxMpKefuMessage wechatMessage = WxMpKefuMessage.TEXT().toUser(sendUser).content("正在为您转接人工,请稍后").build();
590
-                    try {
591
-                        webSocket.wxMpService.getKefuService().sendKefuMessage(wechatMessage);
592
-                    } catch (WxErrorException e) {
593
-                        throw new RuntimeException(e);
594
-                    }
595
-                    addMsg(sendUser,"正在为您转接人工,请稍后");
536
+            if ("text".equals(msgType)) {
537
+                content = map.get("Content");
538
+                message.setMsgContent(content);
539
+            }
540
+            else if ("image".equals(msgType) || "voice".equals(msgType)) {
541
+                String mediaId=map.get("MediaId");
542
+                message.setMsgMediaid(mediaId);
543
+                String fn = System.currentTimeMillis()+".";
544
+                String fileName = fn + "jpg";
545
+                if ("voice".equals(msgType)) {
546
+                    message.setMsgFormat(map.get("Format"));
547
+                    fileName = fn + map.get("Format");
596 548
                 }
597
-                else
598
-                {
599
-                    webSocket.messageService.insert(message);
600
-                    String  answer= configService.getConfigValue("prompt");
601
-                    WxMpKefuMessage wechatMessage = WxMpKefuMessage.TEXT().toUser(sendUser).content(answer).build();
602
-                    try {
603
-                        webSocket.wxMpService.getKefuService().sendKefuMessage(wechatMessage);
604
-                    } catch (WxErrorException e) {
605
-                        throw new RuntimeException(e);
549
+                //下载临时素材
550
+                try {
551
+                    String path = "files/online/" + DateHelper.getDate();
552
+                    File pFile = new File(path);
553
+                    if (!pFile.exists()) pFile.mkdirs();
554
+                    String filePath = pFile.getAbsolutePath() + "/" + fileName;
555
+                    File lFile = new File(filePath);
556
+                    if (!lFile.exists()) lFile.createNewFile();
557
+                    File file = webSocket.wxMpService.getMaterialService().mediaDownload(mediaId);
558
+                    InputStream inputStream = new FileInputStream(file);
559
+                    byte[] buffer = new byte[1024];
560
+                    FileOutputStream outputStream = new FileOutputStream(lFile);
561
+                    int length;
562
+                    while ((length = inputStream.read(buffer)) > 0) {
563
+                        outputStream.write(buffer, 0, length);
606 564
                     }
607
-                    addMsg(sendUser,answer);
565
+                    inputStream.close();
566
+                    outputStream.close();
567
+                    message.setMsgFile(path + "/" + fileName);
568
+                    content = path + "/" + fileName;
569
+                } catch (WxErrorException e) {
570
+                    log.error("下载文件失败", e);
571
+                    throw new RuntimeException(e);
572
+                } catch (IOException e) {
573
+                    log.error("下载文件失败", e);
574
+                    throw new RuntimeException(e);
608 575
                 }
609 576
             }
610
-        }
577
+
578
+            if (!customers.containsKey(sendUser)) {
579
+                customers.put(sendUser, 2);
580
+                addCustomer(sendUser,2,null);
581
+            };
582
+
583
+            String kf = khkfs.get(sendUser);
584
+//            if(content.contains("人工"))
585
+//            {
586
+//
587
+//
588
+//                if (StringHelper.isEmpty(kf)||servicers.get(kf)==2) {
589
+//                    kf = servicerQueue.poll();
590
+//                    if (!StringHelper.isEmpty(kf)) {
591
+//                        servicerQueue.add(kf);
592
+//                        khkfs.put(sendUser, kf);
593
+//                        WxMpKefuMessage wechatMessage = WxMpKefuMessage.TEXT().toUser(sendUser).content("正在为您转接人工,请稍后").build();
594
+//                        try {
595
+//                            webSocket.wxMpService.getKefuService().sendKefuMessage(wechatMessage);
596
+//                        } catch (WxErrorException e) {
597
+//                            throw new RuntimeException(e);
598
+//                        }
599
+//                        addMsg(sendUser,"正在为您转接人工,请稍后");
600
+//                    }
601
+//                    else
602
+//                    {
603
+//                        webSocket.messageService.insert(message);
604
+//                        String  answer= configService.getConfigValue("prompt");
605
+//                        WxMpKefuMessage wechatMessage = WxMpKefuMessage.TEXT().toUser(sendUser).content(answer).build();
606
+//                        try {
607
+//                            webSocket.wxMpService.getKefuService().sendKefuMessage(wechatMessage);
608
+//                        } catch (WxErrorException e) {
609
+//                            throw new RuntimeException(e);
610
+//                        }
611
+//                        addMsg(sendUser,answer);
612
+//                    }
613
+//                }
614
+//            }
611 615
 
612 616
 
613
-        if (!StringHelper.isEmpty(kf)) {
614
-            message.setKfUser(kf);
615
-            Session session1 = kfsessionPool.get(kf);
616
-            if (session1 != null) {
617
-                MessageView mv = new MessageView();
618
-                mv.setStatus("success");
619
-                mv.setType(msgType);
620
-                mv.setContent(content);
621
-                mv.setUser(sendUser);
622
-                session1.getAsyncRemote().sendText(JSON.toJSONString(mv));
617
+            if (!StringHelper.isEmpty(kf)) {
618
+                message.setKfUser(kf);
619
+                Session session1 = kfsessionPool.get(kf);
620
+                if (session1 != null) {
621
+                    MessageView mv = new MessageView();
622
+                    mv.setStatus("success");
623
+                    mv.setType(msgType);
624
+                    mv.setContent(content);
625
+                    mv.setUser(sendUser);
626
+                    session1.getAsyncRemote().sendText(JSON.toJSONString(mv));
627
+                }
628
+                webSocket.messageService.insert(message);
623 629
             }
624
-            webSocket.messageService.insert(message);
625
-        }
626
-        else  if (!content.contains("人工"))
627
-        {
628
-            webSocket.messageService.insert(message);
629
-            DifyChatMessagesInput input=new DifyChatMessagesInput();
630
-            LambdaQueryWrapper<DifyAssistant> qw = new LambdaQueryWrapper<>();
631
-            qw.eq(DifyAssistant::getCode, "mxyh");
632
-            DifyAssistant dify=difyAssistantService.getEntity(qw);
633
-            if (dify!=null)
630
+            else
634 631
             {
635
-                input.setId(dify.getAssistantId());
636
-                input.setQuery(content);
637
-                input.setConversation_id(conversation.getOrDefault(sendUser, ""));
638
-                input.setAuto_generate_name(false);
639
-                try
632
+                if ("text".equals(msgType))
640 633
                 {
641
-                    String waitAnswer="正在为你查询,请稍后";
642
-                    WxMpKefuMessage wechatMessage = WxMpKefuMessage.TEXT().toUser(sendUser).content(waitAnswer).build();
643
-                    try {
644
-                        webSocket.wxMpService.getKefuService().sendKefuMessage(wechatMessage);
645
-                    } catch (WxErrorException e) {
646
-                        throw new RuntimeException(e);
647
-                    }
648
-                    addMsg(sendUser,waitAnswer);
649
-                    String json=difyAssistantService.sendMessages(input,dify,sendUser);
650
-                    ObjectMapper mapper = new ObjectMapper();
651
-                    JsonNode rootNode = mapper.readTree(json);
652
-                    String answer = rootNode.get("answer").asText();
653
-                    String conversationId = rootNode.get("conversation_id").asText();
654
-                    if(!conversation.containsKey(sendUser))
634
+                    webSocket.messageService.insert(message);
635
+                    DifyChatMessagesInput input=new DifyChatMessagesInput();
636
+                    LambdaQueryWrapper<DifyAssistant> qw = new LambdaQueryWrapper<>();
637
+                    qw.eq(DifyAssistant::getCode, "mxyh");
638
+                    DifyAssistant dify=difyAssistantService.getEntity(qw);
639
+                    if (dify!=null)
655 640
                     {
656
-                        conversation.remove(sendUser);
657
-                        conversation.put(sendUser,conversationId);
658
-                    }
659
-                    WxMpKefuMessage wechatMsg = WxMpKefuMessage.TEXT().toUser(sendUser).content(answer).build();
660
-                    try {
661
-                        webSocket.wxMpService.getKefuService().sendKefuMessage(wechatMsg);
662
-                    } catch (WxErrorException e) {
663
-                        throw new RuntimeException(e);
664
-                    }
665
-                    addMsg(sendUser,answer);
641
+                        input.setId(dify.getAssistantId());
642
+                        input.setQuery(content);
643
+                        Map<String, Object> conversationMap= conversations.get(sendUser);
644
+                        String Conversation_id="";
645
+                        if (conversationMap!=null)
646
+                        {
647
+                            Object Aime=conversationMap.get("conversationAime");
648
+                            Object Id=conversationMap.get("conversationId");
649
+                            if (Aime!=null)
650
+                            {
651
+                                Date time= (Date) conversationMap.get("conversationAime");
652
+                                // 获取当前时间
653
+                                Date now = new Date();
654
+                                // 计算时间差的绝对值(毫秒)
655
+                                long diffInMilliseconds = Math.abs(now.getTime() - time.getTime());
656
+                                if (diffInMilliseconds <= (30 * 60 * 1000)&&Id!=null)
657
+                                {
658
+                                    Conversation_id=Id.toString();
659
+                                }
660
+                            }
661
+                        }
662
+                        input.setConversation_id(Conversation_id);
663
+                        input.setAuto_generate_name(false);
664
+                        try
665
+                        {
666
+//                            String waitAnswer="正在为你查询,请稍后";
667
+//                            WxMpKefuMessage wechatMessage = WxMpKefuMessage.TEXT().toUser(sendUser).content(waitAnswer).build();
668
+//                            try {
669
+//                                webSocket.wxMpService.getKefuService().sendKefuMessage(wechatMessage);
670
+//                            } catch (WxErrorException e) {
671
+//                                throw new RuntimeException(e);
672
+//                            }
673
+//                            addMsg(sendUser,waitAnswer);
674
+                            String json=difyAssistantService.sendMessages(input,dify,sendUser);
675
+                            ObjectMapper mapper = new ObjectMapper();
676
+                            JsonNode rootNode = mapper.readTree(json);
677
+                            String answer = rootNode.get("answer").asText();
678
+                            String conversationId = rootNode.get("conversation_id").asText();
679
+                            if(!conversations.containsKey(sendUser))
680
+                            {
681
+                                conversations.remove(sendUser);
682
+                                Map<String,Object> conversationsMap=new HashMap<>();
683
+                                conversationsMap.put("conversationId",conversationId);
684
+                                conversationsMap.put("conversationAime",new Date());
685
+                                conversations.put(sendUser,conversationsMap);
686
+                            }
687
+                            WxMpKefuMessage wechatMsg = WxMpKefuMessage.TEXT().toUser(sendUser).content(answer).build();
688
+                            try {
689
+                                webSocket.wxMpService.getKefuService().sendKefuMessage(wechatMsg);
690
+                            } catch (WxErrorException e) {
691
+                                throw new RuntimeException(e);
692
+                            }
693
+                            addMsg(sendUser,answer);
694
+
695
+                        }
696
+                        catch (Exception E)
697
+                        {}
666 698
 
699
+                    }
667 700
                 }
668
-                catch (Exception E)
669
-                {}
670 701
 
671
-            }
672 702
 
673 703
 
704
+            }
705
+
674 706
         }
675 707
 
708
+
676 709
     }
677 710
     public void sendMessage(String kf, String message) {
678 711
         Session session1 = kfsessionPool.get(kf);