report_chapter_permission_mapping.go 4.4 KB

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