123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- package data_manage
- import (
- "eta_gn/eta_api/global"
- "eta_gn/eta_api/utils"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- type SmmClassify struct {
- TypeName string `orm:"column(type_name)" description:"分类名称"`
- TypeCode string `orm:"column(type_code)" description:"分类名称编码"`
- }
- type SmmFrequency struct {
- Frequency string `description:"频度"`
- }
- func GetSmmFrequencyByClassifyId(classifyId int) (items []*GlFrequency, err error) {
- sql := ` SELECT frequency FROM base_from_smm_index WHERE classify_id = ? `
- sql += ` GROUP BY frequency ORDER BY frequency ASC `
- err = global.DmSQL["data"].Raw(sql, classifyId).Find(&items).Error
- return
- }
- type SmmIndex struct {
- BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk" gorm:"primaryKey" `
- 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
- CreateTime string
- ModifyTime string
- IsStop int `description:"是否停更:1:停更,0:未停更"`
- EndValue float64 `description:"指标的最新值"`
- }
- type SmmIndexItem struct {
- BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk" gorm:"primaryKey" `
- ClassifyId int
- ParentClassifyId 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
- CreateTime string
- ModifyTime string
- IsStop int `description:"是否停更:1:停更,0:未停更"`
- EndValue float64 `description:"指标的最新值"`
- }
- func GetSmmIndex(condition string, pars []interface{}) (items []*SmmIndex, err error) {
- sql := ` SELECT * FROM base_from_smm_index WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += `ORDER BY sort ASC, base_from_smm_index_id asc`
- err = global.DmSQL["data"].Raw(sql, pars...).Find(&items).Error
- return
- }
- // GetSmmIndexById
- // @Description: 根据id获取指标信息
- // @author: Roc
- // @datetime 2024-01-10 14:25:26
- // @param basFromSmmIndexId int
- // @return item *SmmIndex
- // @return err error
- func GetSmmIndexById(basFromSmmIndexId int) (item *SmmIndex, err error) {
- sql := ` SELECT * FROM base_from_smm_index WHERE base_from_smm_index_id = ? `
- err = global.DmSQL["data"].Raw(sql, basFromSmmIndexId).First(&item).Error
- return
- }
- type SmmExportIndex struct {
- TypeName 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
- ModifyTime string
- }
- func GetSmmFrequency(classifyId int) (items []*string, err error) {
- sql := `SELECT DISTINCT frequency FROM base_from_smm_index WHERE classify_id=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
- err = global.DmSQL["data"].Raw(sql, classifyId).Find(&items).Error
- return
- }
- func GetSmmFrequencyByCode(code string) (items []*string, err error) {
- sql := `SELECT DISTINCT frequency FROM base_from_smm_index WHERE index_code=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
- err = global.DmSQL["data"].Raw(sql, code).Find(&items).Error
- return
- }
- type SmmIndexList struct {
- BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk" gorm:"primaryKey" `
- 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
- ModifyTime string
- DataList []*SmmIndexData
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type SmmIndexData struct {
- Value string `orm:"column(value)" description:"日期"`
- DataTime string `orm:"column(data_time)" description:"值"`
- }
- func GetSmmIndexData(indexCode string, startSize, pageSize int) (items []*SmmIndexData, err error) {
- sql := ` SELECT * FROM base_from_smm_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
- err = global.DmSQL["data"].Raw(sql, indexCode, startSize, pageSize).Find(&items).Error
- return
- }
- func GetSmmIndexDataCount(indexCode string) (count int, err error) {
- sql := ` SELECT COUNT(1) AS count FROM base_from_smm_data WHERE index_code=? `
- err = global.DmSQL["data"].Raw(sql, indexCode).Scan(&count).Error
- return
- }
- // GetSmmItemList 模糊查询Smm数据库指标列表
- func GetSmmItemList(keyword string) (items []*SmmIndexItem, err error) {
- sql := "SELECT * FROM base_from_smm_index WHERE CONCAT(index_name,index_code) LIKE ? "
- err = global.DmSQL["data"].Raw(sql, utils.GetLikeKeyword(keyword)).Find(&items).Error
- return
- }
- func GetSmmIndexDataByCode(indexCode string) (items []*SmmIndexData, err error) {
- sql := ` SELECT * FROM base_from_smm_data WHERE index_code=? ORDER BY data_time DESC `
- err = global.DmSQL["data"].Raw(sql, indexCode).Find(&items).Error
- return
- }
- func GetSmmDataMaxCount(classifyId int) (count int, err error) {
- sql := `SELECT COALESCE(MAX(t.num), 0) AS count FROM (
- SELECT COUNT(1) AS num FROM base_from_smm_index AS a
- INNER JOIN base_from_smm_data AS b ON a.index_code=b.index_code
- WHERE a.classify_id=?
- GROUP BY a.base_from_smm_index_id
- )AS t `
- err = global.DmSQL["data"].Raw(sql, classifyId).Scan(&count).Error
- return
- }
- type ExportSmmDataMaxCount struct {
- TypeName string
- Count int
- }
- type ExportSmmIndexData struct {
- Value string `orm:"column(value)" description:"日期"`
- DataTime string `orm:"column(data_time)" description:"值"`
- IndexCode string `orm:"column(index_code)" description:"指标编码"`
- }
- // GetSmmBaseInfoList
- // @Description: 获取有色数据列表
- // @author: Roc
- // @datetime 2024-01-10 14:28:29
- // @param condition string
- // @param pars []interface{}
- // @param orderBy string
- // @param startSize int
- // @param pageSize int
- // @return total int
- // @return items []*BaseRefreshEdbInfo
- // @return err error
- func GetSmmBaseInfoList(condition string, pars []interface{}, orderBy string, startSize, pageSize int) (total int, items []*BaseRefreshEdbInfo, err error) {
- // 数量汇总
- totalSql := ` SELECT count(1) FROM base_from_smm_index WHERE 1=1 `
- if condition != "" {
- totalSql += condition
- }
- err = global.DmSQL["data"].Raw(totalSql, pars...).Scan(&total).Error
- if err != nil {
- return
- }
- // 列表数据
- sql := ` SELECT base_from_smm_index_id as edb_info_id, classify_id,index_code,index_name,end_date,end_value,frequency,is_stop,terminal_code FROM base_from_smm_index WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- if orderBy != "" {
- sql += ` ORDER BY ` + orderBy
- } else {
- sql += ` ORDER BY base_from_smm_index_id ASC `
- }
- sql += ` LIMIT ?,? `
- pars = append(pars, startSize)
- pars = append(pars, pageSize)
- err = global.DmSQL["data"].Raw(sql, pars...).Find(&items).Error
- return
- }
- // ModifySmmUpdateStatus
- // @Description: 修改有色数据停更状态
- // @author: Roc
- // @datetime 2024-01-08 16:23:31
- // @param edbIdList []int
- // @param indexCodeList []string
- // @param isStop int
- // @return err error
- func ModifySmmUpdateStatus(edbIdList []int, indexCodeList []string, isStop int) (err error) {
- idNum := len(edbIdList)
- if idNum <= 0 {
- return
- }
- to := global.DmSQL["data"].Begin()
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- // 更改数据源的更新状态
- sql := ` UPDATE base_from_smm_index SET is_stop = ? WHERE base_from_smm_index_id IN (` + utils.GetOrmInReplace(idNum) + `) `
- err = to.Exec(sql, isStop, edbIdList).Error
- if err != nil {
- return
- }
- codeNum := len(indexCodeList)
- if codeNum <= 0 {
- // 需要通过指标id列表查找code列表
- sql := ` SELECT index_code FROM base_from_smm_index WHERE base_from_smm_index_id IN (` + utils.GetOrmInReplace(idNum) + `) `
- err = to.Raw(sql, edbIdList).Find(&indexCodeList).Error
- if err != nil {
- return
- }
- }
- codeNum = len(indexCodeList)
- // 查出来的编码是空的话,那么就直接返回了
- if codeNum <= 0 {
- return
- }
- // 更改指标的更新状态
- sql = ` UPDATE edb_info SET no_update = ? WHERE source = ? AND sub_source= ? AND edb_code IN (` + utils.GetOrmInReplace(codeNum) + `) `
- err = to.Exec(sql, isStop, utils.DATA_SOURCE_YS, 0, indexCodeList).Error
- if err != nil {
- return
- }
- return
- }
|