report_grant.go 1.9 KB

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