You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

resourcepanelconfigmodel_gen.go 6.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Code generated by goctl. DO NOT EDIT.
  2. package models
  3. import (
  4. "context"
  5. "database/sql"
  6. "fmt"
  7. "strings"
  8. "time"
  9. "github.com/zeromicro/go-zero/core/stores/builder"
  10. "github.com/zeromicro/go-zero/core/stores/cache"
  11. "github.com/zeromicro/go-zero/core/stores/sqlc"
  12. "github.com/zeromicro/go-zero/core/stores/sqlx"
  13. "github.com/zeromicro/go-zero/core/stringx"
  14. )
  15. var (
  16. resourcePanelConfigFieldNames = builder.RawFieldNames(&ResourcePanelConfig{})
  17. resourcePanelConfigRows = strings.Join(resourcePanelConfigFieldNames, ",")
  18. resourcePanelConfigRowsExpectAutoSet = strings.Join(stringx.Remove(resourcePanelConfigFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
  19. resourcePanelConfigRowsWithPlaceHolder = strings.Join(stringx.Remove(resourcePanelConfigFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
  20. cachePcmResourcePanelConfigIdPrefix = "cache:pcm:resourcePanelConfig:id:"
  21. )
  22. type (
  23. resourcePanelConfigModel interface {
  24. Insert(ctx context.Context, data *ResourcePanelConfig) (sql.Result, error)
  25. FindOne(ctx context.Context, id int64) (*ResourcePanelConfig, error)
  26. Update(ctx context.Context, data *ResourcePanelConfig) error
  27. Delete(ctx context.Context, id int64) error
  28. }
  29. defaultResourcePanelConfigModel struct {
  30. sqlc.CachedConn
  31. table string
  32. }
  33. ResourcePanelConfig struct {
  34. Id int64 `db:"id"`
  35. Title string `db:"title"` // 标题
  36. TitleColor string `db:"title_color"` // 标题色
  37. MainColor string `db:"main_color"` // 主色调
  38. MainColor2 string `db:"main_color2"` // 次主色调
  39. TextColor string `db:"text_color"` // 文字颜色
  40. BackgroundColor string `db:"background_color"` // 背景底色
  41. Center string `db:"center"` // 中心点
  42. CenterPosition string `db:"center_position"` // 中心点坐标
  43. ProvinceBgColor string `db:"province_bg_color"` // 三级地图底色
  44. StatusIng string `db:"status_ing"` // 接入中图标
  45. StatusUn string `db:"status_un"` // 未接入图标
  46. StatusEnd string `db:"status_end"` // 已接入图标
  47. TitleIcon string `db:"title_icon"` // 标题底图
  48. SubTitleIcon string `db:"sub_title_icon"` // 小标题底图
  49. NumberBg string `db:"number_bg"` // 数字底图
  50. TaskBg string `db:"task_bg"` // 任务底图
  51. CreateTime time.Time `db:"create_time"` // 创建时间
  52. UpdateTime time.Time `db:"update_time"` // 更新时间
  53. }
  54. )
  55. func newResourcePanelConfigModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultResourcePanelConfigModel {
  56. return &defaultResourcePanelConfigModel{
  57. CachedConn: sqlc.NewConn(conn, c, opts...),
  58. table: "`resource_panel_config`",
  59. }
  60. }
  61. func (m *defaultResourcePanelConfigModel) Delete(ctx context.Context, id int64) error {
  62. pcmResourcePanelConfigIdKey := fmt.Sprintf("%s%v", cachePcmResourcePanelConfigIdPrefix, id)
  63. _, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
  64. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  65. return conn.ExecCtx(ctx, query, id)
  66. }, pcmResourcePanelConfigIdKey)
  67. return err
  68. }
  69. func (m *defaultResourcePanelConfigModel) FindOne(ctx context.Context, id int64) (*ResourcePanelConfig, error) {
  70. pcmResourcePanelConfigIdKey := fmt.Sprintf("%s%v", cachePcmResourcePanelConfigIdPrefix, id)
  71. var resp ResourcePanelConfig
  72. err := m.QueryRowCtx(ctx, &resp, pcmResourcePanelConfigIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
  73. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", resourcePanelConfigRows, m.table)
  74. return conn.QueryRowCtx(ctx, v, query, id)
  75. })
  76. switch err {
  77. case nil:
  78. return &resp, nil
  79. case sqlc.ErrNotFound:
  80. return nil, ErrNotFound
  81. default:
  82. return nil, err
  83. }
  84. }
  85. func (m *defaultResourcePanelConfigModel) Insert(ctx context.Context, data *ResourcePanelConfig) (sql.Result, error) {
  86. pcmResourcePanelConfigIdKey := fmt.Sprintf("%s%v", cachePcmResourcePanelConfigIdPrefix, data.Id)
  87. ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
  88. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, resourcePanelConfigRowsExpectAutoSet)
  89. return conn.ExecCtx(ctx, query, data.Title, data.TitleColor, data.MainColor, data.MainColor2, data.TextColor, data.BackgroundColor, data.Center, data.CenterPosition, data.ProvinceBgColor, data.StatusIng, data.StatusUn, data.StatusEnd, data.TitleIcon, data.SubTitleIcon, data.NumberBg, data.TaskBg)
  90. }, pcmResourcePanelConfigIdKey)
  91. return ret, err
  92. }
  93. func (m *defaultResourcePanelConfigModel) Update(ctx context.Context, data *ResourcePanelConfig) error {
  94. pcmResourcePanelConfigIdKey := fmt.Sprintf("%s%v", cachePcmResourcePanelConfigIdPrefix, data.Id)
  95. _, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
  96. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, resourcePanelConfigRowsWithPlaceHolder)
  97. return conn.ExecCtx(ctx, query, data.Title, data.TitleColor, data.MainColor, data.MainColor2, data.TextColor, data.BackgroundColor, data.Center, data.CenterPosition, data.ProvinceBgColor, data.StatusIng, data.StatusUn, data.StatusEnd, data.TitleIcon, data.SubTitleIcon, data.NumberBg, data.TaskBg, data.Id)
  98. }, pcmResourcePanelConfigIdKey)
  99. return err
  100. }
  101. func (m *defaultResourcePanelConfigModel) formatPrimary(primary any) string {
  102. return fmt.Sprintf("%s%v", cachePcmResourcePanelConfigIdPrefix, primary)
  103. }
  104. func (m *defaultResourcePanelConfigModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
  105. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", resourcePanelConfigRows, m.table)
  106. return conn.QueryRowCtx(ctx, v, query, primary)
  107. }
  108. func (m *defaultResourcePanelConfigModel) tableName() string {
  109. return m.table
  110. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.