outside_report_attachment.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. "gorm.io/gorm"
  7. )
  8. type OutsideReportAttachment struct {
  9. OutsideReportAttachmentId int `orm:"column(outside_report_attachment_id);pk" gorm:"primaryKey" description:"外部报告附件ID"`
  10. OutsideReportId int `orm:"column(outside_report_id)" description:"报告id"`
  11. Title string `orm:"column(title)" description:"附件名称"`
  12. Url string `orm:"column(url)" description:"附件地址"`
  13. CreateTime string `orm:"column(create_time)" description:"附件新增时间"`
  14. FileSize int64 `orm:"column(file_size)" description:"附件大小"`
  15. }
  16. func (o *OutsideReportAttachment) AfterFind(db *gorm.DB) (err error) {
  17. o.CreateTime = utils.GormDateStrToDateTimeStr(o.CreateTime)
  18. return
  19. }
  20. // SaveOutsideReportAttachment 保存附件
  21. func SaveOutsideReportAttachment(attachment *OutsideReportAttachment) (int64, error) {
  22. o := global.DbMap[utils.DbNameReport]
  23. err := o.Create(attachment).Error
  24. if err != nil {
  25. return 0, err
  26. }
  27. id := int64(attachment.OutsideReportAttachmentId)
  28. return id, err
  29. }
  30. // GetOutsideReportAttachmentListByReportId 根据报告id获取附件列表
  31. func GetOutsideReportAttachmentListByReportId(outsideReportId int) (attachmentList []*OutsideReportAttachment, err error) {
  32. o := global.DbMap[utils.DbNameReport]
  33. sql := "SELECT * FROM outside_report_attachment WHERE outside_report_id = ?"
  34. err = o.Raw(sql, outsideReportId).Find(&attachmentList).Error
  35. return
  36. }
  37. // DeleteReportAttachmentByReportId 根据报告id删除附件
  38. func DeleteReportAttachmentByReportId(outsideReportId int) (err error) {
  39. o := global.DbMap[utils.DbNameReport]
  40. sql := "DELETE FROM outside_report_attachment WHERE outside_report_id = ?"
  41. err = o.Exec(sql, outsideReportId).Error
  42. return
  43. }