report_grant.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package report
  2. import (
  3. "eta/eta_mobile/utils"
  4. "github.com/beego/beego/v2/client/orm"
  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 := orm.NewOrmUsingDB("rddp")
  25. to, err := o.Begin()
  26. if err != nil {
  27. return
  28. }
  29. defer func() {
  30. if err != nil {
  31. _ = to.Rollback()
  32. } else {
  33. _ = to.Commit()
  34. }
  35. }()
  36. sql := "DELETE from report_grant where report_id=?"
  37. _, err = to.Raw(sql, reportId).Exec()
  38. if err != nil {
  39. return
  40. }
  41. // 新增授权记录
  42. if len(list) > 0 {
  43. _, tmpErr := to.InsertMulti(500, list)
  44. if tmpErr != nil {
  45. err = tmpErr
  46. return
  47. }
  48. }
  49. return
  50. }
  51. // GetGrantListById
  52. // @Description: 根据id获取授权列表
  53. // @author: Roc
  54. // @receiver m
  55. // @datetime 2024-06-04 15:33:58
  56. // @param reportId int
  57. // @return list []*ReportGrant
  58. // @return err error
  59. func (m ReportGrant) GetGrantListById(reportId int) (list []*ReportGrant, err error) {
  60. o := orm.NewOrmUsingDB("rddp")
  61. sql := `SELECT * FROM report_grant WHERE report_id=? `
  62. _, err = o.Raw(sql, reportId).QueryRows(&list)
  63. return
  64. }
  65. // GetGrantListByIdList
  66. // @Description: 根据id列表获取授权列表
  67. // @author: Roc
  68. // @receiver m
  69. // @datetime 2024-06-04 15:33:58
  70. // @param reportIdList []int
  71. // @return list []*ReportGrant
  72. // @return err error
  73. func (m ReportGrant) GetGrantListByIdList(reportIdList []int) (list []*ReportGrant, err error) {
  74. num := len(reportIdList)
  75. if num <= 0 {
  76. return
  77. }
  78. o := orm.NewOrmUsingDB("rddp")
  79. sql := `SELECT * FROM report_grant WHERE report_id in (` + utils.GetOrmInReplace(num) + `) `
  80. _, err = o.Raw(sql, reportIdList).QueryRows(&list)
  81. return
  82. }
  83. // GetGrantByIdAndAdmin
  84. // @Description: 根据reportId和操作人获取报告权限配置
  85. // @author: Roc
  86. // @receiver m
  87. // @datetime 2024-06-04 15:49:59
  88. // @param reportId int
  89. // @param sysUserId int
  90. // @return item *ReportGrant
  91. // @return err error
  92. func (m ReportGrant) GetGrantByIdAndAdmin(reportId, sysUserId int) (item *ReportGrant, err error) {
  93. o := orm.NewOrmUsingDB("rddp")
  94. sql := `SELECT * FROM report_grant WHERE report_id = ? AND admin_id = ? `
  95. err = o.Raw(sql, reportId, sysUserId).QueryRow(&item)
  96. return
  97. }
  98. // GetGrantListByAdminId
  99. // @Description: 根据id获取授权列表
  100. // @author: Roc
  101. // @receiver m
  102. // @datetime 2024-06-04 15:33:58
  103. // @param adminId int
  104. // @return list []*ReportGrant
  105. // @return err error
  106. func (m ReportGrant) GetGrantListByAdminId(adminId int) (list []*ReportGrant, err error) {
  107. o := orm.NewOrmUsingDB("rddp")
  108. sql := `SELECT * FROM report_grant WHERE admin_id=? `
  109. _, err = o.Raw(sql, adminId).QueryRows(&list)
  110. return
  111. }