package edb_refresh

import (
	"errors"
	"github.com/beego/beego/v2/client/orm"
	"time"
)

// EdbRefreshMapping
// @Description: 指标刷新时间配置关系表
type EdbRefreshMapping struct {
	EdbRefreshMappingId int       `orm:"column(edb_refresh_mapping_id);pk"`
	Source              int       `description:"来源"`
	SubSource           int       `description:"来源名称"`
	EdbInfoId           int       `description:"指标id，如果是数据源（钢联、有色）的，那么就是数据源里面的id"`
	EdbRefreshConfigId  int       `description:"刷新配置id"`
	SysUserId           int       `description:"操作人id"`
	SysUserRealName     string    `description:"操作人真实姓名"`
	ModifyTime          time.Time `description:"最晚一次的更新时间"`
	CreateTime          time.Time `description:"添加时间"`
}

// Add
// @Description: 添加
// @author: Roc
// @receiver m
// @datetime 2023-12-14 16:11:10
// @param cols []string
// @return err error
func (m *EdbRefreshMapping) Add() (err error) {
	if m.EdbRefreshMappingId > 0 {
		err = errors.New("该配置已存在")
		return
	}
	o := orm.NewOrmUsingDB("data")
	lastId, err := o.Insert(m)
	if err != nil {
		return
	}
	m.EdbRefreshMappingId = int(lastId)

	return
}

// Update
// @Description: 更新
// @author: Roc
// @receiver m
// @datetime 2023-12-14 16:11:10
// @param cols []string
// @return err error
func (m *EdbRefreshMapping) Update(cols []string) (err error) {
	o := orm.NewOrmUsingDB("data")
	_, err = o.Update(m, cols...)
	return
}

// Delete
// @Description: 删除
// @author: Roc
// @receiver m
// @datetime 2023-12-14 16:11:10
// @return err error
func (m *EdbRefreshMapping) Delete() (err error) {
	o := orm.NewOrmUsingDB("data")
	_, err = o.Delete(m)
	return
}
