company_industry.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package company
  2. import "github.com/beego/beego/v2/client/orm"
  3. type CompanyIndustry struct {
  4. IndustryId int `description:"行业id"`
  5. IndustryName string `description:"行业名称"`
  6. ParentId int `description:"父级id"`
  7. Classify string `description:"分类"`
  8. }
  9. type CompanyIndustryItem struct {
  10. IndustryId int `description:"行业id"`
  11. IndustryName string `description:"行业名称"`
  12. Classify string `description:"分类"`
  13. Children []*CompanyIndustryItemSub `json:"children"`
  14. }
  15. type CompanyIndustryItemSub struct {
  16. IndustryId int `description:"行业id"`
  17. IndustryName string `description:"行业名称"`
  18. Classify string `description:"分类"`
  19. }
  20. type CompanyIndustryResp struct {
  21. List []*CompanyIndustryItem
  22. }
  23. func GetCompanyIndustry(productName string) (items []*CompanyIndustryItem, err error) {
  24. o := orm.NewOrm()
  25. sql := `SELECT * FROM company_industry WHERE product_name=? AND parent_id=0 ORDER BY industry_id ASC`
  26. _, err = o.Raw(sql, productName).QueryRows(&items)
  27. return
  28. }
  29. func GetCompanyIndustryChildren(classify string, parentId int) (items []*CompanyIndustryItemSub, err error) {
  30. o := orm.NewOrm()
  31. sql := `SELECT * FROM company_industry WHERE product_name=? AND parent_id=? ORDER BY industry_id ASC`
  32. _, err = o.Raw(sql, classify, parentId).QueryRows(&items)
  33. return
  34. }
  35. func GetCompanyIndustryById(industryId int) (items *CompanyIndustry, err error) {
  36. o := orm.NewOrm()
  37. sql := `SELECT * FROM company_industry WHERE industry_id=? `
  38. err = o.Raw(sql, industryId).QueryRow(&items)
  39. return
  40. }