dcEventBindModel_gen.go 5.4 KB

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