123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- package data_manage
- import (
- "eta/eta_api/utils"
- "time"
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- type BaseFromGprRiskIndex struct {
- BaseFromGprRiskIndexId int `orm:"column(base_from_gpr_risk_index_id);pk"`
- ClassifyId int
- IndexCode string
- IndexName string
- Frequency string
- Unit string
- Sort int
- StartDate string `description:"开始日期"`
- EndDate string `description:"结束日期"`
- EndValue float64
- CreateTime time.Time
- ModifyTime time.Time
- }
- type BaseFromGprRiskIndexList struct {
- BaseFromGprRiskIndexId int `orm:"column(base_from_gpr_risk_index_id);pk"`
- ClassifyId int
- Interface string
- EdbInfoId int
- EdbUniqueCode string `description:"指标库唯一编码"`
- EdbClassifyId int `description:"指标库分类ID"`
- StartDate string
- EndDate string
- EndValue float64
- IndexCode string
- IndexName string
- Frequency string
- Unit string
- Sort int
- CreateTime string
- ModifyTime string
- EdbExist int `description:"指标库是否已添加:0-否;1-是"`
- DataList []*BaseFromGprRiskData
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type BaseFromGprRiskIndexSearchList struct {
- List []*BaseFromGprRiskIndexList
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type GprRiskSingleDataResp struct {
- BaseFromGprRiskIndexId int
- ClassifyId int
- EdbInfoId int
- IndexCode string
- IndexName string
- Frequency string
- Unit string
- StartTime string
- CreateTime string
- ModifyTime string
- EdbExist int `description:"指标库是否已添加:0-否;1-是"`
- Data []*GprRiskSingleData
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type GprRiskSingleData struct {
- Value string `orm:"column(value)" description:"日期"`
- DataTime string `orm:"column(data_time)" description:"值"`
- }
- func GetGprRiskIndexByClassifyId(classifyId int) (items []*BaseFromGprRiskIndex, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT base_from_gpr_risk_index_id, classify_id, index_code, index_name FROM base_from_gpr_risk_index WHERE classify_id=? ORDER BY sort ASC, base_from_gpr_risk_index_id ASC `
- _, err = o.Raw(sql, classifyId).QueryRows(&items)
- return
- }
- func GetGprRiskIndex(condition string, pars interface{}) (items []*BaseFromGprRiskIndexList, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_gpr_risk_index WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY sort ASC, base_from_gpr_risk_index_id asc`
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- func GetGprRiskIndexPage(condition string, pars interface{}, startSize, pageSize int) (items []*BaseFromGprRiskIndexList, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_gpr_risk_index WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY sort ASC, base_from_gpr_risk_index_id asc LIMIT ?,?`
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- func GetGprRiskIndexPageCount(condition string, pars interface{}) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT COUNT(1) AS count FROM base_from_gpr_risk_index WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- func GetGprRiskIndexDataCount(indexCode string) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT COUNT(1) AS count FROM base_from_gpr_risk_data WHERE index_code=? `
- err = o.Raw(sql, indexCode).QueryRow(&count)
- return
- }
- func GetGprRiskIndexDataByDataTime(indexCodes []string, startDate, endDate string) (items []*BaseFromGprRiskData, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_gpr_risk_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 GetGprRiskIndexDataTimePageByCodes(indexCodes []string, startSize, pageSize int) (dataTimes []string, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT data_time FROM base_from_gpr_risk_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 GetGprRiskIndexDataTimePageCount(indexCodes []string) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT COUNT(DISTINCT data_time) AS count FROM base_from_gpr_risk_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `) `
- err = o.Raw(sql, indexCodes).QueryRow(&count)
- return
- }
- func GetGprRiskIndexDataByCodes(indexCode []string) (items []*BaseFromGprRiskData, err error) {
- if len(indexCode) == 0 {
- return
- }
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_gpr_risk_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCode)) + `) ORDER BY data_time DESC `
- _, err = o.Raw(sql, indexCode).QueryRows(&items)
- return
- }
- // GetGprRiskByConditionAndFrequency 根据条件获取涌益咨询指标列表
- func GetGprRiskByConditionAndFrequency(condition, frequency string, pars []interface{}) (items []*BaseFromGprRiskIndex, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_gpr_risk_index WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += ` AND frequency=?`
- sql += ` ORDER BY sort ASC, base_from_gpr_risk_index_id ASC`
- _, err = o.Raw(sql, pars, frequency).QueryRows(&items)
- return
- }
- func GetGprRiskFrequencyByCondition(condition string, pars []interface{}) (items []string, err error) {
- sql := `SELECT DISTINCT frequency FROM base_from_gpr_risk_index WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY FIELD(frequency,'日度','周度','旬度','月度','季度','半年度','年度') `
- o := orm.NewOrmUsingDB("data")
- _, err = o.Raw(sql, pars...).QueryRows(&items)
- return
- }
- // GetGprRiskDataDataTimeByIndexId 根据指标id获取指标数据的日期列表
- func GetGprRiskDataDataTimeByIndexId(indexIdList []int) (items []string, err error) {
- if len(indexIdList) == 0 {
- return
- }
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT DISTINCT data_time FROM base_from_gpr_risk_data WHERE base_from_gpr_risk_index_id IN (` + utils.GetOrmInReplace(len(indexIdList)) + `) ORDER BY data_time DESC`
- _, err = o.Raw(sql, indexIdList).QueryRows(&items)
- return
- }
- type BaseFromGprRiskData struct {
- BaseFromGprRiskDataId int `orm:"column(base_from_gpr_risk_data_id);pk"`
- BaseFromGprRiskIndexId int
- IndexCode string
- DataTime string
- Value string
- CreateTime string
- ModifyTime string
- DataTimestamp int64
- }
- type BaseFromGprRiskIndexSearchItem struct {
- BaseFromGprRiskIndexId int `orm:"column(base_from_gpr_risk_index_id);pk"`
- ClassifyId int
- ParentClassifyId int
- IndexCode string
- IndexName string
- }
- // BatchCheckGprRiskEdbReq 指标数据结构体
- type BatchCheckGprRiskEdbReq 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时, 该数组为不选的指标"`
- }
- // GetGprRiskItemList 模糊查询GprRisk数据库指标列表
- func GetGprRiskItemList(condition string) (items []*BaseFromGprRiskIndexSearchItem, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := "SELECT * FROM base_from_gpr_risk_index WHERE 1=1"
- if condition != "" {
- sql += condition
- }
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- func GetGprRiskIndexDataByCode(indexCode string, pageIndex, pageSize int) (list []*BaseFromGprRiskData, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM base_from_gpr_risk_data WHERE index_code=? order by data_time desc limit ?,?`
- _, err = o.Raw(sql, indexCode, pageIndex, pageSize).QueryRows(&list)
- return
- }
- func GetGprRiskIndexDataTotalByCode(indexCode string) (total int64, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT count(*) FROM base_from_gpr_risk_data WHERE index_code=?`
- err = o.Raw(sql, indexCode).QueryRow(&total)
- return
- }
- func GetBaseFromGprRiskIndexByIndexCode(indexCode string) (list *BaseFromGprRiskIndex, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_gpr_risk_index WHERE index_code=? `
- err = o.Raw(sql, indexCode).QueryRow(&list)
- return
- }
- type BaseFromGprRiskIndexType struct {
- Type2 string `orm:"column(type_2)"`
- Type3 string `orm:"column(type_3)"`
- }
- // Update 更新GprRisk指标基础信息
- func (item *BaseFromGprRiskIndex) Update(cols []string) (err error) {
- o := orm.NewOrmUsingDB("data")
- _, err = o.Update(item, cols...)
- return
- }
- // EditGprRiskIndexInfoResp 新增指标的返回
- type EditGprRiskIndexInfoResp struct {
- BaseFromGprRiskIndexId int `description:"指标ID"`
- IndexCode string `description:"指标code"`
- }
- type GprRiskIndexSource2EdbReq struct {
- EdbCode string
- EdbName string
- Frequency string
- Unit string
- ClassifyId int
- AdminId int
- AdminRealName string
- }
- func GetGprRiskFrequencyByClassifyId(classifyId int) (items []*GlFrequency, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT frequency FROM base_from_gpr_risk_index WHERE classify_id = ? `
- sql += ` GROUP BY frequency ORDER BY frequency ASC `
- _, err = o.Raw(sql, classifyId).QueryRows(&items)
- return
- }
|