chart_variety_mapping.go 2.1 KB

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