dcEventBindModel_gen.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // Code generated by goctl. DO NOT EDIT.
  2. package model
  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/sqlc"
  11. "github.com/zeromicro/go-zero/core/stores/sqlx"
  12. "github.com/zeromicro/go-zero/core/stringx"
  13. )
  14. var (
  15. dcEventBindFieldNames = builder.RawFieldNames(&DcEventBind{})
  16. dcEventBindRows = strings.Join(dcEventBindFieldNames, ",")
  17. dcEventBindRowsExpectAutoSet = strings.Join(stringx.Remove(dcEventBindFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
  18. dcEventBindRowsWithPlaceHolder = strings.Join(stringx.Remove(dcEventBindFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
  19. )
  20. type (
  21. dcEventBindModel interface {
  22. Insert(ctx context.Context, data *DcEventBind) (sql.Result, error)
  23. FindOne(ctx context.Context, id int64) (*DcEventBind, error)
  24. FindByProjectIdRuleFlag(ctx context.Context, projectId int64, ruleFlag string) ([]DcEventBind, error)
  25. FindOneByProjectIdItemName(ctx context.Context, projectId int64, item string, name string) (*DcEventBind, error)
  26. FindOneByProjectIdItemRuleFlag(ctx context.Context, projectId int64, item string, ruleFlag string) (*DcEventBind, error)
  27. Update(ctx context.Context, data *DcEventBind) error
  28. Delete(ctx context.Context, id int64) error
  29. }
  30. defaultDcEventBindModel struct {
  31. conn sqlx.SqlConn
  32. table string
  33. }
  34. DcEventBind struct {
  35. Id int64 `db:"id"`
  36. ProjectId int64 `db:"project_id"` // 项目 ID
  37. DeviceCode string `db:"device_code"` // 设备位号
  38. Name string `db:"name"` // 事件名称
  39. Item string `db:"item"` // 点位名称
  40. RuleFlag string `db:"rule_flag"` // 绑定的事件引擎
  41. Config EventRule `db:"config"` // 事件配置 一个 json 配置,用于
  42. Interval int64 `db:"interval"` // 检测时间间隔
  43. CTime time.Time `db:"c_time"`
  44. }
  45. )
  46. func newDcEventBindModel(conn sqlx.SqlConn) *defaultDcEventBindModel {
  47. return &defaultDcEventBindModel{
  48. conn: conn,
  49. table: "`dc_event_bind`",
  50. }
  51. }
  52. func (m *defaultDcEventBindModel) withSession(session sqlx.Session) *defaultDcEventBindModel {
  53. return &defaultDcEventBindModel{
  54. conn: sqlx.NewSqlConnFromSession(session),
  55. table: "`dc_event_bind`",
  56. }
  57. }
  58. func (m *defaultDcEventBindModel) Delete(ctx context.Context, id int64) error {
  59. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  60. _, err := m.conn.ExecCtx(ctx, query, id)
  61. return err
  62. }
  63. func (m *defaultDcEventBindModel) FindOne(ctx context.Context, id int64) (*DcEventBind, error) {
  64. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", dcEventBindRows, m.table)
  65. var resp DcEventBind
  66. err := m.conn.QueryRowCtx(ctx, &resp, query, id)
  67. switch err {
  68. case nil:
  69. return &resp, nil
  70. case sqlc.ErrNotFound:
  71. return nil, ErrNotFound
  72. default:
  73. return nil, err
  74. }
  75. }
  76. func (m *defaultDcEventBindModel) FindByProjectIdRuleFlag(ctx context.Context, projectId int64, ruleFlag string) ([]DcEventBind, error) {
  77. var resp []DcEventBind
  78. query := fmt.Sprintf("select %s from %s where `project_id` = ? and `rule_flag` = ?", dcEventBindRows, m.table)
  79. err := m.conn.QueryRowsCtx(ctx, &resp, query, projectId, ruleFlag)
  80. switch err {
  81. case nil:
  82. return resp, nil
  83. case sqlc.ErrNotFound:
  84. return nil, ErrNotFound
  85. default:
  86. return nil, err
  87. }
  88. }
  89. func (m *defaultDcEventBindModel) FindOneByProjectIdItemRuleFlag(ctx context.Context, projectId int64, item string, ruleFlag string) (*DcEventBind, error) {
  90. var resp DcEventBind
  91. query := fmt.Sprintf("select %s from %s where `project_id` = ? and `item` = ? and `rule_flag` = ? limit 1", dcEventBindRows, m.table)
  92. err := m.conn.QueryRowCtx(ctx, &resp, query, projectId, item, ruleFlag)
  93. switch err {
  94. case nil:
  95. return &resp, nil
  96. case sqlc.ErrNotFound:
  97. return nil, ErrNotFound
  98. default:
  99. return nil, err
  100. }
  101. }
  102. func (m *defaultDcEventBindModel) FindOneByProjectIdItemName(ctx context.Context, projectId int64, item string, name string) (*DcEventBind, error) {
  103. var resp DcEventBind
  104. query := fmt.Sprintf("select %s from %s where `project_id` = ? and `item` = ? and `name` = ? limit 1", dcEventBindRows, m.table)
  105. err := m.conn.QueryRowCtx(ctx, &resp, query, projectId, item, name)
  106. switch err {
  107. case nil:
  108. return &resp, nil
  109. case sqlc.ErrNotFound:
  110. return nil, ErrNotFound
  111. default:
  112. return nil, err
  113. }
  114. }
  115. func (m *defaultDcEventBindModel) Insert(ctx context.Context, data *DcEventBind) (sql.Result, error) {
  116. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, dcEventBindRowsExpectAutoSet)
  117. ret, err := m.conn.ExecCtx(ctx, query, data.ProjectId, data.DeviceCode, data.Name, data.Item, data.RuleFlag, data.Config, data.Interval, data.CTime)
  118. return ret, err
  119. }
  120. func (m *defaultDcEventBindModel) Update(ctx context.Context, newData *DcEventBind) error {
  121. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, dcEventBindRowsWithPlaceHolder)
  122. _, err := m.conn.ExecCtx(ctx, query, newData.ProjectId, newData.DeviceCode, newData.Name, newData.Item, newData.RuleFlag, newData.Config, newData.Interval, newData.CTime, newData.Id)
  123. return err
  124. }
  125. func (m *defaultDcEventBindModel) tableName() string {
  126. return m.table
  127. }