123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- // Code generated by goctl. DO NOT EDIT.
- package model
- import (
- "context"
- "database/sql"
- "fmt"
- "metawant.greentech.com.cn/gaoyagang/gt-common/identify"
- "strings"
- "time"
- "github.com/zeromicro/go-zero/core/stores/builder"
- "github.com/zeromicro/go-zero/core/stores/sqlc"
- "github.com/zeromicro/go-zero/core/stores/sqlx"
- "github.com/zeromicro/go-zero/core/stringx"
- )
- var (
- dcEventBindFieldNames = builder.RawFieldNames(&DcEventBind{})
- dcEventBindRows = strings.Join(dcEventBindFieldNames, ",")
- dcEventBindRowsExpectAutoSet = strings.Join(stringx.Remove(dcEventBindFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
- dcEventBindRowsWithPlaceHolder = strings.Join(stringx.Remove(dcEventBindFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
- )
- type (
- dcEventBindModel interface {
- Insert(ctx context.Context, data *DcEventBind) (sql.Result, error)
- FindOne(ctx context.Context, id int64) (*DcEventBind, error)
- FindByProjectIdRuleFlag(ctx context.Context, projectId int64, ruleFlag string) ([]DcEventBind, error)
- FindOneByProjectIdItemName(ctx context.Context, projectId int64, item string, name string) (*DcEventBind, error)
- FindOneByProjectIdItemRuleFlag(ctx context.Context, projectId int64, item string, ruleFlag string) (*DcEventBind, error)
- Update(ctx context.Context, data *DcEventBind) error
- Delete(ctx context.Context, id int64) error
- }
- defaultDcEventBindModel struct {
- conn sqlx.SqlConn
- table string
- }
- DcEventBind struct {
- Id int64 `db:"id"`
- ProjectId int64 `db:"project_id"` // 项目 ID
- DeviceCode string `db:"device_code"` // 设备位号
- Name string `db:"name"` // 事件名称
- Item string `db:"item"` // 点位名称
- RuleFlag string `db:"rule_flag"` // 绑定的事件引擎
- Config identify.Rule `db:"config"` // 事件配置 一个 json 配置,用于
- Interval int64 `db:"interval"` // 检测时间间隔
- CTime time.Time `db:"c_time"`
- }
- )
- func newDcEventBindModel(conn sqlx.SqlConn) *defaultDcEventBindModel {
- return &defaultDcEventBindModel{
- conn: conn,
- table: "`dc_event_bind`",
- }
- }
- func (m *defaultDcEventBindModel) withSession(session sqlx.Session) *defaultDcEventBindModel {
- return &defaultDcEventBindModel{
- conn: sqlx.NewSqlConnFromSession(session),
- table: "`dc_event_bind`",
- }
- }
- func (m *defaultDcEventBindModel) Delete(ctx context.Context, id int64) error {
- query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
- _, err := m.conn.ExecCtx(ctx, query, id)
- return err
- }
- func (m *defaultDcEventBindModel) FindOne(ctx context.Context, id int64) (*DcEventBind, error) {
- query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", dcEventBindRows, m.table)
- var resp DcEventBind
- err := m.conn.QueryRowCtx(ctx, &resp, query, id)
- switch err {
- case nil:
- return &resp, nil
- case sqlc.ErrNotFound:
- return nil, ErrNotFound
- default:
- return nil, err
- }
- }
- func (m *defaultDcEventBindModel) FindByProjectIdRuleFlag(ctx context.Context, projectId int64, ruleFlag string) ([]DcEventBind, error) {
- var resp []DcEventBind
- query := fmt.Sprintf("select %s from %s where `project_id` = ? and `rule_flag` = ?", dcEventBindRows, m.table)
- err := m.conn.QueryRowsCtx(ctx, &resp, query, projectId, ruleFlag)
- switch err {
- case nil:
- return resp, nil
- case sqlc.ErrNotFound:
- return nil, ErrNotFound
- default:
- return nil, err
- }
- }
- func (m *defaultDcEventBindModel) FindOneByProjectIdItemRuleFlag(ctx context.Context, projectId int64, item string, ruleFlag string) (*DcEventBind, error) {
- var resp DcEventBind
- query := fmt.Sprintf("select %s from %s where `project_id` = ? and `item` = ? and `rule_flag` = ? limit 1", dcEventBindRows, m.table)
- err := m.conn.QueryRowCtx(ctx, &resp, query, projectId, item, ruleFlag)
- switch err {
- case nil:
- return &resp, nil
- case sqlc.ErrNotFound:
- return nil, ErrNotFound
- default:
- return nil, err
- }
- }
- func (m *defaultDcEventBindModel) FindOneByProjectIdItemName(ctx context.Context, projectId int64, item string, name string) (*DcEventBind, error) {
- var resp DcEventBind
- query := fmt.Sprintf("select %s from %s where `project_id` = ? and `item` = ? and `name` = ? limit 1", dcEventBindRows, m.table)
- err := m.conn.QueryRowCtx(ctx, &resp, query, projectId, item, name)
- switch err {
- case nil:
- return &resp, nil
- case sqlc.ErrNotFound:
- return nil, ErrNotFound
- default:
- return nil, err
- }
- }
- func (m *defaultDcEventBindModel) Insert(ctx context.Context, data *DcEventBind) (sql.Result, error) {
- query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, dcEventBindRowsExpectAutoSet)
- ret, err := m.conn.ExecCtx(ctx, query, data.ProjectId, data.DeviceCode, data.Name, data.Item, data.RuleFlag, data.Config, data.Interval, data.CTime)
- return ret, err
- }
- func (m *defaultDcEventBindModel) Update(ctx context.Context, newData *DcEventBind) error {
- query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, dcEventBindRowsWithPlaceHolder)
- _, err := m.conn.ExecCtx(ctx, query, newData.ProjectId, newData.DeviceCode, newData.Name, newData.Item, newData.RuleFlag, newData.Config, newData.Interval, newData.CTime, newData.Id)
- return err
- }
- func (m *defaultDcEventBindModel) tableName() string {
- return m.table
- }
|