outside_report_attachment.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // @Author gmy 2024/9/19 15:13:00
  2. package document_manage_model
  3. import (
  4. "eta/eta_api/global"
  5. "eta/eta_api/utils"
  6. "github.com/beego/beego/v2/client/orm"
  7. "gorm.io/gorm"
  8. )
  9. type OutsideReportAttachment struct {
  10. OutsideReportAttachmentId int `orm:"column(outside_report_attachment_id);pk" gorm:"primaryKey" description:"外部报告附件ID"`
  11. OutsideReportId int `orm:"column(outside_report_id)" description:"报告id"`
  12. Title string `orm:"column(title)" description:"附件名称"`
  13. Url string `orm:"column(url)" description:"附件地址"`
  14. CreateTime string `orm:"column(create_time)" description:"附件新增时间"`
  15. FileSize int64 `orm:"column(file_size)" description:"附件大小"`
  16. }
  17. func (o *OutsideReportAttachment) AfterFind(db *gorm.DB) (err error) {
  18. o.CreateTime = utils.GormDateStrToDateTimeStr(o.CreateTime)
  19. return
  20. }
  21. // 在 init 函数中注册模型
  22. func init() {
  23. orm.RegisterModel(new(OutsideReportAttachment))
  24. }
  25. // SaveOutsideReportAttachment 保存附件
  26. func SaveOutsideReportAttachment(attachment *OutsideReportAttachment) (int64, error) {
  27. o := global.DbMap[utils.DbNameReport]
  28. err := o.Create(attachment).Error
  29. if err != nil {
  30. return 0, err
  31. }
  32. id := int64(attachment.OutsideReportAttachmentId)
  33. return id, err
  34. }
  35. // GetOutsideReportAttachmentListByReportId 根据报告id获取附件列表
  36. func GetOutsideReportAttachmentListByReportId(outsideReportId int) (attachmentList []*OutsideReportAttachment, err error) {
  37. o := global.DbMap[utils.DbNameReport]
  38. sql := "SELECT * FROM outside_report_attachment WHERE outside_report_id = ?"
  39. err = o.Raw(sql, outsideReportId).Find(&attachmentList).Error
  40. return
  41. }
  42. // DeleteReportAttachmentByReportId 根据报告id删除附件
  43. func DeleteReportAttachmentByReportId(outsideReportId int) (err error) {
  44. o := global.DbMap[utils.DbNameReport]
  45. sql := "DELETE FROM outside_report_attachment WHERE outside_report_id = ?"
  46. err = o.Exec(sql, outsideReportId).Error
  47. return
  48. }