|
@@ -0,0 +1,231 @@
|
|
|
+package data_manage
|
|
|
+
|
|
|
+import (
|
|
|
+ "eta/eta_api/utils"
|
|
|
+ "fmt"
|
|
|
+ "github.com/beego/beego/v2/client/orm"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+type BaseFromBusinessData struct {
|
|
|
+ BusinessDataId int `orm:"column(business_data_id);pk" 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) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+
|
|
|
+ sql := `SELECT * FROM base_from_business_data WHERE 1=1 `
|
|
|
+ if condition != `` {
|
|
|
+ sql += ` ` + condition
|
|
|
+ }
|
|
|
+
|
|
|
+ if order != `` {
|
|
|
+ sql += ` ORDER BY ` + order
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = o.Raw(sql, pars).QueryRows(&result)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (m *BaseFromBusinessData) GetLimitDataList(condition string, pars []interface{}, order string, size int64) (result []*BaseFromBusinessData, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("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).QueryRows(&result)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (m *BaseFromBusinessData) GetPageDataList(condition []string, pars []interface{}, order string, startSize, size int64) (result []*BaseFromBusinessData, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ 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 = o.Raw(sql, pars).QueryRows(&result)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (m *BaseFromBusinessData) GetCountDataList(condition []string, pars []interface{}) (count int64, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ sql := `SELECT COUNT(1) FROM base_from_business_data `
|
|
|
+ if len(condition) > 0 {
|
|
|
+ sql += ` WHERE ` + strings.Join(condition, " AND ")
|
|
|
+ }
|
|
|
+ err = o.Raw(sql, pars).QueryRow(&count)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (m *BaseFromBusinessData) InsertDataByColl(addData interface{}) (err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ _, err = o.Insert(addData)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (m *BaseFromBusinessData) BatchInsertData(bulk int, dataList []interface{}) (err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ _, err = o.InsertMulti(bulk, dataList)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (m *BaseFromBusinessData) UpdateData(updateCols []string) (err error) {
|
|
|
+ o := orm.NewOrmUsingDB("data")
|
|
|
+ _, err = o.Update(m, updateCols...)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("UpdateDataByColl:Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (m *BaseFromBusinessData) GetEdbInfoMaxAndMinInfo(indexCode string) (result EdbInfoMaxAndMinInfo, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("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).QueryRow(&result)
|
|
|
+ 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).QueryRow(&latestValue)
|
|
|
+ result.LatestValue = latestValue
|
|
|
+
|
|
|
+ return
|
|
|
+}
|