chart_variety.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package cross_variety
  2. import (
  3. "eta/eta_chart_lib/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // ChartVariety
  8. // @Description: chart_variety 图表品种表
  9. type ChartVariety struct {
  10. ChartVarietyId int `orm:"column(chart_variety_id);pk"`
  11. ChartVarietyName string `description:"品种名称"`
  12. ChartVarietyNameEn string `description:"品种名称(英文)"`
  13. SysUserId int `description:"创建人id"`
  14. SysUserRealName string `description:"创建人姓名"`
  15. ModifyTime time.Time `description:"修改时间"`
  16. CreateTime time.Time `description:"创建时间"`
  17. }
  18. // GetVarietyById
  19. // @Description: 根据品种id获取品种详情
  20. // @author: Roc
  21. // @datetime 2023-11-21 14:55:31
  22. // @param id int
  23. // @return item *ChartVariety
  24. // @return err error
  25. func GetVarietyById(id int) (item *ChartVariety, err error) {
  26. o := orm.NewOrmUsingDB("data")
  27. sql := `SELECT * FROM chart_variety WHERE chart_variety_id = ?`
  28. err = o.Raw(sql, id).QueryRow(&item)
  29. return
  30. }
  31. // GetVarietyByName
  32. // @Description: 根据品种名称获取品种详情
  33. // @author: Roc
  34. // @datetime 2023-11-21 14:55:20
  35. // @param name string
  36. // @return item *ChartVariety
  37. // @return err error
  38. func GetVarietyByName(name string) (item *ChartVariety, err error) {
  39. o := orm.NewOrmUsingDB("data")
  40. sql := `SELECT * FROM chart_variety WHERE chart_variety_name = ?`
  41. err = o.Raw(sql, name).QueryRow(&item)
  42. return
  43. }
  44. // AddVariety
  45. // @Description: 添加品种
  46. // @author: Roc
  47. // @datetime 2023-11-21 14:52:56
  48. // @param item *ChartVariety
  49. // @return err error
  50. func AddVariety(item *ChartVariety) (err error) {
  51. o := orm.NewOrmUsingDB("data")
  52. lastId, err := o.Insert(item)
  53. if err != nil {
  54. return
  55. }
  56. item.ChartVarietyId = int(lastId)
  57. return
  58. }
  59. // Update
  60. // @Description: 更新品种
  61. // @author: Roc
  62. // @receiver item
  63. // @datetime 2023-11-21 15:15:17
  64. // @param updateColList []string
  65. // @return err error
  66. func (item *ChartVariety) Update(updateColList []string) (err error) {
  67. to := orm.NewOrmUsingDB("data")
  68. _, err = to.Update(item, updateColList...)
  69. return
  70. }
  71. // Delete 删除
  72. func (item *ChartVariety) Delete() (err error) {
  73. o := orm.NewOrmUsingDB("data")
  74. _, err = o.Delete(item)
  75. return
  76. }
  77. // GetVarietyList
  78. // @Description: 获取所有品种列表
  79. // @author: Roc
  80. // @datetime 2023-11-22 10:44:35
  81. // @return items []*ChartVariety
  82. // @return err error
  83. func GetVarietyList() (items []*ChartVariety, err error) {
  84. o := orm.NewOrmUsingDB("data")
  85. sql := `SELECT * FROM chart_variety WHERE 1 = 1 `
  86. _, err = o.Raw(sql).QueryRows(&items)
  87. return
  88. }
  89. // GetVarietyListByIdList
  90. // @Description: 根据ID列表获取品种列表
  91. // @author: Roc
  92. // @datetime 2023-11-23 17:56:39
  93. // @param idList []int
  94. // @return items []*ChartVariety
  95. // @return err error
  96. func GetVarietyListByIdList(idList []int) (items []*ChartVariety, err error) {
  97. num := len(idList)
  98. if num <= 0 {
  99. return
  100. }
  101. o := orm.NewOrmUsingDB("data")
  102. sql := `SELECT * FROM chart_variety WHERE 1 = 1 AND chart_variety_id in (` + utils.GetOrmInReplace(num) + `)`
  103. _, err = o.Raw(sql, idList).QueryRows(&items)
  104. return
  105. }