|
|
@@ -2,22 +2,31 @@ package api.service.call.impl;
|
|
2
|
2
|
|
|
3
|
3
|
import api.entity.database.call.Ivr;
|
|
4
|
4
|
import api.entity.input.call.*;
|
|
5
|
|
-
|
|
6
|
5
|
import api.mapper.call.IvrMapper;
|
|
7
|
6
|
import api.service.call.IIvrService;
|
|
8
|
7
|
import api.service.BaseServiceImpl;
|
|
9
|
8
|
import api.service.call.IIvrSqlService;
|
|
10
|
9
|
import api.util.enums.IvrType;
|
|
11
|
|
-import api.util.helper.StringHelper;
|
|
12
|
|
-import api.util.helper.TtsHelper;
|
|
13
|
|
-
|
|
|
10
|
+import api.util.helper.*;
|
|
|
11
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
14
|
12
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
15
|
13
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
14
|
+import lombok.Data;
|
|
16
|
15
|
import lombok.var;
|
|
17
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
18
|
17
|
import org.springframework.stereotype.Service;
|
|
19
|
18
|
import org.springframework.transaction.annotation.Transactional;
|
|
20
|
19
|
|
|
|
20
|
+import org.w3c.dom.*;
|
|
|
21
|
+import org.w3c.dom.Node;
|
|
|
22
|
+
|
|
|
23
|
+import javax.xml.parsers.*;
|
|
|
24
|
+import javax.xml.transform.*;
|
|
|
25
|
+import javax.xml.transform.dom.DOMSource;
|
|
|
26
|
+import javax.xml.transform.stream.StreamResult;
|
|
|
27
|
+import java.io.File;
|
|
|
28
|
+import java.io.StringReader;
|
|
|
29
|
+import java.io.StringWriter;
|
|
21
|
30
|
import java.util.*;
|
|
22
|
31
|
import java.util.stream.Collectors;
|
|
23
|
32
|
|
|
|
@@ -26,18 +35,25 @@ import java.util.stream.Collectors;
|
|
26
|
35
|
public class IvrServiceImpl extends BaseServiceImpl<IvrMapper, Ivr> implements IIvrService{
|
|
27
|
36
|
public IvrServiceImpl(){ super(false); }
|
|
28
|
37
|
@Autowired
|
|
|
38
|
+ public static final String middlewareUrl= SpringHelper.getRequiredProperty("spring.middlewareUrl");
|
|
|
39
|
+ // @Autowired
|
|
|
40
|
+ // public static final String curlUrl= SpringHelper.getRequiredProperty("spring.curlUrl");
|
|
|
41
|
+
|
|
|
42
|
+ @Autowired
|
|
29
|
43
|
private IIvrSqlService iIvrSqlService;
|
|
30
|
44
|
//新增
|
|
31
|
45
|
@Override
|
|
32
|
46
|
public boolean insert(Ivr entity) {
|
|
33
|
|
- dealIvr(entity);
|
|
|
47
|
+ // dealIvr(entity);
|
|
|
48
|
+ // HttpHelper.sendGet(middlewareUrl+"/ivr/delete");
|
|
34
|
49
|
return this.save(entity);
|
|
35
|
50
|
}
|
|
36
|
51
|
|
|
37
|
52
|
//编辑
|
|
38
|
53
|
@Override
|
|
39
|
54
|
public boolean update(Ivr entity) {
|
|
40
|
|
- dealIvr(entity);
|
|
|
55
|
+ // dealIvr(entity);
|
|
|
56
|
+ // HttpHelper.sendGet(middlewareUrl+"/ivr/delete");
|
|
41
|
57
|
return this.updateById(entity);
|
|
42
|
58
|
}
|
|
43
|
59
|
|
|
|
@@ -70,7 +86,7 @@ public class IvrServiceImpl extends BaseServiceImpl<IvrMapper, Ivr> implements I
|
|
70
|
86
|
" <action application=\"set\" data=\"call_timeout=60\"/>\n" +
|
|
71
|
87
|
" <action application=\"set\" data=\"continue_on_fail=USER_BUSY,NO_ANSWER\"/>\n" +
|
|
72
|
88
|
" <action application=\"export\" data=\"op_type=${op_type}\"/>\n" +
|
|
73
|
|
- " <action application=\"bridge\" data=\"{origination_caller_id_name=18538595479,origination_caller_id_number=18538595478,ignore_early_media=true}sofia/gateway/hykj/$1\"/>\n" +
|
|
|
89
|
+ " <action application=\"bridge\" data=\"{ignore_early_media=true}sofia/gateway/hykj/$1\"/>\n" +
|
|
74
|
90
|
" <action application=\"hangup\" data=\"${originate_disposition}\"/>\n" +
|
|
75
|
91
|
" <action name=\"start_dtmf\"/>\n" +
|
|
76
|
92
|
" </condition>\n" +
|
|
|
@@ -108,7 +124,8 @@ public class IvrServiceImpl extends BaseServiceImpl<IvrMapper, Ivr> implements I
|
|
108
|
124
|
" </menu>\n";
|
|
109
|
125
|
|
|
110
|
126
|
//处理ivr
|
|
111
|
|
- private void dealIvr(Ivr entity){
|
|
|
127
|
+ @Override
|
|
|
128
|
+ public void dealIvr(Ivr entity){
|
|
112
|
129
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
113
|
130
|
List<IvrProperties> propertiesList=new ArrayList<>();
|
|
114
|
131
|
List<IvrEdges> edgesList=new ArrayList<>();
|
|
|
@@ -174,17 +191,19 @@ public class IvrServiceImpl extends BaseServiceImpl<IvrMapper, Ivr> implements I
|
|
174
|
191
|
"<document type=\"freeswitch/xml\">\n" +
|
|
175
|
192
|
" <section name=\"dialplan\">\n" +
|
|
176
|
193
|
contextDefault +
|
|
177
|
|
- " <context name=\"public\">\n" +
|
|
|
194
|
+ " <context name=\"public\">\n" +
|
|
178
|
195
|
" <extension name=\"public_1\">\n" +
|
|
179
|
196
|
" <condition field=\"destination_number\" expression=\"^(.*)$\">\n" +
|
|
180
|
197
|
" <action application=\"sleep\" data=\"1000\"/>\n" +
|
|
181
|
198
|
" <action application=\"answer\"/>\n" +
|
|
182
|
|
- " <action application=\"set\" data=\"basenumber=$1\"/>\n" +
|
|
183
|
|
- " <action application=\"set\" data=\"wait=0\"/>\n" +
|
|
184
|
|
- " <action application=\"transfer\" data=\"$1 XML " + toNode.getProperties().getName() + toNode.getId()+ "\"/>\n" +
|
|
|
199
|
+ " <action application=\"odbc_query\" inline=\"true\" data=\"call proc_IVRFirst('${uuid}','${caller_id_number}','$1','${network_addr}')\"/>\n" +
|
|
|
200
|
+ (toNode.getType().equals(IvrType.audiodtmf)?
|
|
|
201
|
+ " <action application=\"sleep\" data=\"1000\"/>\n " +
|
|
|
202
|
+ " <action application=\"ivr\" data=\""+toNode.getProperties().getName()+ toNode.getId()+"\"/>\n":
|
|
|
203
|
+ " <action application=\"transfer\" data=\"${destination_number} XML "+toNode.getProperties().getName()+ toNode.getId()+"\"/>\n")+
|
|
185
|
204
|
" </condition>\n" +
|
|
186
|
205
|
" </extension>\n" +
|
|
187
|
|
- " </context>\n" +
|
|
|
206
|
+ " </context>\n"+
|
|
188
|
207
|
contextXml +
|
|
189
|
208
|
" </section>\n" +
|
|
190
|
209
|
"</document>";
|
|
|
@@ -210,11 +229,14 @@ public class IvrServiceImpl extends BaseServiceImpl<IvrMapper, Ivr> implements I
|
|
210
|
229
|
private StringBuilder getXml( List<IvrProperties> nodes , List<IvrEdges> paths,IvrProperties currNode,List<String> ids,StringBuilder menuXml) {
|
|
211
|
230
|
|
|
212
|
231
|
|
|
|
232
|
+
|
|
213
|
233
|
boolean isexist = ids.contains(currNode.getId());
|
|
214
|
234
|
if (!isexist) {
|
|
215
|
235
|
ids.add(currNode.getId());
|
|
216
|
236
|
}
|
|
217
|
|
-
|
|
|
237
|
+ else {
|
|
|
238
|
+ return new StringBuilder();
|
|
|
239
|
+ }
|
|
218
|
240
|
StringBuilder xml = new StringBuilder();
|
|
219
|
241
|
StringBuilder nextXml = new StringBuilder();
|
|
220
|
242
|
Map<String, Object> data = currNode.getProperties().getAttr();
|
|
|
@@ -227,18 +249,18 @@ public class IvrServiceImpl extends BaseServiceImpl<IvrMapper, Ivr> implements I
|
|
227
|
249
|
StringBuilder mxml = new StringBuilder(" <menu name=\"" + currNode.getProperties().getName()+ currNode.getId() + "\" ");
|
|
228
|
250
|
if (Objects.equals(data.get("type").toString(), "audio"))
|
|
229
|
251
|
{
|
|
230
|
|
- mxml.append("greet-long").append("=\"").append(data.get("file").toString()).append("\" ");
|
|
231
|
|
- mxml.append("greet-short").append("=\"").append(data.get("greetShortUrl").toString()).append("\" ");
|
|
232
|
|
- mxml.append("invalid-sound").append("=\"").append(data.get("invalidSoundUrl").toString()).append("\" ");
|
|
233
|
|
- mxml.append("exit-sound").append("=\"").append(data.get("xitSoundUrl").toString()).append("\" ");
|
|
|
252
|
+ mxml.append("greet-long").append("=\"").append(GetPath(data.get("file").toString())).append("\" ");
|
|
|
253
|
+ mxml.append("greet-short").append("=\"").append(GetPath(data.get("greetShortUrl").toString())).append("\" ");
|
|
|
254
|
+ mxml.append("invalid-sound").append("=\"").append(GetPath(data.get("invalidSoundUrl").toString())).append("\" ");
|
|
|
255
|
+ mxml.append("exit-sound").append("=\"").append(GetPath(data.get("xitSoundUrl").toString())).append("\" ");
|
|
234
|
256
|
|
|
235
|
257
|
}
|
|
236
|
258
|
else
|
|
237
|
259
|
{
|
|
238
|
|
- mxml.append("greet-long").append("=\"").append(TtsHelper.TextToSpeech(data.get("content").toString())).append("\" ");
|
|
239
|
|
- mxml.append("greet-short").append("=\"").append(TtsHelper.TextToSpeech(data.get("greetShort").toString())).append("\" ");
|
|
240
|
|
- mxml.append("invalid-sound").append("=\"").append(TtsHelper.TextToSpeech(data.get("invalidSound").toString())).append("\" ");
|
|
241
|
|
- mxml.append("exit-sound").append("=\"").append(TtsHelper.TextToSpeech(data.get("xitSound").toString())).append("\" ");
|
|
|
260
|
+ mxml.append("greet-long").append("=\"").append(GetPath(TtsHelper.TextToSpeech(data.get("content").toString()) )).append("\" ");
|
|
|
261
|
+ mxml.append("greet-short").append("=\"").append(GetPath(TtsHelper.TextToSpeech(data.get("greetShort").toString()))).append("\" ");
|
|
|
262
|
+ mxml.append("invalid-sound").append("=\"").append(GetPath(TtsHelper.TextToSpeech(data.get("invalidSound").toString()))).append("\" ");
|
|
|
263
|
+ mxml.append("exit-sound").append("=\"").append(GetPath(TtsHelper.TextToSpeech(data.get("xitSound").toString()))).append("\" ");
|
|
242
|
264
|
|
|
243
|
265
|
}
|
|
244
|
266
|
mxml.append("confirm-macro").append("=\"").append("\" ");
|
|
|
@@ -247,10 +269,10 @@ public class IvrServiceImpl extends BaseServiceImpl<IvrMapper, Ivr> implements I
|
|
247
|
269
|
mxml.append("tts-voice").append("=\"").append("\" ");
|
|
248
|
270
|
mxml.append("confirm-attempts").append("=\"").append("\" ");
|
|
249
|
271
|
mxml.append("timeout").append("=\"").append(data.get("timeout").toString()).append("\" ");
|
|
250
|
|
- mxml.append("inter-digit-timeout").append("\" ");
|
|
|
272
|
+ mxml.append("inter-digit-timeout").append("=\" ").append("\" ");
|
|
251
|
273
|
mxml.append("max-failures").append("=\"").append(data.get("maxFailures").toString()).append("\" ");
|
|
252
|
274
|
mxml.append("max-timeouts").append("=\"").append(data.get("maxTimeouts").toString()).append("\" ");
|
|
253
|
|
- mxml.append("digit-len").append("=\"").append("\" ");
|
|
|
275
|
+ mxml.append("digit-len").append("=\"").append("1\" ");
|
|
254
|
276
|
|
|
255
|
277
|
mxml.append(">\n");
|
|
256
|
278
|
for (IvrEdges path : nodePaths) {
|
|
|
@@ -283,9 +305,9 @@ public class IvrServiceImpl extends BaseServiceImpl<IvrMapper, Ivr> implements I
|
|
283
|
305
|
}
|
|
284
|
306
|
IvrProperties toNode = nodes.stream().filter(p -> p.getId().equals(path.getTargetNodeId())).findFirst().get();
|
|
285
|
307
|
if (toNode.getType().equals(IvrType.audiodtmf)) {
|
|
286
|
|
- xml.append(" <action application=\"ivr\" data=\"").append(toNode.getProperties().getName()).append( toNode.getId()).append("\"/>\n");
|
|
|
308
|
+ xml.append(" <action application=\"sleep\" data=\"1000\"/>\n <action application=\"ivr\" data=\"").append(toNode.getProperties().getName()).append( toNode.getId()).append("\"/>\n");
|
|
287
|
309
|
} else {
|
|
288
|
|
- xml.append(" <action application=\"transfer\" data=\"${destination_number} XML ").append(toNode.getProperties().getName()).append( toNode.getId()).append("\"/>\n");
|
|
|
310
|
+ xml.append(" <action application=\"transfer\" data=\"${destination_number} XML ").append(toNode.getProperties().getName()).append( toNode.getId()).append("\"/>\n");
|
|
289
|
311
|
}
|
|
290
|
312
|
xml.append(" </condition>\n");
|
|
291
|
313
|
xml.append(" </extension>\n");
|
|
|
@@ -312,9 +334,20 @@ public class IvrServiceImpl extends BaseServiceImpl<IvrMapper, Ivr> implements I
|
|
312
|
334
|
var content= mapper.readValue(model.getSqlContent(), Map.class);
|
|
313
|
335
|
if(content!=null)
|
|
314
|
336
|
{
|
|
315
|
|
- xml.append(" " +
|
|
316
|
|
- " <action application=\"odbc_query\" data=\"").
|
|
317
|
|
- append(content.get("content").toString()).append("\"/>\n");
|
|
|
337
|
+ if (Objects.equals(content.get("field").toString(), "curl_response_data"))
|
|
|
338
|
+ {
|
|
|
339
|
+ xml.append(" " +
|
|
|
340
|
+ " <action application=\"curl\" data=\"").
|
|
|
341
|
+ append(content.get("content").toString()).append("\"/>\n");
|
|
|
342
|
+ }
|
|
|
343
|
+ else
|
|
|
344
|
+ {
|
|
|
345
|
+ xml.append(" " +
|
|
|
346
|
+ " <action application=\"odbc_query\" data=\"").
|
|
|
347
|
+ append(content.get("content").toString()).append("\"/>\n");
|
|
|
348
|
+ }
|
|
|
349
|
+
|
|
|
350
|
+
|
|
318
|
351
|
}
|
|
319
|
352
|
}
|
|
320
|
353
|
}
|
|
|
@@ -342,7 +375,7 @@ public class IvrServiceImpl extends BaseServiceImpl<IvrMapper, Ivr> implements I
|
|
342
|
375
|
}
|
|
343
|
376
|
IvrProperties toNode = nodes.stream().filter(p -> p.getId().equals(path.getTargetNodeId())).findFirst().get();
|
|
344
|
377
|
if (toNode.getType().equals(IvrType.audiodtmf)) {
|
|
345
|
|
- xml.append(" <action application=\"ivr\" data=\"").append(toNode.getProperties().getName()).append( toNode.getId()).append("\"/>\n");
|
|
|
378
|
+ xml.append(" <action application=\"sleep\" data=\"1000\"/>\\n <action application=\"ivr\" data=\"").append(toNode.getProperties().getName()).append( toNode.getId()).append("\"/>\n");
|
|
346
|
379
|
} else {
|
|
347
|
380
|
xml.append(" <action application=\"transfer\" data=\"${destination_number} XML ").append(toNode.getProperties().getName()).append( toNode.getId()).append("\"/>\n");
|
|
348
|
381
|
}
|
|
|
@@ -372,11 +405,11 @@ public class IvrServiceImpl extends BaseServiceImpl<IvrMapper, Ivr> implements I
|
|
372
|
405
|
case audio:
|
|
373
|
406
|
if(Objects.equals(data.get("type").toString(), "audio"))
|
|
374
|
407
|
{
|
|
375
|
|
- xml.append(" <action application=\"playback\" data=\"").append(data.get("file").toString()).append("\"/>\n");
|
|
|
408
|
+ xml.append(" <action application=\"sleep\" data=\"1000\"/>\n <action application=\"playback\" data=\"").append(GetPath(data.get("file").toString())).append("\"/>\n");
|
|
376
|
409
|
}
|
|
377
|
410
|
else
|
|
378
|
411
|
{
|
|
379
|
|
- xml.append(" <action application=\"playback\" data=\"").append(TtsHelper.TextToSpeech(data.get("content").toString())).append("\"/>\n");
|
|
|
412
|
+ xml.append(" <action application=\"sleep\" data=\"1000\"/>\n <action application=\"playback\" data=\"").append(GetPath(TtsHelper.TextToSpeech(data.get("content").toString()))).append("\"/>\n");
|
|
380
|
413
|
}
|
|
381
|
414
|
break;
|
|
382
|
415
|
case queue:
|
|
|
@@ -420,6 +453,10 @@ public class IvrServiceImpl extends BaseServiceImpl<IvrMapper, Ivr> implements I
|
|
420
|
453
|
case hangup:
|
|
421
|
454
|
xml.append(" <action application=\"hangup\"/>\n");
|
|
422
|
455
|
break;
|
|
|
456
|
+ case robot:
|
|
|
457
|
+ xml.append(" <action application=\"set\" data=\"robot=1\"/>");
|
|
|
458
|
+ xml.append(" <action application=\"park\"/>");
|
|
|
459
|
+ break;
|
|
423
|
460
|
}
|
|
424
|
461
|
|
|
425
|
462
|
if (nodePaths.size() > 0) {
|
|
|
@@ -427,7 +464,7 @@ public class IvrServiceImpl extends BaseServiceImpl<IvrMapper, Ivr> implements I
|
|
427
|
464
|
IvrEdges path = nodePaths.get(0);
|
|
428
|
465
|
IvrProperties toNode = nodes.stream().filter(p -> p.getId().equals(path.getTargetNodeId())).findFirst().get();
|
|
429
|
466
|
if (toNode.getType().equals(IvrType.audiodtmf)) {
|
|
430
|
|
- xml.append(" <action application=\"ivr\" data=\"").append(toNode.getProperties().getName()).append( toNode.getId()).append("\"/>\n");
|
|
|
467
|
+ xml.append(" <action application=\"sleep\" data=\"1000\"/>\n <action application=\"ivr\" data=\"").append(toNode.getProperties().getName()).append( toNode.getId()).append("\"/>\n");
|
|
431
|
468
|
} else {
|
|
432
|
469
|
xml.append(" <action application=\"transfer\" data=\"${destination_number} XML ").append(toNode.getProperties().getName()).append( toNode.getId()).append("\"/>\n");
|
|
433
|
470
|
}
|
|
|
@@ -445,4 +482,37 @@ public class IvrServiceImpl extends BaseServiceImpl<IvrMapper, Ivr> implements I
|
|
445
|
482
|
return xml;
|
|
446
|
483
|
}
|
|
447
|
484
|
}
|
|
|
485
|
+
|
|
|
486
|
+ private static String GetPath(String filePath)
|
|
|
487
|
+ {
|
|
|
488
|
+ try
|
|
|
489
|
+ {
|
|
|
490
|
+ File file = new File(filePath);
|
|
|
491
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
492
|
+ String json= HttpHelper.sendUploadFile(middlewareUrl+"/Home/UploadSpeech",file);
|
|
|
493
|
+ AjaxResult ajaxResult = mapper.readValue(json, AjaxResult.class);
|
|
|
494
|
+ if (Objects.equals(ajaxResult.state, "success"))
|
|
|
495
|
+ {
|
|
|
496
|
+ return ajaxResult.data.toString();
|
|
|
497
|
+ }
|
|
|
498
|
+ else
|
|
|
499
|
+ {
|
|
|
500
|
+ return "";
|
|
|
501
|
+ }
|
|
|
502
|
+ }
|
|
|
503
|
+ catch (Exception e)
|
|
|
504
|
+ {
|
|
|
505
|
+
|
|
|
506
|
+ return "";
|
|
|
507
|
+ }
|
|
|
508
|
+
|
|
|
509
|
+ }
|
|
|
510
|
+ @Data
|
|
|
511
|
+ private static class AjaxResult {
|
|
|
512
|
+ private String state;
|
|
|
513
|
+ private String message;
|
|
|
514
|
+ private Object data;
|
|
|
515
|
+ }
|
|
|
516
|
+
|
|
|
517
|
+
|
|
448
|
518
|
}
|