e_robot_config.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package entity
  2. import (
  3. "context"
  4. "gorm.io/gorm"
  5. "yx-dataset-server/app/schema"
  6. )
  7. // GetRobotConfigDB 获取RobotConfig存储
  8. func GetRobotConfigDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
  9. return getDBWithModel(ctx, defDB, RobotConfig{})
  10. }
  11. // SchemaRobotConfig RobotConfig对象
  12. type SchemaRobotConfig schema.RobotConfig
  13. // ToRobotConfig 转换为RobotConfig实体
  14. func (a SchemaRobotConfig) ToRobotConfig() *RobotConfig {
  15. item := &RobotConfig{
  16. RecordID: a.RecordID,
  17. OrgId: a.OrgId,
  18. Name: a.Name,
  19. Type: a.Type,
  20. APPID: a.APPID,
  21. ClientId: a.ClientId,
  22. ClientSecret: a.ClientSecret,
  23. Webhook: a.Webhook,
  24. AssistantId: a.AssistantId,
  25. SessionId: a.SessionId,
  26. CreatorId: a.CreatorId,
  27. }
  28. return item
  29. }
  30. // ToSchemaRobotConfig 转换为RobotConfig对象
  31. func (a RobotConfig) ToSchemaRobotConfig() *schema.RobotConfig {
  32. item := &schema.RobotConfig{
  33. RecordID: a.RecordID,
  34. OrgId: a.OrgId,
  35. Name: a.Name,
  36. Type: a.Type,
  37. APPID: a.APPID,
  38. ClientId: a.ClientId,
  39. ClientSecret: a.ClientSecret,
  40. Webhook: a.Webhook,
  41. CreatorId: a.CreatorId,
  42. AssistantId: a.AssistantId,
  43. SessionId: a.SessionId,
  44. CreatedAt: a.CreatedAt,
  45. }
  46. return item
  47. }
  48. // RobotConfig RobotConfig实体
  49. type RobotConfig struct {
  50. gorm.Model
  51. RecordID string `gorm:"column:record_id;size:32;index;"` // 记录id
  52. OrgId string `gorm:"column:org_id;size:32;index;"` // 组织ID
  53. Name string `gorm:"column:name;size:20;"` // 机器人名称
  54. Type int `gorm:"column:type;"` // 机器人类型
  55. APPID string `gorm:"column:appid;size:50;"` // APP ID
  56. ClientId string `gorm:"column:client_id;size:50;"` // 客户端ID
  57. ClientSecret string `gorm:"column:client_secret;size:100;"` // 客户端密钥
  58. Webhook string `gorm:"column:webhook;size:100;"` // 消息接收WebHook
  59. AssistantId string `gorm:"column:assistant_id;size:32;"` // 助手id
  60. SessionId string `gorm:"column:session_id;size:32;"` // 会话id
  61. CreatorId string `gorm:"column:creator_id;size:32;"` // 创建人
  62. }
  63. // RobotConfigs RobotConfig列表
  64. type RobotConfigs []*RobotConfig
  65. // ToSchemaRobotConfigs 转换为RobotConfig对象列表
  66. func (a RobotConfigs) ToSchemaRobotConfigs() []*schema.RobotConfig {
  67. list := make([]*schema.RobotConfig, len(a))
  68. for i, item := range a {
  69. list[i] = item.ToSchemaRobotConfig()
  70. }
  71. return list
  72. }