123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package edbmonitor
- import (
- "eta/eta_api/utils"
- "time"
- "github.com/beego/beego/v2/client/orm"
- )
- type EdbMonitorInfo struct {
- EdbMonitorId int `orm:"column(edb_monitor_id);pk"`
- EdbMonitorClassifyId int `description:"预警分类id"`
- EdbMonitorName string `description:"预警名称"`
- EdbInfoId int `description:"指标id"`
- EdbInfoType int `description:"指标类型"`
- EdbUniqueCode string `description:"指标唯一标识"`
- EdbClassifyId int `description:"指标id"`
- EdbCode string `description:"指标编码"`
- Source int `description:"指标来源"`
- SubSource int `description:"指标子来源: 0-经济数据库;1-日期序列;2-高频数据"`
- EdbLatestDate string `description:"最新日期"`
- EdbLatestValue float64 `description:"指标最新值"`
- MonitorType int `description:"突破方式: 0-向上突破;1-向下突破"`
- MonitorData float64 `description:"预警值"`
- MonitorLevel string `description:"预警等级"`
- State int `description:"预警状态: 0-已关闭;1-未触发;2-已触发"`
- EdbTriggerDate time.Time `description:"触发日期"`
- MonitorTriggerTime time.Time `description:"预警触发时间"`
- CreateUserId int `description:"创建人id"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- }
- func (m *EdbMonitorInfo) Insert() (int64, error) {
- o := orm.NewOrmUsingDB("data")
- return o.Insert(m)
- }
- func (m *EdbMonitorInfo) Update(cols []string) (err error) {
- if len(cols) == 0 {
- return
- }
- o := orm.NewOrmUsingDB("data")
- _, err = o.Update(m, cols...)
- return
- }
- func GetEdbMonitorLevelList() (list []string, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT DISTINCT monitor_level FROM edb_monitor_info`
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- func GetEdbMonitorEdbInfoList() (items []*EdbMonitorInfo, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM edb_monitor_info WHERE state <> 0`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- func DeleteEdbMonitorInfoById(id int) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `DELETE FROM edb_monitor_info WHERE edb_monitor_id =?`
- _, err = o.Raw(sql, id).Exec()
- return
- }
- func DeleteEdbMonitorInfoByIdList(ids []int) (err error) {
- if len(ids) == 0 {
- return
- }
- o := orm.NewOrmUsingDB("data")
- sql := `DELETE FROM edb_monitor_info WHERE edb_monitor_id IN(` + utils.GetOrmInReplace(len(ids)) + `)`
- _, err = o.Raw(sql, ids).Exec()
- return
- }
- func GetEdbMonitorInfoById(id int) (item *EdbMonitorInfo, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM edb_monitor_info WHERE edb_monitor_id =?`
- err = o.Raw(sql, id).QueryRow(&item)
- return
- }
- func GetEdbMonitorInfoByEdbInfoId(edbInfoId int) (items []*EdbMonitorInfo, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM edb_monitor_info WHERE edb_info_id =?`
- _, err = o.Raw(sql, edbInfoId).QueryRows(&items)
- return
- }
- func GetEdbMonitorInfoCountByClassifyId(classifyId []int) (count int, err error) {
- if len(classifyId) == 0 {
- return
- }
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT COUNT(*) AS count FROM edb_monitor_info WHERE edb_monitor_classify_id IN(` + utils.GetOrmInReplace(len(classifyId)) + `)`
- err = o.Raw(sql, classifyId).QueryRow(&count)
- return
- }
- func GetEdbMonitorInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT COUNT(*) AS count FROM edb_monitor_info WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- func GetEdbMonitorInfoPageByCondition(condition string, pars []interface{}, startSize int, pageSize int) (items []*EdbMonitorInfo, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM edb_monitor_info WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY create_time DESC LIMIT?,?`
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- func GetEdbMonitorCreateUserId() (userIds []int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT DISTINCT create_user_id FROM edb_monitor_info`
- _, err = o.Raw(sql).QueryRows(&userIds)
- return
- }
|