chart_permission.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package models
  2. import (
  3. "eta/eta_mini_bridge/utils"
  4. "fmt"
  5. "strings"
  6. "time"
  7. "github.com/beego/beego/v2/client/orm"
  8. )
  9. type ChartPermission struct {
  10. ChartPermissionId int `orm:"pk" description:"权限ID"`
  11. ChartPermissionName string `description:"名称"`
  12. PermissionName string `description:"权限名"`
  13. Sort int `description:"排序"`
  14. Enabled int `description:"是否可用"`
  15. CreatedTime time.Time `description:"创建时间"`
  16. LastUpdatedTime time.Time `description:"更新时间"`
  17. TeleconferenceSort int `description:"电话会类型排序"`
  18. Remark string `description:"备注"`
  19. ClassifyName string `description:"分类名称"`
  20. ProductName string `description:"产品名称" `
  21. ProductId int `description:"产品ID"`
  22. ImageUrl string `description:"图片地址"`
  23. ShowType int `description:"1:查研观向小程序展示"`
  24. IsOther int `description:"是否是其他,用于查研观向小程序后台展示"`
  25. IsReport int `description:"是否是报告,用于查研观向小程序前台报告展示"`
  26. CygxAuth int `description:"是否是权限,用于查研观向小程序前台权限校验"`
  27. PermissionType int `description:"1主观,2客观"`
  28. YbImgUrl string `description:"研报小程序报告列表icon"`
  29. ProductPermissionName string `description:"种类权限名称"`
  30. PriceDrivenState int `description:"品种价格驱动开启状态 0-关闭 1-开启"`
  31. ImageUrlM string `description:"图片地址(查研观向移动端)"`
  32. ParentId int `description:"父级权限id"`
  33. IsPublic int `description:"是否是公有权限1:公有权限,0私有权限"`
  34. }
  35. type ChartPermissionView struct {
  36. ChartPermissionId int `orm:"pk" description:"权限ID"`
  37. PermissionName string `description:"权限名"`
  38. Child []*ChartPermissionView `description:"子权限"`
  39. IsPublic int `description:"是否是公有权限1:公有权限,0私有权限"`
  40. ParentId int `description:"父级权限id"`
  41. Sort int `description:"排序"`
  42. }
  43. type BySortChartPermissionView []*ChartPermissionView
  44. func (a BySortChartPermissionView) Len() int { return len(a) }
  45. func (a BySortChartPermissionView) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
  46. func (a BySortChartPermissionView) Less(i, j int) bool { return a[i].Sort < a[j].Sort }
  47. // GetChartPermissionList 获取全部权限品种权限列表
  48. func GetChartPermissionList() (items []*ChartPermission, err error) {
  49. o := orm.NewOrmUsingDB("rddp")
  50. sql := `SELECT * FROM chart_permission WHERE enabled=1 AND product_id=1 ORDER BY sort ASC`
  51. _, err = o.Raw(sql).QueryRows(&items)
  52. return
  53. }
  54. // GetChildChartPermissionListById 根据品种id获取子品种权限列表
  55. func GetChildChartPermissionListById(id int) (items []*ChartPermission, err error) {
  56. o := orm.NewOrmUsingDB("rddp")
  57. sql := `SELECT * FROM chart_permission WHERE enabled=1 AND product_id=1 AND parent_id=? ORDER BY sort ASC`
  58. _, err = o.Raw(sql, id).QueryRows(&items)
  59. return
  60. }
  61. // GetChartPermissionListByStrIds 根据品种ids获取品种权限列表
  62. func GetChartPermissionListByStrIds(chartPermissionIds []string) (items []*ChartPermission, err error) {
  63. // 没有品种权限就返回空
  64. if len(chartPermissionIds) == 0 {
  65. return
  66. }
  67. o := orm.NewOrmUsingDB("rddp")
  68. sql := `SELECT * FROM chart_permission WHERE enabled=1 AND product_id=1 `
  69. if len(chartPermissionIds) > 0 {
  70. sql += fmt.Sprintf(" AND chart_permission_id IN (%s) ", strings.Join(chartPermissionIds, ","))
  71. }
  72. sql += ` ORDER BY sort ASC `
  73. _, err = o.Raw(sql).QueryRows(&items)
  74. return
  75. }
  76. // GetChartPermissionListByIds 根据品种ids获取品种权限列表
  77. func GetChartPermissionListByIds(chartPermissionIds []int) (items []*ChartPermission, err error) {
  78. // 没有品种权限就返回空
  79. if len(chartPermissionIds) == 0 {
  80. return
  81. }
  82. o := orm.NewOrmUsingDB("rddp")
  83. sql := `SELECT * FROM chart_permission WHERE enabled=1 AND product_id=1 `
  84. if len(chartPermissionIds) > 0 {
  85. sql += fmt.Sprintf(" AND chart_permission_id IN (%s) ", utils.GetOrmReplaceHolder(len(chartPermissionIds)))
  86. }
  87. sql += ` ORDER BY sort ASC `
  88. _, err = o.Raw(sql, chartPermissionIds).QueryRows(&items)
  89. return
  90. }
  91. // GetChartPermissionById 根据品种id获取品种权限
  92. func GetChartPermissionById(chartPermissionId int) (item *ChartPermission, err error) {
  93. o := orm.NewOrmUsingDB("rddp")
  94. sql := `SELECT * FROM chart_permission WHERE enabled=1 AND product_id=1 AND chart_permission_id=?`
  95. err = o.Raw(sql, chartPermissionId).QueryRow(&item)
  96. return
  97. }
  98. // GetChildChartPermissionIdsById 根据品种id获取子品种权限的id列表
  99. func GetChildChartPermissionIdsById(chartPermissionId int) (items []int, err error) {
  100. o := orm.NewOrmUsingDB("rddp")
  101. sql := `SELECT chart_permission_id FROM chart_permission WHERE enabled=1 AND product_id=1 AND parent_id=? ORDER BY sort ASC`
  102. _, err = o.Raw(sql, chartPermissionId).QueryRows(&items)
  103. return
  104. }
  105. // // GetChartPermissionListByIds2 根据品种ids获取品种权限列表
  106. // func GetChartPermissionListByIds2(chartPermissionIds []string) (items []*ChartPermission, err error) {
  107. // if len(chartPermissionIds) == 0 {
  108. // return
  109. // }
  110. // o := orm.NewOrmUsingDB("rddp")
  111. // sql := `SELECT * FROM chart_permission
  112. // WHERE enabled=1 AND product_id=1 `
  113. // var idsStr string
  114. // if len(chartPermissionIds) > 0 {
  115. // idsStr = strings.Join(chartPermissionIds, ",")
  116. // sql += fmt.Sprintf(" AND chart_permission_id in (%s) ", idsStr)
  117. // }
  118. // sql += ` ORDER BY sort ASC`
  119. // _, err = o.Raw(sql).QueryRows(&items)
  120. // return
  121. // }