chart_permission.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 GetChartPermissionAllXzs(condition string, pars []interface{}) (items []*ChartPermissionXzsResp, err error) {
  44. o := orm.NewOrmUsingDB("weekly_report")
  45. sql := `SELECT * FROM chart_permission WHERE product_id=2 AND is_report=1 AND permission_type!=2 AND chart_permission_id != 52 ` + condition + ` ORDER BY sort ASC `
  46. _, err = o.Raw(sql, pars).QueryRows(&items)
  47. return
  48. }
  49. func GetChartPermissionListRai() (items []*ChartPermission, err error) {
  50. o := orm.NewOrmUsingDB("weekly_report")
  51. sql := `SELECT * FROM chart_permission WHERE product_id=2 ORDER BY sort ASC `
  52. _, err = o.Raw(sql).QueryRows(&items)
  53. return
  54. }
  55. // GetChartPermissionList 获取品种权限列表
  56. func GetChartPermissionList() (list []*ChartPermissionCrm, err error) {
  57. o := orm.NewOrmUsingDB("weekly_report")
  58. sql := `SELECT * FROM chart_permission WHERE parent_id > 0 ORDER BY product_id ASC, sort ASC`
  59. _, err = o.Raw(sql).QueryRows(&list)
  60. return
  61. }
  62. func GetCategoryId(chartPermissionId int) (category_id string, err error) {
  63. o := orm.NewOrm()
  64. sql := ` SELECT GROUP_CONCAT(a.category_id) AS category_id
  65. FROM cygx_report_mapping AS a
  66. WHERE a.chart_permission_id=? AND a.is_summary = 1
  67. GROUP BY a.chart_permission_id `
  68. err = o.Raw(sql, chartPermissionId).QueryRow(&category_id)
  69. return
  70. }
  71. func GetChartPermissionReportAll(condition string) (items []*ChartPermission, err error) {
  72. o := orm.NewOrmUsingDB("weekly_report")
  73. sql := `SELECT * FROM chart_permission WHERE product_id=2 AND is_report=1 AND permission_type!=2 ` + condition + ` ORDER BY sort ASC `
  74. _, err = o.Raw(sql).QueryRows(&items)
  75. return
  76. }
  77. func GetChartPermissionById(chartPermissionId int) (item *ChartPermission, err error) {
  78. o := orm.NewOrmUsingDB("weekly_report")
  79. sql := `SELECT * FROM chart_permission WHERE chart_permission_id = ? `
  80. err = o.Raw(sql, chartPermissionId).QueryRow(&item)
  81. return
  82. }
  83. func GetChartPermissionActivity() (items []*ActivityChartPermission, err error) {
  84. o := orm.NewOrmUsingDB("weekly_report")
  85. //sql := `SELECT * FROM chart_permission WHERE chart_permission_id IN (19,20,21,22,23,31,53) ORDER BY sort ASC `
  86. 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 `
  87. _, err = o.Raw(sql).QueryRows(&items)
  88. return
  89. }
  90. // 处理添加主观客观之后的分类ID错误
  91. func GetUserCompanyPermission(companyId int) (items []*ActivityChartPermission, err error) {
  92. list, err := GetUserCompanyPermissionSandO(companyId)
  93. if err != nil {
  94. return
  95. }
  96. if len(list) == 0 {
  97. return
  98. }
  99. var chartPermissionName string
  100. for _, v := range list {
  101. chartPermissionName += "'" + v.PermissionName + "'" + ","
  102. }
  103. chartPermissionName = strings.Trim(chartPermissionName, ",")
  104. sql := ` SELECT b.*
  105. FROM company_report_permission AS a
  106. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  107. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  108. WHERE a.product_id=2
  109. AND c.is_suspend=0
  110. AND b.cygx_auth=1
  111. AND b.is_other=0
  112. AND c.status IN('正式','试用','永续')
  113. AND a.status IN('正式','试用','永续')
  114. AND b.chart_permission_name IN (` + chartPermissionName + `)
  115. GROUP BY b.chart_permission_name
  116. ORDER BY b.sort ASC `
  117. o := orm.NewOrmUsingDB("weekly_report")
  118. _, err = o.Raw(sql).QueryRows(&items)
  119. return
  120. }
  121. func GetUserCompanyPermissionSandO(companyId int) (items []*ActivityChartPermission, err error) {
  122. sql := ` SELECT b.*
  123. FROM company_report_permission AS a
  124. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  125. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  126. WHERE a.company_id=?
  127. AND a.product_id=2
  128. AND c.is_suspend=0
  129. AND b.cygx_auth=1
  130. AND b.is_other=0
  131. AND c.status IN('正式','试用','永续')
  132. AND a.status IN('正式','试用','永续')
  133. AND b.chart_permission_name != '专家'
  134. GROUP BY b.chart_permission_name
  135. ORDER BY b.sort ASC `
  136. o := orm.NewOrmUsingDB("weekly_report")
  137. _, err = o.Raw(sql, companyId).QueryRows(&items)
  138. return
  139. }
  140. // 获取策略下面的所有分类
  141. func GetCompanyReportPermissionAll() (items []*CompanyReportPermission, err error) {
  142. o := orm.NewOrmUsingDB("weekly_report")
  143. 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'`
  144. _, err = o.Raw(sql).QueryRows(&items)
  145. return
  146. }
  147. // 获取海通国际开通的默认权限
  148. func GetCompanyPermissionIdWithHtgj() (chartpermissionids string, err error) {
  149. sql := ` SELECT GROUP_CONCAT(DISTINCT chart_permission_id ORDER BY b.sort ASC SEPARATOR ',') AS chartpermissionids
  150. FROM chart_permission as b
  151. WHERE chart_permission_name IN ('医药','消费','科技','智造','买方研选')`
  152. o := orm.NewOrmUsingDB("weekly_report")
  153. err = o.Raw(sql).QueryRow(&chartpermissionids)
  154. return
  155. }
  156. // GetChartPermissionById 主键获取权限
  157. func GetChartPermissionByRemark(remark string) (item *ChartPermission, err error) {
  158. o := orm.NewOrmUsingDB("weekly_report")
  159. sql := `SELECT * FROM chart_permission WHERE remark = ? LIMIT 1`
  160. err = o.Raw(sql, remark).QueryRow(&item)
  161. return
  162. }
  163. func GetChartPermissionIdByName(condition string, pars []interface{}) (chartpermissionids string, err error) {
  164. o := orm.NewOrmUsingDB("weekly_report")
  165. sql := `SELECT GROUP_CONCAT(DISTINCT chart_permission_id SEPARATOR ',') AS chartpermissionids FROM chart_permission WHERE product_id=2 ` + condition
  166. err = o.Raw(sql, pars).QueryRow(&chartpermissionids)
  167. return
  168. }
  169. type ChartPermissionXzsResp struct {
  170. ChartPermissionId int `description:"权限id"`
  171. PermissionName string `description:"权限名称"`
  172. HasCheck bool `description:"是否有权限"`
  173. AllTracks string `default:"全部赛道";description:"全部赛道"`
  174. ListFollow []*IndustrialManagementRep // 重点关注
  175. CheckListFollow []int // 重点关注的ID
  176. ListPush []*IndustrialManagementRep // 接受推送
  177. CheckListPush []int // 接受推送的ID
  178. ListUninterested []*IndustrialManagementRep // 不感兴趣
  179. CheckListUninterested []int // 不感兴趣的ID
  180. }