report_chapter_grant.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package report
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // ReportChapterGrant
  8. // @Description: 报告章节授权用户表
  9. type ReportChapterGrant struct {
  10. GrantId int `orm:"column(grant_id)"` // 授权id
  11. ReportChapterId int `description:"报告章节id"`
  12. AdminId int `description:"授权的用户id"`
  13. CreateTime time.Time `description:"授权时间"`
  14. }
  15. // MultiAddReportChapterGrantGrant
  16. // @Description: 批量添加报告授权用户
  17. // @author: Roc
  18. // @receiver m
  19. // @datetime 2024-06-04 15:36:02
  20. // @param reportChapterId int
  21. // @param list []*ReportChapterGrant
  22. // @return err error
  23. func (m ReportChapterGrant) MultiAddReportChapterGrantGrant(reportChapterId int, list []*ReportChapterGrant) (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_chapter_grant where report_chapter_id=?"
  37. _, err = to.Raw(sql, reportChapterId).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 reportChapterId int
  57. // @return list []*ReportChapterGrant
  58. // @return err error
  59. func (m ReportChapterGrant) GetGrantListById(reportChapterId int) (list []*ReportChapterGrant, err error) {
  60. o := orm.NewOrmUsingDB("rddp")
  61. sql := `SELECT * FROM report_chapter_grant WHERE report_chapter_id=? `
  62. _, err = o.Raw(sql, reportChapterId).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 reportChapterIdList []int
  71. // @return list []*ReportChapterGrant
  72. // @return err error
  73. func (m ReportChapterGrant) GetGrantListByIdList(reportChapterIdList []int) (list []*ReportChapterGrant, err error) {
  74. num := len(reportChapterIdList)
  75. if num <= 0 {
  76. return
  77. }
  78. o := orm.NewOrmUsingDB("rddp")
  79. sql := `SELECT * FROM report_chapter_grant WHERE report_chapter_id in (` + utils.GetOrmInReplace(num) + `) `
  80. _, err = o.Raw(sql, reportChapterIdList).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 reportChapterId int
  89. // @param sysUserId int
  90. // @return item *ReportGrant
  91. // @return err error
  92. func (m ReportChapterGrant) GetGrantByIdAndAdmin(reportChapterId, sysUserId int) (item *ReportGrant, err error) {
  93. o := orm.NewOrmUsingDB("rddp")
  94. sql := `SELECT * FROM report_chapter_grant WHERE report_chapter_id = ? AND admin_id = ? `
  95. err = o.Raw(sql, reportChapterId, sysUserId).QueryRow(&item)
  96. return
  97. }