report_grant.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package report
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "time"
  6. )
  7. // ReportGrant
  8. // @Description: 报告授权用户表
  9. type ReportGrant struct {
  10. GrantId int `orm:"column(grant_id)"` // 授权id
  11. ReportId int `description:"报告id"`
  12. AdminId int `description:"授权的用户id"`
  13. CreateTime time.Time `description:"授权时间"`
  14. }
  15. // MultiAddReportGrantGrant
  16. // @Description: 批量添加报告授权用户
  17. // @author: Roc
  18. // @receiver m
  19. // @datetime 2024-06-04 15:36:02
  20. // @param reportId int
  21. // @param list []*ReportGrant
  22. // @return err error
  23. func (m ReportGrant) MultiAddReportGrantGrant(reportId int, list []*ReportGrant) (err error) {
  24. o := global.DbMap[utils.DbNameReport]
  25. to := o.Begin()
  26. defer func() {
  27. if err != nil {
  28. _ = to.Rollback()
  29. } else {
  30. _ = to.Commit()
  31. }
  32. }()
  33. sql := "DELETE from report_grant where report_id=?"
  34. err = to.Exec(sql, reportId).Error
  35. if err != nil {
  36. return
  37. }
  38. // 新增授权记录
  39. if len(list) > 0 {
  40. tmpErr := to.CreateInBatches(list, utils.MultiAddNum).Error
  41. if tmpErr != nil {
  42. err = tmpErr
  43. return
  44. }
  45. }
  46. return
  47. }
  48. // GetGrantListById
  49. // @Description: 根据id获取授权列表
  50. // @author: Roc
  51. // @receiver m
  52. // @datetime 2024-06-04 15:33:58
  53. // @param reportId int
  54. // @return list []*ReportGrant
  55. // @return err error
  56. func (m ReportGrant) GetGrantListById(reportId int) (list []*ReportGrant, err error) {
  57. o := global.DbMap[utils.DbNameReport]
  58. sql := `SELECT * FROM report_grant WHERE report_id=? `
  59. err = o.Raw(sql, reportId).Find(&list).Error
  60. return
  61. }
  62. // GetGrantListByIdList
  63. // @Description: 根据id列表获取授权列表
  64. // @author: Roc
  65. // @receiver m
  66. // @datetime 2024-06-04 15:33:58
  67. // @param reportIdList []int
  68. // @return list []*ReportGrant
  69. // @return err error
  70. func (m ReportGrant) GetGrantListByIdList(reportIdList []int) (list []*ReportGrant, err error) {
  71. num := len(reportIdList)
  72. if num <= 0 {
  73. return
  74. }
  75. o := global.DbMap[utils.DbNameReport]
  76. sql := `SELECT * FROM report_grant WHERE report_id in (` + utils.GetOrmInReplace(num) + `) `
  77. err = o.Raw(sql, reportIdList).Find(&list).Error
  78. return
  79. }
  80. // GetGrantByIdAndAdmin
  81. // @Description: 根据reportId和操作人获取报告权限配置
  82. // @author: Roc
  83. // @receiver m
  84. // @datetime 2024-06-04 15:49:59
  85. // @param reportId int
  86. // @param sysUserId int
  87. // @return item *ReportGrant
  88. // @return err error
  89. func (m ReportGrant) GetGrantByIdAndAdmin(reportId, sysUserId int) (item *ReportGrant, err error) {
  90. o := global.DbMap[utils.DbNameReport]
  91. sql := `SELECT * FROM report_grant WHERE report_id = ? AND admin_id = ? `
  92. err = o.Raw(sql, reportId, sysUserId).First(&item).Error
  93. return
  94. }
  95. // GetGrantListByAdminId
  96. // @Description: 根据id获取授权列表
  97. // @author: Roc
  98. // @receiver m
  99. // @datetime 2024-06-04 15:33:58
  100. // @param adminId int
  101. // @return list []*ReportGrant
  102. // @return err error
  103. func (m ReportGrant) GetGrantListByAdminId(adminId int) (list []*ReportGrant, err error) {
  104. o := global.DbMap[utils.DbNameReport]
  105. sql := `SELECT * FROM report_grant WHERE admin_id=? `
  106. err = o.Raw(sql, adminId).Find(&list).Error
  107. return
  108. }