permission.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package models
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strconv"
  6. )
  7. // ChartPermissionSearchKeyWordMapping 权限相关
  8. type ChartPermissionSearchKeyWordMapping struct {
  9. Id int `description:"id" json:"-"`
  10. ChartPermissionId int `description:"权限id"`
  11. KeyWord string `description:"二级分类名称"`
  12. From string `description:"类型标识" json:"-"`
  13. TacticType string `description:"策略表type字段值" json:"-"`
  14. TeleconferenceSort int `description:"电话会类型排序" json:"-"`
  15. ClassifyId int `description:"分类ID"`
  16. }
  17. func GetPermission(classifyId int) (items []*ChartPermissionSearchKeyWordMapping, err error) {
  18. o := orm.NewOrmUsingDB("rddp")
  19. sql := `SELECT * FROM chart_permission_search_key_word_mapping AS a WHERE a.from='rddp' AND a.classify_id = ? `
  20. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  21. return
  22. }
  23. func GetAllPermissionMapping() (items []*ChartPermissionSearchKeyWordMapping, err error) {
  24. o := orm.NewOrmUsingDB("rddp")
  25. sql := `SELECT * FROM chart_permission_search_key_word_mapping AS a WHERE a.from='rddp'`
  26. _, err = o.Raw(sql).QueryRows(&items)
  27. return
  28. }
  29. // EditChartPermissionSearchKeyWordMappingMulti 修改报告报告权限(先删除原有的权限,再添加新的权限)
  30. func EditChartPermissionSearchKeyWordMappingMulti(keyword string, permissionIdList []int, classifyId int) (err error) {
  31. o := orm.NewOrmUsingDB("rddp")
  32. to, err := o.Begin()
  33. if err != nil {
  34. return
  35. }
  36. defer func() {
  37. if err != nil {
  38. _ = to.Rollback()
  39. } else {
  40. _ = to.Commit()
  41. }
  42. }()
  43. sql := "DELETE FROM chart_permission_search_key_word_mapping WHERE `from` = 'rddp' AND classify_id = ?"
  44. _, err = to.Raw(sql, classifyId).Exec()
  45. if err != nil {
  46. return
  47. }
  48. if len(permissionIdList) > 0 {
  49. chartPermissionSearchKeyWordMappingList := make([]*ChartPermissionSearchKeyWordMapping, 0)
  50. for _, permissionId := range permissionIdList {
  51. tmpChartPermissionSearchKeyWordMapping := &ChartPermissionSearchKeyWordMapping{
  52. ChartPermissionId: permissionId,
  53. KeyWord: keyword,
  54. From: "rddp",
  55. TacticType: "",
  56. TeleconferenceSort: 0,
  57. ClassifyId: classifyId,
  58. }
  59. chartPermissionSearchKeyWordMappingList = append(chartPermissionSearchKeyWordMappingList, tmpChartPermissionSearchKeyWordMapping)
  60. }
  61. _, err = to.InsertMulti(len(chartPermissionSearchKeyWordMappingList), chartPermissionSearchKeyWordMappingList)
  62. }
  63. return
  64. }
  65. func AddChartPermissionChapterMapping(chartPermissionId int, reportId int64) (err error) {
  66. sql := `INSERT INTO chart_permission_chapter_mapping (chart_permission_id, report_chapter_type_id,research_type)
  67. VALUES(?,?,?)`
  68. o := orm.NewOrmUsingDB("rddp")
  69. _, err = o.Raw(sql, chartPermissionId, reportId, "rddp").Exec()
  70. return
  71. }
  72. func RemoveChartPermissionChapterMapping(reportId int64) (err error) {
  73. sql := ` DELETE FROM chart_permission_chapter_mapping WHERE research_type=? AND report_chapter_type_id=? `
  74. o := orm.NewOrmUsingDB("rddp")
  75. _, err = o.Raw(sql, "rddp", reportId).Exec()
  76. return
  77. }
  78. type ChartPermissionMappingIdName struct {
  79. PermissionId int
  80. PermissionName string
  81. }
  82. func GetChartPermissionNameFromMappingByKeyword(source string, classifyId int) (list []*ChartPermissionMappingIdName, err error) {
  83. o := orm.NewOrmUsingDB("rddp")
  84. sql := " SELECT b.chart_permission_id AS permission_id,b.permission_name FROM chart_permission_search_key_word_mapping AS a INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id WHERE a.`from` = ? AND a.classify_id = ? "
  85. _, err = o.Raw(sql, source, classifyId).QueryRows(&list)
  86. return
  87. }
  88. // UpdateChartPermissionNameFromMappingByKeyword 根据关键词及来源更新新关键词
  89. func UpdateChartPermissionNameFromMappingByKeyword(newKeyword string, classifyId int, source string) (err error) {
  90. o := orm.NewOrmUsingDB("rddp")
  91. sql := " UPDATE chart_permission_search_key_word_mapping SET key_word = ? WHERE classify_id = ? AND `from` = ? "
  92. _, err = o.Raw(sql, newKeyword, classifyId, source).Exec()
  93. return
  94. }
  95. // ChartPermissionSearchKeyWordMappingAndPermissionName
  96. // @Description: 分类关联品种
  97. type ChartPermissionSearchKeyWordMappingAndPermissionName struct {
  98. ChartPermissionId int `description:"权限id"`
  99. ChartPermissionName string `description:"权限名称"`
  100. PermissionName string `description:"权限名称"`
  101. KeyWord string `description:"二级分类名称"`
  102. ClassifyId int `description:"分类ID"`
  103. }
  104. // GetPermissionByClassifyId
  105. // @Description: 根据分类id获取关联的报告权限
  106. // @author: Roc
  107. // @datetime 2024-06-19 14:56:44
  108. // @param classifyId int
  109. // @return items []*ChartPermissionSearchKeyWordMappingAndPermissionName
  110. // @return err error
  111. func GetPermissionByClassifyId(classifyId int) (items []*ChartPermissionSearchKeyWordMappingAndPermissionName, err error) {
  112. o := orm.NewOrmUsingDB("rddp")
  113. sql := `SELECT a.chart_permission_name,a.permission_name,b.chart_permission_id,b.key_word,b.classify_id FROM chart_permission AS a
  114. join chart_permission_search_key_word_mapping AS b ON a.chart_permission_id=b.chart_permission_id WHERE b.from='rddp' AND b.classify_id = ? `
  115. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  116. return
  117. }
  118. func GetClassifyIdsByPermissionId(chartPermissionIdList []string) (classifyIds []string, err error) {
  119. o := orm.NewOrmUsingDB("rddp")
  120. sql := `SELECT classify_id
  121. FROM chart_permission_search_key_word_mapping
  122. WHERE chart_permission_id IN (` + utils.GetOrmInReplace(len(chartPermissionIdList)) + `)
  123. GROUP BY classify_id
  124. HAVING COUNT(DISTINCT chart_permission_id) = ` + strconv.Itoa(len(chartPermissionIdList)) + ``
  125. _, err = o.Raw(sql, chartPermissionIdList).QueryRows(&classifyIds)
  126. return
  127. }