outside_report_attachment.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. }
  11. // 在 init 函数中注册模型
  12. func init() {
  13. orm.RegisterModel(new(OutsideReportAttachment))
  14. }
  15. // SaveOutsideReportAttachment 保存附件
  16. func SaveOutsideReportAttachment(attachment *OutsideReportAttachment) (int64, error) {
  17. o := orm.NewOrmUsingDB("rddp")
  18. return o.Insert(attachment)
  19. }
  20. // GetOutsideReportAttachmentListByReportId 根据报告id获取附件列表
  21. func GetOutsideReportAttachmentListByReportId(outsideReportId int) ([]*OutsideReportAttachment, error) {
  22. o := orm.NewOrmUsingDB("rddp")
  23. var attachmentList []*OutsideReportAttachment
  24. _, err := o.QueryTable("outside_report_attachment").
  25. Filter("outside_report_id", outsideReportId).
  26. All(&attachmentList)
  27. if err != nil {
  28. return nil, err
  29. }
  30. return attachmentList, nil
  31. }
  32. // DeleteReportAttachmentByReportId 根据报告id删除附件
  33. func DeleteReportAttachmentByReportId(outsideReportId int) error {
  34. o := orm.NewOrmUsingDB("rddp")
  35. _, err := o.QueryTable("outside_report_attachment").
  36. Filter("outside_report_id", outsideReportId).
  37. Delete()
  38. return err
  39. }