Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

config_template.go 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package models
  2. import (
  3. "database/sql"
  4. "encoding/json"
  5. "strings"
  6. "time"
  7. )
  8. // ConfigTemplate 配置模板表
  9. type ConfigTemplate struct {
  10. ID int64 `json:"id" db:"id"` // 技术主键
  11. Name string `json:"name" db:"name"` // 模板名称
  12. TypeCode string `json:"type_code" db:"type_code"` // 类型编码,关联template_type.code
  13. Content json.RawMessage `json:"content" db:"content"` // 模板内容JSON
  14. ServiceType sql.NullString `json:"service_type,omitempty" db:"service_type"` // 适用服务类型
  15. IsDefault bool `json:"is_default" db:"is_default"` // 是否默认模板
  16. SortOrder int `json:"sort_order" db:"sort_order"` // 排序号
  17. Creator string `json:"creator" db:"creator"` // 创建人
  18. CreatedAt time.Time `json:"created_at" db:"created_at"` // 创建时间
  19. }
  20. // TableName 返回表名
  21. func (ConfigTemplate) TableName() string {
  22. return "config_template"
  23. }
  24. // TemplateKey 返回业务键:type_code.name
  25. func (c *ConfigTemplate) TemplateKey() string {
  26. return c.TypeCode + "." + c.Name
  27. }
  28. // ParseTemplateKey 解析业务键
  29. func ParseTemplateKey(key string) (typeCode, name string, ok bool) {
  30. parts := strings.SplitN(key, ".", 2)
  31. if len(parts) != 2 {
  32. return "", "", false
  33. }
  34. return parts[0], parts[1], true
  35. }