123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- // Code generated by goctl. DO NOT EDIT.
- package model
- import (
- "context"
- "database/sql"
- "fmt"
- "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"
- "metawant.greentech.com.cn/gaoyagang/gt-common/envitem"
- "strings"
- )
- var (
- dcDeviceBindFieldNames = builder.RawFieldNames(&DcDeviceBind{})
- dcDeviceBindRows = strings.Join(dcDeviceBindFieldNames, ",")
- dcDeviceBindRowsExpectAutoSet = strings.Join(stringx.Remove(dcDeviceBindFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
- dcDeviceBindRowsWithPlaceHolder = strings.Join(stringx.Remove(dcDeviceBindFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
- )
- type (
- dcDeviceBindModel interface {
- Insert(ctx context.Context, data *DcDeviceBind) (sql.Result, error)
- FindOne(ctx context.Context, id int64) (*DcDeviceBind, error)
- FindByProjectIdDeviceType(ctx context.Context, projectId int64, deviceType string) ([]DcDeviceBind, error)
- FindOneByProjectIdDeviceCode(ctx context.Context, projectId int64, deviceCode string) (*DcDeviceBind, error)
- Update(ctx context.Context, data *DcDeviceBind) error
- Delete(ctx context.Context, id int64) error
- }
- defaultDcDeviceBindModel struct {
- conn sqlx.SqlConn
- table string
- }
- DcDeviceBind struct {
- Id int64 `db:"id"`
- ProjectId int64 `db:"project_id"`
- Name string `db:"name"` // 关系名
- DeviceCode string `db:"device_code"` // 关键设备指标
- DeviceType string `db:"device_type"` // 设备类型
- Status int64 `db:"status"` // 当前状态 0: 禁用 1: 正常
- Items envitem.MultiEnvItem `db:"items"` // 相关点位集合
- TargetTable string `db:"target_table"` // 数据存入目标表名
- }
- )
- func newDcDeviceBindModel(conn sqlx.SqlConn) *defaultDcDeviceBindModel {
- return &defaultDcDeviceBindModel{
- conn: conn,
- table: "`dc_device_bind`",
- }
- }
- func (m *defaultDcDeviceBindModel) withSession(session sqlx.Session) *defaultDcDeviceBindModel {
- return &defaultDcDeviceBindModel{
- conn: sqlx.NewSqlConnFromSession(session),
- table: "`dc_device_bind`",
- }
- }
- func (m *defaultDcDeviceBindModel) 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 *defaultDcDeviceBindModel) FindOne(ctx context.Context, id int64) (*DcDeviceBind, error) {
- query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", dcDeviceBindRows, m.table)
- var resp DcDeviceBind
- 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 *defaultDcDeviceBindModel) FindByProjectIdDeviceType(ctx context.Context, projectId int64, deviceType string) ([]DcDeviceBind, error) {
- var resp []DcDeviceBind
- query := fmt.Sprintf("select %s from %s where `project_id` = ? and `device_type` = ?", dcDeviceBindRows, m.table)
- err := m.conn.QueryRowsCtx(ctx, &resp, query, projectId, deviceType)
- switch err {
- case nil:
- return resp, nil
- case sqlc.ErrNotFound:
- return nil, ErrNotFound
- default:
- return nil, err
- }
- }
- func (m *defaultDcDeviceBindModel) FindOneByProjectIdDeviceCode(ctx context.Context, projectId int64, deviceCode string) (*DcDeviceBind, error) {
- var resp DcDeviceBind
- query := fmt.Sprintf("select %s from %s where `project_id` = ? and `device_code` = ? limit 1", dcDeviceBindRows, m.table)
- err := m.conn.QueryRowCtx(ctx, &resp, query, projectId, deviceCode)
- switch err {
- case nil:
- return &resp, nil
- case sqlc.ErrNotFound:
- return nil, ErrNotFound
- default:
- return nil, err
- }
- }
- func (m *defaultDcDeviceBindModel) Insert(ctx context.Context, data *DcDeviceBind) (sql.Result, error) {
- query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, dcDeviceBindRowsExpectAutoSet)
- ret, err := m.conn.ExecCtx(ctx, query, data.ProjectId, data.Name, data.DeviceCode, data.DeviceType, data.Status, data.Items, data.TargetTable)
- return ret, err
- }
- func (m *defaultDcDeviceBindModel) Update(ctx context.Context, newData *DcDeviceBind) error {
- query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, dcDeviceBindRowsWithPlaceHolder)
- _, err := m.conn.ExecCtx(ctx, query, newData.ProjectId, newData.Name, newData.DeviceCode, newData.DeviceType, newData.Status, newData.Items, newData.TargetTable, newData.Id)
- return err
- }
- func (m *defaultDcDeviceBindModel) tableName() string {
- return m.table
- }
|