agent-module.service.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { Injectable } from '@nestjs/common'
  2. import { IAgentModuleService } from '@/interface/agent-module.interface'
  3. import { ServiceResponse } from '@/response/response.interface'
  4. import { BusinessCode, HttpStatusCode } from '@/response/status-code.enum'
  5. import { AgentModuleHttpService } from './agent-module-http.service'
  6. @Injectable()
  7. export class AgentModuleService implements IAgentModuleService {
  8. constructor(private readonly httpService: AgentModuleHttpService) {}
  9. async getModuleList(
  10. page: number,
  11. pageSize: number
  12. ): Promise<ServiceResponse<ModuleConfigurationType[]>> {
  13. const { code, data, msg } = await this.httpService.getModuleList(
  14. page,
  15. pageSize
  16. )
  17. if (code !== HttpStatusCode.OK) {
  18. return {
  19. code: BusinessCode.BAD_REQUEST,
  20. msg: msg || '获取模块列表失败',
  21. data: null
  22. }
  23. }
  24. return {
  25. code: BusinessCode.SUCCESS,
  26. data,
  27. msg: msg || '获取模块列表成功'
  28. }
  29. }
  30. async getModuleConfiguration(
  31. module_id: number
  32. ): Promise<ServiceResponse<ModuleConfigurationType>> {
  33. const { code, data, msg } =
  34. await this.httpService.getModuleConfiguration(module_id)
  35. if (code !== HttpStatusCode.OK) {
  36. return {
  37. code: BusinessCode.BAD_REQUEST,
  38. msg: msg || '获取模块配置失败',
  39. data: null
  40. }
  41. }
  42. return {
  43. code: BusinessCode.SUCCESS,
  44. data,
  45. msg: msg || '获取模块配置成功'
  46. }
  47. }
  48. async saveModuleConfiguration(
  49. module_id: number,
  50. name: string,
  51. display_name: string,
  52. default_agent_type: number,
  53. default_agent_id: number
  54. ): Promise<ServiceResponse<any>> {
  55. const { code, data, msg } = await this.httpService.saveModuleConfiguration(
  56. module_id,
  57. name,
  58. display_name,
  59. default_agent_type,
  60. default_agent_id
  61. )
  62. if (code !== HttpStatusCode.OK) {
  63. return {
  64. code: BusinessCode.BAD_REQUEST,
  65. msg: msg || '保存模块配置失败',
  66. data: null
  67. }
  68. }
  69. return {
  70. code: BusinessCode.SUCCESS,
  71. data,
  72. msg: msg || '保存模块配置成功'
  73. }
  74. }
  75. async getModuleAgentTypes(): Promise<ServiceResponse<any>> {
  76. const { code, data, msg } = await this.httpService.getModuleAgentTypes()
  77. if (code !== HttpStatusCode.OK) {
  78. return {
  79. code: BusinessCode.BAD_REQUEST,
  80. msg: msg || '获取模块代理类型失败',
  81. data: null
  82. }
  83. }
  84. return {
  85. code: BusinessCode.SUCCESS,
  86. data,
  87. msg: msg || '获取模块代理类型成功'
  88. }
  89. }
  90. }