permission.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 AddChartPermissionChapterMapping(chartPermissionId int, reportId int64) (err error) {
  19. sql := `INSERT INTO chart_permission_chapter_mapping (chart_permission_id, report_chapter_type_id,research_type)
  20. VALUES(?,?,?)`
  21. o := orm.NewOrmUsingDB("rddp")
  22. _, err = o.Raw(sql, chartPermissionId, reportId, "rddp").Exec()
  23. return
  24. }
  25. func RemoveChartPermissionChapterMapping(reportId int64) (err error) {
  26. sql := ` DELETE FROM chart_permission_chapter_mapping WHERE research_type=? AND report_chapter_type_id=? `
  27. o := orm.NewOrmUsingDB("rddp")
  28. _, err = o.Raw(sql, "rddp", reportId).Exec()
  29. return
  30. }
  31. type ChartPermissionMappingIdName struct {
  32. PermissionId int
  33. PermissionName string
  34. }
  35. func GetChartPermissionNameFromMappingByKeyword(keyword string, source string) (list []*ChartPermissionMappingIdName, err error) {
  36. o := orm.NewOrmUsingDB("rddp")
  37. 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 = ? "
  38. _, err = o.Raw(sql, source, keyword).QueryRows(&list)
  39. return
  40. }