bi_dashboard_grant.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package bi_dashboard
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "time"
  6. )
  7. type BiDashboardGrant struct {
  8. GrantId int `gorm:"primaryKey;autoIncrement;column:grant_id"` // 授权id
  9. BiDashboardId int `gorm:"column:bi_dashboard_id" ` // 看板id
  10. GrantAdminId int `gorm:"column:grant_admin_id"` // 授权的用户id
  11. CreateTime time.Time `gorm:"column:create_time"` // 授权时间
  12. }
  13. // tableName
  14. func (m *BiDashboardGrant) TableName() string {
  15. return "bi_dashboard_grant"
  16. }
  17. // GrantDashboardReq 分配看板权限
  18. type GrantDashboardReq struct {
  19. BiDashboardId int `description:"看板id" `
  20. AdminIdStr string `description:"指定成员id,多个成员用英文,隔开"`
  21. }
  22. // MultiAddDashboardGrant 批量添加授权记录
  23. func MultiAddDashboardGrant(boardId int, list []*BiDashboardGrant) (err error) {
  24. to := global.DEFAULT_DmSQL.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.Exec(sql, boardId).Error
  34. if err != nil {
  35. return
  36. }
  37. // 新增授权记录
  38. if len(list) > 0 {
  39. //_, tmpErr := to.InsertMulti(len(list), list)
  40. tmpErr := to.CreateInBatches(list, utils.MultiAddNum).Error
  41. if tmpErr != nil {
  42. err = tmpErr
  43. return
  44. }
  45. }
  46. return
  47. }
  48. // PublicDashboardReq 设置公共看板权限
  49. type PublicDashboardReq struct {
  50. BiDashboardId int `description:"看板id" `
  51. ClassifyId int `description:"分类id"`
  52. }
  53. // del
  54. func DeleteDashboardGrant(biDashboardId int) (err error) {
  55. return global.DEFAULT_DmSQL.Where("bi_dashboard_id=?", biDashboardId).Delete(&BiDashboardGrant{}).Error
  56. }
  57. // get
  58. func GetDashboardGrantInfo(biDashboardId int) (list []*BiDashboardGrant, err error) {
  59. return list, global.DEFAULT_DmSQL.Where("bi_dashboard_id=?", biDashboardId).Find(&list).Error
  60. }