base_from_national_statistics_data.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strings"
  6. "time"
  7. )
  8. // BaseFromNationalStatisticsData 国统局-指标
  9. type BaseFromNationalStatisticsData struct {
  10. BaseFromNationalStatisticsDataId int `orm:"column(base_from_national_statistics_data_id);pk"`
  11. BaseFromNationalStatisticsIndexId int `description:"指标ID"`
  12. IndexCode string `description:"指标编码"`
  13. DataTime time.Time `description:"数据日期"`
  14. Value float64 `description:"数据值"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"更新时间"`
  17. }
  18. func (m *BaseFromNationalStatisticsData) TableName() string {
  19. return "base_from_national_statistics_data"
  20. }
  21. func (m *BaseFromNationalStatisticsData) Create() (err error) {
  22. o := orm.NewOrmUsingDB("data")
  23. id, err := o.Insert(m)
  24. if err != nil {
  25. return
  26. }
  27. m.BaseFromNationalStatisticsDataId = int(id)
  28. return
  29. }
  30. func (m *BaseFromNationalStatisticsData) CreateMulti(items []*BaseFromNationalStatisticsData) (err error) {
  31. if len(items) == 0 {
  32. return
  33. }
  34. o := orm.NewOrmUsingDB("data")
  35. _, err = o.InsertMulti(len(items), items)
  36. return
  37. }
  38. func (m *BaseFromNationalStatisticsData) Update(cols []string) (err error) {
  39. o := orm.NewOrmUsingDB("data")
  40. _, err = o.Update(m, cols...)
  41. return
  42. }
  43. func (m *BaseFromNationalStatisticsData) Del() (err error) {
  44. o := orm.NewOrmUsingDB("data")
  45. sql := `DELETE FROM base_from_national_statistics_data WHERE base_from_national_statistics_data_id = ? LIMIT 1`
  46. _, err = o.Raw(sql, m.BaseFromNationalStatisticsDataId).Exec()
  47. return
  48. }
  49. func (m *BaseFromNationalStatisticsData) GetItemById(id int) (err error) {
  50. o := orm.NewOrmUsingDB("data")
  51. sql := `SELECT * FROM base_from_national_statistics_data WHERE base_from_national_statistics_data_id = ? LIMIT 1`
  52. err = o.Raw(sql, id).QueryRow(&m)
  53. return
  54. }
  55. func (m *BaseFromNationalStatisticsData) GetItemByCondition(condition string, pars []interface{}) (err error) {
  56. o := orm.NewOrmUsingDB("data")
  57. sql := `SELECT * FROM base_from_national_statistics_data WHERE 1=1 `
  58. sql += condition
  59. sql += ` LIMIT 1`
  60. err = o.Raw(sql, pars).QueryRow(&m)
  61. return
  62. }
  63. func (m *BaseFromNationalStatisticsData) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  64. o := orm.NewOrmUsingDB("data")
  65. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  66. err = o.Raw(sql, pars).QueryRow(&count)
  67. return
  68. }
  69. func (m *BaseFromNationalStatisticsData) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromNationalStatisticsData, err error) {
  70. o := orm.NewOrmUsingDB("data")
  71. fields := strings.Join(fieldArr, ",")
  72. if len(fieldArr) == 0 {
  73. fields = `*`
  74. }
  75. order := `ORDER BY create_time DESC`
  76. if orderRule != "" {
  77. order = ` ORDER BY ` + orderRule
  78. }
  79. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  80. _, err = o.Raw(sql, pars).QueryRows(&items)
  81. return
  82. }