report_chapter_permission_mapping.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package report
  2. import (
  3. "eta/eta_api/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. // GetPermissionListByIdList
  66. // @Description: 根据id列表获取品种权限列表
  67. // @author: Roc
  68. // @receiver m
  69. // @datetime 2024-06-04 15:33:58
  70. // @param reportChapterIdList []int
  71. // @return list []*ReportChapterPermissionMapping
  72. // @return err error
  73. func (m ReportChapterPermissionMapping) GetPermissionListByIdList(reportChapterIdList []int) (list []*ReportChapterPermissionMapping, err error) {
  74. num := len(reportChapterIdList)
  75. if num <= 0 {
  76. return
  77. }
  78. o := orm.NewOrmUsingDB("rddp")
  79. sql := `SELECT * FROM report_chapter_permission_mapping WHERE report_chapter_id in (` + utils.GetOrmInReplace(num) + `) `
  80. _, err = o.Raw(sql, reportChapterIdList).QueryRows(&list)
  81. return
  82. }