report_chapter_permission_mapping.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package report
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "time"
  6. )
  7. // ReportChapterPermissionMapping
  8. // @Description: 报告章节的权限关系表
  9. type ReportChapterPermissionMapping struct {
  10. ReportChapterPermissionMappingId int `orm:"column(report_chapter_permission_mapping_id)"`
  11. ReportChapterId int `description:"报告章节的id"` // 报告章节的id
  12. ChartPermissionId int `description:"权限id"` // 权限id
  13. CreateTime time.Time
  14. }
  15. // MultiAddReportChapterPermissionMappingPermission
  16. // @Description: 批量添加报告品种权限用户
  17. // @author: Roc
  18. // @receiver m
  19. // @datetime 2024-06-04 15:36:02
  20. // @param reportChapterId int
  21. // @param list []*ReportChapterPermissionMapping
  22. // @return err error
  23. func (m ReportChapterPermissionMapping) MultiAddReportChapterPermissionMappingPermission(reportChapterId int, list []*ReportChapterPermissionMapping) (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_permission_mapping 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. // GetPermissionListById
  49. // @Description: 根据id获取品种权限列表
  50. // @author: Roc
  51. // @receiver m
  52. // @datetime 2024-06-04 15:33:58
  53. // @param reportChapterId int
  54. // @return list []*ReportChapterPermissionMapping
  55. // @return err error
  56. func (m ReportChapterPermissionMapping) GetPermissionListById(reportChapterId int) (list []*ReportChapterPermissionMapping, err error) {
  57. o := global.DbMap[utils.DbNameReport]
  58. sql := `SELECT * FROM report_chapter_permission_mapping WHERE report_chapter_id=? `
  59. err = o.Raw(sql, reportChapterId).Find(&list).Error
  60. return
  61. }
  62. // ReportChapterPermissionItem
  63. // @Description: 报告章节的权限关系表(带有品种名称)
  64. type ReportChapterPermissionItem struct {
  65. ReportChapterPermissionMappingId int `orm:"column(report_chapter_permission_mapping_id)"`
  66. ReportChapterId int `description:"报告章节的id"`
  67. ChartPermissionId int `description:"权限id"`
  68. ChartPermissionName string `description:"品种名称"`
  69. CreateTime time.Time
  70. }
  71. // GetPermissionItemListById
  72. // @Description: 根据id获取品种权限列表(带有品种名称)
  73. // @author: Roc
  74. // @receiver m
  75. // @datetime 2024-06-04 15:33:58
  76. // @param reportChapterId int
  77. // @return list []*ReportChapterPermissionMapping
  78. // @return err error
  79. func (m ReportChapterPermissionMapping) GetPermissionItemListById(reportChapterId int) (list []*ReportChapterPermissionItem, err error) {
  80. o := global.DbMap[utils.DbNameReport]
  81. sql := `SELECT a.*,b.chart_permission_name FROM report_chapter_permission_mapping AS a
  82. JOIN chart_permission AS b on a.chart_permission_id=b.chart_permission_id WHERE report_chapter_id=? `
  83. err = o.Raw(sql, reportChapterId).Find(&list).Error
  84. return
  85. }
  86. // GetPermissionListByIdList
  87. // @Description: 根据id列表获取品种权限列表
  88. // @author: Roc
  89. // @receiver m
  90. // @datetime 2024-06-04 15:33:58
  91. // @param reportChapterIdList []int
  92. // @return list []*ReportChapterPermissionMapping
  93. // @return err error
  94. func (m ReportChapterPermissionMapping) GetPermissionListByIdList(reportChapterIdList []int) (list []*ReportChapterPermissionMapping, err error) {
  95. num := len(reportChapterIdList)
  96. if num <= 0 {
  97. return
  98. }
  99. o := global.DbMap[utils.DbNameReport]
  100. sql := `SELECT * FROM report_chapter_permission_mapping WHERE report_chapter_id in (` + utils.GetOrmInReplace(num) + `) `
  101. err = o.Raw(sql, reportChapterIdList).Find(&list).Error
  102. return
  103. }
  104. // MultiAdd
  105. // @Description: 批量添加
  106. // @author: Roc
  107. // @receiver m
  108. // @datetime 2024-06-20 18:04:33
  109. // @param list []*ReportChapterPermissionMapping
  110. // @return err error
  111. func (m ReportChapterPermissionMapping) MultiAdd(list []*ReportChapterPermissionMapping) (err error) {
  112. o := global.DbMap[utils.DbNameReport]
  113. to := o.Begin()
  114. defer func() {
  115. if err != nil {
  116. _ = to.Rollback()
  117. } else {
  118. _ = to.Commit()
  119. }
  120. }()
  121. // 新增品种权限记录
  122. if len(list) > 0 {
  123. err = to.CreateInBatches(list, utils.MultiAddNum).Error
  124. if err != nil {
  125. return
  126. }
  127. }
  128. return
  129. }