permission.go 3.6 KB

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