123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- package data_manage
- import (
- "eta_gn/eta_api/global"
- "eta_gn/eta_api/utils"
- "fmt"
- "strings"
- "time"
- )
- type BaseFromBusinessData struct {
- BusinessDataId int `orm:"column(business_data_id);pk" gorm:"primaryKey" json:"business_data_id"`
- BaseFromBusinessIndexId int `json:"base_from_business_index_id"`
- IndexCode string `json:"index_code"`
- DataTime time.Time `json:"data_time"`
- Value float64 `json:"value"`
- CreateTime time.Time `json:"create_time"`
- ModifyTime time.Time `json:"modify_time"`
- }
- func (m *BaseFromBusinessData) TableName() string {
- return "base_from_business_data"
- }
- func (m *BaseFromBusinessData) CollectionName() string {
- return "base_from_business_data"
- }
- func (m *BaseFromBusinessData) DataBaseName() string {
- return utils.MgoDataDbName
- }
- type WhereParams struct {
- Condition string
- Pars []interface{}
- Order string `description:"排序字段"`
- }
- func (m *BaseFromBusinessData) GetAllDataList(condition string, pars []interface{}, order string) (result []*BaseFromBusinessData, err error) {
- sql := `SELECT * FROM base_from_business_data WHERE 1=1 `
- if condition != `` {
- sql += ` ` + condition
- }
- if order != `` {
- sql += ` ORDER BY ` + order
- }
- err = global.DmSQL["data"].Raw(sql, pars...).Scan(&result).Error
- return
- }
- func (m *BaseFromBusinessData) GetLimitDataList(condition string, pars []interface{}, order string, size int64) (result []*BaseFromBusinessData, err error) {
- o := global.DmSQL["data"]
- sql := `SELECT * FROM base_from_business_data WHERE 1=1 `
- if condition != `` {
- sql += ` ` + condition
- }
- if order != `` {
- sql += ` ORDER BY ` + order
- }
- sql += fmt.Sprintf(` LIMIT %d`, size)
- err = o.Raw(sql, pars...).Scan(&result).Error
- return
- }
- func (m *BaseFromBusinessData) GetPageDataList(condition []string, pars []interface{}, order string, startSize, size int64) (result []*BaseFromBusinessData, err error) {
- sql := `SELECT * FROM base_from_business_data `
- if len(condition) > 0 {
- sql += ` WHERE ` + strings.Join(condition, " AND ")
- }
- if order != `` {
- sql += ` ORDER BY ` + order
- }
- sql += fmt.Sprintf(` LIMIT %d,%d`, startSize, size)
- err = global.DmSQL["data"].Raw(sql, pars...).Scan(&result).Error
- return
- }
- func (m *BaseFromBusinessData) GetCountDataList(condition []string, pars []interface{}) (count int64, err error) {
- sql := `SELECT COUNT(1) FROM base_from_business_data `
- if len(condition) > 0 {
- sql += ` WHERE ` + strings.Join(condition, " AND ")
- }
- err = global.DmSQL["data"].Raw(sql, pars...).Scan(&count).Error
- return
- }
- func (m *BaseFromBusinessData) InsertDataByColl(addData interface{}) (err error) {
- err = global.DmSQL["data"].Create(addData).Error
- return
- }
- func (m *BaseFromBusinessData) BatchInsertData(bulk int, dataList []interface{}) (err error) {
- err = global.DmSQL["data"].CreateInBatches(dataList, bulk).Error
- return
- }
- func (m *BaseFromBusinessData) UpdateData(updateCols []string) (err error) {
- err = global.DmSQL["data"].Select(updateCols).Updates(m).Error
- if err != nil {
- fmt.Println("UpdateDataByColl:Err:" + err.Error())
- return
- }
- return
- }
- func (m *BaseFromBusinessData) GetEdbInfoMaxAndMinInfo(indexCode string) (result EdbInfoMaxAndMinInfo, err error) {
- o := global.DmSQL["data"]
- sql := ``
- sql = ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date,MIN(value) AS min_value,MAX(value) AS max_value FROM base_from_business_data WHERE index_code = ? `
- err = o.Raw(sql, indexCode).Scan(&result).Error
- if err != nil {
- return
- }
- var latestValue float64
- sql = ` SELECT value AS latest_value FROM base_from_business_data WHERE index_code = ? ORDER BY data_time DESC LIMIT 1 `
- err = o.Raw(sql, indexCode).Scan(&latestValue).Error
- result.LatestValue = latestValue
- return
- }
|