bi_dashboard_grant.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package bi_dashboard
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type BiDashboardGrant struct {
  7. GrantId int `orm:"column(grant_id);pk"` // 授权id
  8. BiDashboardId int `gorm:"column:bi_dashboard_id" ` // 看板id
  9. GrantAdminId int `gorm:"column:grant_admin_id"` // 授权的用户id
  10. CreateTime time.Time `gorm:"column:create_time"` // 授权时间
  11. }
  12. // tableName
  13. func (m *BiDashboardGrant) TableName() string {
  14. return "bi_dashboard_grant"
  15. }
  16. // GrantDashboardReq 分配看板权限
  17. type GrantDashboardReq struct {
  18. BiDashboardId int `description:"看板id" `
  19. AdminIdStr string `description:"指定成员id,多个成员用英文,隔开"`
  20. }
  21. // MultiAddDashboardGrant 批量添加授权记录
  22. func MultiAddDashboardGrant(boardId int, list []*BiDashboardGrant) (err error) {
  23. o := orm.NewOrm()
  24. to, err := o.Begin()
  25. defer func() {
  26. if err != nil {
  27. _ = to.Rollback()
  28. } else {
  29. _ = to.Commit()
  30. }
  31. }()
  32. sql := "DELETE from bi_dashboard_grant where bi_dashboard_id=?"
  33. _, err = to.Raw(sql, boardId).Exec()
  34. if err != nil {
  35. return
  36. }
  37. // 新增授权记录
  38. if len(list) > 0 {
  39. _, tmpErr := to.InsertMulti(len(list), list)
  40. if tmpErr != nil {
  41. err = tmpErr
  42. return
  43. }
  44. }
  45. return
  46. }
  47. // PublicDashboardReq 设置公共看板权限
  48. type PublicDashboardReq struct {
  49. BiDashboardId int `description:"看板id" `
  50. }
  51. // del
  52. func DeleteDashboardGrant(biDashboardId int) (err error) {
  53. //return global.DEFAULT_DmSQL.Where("bi_dashboard_id=?", biDashboardId).Delete(&BiDashboardGrant{}).Error
  54. o := orm.NewOrm()
  55. _, err = o.Raw("DELETE from bi_dashboard_grant where bi_dashboard_id=?", biDashboardId).Exec()
  56. return
  57. }
  58. // get
  59. func GetDashboardGrantInfo(biDashboardId int) (list []*BiDashboardGrant, err error) {
  60. //return list, global.DEFAULT_DmSQL.Where("bi_dashboard_id=?", biDashboardId).Find(&list).Error
  61. o := orm.NewOrm()
  62. _, err = o.Raw("SELECT * FROM bi_dashboard_grant where bi_dashboard_id=?", biDashboardId).QueryRows(&list)
  63. return
  64. }