report_chapter_grant.go 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package report
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "time"
  6. )
  7. type ReportChapterGrant struct {
  8. GrantId int `gorm:"primaryKey;column:grant_id;type:int(9) unsigned;not null"` // 授权id
  9. ReportChapterId int `gorm:"index:idx_report_chapterid;column:report_chapter_id;type:int(9) unsigned;not null;default:0"` // 报告章节id
  10. AdminId int `gorm:"column:admin_id;type:int(9) unsigned;default:0"` // 授权的用户id
  11. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP"` // 授权时间
  12. }
  13. // MultiAddReportChapterGrantGrant
  14. // @Description: 批量添加报告授权用户
  15. // @author: Roc
  16. // @receiver m
  17. // @datetime 2024-06-04 15:36:02
  18. // @param reportChapterId int
  19. // @param list []*ReportChapterGrant
  20. // @return err error
  21. func (m ReportChapterGrant) MultiAddReportChapterGrantGrant(reportChapterId int, list []*ReportChapterGrant) (err error) {
  22. tx := global.DmSQL["rddp"].Begin()
  23. defer func() {
  24. if err != nil {
  25. _ = tx.Rollback()
  26. return
  27. }
  28. _ = tx.Commit()
  29. }()
  30. sql := "DELETE from report_chapter_grant where report_chapter_id=?"
  31. err = tx.Exec(sql, reportChapterId).Error
  32. if err != nil {
  33. return
  34. }
  35. // 新增授权记录
  36. if len(list) > 0 {
  37. e := tx.CreateInBatches(list, utils.MultiAddNum).Error
  38. if e != nil {
  39. err = e
  40. return
  41. }
  42. }
  43. return
  44. }
  45. // GetGrantListById
  46. // @Description: 根据id获取授权列表
  47. // @author: Roc
  48. // @receiver m
  49. // @datetime 2024-06-04 15:33:58
  50. // @param reportChapterId int
  51. // @return list []*ReportChapterGrant
  52. // @return err error
  53. func (m ReportChapterGrant) GetGrantListById(reportChapterId int) (list []*ReportChapterGrant, err error) {
  54. sql := `SELECT * FROM report_chapter_grant WHERE report_chapter_id=? `
  55. err = global.DmSQL["rddp"].Raw(sql, reportChapterId).Find(&list).Error
  56. return
  57. }
  58. // GetGrantListByIdList
  59. // @Description: 根据id列表获取授权列表
  60. // @author: Roc
  61. // @receiver m
  62. // @datetime 2024-06-04 15:33:58
  63. // @param reportChapterIdList []int
  64. // @return list []*ReportChapterGrant
  65. // @return err error
  66. func (m ReportChapterGrant) GetGrantListByIdList(reportChapterIdList []int) (list []*ReportChapterGrant, err error) {
  67. num := len(reportChapterIdList)
  68. if num <= 0 {
  69. return
  70. }
  71. sql := `SELECT * FROM report_chapter_grant WHERE report_chapter_id in (` + utils.GetOrmInReplace(num) + `) `
  72. err = global.DmSQL["rddp"].Raw(sql, reportChapterIdList).Find(&list).Error
  73. return
  74. }
  75. // GetGrantByIdAndAdmin
  76. // @Description: 根据reportId和操作人获取报告章节权限配置
  77. // @author: Roc
  78. // @receiver m
  79. // @datetime 2024-06-04 15:49:59
  80. // @param reportChapterId int
  81. // @param sysUserId int
  82. // @return item *ReportGrant
  83. // @return err error
  84. func (m ReportChapterGrant) GetGrantByIdAndAdmin(reportChapterId, sysUserId int) (item *ReportGrant, err error) {
  85. sql := `SELECT * FROM report_chapter_grant WHERE report_chapter_id = ? AND admin_id = ? `
  86. err = global.DmSQL["rddp"].Raw(sql, reportChapterId, sysUserId).First(&item).Error
  87. return
  88. }