permission.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. }
  12. func GetPermission(classifyNameSecond string) (items []*ChartPermissionSearchKeyWordMapping, err error) {
  13. o := orm.NewOrmUsingDB("rddp")
  14. sql := `SELECT * FROM chart_permission_search_key_word_mapping AS a WHERE a.from='rddp' AND a.key_word=? `
  15. _, err = o.Raw(sql, classifyNameSecond).QueryRows(&items)
  16. return
  17. }
  18. func GetAllPermissionMapping() (items []*ChartPermissionSearchKeyWordMapping, err error) {
  19. o := orm.NewOrmUsingDB("rddp")
  20. sql := `SELECT * FROM chart_permission_search_key_word_mapping AS a WHERE a.from='rddp'`
  21. _, err = o.Raw(sql).QueryRows(&items)
  22. return
  23. }
  24. // EditChartPermissionSearchKeyWordMappingMulti 修改报告报告权限(先删除原有的权限,再添加新的权限)
  25. func EditChartPermissionSearchKeyWordMappingMulti(keyword string, permissionIdList []int) (err error) {
  26. o := orm.NewOrmUsingDB("rddp")
  27. to, err := o.Begin()
  28. if err != nil {
  29. return
  30. }
  31. defer func() {
  32. if err != nil {
  33. _ = to.Rollback()
  34. } else {
  35. _ = to.Commit()
  36. }
  37. }()
  38. sql := "delete from chart_permission_search_key_word_mapping WHERE `from`='rddp' AND key_word=? "
  39. _, err = to.Raw(sql, keyword).Exec()
  40. if err != nil {
  41. return
  42. }
  43. if len(permissionIdList) > 0 {
  44. chartPermissionSearchKeyWordMappingList := make([]*ChartPermissionSearchKeyWordMapping, 0)
  45. for _, permissionId := range permissionIdList {
  46. tmpChartPermissionSearchKeyWordMapping := &ChartPermissionSearchKeyWordMapping{
  47. ChartPermissionId: permissionId,
  48. KeyWord: keyword,
  49. From: "rddp",
  50. TacticType: "",
  51. TeleconferenceSort: 0,
  52. }
  53. chartPermissionSearchKeyWordMappingList = append(chartPermissionSearchKeyWordMappingList, tmpChartPermissionSearchKeyWordMapping)
  54. }
  55. _, err = to.InsertMulti(len(chartPermissionSearchKeyWordMappingList), chartPermissionSearchKeyWordMappingList)
  56. }
  57. return
  58. }
  59. func AddChartPermissionChapterMapping(chartPermissionId int, reportId int64) (err error) {
  60. sql := `INSERT INTO chart_permission_chapter_mapping (chart_permission_id, report_chapter_type_id,research_type)
  61. VALUES(?,?,?)`
  62. o := orm.NewOrmUsingDB("rddp")
  63. _, err = o.Raw(sql, chartPermissionId, reportId, "rddp").Exec()
  64. return
  65. }
  66. func RemoveChartPermissionChapterMapping(reportId int64) (err error) {
  67. sql := ` DELETE FROM chart_permission_chapter_mapping WHERE research_type=? AND report_chapter_type_id=? `
  68. o := orm.NewOrmUsingDB("rddp")
  69. _, err = o.Raw(sql, "rddp", reportId).Exec()
  70. return
  71. }
  72. type ChartPermissionMappingIdName struct {
  73. PermissionId int
  74. PermissionName string
  75. }
  76. func GetChartPermissionNameFromMappingByKeyword(keyword string, source string) (list []*ChartPermissionMappingIdName, err error) {
  77. o := orm.NewOrmUsingDB("rddp")
  78. 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.key_word = ? "
  79. _, err = o.Raw(sql, source, keyword).QueryRows(&list)
  80. return
  81. }
  82. // UpdateChartPermissionNameFromMappingByKeyword 根据关键词及来源更新新关键词
  83. func UpdateChartPermissionNameFromMappingByKeyword(newKeyword, keyword, source string) (err error) {
  84. o := orm.NewOrmUsingDB("rddp")
  85. sql := " UPDATE chart_permission_search_key_word_mapping SET key_word = ? WHERE key_word = ? AND `from` = ? "
  86. _, err = o.Raw(sql, newKeyword, keyword, source).Exec()
  87. return
  88. }