chart_variety_mapping.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package cross_variety
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // ChartVarietyMapping
  7. // @Description: 图表与品种的关系表
  8. type ChartVarietyMapping struct {
  9. Id int `orm:"column(id);pk"`
  10. ChartInfoId int `description:"图表id"`
  11. ChartVarietyId int `description:"品种id"`
  12. ModifyTime time.Time `description:"修改时间"`
  13. CreateTime time.Time `description:"创建时间"`
  14. }
  15. // GetChartVarietyMappingList
  16. // @Description: 获取图表与品种的关系列表表
  17. // @author: Roc
  18. // @datetime 2023-11-24 15:22:36
  19. // @param chartInfoId int
  20. // @return items []*ChartVarietyMapping
  21. // @return err error
  22. func GetChartVarietyMappingList(chartInfoId int) (items []*ChartVarietyMapping, err error) {
  23. o := orm.NewOrmUsingDB("data")
  24. sql := `SELECT * FROM chart_variety_mapping WHERE chart_info_id = ? `
  25. _, err = o.Raw(sql, chartInfoId).QueryRows(&items)
  26. return
  27. }
  28. // GetCountChartByVarietyId
  29. // @Description: 根据品种id获取引用该标签的图表数量
  30. // @author: Roc
  31. // @datetime 2023-11-27 10:41:46
  32. // @param tagId int
  33. // @return total int64
  34. // @return err error
  35. func GetCountChartByVarietyId(varietyId int) (total int64, err error) {
  36. o := orm.NewOrmUsingDB("data")
  37. sql := `SELECT count(1) total FROM chart_info AS a JOIN
  38. chart_variety_mapping AS b on a.chart_info_id = b.chart_info_id
  39. WHERE b.chart_variety_id = ? `
  40. err = o.Raw(sql, varietyId).QueryRow(&total)
  41. return
  42. }