variety_edb_info.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package data_manage
  2. import (
  3. "eta/eta_hub/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "strings"
  7. "time"
  8. )
  9. // VarietyEdbInfo 品种指标表
  10. type VarietyEdbInfo struct {
  11. VarietyEdbId int `orm:"column(variety_edb_id);pk"`
  12. VarietyId int `description:"品种id"`
  13. EdbName string `description:"品种指标名称"`
  14. Frequency string `description:"频度"`
  15. StartDate time.Time `description:"开始日期"`
  16. EndDate time.Time `description:"结束日期"`
  17. LatestValue float64 `description:"最新值"`
  18. EdbInfoId int `description:"指标id"`
  19. EdbCode string `description:"品种编码"`
  20. Source int `description:"来源,1:影响周度产量;2:周度产量变动;3:影响月度产量;4:月度产量变动"`
  21. ModifyTime time.Time `description:"更新时间"`
  22. CreateTime time.Time `description:"添加时间"`
  23. }
  24. func (m *VarietyEdbInfo) GetItemsByCondition(cond string, pars []interface{}, fieldArr []string, orderRule string) (items []*VarietyEdbInfo, err error) {
  25. o := orm.NewOrmUsingDB("data")
  26. fields := strings.Join(fieldArr, ",")
  27. if len(fieldArr) == 0 {
  28. fields = `*`
  29. }
  30. order := `ORDER BY create_time DESC`
  31. if orderRule != "" {
  32. order = ` ORDER BY ` + orderRule
  33. }
  34. sql := fmt.Sprintf(`SELECT %s FROM variety_edb_info WHERE 1=1 %s %s`, fields, cond, order)
  35. _, err = o.Raw(sql, pars).QueryRows(&items)
  36. return
  37. }
  38. // VarietyEdbInfoItem 品种指标信息
  39. type VarietyEdbInfoItem struct {
  40. EdbInfoId int `description:"指标ID"`
  41. EdbName string `description:"指标名称"`
  42. EdbCode string `description:"指标编码"`
  43. VarietyId int `description:"品种ID"`
  44. StartDate string `description:"开始日期"`
  45. EndDate string `description:"结束日期"`
  46. Frequency string `description:"频度"`
  47. LatestValue float64 `description:"最新值"`
  48. CreateTime string `description:"创建时间"`
  49. UpdateTime string `description:"更新时间"`
  50. }
  51. func FormatVarietyEdbInfo2Item(origin *VarietyEdbInfo) (item *VarietyEdbInfoItem) {
  52. if origin == nil {
  53. return
  54. }
  55. item = new(VarietyEdbInfoItem)
  56. item.EdbInfoId = origin.EdbInfoId
  57. item.EdbName = origin.EdbName
  58. item.EdbCode = origin.EdbCode
  59. item.VarietyId = origin.VarietyId
  60. item.StartDate = utils.TimeTransferString(utils.FormatDate, origin.StartDate)
  61. item.EndDate = utils.TimeTransferString(utils.FormatDate, origin.EndDate)
  62. item.Frequency = origin.Frequency
  63. item.LatestValue = origin.LatestValue
  64. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  65. item.UpdateTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  66. return
  67. }