report_grant.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. 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. err = to.Exec(sql, reportId).Error
  38. if err != nil {
  39. return
  40. }
  41. // 新增授权记录
  42. if len(list) > 0 {
  43. //_, tmpErr := to.InsertMulti(len(list), list)
  44. tmpErr := to.CreateInBatches(list, utils.MultiAddNum).Error
  45. if tmpErr != nil {
  46. err = tmpErr
  47. return
  48. }
  49. }
  50. return
  51. }
  52. // DeleteReportGrant 移除授权记录
  53. func DeleteReportGrant(reportId int) (err error) {
  54. //o := orm.NewOrmUsingDB("rddp")
  55. sql := "DELETE from report_grant where report_id=?"
  56. //_, err = o.Raw(sql, reportId).Exec()
  57. err = global.DmSQL["rddp"].Exec(sql, reportId).Error
  58. return
  59. }