outside_report_attachment.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // @Author gmy 2024/9/19 15:13:00
  2. package document_manage_model
  3. import (
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. type OutsideReportAttachment struct {
  7. OutsideReportAttachmentId int `orm:"column(outside_report_attachment_id);pk" description:"外部报告附件ID"`
  8. OutsideReportId int `orm:"column(outside_report_id)" description:"报告id"`
  9. Title string `orm:"column(title)" description:"附件名称"`
  10. Url string `orm:"column(url)" description:"附件地址"`
  11. CreateTime string `orm:"column(create_time)" description:"附件新增时间"`
  12. FileSize int64 `orm:"column(file_size)" description:"附件大小"`
  13. }
  14. // 在 init 函数中注册模型
  15. func init() {
  16. orm.RegisterModel(new(OutsideReportAttachment))
  17. }
  18. // SaveOutsideReportAttachment 保存附件
  19. func SaveOutsideReportAttachment(attachment *OutsideReportAttachment) (int64, error) {
  20. o := orm.NewOrmUsingDB("rddp")
  21. return o.Insert(attachment)
  22. }
  23. // GetOutsideReportAttachmentListByReportId 根据报告id获取附件列表
  24. func GetOutsideReportAttachmentListByReportId(outsideReportId int) ([]*OutsideReportAttachment, error) {
  25. o := orm.NewOrmUsingDB("rddp")
  26. var attachmentList []*OutsideReportAttachment
  27. _, err := o.QueryTable("outside_report_attachment").
  28. Filter("outside_report_id", outsideReportId).
  29. All(&attachmentList)
  30. if err != nil {
  31. return nil, err
  32. }
  33. return attachmentList, nil
  34. }
  35. // DeleteReportAttachmentByReportId 根据报告id删除附件
  36. func DeleteReportAttachmentByReportId(outsideReportId int) error {
  37. o := orm.NewOrmUsingDB("rddp")
  38. _, err := o.QueryTable("outside_report_attachment").
  39. Filter("outside_report_id", outsideReportId).
  40. Delete()
  41. return err
  42. }