industry_map.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package cygx
  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. Level int `description:"层级深度"`
  11. CreateTime time.Time
  12. ModifyTime time.Time
  13. }
  14. type CygxIndustryMapItems struct {
  15. IndustryMapId int `orm:"column(industry_map_id);" description:"行业图谱id"`
  16. IndustryMapName string
  17. ParentId int
  18. Level int `description:"层级深度"`
  19. Children []*CygxIndustryMapItems
  20. }
  21. func GetCygxIndustryMapByParentId(parentId int) (items []*CygxIndustryMapItems, err error) {
  22. o := orm.NewOrmUsingDB("hz_cygx")
  23. sql := ` SELECT * FROM cygx_industry_map WHERE parent_id=?`
  24. _, err = o.Raw(sql, parentId).QueryRows(&items)
  25. return
  26. }
  27. func GetCygxIndustryMapAll() (items []*CygxIndustryMapItems, err error) {
  28. o := orm.NewOrmUsingDB("hz_cygx")
  29. sql := ` SELECT * FROM cygx_industry_map WHERE parent_id<>0`
  30. _, err = o.Raw(sql).QueryRows(&items)
  31. return
  32. }
  33. type CygxIndustryMapResp struct {
  34. Node *CygxIndustryMapItems
  35. }
  36. // 新增图谱
  37. type IndustryMapAddReq struct {
  38. IndustryMapId int `orm:"column(industry_map_id);" description:"行业图谱id"`
  39. IndustryMapName string `description:"图谱名称"`
  40. Level int `description:"层级深度"`
  41. }
  42. func GetCygxIndustryMapByName(name string) (count int, err error) {
  43. o := orm.NewOrmUsingDB("hz_cygx")
  44. sql := ` SELECT COUNT(1) AS count FROM cygx_industry_map WHERE industry_map_name=?`
  45. err = o.Raw(sql, name).QueryRow(&count)
  46. return
  47. }
  48. func AddCygxIndustryMap(item *CygxIndustryMap) (err error) {
  49. o := orm.NewOrmUsingDB("hz_cygx")
  50. _, err = o.Insert(item)
  51. return
  52. }
  53. // 编辑图谱
  54. type IndustryMapEditReq struct {
  55. IndustryMapId int `orm:"column(industry_map_id);" description:"行业图谱id"`
  56. IndustryMapName string `description:"图谱名称"`
  57. }
  58. func GetCygxIndustryMapById(industryMapId int) (items *CygxIndustryMapItems, err error) {
  59. o := orm.NewOrmUsingDB("hz_cygx")
  60. sql := ` SELECT * FROM cygx_industry_map WHERE industry_map_id=?`
  61. err = o.Raw(sql, industryMapId).QueryRow(&items)
  62. return
  63. }
  64. func EditCygxIndustryMap(item *IndustryMapEditReq) (err error) {
  65. o := orm.NewOrmUsingDB("hz_cygx")
  66. sql := `UPDATE cygx_industry_map SET industry_map_name=?,modify_time = NOW() WHERE industry_map_id=? `
  67. _, err = o.Raw(sql, item.IndustryMapName, item.IndustryMapId).Exec()
  68. return
  69. }
  70. // 编辑图谱
  71. type IndustryMapDeleteReq struct {
  72. IndustryMapId int `orm:"column(industry_map_id);" description:"行业图谱id"`
  73. }
  74. func DeleteCygxIndustryMap(industryMapId int) (err error) {
  75. o := orm.NewOrm()
  76. sql := `DELETE FROM cygx_industry_map WHERE industry_map_id=? `
  77. _, err = o.Raw(sql, industryMapId).Exec()
  78. return
  79. }
  80. // 列表
  81. func GetIndustrialMapListName(condition string) (items []*IndustryMapAddReq, err error) {
  82. o := orm.NewOrmUsingDB("hz_cygx")
  83. sql := `SELECT * FROM cygx_industry_map WHERE 1= 1 `
  84. if condition != "" {
  85. sql += condition
  86. }
  87. sql += ` GROUP BY industry_map_name `
  88. _, err = o.Raw(sql).QueryRows(&items)
  89. return
  90. }