report_chapter_grant.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package report
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  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 := 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_chapter_grant where report_chapter_id=?"
  34. err = to.Exec(sql, reportChapterId).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 reportChapterId int
  54. // @return list []*ReportChapterGrant
  55. // @return err error
  56. func (m ReportChapterGrant) GetGrantListById(reportChapterId int) (list []*ReportChapterGrant, err error) {
  57. o := global.DbMap[utils.DbNameReport]
  58. sql := `SELECT * FROM report_chapter_grant WHERE report_chapter_id=? `
  59. err = o.Raw(sql, reportChapterId).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 reportChapterIdList []int
  68. // @return list []*ReportChapterGrant
  69. // @return err error
  70. func (m ReportChapterGrant) GetGrantListByIdList(reportChapterIdList []int) (list []*ReportChapterGrant, err error) {
  71. num := len(reportChapterIdList)
  72. if num <= 0 {
  73. return
  74. }
  75. o := global.DbMap[utils.DbNameReport]
  76. sql := `SELECT * FROM report_chapter_grant WHERE report_chapter_id in (` + utils.GetOrmInReplace(num) + `) `
  77. err = o.Raw(sql, reportChapterIdList).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 reportChapterId int
  86. // @param sysUserId int
  87. // @return item *ReportGrant
  88. // @return err error
  89. func (m ReportChapterGrant) GetGrantByIdAndAdmin(reportChapterId, sysUserId int) (item *ReportGrant, err error) {
  90. o := global.DbMap[utils.DbNameReport]
  91. sql := `SELECT * FROM report_chapter_grant WHERE report_chapter_id = ? AND admin_id = ? `
  92. err = o.Raw(sql, reportChapterId, sysUserId).First(&item).Error
  93. return
  94. }