outside_report_attachment.go 1.7 KB

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