permission.go 5.6 KB

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