|
@@ -0,0 +1,91 @@
|
|
|
|
+import { Injectable } from '@nestjs/common'
|
|
|
|
+
|
|
|
|
+import { IAgentModuleService } from '@/interface/agent-module.interface'
|
|
|
|
+import { ServiceResponse } from '@/response/response.interface'
|
|
|
|
+import { BusinessCode, HttpStatusCode } from '@/response/status-code.enum'
|
|
|
|
+
|
|
|
|
+import { AgentModuleHttpService } from './agent-module-http.service'
|
|
|
|
+
|
|
|
|
+@Injectable()
|
|
|
|
+export class AgentModuleService implements IAgentModuleService {
|
|
|
|
+ constructor(private readonly httpService: AgentModuleHttpService) {}
|
|
|
|
+
|
|
|
|
+ async getModuleList(): Promise<ServiceResponse<ModuleConfigurationType[]>> {
|
|
|
|
+ const { code, data, msg } = await this.httpService.getModuleList()
|
|
|
|
+ if (code !== HttpStatusCode.OK) {
|
|
|
|
+ return {
|
|
|
|
+ code: BusinessCode.BAD_REQUEST,
|
|
|
|
+ msg: msg || '获取模块列表失败',
|
|
|
|
+ data: null
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return {
|
|
|
|
+ code: BusinessCode.SUCCESS,
|
|
|
|
+ data,
|
|
|
|
+ msg: msg || '获取模块列表成功'
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async getModuleConfiguration(
|
|
|
|
+ module_id: number
|
|
|
|
+ ): Promise<ServiceResponse<ModuleConfigurationType>> {
|
|
|
|
+ const { code, data, msg } =
|
|
|
|
+ await this.httpService.getModuleConfiguration(module_id)
|
|
|
|
+ if (code !== HttpStatusCode.OK) {
|
|
|
|
+ return {
|
|
|
|
+ code: BusinessCode.BAD_REQUEST,
|
|
|
|
+ msg: msg || '获取模块配置失败',
|
|
|
|
+ data: null
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return {
|
|
|
|
+ code: BusinessCode.SUCCESS,
|
|
|
|
+ data,
|
|
|
|
+ msg: msg || '获取模块配置成功'
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async saveModuleConfiguration(
|
|
|
|
+ module_id: number,
|
|
|
|
+ name: string,
|
|
|
|
+ display_name: string,
|
|
|
|
+ default_agent_type: number,
|
|
|
|
+ default_agent_id: number
|
|
|
|
+ ): Promise<ServiceResponse<any>> {
|
|
|
|
+ const { code, data, msg } = await this.httpService.saveModuleConfiguration(
|
|
|
|
+ module_id,
|
|
|
|
+ name,
|
|
|
|
+ display_name,
|
|
|
|
+ default_agent_type,
|
|
|
|
+ default_agent_id
|
|
|
|
+ )
|
|
|
|
+ if (code !== HttpStatusCode.OK) {
|
|
|
|
+ return {
|
|
|
|
+ code: BusinessCode.BAD_REQUEST,
|
|
|
|
+ msg: msg || '保存模块配置失败',
|
|
|
|
+ data: null
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return {
|
|
|
|
+ code: BusinessCode.SUCCESS,
|
|
|
|
+ data,
|
|
|
|
+ msg: msg || '保存模块配置成功'
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async getModuleAgentTypes(): Promise<ServiceResponse<any>> {
|
|
|
|
+ const { code, data, msg } = await this.httpService.getModuleAgentTypes()
|
|
|
|
+ if (code !== HttpStatusCode.OK) {
|
|
|
|
+ return {
|
|
|
|
+ code: BusinessCode.BAD_REQUEST,
|
|
|
|
+ msg: msg || '获取模块代理类型失败',
|
|
|
|
+ data: null
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return {
|
|
|
|
+ code: BusinessCode.SUCCESS,
|
|
|
|
+ data,
|
|
|
|
+ msg: msg || '获取模块代理类型成功'
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|