permission.go 5.2 KB

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