chart_permission.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "strings"
  5. )
  6. type ChartPermission struct {
  7. ChartPermissionId int `description:"权限id"`
  8. PermissionName string `description:"权限名称"`
  9. IsShowSustainable bool `description:"是否展示限免标签"`
  10. ImageUrlM string `description:"图片地址"`
  11. IsChoose bool `description:"是否选择"`
  12. }
  13. type ActivityChartPermission struct {
  14. ChartPermissionId int `description:"权限id"`
  15. PermissionName string `description:"权限名称"`
  16. IsChoose bool `description:"是否选择"`
  17. }
  18. type ChartPermissionResp struct {
  19. List []*ChartPermission
  20. }
  21. func GetChartPermissionById(chartPermissionId int) (item *ChartPermission, err error) {
  22. o := orm.NewOrmUsingDB("weekly_report")
  23. sql := `SELECT * FROM chart_permission WHERE chart_permission_id = ? `
  24. err = o.Raw(sql, chartPermissionId).QueryRow(&item)
  25. return
  26. }
  27. func GetChartPermissionActivity() (items []*ActivityChartPermission, err error) {
  28. o := orm.NewOrmUsingDB("weekly_report")
  29. sql := `SELECT * FROM chart_permission WHERE chart_permission_id IN (19,20,21,22,23,31) ORDER BY sort ASC `
  30. _, err = o.Raw(sql).QueryRows(&items)
  31. return
  32. }
  33. // 处理添加主观客观之后的分类ID错误
  34. func GetUserCompanyPermission(companyId int) (items []*ActivityChartPermission, err error) {
  35. list, err := GetUserCompanyPermissionSandO(companyId)
  36. if err != nil {
  37. return
  38. }
  39. if len(list) == 0 {
  40. return
  41. }
  42. var chartPermissionName string
  43. for _, v := range list {
  44. chartPermissionName += "'" + v.PermissionName + "'" + ","
  45. }
  46. chartPermissionName = strings.Trim(chartPermissionName, ",")
  47. sql := ` SELECT b.*
  48. FROM company_report_permission AS a
  49. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  50. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  51. WHERE a.product_id=2
  52. AND c.is_suspend=0
  53. AND b.cygx_auth=1
  54. AND b.is_other=0
  55. AND c.status IN('正式','试用','永续')
  56. AND a.status IN('正式','试用','永续')
  57. AND b.chart_permission_name IN (` + chartPermissionName + `)
  58. GROUP BY b.chart_permission_name
  59. ORDER BY b.sort ASC `
  60. o := orm.NewOrmUsingDB("weekly_report")
  61. _, err = o.Raw(sql).QueryRows(&items)
  62. return
  63. }
  64. func GetUserCompanyPermissionSandO(companyId int) (items []*ActivityChartPermission, err error) {
  65. sql := ` SELECT b.*
  66. FROM company_report_permission AS a
  67. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  68. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  69. WHERE a.company_id=?
  70. AND a.product_id=2
  71. AND c.is_suspend=0
  72. AND b.cygx_auth=1
  73. AND b.is_other=0
  74. AND c.status IN('正式','试用','永续')
  75. AND a.status IN('正式','试用','永续')
  76. AND b.chart_permission_name != '专家'
  77. GROUP BY b.chart_permission_name
  78. ORDER BY b.sort ASC `
  79. o := orm.NewOrmUsingDB("weekly_report")
  80. _, err = o.Raw(sql, companyId).QueryRows(&items)
  81. return
  82. }