123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- package data_manage
- import (
- "eta/eta_api/utils"
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "time"
- )
- type BaseFromCCFIndex struct {
- BaseFromCcfIndexId int `orm:"column(base_from_ccf_index_id);pk"`
- ClassifyId int
- IndexCode string
- IndexName string
- Frequency string
- Unit string
- Sort int
- CreateTime time.Time
- ModifyTime time.Time
- }
- type BaseFromCCFIndexList struct {
- BaseFromCcfIndexId int `orm:"column(base_from_ccf_index_id);pk"`
- EdbInfoId int
- ClassifyId int
- IndexCode string
- IndexName string
- Frequency string
- Unit string
- Sort int
- CreateTime string
- ModifyTime string
- EndDate string
- EndValue string
- EdbExist int `description:"指标库是否已添加:0-否;1-是"`
- DataList []*BaseFromCCFData
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type CCFSingleDataResp struct {
- BaseFromCcfIndexId int
- ClassifyId int
- IndexCode string
- IndexName string
- Frequency string
- Unit string
- CreateTime string
- ModifyTime string
- Data []*CCFSingleData
- }
- type CCFSingleData struct {
- Value string `orm:"column(value)" description:"日期"`
- DataTime string `orm:"column(data_time)" description:"值"`
- }
- func GetCCFIndex(condition string, pars interface{}) (items []*BaseFromCCFIndexList, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_ccf_index WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY sort ASC, base_from_ccf_index_id asc`
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- func GetCCFIndexDataCount(indexCode string) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT COUNT(1) AS count FROM base_from_ccf_data WHERE index_code=? `
- err = o.Raw(sql, indexCode).QueryRow(&count)
- return
- }
- type CCFIndexDataCountGroup struct {
- IndexCode string
- Count int
- }
- func GetCCFIndexDataCountGroup(indexCodes []string) (items []*CCFIndexDataCountGroup, err error) {
- if len(indexCodes) <= 0 {
- return
- }
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT COUNT(1) AS count, index_code FROM base_from_ccf_data WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodes)) + `) GROUP BY index_code`
- _, err = o.Raw(sql, indexCodes).QueryRows(&items)
- return
- }
- func GetCCFIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromCCFData, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_ccf_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
- return
- }
- func GetCCFIndexDataByCodes(indexCode []string) (items []*BaseFromCCFData, err error) {
- if len(indexCode) <= 0 {
- return
- }
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_ccf_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCode)) + `) ORDER BY data_time DESC `
- _, err = o.Raw(sql, indexCode).QueryRows(&items)
- return
- }
- type BaseFromCCFData struct {
- BaseFromCcfDataId int `orm:"column(base_from_ccf_data_id);pk"`
- BaseFromCcfIndexId int
- IndexCode string
- DataTime string
- Value string
- CreateTime string
- ModifyTime string
- DataTimestamp int64
- }
- type BaseFromCCFIndexSearchItem struct {
- BaseFromCcfIndexId int `orm:"column(base_from_ccf_index_id);pk"`
- ClassifyId int
- IndexCode string
- IndexName string
- }
- // GetCCFItemList 模糊查询CCF数据库指标列表
- func GetCCFItemList(condition string) (items []*BaseFromCCFIndexSearchItem, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := "SELECT * FROM base_from_ccf_index WHERE 1=1"
- if condition != "" {
- sql += condition
- }
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- func GetCCFIndexDataByCode(indexCode string) (list []*BaseFromCCFData, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM base_from_ccf_data WHERE index_code=? `
- _, err = o.Raw(sql, indexCode).QueryRows(&list)
- return
- }
- func GetBaseFromCCFIndexByIndexCode(indexCode string) (list *BaseFromCCFIndex, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_ccf_index WHERE index_code=? `
- err = o.Raw(sql, indexCode).QueryRow(&list)
- return
- }
- func GetCCFIndexPage(condition string, pars interface{}, startSize, pageSize int) (items []*BaseFromCCFIndexList, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_ccf_index WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY sort ASC, base_from_ccf_index_id asc LIMIT ?,?`
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- func GetCCFIndexPageCount(condition string, pars interface{}) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT COUNT(1) AS count FROM base_from_ccf_index WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- type BaseFromCCFIndexSearchList struct {
- List []*BaseFromCCFIndexList
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type CCFIndexSource2EdbReq struct {
- EdbCode string
- EdbName string
- Frequency string
- Unit string
- ClassifyId int
- AdminId int
- AdminRealName string
- }
- // BatchCheckCCFEdbReq 指标数据结构体
- type BatchCheckCCFEdbReq struct {
- //IsJoinEdb int `form:"IsJoinEdb" description:"是否加到指标库,0:未加到指标库"`
- Frequencies string `description:"频度;枚举值:日度、周度、月度、季度、半年度、年度"`
- Keyword string `description:"关键字"`
- ClassifyIds string `description:"所选品种id列表"`
- ListAll bool `form:"ListAll" json:"ListAll" description:"列表全选"`
- TradeCodeList string `form:"TradeCodeList" json:"TradeCodeList" description:"全选为false时, 该数组为选中; 全选为true时, 该数组为不选的指标"`
- }
- func GetCCFFrequencyByClassifyId(classifyId int) (items []*GlFrequency, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT frequency FROM base_from_ccf_index WHERE classify_id = ? `
- sql += ` GROUP BY frequency ORDER BY frequency ASC `
- _, err = o.Raw(sql, classifyId).QueryRows(&items)
- return
- }
- func GetCCFIndexDataByDataTime(indexCodes []string, startDate, endDate string) (items []*BaseFromCCFData, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_ccf_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `) and data_time >=? and data_time <? ORDER BY data_time DESC `
- _, err = o.Raw(sql, indexCodes, startDate, endDate).QueryRows(&items)
- return
- }
- func GetCCFIndexDataTimePageByCodes(indexCodes []string, startSize, pageSize int) (dataTimes []string, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT data_time FROM base_from_ccf_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `) GROUP BY data_time ORDER BY data_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, indexCodes, startSize, pageSize).QueryRows(&dataTimes)
- return
- }
- func GetCCFIndexDataTimePageCount(indexCodes []string) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT COUNT(DISTINCT data_time) AS count FROM base_from_ccf_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `)`
- err = o.Raw(sql, indexCodes).QueryRow(&count)
- return
- }
- // GetCCFDataDataTimeByIndexId 根据指标id获取指标数据的日期列表
- func GetCCFDataDataTimeByIndexId(indexIdList []int) (items []string, err error) {
- if len(indexIdList) == 0 {
- return
- }
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT DISTINCT data_time FROM base_from_ccf_data WHERE base_from_ccf_index_id IN (` + utils.GetOrmInReplace(len(indexIdList)) + `) ORDER BY data_time DESC`
- _, err = o.Raw(sql, indexIdList).QueryRows(&items)
- return
- }
- func GetCCFIndexDataByIndexIdAndDataTime(indexId []int, dataTimeList []string) (items []*BaseFromCCFData, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_ccf_data WHERE base_from_ccf_index_id in (` + utils.GetOrmInReplace(len(indexId)) + `) and data_time in (` + utils.GetOrmInReplace(len(dataTimeList)) + `) `
- _, err = o.Raw(sql, indexId, dataTimeList).QueryRows(&items)
- return
- }
|