base_from_national_statistics_classify.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package data_manage
  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. }
  85. type BaseFromNationalStatisticsClassifyItem struct {
  86. ClassifyId int `description:"分类ID"`
  87. ClassifyName string `description:"分类名称"`
  88. ParentId int `description:"父级分类ID"`
  89. ParentIds []int `description:"父级分类ID集合-用于前端的定位"`
  90. Dbcode string `description:"数据库编码"`
  91. IsParent int `description:"是否存在子分类: 0-否; 1-是"`
  92. Children []*BaseFromNationalStatisticsClassifyItem `description:"子分类"`
  93. }