CcLlmAgentAccountController.java 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. package com.ruoyi.aicall.controller;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.ruoyi.aicall.domain.CcLlmAgentProvider;
  6. import com.ruoyi.aicall.llm.ILlmCapability;
  7. import com.ruoyi.aicall.llm.model.AccountBaseEntity;
  8. import com.ruoyi.cc.service.ICcParamsService;
  9. import com.ruoyi.cc.utils.LlmAccountParser;
  10. import com.ruoyi.common.utils.CommonUtils;
  11. import com.ruoyi.common.utils.ExceptionUtil;
  12. import com.ruoyi.common.utils.StringUtils;
  13. import org.apache.shiro.authz.annotation.RequiresPermissions;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Controller;
  16. import org.springframework.ui.ModelMap;
  17. import org.springframework.web.bind.annotation.GetMapping;
  18. import org.springframework.web.bind.annotation.PathVariable;
  19. import org.springframework.web.bind.annotation.PostMapping;
  20. import org.springframework.web.bind.annotation.RequestMapping;
  21. import org.springframework.web.bind.annotation.ResponseBody;
  22. import com.ruoyi.common.annotation.Log;
  23. import com.ruoyi.common.enums.BusinessType;
  24. import com.ruoyi.aicall.domain.CcLlmAgentAccount;
  25. import com.ruoyi.aicall.service.ICcLlmAgentAccountService;
  26. import com.ruoyi.common.core.controller.BaseController;
  27. import com.ruoyi.common.core.domain.AjaxResult;
  28. import com.ruoyi.common.utils.poi.ExcelUtil;
  29. import com.ruoyi.common.core.page.TableDataInfo;
  30. /**
  31. * 机器人参数配置Controller
  32. *
  33. * @author ruoyi
  34. * @date 2025-06-16
  35. */
  36. @Controller
  37. @RequestMapping("/aicall/account")
  38. public class CcLlmAgentAccountController extends BaseController
  39. {
  40. private String prefix = "aicall/account";
  41. @Autowired
  42. private ICcLlmAgentAccountService ccLlmAgentAccountService;
  43. @Autowired
  44. private ICcParamsService ccParamsService;
  45. private static List<String> hideKeys = Arrays.asList("apiKey", "oauthPrivateKey", "oauthPublicKeyId", "patToken");
  46. @RequiresPermissions("aicall:account:view")
  47. @GetMapping()
  48. public String account()
  49. {
  50. return prefix + "/account";
  51. }
  52. /**
  53. * 查询机器人参数配置列表
  54. */
  55. @RequiresPermissions("aicall:account:list")
  56. @PostMapping("/list")
  57. @ResponseBody
  58. public TableDataInfo list(CcLlmAgentAccount ccLlmAgentAccount)
  59. {
  60. startPage();
  61. List<CcLlmAgentAccount> list = ccLlmAgentAccountService.selectCcLlmAgentAccountList(ccLlmAgentAccount);
  62. TableDataInfo tableDataInfo = getDataTable(list);
  63. List<CcLlmAgentAccount> records = (List<CcLlmAgentAccount>) tableDataInfo.getRows();
  64. for (CcLlmAgentAccount data: records) {
  65. JSONObject accountJson = JSONObject.parseObject(data.getAccountJson());
  66. for (String key: accountJson.keySet()) {
  67. if (hideKeys.contains(key)) {
  68. accountJson.put(key, CommonUtils.maskStringUtil(accountJson.getString(key)));
  69. }
  70. }
  71. data.setAccountJson(JSONObject.toJSONString(accountJson));
  72. }
  73. tableDataInfo.setRows(records);
  74. return tableDataInfo;
  75. }
  76. /**
  77. * 导出机器人参数配置列表
  78. */
  79. @RequiresPermissions("aicall:account:export")
  80. @Log(title = "机器人参数配置", businessType = BusinessType.EXPORT)
  81. @PostMapping("/export")
  82. @ResponseBody
  83. public AjaxResult export(CcLlmAgentAccount ccLlmAgentAccount)
  84. {
  85. List<CcLlmAgentAccount> list = ccLlmAgentAccountService.selectCcLlmAgentAccountList(ccLlmAgentAccount);
  86. ExcelUtil<CcLlmAgentAccount> util = new ExcelUtil<CcLlmAgentAccount>(CcLlmAgentAccount.class);
  87. return util.exportExcel(list, "机器人参数配置数据");
  88. }
  89. /**
  90. * 新增机器人参数配置
  91. */
  92. @GetMapping("/add")
  93. public String add(ModelMap mmap)
  94. {
  95. CcLlmAgentAccount ccLlmAgentAccount = new CcLlmAgentAccount();
  96. ccLlmAgentAccount.setInterruptIgnoreKeywords(ccParamsService.getParamValueByCode("default_interrupt_ignore_keywords", ""));
  97. ccLlmAgentAccount.setInterruptFlag(0);
  98. mmap.put("ccLlmAgentAccount", ccLlmAgentAccount);
  99. return prefix + "/add";
  100. }
  101. /**
  102. * 新增保存机器人参数配置
  103. */
  104. @RequiresPermissions("aicall:account:add")
  105. @Log(title = "机器人参数配置", businessType = BusinessType.INSERT)
  106. @PostMapping("/add")
  107. @ResponseBody
  108. public AjaxResult addSave(CcLlmAgentAccount ccLlmAgentAccount)
  109. {
  110. if ("Coze".equalsIgnoreCase(ccLlmAgentAccount.getProviderClassName())) {
  111. ccLlmAgentAccount.setAccountEntity("CozeAccount");
  112. } else if ("JiutianWorkflow".equalsIgnoreCase(ccLlmAgentAccount.getProviderClassName())
  113. || "JiutianAgent".equalsIgnoreCase(ccLlmAgentAccount.getProviderClassName())) {
  114. ccLlmAgentAccount.setAccountEntity("JiutianAccount");
  115. } else {
  116. ccLlmAgentAccount.setAccountEntity("LlmAccount");
  117. }
  118. return toAjax(ccLlmAgentAccountService.insertCcLlmAgentAccount(ccLlmAgentAccount));
  119. }
  120. /**
  121. * 修改机器人参数配置
  122. */
  123. @RequiresPermissions("aicall:account:edit")
  124. @GetMapping("/edit/{id}")
  125. public String edit(@PathVariable("id") Integer id, ModelMap mmap)
  126. {
  127. CcLlmAgentAccount ccLlmAgentAccount = ccLlmAgentAccountService.selectCcLlmAgentAccountById(id);
  128. if (StringUtils.isBlank(ccLlmAgentAccount.getInterruptIgnoreKeywords())) {
  129. ccLlmAgentAccount.setInterruptIgnoreKeywords(ccParamsService.getParamValueByCode("default_interrupt_ignore_keywords", ""));
  130. }
  131. JSONObject accountJson = JSONObject.parseObject(ccLlmAgentAccount.getAccountJson());
  132. for (String key: accountJson.keySet()) {
  133. if (hideKeys.contains(key)) {
  134. accountJson.put(key, CommonUtils.maskStringUtil(accountJson.getString(key)));
  135. }
  136. }
  137. ccLlmAgentAccount.setAccountJson(JSONObject.toJSONString(accountJson));
  138. mmap.put("ccLlmAgentAccount", ccLlmAgentAccount);
  139. return prefix + "/edit";
  140. }
  141. /**
  142. * 复制机器人参数配置
  143. */
  144. @RequiresPermissions("aicall:account:edit")
  145. @GetMapping("/copy/{id}")
  146. public String copy(@PathVariable("id") Integer id, ModelMap mmap)
  147. {
  148. CcLlmAgentAccount ccLlmAgentAccount = ccLlmAgentAccountService.selectCcLlmAgentAccountById(id);
  149. if (StringUtils.isBlank(ccLlmAgentAccount.getInterruptIgnoreKeywords())) {
  150. ccLlmAgentAccount.setInterruptIgnoreKeywords(ccParamsService.getParamValueByCode("default_interrupt_ignore_keywords", ""));
  151. }
  152. ccLlmAgentAccount.setId(-1*ccLlmAgentAccount.getId());
  153. ccLlmAgentAccount.setName(ccLlmAgentAccount.getName() + "-副本");
  154. JSONObject accountJson = JSONObject.parseObject(ccLlmAgentAccount.getAccountJson());
  155. for (String key: accountJson.keySet()) {
  156. if (hideKeys.contains(key)) {
  157. accountJson.put(key, CommonUtils.maskStringUtil(accountJson.getString(key)));
  158. }
  159. }
  160. ccLlmAgentAccount.setAccountJson(JSONObject.toJSONString(accountJson));
  161. mmap.put("ccLlmAgentAccount", ccLlmAgentAccount);
  162. return prefix + "/edit";
  163. }
  164. /**
  165. * 修改保存机器人参数配置
  166. */
  167. @RequiresPermissions("aicall:account:edit")
  168. @Log(title = "机器人参数配置", businessType = BusinessType.UPDATE)
  169. @PostMapping("/edit")
  170. @ResponseBody
  171. public AjaxResult editSave(CcLlmAgentAccount ccLlmAgentAccount)
  172. {
  173. if ("Coze".equalsIgnoreCase(ccLlmAgentAccount.getProviderClassName())) {
  174. ccLlmAgentAccount.setAccountEntity("CozeAccount");
  175. } else if ("JiutianWorkflow".equalsIgnoreCase(ccLlmAgentAccount.getProviderClassName())
  176. || "JiutianAgent".equalsIgnoreCase(ccLlmAgentAccount.getProviderClassName())) {
  177. ccLlmAgentAccount.setAccountEntity("JiutianAccount");
  178. } else {
  179. ccLlmAgentAccount.setAccountEntity("LlmAccount");
  180. }
  181. Integer orignId = ccLlmAgentAccount.getId();
  182. if (orignId < 0) {
  183. orignId = orignId * -1;
  184. }
  185. CcLlmAgentAccount oldCcLlmAgentAccount = ccLlmAgentAccountService.selectCcLlmAgentAccountById(orignId);
  186. JSONObject oldAccountJson = JSONObject.parseObject(oldCcLlmAgentAccount.getAccountJson());
  187. JSONObject newAccountJson = JSONObject.parseObject(ccLlmAgentAccount.getAccountJson());
  188. for (String key: newAccountJson.keySet()) {
  189. // 是需要脱敏的key,且值包含星号,则值不更新
  190. if (hideKeys.contains(key) && newAccountJson.getString(key).contains("****")) {
  191. newAccountJson.put(key, oldAccountJson.getString(key));
  192. }
  193. }
  194. ccLlmAgentAccount.setAccountJson(JSONObject.toJSONString(newAccountJson));
  195. if (ccLlmAgentAccount.getId() > 0) {
  196. return toAjax(ccLlmAgentAccountService.updateCcLlmAgentAccount(ccLlmAgentAccount));
  197. } else {
  198. ccLlmAgentAccount.setId(null);
  199. return toAjax(ccLlmAgentAccountService.insertCcLlmAgentAccount(ccLlmAgentAccount));
  200. }
  201. }
  202. /**
  203. * 删除机器人参数配置
  204. */
  205. @RequiresPermissions("aicall:account:remove")
  206. @Log(title = "机器人参数配置", businessType = BusinessType.DELETE)
  207. @PostMapping( "/remove")
  208. @ResponseBody
  209. public AjaxResult remove(String ids)
  210. {
  211. return toAjax(ccLlmAgentAccountService.deleteCcLlmAgentAccountByIds(ids));
  212. }
  213. @GetMapping("/all")
  214. @ResponseBody
  215. public AjaxResult all()
  216. {
  217. List<CcLlmAgentAccount> list = ccLlmAgentAccountService.selectCcLlmAgentAccountList(new CcLlmAgentAccount());
  218. for (CcLlmAgentAccount data: list) {
  219. JSONObject accountJson = JSONObject.parseObject(data.getAccountJson());
  220. for (String key: accountJson.keySet()) {
  221. if (hideKeys.contains(key)) {
  222. accountJson.put(key, CommonUtils.maskStringUtil(accountJson.getString(key)));
  223. }
  224. }
  225. data.setAccountJson(JSONObject.toJSONString(accountJson));
  226. }
  227. return AjaxResult.success(list);
  228. }
  229. }