write_company_easycall_controller.mjs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import fs from 'fs'
  2. import path from 'path'
  3. import { fileURLToPath } from 'url'
  4. const __dirname = path.dirname(fileURLToPath(import.meta.url))
  5. const p = path.resolve(__dirname, '../../fs-saas-admin/src/main/java/com/fs/company/controller/CompanyEasyCallController.java')
  6. const content = `package com.fs.company.controller;
  7. import com.fs.aicall.domain.CcLlmAgentAccount;
  8. import com.fs.aicall.domain.CcTtsAliyun;
  9. import com.fs.aicall.service.ICcLlmAgentAccountService;
  10. import com.fs.aicall.service.ICompanyBindAiModelService;
  11. import com.fs.common.core.controller.BaseController;
  12. import com.fs.common.core.domain.R;
  13. import com.fs.company.mapper.CompanyVoiceCloneRefMapper;
  14. import com.fs.company.service.easycall.IEasyCallService;
  15. import com.fs.company.support.AdminCompanyScopeHelper;
  16. import com.fs.company.vo.easycall.EasyCallBusiGroupVO;
  17. import com.fs.company.vo.easycall.EasyCallGatewayVO;
  18. import com.fs.company.vo.easycall.EasyCallVoiceCodeVO;
  19. import com.fs.company.vo.easycall.ExtensionVO;
  20. import io.swagger.annotations.Api;
  21. import io.swagger.annotations.ApiOperation;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.web.bind.annotation.GetMapping;
  24. import org.springframework.web.bind.annotation.RequestMapping;
  25. import org.springframework.web.bind.annotation.RequestParam;
  26. import org.springframework.web.bind.annotation.RestController;
  27. import java.util.ArrayList;
  28. import java.util.List;
  29. import java.util.stream.Collectors;
  30. /**
  31. * EasyCall \u5916\u547c\u57fa\u7840\u6570\u636e\uff08\u603b\u540e\u53f0\u6865\u63a5\uff09
  32. * \u9500\u552e\u7aef\u4ece\u767b\u5f55\u6001\u53d6 companyId\uff1b\u603b\u540e\u53f0\u901a\u8fc7 companyId \u53c2\u6570\u6307\u5b9a\u516c\u53f8\u3002
  33. */
  34. @Api(tags = "EasyCallCenter365\u5916\u547c\u7ba1\u7406(\u603b\u540e\u53f0)")
  35. @RestController
  36. @RequestMapping("/company/easyCall")
  37. public class CompanyEasyCallController extends BaseController {
  38. @Autowired
  39. private IEasyCallService easyCallService;
  40. @Autowired
  41. private ICompanyBindAiModelService companyBindAiModelService;
  42. @Autowired
  43. private ICcLlmAgentAccountService ccLlmAgentAccountService;
  44. @Autowired
  45. private CompanyVoiceCloneRefMapper companyVoiceCloneRefMapper;
  46. @ApiOperation("\u83b7\u53d6\u7f51\u5173\u5217\u8868")
  47. @GetMapping("/gateway/list")
  48. public R getGatewayList(@RequestParam Long companyId) {
  49. Long cid = AdminCompanyScopeHelper.requireCompanyId(companyId, "\u8bf7\u9009\u62e9\u9500\u552e\u516c\u53f8");
  50. List<EasyCallGatewayVO> list = easyCallService.getGatewayList(cid);
  51. return R.ok().put("data", list);
  52. }
  53. @ApiOperation("\u83b7\u53d6\u5927\u6a21\u578b\u914d\u7f6e\u5217\u8868")
  54. @GetMapping("/llmAccount/list")
  55. public R getLlmAccountList(@RequestParam Long companyId) {
  56. Long cid = AdminCompanyScopeHelper.requireCompanyId(companyId, "\u8bf7\u9009\u62e9\u9500\u552e\u516c\u53f8");
  57. List<Long> modelIds = companyBindAiModelService.selectVisibleModelIdsForCompany(cid);
  58. if (modelIds.isEmpty()) {
  59. return R.ok().put("data", new ArrayList<>());
  60. }
  61. CcLlmAgentAccount ccLlmAgentAccount = new CcLlmAgentAccount();
  62. ccLlmAgentAccount.setModelIds(modelIds);
  63. List<CcLlmAgentAccount> list = ccLlmAgentAccountService.selectCcLlmAgentAccountList(ccLlmAgentAccount);
  64. return R.ok().put("data", list);
  65. }
  66. @ApiOperation("\u83b7\u53d6\u97f3\u8272\u5217\u8868")
  67. @GetMapping("/voiceCode/list")
  68. public R getVoiceCodeList(@RequestParam Long companyId) {
  69. Long cid = AdminCompanyScopeHelper.requireCompanyId(companyId, "\u8bf7\u9009\u62e9\u9500\u552e\u516c\u53f8");
  70. List<Long> ttsIds = companyVoiceCloneRefMapper.selectActiveTtsIds(cid, null);
  71. List<CcTtsAliyun> ccTtsAliyuns = companyVoiceCloneRefMapper.selectCcTtsAliyunList();
  72. List<EasyCallVoiceCodeVO> result = ccTtsAliyuns.stream()
  73. .filter(item -> item.getPriority() == 1
  74. || (item.getPriority() == 0 && ttsIds.contains(item.getId())))
  75. .map(item -> {
  76. EasyCallVoiceCodeVO vo = new EasyCallVoiceCodeVO();
  77. vo.setVoiceCode(item.getVoiceCode());
  78. vo.setVoiceName(item.getVoiceName());
  79. vo.setVoiceSource(item.getVoiceSource());
  80. vo.setTtsModels(item.getTtsModels());
  81. return vo;
  82. })
  83. .collect(Collectors.toList());
  84. return R.ok().put("data", result);
  85. }
  86. @ApiOperation("\u83b7\u53d6\u6280\u80fd\u7ec4\u5217\u8868")
  87. @GetMapping("/busiGroup/list")
  88. public R getBusiGroupList(@RequestParam Long companyId) {
  89. Long cid = AdminCompanyScopeHelper.requireCompanyId(companyId, "\u8bf7\u9009\u62e9\u9500\u552e\u516c\u53f8");
  90. List<EasyCallBusiGroupVO> list = easyCallService.getBusiGroupList(cid);
  91. return R.ok().put("data", list);
  92. }
  93. @ApiOperation("\u83b7\u53d6\u5206\u673a\u53f7\u7801list")
  94. @GetMapping("/getExtensionList")
  95. public R getExtensionList(@RequestParam Long companyId) {
  96. Long cid = AdminCompanyScopeHelper.requireCompanyId(companyId, "\u8bf7\u9009\u62e9\u9500\u552e\u516c\u53f8");
  97. List<ExtensionVO> extensionList = easyCallService.getExtensionList(cid);
  98. return R.ok().put("data", extensionList);
  99. }
  100. }
  101. `
  102. fs.writeFileSync(p, content, 'utf8')
  103. const t = fs.readFileSync(p, 'utf8')
  104. console.log('written', p)
  105. console.log('FFFD', t.includes('\uFFFD'))
  106. console.log('sample', t.includes('\u8bf7\u9009\u62e9\u9500\u552e\u516c\u53f8'))