FsConfController.java 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379
  1. package com.ruoyi.cc.controller;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.ruoyi.aicall.domain.CcCallPhone;
  5. import com.ruoyi.aicall.service.ICcCallPhoneService;
  6. import com.ruoyi.aicall.service.ICcInboundLlmAccountService;
  7. import com.ruoyi.cc.domain.CcInboundCdr;
  8. import com.ruoyi.cc.domain.CcOutboundCdr;
  9. import com.ruoyi.cc.domain.CcParams;
  10. import com.ruoyi.cc.model.FsConfProfile;
  11. import com.ruoyi.cc.model.FsMod;
  12. import com.ruoyi.cc.model.ProfileRegExtnumModel;
  13. import com.ruoyi.cc.model.ProfileStatusModel;
  14. import com.ruoyi.cc.service.*;
  15. import com.ruoyi.common.core.controller.BaseController;
  16. import com.ruoyi.common.core.domain.AjaxResult;
  17. import com.ruoyi.common.core.page.TableDataInfo;
  18. import com.ruoyi.common.utils.CommonUtils;
  19. import com.ruoyi.common.utils.DateUtils;
  20. import com.ruoyi.common.utils.StringUtils;
  21. import com.ruoyi.framework.web.domain.server.Sys;
  22. import link.thingscloud.freeswitch.esl.EslConnectionUtil;
  23. import link.thingscloud.freeswitch.esl.transport.message.EslMessage;
  24. import org.apache.shiro.authz.annotation.RequiresPermissions;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.stereotype.Controller;
  27. import org.springframework.ui.ModelMap;
  28. import org.springframework.util.CollectionUtils;
  29. import org.springframework.web.bind.annotation.*;
  30. import org.w3c.dom.Document;
  31. import org.w3c.dom.Element;
  32. import org.w3c.dom.Node;
  33. import org.w3c.dom.NodeList;
  34. import org.xml.sax.InputSource;
  35. import javax.servlet.http.HttpServletResponse;
  36. import javax.xml.parsers.DocumentBuilder;
  37. import javax.xml.parsers.DocumentBuilderFactory;
  38. import java.io.IOException;
  39. import java.io.OutputStream;
  40. import java.io.StringReader;
  41. import java.net.URLEncoder;
  42. import java.nio.charset.StandardCharsets;
  43. import java.text.SimpleDateFormat;
  44. import java.util.ArrayList;
  45. import java.util.Date;
  46. import java.util.List;
  47. /**
  48. * freeswitch配置文件控制层
  49. */
  50. @Controller
  51. @RequestMapping("/cc/fsconf")
  52. public class FsConfController extends BaseController {
  53. @Autowired
  54. private IFsConfService fsConfService;
  55. @Autowired
  56. private IFsVariablesService fsVariablesService;
  57. @Autowired
  58. private ICcParamsService ccParamsService;
  59. @Autowired
  60. private ICcGatewaysService ccGatewaysService;
  61. @Autowired
  62. private ICcCallPhoneService callPhoneService;
  63. @Autowired
  64. private ICcInboundCdrService inboundCdrService;
  65. @Autowired
  66. private ICcOutboundCdrService outboundCdrService;
  67. /**
  68. * 系统全局配置
  69. * @return
  70. */
  71. @RequiresPermissions("cc:switchconf:view")
  72. @GetMapping(value = "/switchconf")
  73. public String switchConf() {
  74. return "cc/switchconf/switchconf";
  75. }
  76. /**
  77. * 保存系统全局配置
  78. * @param params
  79. * @return
  80. */
  81. @PostMapping(value = "/setSwitchConf")
  82. @ResponseBody
  83. public AjaxResult setSwitchConf(@RequestBody JSONArray params) {
  84. fsConfService.setSwitchConf(params);
  85. return AjaxResult.success("设置成功!");
  86. }
  87. /**
  88. * 重启fs服务
  89. * @return
  90. */
  91. @GetMapping(value = "/restartFs")
  92. @ResponseBody
  93. public AjaxResult restartFs() {
  94. fsConfService.restartFs();
  95. return AjaxResult.success("重启成功!");
  96. }
  97. /**
  98. * 获取系统全局配置
  99. * @return
  100. */
  101. @GetMapping(value = "/getSwitchConf")
  102. @ResponseBody
  103. public AjaxResult getSwitchConf() {
  104. // 配置文件所有配置
  105. JSONObject confAllVars = fsConfService.getSwitchConf();
  106. // 可配置的基本配置,其他的为隐藏的高级配置
  107. JSONObject fsVars = fsVariablesService.getFsVariablesByCat(2); // key: 参数名, value:别名
  108. JSONArray baseConfigs = new JSONArray();
  109. JSONArray advancedConfigs = new JSONArray();
  110. for (String name: confAllVars.keySet()) {
  111. JSONObject var = new JSONObject();
  112. var.put("name", name);
  113. var.put("value", confAllVars.getString(name));
  114. if (fsVars.keySet().contains(name)) {
  115. // 基本配置
  116. var.put("aliasName", fsVars.getString(name)); // 别名
  117. baseConfigs.add(var);
  118. } else {
  119. // 高级配置
  120. var.put("aliasName", name); // 高级配置没有别名
  121. advancedConfigs.add(var);
  122. }
  123. }
  124. JSONObject result = new JSONObject();
  125. result.put("baseConfigs", baseConfigs);
  126. result.put("advancedConfigs", advancedConfigs);
  127. return AjaxResult.success("success", result);
  128. }
  129. /**
  130. * 全局编码配置
  131. * @return
  132. */
  133. @RequiresPermissions("cc:varsconf:view")
  134. @GetMapping(value = "/varsconf")
  135. public String varsConf() {
  136. return "cc/varsconf/varsconf";
  137. }
  138. /**
  139. * 保存全局编码配置
  140. * @param params
  141. * @return
  142. */
  143. @PostMapping(value = "/setVarsConf")
  144. @ResponseBody
  145. public AjaxResult setVarsConf(@RequestBody JSONArray params) {
  146. fsConfService.setVarsConf(params);
  147. return AjaxResult.success("设置成功!");
  148. }
  149. /**
  150. * 获取全局编码配置
  151. * @return
  152. */
  153. @GetMapping(value = "/getVarsConf")
  154. @ResponseBody
  155. public AjaxResult getVarsConf() {
  156. // 配置文件所有配置
  157. JSONObject confAllVars = fsConfService.getVarsConf();
  158. // 可配置的基本配置,其他的为隐藏的高级配置(1. vars.xml 2. switch.conf.xml 3. profile 4. xunfei_asr 5. aliyun asr)
  159. JSONObject fsVars = fsVariablesService.getFsVariablesByCat(1); // key: 参数名, value:别名
  160. JSONArray baseConfigs = new JSONArray();
  161. JSONArray advancedConfigs = new JSONArray();
  162. for (String name: confAllVars.keySet()) {
  163. JSONObject var = new JSONObject();
  164. var.put("name", name);
  165. var.put("value", confAllVars.getString(name));
  166. if (fsVars.keySet().contains(name)) {
  167. // 基本配置
  168. var.put("aliasName", fsVars.getString(name)); // 别名
  169. baseConfigs.add(var);
  170. } else {
  171. // 高级配置
  172. var.put("aliasName", name); // 高级配置没有别名
  173. advancedConfigs.add(var);
  174. }
  175. }
  176. JSONObject result = new JSONObject();
  177. result.put("baseConfigs", baseConfigs);
  178. result.put("advancedConfigs", advancedConfigs);
  179. return AjaxResult.success("success", result);
  180. }
  181. /**
  182. * ASR(讯飞)参数配置
  183. * @return
  184. */
  185. @RequiresPermissions("cc:xunfeiasrconf:view")
  186. @GetMapping(value = "/xunfeiasrconf")
  187. public String xunfeiAsrConf() {
  188. return "cc/xunfeiasrconf/xunfeiasrconf";
  189. }
  190. /**
  191. * FunAsr参数配置
  192. * @return
  193. */
  194. @RequiresPermissions("cc:funasrconf:view")
  195. @GetMapping(value = "/funasrconf")
  196. public String funAsrConf() {
  197. return "cc/funasrconf/funasrconf";
  198. }
  199. /**
  200. * TTS(阿里)参数配置
  201. * @return
  202. */
  203. @RequiresPermissions("cc:alittsconf:view")
  204. @GetMapping(value = "/alittsconf")
  205. public String aliTtsConf() {
  206. return "cc/alittsconf/alittsconf";
  207. }
  208. /**
  209. * TTS(科大讯飞)参数配置
  210. * @return
  211. */
  212. @RequiresPermissions("cc:xfttsconf:view")
  213. @GetMapping(value = "/xfttsconf")
  214. public String xfTtsConf() {
  215. return "cc/xfttsconf/xfttsconf";
  216. }
  217. /**
  218. * 获取阿里云tts配置
  219. * @return
  220. */
  221. @GetMapping(value = "/getAliTtsConf")
  222. @ResponseBody
  223. public AjaxResult getAliTtsConf() {
  224. String asrFileName = "/autoload_configs/aliyun_tts.conf.xml";
  225. return getConfigFileJsonData(asrFileName, 5);
  226. }
  227. /**
  228. * 获取讯飞tts配置
  229. * @return
  230. */
  231. @GetMapping(value = "/getXfTtsConf")
  232. @ResponseBody
  233. public AjaxResult getXfTtsConf() {
  234. String asrFileName = "/autoload_configs/xf_tts.conf.xml";
  235. return getConfigFileJsonData(asrFileName, 5);
  236. }
  237. /**
  238. * 豆包tts 参数配置
  239. * @return
  240. */
  241. @RequiresPermissions("cc:doubaottsconf:view")
  242. @GetMapping(value = "/doubaottsconf")
  243. public String doubaoTtsConf() {
  244. return "cc/doubaottsconf/doubaottsconf";
  245. }
  246. /**
  247. * 获取豆包tts配置
  248. * @return
  249. */
  250. @GetMapping(value = "/getDoubaoTtsConf")
  251. @ResponseBody
  252. public AjaxResult getDoubaoTtsConf() {
  253. String fileName = "/autoload_configs/doubao_vcl_tts.conf.xml";
  254. return getConfigFileJsonData(fileName, 5);
  255. }
  256. /**
  257. * 保存Doubao TTS配置
  258. * @param params
  259. * @return
  260. */
  261. @PostMapping(value = "/setDoubaoTtsConf")
  262. @ResponseBody
  263. public AjaxResult setDoubaoTtsConf(@RequestBody JSONArray params) {
  264. String asrFileName = "/autoload_configs/doubao_vcl_tts.conf.xml";
  265. String moduleName = "mod_doubao_vcl_tts";
  266. AjaxResult result = saveAndReloadTtsModule("doubao-tts-account-json",
  267. asrFileName, moduleName, params);
  268. return result;
  269. }
  270. /**
  271. * ASR(阿里)参数配置
  272. * @return
  273. */
  274. @RequiresPermissions("cc:aliasrconf:view")
  275. @GetMapping(value = "/aliasrconf")
  276. public String aliAsrConf() {
  277. return "cc/aliasrconf/aliasrconf";
  278. }
  279. /**
  280. * ASR(阿里新模块)参数配置
  281. * @return
  282. */
  283. @RequiresPermissions("cc:aliasrbridgeconf:view")
  284. @GetMapping(value = "/aliasrbridgeconf")
  285. public String aliAsrBridgeConf() {
  286. return "cc/aliasrbridgeconf/aliasrbridgeconf";
  287. }
  288. /**
  289. * ASR(腾讯新模块)参数配置
  290. * @return
  291. */
  292. @RequiresPermissions("cc:txasrbridgeconf:view")
  293. @GetMapping(value = "/txasrbridgeconf")
  294. public String txAsrBridgeConf() {
  295. return "cc/txasrbridgeconf/txasrbridgeconf";
  296. }
  297. /**
  298. * ASR(腾讯MPS字幕模块)参数配置
  299. * @return
  300. */
  301. @RequiresPermissions("cc:txasr1bridgeconf:view")
  302. @GetMapping(value = "/txasr1bridgeconf")
  303. public String txAsr1BridgeConf() {
  304. return "cc/txasr1bridgeconf/txasr1bridgeconf";
  305. }
  306. /**
  307. * 获取ASR配置
  308. * @return
  309. */
  310. @GetMapping(value = "/getAliAsrConf")
  311. @ResponseBody
  312. public AjaxResult getAliAsrConf() {
  313. String asrFileName = "/autoload_configs/aliyun_asr.conf.xml";
  314. return getConfigFileJsonData(asrFileName, 5);
  315. }
  316. /**
  317. * 获取新 ASR 模块配置
  318. * @return
  319. */
  320. @GetMapping(value = "/getAliBridgeAsrConf")
  321. @ResponseBody
  322. public AjaxResult getAliBridgeAsrConf() {
  323. String asrFileName = "/autoload_configs/ali_asr.conf.xml";
  324. return getConfigFileJsonData(asrFileName, 5);
  325. }
  326. /**
  327. * 获取腾讯 ASR 模块配置
  328. * @return
  329. */
  330. @GetMapping(value = "/getTxBridgeAsrConf")
  331. @ResponseBody
  332. public AjaxResult getTxBridgeAsrConf() {
  333. String asrFileName = "/autoload_configs/tx_asr.conf.xml";
  334. return getConfigFileJsonData(asrFileName, 5);
  335. }
  336. /**
  337. * 获取腾讯 ASR1 模块配置
  338. * @return
  339. */
  340. @GetMapping(value = "/getTxBridgeAsr1Conf")
  341. @ResponseBody
  342. public AjaxResult getTxBridgeAsr1Conf() {
  343. String asrFileName = "/autoload_configs/tx_asr1.conf.xml";
  344. return getConfigFileJsonData(asrFileName, 5);
  345. }
  346. /**
  347. * 获取FunASR配置
  348. * @return
  349. */
  350. @GetMapping(value = "/getFunAsrConf")
  351. @ResponseBody
  352. public AjaxResult getFunAsrConf() {
  353. return getConfigFileJsonData("/autoload_configs/funasr.conf.xml", 4);
  354. }
  355. @GetMapping(value = "/chinatelecomasrconf")
  356. public String chinatelecomAsrConf() {
  357. return "cc/chinatelecomasrconf/chinatelecomasrconf";
  358. }
  359. @GetMapping(value = "/chinatelecomttsconf")
  360. public String chinatelecomTtsConf() {
  361. return "cc/chinatelecomttsconf/chinatelecomttsconf";
  362. }
  363. @GetMapping(value = "/getChinatelecomAsrConf")
  364. @ResponseBody
  365. public AjaxResult getChinatelecomAsrConf() {
  366. String asrFileName = "/autoload_configs/chinatelecom_asr.conf.xml";
  367. return getConfigFileJsonData(asrFileName, 5);
  368. }
  369. @GetMapping(value = "/getChinatelecomTtsConf")
  370. @ResponseBody
  371. public AjaxResult getChinatelecomTtsConf() {
  372. String fileName = "/autoload_configs/chinatelecom_tts.conf.xml";
  373. return getConfigFileJsonData(fileName, 5);
  374. }
  375. /**
  376. * 获取ASR配置
  377. * @return
  378. */
  379. @GetMapping(value = "/getXunfeiAsrConf")
  380. @ResponseBody
  381. public AjaxResult getXunfeiAsrConf() {
  382. return getConfigFileJsonData("/autoload_configs/xunfei_asr.conf.xml", 4);
  383. }
  384. private AjaxResult getConfigFileJsonData(String configFile, int cat){
  385. JSONObject confAllVars = fsConfService.getAsrConf(configFile);
  386. if(confAllVars.size() != 0) {
  387. JSONObject fsVars = fsVariablesService.getFsVariablesByCat(cat); // key: 参数名, value:别名
  388. JSONArray baseConfigs = new JSONArray();
  389. for (String name : confAllVars.keySet()) {
  390. JSONObject var = new JSONObject();
  391. var.put("name", name);
  392. boolean hidden = fsConfService.checkNeedHidden(name);
  393. // server_url_webapi不需要加密
  394. if ("server_url_webapi".equals(name)) {
  395. hidden = false;
  396. }
  397. if(hidden){
  398. var.put("value", CommonUtils.maskStringUtil(confAllVars.getString(name)));
  399. }else {
  400. var.put("value", confAllVars.getString(name));
  401. }
  402. if (fsVars.keySet().contains(name)) {
  403. // 基本配置
  404. var.put("aliasName", fsVars.getString(name)); // 别名
  405. baseConfigs.add(var);
  406. } else {
  407. // 高级配置
  408. var.put("aliasName", name); // 高级配置没有别名
  409. baseConfigs.add(var);
  410. }
  411. }
  412. return AjaxResult.success("success", baseConfigs);
  413. }else{
  414. return AjaxResult.error(String.format("config file not found: %s", configFile));
  415. }
  416. }
  417. private AjaxResult saveAndReloadAsrModule(String asrFileName, String moduleName, JSONArray params, String asrProvider){
  418. String result = fsConfService.setAsrConf(params, asrFileName);
  419. if(StringUtils.isEmpty(result)) {
  420. // 更新cc_params参数表
  421. ccParamsService.updateParamsValue("sys-asr-provider", asrProvider);
  422. String reloadRsp = ccParamsService.reloadParams();
  423. if(!reloadRsp.equalsIgnoreCase("success")){
  424. return error("参数修改成功, 但是刷新失败, 请手动重启 call-center!");
  425. }
  426. // reload
  427. EslMessage resp = EslConnectionUtil.sendSyncApiCommand("reload", moduleName);
  428. String respText = CommonUtils.ListToString(resp.getBodyLines());
  429. if(respText.contains("OK module loaded")) {
  430. return AjaxResult.success("配置写入成功!\n 模块已成功加载!");
  431. }else{
  432. return AjaxResult.error("配置写入成功!\n 但是模块加载失败! \n" + respText);
  433. }
  434. }else{
  435. return AjaxResult.error("配置文件写入失败!\n " + result);
  436. }
  437. }
  438. private AjaxResult saveAndReloadTtsModule(String paramCode, String asrFileName, String moduleName, JSONArray params){
  439. String result = fsConfService.setAsrConf(params, asrFileName);
  440. if(StringUtils.isEmpty(result)) {
  441. if (StringUtils.isNotEmpty(paramCode)) {
  442. String ttsAccountJson = ccParamsService.getParamValueByCode(paramCode, "{}");
  443. logger.info("修改前的tts账号信息");
  444. JSONObject paramValues = JSONObject.parseObject(ttsAccountJson);
  445. for (int j = 0; j < params.size(); j++) {
  446. JSONObject param = params.getJSONObject(j);
  447. String attrName = param.getString("name");
  448. String attValue = param.getString("value");
  449. // 包含星号的参数值不更新
  450. if (!attValue.contains("****")) {
  451. paramValues.put(attrName, attValue);
  452. }
  453. }
  454. ccParamsService.updateParamsValue(paramCode, JSONObject.toJSONString(paramValues));
  455. String reloadRsp = ccParamsService.reloadParams();
  456. if(!reloadRsp.equalsIgnoreCase("success")){
  457. return error("参数修改成功, 但是刷新失败, 请手动重启 call-center!");
  458. }
  459. }
  460. EslMessage resp = EslConnectionUtil.sendSyncApiCommand("reload", moduleName);
  461. String respText = CommonUtils.ListToString(resp.getBodyLines());
  462. if(respText.contains("OK module loaded")) {
  463. return AjaxResult.success("配置写入成功!\n 模块已成功加载!");
  464. }else{
  465. return AjaxResult.error("配置写入成功!\n 但是模块加载失败! \n" + respText);
  466. }
  467. }else{
  468. return AjaxResult.error("配置文件写入失败!\n " + result);
  469. }
  470. }
  471. /**
  472. * 保存ASR配置
  473. * @param params
  474. * @return
  475. */
  476. @PostMapping(value = "/setAliAsrConf")
  477. @ResponseBody
  478. public AjaxResult setAliAsrConf(@RequestBody JSONArray params) {
  479. String asrFileName = "/autoload_configs/aliyun_asr.conf.xml";
  480. String moduleName = "mod_aliyun_asr";
  481. return saveAndReloadAsrModule(asrFileName, moduleName, params, "aliyun");
  482. }
  483. /**
  484. * 保存新 ASR 模块配置
  485. * @param params
  486. * @return
  487. */
  488. @PostMapping(value = "/setAliBridgeAsrConf")
  489. @ResponseBody
  490. public AjaxResult setAliBridgeAsrConf(@RequestBody JSONArray params) {
  491. String asrFileName = "/autoload_configs/ali_asr.conf.xml";
  492. String moduleName = "mod_ali_asr";
  493. return saveAndReloadAsrModule(asrFileName, moduleName, params, "ali");
  494. }
  495. /**
  496. * 保存腾讯 ASR 模块配置
  497. * @param params
  498. * @return
  499. */
  500. @PostMapping(value = "/setTxBridgeAsrConf")
  501. @ResponseBody
  502. public AjaxResult setTxBridgeAsrConf(@RequestBody JSONArray params) {
  503. String asrFileName = "/autoload_configs/tx_asr.conf.xml";
  504. String moduleName = "mod_tx_asr";
  505. return saveAndReloadAsrModule(asrFileName, moduleName, params, "tx");
  506. }
  507. /**
  508. * 保存腾讯 ASR1 模块配置
  509. * @param params
  510. * @return
  511. */
  512. @PostMapping(value = "/setTxBridgeAsr1Conf")
  513. @ResponseBody
  514. public AjaxResult setTxBridgeAsr1Conf(@RequestBody JSONArray params) {
  515. String asrFileName = "/autoload_configs/tx_asr1.conf.xml";
  516. String moduleName = "mod_tx_asr1";
  517. return saveAndReloadAsrModule(asrFileName, moduleName, params, "tx1");
  518. }
  519. /**
  520. * 保存ASR配置
  521. * @param params
  522. * @return
  523. */
  524. @PostMapping(value = "/setChinatelecomAsrConf")
  525. @ResponseBody
  526. public AjaxResult setChinatelecomAsrConf(@RequestBody JSONArray params) {
  527. String asrFileName = "/autoload_configs/chinatelecom_asr.conf.xml";
  528. String moduleName = "mod_chinatelecom_asr";
  529. return saveAndReloadAsrModule(asrFileName, moduleName, params, "chinatelecom");
  530. }
  531. /**
  532. * 保存TTS配置
  533. * @param params
  534. * @return
  535. */
  536. @PostMapping(value = "/setAliTtsConf")
  537. @ResponseBody
  538. public AjaxResult setAliTtsConf(@RequestBody JSONArray params) {
  539. String asrFileName = "/autoload_configs/aliyun_tts.conf.xml";
  540. String moduleName = "mod_aliyun_tts";
  541. AjaxResult result = saveAndReloadTtsModule("aliyun-tts-account-json",
  542. asrFileName, moduleName, params);
  543. return result;
  544. }
  545. /**
  546. * 保存讯飞TTS配置
  547. * @param params
  548. * @return
  549. */
  550. @PostMapping(value = "/setXfTtsConf")
  551. @ResponseBody
  552. public AjaxResult setXfTtsConf(@RequestBody JSONArray params) {
  553. String asrFileName = "/autoload_configs/xf_tts.conf.xml";
  554. String moduleName = "mod_xf_tts";
  555. AjaxResult result = saveAndReloadTtsModule("", asrFileName, moduleName, params);
  556. return result;
  557. }
  558. /**
  559. * 保存TTS配置
  560. * @param params
  561. * @return
  562. */
  563. @PostMapping(value = "/setChinatelecomTtsConf")
  564. @ResponseBody
  565. public AjaxResult setChinatelecomTtsConf(@RequestBody JSONArray params) {
  566. String asrFileName = "/autoload_configs/chinatelecom_tts.conf.xml";
  567. String moduleName = "mod_chinatelecom_tts";
  568. AjaxResult result = saveAndReloadTtsModule("", asrFileName, moduleName, params);
  569. return result;
  570. }
  571. /**
  572. * 保存ASR配置
  573. * @param params
  574. * @return
  575. */
  576. @PostMapping(value = "/setXunfeiAsrConf")
  577. @ResponseBody
  578. public AjaxResult setXunfeiAsrConf(@RequestBody JSONArray params) {
  579. String asrFileName = "/autoload_configs/xunfei_asr.conf.xml";
  580. String moduleName = "mod_xunfei_asr";
  581. return saveAndReloadAsrModule(asrFileName, moduleName, params, "xunfeiasr");
  582. }
  583. /**
  584. * 保存FunASR配置
  585. * @param params
  586. * @return
  587. */
  588. @PostMapping(value = "/setFunAsrConf")
  589. @ResponseBody
  590. public AjaxResult setFunAsrConf(@RequestBody JSONArray params) {
  591. String asrFileName = "/autoload_configs/funasr.conf.xml";
  592. String moduleName = "mod_funasr";
  593. return saveAndReloadAsrModule(asrFileName, moduleName, params, "funasr");
  594. }
  595. /**
  596. * ASR引擎设置
  597. * @return
  598. */
  599. @RequiresPermissions("cc:asrengine:view")
  600. @GetMapping(value = "/asrengine")
  601. public String asrengine(ModelMap mmap) {
  602. String asrEngine = fsConfService.getAsrengine();
  603. FsMod mod = new FsMod();
  604. mod.setModName("asrEngine");
  605. mod.setModValue(asrEngine);
  606. mmap.put("mod", mod);
  607. return "cc/asrengine/asrengine";
  608. }
  609. /**
  610. * 设置ASR引擎(mod_xunfei_asr、mod_aliyun_asr、mod_ali_asr、mod_tx_asr、mod_tx_asr1)
  611. * @param asrengine
  612. * @return
  613. */
  614. @GetMapping(value = "/setAsrengine")
  615. @ResponseBody
  616. public AjaxResult setAsrengine(@RequestParam String asrengine) {
  617. String result = fsConfService.setAsrengine(asrengine);
  618. if(StringUtils.isEmpty(result)){
  619. if (StringUtils.isNotEmpty(asrengine)) {
  620. EslConnectionUtil.sendSyncApiCommand("unload", "mod_xunfei_asr");
  621. EslConnectionUtil.sendSyncApiCommand("unload", "mod_funasr");
  622. EslConnectionUtil.sendSyncApiCommand("unload", "mod_aliyun_asr");
  623. EslConnectionUtil.sendSyncApiCommand("unload", "mod_ali_asr");
  624. EslConnectionUtil.sendSyncApiCommand("unload", "mod_tx_asr");
  625. EslConnectionUtil.sendSyncApiCommand("unload", "mod_tx_asr1");
  626. EslMessage resp = EslConnectionUtil.sendSyncApiCommand("load", asrengine.trim());
  627. String text = CommonUtils.ListToString(resp.getBodyLines() , '\n');
  628. if(text.contains("+OK")) {
  629. return AjaxResult.success("设置成功!");
  630. }else{
  631. return AjaxResult.success("设置失败!\n " + text);
  632. }
  633. }else{
  634. return AjaxResult.error("参数错误!");
  635. }
  636. }else {
  637. return AjaxResult.error(result);
  638. }
  639. }
  640. /**
  641. * 证书配置
  642. * @return
  643. */
  644. @RequiresPermissions("cc:certwsspen:view")
  645. @GetMapping(value = "/certwsspen")
  646. public String certWssPen() {
  647. return "cc/certwsspen/certwsspen";
  648. }
  649. /**
  650. * 获取证书配置
  651. * @return
  652. */
  653. @GetMapping(value = "/getCertWssPen")
  654. @ResponseBody
  655. public AjaxResult getCertWssPen() {
  656. JSONObject result = new JSONObject();
  657. result.put("certValue", fsConfService.getCertWssPen());
  658. return AjaxResult.success("success", result);
  659. }
  660. /**
  661. * 保存证书配置
  662. * @param params
  663. * @return
  664. */
  665. @PostMapping(value = "/setCertWssPen")
  666. @ResponseBody
  667. public AjaxResult setCertWssPen(@RequestBody JSONObject params) {
  668. fsConfService.setCertWssPen(params.getString("certValue"));
  669. return AjaxResult.success("设置成功!");
  670. }
  671. /**
  672. * 授权配置
  673. * @return
  674. */
  675. @RequiresPermissions("cc:licenseconf:view")
  676. @GetMapping(value = "/licenseconf")
  677. public String licenseconf() {
  678. return "cc/licenseconf/licenseconf";
  679. }
  680. /**
  681. * 获取授权配置
  682. * @return
  683. */
  684. @GetMapping(value = "/getLicenseConf")
  685. @ResponseBody
  686. public AjaxResult getLicenseConf() {
  687. JSONObject result = new JSONObject();
  688. result.put("fingerprintValue", fsConfService.getFingerprintValue());
  689. result.put("licenseValue", fsConfService.getLicenseValue());
  690. result.put("licenseInfo", fsConfService.getLicenseInfo());
  691. return AjaxResult.success("success", result);
  692. }
  693. /**
  694. * 保存授权配置
  695. * @param params
  696. * @return
  697. */
  698. @PostMapping(value = "/setLicenseConf")
  699. @ResponseBody
  700. public AjaxResult setLicenseConf(@RequestBody JSONObject params) {
  701. fsConfService.setLicenseConf(params.getString("licenseValue"));
  702. return AjaxResult.success("设置成功!");
  703. }
  704. /**
  705. * 日志监控
  706. * @return
  707. */
  708. @RequiresPermissions("cc:catlogs:view")
  709. @GetMapping(value = "/catlogs")
  710. public String catLogs(ModelMap mmap) {
  711. String ccLogFiles = ccParamsService.getParamValueByCode("cc_log_file_path", "");
  712. String errorLogFiles = ccLogFiles.replace("easycallcenter365.log", "easycallcenter365-ERROR.log");
  713. String errorLogs = fsConfService.getLogs("", errorLogFiles, "error");
  714. mmap.put("errorLogs", errorLogs);
  715. return "cc/catlogs/catlogs";
  716. }
  717. /**
  718. * 获取日志
  719. * @return
  720. */
  721. @GetMapping(value = "/getLogs")
  722. @ResponseBody
  723. public AjaxResult getLogs(@RequestParam String uuid) {
  724. if (StringUtils.isBlank(uuid) || uuid.length() <= 10) {
  725. return AjaxResult.error("请输入正确的uuid");
  726. }
  727. uuid = uuid.trim();
  728. JSONObject result = new JSONObject();
  729. // result.put("fsLogs", "这是freeswitch日志:\r\n19:21:38.255 [schedule-pool-3] INFO c.r.f.s.w.s.OnlineWebSessionManager - [validateSessions,100] - invalidation sessions...\r\n19:21:38.281 [schedule-pool-3] DEBUG c.r.s.m.S.selectOnlineByExpired - [debug,135] - ==> Preparing: select sessionId, login_name, dept_name, ipaddr, login_location, browser, os, status, start_timestamp, last_access_time, expire_time from sys_user_online o WHERE o.last_access_time <= ? ORDER BY o.last_access_time ASC\r\n19:21:38.283 [schedule-pool-3] DEBUG c.r.s.m.S.selectOnlineByExpired - [debug,135] - ==> Parameters: 2024-12-22 18:51:38(String)\r\n19:21:38.312 [schedule-pool-3] DEBUG c.r.s.m.S.selectOnlineByExpired - [debug,135] - <== Total: 0\r\n19:21:38.313 [schedule-pool-3] INFO c.r.f.s.w.s.OnlineWebSessionManager - [validateSessions,165] - Finished invalidation session. No sessions were stopped.\r\n");
  730. // result.put("ccLogs", "这是callcenter日志:\r\n19:21:38.255 [schedule-pool-3] INFO c.r.f.s.w.s.OnlineWebSessionManager - [validateSessions,100] - invalidation sessions...\r\n19:21:38.281 [schedule-pool-3] DEBUG c.r.s.m.S.selectOnlineByExpired - [debug,135] - ==> Preparing: select sessionId, login_name, dept_name, ipaddr, login_location, browser, os, status, start_timestamp, last_access_time, expire_time from sys_user_online o WHERE o.last_access_time <= ? ORDER BY o.last_access_time ASC\r\n19:21:38.283 [schedule-pool-3] DEBUG c.r.s.m.S.selectOnlineByExpired - [debug,135] - ==> Parameters: 2024-12-22 18:51:38(String)\r\n19:21:38.312 [schedule-pool-3] DEBUG c.r.s.m.S.selectOnlineByExpired - [debug,135] - <== Total: 0\r\n19:21:38.313 [schedule-pool-3] INFO c.r.f.s.w.s.OnlineWebSessionManager - [validateSessions,165] - Finished invalidation session. No sessions were stopped.\r\n");
  731. String fsLogFiles = ccParamsService.getParamValueByCode("fs_log_file_path", "");
  732. String fsLogs = fsConfService.getLogs(uuid, fsLogFiles, "cc");
  733. result.put("fsLogs", fsLogs); // freeswitch日志
  734. String ccLogFiles = ccParamsService.getParamValueByCode("cc_log_file_path", "");
  735. String ccLogs = fsConfService.getLogs(uuid, ccLogFiles, "cc");
  736. if (StringUtils.isNotEmpty(fsLogs)
  737. && StringUtils.isBlank(ccLogs)) {
  738. // String ccHisLogFiles = ccLogFiles.replace(".log", ".*.log");
  739. // logger.info(ccHisLogFiles);
  740. // ccLogs = fsConfService.getLogs(uuid, ccHisLogFiles, "cc");
  741. List<CcCallPhone> callPhoneList = callPhoneService.selectCcCallPhoneList(new CcCallPhone().setUuid(uuid));
  742. if (!CollectionUtils.isEmpty(callPhoneList)) {
  743. String date = DateUtils.parseDateToStr("yyyy-MM-dd", new Date(callPhoneList.get(0).getCalloutTime()));
  744. String ccHisLogFiles = ccLogFiles.replace(".log", "." + date + ".0.log");
  745. logger.info(ccHisLogFiles);
  746. ccLogs = fsConfService.getLogs(uuid, ccHisLogFiles, "cc");
  747. } else {
  748. List<CcInboundCdr> inboundCdrList = inboundCdrService.selectCcInboundCdrList(new CcInboundCdr().setUuid(uuid));
  749. if (!CollectionUtils.isEmpty(inboundCdrList)) {
  750. String date = DateUtils.parseDateToStr("yyyy-MM-dd", new Date(inboundCdrList.get(0).getInboundTime()));
  751. String ccHisLogFiles = ccLogFiles.replace(".log", "." + date + ".0.log");
  752. logger.info(ccHisLogFiles);
  753. ccLogs = fsConfService.getLogs(uuid, ccHisLogFiles, "cc");
  754. } else {
  755. List<CcOutboundCdr> outboundCdrList = outboundCdrService.selectCcOutboundCdrList(new CcOutboundCdr().setUuid(uuid));
  756. if (!CollectionUtils.isEmpty(outboundCdrList)) {
  757. String date = DateUtils.parseDateToStr("yyyy-MM-dd", new Date(outboundCdrList.get(0).getStartTime()));
  758. String ccHisLogFiles = ccLogFiles.replace(".log", "." + date + ".0.log");
  759. logger.info(ccHisLogFiles);
  760. ccLogs = fsConfService.getLogs(uuid, ccHisLogFiles, "cc");
  761. }
  762. }
  763. }
  764. }
  765. result.put("ccLogs", ccLogs); // callcenter日志
  766. return AjaxResult.success("success", result);
  767. }
  768. /**
  769. * 获取日志
  770. * @return
  771. */
  772. @GetMapping(value = "/downloadLogs")
  773. @ResponseBody
  774. public void downloadLogs(@RequestParam String uuid, HttpServletResponse response) {
  775. if (StringUtils.isBlank(uuid) || uuid.length() <= 10) {
  776. try {
  777. response.setContentType("application/json;charset=UTF-8");
  778. response.getWriter().write("{\"code\":500,\"msg\":\"请输入正确的uuid\"}");
  779. } catch (IOException e) {
  780. logger.error("写入错误响应失败", e);
  781. }
  782. return;
  783. }
  784. uuid = uuid.trim();
  785. // 获取日志内容
  786. String fsLogFiles = ccParamsService.getParamValueByCode("fs_log_file_path", "");
  787. String fsLogs = fsConfService.getLogs(uuid, fsLogFiles, "cc");
  788. String ccLogFiles = ccParamsService.getParamValueByCode("cc_log_file_path", "");
  789. String ccLogs = fsConfService.getLogs(uuid, ccLogFiles, "cc");
  790. if (StringUtils.isNotEmpty(fsLogs)
  791. && StringUtils.isBlank(ccLogs)) {
  792. // String ccHisLogFiles = ccLogFiles.replace(".log", ".*.log");
  793. // logger.info(ccHisLogFiles);
  794. // ccLogs = fsConfService.getLogs(uuid, ccHisLogFiles, "cc");
  795. List<CcCallPhone> callPhoneList = callPhoneService.selectCcCallPhoneList(new CcCallPhone().setUuid(uuid));
  796. if (!CollectionUtils.isEmpty(callPhoneList)) {
  797. String date = DateUtils.parseDateToStr("yyyy-MM-dd", new Date(callPhoneList.get(0).getCalloutTime()));
  798. String ccHisLogFiles = ccLogFiles.replace(".log", "." + date + ".0.log");
  799. logger.info(ccHisLogFiles);
  800. ccLogs = fsConfService.getLogs(uuid, ccHisLogFiles, "cc");
  801. } else {
  802. List<CcInboundCdr> inboundCdrList = inboundCdrService.selectCcInboundCdrList(new CcInboundCdr().setUuid(uuid));
  803. if (!CollectionUtils.isEmpty(inboundCdrList)) {
  804. String date = DateUtils.parseDateToStr("yyyy-MM-dd", new Date(inboundCdrList.get(0).getInboundTime()));
  805. String ccHisLogFiles = ccLogFiles.replace(".log", "." + date + ".0.log");
  806. logger.info(ccHisLogFiles);
  807. ccLogs = fsConfService.getLogs(uuid, ccHisLogFiles, "cc");
  808. } else {
  809. List<CcOutboundCdr> outboundCdrList = outboundCdrService.selectCcOutboundCdrList(new CcOutboundCdr().setUuid(uuid));
  810. if (!CollectionUtils.isEmpty(outboundCdrList)) {
  811. String date = DateUtils.parseDateToStr("yyyy-MM-dd", new Date(outboundCdrList.get(0).getStartTime()));
  812. String ccHisLogFiles = ccLogFiles.replace(".log", "." + date + ".0.log");
  813. logger.info(ccHisLogFiles);
  814. ccLogs = fsConfService.getLogs(uuid, ccHisLogFiles, "cc");
  815. }
  816. }
  817. }
  818. }
  819. String errorLogFiles = ccLogFiles.replace("easycallcenter365.log", "easycallcenter365-ERROR.log");
  820. String errorLogs = fsConfService.getLogs("", errorLogFiles, "error");
  821. // 生成TXT文件内容
  822. StringBuilder fileContent = new StringBuilder();
  823. fileContent.append("========================================\n");
  824. fileContent.append("UUID: ").append(uuid).append("\n");
  825. fileContent.append("下载时间: ").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())).append("\n");
  826. fileContent.append("========================================\n\n");
  827. fileContent.append("【FreeSwitch 日志】\n");
  828. fileContent.append("========================================\n");
  829. fileContent.append(StringUtils.isNotBlank(fsLogs) ? fsLogs : "无日志内容\n");
  830. fileContent.append("\n\n");
  831. fileContent.append("【CallCenter 日志】\n");
  832. fileContent.append("========================================\n");
  833. fileContent.append(StringUtils.isNotBlank(ccLogs) ? ccLogs : "无日志内容\n");
  834. fileContent.append("【Error 日志】\n");
  835. fileContent.append("========================================\n");
  836. fileContent.append(StringUtils.isNotBlank(errorLogs) ? errorLogs : "无日志内容\n");
  837. fileContent.append("\n\n");
  838. // 设置响应头,实现浏览器下载
  839. String fileName = "logs_" + uuid + "_" + System.currentTimeMillis() + ".txt";
  840. try {
  841. response.setContentType("text/plain;charset=UTF-8");
  842. response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(fileName, "UTF-8") + "\"");
  843. response.setHeader("Cache-Control", "no-cache");
  844. response.setContentLength(fileContent.toString().getBytes(StandardCharsets.UTF_8).length);
  845. // 写入文件内容
  846. try (OutputStream out = response.getOutputStream()) {
  847. out.write(fileContent.toString().getBytes(StandardCharsets.UTF_8));
  848. out.flush();
  849. }
  850. } catch (IOException e) {
  851. logger.error("下载日志文件失败", e);
  852. }
  853. }
  854. @RequiresPermissions("cc:profileconf:view")
  855. @GetMapping("/profileconf")
  856. public String profile()
  857. {
  858. ccGatewaysService.refreshGatewaysFiles();
  859. return "cc/profileconf/profileconf";
  860. }
  861. @RequiresPermissions("cc:profileconf:add")
  862. @GetMapping("/profileconf/add/{profileType}")
  863. public String addProfile(@PathVariable("profileType") String profileType, ModelMap mmap)
  864. {
  865. mmap.put("profileType", profileType);
  866. return "cc/profileconf/add";
  867. }
  868. @RequiresPermissions("cc:profileconf:edit")
  869. @GetMapping("/profileconf/edit/{profileName}")
  870. public String editProfile(@PathVariable("profileName") String profileName, ModelMap mmap)
  871. {
  872. mmap.put("profileName", profileName);
  873. return "cc/profileconf/edit";
  874. }
  875. /**
  876. * 查询分机管理列表
  877. */
  878. @RequiresPermissions("cc:profileconf:list")
  879. @PostMapping("/profileList")
  880. @ResponseBody
  881. public TableDataInfo profileList()
  882. {
  883. startPage();
  884. List<FsConfProfile> list = fsConfService.selectProfileList();
  885. return getDataTable(list);
  886. }
  887. @PostMapping(value = "/setProfileConf")
  888. @ResponseBody
  889. public AjaxResult setProfileConf(@RequestBody JSONArray params) {
  890. String profileName = "";
  891. String profileType = "";
  892. String operaType = "";
  893. JSONArray xmlParams = new JSONArray();
  894. for (int i = 0; i < params.size(); i++) {
  895. JSONObject param = params.getJSONObject(i);
  896. // 不需要写入文件的属性
  897. if ("_profileType".equals(param.getString("name"))) {
  898. profileType = param.getString("value");
  899. continue;
  900. }
  901. if ("_operaType".equals(param.getString("name"))) {
  902. operaType = param.getString("value");
  903. continue;
  904. }
  905. // 需要写入文件的属性
  906. if ("profileName".equals(param.getString("name"))) {
  907. profileName = param.getString("value");
  908. }
  909. xmlParams.add(param);
  910. }
  911. logger.info("profileName:" + profileName);
  912. logger.info("profileType:" + profileType);
  913. logger.info("operaType:" + operaType);
  914. String saveSuccess = fsConfService.setProfileConf(profileName, profileType, xmlParams);
  915. if(!StringUtils.isEmpty(saveSuccess)){
  916. return AjaxResult.error(saveSuccess);
  917. }
  918. if ("add".equals(operaType)) {
  919. // 新增后启动
  920. EslMessage eslMessage = EslConnectionUtil.sendSyncApiCommand("sofia", "profile " + profileName + " start");
  921. if (null != eslMessage) {
  922. logger.info(StringUtils.joinWith("/r/n", eslMessage.getBodyLines().toArray()));
  923. }
  924. } else if ("edit".equals(operaType)) {
  925. // 修改后重启
  926. EslMessage eslMessage = EslConnectionUtil.sendSyncApiCommand("sofia", "profile " + profileName + " restart");
  927. if (null != eslMessage) {
  928. logger.info(StringUtils.joinWith("/r/n", eslMessage.getBodyLines().toArray()));
  929. }
  930. }
  931. return AjaxResult.success("设置成功!");
  932. }
  933. @GetMapping(value = "/getProfileConf")
  934. @ResponseBody
  935. public AjaxResult getProfileConf(@RequestParam(required = false) String profileName, @RequestParam(required = false) String profileType) {
  936. // 配置文件所有配置
  937. JSONObject confAllVars = fsConfService.getProfileConf(profileName, profileType);
  938. // 可配置的基本配置,其他的为隐藏的高级配置
  939. JSONObject fsVars = fsVariablesService.getFsVariablesByCat(3); // key: 参数名, value:别名
  940. JSONArray baseConfigs = new JSONArray();
  941. JSONArray advancedConfigs = new JSONArray();
  942. for (String name: confAllVars.keySet()) {
  943. JSONObject var = new JSONObject();
  944. var.put("name", name);
  945. var.put("value", confAllVars.getString(name));
  946. if (fsVars.keySet().contains(name)) {
  947. // 基本配置
  948. var.put("aliasName", fsVars.getString(name)); // 别名
  949. baseConfigs.add(var);
  950. } else {
  951. // 高级配置
  952. var.put("aliasName", name); // 高级配置没有别名
  953. advancedConfigs.add(var);
  954. }
  955. }
  956. JSONObject result = new JSONObject();
  957. result.put("baseConfigs", baseConfigs);
  958. result.put("advancedConfigs", advancedConfigs);
  959. return AjaxResult.success("success", result);
  960. }
  961. @GetMapping(value = "/getProfileStatus")
  962. @ResponseBody
  963. public AjaxResult getProfileStatus(@RequestParam String profileName) {
  964. JSONObject result = new JSONObject();
  965. EslMessage eslMessage = EslConnectionUtil.sendSyncApiCommand("sofia", "xmlstatus");
  966. if (null != eslMessage) {
  967. logger.info(StringUtils.joinWith("\r\n", eslMessage.getBodyLines().toArray()));
  968. List<ProfileStatusModel> list = convertProfileStatusXml(StringUtils.joinWith("", eslMessage.getBodyLines().toArray()));
  969. logger.info(JSONObject.toJSONString(list));
  970. result.put("data", list);
  971. } else {
  972. result.put("msg", "系统错误");
  973. }
  974. return AjaxResult.success("success", result);
  975. }
  976. /**
  977. * profileStatus格式转换
  978. * @param xml
  979. * @return
  980. */
  981. private List<ProfileStatusModel> convertProfileStatusXml(String xml) {
  982. List<ProfileStatusModel> list = new ArrayList<>();
  983. try {
  984. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  985. DocumentBuilder builder = factory.newDocumentBuilder();
  986. InputSource is = new InputSource(new StringReader(xml));
  987. Document doc = builder.parse(is);
  988. // 根节点
  989. Node profiles = doc.getDocumentElement();
  990. // 下层数据节点(profile、gateway、alias等)
  991. NodeList children = profiles.getChildNodes();
  992. for (int i = 0; i < children.getLength(); i++) {
  993. // 比如profile节点
  994. Node child = children.item(i);
  995. if (child.getNodeType() == Node.ELEMENT_NODE) {
  996. Element element = (Element) children.item(i);
  997. Node name = element.getElementsByTagName("name").item(0);
  998. Node type = element.getElementsByTagName("type").item(0);
  999. Node data = element.getElementsByTagName("data").item(0);
  1000. Node state = element.getElementsByTagName("state").item(0);
  1001. ProfileStatusModel model = new ProfileStatusModel();
  1002. if (null != name && StringUtils.isNotEmpty(name.getTextContent())) {
  1003. model.setName(name.getTextContent().trim());
  1004. }
  1005. if (null != type && StringUtils.isNotEmpty(type.getTextContent())) {
  1006. model.setType(type.getTextContent().trim());
  1007. }
  1008. if (null != data && StringUtils.isNotEmpty(data.getTextContent())) {
  1009. model.setData(data.getTextContent().trim());
  1010. }
  1011. if (null != state && StringUtils.isNotEmpty(state.getTextContent())) {
  1012. model.setState(state.getTextContent().trim());
  1013. }
  1014. list.add(model);
  1015. }
  1016. }
  1017. } catch (Exception e) {
  1018. e.printStackTrace();
  1019. }
  1020. return list;
  1021. }
  1022. @GetMapping(value = "/startProfile")
  1023. @ResponseBody
  1024. public AjaxResult startProfile(@RequestParam String profileName) {
  1025. JSONObject result = new JSONObject();
  1026. EslMessage eslMessage = EslConnectionUtil.sendSyncApiCommand("sofia", "profile " + profileName + " start");
  1027. if (null != eslMessage) {
  1028. result.put("msg", eslMessage.getBodyLines());
  1029. } else {
  1030. result.put("msg", "系统错误");
  1031. }
  1032. return AjaxResult.success("success", result);
  1033. }
  1034. @GetMapping(value = "/stopProfile")
  1035. @ResponseBody
  1036. public AjaxResult stopProfile(@RequestParam String profileName) {
  1037. JSONObject result = new JSONObject();
  1038. EslMessage eslMessage = EslConnectionUtil.sendSyncApiCommand("sofia", "profile " + profileName + " stop");
  1039. if (null != eslMessage) {
  1040. result.put("msg", eslMessage.getBodyLines());
  1041. } else {
  1042. result.put("msg", "系统错误");
  1043. }
  1044. return AjaxResult.success("success", result);
  1045. }
  1046. @GetMapping(value = "/restartProfile")
  1047. @ResponseBody
  1048. public AjaxResult restartProfile(@RequestParam String profileName) {
  1049. JSONObject result = new JSONObject();
  1050. EslMessage eslMessage = EslConnectionUtil.sendSyncApiCommand("sofia", "profile " + profileName + " restart");
  1051. if (null != eslMessage) {
  1052. result.put("msg", eslMessage.getBodyLines());
  1053. } else {
  1054. result.put("msg", "系统错误");
  1055. }
  1056. return AjaxResult.success("success", result);
  1057. }
  1058. @GetMapping(value = "/getExtnumList")
  1059. @ResponseBody
  1060. public AjaxResult getExtnumList(@RequestParam String profileName) {
  1061. JSONObject result = new JSONObject();
  1062. EslMessage eslMessage = EslConnectionUtil.sendSyncApiCommand("sofia", "xmlstatus profile " + profileName + " reg");
  1063. if (null != eslMessage) {
  1064. logger.info(StringUtils.joinWith("\r\n", eslMessage.getBodyLines().toArray()));
  1065. List<ProfileRegExtnumModel> list = convertProfileRegExtnumXml(StringUtils.joinWith("", eslMessage.getBodyLines().toArray()));
  1066. logger.info(JSONObject.toJSONString(list));
  1067. result.put("data", list);
  1068. } else {
  1069. result.put("msg", "系统错误");
  1070. }
  1071. return AjaxResult.success("success", result);
  1072. }
  1073. private List<ProfileRegExtnumModel> convertProfileRegExtnumXml(String xml) {
  1074. List<ProfileRegExtnumModel> list = new ArrayList<>();
  1075. try {
  1076. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  1077. DocumentBuilder builder = factory.newDocumentBuilder();
  1078. InputSource is = new InputSource(new StringReader(xml));
  1079. Document doc = builder.parse(is);
  1080. NodeList children = doc.getElementsByTagName("registration");
  1081. for (int i = 0; i < children.getLength(); i++) {
  1082. // 比如profile节点
  1083. Node child = children.item(i);
  1084. if (child.getNodeType() == Node.ELEMENT_NODE) {
  1085. Element element = (Element) children.item(i);
  1086. Node user = element.getElementsByTagName("user").item(0);
  1087. Node networkIp = element.getElementsByTagName("network-ip").item(0);
  1088. Node networkPort = element.getElementsByTagName("network-port").item(0);
  1089. Node status = element.getElementsByTagName("status").item(0);
  1090. Node agent = element.getElementsByTagName("agent").item(0);
  1091. ProfileRegExtnumModel model = new ProfileRegExtnumModel();
  1092. if (null != user && StringUtils.isNotEmpty(user.getTextContent())) {
  1093. model.setUser(user.getTextContent().trim().split("@")[0]);
  1094. }
  1095. if (null != networkIp && StringUtils.isNotEmpty(networkIp.getTextContent())) {
  1096. model.setNetworkIp(networkIp.getTextContent().trim());
  1097. }
  1098. if (null != networkPort && StringUtils.isNotEmpty(networkPort.getTextContent())) {
  1099. model.setNetworkPort(networkPort.getTextContent().trim());
  1100. }
  1101. if (null != status && StringUtils.isNotEmpty(status.getTextContent())) {
  1102. model.setStatus(status.getTextContent().trim());
  1103. }
  1104. if (null != agent && StringUtils.isNotEmpty(agent.getTextContent())) {
  1105. String agentValue = agent.getTextContent().trim();
  1106. if (agentValue.length() > 16) {
  1107. agentValue = agentValue.substring(0, 14) + "...";
  1108. }
  1109. model.setAgent(agentValue);
  1110. }
  1111. list.add(model);
  1112. }
  1113. }
  1114. } catch (Exception e) {
  1115. e.printStackTrace();
  1116. }
  1117. return list;
  1118. }
  1119. /**
  1120. * ASR(亚马逊)参数配置
  1121. * @return
  1122. */
  1123. @GetMapping(value = "/awsasrconf")
  1124. public String awsAsrConf() {
  1125. return "cc/awsasrconf/awsasrconf";
  1126. }
  1127. /**
  1128. * 获取亚马逊ASR配置
  1129. * @return
  1130. */
  1131. @GetMapping(value = "/getAwsAsrConf")
  1132. @ResponseBody
  1133. public AjaxResult getAwsAsrConf() {
  1134. String asrFileName = "/autoload_configs/aws_asr.conf.xml";
  1135. return getConfigFileJsonData(asrFileName, 5);
  1136. }
  1137. /**
  1138. * 保存ASR配置
  1139. * @param params
  1140. * @return
  1141. */
  1142. @PostMapping(value = "/setAwsAsrConf")
  1143. @ResponseBody
  1144. public AjaxResult setAwsAsrConf(@RequestBody JSONArray params) {
  1145. String asrFileName = "/autoload_configs/aws_asr.conf.xml";
  1146. String moduleName = "mod_aws_asr";
  1147. return saveAndReloadAsrModule(asrFileName, moduleName, params, "aws");
  1148. }
  1149. /**
  1150. * TTS(亚马逊)参数配置
  1151. * @return
  1152. */
  1153. @RequiresPermissions("cc:awsttsconf:view")
  1154. @GetMapping(value = "/awsttsconf")
  1155. public String awsTtsConf() {
  1156. return "cc/awsttsconf/awsttsconf";
  1157. }
  1158. /**
  1159. * 获取亚马逊tts配置
  1160. * @return
  1161. */
  1162. @GetMapping(value = "/getAwsTtsConf")
  1163. @ResponseBody
  1164. public AjaxResult getAwsTtsConf() {
  1165. String ttsFileName = "/autoload_configs/aws_tts.conf.xml";
  1166. return getConfigFileJsonData(ttsFileName, 5);
  1167. }
  1168. /**
  1169. * 保存TTS配置
  1170. * @param params
  1171. * @return
  1172. */
  1173. @PostMapping(value = "/setAwsTtsConf")
  1174. @ResponseBody
  1175. public AjaxResult setAwsTtsConf(@RequestBody JSONArray params) {
  1176. String asrFileName = "/autoload_configs/aws_tts.conf.xml";
  1177. String moduleName = "mod_aws_tts";
  1178. AjaxResult result = saveAndReloadTtsModule("aws-tts-account-json",
  1179. asrFileName, moduleName, params);
  1180. return result;
  1181. }
  1182. /**
  1183. * ASR(deepgram)参数配置
  1184. * @return
  1185. */
  1186. @GetMapping(value = "/deepgramasrconf")
  1187. public String deepgramAsrConf() {
  1188. return "cc/deepgramasrconf/deepgramasrconf";
  1189. }
  1190. /**
  1191. * 获取Deepgram ASR配置
  1192. * @return
  1193. */
  1194. @GetMapping(value = "/getDeepgramAsrConf")
  1195. @ResponseBody
  1196. public AjaxResult getDeepgramAsrConf() {
  1197. String asrFileName = "/autoload_configs/deepgram_asr.conf.xml";
  1198. return getConfigFileJsonData(asrFileName, 5);
  1199. }
  1200. /**
  1201. * 保存ASR配置
  1202. * @param params
  1203. * @return
  1204. */
  1205. @PostMapping(value = "/setDeepgramAsrConf")
  1206. @ResponseBody
  1207. public AjaxResult setDeepgramAsrConf(@RequestBody JSONArray params) {
  1208. String asrFileName = "/autoload_configs/deepgram_asr.conf.xml";
  1209. String moduleName = "mod_deepgram_asr";
  1210. return saveAndReloadAsrModule(asrFileName, moduleName, params, "deepgram");
  1211. }
  1212. /**
  1213. * TTS(deepgram)参数配置
  1214. * @return
  1215. */
  1216. @RequiresPermissions("cc:deepgramttsconf:view")
  1217. @GetMapping(value = "/deepgramttsconf")
  1218. public String deepgramTtsConf() {
  1219. return "cc/deepgramttsconf/deepgramttsconf";
  1220. }
  1221. /**
  1222. * 获取deepgram tts配置
  1223. * @return
  1224. */
  1225. @GetMapping(value = "/getDeepgramTtsConf")
  1226. @ResponseBody
  1227. public AjaxResult getDeepgramTtsConf() {
  1228. String ttsFileName = "/autoload_configs/deepgram_tts.conf.xml";
  1229. return getConfigFileJsonData(ttsFileName, 5);
  1230. }
  1231. /**
  1232. * 保存TTS配置
  1233. * @param params
  1234. * @return
  1235. */
  1236. @PostMapping(value = "/setDeepgramTtsConf")
  1237. @ResponseBody
  1238. public AjaxResult setDeepgramTtsConf(@RequestBody JSONArray params) {
  1239. String asrFileName = "/autoload_configs/deepgram_tts.conf.xml";
  1240. String moduleName = "mod_deepgram_tts";
  1241. AjaxResult result = saveAndReloadTtsModule("deepgram-tts-account-json",
  1242. asrFileName, moduleName, params);
  1243. return result;
  1244. }
  1245. }