industry_map.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxIndustryMap struct {
  7. IndustryMapId int `orm:"column(industry_map_id);pk" description:"行业图谱id"`
  8. IndustryMapName string
  9. ParentId int
  10. CreateTime time.Time
  11. }
  12. func GetCygxIndustryMapByName(industryName string) (item *CygxIndustryMap, err error) {
  13. o := orm.NewOrm()
  14. sql := ` SELECT * FROM cygx_industry_map WHERE industry_map_name=? ORDER BY parent_id ASC LIMIT 1 `
  15. err = o.Raw(sql, industryName).QueryRow(&item)
  16. return
  17. }
  18. func GetCygxIndustryMapAll() (items []*CygxIndustryMapItems, err error) {
  19. o := orm.NewOrm()
  20. sql := ` SELECT * FROM cygx_industry_map WHERE parent_id<>0`
  21. _, err = o.Raw(sql).QueryRows(&items)
  22. return
  23. }
  24. type CygxIndustryMapItems struct {
  25. IndustryMapId int `orm:"column(industry_map_id);" description:"行业图谱id"`
  26. IndustryMapName string
  27. ParentId int
  28. Level int
  29. Children []*CygxIndustryMapItems
  30. }
  31. func GetCygxIndustryMapByParentId(parentId int) (items []*CygxIndustryMapItems, err error) {
  32. o := orm.NewOrm()
  33. sql := ` SELECT * FROM cygx_industry_map WHERE parent_id=?`
  34. _, err = o.Raw(sql, parentId).QueryRows(&items)
  35. return
  36. }
  37. func GetCygxIndustryMapByLevel(level int) (items []*CygxIndustryMapItems, err error) {
  38. o := orm.NewOrm()
  39. sql := ` SELECT * FROM cygx_industry_map WHERE level=?`
  40. _, err = o.Raw(sql, level).QueryRows(&items)
  41. return
  42. }
  43. //根据名称模糊匹配获取一条数据
  44. func GetFirstCygxIndustryItemByName(industryName string) (items *CygxIndustryMapItems, err error) {
  45. o := orm.NewOrm()
  46. sql := ` SELECT * FROM cygx_industry_map WHERE industry_map_name like '%` + industryName + `%' order by industry_map_id asc`
  47. err = o.Raw(sql).QueryRow(&items)
  48. return
  49. }
  50. //根据名称模糊匹配获取一条数据
  51. func GetFirstCygxIndustryListByName(industryName string) (list []*CygxIndustryMapItems, err error) {
  52. o := orm.NewOrm()
  53. sql := ` SELECT * FROM cygx_industry_map WHERE industry_map_name like '%` + industryName + `%' order by level,industry_map_id asc`
  54. _, err = o.Raw(sql).QueryRows(&list)
  55. return
  56. }
  57. //根据名称模糊匹配获取一条数据
  58. func FixLevelData(industryMapId int, level int) (list []*CygxIndustryMapItems, err error) {
  59. o := orm.NewOrm()
  60. sql := ` UPDATE cygx_industry_map set level = ? WHERE industry_map_id = ?`
  61. _, err = o.Raw(sql, level, industryMapId).QueryRows(&list)
  62. return
  63. }
  64. //func