report_grant.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package models
  2. import (
  3. "time"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. // ReportGrant Ppt授权表
  7. type ReportGrant struct {
  8. GrantId int64 `orm:"column(grant_id);pk;auto" description:"自增序号"`
  9. ReportId int64 `description:"report ID"`
  10. DepartmentId int64 `description:"授权部门id"`
  11. GrantAdminId int64 `description:"授权部门id"`
  12. CreateTime time.Time `orm:"auto_now_add;type(datetime)" description:"创建时间"`
  13. }
  14. // GetReportGrantInfo 获取已经有权限的report列表
  15. func GetReportGrantInfo(reportId int) (list []*ReportGrant, err error) {
  16. o := orm.NewOrmUsingDB("rddp")
  17. sql := `SELECT * FROM report_grant WHERE report_id=? `
  18. _, err = o.Raw(sql, reportId).QueryRows(&list)
  19. return
  20. }
  21. // MultiAddReportGrant 批量添加授权记录
  22. func MultiAddReportGrant(reportId int, list []*ReportGrant) (err error) {
  23. o := orm.NewOrmUsingDB("rddp")
  24. to, err := o.Begin()
  25. if err != nil {
  26. return
  27. }
  28. defer func() {
  29. if err != nil {
  30. _ = to.Rollback()
  31. } else {
  32. _ = to.Commit()
  33. }
  34. }()
  35. sql := "DELETE from report_grant where report_id=?"
  36. _, err = to.Raw(sql, reportId).Exec()
  37. if err != nil {
  38. return
  39. }
  40. // 新增授权记录
  41. if len(list) > 0 {
  42. _, tmpErr := to.InsertMulti(len(list), list)
  43. if tmpErr != nil {
  44. err = tmpErr
  45. return
  46. }
  47. }
  48. return
  49. }
  50. // DeleteReportGrant 移除授权记录
  51. func DeleteReportGrant(reportId int) (err error) {
  52. o := orm.NewOrmUsingDB("rddp")
  53. sql := "DELETE from report_grant where report_id=?"
  54. _, err = o.Raw(sql, reportId).Exec()
  55. return
  56. }