Explorar el Código

Merge branch 'master-all' of http://192.168.1.222:3000/jiayi/callcenter-api into master-all

liyuanyuan hace 6 meses
padre
commit
bc2a5b8bdc

+ 232 - 10
hjzx-api/src/main/java/api/controller/call/IvrController.java

@@ -2,32 +2,53 @@ package api.controller.call;
2 2
 
3 3
 import api.controller.BaseController;
4 4
 import api.entity.database.call.Ivr;
5
+import api.entity.database.call.Mobile;
6
+import api.entity.database.call.RepConfig;
5 7
 import api.entity.input.PageInput;
6 8
 import api.model.AjaxResult;
7 9
 import api.service.call.IIvrService;
10
+import api.service.call.IMobileService;
11
+import api.service.call.IRepConfigService;
8 12
 import api.util.annotation.Anonymous;
9 13
 import api.util.annotation.Log;
10 14
 import api.util.enums.BusinessType;
15
+import api.util.helper.HttpHelper;
16
+import api.util.helper.SpringHelper;
11 17
 import api.util.helper.StringHelper;
12 18
 import com.alibaba.fastjson2.JSON;
13 19
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
20
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
14 21
 import com.baomidou.mybatisplus.core.metadata.IPage;
15 22
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
16 23
 import io.swagger.annotations.Api;
17 24
 import io.swagger.annotations.ApiOperation;
25
+import lombok.var;
18 26
 import org.springframework.beans.factory.annotation.Autowired;
19 27
 import org.springframework.web.bind.annotation.*;
20 28
 
29
+import java.math.BigDecimal;
30
+import java.math.RoundingMode;
31
+import java.time.LocalDate;
32
+import java.time.format.DateTimeFormatter;
21 33
 import java.util.Arrays;
22 34
 import java.util.Date;
35
+import java.util.Map;
36
+import java.util.concurrent.CompletableFuture;
37
+import java.util.concurrent.TimeUnit;
23 38
 
24 39
 @Api(value = "ivr流程管理",tags = "ivr流程管理")
25 40
 @RestController
26 41
 @RequestMapping("/call/ivr")
42
+@Anonymous
27 43
 public class IvrController extends BaseController {
28 44
     @Autowired
29 45
     private IIvrService ivrService;
30
-
46
+    @Autowired
47
+    private IRepConfigService configService;
48
+    @Autowired
49
+    private IMobileService mobileService;
50
+    @Autowired
51
+    public  static  final String middlewareUrl= SpringHelper.getRequiredProperty("spring.middlewareUrl");
31 52
     @ApiOperation("列表")
32 53
     @Log(title = "查询call_ivr列表",businessType = BusinessType.QUERY)
33 54
     @GetMapping
@@ -60,23 +81,143 @@ public class IvrController extends BaseController {
60 81
     public AjaxResult add(@RequestBody Ivr input) {
61 82
         LambdaQueryWrapper<Ivr> qw = new LambdaQueryWrapper();
62 83
         qw.eq(Ivr::getName, input.getName());
84
+
63 85
         if (ivrService.getCount(qw) > 0) {
64 86
             return Error("此名称已经存在");
65 87
         }
66
-
67
-        //input.setCreateBy(CurrentUser().getUserName());
88
+        LambdaQueryWrapper<Ivr> queryWrapper = new LambdaQueryWrapper<>();
89
+        queryWrapper.orderByDesc(Ivr::getIvrId).last("limit 1");;
90
+        Map<String, Object> map = ivrService.getMapFirst(queryWrapper);
91
+        if (map != null &&map.get("version")!=null&& StringHelper.isNotEmpty(map.get("version").toString()) ) {
92
+            try {
93
+                BigDecimal num = new BigDecimal(map.get("version").toString())
94
+                        .setScale(1, RoundingMode.HALF_UP);
95
+                // 加上0.1并格式化结果
96
+                BigDecimal result = num.add(new BigDecimal("0.1"));
97
+                String formatted = String.format("%.1f", result); // 格式化为一位小数
98
+                input.setVersion(formatted);
99
+            }
100
+            catch (Exception E)
101
+            {
102
+            }
103
+        }
104
+        input.setState(0L);
68 105
         input.setCreateTime(new Date());
69 106
         input.setDelFlag("0");
70
-        boolean result = ivrService.insert(input);
71
-        if (result) {
72
-            return Success("成功");
107
+        boolean n = ivrService.insert(input);
108
+        if (n) {
109
+            CompletableFuture.supplyAsync(() -> {
110
+                ivrService.dealIvr(input);
111
+                input.setState(1L);
112
+                ivrService.update(input);
113
+                return null;
114
+            }).thenAccept(result -> System.out.println("Result: " + result));
115
+            return  Success("新增成功");
73 116
         } else {
74 117
             return Error("新增失败");
75 118
         }
119
+        //input.setCreateBy(CurrentUser().getUserName());
76 120
     }
77 121
 
122
+    @ApiOperation("启用ivr")
123
+    @Log(title = "启用ivr",businessType = BusinessType.UPDATE)
124
+    @GetMapping("/Enable/{id}")
125
+    public AjaxResult Enable(@PathVariable long id)  {
126
+        Ivr model=ivrService.getEntity(id);
127
+        if (model!=null)
128
+        {
129
+            if(model.getState()==0)
130
+            {
131
+                return  Error("当前ivr还未生成");
132
+            }
133
+            LambdaUpdateWrapper<Ivr> qu=new LambdaUpdateWrapper<>();
134
+            qu .eq(Ivr::getIsEnable,1L);
135
+            qu.set(Ivr::getIsEnable,0L);
136
+            ivrService.updateBatch(qu);
137
+            model.setIsEnable(1L);
138
+            HttpHelper.sendGet(middlewareUrl+"/ivr/delete");
139
+            if (ivrService.update(model))
140
+            {
141
+                return  Success("启用成功");
142
+            }
143
+            else
144
+            {
145
+                return  Error("启用失败");
146
+            }
147
+        }
148
+        else
149
+        {
150
+            return  Error("该ivr不存在");
151
+        }
152
+    }
153
+    @ApiOperation("获取当前测试号码")
154
+    @Log(title = "获取当前测试号码",businessType = BusinessType.QUERY)
155
+    @GetMapping("/TestPhone")
156
+    public AjaxResult TestPhone()  {
157
+        return Success("获取成功",configService.getConfigValue("TestCode"))  ;
158
+    }
159
+    @ApiOperation("启用测试ivr")
160
+    @Log(title = "启用测试ivr",businessType = BusinessType.UPDATE)
161
+    @GetMapping("/TestEnable/{id}")
162
+    public AjaxResult TestEnable(@PathVariable long id,@RequestParam String testPhone)  {
163
+        Ivr model=ivrService.getEntity(id);
164
+        if (model!=null)
165
+        {
166
+            if(model.getState()==0)
167
+            {
168
+                return  Error("当前ivr还未生成");
169
+            }
170
+            if(model.getIsEnable()==1)
171
+            {
172
+                return  Error("当前ivr已启用不可设置为测试ivr");
173
+            } else if (model.getIsEnable()==2) {
174
+                return  Error("当前ivr已被设置为测试ivr不用重复设置");
175
+            }
176
+            if (StringHelper.isNotEmpty(testPhone))
177
+            {   String phone1= testPhone.trim();
178
+                if (phone1.length()!=11)
179
+                {
180
+                    return Error("请输入正确的测试手机号码");
181
+                }
182
+                String fix = ""; String bfix = ""; String wfix = "0";
183
+                String zipcode = "0371";
184
+                int zip = GetZipCodeByPhone(phone1, zipcode);
185
+                if (zip == 1)
186
+                {
187
+                    fix = bfix;
188
+                }
189
+                else if (zip == 2)
190
+                {
191
+                    fix = wfix;
192
+                }
193
+                phone1=fix+phone1;
194
+                LambdaUpdateWrapper<RepConfig> qr=new LambdaUpdateWrapper<>();
195
+                qr .eq(RepConfig::getCode,"TestCode");
196
+                qr.set(RepConfig::getValue,phone1);
197
+                configService.updateBatch(qr);
78 198
 
79
-
199
+            }
200
+            //取消之前的测试ivr
201
+            LambdaUpdateWrapper<Ivr> qu=new LambdaUpdateWrapper<>();
202
+            qu .eq(Ivr::getIsEnable,2L);
203
+            qu.set(Ivr::getIsEnable,0L);
204
+            ivrService.updateBatch(qu);
205
+            HttpHelper.sendGet(middlewareUrl+"/ivr/deleteTest");
206
+            model.setIsEnable(2L);
207
+            if (ivrService.update(model))
208
+            {
209
+                return  Success("启用成功");
210
+            }
211
+            else
212
+            {
213
+                return  Error("启用失败");
214
+            }
215
+        }
216
+        else
217
+        {
218
+            return  Error("该ivr不存在");
219
+        }
220
+    }
80 221
     @ApiOperation("编辑")
81 222
     @Log(title = "编辑call_ivr",businessType = BusinessType.UPDATE)
82 223
     @PutMapping
@@ -88,10 +229,17 @@ public class IvrController extends BaseController {
88 229
             return Error("此名称已经存在");
89 230
         }
90 231
         input.setUpdateBy(CurrentUser().getUserName());
232
+        input.setState(0L);
91 233
         input.setUpdateTime(new Date());
92
-        boolean result = ivrService.update(input);
93
-        if (result) {
94
-            return Success("成功");
234
+        boolean n = ivrService.update(input);
235
+        if (n) {
236
+            CompletableFuture.supplyAsync(() -> {
237
+                ivrService.dealIvr(input);
238
+                input.setState(1L);
239
+                ivrService.update(input);
240
+                return null;
241
+            }).thenAccept(result -> System.out.println("Result: " + result));
242
+            return  Success("成功");
95 243
         } else {
96 244
             return Error("修改失败");
97 245
         }
@@ -118,5 +266,79 @@ public class IvrController extends BaseController {
118 266
                 "]";
119 267
         return Success("成功", JSON.parseArray(json));
120 268
     }
269
+    /// <summary>
270
+    /// 根据号码和区号判断号码是否为归属地号码
271
+    /// 返回0为分机号或特殊号码
272
+    /// 返回1为本地号码
273
+    /// 返回2为外地号码
274
+    /// </summary>
275
+    /// <param name="phone"></param>
276
+    /// <param name="zipcode"></param>
277
+    /// <returns></returns>
278
+    private int GetZipCodeByPhone(String phone,String zipcode)
279
+    {
280
+        int res = 0;
281
+        if (phone.length() >= 7)
282
+        {
283
+            //7位及7位以上是固定电话或手机
284
+            //判断是否手机
285
+            if (phone.length() == 11 && phone.charAt(0) == '1')
286
+            {//号码为11位,首位是1,为手机号
287
+                LambdaQueryWrapper<Mobile> qw = new LambdaQueryWrapper<>();
288
+                qw.eq( Mobile::getMobilePrefix, phone.substring(0,7));
289
+                var mobileModel=mobileService.getEntity(qw);
290
+                if (mobileModel != null)
291
+                {
292
+                    if (mobileModel.getLocationCode().equals(zipcode))
293
+                    {
294
+                        res = 1;
295
+                    }
296
+                    else
297
+                    {
298
+                        res = 2;
299
+                    }
300
+                }
301
+            }
302
+            else
303
+            {
304
+                if (phone.length()== 11 && phone.substring(0, 3).equals(zipcode))
305
+                {//号码为11位
306
+                    //截取前三位区号判断是否本地
307
+                    boolean resbd3 = phone.substring(0, 3).equals(zipcode);
308
+                    //截取前四位区号判断是否本地
309
+                    boolean resbd4 = phone.substring(0, 4).equals(zipcode);
310
+                    if (resbd3 || resbd4)
311
+                    {
312
+                        res = 3;
313
+                    }
314
+                    else
315
+                    {
316
+                        res = 4;
317
+                    }
318
+                }
319
+                else if (phone.length() < 11)
320
+                {//号码小于11位,为本地
321
+                    if (phone.substring(0, 1).equals("0"))
121 322
 
323
+                    {
324
+                        if (phone.substring(0, 4).equals(zipcode))
325
+                            res = 3;
326
+                        else
327
+                            res = 4;
328
+                    }
329
+                    else
330
+                        res = 3;
331
+                }
332
+                else if (phone.length() > 11 && phone.substring(0, 4).equals(zipcode))
333
+                {//号码大于11位,截取前四位区号判断是否本地
334
+                    res = 3;
335
+                }
336
+                else
337
+                {
338
+                    res = 4;
339
+                }
340
+            }
341
+        }
342
+        return res;
343
+    }
122 344
 }

+ 2 - 1
hjzx-api/src/main/resources/application-dev.yml

@@ -6,7 +6,7 @@ spring:
6 6
   datasource:
7 7
     type: com.alibaba.druid.pool.DruidDataSource
8 8
     driver-class-name: com.mysql.cj.jdbc.Driver
9
-    url: jdbc:mysql://192.168.1.8:3306/hjzx_rjmx?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
9
+    url: jdbc:mysql://192.168.1.8:3306/hjzx_xy?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
10 10
     username: root
11 11
     password: 800100
12 12
 
@@ -76,3 +76,4 @@ spring:
76 76
   isNote: 1
77 77
   pushUrl: 192.168.1.15:8320/Home/receiveCall
78 78
   curlUrl: http://192.168.1.15:8320/
79
+  middlewareUrl: http://192.168.1.19:9000/

+ 1 - 0
hjzx-api/src/main/resources/application-production.yml

@@ -42,3 +42,4 @@ spring:
42 42
   isNote: 1
43 43
   pushUrl: 192.168.1.15:8320/Home/receiveCall
44 44
   curlUrl: http://192.168.1.15:8320/
45
+  middlewareUrl: http://127.0.0.1:9000/

+ 7 - 0
hjzx-entity/src/main/java/api/entity/database/call/Ivr.java

@@ -59,4 +59,11 @@ public class Ivr {
59 59
     /** 删除时间 */
60 60
     @ApiModelProperty("删除时间")
61 61
     private Date delTime;
62
+    /** 是否启用0否1是 */
63
+    @ApiModelProperty("是否启用0否1是")
64
+    private Long isEnable;
65
+    /** 0生成中1已生成 */
66
+    @ApiModelProperty("0生成中1已生成")
67
+    private Long state;
68
+
62 69
 }

+ 25 - 0
hjzx-entity/src/main/java/api/entity/database/call/RepConfig.java

@@ -0,0 +1,25 @@
1
+package api.entity.database.call;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableId;
5
+import com.baomidou.mybatisplus.annotation.TableName;
6
+import io.swagger.annotations.ApiModelProperty;
7
+import lombok.Data;
8
+
9
+@Data
10
+@TableName("rep_config")
11
+public class RepConfig {
12
+    /** 自增主键 */
13
+    @ApiModelProperty("自增主键")
14
+    @TableId(type = IdType.AUTO)
15
+    private Integer id;
16
+    /** 编码 */
17
+    @ApiModelProperty("编码")
18
+    private String code;
19
+    /** 值 */
20
+    @ApiModelProperty("值")
21
+    private String value;
22
+    /** 描述 */
23
+    @ApiModelProperty("描述")
24
+    private String remark;
25
+}

+ 9 - 0
hjzx-mapper/src/main/java/api/mapper/call/RepConfigMapper.java

@@ -0,0 +1,9 @@
1
+package api.mapper.call;
2
+
3
+import api.entity.database.call.RepConfig;
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+@Mapper
8
+public interface RepConfigMapper extends BaseMapper<RepConfig> {
9
+}

+ 3 - 0
hjzx-service/src/main/java/api/service/call/IIvrService.java

@@ -4,4 +4,7 @@ import api.entity.database.call.Ivr;
4 4
 import api.service.IBaseService;
5 5
 
6 6
 public interface IIvrService extends IBaseService<Ivr> {
7
+    //处理ivr
8
+    void dealIvr(Ivr entity);
9
+
7 10
 }

+ 8 - 0
hjzx-service/src/main/java/api/service/call/IRepConfigService.java

@@ -0,0 +1,8 @@
1
+package api.service.call;
2
+
3
+import api.entity.database.call.RepConfig;
4
+import api.service.IBaseService;
5
+
6
+public interface IRepConfigService extends IBaseService<RepConfig> {
7
+    String getConfigValue(String code);
8
+}

+ 103 - 33
hjzx-service/src/main/java/api/service/call/impl/IvrServiceImpl.java

@@ -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
 }

+ 27 - 0
hjzx-service/src/main/java/api/service/call/impl/RepConfigServiceImpl.java

@@ -0,0 +1,27 @@
1
+package api.service.call.impl;
2
+
3
+import api.entity.database.call.RepConfig;
4
+import api.mapper.call.RepConfigMapper;
5
+import api.service.BaseServiceImpl;
6
+import api.service.call.IRepConfigService;
7
+import org.springframework.stereotype.Service;
8
+import org.springframework.transaction.annotation.Transactional;
9
+
10
+
11
+import java.util.List;
12
+import java.util.stream.Collectors;
13
+@Transactional
14
+@Service
15
+public class RepConfigServiceImpl extends BaseServiceImpl<RepConfigMapper, RepConfig> implements IRepConfigService {
16
+    public RepConfigServiceImpl(){ super(true); }
17
+
18
+    @Override
19
+    public String getConfigValue(String code) {
20
+        List<RepConfig> configs = getList().stream().filter(p->p.getCode().equals(code)).collect(Collectors.toList());
21
+        if (configs.size()>0) {
22
+            return configs.get(0).getValue();
23
+        } else {
24
+            return null;
25
+        }
26
+    }
27
+}

+ 3 - 1
hjzx-util/src/main/java/api/util/enums/IvrType.java

@@ -66,5 +66,7 @@ public enum IvrType
66 66
      * 挂机
67 67
      */
68 68
 
69
-    hangup
69
+    hangup,
70
+
71
+    robot
70 72
 }

+ 42 - 4
hjzx-util/src/main/java/api/util/helper/HttpHelper.java

@@ -20,10 +20,7 @@ import org.springframework.stereotype.Component;
20 20
 
21 21
 import javax.net.ssl.*;
22 22
 import java.io.*;
23
-import java.net.ConnectException;
24
-import java.net.SocketTimeoutException;
25
-import java.net.URL;
26
-import java.net.URLConnection;
23
+import java.net.*;
27 24
 import java.nio.charset.Charset;
28 25
 import java.nio.charset.StandardCharsets;
29 26
 import java.security.cert.X509Certificate;
@@ -45,6 +42,11 @@ public class HttpHelper {
45 42
         return sendGet(url, "");
46 43
     }
47 44
 
45
+    public static String sendUploadFile(String url,File file) throws IOException {
46
+        return uploadFile(url, file);
47
+    }
48
+
49
+
48 50
     /**
49 51
      * 向指定 URL 发送GET方法的请求
50 52
      *
@@ -374,7 +376,43 @@ public class HttpHelper {
374 376
             httpClient.close();
375 377
         }
376 378
     }
379
+    public static String uploadFile(String apiUrl, File file) throws IOException {
380
+        String BOUNDARY = "----WebKitFormBoundary" + System.currentTimeMillis();
381
+        HttpURLConnection conn = (HttpURLConnection) new URL(apiUrl).openConnection();
382
+        conn.setDoOutput(true);
383
+        conn.setRequestMethod("POST");
384
+        conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
377 385
 
386
+        try (OutputStream os = conn.getOutputStream();
387
+             InputStream is = new FileInputStream(file)) {
388
+            // 构建请求体
389
+            String header = "--" + BOUNDARY + "\r\n" +
390
+                    "Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getName() + "\"\r\n" +
391
+                    "Content-Type: application/octet-stream\r\n\r\n";
392
+            os.write(header.getBytes());
393
+
394
+            // 写入文件流
395
+            byte[] buffer = new byte[4096];
396
+            int bytesRead;
397
+            while ((bytesRead = is.read(buffer)) != -1) {
398
+                os.write(buffer, 0, bytesRead);
399
+            }
400
+            os.write(("\r\n--" + BOUNDARY + "--\r\n").getBytes());
401
+        }
402
+        StringBuilder result=new StringBuilder();
403
+        // 处理响应
404
+        if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
405
+            try (InputStream resIs = conn.getInputStream()) {
406
+                BufferedReader reader = new BufferedReader(new InputStreamReader(resIs));
407
+                String line;
408
+                while ((line = reader.readLine()) != null)
409
+                {
410
+                    result.append(line);
411
+                }
412
+            }
413
+        }
414
+        return result.toString();
415
+    }
378 416
     /**
379 417
      * 简化版 - 发送 form-data 格式的 POST 请求(不带请求头)
380 418
      *

+ 3 - 4
hjzx-util/src/main/java/api/util/helper/TtsHelper.java

@@ -54,8 +54,7 @@ public class TtsHelper {
54 54
     }
55 55
     public  static  final String curlUrl= SpringHelper.getRequiredProperty("spring.curlUrl");;
56 56
     public static String TextToSpeech(String word) {
57
-         String path=curlUrl+TextToSpeech(word, "");
58
-        return path;
57
+        return  TextToSpeech(word, "");
59 58
     }
60 59
 
61 60
     public static String TextToSpeech(String word, String filename) {
@@ -71,8 +70,8 @@ public class TtsHelper {
71 70
         String filePath = file.getAbsolutePath() + "/" + filename + ".wav";
72 71
 
73 72
         transfer(word,filePath);
74
-
75
-        return parentPath+ "/" + filename + ".wav";
73
+       // String path= "/" +parentPath+"/" + filename + ".wav";
74
+        return filePath;
76 75
     }
77 76
 
78 77
     public static String TextToSpeechAgent(String word, String filename) {