chart_variety.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package cross_variety
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "time"
  6. )
  7. // ChartVariety
  8. // @Description: chart_variety 图表品种表
  9. type ChartVariety struct {
  10. ChartVarietyId int `orm:"column(chart_variety_id);pk" gorm:"primaryKey" `
  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. sql := `SELECT * FROM chart_variety WHERE chart_variety_id = ?`
  27. err = global.DmSQL["data"].Raw(sql, id).First(&item).Error
  28. return
  29. }
  30. // GetVarietyByName
  31. // @Description: 根据品种名称获取品种详情
  32. // @author: Roc
  33. // @datetime 2023-11-21 14:55:20
  34. // @param name string
  35. // @return item *ChartVariety
  36. // @return err error
  37. func GetVarietyByName(name string) (item *ChartVariety, err error) {
  38. sql := `SELECT * FROM chart_variety WHERE chart_variety_name = ?`
  39. err = global.DmSQL["data"].Raw(sql, name).First(&item).Error
  40. return
  41. }
  42. // AddVariety
  43. // @Description: 添加品种
  44. // @author: Roc
  45. // @datetime 2023-11-21 14:52:56
  46. // @param item *ChartVariety
  47. // @return err error
  48. func AddVariety(item *ChartVariety) (err error) {
  49. err = global.DmSQL["data"].Create(item).Error
  50. return
  51. }
  52. // Update
  53. // @Description: 更新品种
  54. // @author: Roc
  55. // @receiver item
  56. // @datetime 2023-11-21 15:15:17
  57. // @param updateColList []string
  58. // @return err error
  59. func (item *ChartVariety) Update(updateColList []string) (err error) {
  60. err = global.DmSQL["data"].Select(updateColList).Updates(item).Error
  61. return
  62. }
  63. // Delete 删除
  64. func (item *ChartVariety) Delete() (err error) {
  65. sql := ` DELETE FROM chart_variety WHERE chart_variety_id=? `
  66. err = global.DmSQL["data"].Exec(sql, item.ChartVarietyId).Error
  67. return
  68. }
  69. // GetVarietyList
  70. // @Description: 获取所有品种列表
  71. // @author: Roc
  72. // @datetime 2023-11-22 10:44:35
  73. // @return items []*ChartVariety
  74. // @return err error
  75. func GetVarietyList() (items []*ChartVariety, err error) {
  76. sql := `SELECT * FROM chart_variety WHERE 1 = 1 `
  77. err = global.DmSQL["data"].Raw(sql).Find(&items).Error
  78. return
  79. }
  80. // GetVarietyListByIdList
  81. // @Description: 根据ID列表获取品种列表
  82. // @author: Roc
  83. // @datetime 2023-11-23 17:56:39
  84. // @param idList []int
  85. // @return items []*ChartVariety
  86. // @return err error
  87. func GetVarietyListByIdList(idList []int) (items []*ChartVariety, err error) {
  88. num := len(idList)
  89. if num <= 0 {
  90. return
  91. }
  92. sql := `SELECT * FROM chart_variety WHERE 1 = 1 AND chart_variety_id in (` + utils.GetOrmInReplace(num) + `)`
  93. err = global.DmSQL["data"].Raw(sql, idList).Find(&items).Error
  94. return
  95. }