package data_manage import ( "eta_gn/eta_api/global" "fmt" "time" ) // EdbTerminal 指标终端 type EdbTerminal struct { TerminalId int `orm:"column(terminal_id);pk" gorm:"primaryKey" ` Source int `orm:"column(source)" description:"指标来源类型"` Name string `description:"终端名称"` TerminalCode string `description:"终端编码,用于配置在机器上"` ServerUrl string `description:"终端地址"` DirPath string `description:"终端存放的文件夹路径"` Num int `description:"终端最大指标数"` Status int `description:"状态,1启用,2禁用"` Value string `description:"终端相关的token"` ModifyTime time.Time `description:"修改时间"` CreateTime time.Time `description:"创建时间"` } type EdbTerminalItem struct { TerminalId int `orm:"column(terminal_id);pk" gorm:"primaryKey" ` Source int `description:"指标来源类型"` Name string `description:"终端别名"` TerminalCode string `description:"终端编码,用于配置在机器上"` ServerUrl string `description:"终端地址"` DirPath string `description:"终端存放的文件夹路径"` Num int `description:"终端最大指标数"` Status int `description:"状态,1启用,2禁用"` Value string `description:"终端相关的token"` ModifyTime string `description:"修改时间"` CreateTime string `description:"创建时间"` } type EdbTerminalCode struct { TerminalCode string `description:"终端编码,用于配置在机器上"` Source int `description:"指标来源类型"` Name string `description:"终端别名"` } // GetEdbTerminalListBySource 根据指标来源类型获取所有的终端列表 func GetEdbTerminalListBySource(source int) (items []*EdbTerminal, err error) { o := global.DmSQL["data"] sql := ` SELECT * FROM edb_terminal WHERE source = ? and status=1 ORDER BY terminal_id ASC ` err = o.Raw(sql, source).Find(&items).Error return } type BaseIndexTerminalCode struct { TerminalCode string `description:"终端编码,用于配置在机器上"` IndexName string } type EdbTerminalListResp struct { List []*EdbTerminalItem `description:"列表数据"` } type EdbTerminalCodeResp struct { List []*EdbTerminalCode `description:"终端编码列表"` } type AddEdbTerminalListReq struct { TerminalId int `description:"终端id"` Source int `description:"指标来源类型"` Name string `description:"终端别名"` //TerminalCode string `description:"终端编码,用于配置在机器上"` ServerUrl string `description:"终端地址"` DirPath string `description:"终端存放的文件夹路径"` Num int `description:"终端最大指标数"` //Status int `description:"状态,1启用,2禁用"` Value string `description:"终端相关的token"` } type SetEdbTerminalStatusReq struct { TerminalId int `description:"终端id"` Status int `description:"状态,1启用,2禁用"` } // GetBaseIndexTerminalCode 获取数据源的终端code func GetBaseIndexTerminalCode(edbCode, tableName string) (item BaseIndexTerminalCode, err error) { o := global.DmSQL["data"] sql := fmt.Sprintf(`select terminal_code, index_name from %s where index_code = ? `, tableName) err = o.Raw(sql, edbCode).Scan(&item).Error return } // GetEdbTerminalById 主键获取终端 func GetEdbTerminalById(id int) (item *EdbTerminal, err error) { sql := `SELECT * FROM edb_terminal WHERE terminal_id = ? LIMIT 1` err = global.DmSQL["data"].Raw(sql, id).First(&item).Error return } func GetEdbTerminalByTerminalCode(terminalCode string) (item *EdbTerminal, err error) { sql := `SELECT * FROM edb_terminal WHERE terminal_code = ? LIMIT 1` err = global.DmSQL["data"].Raw(sql, terminalCode).First(&item).Error return } func GetEdbTerminalList() (item []*EdbTerminalItem, err error) { o := global.DmSQL["data"] sql := ` SELECT * FROM edb_terminal ORDER BY terminal_id ASC` err = o.Raw(sql).Scan(&item).Error return } func GetEdbTerminalBySource(source int) (item []*EdbTerminalItem, err error) { o := global.DmSQL["data"] sql := ` SELECT * FROM edb_terminal where source=? ORDER BY terminal_id ASC` err = o.Raw(sql, source).Scan(&item).Error return } func (item *EdbTerminal) Add() (err error) { err = global.DmSQL["data"].Create(item).Error return } func (item *EdbTerminal) Update(cols []string) (err error) { o := global.DmSQL["data"] err = o.Select(cols).Updates(item).Error return } // GetEdbTerminalByCode 根据终端编码获取终端信息 func GetEdbTerminalByCode(terminalCode string) (item *EdbTerminal, err error) { sql := ` SELECT * FROM edb_terminal WHERE terminal_code = ? ` err = global.DmSQL["data"].Raw(sql, terminalCode).First(&item).Error return } type TerminalCodeCountGroup struct { TerminalCode string Total int } // GetEdbCountGroupByTerminal 获取终端code分组总数 func GetEdbCountGroupByTerminal(source int) (list []TerminalCodeCountGroup, err error) { o := global.DmSQL["data"] sql := `select terminal_code,count(1) total from edb_info where source = ? AND no_update=0 AND terminal_code != "" group by terminal_code; ` err = o.Raw(sql, source).Scan(&list).Error return }