e_role.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package entity
  2. import (
  3. "context"
  4. "gorm.io/gorm"
  5. "yx-dataset-server/app/schema"
  6. )
  7. // GetRoleDB 获取Role存储
  8. func GetRoleDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
  9. return getDBWithModel(ctx, defDB, Role{})
  10. }
  11. // SchemaRole Role对象
  12. type SchemaRole schema.Role
  13. // ToRole 转换为Role实体
  14. func (a SchemaRole) ToRole() *Role {
  15. item := &Role{
  16. RecordID: a.RecordID,
  17. Name: a.Name,
  18. Code: a.Code,
  19. ChartNum: a.ChartNum,
  20. }
  21. return item
  22. }
  23. // ToSchemaRole 转换为Role对象
  24. func (a Role) ToSchemaRole() *schema.Role {
  25. item := &schema.Role{
  26. RecordID: a.RecordID,
  27. Name: a.Name,
  28. Code: a.Code,
  29. ChartNum: a.ChartNum,
  30. Creator: a.CreatorId,
  31. CreatedAt: a.CreatedAt,
  32. }
  33. return item
  34. }
  35. // Role Role实体
  36. type Role struct {
  37. gorm.Model
  38. RecordID string `gorm:"column:record_id;size:32;index;"`
  39. Name string `gorm:"column:name;size:30;"` // 角色名称
  40. Code string `gorm:"column:code;size:5;"` // 角色编码(11 系统管理员 12 企业管理员 99 企业员工)
  41. ChartNum int `gorm:"column:chart_num;"` // 对话轮次/日
  42. CreatorId string `gorm:"column:creator_id;size:32;"`
  43. }
  44. // Roles Role列表
  45. type Roles []*Role
  46. // ToSchemaRoles 转换为Role对象列表
  47. func (a Roles) ToSchemaRoles() []*schema.Role {
  48. list := make([]*schema.Role, len(a))
  49. for i, item := range a {
  50. list[i] = item.ToSchemaRole()
  51. }
  52. return list
  53. }