bi_dashboard_grant.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. func (m *BiDashboardGrant) TableName() string {
  14. return "bi_dashboard_grant"
  15. }
  16. type GrantDashboardReq struct {
  17. BiDashboardId int `description:"看板id" `
  18. AdminIdStr string `description:"指定成员id,多个成员用英文,隔开"`
  19. }
  20. func MultiAddDashboardGrant(boardId int, list []*BiDashboardGrant) (err error) {
  21. to := global.DEFAULT_DmSQL.Begin()
  22. defer func() {
  23. if err != nil {
  24. _ = to.Rollback()
  25. } else {
  26. _ = to.Commit()
  27. }
  28. }()
  29. sql := "DELETE from bi_dashboard_grant where bi_dashboard_id=?"
  30. err = to.Exec(sql, boardId).Error
  31. if err != nil {
  32. return
  33. }
  34. if len(list) > 0 {
  35. tmpErr := to.CreateInBatches(list, utils.MultiAddNum).Error
  36. if tmpErr != nil {
  37. err = tmpErr
  38. return
  39. }
  40. }
  41. return
  42. }
  43. type PublicDashboardReq struct {
  44. BiDashboardId int `description:"看板id" `
  45. ClassifyId int `description:"分类id"`
  46. }
  47. func DeleteDashboardGrant(biDashboardId int) (err error) {
  48. return global.DEFAULT_DmSQL.Where("bi_dashboard_id=?", biDashboardId).Delete(&BiDashboardGrant{}).Error
  49. }
  50. func GetDashboardGrantInfo(biDashboardId int) (list []*BiDashboardGrant, err error) {
  51. return list, global.DEFAULT_DmSQL.Where("bi_dashboard_id=?", biDashboardId).Find(&list).Error
  52. }