report_ppt_img.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "time"
  6. )
  7. // ReportPptImg Ppt转报告的图片记录表
  8. type ReportPptImg struct {
  9. ReportPptImgId int `gorm:"column:report_ppt_img_id" json:"report_ppt_img_id"` //`orm:"column(report_ppt_img_id);pk;auto" description:"自增id"`
  10. PptId int `gorm:"column:ppt_id"` //`description:"ppt的id"`
  11. ReportId int `gorm:"column:report_id"` //`description:"关联的报告ID"`
  12. ReportChapterId int `gorm:"column:report_chapter_id"` //`description:"关联的报告章节ID"`
  13. ImgUrl string `gorm:"column:img_url"` // `description:"ppt图片地址"`
  14. CreateTime time.Time `gorm:"column:create_time"` //`description:"创建时间"`
  15. }
  16. // AddAndEditMultiReportPptImg 批量添加Ppt转报告的图片记录
  17. func AddAndEditMultiReportPptImg(pptId int, reportPptImgList []*ReportPptImg) (err error) {
  18. if len(reportPptImgList) < 0 {
  19. return
  20. }
  21. //o := orm.NewOrmUsingDB("rddp")
  22. //
  23. //to, err := o.Begin()
  24. to := global.DmSQL["rddp"].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_ppt_img WHERE ppt_id = ?`
  36. //_, err = to.Raw(sql, pptId).Exec()
  37. err = to.Exec(sql, pptId).Error
  38. if err != nil {
  39. return
  40. }
  41. //_, err = to.InsertMulti(len(reportPptImgList), reportPptImgList)
  42. err = to.CreateInBatches(reportPptImgList, utils.MultiAddNum).Error
  43. return
  44. }