s_dataset_relation.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package schema
  2. // 知识库类型(DatasetRelation.Type / Dataset.Type)
  3. const (
  4. DatasetTypePublic = 1 // 公共/共享知识库(系统管理员创建)
  5. DatasetTypeOrg = 2 // 企业知识库(企业管理员创建)
  6. DatasetTypePersonal = 3 // 个人知识库(员工自建)
  7. )
  8. // DatasetRelation 知识库关系映射
  9. // BizID 表示授权主体:
  10. // - 组织级授权:BizID = org_id
  11. // - 用户级授权:BizID = user_id
  12. // Type 表示该知识库本身的分类(1/2/3),便于前端按类型区分渲染。
  13. type DatasetRelation struct {
  14. RecordID string `json:"record_id"` // 记录id
  15. DatasetId string `json:"dataset_id"` // 知识库id
  16. BizId string `json:"biz_id"` // 业务id:企业id 或 用户id
  17. Type int `json:"type"` // 1 公共/共享 2 企业 3 个人
  18. CreatorId string `json:"creator_id"` // 关联创建人
  19. }
  20. // DatasetRelationQueryParam 查询条件
  21. type DatasetRelationQueryParam struct {
  22. RecordIDs []string
  23. DatasetId string
  24. DatasetIds []string
  25. BizId string
  26. BizIds []string
  27. Type int // 0 表示不按类型筛选
  28. Types []int // 按多种类型筛选
  29. }
  30. // DatasetRelationQueryOptions 可选查询参数
  31. type DatasetRelationQueryOptions struct {
  32. PageParam *PaginationParam
  33. }
  34. type DatasetRelations []*DatasetRelation
  35. // DatasetRelationQueryResult 查询结果
  36. type DatasetRelationQueryResult struct {
  37. Data DatasetRelations
  38. PageResult *PaginationResult
  39. }
  40. // ToDatasetIds 提取 dataset_id 列表
  41. func (a DatasetRelations) ToDatasetIds() []string {
  42. ids := make([]string, len(a))
  43. for i, v := range a {
  44. ids[i] = v.DatasetId
  45. }
  46. return ids
  47. }
  48. // FilterByType 按 type 过滤
  49. func (a DatasetRelations) FilterByType(t int) DatasetRelations {
  50. out := make(DatasetRelations, 0, len(a))
  51. for _, v := range a {
  52. if v.Type == t {
  53. out = append(out, v)
  54. }
  55. }
  56. return out
  57. }