chart_permission.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 ChartPermissionItemResp struct {
  14. ChartPermissionId int `description:"权限id"`
  15. PermissionName string `description:"权限名称"`
  16. IsShowSustainable bool `description:"是否展示限免标签"`
  17. ImageUrlM string `description:"图片地址"`
  18. IsChoose bool `description:"是否选择"`
  19. MatchTypeName string `description:"匹配类型名称"`
  20. }
  21. type ActivityChartPermission struct {
  22. ChartPermissionId int `description:"权限id"`
  23. PermissionName string `description:"权限名称"`
  24. IsChoose bool `description:"是否选择"`
  25. }
  26. // ChartPermission 报告权限表
  27. type ChartPermissionCrm struct {
  28. ChartPermissionId int `orm:"column(chart_permission_id);pk" description:"问题ID"`
  29. ChartPermissionName string `description:"名称"`
  30. PermissionName string `description:"权限名"`
  31. Remark string `description:"备注"`
  32. ProductId int `description:"产品ID"`
  33. }
  34. type ChartPermissionResp struct {
  35. List []*ChartPermission
  36. }
  37. func GetChartPermissionAll(condition string) (items []*ChartPermission, err error) {
  38. o := orm.NewOrmUsingDB("weekly_report")
  39. sql := `SELECT * FROM chart_permission WHERE product_id=2 AND show_type=1 AND permission_type!=2 ` + condition + ` ORDER BY sort ASC `
  40. _, err = o.Raw(sql).QueryRows(&items)
  41. return
  42. }
  43. func GetChartPermissionListRai() (items []*ChartPermission, err error) {
  44. o := orm.NewOrmUsingDB("weekly_report")
  45. sql := `SELECT * FROM chart_permission WHERE product_id=2 ORDER BY sort ASC `
  46. _, err = o.Raw(sql).QueryRows(&items)
  47. return
  48. }
  49. // GetChartPermissionList 获取品种权限列表
  50. func GetChartPermissionList() (list []*ChartPermissionCrm, err error) {
  51. o := orm.NewOrmUsingDB("weekly_report")
  52. sql := `SELECT * FROM chart_permission WHERE parent_id > 0 ORDER BY product_id ASC, sort ASC`
  53. _, err = o.Raw(sql).QueryRows(&list)
  54. return
  55. }
  56. func GetCategoryId(chartPermissionId int) (category_id string, err error) {
  57. o := orm.NewOrm()
  58. sql := ` SELECT GROUP_CONCAT(a.category_id) AS category_id
  59. FROM cygx_report_mapping AS a
  60. WHERE a.chart_permission_id=? AND a.is_summary = 1
  61. GROUP BY a.chart_permission_id `
  62. err = o.Raw(sql, chartPermissionId).QueryRow(&category_id)
  63. return
  64. }
  65. func GetChartPermissionReportAll(condition string) (items []*ChartPermission, err error) {
  66. o := orm.NewOrmUsingDB("weekly_report")
  67. sql := `SELECT * FROM chart_permission WHERE product_id=2 AND is_report=1 AND permission_type!=2 ` + condition + ` ORDER BY sort ASC `
  68. _, err = o.Raw(sql).QueryRows(&items)
  69. return
  70. }
  71. func GetChartPermissionById(chartPermissionId int) (item *ChartPermission, err error) {
  72. o := orm.NewOrmUsingDB("weekly_report")
  73. sql := `SELECT * FROM chart_permission WHERE chart_permission_id = ? `
  74. err = o.Raw(sql, chartPermissionId).QueryRow(&item)
  75. return
  76. }
  77. func GetChartPermissionActivity() (items []*ActivityChartPermission, err error) {
  78. o := orm.NewOrmUsingDB("weekly_report")
  79. //sql := `SELECT * FROM chart_permission WHERE chart_permission_id IN (19,20,21,22,23,31,53) ORDER BY sort ASC `
  80. sql := `SELECT * FROM chart_permission WHERE product_id=2 AND is_report=1 AND permission_type!=2 AND permission_name IN ('医药','消费','科技','智造','策略','固收','研选订阅','周期') ORDER BY sort ASC `
  81. _, err = o.Raw(sql).QueryRows(&items)
  82. return
  83. }
  84. // 处理添加主观客观之后的分类ID错误
  85. func GetUserCompanyPermission(companyId int) (items []*ActivityChartPermission, err error) {
  86. list, err := GetUserCompanyPermissionSandO(companyId)
  87. if err != nil {
  88. return
  89. }
  90. if len(list) == 0 {
  91. return
  92. }
  93. var chartPermissionName string
  94. for _, v := range list {
  95. chartPermissionName += "'" + v.PermissionName + "'" + ","
  96. }
  97. chartPermissionName = strings.Trim(chartPermissionName, ",")
  98. sql := ` SELECT b.*
  99. FROM company_report_permission AS a
  100. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  101. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  102. WHERE a.product_id=2
  103. AND c.is_suspend=0
  104. AND b.cygx_auth=1
  105. AND b.is_other=0
  106. AND c.status IN('正式','试用','永续')
  107. AND a.status IN('正式','试用','永续')
  108. AND b.chart_permission_name IN (` + chartPermissionName + `)
  109. GROUP BY b.chart_permission_name
  110. ORDER BY b.sort ASC `
  111. o := orm.NewOrmUsingDB("weekly_report")
  112. _, err = o.Raw(sql).QueryRows(&items)
  113. return
  114. }
  115. func GetUserCompanyPermissionSandO(companyId int) (items []*ActivityChartPermission, err error) {
  116. sql := ` SELECT b.*
  117. FROM company_report_permission AS a
  118. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  119. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  120. WHERE a.company_id=?
  121. AND a.product_id=2
  122. AND c.is_suspend=0
  123. AND b.cygx_auth=1
  124. AND b.is_other=0
  125. AND c.status IN('正式','试用','永续')
  126. AND a.status IN('正式','试用','永续')
  127. AND b.chart_permission_name != '专家'
  128. GROUP BY b.chart_permission_name
  129. ORDER BY b.sort ASC `
  130. o := orm.NewOrmUsingDB("weekly_report")
  131. _, err = o.Raw(sql, companyId).QueryRows(&items)
  132. return
  133. }
  134. // 获取策略下面的所有分类
  135. func GetCompanyReportPermissionAll() (items []*CompanyReportPermission, err error) {
  136. o := orm.NewOrmUsingDB("weekly_report")
  137. sql := `SELECT * FROM company_report_permission WHERE chart_permission_id IN (19,20,21,22) AND status IN ('正式','试用','永续') AND created_time <= '2021-12-28 15:05:43'`
  138. _, err = o.Raw(sql).QueryRows(&items)
  139. return
  140. }
  141. // 获取海通国际开通的默认权限
  142. func GetCompanyPermissionIdWithHtgj() (chartpermissionids string, err error) {
  143. sql := ` SELECT GROUP_CONCAT(DISTINCT chart_permission_id ORDER BY b.sort ASC SEPARATOR ',') AS chartpermissionids
  144. FROM chart_permission as b
  145. WHERE chart_permission_name IN ('医药','消费','科技','智造','买方研选')`
  146. o := orm.NewOrmUsingDB("weekly_report")
  147. err = o.Raw(sql).QueryRow(&chartpermissionids)
  148. return
  149. }
  150. // GetChartPermissionById 主键获取权限
  151. func GetChartPermissionByRemark(remark string) (item *ChartPermission, err error) {
  152. o := orm.NewOrmUsingDB("weekly_report")
  153. sql := `SELECT * FROM chart_permission WHERE remark = ? LIMIT 1`
  154. err = o.Raw(sql, remark).QueryRow(&item)
  155. return
  156. }
  157. func GetChartPermissionIdByName(condition string, pars []interface{}) (chartpermissionids string, err error) {
  158. o := orm.NewOrmUsingDB("weekly_report")
  159. sql := `SELECT GROUP_CONCAT(DISTINCT chart_permission_id SEPARATOR ',') AS chartpermissionids FROM chart_permission WHERE product_id=2 ` + condition
  160. err = o.Raw(sql, pars).QueryRow(&chartpermissionids)
  161. return
  162. }