123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- package data_manage
- import (
- "eta/eta_api/global"
- "eta/eta_api/utils"
- "fmt"
- "strings"
- "time"
- )
- // BaseFromRadishResearchData 萝卜投研-指标数据
- type BaseFromRadishResearchData struct {
- BaseFromRadishResearchDataId int `orm:"column(base_from_radish_research_data_id);pk" gorm:"primaryKey"`
- BaseFromRadishResearchIndexId int `description:"指标ID"`
- IndexCode string `description:"指标编码"`
- DataTime time.Time `description:"数据日期"`
- Value float64 `description:"数据值"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- DataTimestamp int64 `description:"数据日期时间戳"`
- }
- func (m *BaseFromRadishResearchData) TableName() string {
- return "base_from_radish_research_data"
- }
- type BaseFromRadishResearchDataCols struct {
- PrimaryId string
- BaseFromRadishResearchIndexId string
- IndexCode string
- DataTime string
- Value string
- UniqueCode string
- CreateTime string
- ModifyTime string
- DataTimestamp string
- }
- func (m *BaseFromRadishResearchData) Cols() BaseFromRadishResearchDataCols {
- return BaseFromRadishResearchDataCols{
- PrimaryId: "base_from_radish_research_data_id",
- BaseFromRadishResearchIndexId: "base_from_radish_research_index_id",
- IndexCode: "index_code",
- DataTime: "data_time",
- Value: "value",
- UniqueCode: "unique_code",
- CreateTime: "create_time",
- ModifyTime: "modify_time",
- DataTimestamp: "data_timestamp",
- }
- }
- func (m *BaseFromRadishResearchData) Create() (err error) {
- o := global.DbMap[utils.DbNameIndex]
- err = o.Create(m).Error
- return
- }
- func (m *BaseFromRadishResearchData) CreateMulti(items []*BaseFromRadishResearchData) (err error) {
- if len(items) == 0 {
- return
- }
- o := global.DbMap[utils.DbNameIndex]
- err = o.CreateInBatches(items, utils.MultiAddNum).Error
- return
- }
- func (m *BaseFromRadishResearchData) Update(cols []string) (err error) {
- o := global.DbMap[utils.DbNameIndex]
- err = o.Select(cols).Updates(m).Error
- return
- }
- func (m *BaseFromRadishResearchData) Remove() (err error) {
- o := global.DbMap[utils.DbNameIndex]
- sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
- err = o.Exec(sql, m.BaseFromRadishResearchDataId).Error
- return
- }
- func (m *BaseFromRadishResearchData) MultiRemove(ids []int) (err error) {
- if len(ids) == 0 {
- return
- }
- o := global.DbMap[utils.DbNameIndex]
- sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.Cols().PrimaryId, utils.GetOrmInReplace(len(ids)))
- err = o.Exec(sql, ids).Error
- return
- }
- func (m *BaseFromRadishResearchData) RemoveByCondition(condition string, pars []interface{}) (err error) {
- if condition == "" {
- return
- }
- o := global.DbMap[utils.DbNameIndex]
- sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, m.TableName(), condition)
- err = o.Exec(sql, pars...).Error
- return
- }
- func (m *BaseFromRadishResearchData) GetItemById(id int) (item *BaseFromRadishResearchData, err error) {
- o := global.DbMap[utils.DbNameIndex]
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
- err = o.Raw(sql, id).First(&item).Error
- return
- }
- func (m *BaseFromRadishResearchData) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *BaseFromRadishResearchData, err error) {
- o := global.DbMap[utils.DbNameIndex]
- 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 *BaseFromRadishResearchData) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
- o := global.DbMap[utils.DbNameIndex]
- 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 *BaseFromRadishResearchData) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromRadishResearchData, err error) {
- o := global.DbMap[utils.DbNameIndex]
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- err = o.Raw(sql, pars...).Find(&items).Error
- return
- }
- func (m *BaseFromRadishResearchData) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*BaseFromRadishResearchData, err error) {
- o := global.DbMap[utils.DbNameIndex]
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
- 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, pageSize)
- err = o.Raw(sql, pars...).Find(&items).Error
- return
- }
- // BaseFromRadishResearchDataItem 萝卜投研数据信息
- type BaseFromRadishResearchDataItem struct {
- DataId int `description:"数据ID"`
- IndexId int `description:"指标ID"`
- IndexCode string `description:"指标编码"`
- DataTime string `description:"数据日期"`
- Value float64 `description:"数据值"`
- DataTimestamp int64 `description:"数据日期时间戳"`
- }
- func (m *BaseFromRadishResearchData) Format2Item() (item *BaseFromRadishResearchDataItem) {
- item = new(BaseFromRadishResearchDataItem)
- item.DataId = m.BaseFromRadishResearchDataId
- item.IndexId = m.BaseFromRadishResearchIndexId
- item.IndexCode = m.IndexCode
- item.DataTime = utils.TimeTransferString(utils.FormatDate, m.DataTime)
- item.Value = m.Value
- item.DataTimestamp = m.DataTimestamp
- return
- }
- func (m *BaseFromRadishResearchData) GetDataTimeByIndexIds(indexIds []int) (items []string, err error) {
- if len(indexIds) == 0 {
- return
- }
- o := global.DbMap[utils.DbNameIndex]
- sql := fmt.Sprintf(`SELECT DISTINCT %s FROM %s WHERE %s IN ? ORDER BY %s DESC`, m.Cols().DataTime, m.TableName(), m.Cols().BaseFromRadishResearchIndexId, m.Cols().DataTime)
- err = o.Raw(sql, indexIds).Find(&items).Error
- if err != nil {
- return
- }
- for i, v := range items {
- items[i] = utils.GormDateStrToDateStr(v)
- }
- return
- }
|