123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- package data_manage
- import (
- "eta_gn/eta_api/global"
- "eta_gn/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strings"
- "time"
- )
- // BaseFromBloombergIndex 彭博原始指标表
- type BaseFromBloombergIndex struct {
- BaseFromBloombergIndexId int `orm:"column(base_from_bloomberg_index_id);pk" gorm:"primaryKey" `
- IndexCode string `description:"指标编码"`
- IndexName string `description:"指标名称"`
- Unit string `description:"单位"`
- Source int `description:"数据来源"`
- Frequency string `description:"频度"`
- StartDate time.Time `description:"开始日期"`
- EndDate time.Time `description:"结束日期"`
- Describe string `description:"指标描述"`
- Sort int `description:"排序"`
- IsStop int `description:"是否停更:0-否;1-停更"`
- EdbExist int `description:"指标库是否已添加:0-否;1-是"`
- TerminalCode string `description:"所属终端编码"`
- FilePath string `description:"文件存储路径"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- }
- var BaseFromBloombergIndexCols = struct {
- BaseFromBloombergIndexId string
- IndexCode string
- IndexName string
- Unit string
- Source string
- Frequency string
- StartDate string
- EndDate string
- Describe string
- Sort string
- IsStop string
- EdbExist string
- TerminalCode string
- FilePath string
- CreateTime string
- ModifyTime string
- }{
- BaseFromBloombergIndexId: "base_from_bloomberg_index_id",
- IndexCode: "index_code",
- IndexName: "index_name",
- Unit: "unit",
- Source: "source",
- Frequency: "frequency",
- StartDate: "start_date",
- EndDate: "end_date",
- Describe: "describe",
- Sort: "sort",
- IsStop: "is_stop",
- EdbExist: "edb_exist",
- TerminalCode: "terminal_code",
- FilePath: "file_path",
- CreateTime: "create_time",
- ModifyTime: "modify_time",
- }
- func (m *BaseFromBloombergIndex) TableName() string {
- return "base_from_bloomberg_index"
- }
- func (m *BaseFromBloombergIndex) PrimaryId() string {
- return BaseFromBloombergIndexCols.BaseFromBloombergIndexId
- }
- func (m *BaseFromBloombergIndex) Create() (err error) {
- err = global.DmSQL["data"].Create(m).Error
- return
- }
- func (m *BaseFromBloombergIndex) CreateMulti(items []*BaseFromBloombergIndex) (err error) {
- if len(items) == 0 {
- return
- }
- err = global.DmSQL["data"].CreateInBatches(items, utils.MultiAddNum).Error
- return
- }
- func (m *BaseFromBloombergIndex) Update(cols []string) (err error) {
- o := global.DmSQL["data"]
- err = o.Select(cols).Updates(m).Error
- return
- }
- func (m *BaseFromBloombergIndex) Del() (err error) {
- o := global.DmSQL["data"]
- sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
- err = o.Exec(sql, m.BaseFromBloombergIndexId).Error
- return
- }
- func (m *BaseFromBloombergIndex) MultiDel(menuIds []int) (err error) {
- if len(menuIds) == 0 {
- return
- }
- o := global.DmSQL["data"]
- sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
- err = o.Exec(sql, menuIds).Error
- return
- }
- func (m *BaseFromBloombergIndex) GetItemById(id int) (item *BaseFromBloombergIndex, err error) {
- o := global.DmSQL["data"]
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
- err = o.Raw(sql, id).First(&item).Error
- return
- }
- func (m *BaseFromBloombergIndex) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *BaseFromBloombergIndex, err error) {
- o := global.DmSQL["data"]
- order := ``
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
- err = o.Raw(sql, pars...).First(&item).Error
- return
- }
- func (m *BaseFromBloombergIndex) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
- o := global.DmSQL["data"]
- sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
- err = o.Raw(sql, pars...).Scan(&count).Error
- return
- }
- func (m *BaseFromBloombergIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, limit int) (items []*BaseFromBloombergIndex, err error) {
- o := global.DmSQL["data"]
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := `ORDER BY create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- if limit > 0 {
- sql += fmt.Sprintf(` LIMIT %d`, limit)
- }
- err = o.Raw(sql, pars...).Scan(&items).Error
- return
- }
- func (m *BaseFromBloombergIndex) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*BaseFromBloombergIndex, err error) {
- o := global.DmSQL["data"]
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := `ORDER BY create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
- pars = append(pars, startSize)
- pars = append(pars, pageSize)
- err = o.Raw(sql, pars...).Scan(&items).Error
- return
- }
- // BaseFromBloombergIndexItem 彭博原始指标信息
- type BaseFromBloombergIndexItem struct {
- BaseFromBloombergIndexId int
- IndexCode string `description:"指标编码"`
- IndexName string `description:"指标名称"`
- Unit string `description:"单位"`
- Source int `description:"数据来源"`
- Frequency string `description:"频度"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"结束日期"`
- Describe string `description:"指标描述"`
- Sort int `description:"排序"`
- IsStop int `description:"是否停更:0-否;1-停更"`
- EdbExist int `description:"指标库是否已添加:0-否;1-是"`
- CreateTime string `description:"创建时间"`
- ModifyTime string `description:"修改时间"`
- EdbInfoId int `description:"指标库ID"`
- EdbUniqueCode string `description:"指标库唯一编码"`
- EdbClassifyId int `description:"指标库分类ID"`
- }
- func FormatBaseFromBloombergIndex2Item(origin *BaseFromBloombergIndex) (item *BaseFromBloombergIndexItem) {
- if origin == nil {
- return
- }
- item = new(BaseFromBloombergIndexItem)
- item.BaseFromBloombergIndexId = origin.BaseFromBloombergIndexId
- item.IndexCode = origin.IndexCode
- item.IndexName = origin.IndexName
- item.Unit = origin.Unit
- item.Source = origin.Source
- item.Frequency = origin.Frequency
- item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
- item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
- item.Describe = origin.Describe
- item.Sort = origin.Sort
- item.IsStop = origin.IsStop
- //item.EdbExist = origin.EdbExist
- item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
- item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
- return
- }
- // BloombergSourceListReq 指标列表筛选
- type BloombergSourceListReq struct {
- PageSize int `form:"PageSize"`
- CurrentIndex int `form:"CurrentIndex"`
- Frequency string `form:"Frequency" description:"频度"`
- Keywords string `form:"Keywords" description:"指标ID/指标名称"`
- ListAll bool `form:"ListAll" description:"列表全选"`
- SortField int `form:"SortField" description:"排序字段: 0-默认; 1-开始时间; 2-最新时间; 3-更新时间"`
- SortRule int `form:"SortRule" description:"排序方式: 0-默认; 1-正序; 2-倒序"`
- }
- // BloombergSourceListResp 指标列表响应体
- type BloombergSourceListResp struct {
- List []*BaseFromBloombergIndexItem
- Paging *paging.PagingItem `description:"分页数据"`
- }
- // UpdateEdbExist 标记已添加指标库
- func (m *BaseFromBloombergIndex) UpdateEdbExist(indexCode string) (err error) {
- o := global.DmSQL["data"]
- sql := fmt.Sprintf(`UPDATE %s SET %s = ? WHERE %s = ? LIMIT 1`, m.TableName(), BaseFromBloombergIndexCols.EdbExist, BaseFromBloombergIndexCols.IndexCode)
- err = o.Exec(sql, 1, indexCode).Error
- return
- }
- // BloombergSourceBatchAddCheckReq Bloomberg批量添加校验
- type BloombergSourceBatchAddCheckReq struct {
- BloombergSourceListReq
- IndexCodes []string `form:"IndexCodes" description:"全选为false时, 该数组为选中; 全选为true时, 该数组为不选的指标"`
- }
|