// @Author gmy 2024/9/19 15:13:00 package models import "github.com/beego/beego/v2/client/orm" type OutsideReportAttachment struct { OutsideReportAttachmentId int `orm:"column(outside_report_attachment_id);pk" description:"外部报告附件ID"` OutsideReportId int `orm:"column(outside_report_id)" description:"报告id"` Title string `orm:"column(title)" description:"附件名称"` Url string `orm:"column(url)" description:"附件地址"` CreateTime string `orm:"column(create_time)" description:"附件新增时间"` FileSize int64 `orm:"column(file_size)" description:"附件大小"` } // 在 init 函数中注册模型 func init() { orm.RegisterModel(new(OutsideReportAttachment)) } // GetOutsideReportAttachmentListByReportId 根据报告id获取附件列表 func GetOutsideReportAttachmentListByReportId(outsideReportId int) (attachmentList []*OutsideReportAttachment, err error) { o := orm.NewOrm() // 改写成通过ql查询 sql := `select * from outside_report_attachment where outside_report_id = ?` _, err = o.Raw(sql, outsideReportId).QueryRows(&attachmentList) if err != nil { return nil, err } return attachmentList, nil }