base_from_national_statistics_classify.go 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strings"
  6. "time"
  7. )
  8. // BaseFromNationalStatisticsClassify 国统局-指标分类
  9. type BaseFromNationalStatisticsClassify struct {
  10. BaseFromNationalStatisticsClassifyId int `orm:"column(base_from_national_statistics_classify_id);pk"`
  11. ClassifyName string `description:"分类名称"`
  12. Id string `description:"分类ID(字符串)"`
  13. Dbcode string `description:"dbcode"`
  14. Wdcode string `description:"wdcode"`
  15. Pid string `description:"父级分类ID"`
  16. IsParent int `description:"是否存在子分类: 0-否; 1-是"`
  17. CreateTime time.Time `description:"创建时间"`
  18. ModifyTime time.Time `description:"更新时间"`
  19. }
  20. func (m *BaseFromNationalStatisticsClassify) TableName() string {
  21. return "base_from_national_statistics_classify"
  22. }
  23. func (m *BaseFromNationalStatisticsClassify) Create() (err error) {
  24. o := orm.NewOrmUsingDB("data")
  25. id, err := o.Insert(m)
  26. if err != nil {
  27. return
  28. }
  29. m.BaseFromNationalStatisticsClassifyId = int(id)
  30. return
  31. }
  32. func (m *BaseFromNationalStatisticsClassify) CreateMulti(items []*BaseFromNationalStatisticsClassify) (err error) {
  33. if len(items) == 0 {
  34. return
  35. }
  36. o := orm.NewOrmUsingDB("data")
  37. _, err = o.InsertMulti(len(items), items)
  38. return
  39. }
  40. func (m *BaseFromNationalStatisticsClassify) Update(cols []string) (err error) {
  41. o := orm.NewOrmUsingDB("data")
  42. _, err = o.Update(m, cols...)
  43. return
  44. }
  45. func (m *BaseFromNationalStatisticsClassify) Del() (err error) {
  46. o := orm.NewOrmUsingDB("data")
  47. sql := `DELETE FROM base_from_national_statistics_classify WHERE base_from_national_statistics_classify_id = ? LIMIT 1`
  48. _, err = o.Raw(sql, m.BaseFromNationalStatisticsClassifyId).Exec()
  49. return
  50. }
  51. func (m *BaseFromNationalStatisticsClassify) GetItemById(id int) (err error) {
  52. o := orm.NewOrmUsingDB("data")
  53. sql := `SELECT * FROM base_from_national_statistics_classify WHERE base_from_national_statistics_classify_id = ? LIMIT 1`
  54. err = o.Raw(sql, id).QueryRow(&m)
  55. return
  56. }
  57. func (m *BaseFromNationalStatisticsClassify) GetItemByCondition(condition string, pars []interface{}) (err error) {
  58. o := orm.NewOrmUsingDB("data")
  59. sql := `SELECT * FROM base_from_national_statistics_classify WHERE 1=1 `
  60. sql += condition
  61. sql += ` LIMIT 1`
  62. err = o.Raw(sql, pars).QueryRow(&m)
  63. return
  64. }
  65. func (m *BaseFromNationalStatisticsClassify) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  66. o := orm.NewOrmUsingDB("data")
  67. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  68. err = o.Raw(sql, pars).QueryRow(&count)
  69. return
  70. }
  71. func (m *BaseFromNationalStatisticsClassify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromNationalStatisticsClassify, err error) {
  72. o := orm.NewOrmUsingDB("data")
  73. fields := strings.Join(fieldArr, ",")
  74. if len(fieldArr) == 0 {
  75. fields = `*`
  76. }
  77. order := `ORDER BY create_time DESC`
  78. if orderRule != "" {
  79. order = ` ORDER BY ` + orderRule
  80. }
  81. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  82. _, err = o.Raw(sql, pars).QueryRows(&items)
  83. return
  84. }