123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- package data_manage
- import (
- "eta/eta_mobile/utils"
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type BaseFromSmm struct {
- BaseFromSmmId int `orm:"column(base_from_smm_id);pk"`
- Aid int
- Name string
- Interface string
- ApiUpdate int
- ApiUpdateType string
- ApiType int
- ApiTypeAll string
- Type1 string `orm:"column(type_1)"`
- Type2 string `orm:"column(type_2)"`
- Type3 string `orm:"column(type_3)"`
- ApiStartTime string
- ApiUpdateTime string
- StartTime string
- FinishTime string
- AuthModule string
- AuthLang string
- ApiLabel string
- Enable string
- EditPerson string
- EditTime string
- AuthDur int
- AuthDurType string
- }
- func AddBaseFromSmm(item *BaseFromSmm) (lastId int64, err error) {
- o := orm.NewOrmUsingDB("data")
- lastId, err = o.Insert(item)
- return
- }
- func GetBaseFromSmmList() (list []*BaseFromSmm, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM base_from_smm `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- func GetBaseFromSmmBySmmCode(smmCode string) (item *BaseFromSmm, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM base_from_smm WHERE interface=?`
- err = o.Raw(sql, smmCode).QueryRow(&item)
- return
- }
- type BaseFromSmmIndex struct {
- BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk"`
- ClassifyId int
- Interface string
- Name string
- IndexCode string
- IndexName string
- Type1 string `orm:"column(type_1)"`
- Type2 string `orm:"column(type_2)"`
- Type3 string `orm:"column(type_3)"`
- Frequency string
- Unit string
- ApiStartTime string
- ApiUpdateTime string
- StartTime string
- FinishTime string
- Sort int
- CreateTime time.Time
- ModifyTime time.Time
- }
- func AddBaseFromSmmIndex(item *BaseFromSmmIndex) (lastId int64, err error) {
- o := orm.NewOrmUsingDB("data")
- lastId, err = o.Insert(item)
- return
- }
- func GetBaseFromSmmIndex() (list []*BaseFromSmmIndex, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM base_from_smm_index `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- type BaseFromSmmData struct {
- SmmDataId int `orm:"column(smm_data_id);pk"`
- BaseFromSmmIndexId int
- IndexCode string
- DataTime string
- Value string
- CreateTime time.Time
- ModifyTime time.Time
- DataTimestamp int64
- }
- func AddBaseFromSmmData(item *BaseFromSmmData) (lastId int64, err error) {
- o := orm.NewOrmUsingDB("data")
- lastId, err = o.Insert(item)
- return
- }
- func GetBaseFromSmmDataAll() (list []*BaseFromSmmData, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM base_from_smm_data `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- func ModifyBaseFromSmmData(smmDataId int, value string) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `UPDATE base_from_smm_data SET value=?,modify_time=NOW() WHERE smm_data_id=? `
- _, err = o.Raw(sql, value, smmDataId).Exec()
- return
- }
- func GetBaseFromSmmIndexBySmmCode(smmCode string) (list []*BaseFromSmmIndex, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_smm_index WHERE interface=? `
- _, err = o.Raw(sql, smmCode).QueryRows(&list)
- return
- }
- func GetBaseFromSmmMaxOrMinDate(indexCode string) (min_date, max_date string, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM base_from_smm_data WHERE index_code=? `
- err = o.Raw(sql, indexCode).QueryRow(&min_date, &max_date)
- return
- }
- func ModifyBaseFromSmmMinDateAndMaxDate(baseFromSmmIndexId int, minDate, maxDate string) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` UPDATE base_from_smm_index SET start_date=?,end_date=?,modify_time=NOW() WHERE base_from_smm_index_id=? `
- _, err = o.Raw(sql, minDate, maxDate, baseFromSmmIndexId).Exec()
- return
- }
- func GetBaseFromSmmDataAllByIndexCode(indexCode string) (list []*BaseFromSmmData, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM base_from_smm_data WHERE index_code=? `
- _, err = o.Raw(sql, indexCode).QueryRows(&list)
- return
- }
- func GetBaseFromSmmIndexByIndexCode(indexCode string) (list *BaseFromSmmIndex, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_smm_index WHERE index_code=? `
- err = o.Raw(sql, indexCode).QueryRow(&list)
- return
- }
- // GetBaseFromSmmIndexCountByClassifyIds 获取分类下指标的个数
- func GetBaseFromSmmIndexCountByClassifyIds(classifyIds []int) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- num := len(classifyIds)
- if num <= 0 {
- return
- }
- sql := `SELECT COUNT(1) AS count FROM base_from_smm_index WHERE classify_id IN (` + utils.GetOrmInReplace(num) + `) `
- err = o.Raw(sql, classifyIds).QueryRow(&count)
- return
- }
- // GetBaseFromSmmIndexByClassifyId 获取根据分类查询指标
- func GetBaseFromSmmIndexByClassifyId(classifyId int) (list []*BaseFromSmmIndex, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM base_from_smm_index WHERE classify_id =? ORDER BY sort ASC, base_from_smm_index_id ASC `
- _, err = o.Raw(sql, classifyId).QueryRows(&list)
- return
- }
- // GetSmmIndexAll 用于分类展示
- //func GetSmmIndexAll() (items []*BaseFromSmmClassifyItems, err error) {
- // o := orm.NewOrmUsingDB("data")
- // sql := ` SELECT base_from_smm_index_id, classify_id, index_name as classify_name, index_code as base_from_smm_index_code
- // FROM base_from_smm_index ORDER BY sort ASC, base_from_smm_index_id ASC `
- // _, err = o.Raw(sql).QueryRows(&items)
- // return
- //}
- // GetBaseFromSmmIndexByIndexId 根据指标id获取指标信息
- func GetBaseFromSmmIndexByIndexId(indexId int) (item *BaseFromSmmIndex, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM base_from_smm_index WHERE base_from_smm_index_id=? `
- err = o.Raw(sql, indexId).QueryRow(&item)
- return
- }
- // GetBaseFromSmmIndexMaxSortByClassifyId 根据指标id获取指标信息
- func GetBaseFromSmmIndexMaxSortByClassifyId(classifyId int) (sort int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT max(sort) FROM base_from_smm_index WHERE classify_id=? `
- err = o.Raw(sql, classifyId).QueryRow(&sort)
- return
- }
- // GetBaseFromSmmIndexMinSortByClassifyId 获取最小不等于0的排序
- func GetBaseFromSmmIndexMinSortByClassifyId(classifyId int) (sort int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT min(sort) FROM base_from_smm_index WHERE classify_id=? and sort <> 0 `
- err = o.Raw(sql, classifyId).QueryRow(&sort)
- return
- }
- type BaseFromSmmIndexType struct {
- Type2 string `orm:"column(type_2)"`
- Type3 string `orm:"column(type_3)"`
- }
- // GetBaseFromSmmIndexType 获取历史指标信息类型
- func GetBaseFromSmmIndexType() (list []BaseFromSmmIndexType, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT type_2, type_3 from base_from_smm_index where type_2 <> "" GROUP BY type_2, type_3`
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- // MoveBaseFromSmmIndex 移动指标分类
- func MoveBaseFromSmmIndex(chartInfoId, classifyId int) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` UPDATE base_from_smm_index
- SET
- classify_id = ?, modify_time=NOW()
- WHERE base_from_smm_index_id = ?`
- _, err = o.Raw(sql, classifyId, chartInfoId).Exec()
- return
- }
- // UpdateBaseFromSmmIndexByClassifyId 根据指标id更新排序
- func UpdateBaseFromSmmIndexByClassifyId(classifyId, nowSort, prevIndexInfoId int, updateSort string) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` update base_from_smm_index set sort = ` + updateSort + ` WHERE classify_id=? AND `
- if prevIndexInfoId > 0 {
- sql += ` ( sort > ? or (base_from_smm_index_id > ` + fmt.Sprint(prevIndexInfoId) + ` and sort = ` + fmt.Sprint(nowSort) + `))`
- }
- _, err = o.Raw(sql, classifyId, nowSort).Exec()
- return
- }
- // MoveUpSmmIndexBySort 往上移动
- func MoveUpSmmIndexBySort(classifyId, nextSort, currentSort int) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `update base_from_smm_index set sort = sort + 1 where classify_id=? and sort >= ? and sort< ?`
- _, err = o.Raw(sql, classifyId, nextSort, currentSort).Exec()
- return
- }
- // MoveDownSmmIndexBySort 往下移动
- func MoveDownSmmIndexBySort(classifyId, prevSort, currentSort int) (err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `update base_from_smm_index set sort = sort - 1 where classify_id=? and sort <= ? and sort> ? `
- _, err = o.Raw(sql, classifyId, prevSort, currentSort).Exec()
- return
- }
- // GetFirstBaseFromSmmIndexByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
- func GetFirstBaseFromSmmIndexByClassifyId(classifyId int) (item *BaseFromSmmIndex, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_smm_index WHERE classify_id=? order by sort asc,base_from_smm_index_id asc limit 1`
- err = o.Raw(sql, classifyId).QueryRow(&item)
- return
- }
- // Update 更新Smm指标基础信息
- func (item *BaseFromSmmIndex) Update(cols []string) (err error) {
- o := orm.NewOrmUsingDB("data")
- _, err = o.Update(item, cols...)
- return
- }
- // DeleteBaseFromSmmIndexById 根据指标id删除对应的指标、指标数据
- func DeleteBaseFromSmmIndexById(smmIndexId int) (err error) {
- o := orm.NewOrmUsingDB("data")
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- //删除指标
- sql := `DELETE FROM base_from_smm_index WHERE base_from_smm_index_id = ? `
- _, err = to.Raw(sql, smmIndexId).Exec()
- if err != nil {
- return
- }
- //删除指标数据
- sql = `DELETE FROM base_from_smm_data WHERE base_from_smm_index_id = ? `
- _, err = to.Raw(sql, smmIndexId).Exec()
- if err != nil {
- return
- }
- return
- }
- // EditSmmIndexInfoResp 新增指标的返回
- type EditSmmIndexInfoResp struct {
- BaseFromSmmIndexId int `description:"指标ID"`
- IndexCode string `description:"指标code"`
- }
- //type SmmSingleDataResp struct {
- // BaseFromSmmIndexId int
- // ClassifyId int
- // Interface string
- // Name string
- // IndexCode string
- // IndexName string
- // Frequency string
- // Unit string
- // ApiStartTime string
- // ApiUpdateTime string
- // StartTime string
- // FinishTime string
- // CreateTime string
- // ModifyTime string
- // Data []*SmmIndexData
- //}
|