chart_permission.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package models
  2. import (
  3. "fmt"
  4. "strings"
  5. "time"
  6. "github.com/beego/beego/v2/client/orm"
  7. )
  8. type PermissionClassifyMapping struct {
  9. Id int `orm:"column(id);pk" description:"ID" json:"id"`
  10. PermissionId int ` description:"品种ID" json:"permissionId"`
  11. ClassifyId int `description:"分类ID" json:"classifyName"`
  12. CreatedTime time.Time `description:"创建时间" json:"createdTime"`
  13. UpdatedTime time.Time `description:"更新时间" json:"UpdatedTime"`
  14. }
  15. type ChartPermission struct {
  16. ChartPermissionId int `orm:"column(chart_permission_id);pk" description:"问题ID" json:"chart_permission_id"`
  17. ChartPermissionName string `description:"名称" json:"chart_permission_name"`
  18. PermissionName string `description:"权限名" json:"permission_name"`
  19. Sort int `description:"排序" json:"sort"`
  20. Enabled int `description:"是否可用" json:"enabled"`
  21. CreatedTime time.Time `description:"创建时间" json:"created_time"`
  22. LastUpdatedTime time.Time `description:"更新时间" json:"last_updated_time"`
  23. TeleconferenceSort int `description:"电话会类型排序" json:"teleconference_sort"`
  24. Remark string `description:"备注" json:"remark"`
  25. ClassifyName string `description:"分类名称" json:"classify_name"`
  26. ProductName string `description:"产品名称" json:"product_name"`
  27. ProductId int `description:"产品ID" json:"product_id"`
  28. ImageURL string `orm:"column(image_url);" description:"图片地址" json:"image_url"`
  29. ShowType int `description:"1:查研观向小程序展示" json:"show_type"`
  30. IsOther int `description:"是否是其他,用于查研观向小程序后台展示" json:"is_other"`
  31. IsReport int `description:"是否是报告,用于查研观向小程序前台报告展示" json:"is_report"`
  32. CygxAuth int `description:"是否是权限,用于查研观向小程序前台权限校验" json:"cygx_auth"`
  33. PermissionType int `description:"1主观,2客观" json:"permission_type"`
  34. YbImgUrl string `description:"研报小程序报告列表icon" json:"yb_img_url"`
  35. ProductPermissionName string `description:"种类权限名称" json:"product_permission_name"`
  36. PriceDrivenState int `description:"品种价格驱动开启状态 0-关闭 1-开启" json:"price_driven_state"`
  37. ImageUrlM string `description:"图片地址(查研观向移动端)" json:"image_url_m"`
  38. ParentId int `description:"父级权限id" json:"parent_id"`
  39. IsPublic int `description:"是否是公有权限1:公有权限,0私有权限" json:"is_public"`
  40. }
  41. type ChartPermissionList struct {
  42. ChartPermissionId int `orm:"column(chart_permission_id);pk" description:"问题ID" json:"chart_permission_id"`
  43. ChartPermissionName string `description:"名称" json:"chart_permission_name"`
  44. PermissionName string `description:"权限名" json:"permission_name"`
  45. Sort int `description:"排序" json:"sort"`
  46. Enabled int `description:"是否可用" json:"enabled"`
  47. CreatedTime time.Time `description:"创建时间" json:"created_time"`
  48. LastUpdatedTime time.Time `description:"更新时间" json:"last_updated_time"`
  49. TeleconferenceSort int `description:"电话会类型排序" json:"teleconference_sort"`
  50. Remark string `description:"备注" json:"remark"`
  51. ClassifyName string `description:"分类名称" json:"classify_name"`
  52. ProductName string `description:"产品名称" json:"product_name"`
  53. ProductId int `description:"产品ID" json:"product_id"`
  54. ImageURL string `orm:"column(image_url);" description:"图片地址" json:"image_url"`
  55. ShowType int `description:"1:查研观向小程序展示" json:"show_type"`
  56. IsOther int `description:"是否是其他,用于查研观向小程序后台展示" json:"is_other"`
  57. IsReport int `description:"是否是报告,用于查研观向小程序前台报告展示" json:"is_report"`
  58. CygxAuth int `description:"是否是权限,用于查研观向小程序前台权限校验" json:"cygx_auth"`
  59. PermissionType int `description:"1主观,2客观" json:"permission_type"`
  60. YbImgUrl string `description:"研报小程序报告列表icon" json:"yb_img_url"`
  61. ProductPermissionName string `description:"种类权限名称" json:"product_permission_name"`
  62. PriceDrivenState int `description:"品种价格驱动开启状态 0-关闭 1-开启" json:"price_driven_state"`
  63. ImageUrlM string `description:"图片地址(查研观向移动端)" json:"image_url_m"`
  64. ParentId int `description:"父级权限id" json:"parent_id"`
  65. IsPublic int `description:"是否是公有权限1:公有权限,0私有权限" json:"is_public"`
  66. Child []*ChartPermissionList `description:"子权限"`
  67. }
  68. // ChartPermissionSearchKeyWordMapping 表示 chart_permission_search_key_word_mapping 表的结构
  69. type ChartPermissionSearchKeyWordMapping struct {
  70. ChartPermissionID int `gorm:"column:chart_permission_id"` // chart_permission_id 字段
  71. ClassifyID int `gorm:"column:classify_id"` // classify_id 字段
  72. }
  73. type ChartPermissionView struct {
  74. ParentName string `description:"父权限名称" json:"parent_name"`
  75. PermissionName string `description:"权限名" json:"permission_name"`
  76. }
  77. type ChartPermissionListTree struct {
  78. ChartPermissionId int `description:"权限ID"`
  79. PermissionName string `description:"权限名"`
  80. ParentId int `description:"父权限ID"`
  81. IsPublic int `description:"是否是公有权限"`
  82. PublicChild []*ChartPermissionListTree `description:"公有权限"`
  83. PrivateChild []*ChartPermissionListTree `description:"私有权限"`
  84. }
  85. func GetChartPermissionListByIds(chartPermissionIds []int) (items []*ChartPermissionView, err error) {
  86. o := orm.NewOrmUsingDB("rddp")
  87. sql := `SELECT c.permission_name AS permission_name, lc.permission_name AS parent_name FROM chart_permission c
  88. LEFT JOIN chart_permission lc
  89. ON c.parent_id=lc.chart_permission_id
  90. WHERE c.chart_permission_id in (%s)
  91. `
  92. // 构建 IN 子句的占位符
  93. placeholders := make([]string, len(chartPermissionIds))
  94. args := make([]interface{}, len(chartPermissionIds))
  95. for i, id := range chartPermissionIds {
  96. placeholders[i] = "?"
  97. args[i] = id
  98. }
  99. sql = fmt.Sprintf(sql, strings.Join(placeholders, ","))
  100. _, err = o.Raw(sql, chartPermissionIds).QueryRows(&items)
  101. return
  102. }
  103. func GetByPermissionIdsByClassifyId(classify int) (permissionIds []int, err error) {
  104. o := orm.NewOrm()
  105. sql := "select distinct permission_id from permission_classify_mapping where classify_id =?"
  106. _, err = o.Raw(sql, classify).QueryRows(&permissionIds)
  107. return
  108. }
  109. func GetPermissionNameById(id int) (items string, err error) {
  110. o := orm.NewOrm()
  111. sql := `SELECT name FROM permissions WHERE permission_id=?`
  112. err = o.Raw(sql, id).QueryRow(&items)
  113. return
  114. }
  115. func GetClassifyIdsByPermissionIds(condition string, pars []interface{}) (classifyIds []int, err error) {
  116. o := orm.NewOrm()
  117. sql := "select distinct classify_id from permission_classify_mapping where 1=1 "
  118. if condition != "" {
  119. sql += condition
  120. }
  121. _, err = o.Raw(sql, pars).QueryRows(&classifyIds)
  122. return
  123. }