package data_manage import ( "eta/eta_hub/utils" "fmt" "github.com/beego/beego/v2/client/orm" "strings" "time" ) // VarietyEdbInfo 品种指标表 type VarietyEdbInfo struct { VarietyEdbId int `orm:"column(variety_edb_id);pk"` VarietyId int `description:"品种id"` EdbName string `description:"品种指标名称"` Frequency string `description:"频度"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` LatestValue float64 `description:"最新值"` EdbInfoId int `description:"指标id"` EdbCode string `description:"品种编码"` Source int `description:"来源,1:影响周度产量;2:周度产量变动;3:影响月度产量;4:月度产量变动"` ModifyTime time.Time `description:"更新时间"` CreateTime time.Time `description:"添加时间"` } func (m *VarietyEdbInfo) GetItemsByCondition(cond string, pars []interface{}, fieldArr []string, orderRule string) (items []*VarietyEdbInfo, err error) { o := orm.NewOrmUsingDB("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 variety_edb_info WHERE 1=1 %s %s`, fields, cond, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // VarietyEdbInfoItem 品种指标信息 type VarietyEdbInfoItem struct { EdbInfoId int `description:"指标ID"` EdbName string `description:"指标名称"` EdbCode string `description:"指标编码"` VarietyId int `description:"品种ID"` StartDate string `description:"开始日期"` EndDate string `description:"结束日期"` Frequency string `description:"频度"` LatestValue float64 `description:"最新值"` CreateTime string `description:"创建时间"` UpdateTime string `description:"更新时间"` } func FormatVarietyEdbInfo2Item(origin *VarietyEdbInfo) (item *VarietyEdbInfoItem) { if origin == nil { return } item = new(VarietyEdbInfoItem) item.EdbInfoId = origin.EdbInfoId item.EdbName = origin.EdbName item.EdbCode = origin.EdbCode item.VarietyId = origin.VarietyId item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate) item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate) item.Frequency = origin.Frequency item.LatestValue = origin.LatestValue item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.UpdateTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) return }