outside_report.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package report
  2. import (
  3. "eta/eta_email_analysis/global"
  4. "eta/eta_email_analysis/utils"
  5. "time"
  6. )
  7. // OutsideReport 外部报告
  8. type OutsideReport struct {
  9. OutsideReportID int `gorm:"primaryKey;column:outside_report_id" json:"-"`
  10. Source uint8 `gorm:"column:source" json:"source"` // 来源,1:ETA系统录入;2:API接口录入;3:邮件监听录入
  11. Title string `gorm:"column:title" json:"title"` // 报告标题
  12. Abstract string `gorm:"column:abstract" json:"abstract"` // 摘要
  13. ClassifyID int `gorm:"column:classify_id" json:"classifyId"` // 所属分类id
  14. ClassifyName string `gorm:"column:classify_name" json:"classifyName"` // 所属分类名称(整个分类链条)
  15. Content string `gorm:"column:content" json:"content"` // 报告富文本内容
  16. SysUserID int `gorm:"column:sys_user_id" json:"sysUserId"` // 创建人id
  17. SysUserName string `gorm:"column:sys_user_name" json:"sysUserName"` // 创建人姓名
  18. EmailMessageUID int `gorm:"column:email_message_uid" json:"emailMessageUid"` // 该邮件在邮箱中的唯一id
  19. ReportUpdateTime time.Time `gorm:"column:report_update_time" json:"reportUpdateTime"` // 报告更新时间,如果来源于邮件,那么取邮件的收件时间
  20. ModifyTime time.Time `gorm:"column:modify_time" json:"modifyTime"` // 最近一次修改时间
  21. CreateTime time.Time `gorm:"column:create_time" json:"createTime"` // 创建时间
  22. ReportCode string `gorm:"column:report_code" json:"reportCode"` // 报告唯一编码
  23. }
  24. // TableName get sql table name.获取数据库表名
  25. func (m *OutsideReport) TableName() string {
  26. return "outside_report"
  27. }
  28. // OutsideReportColumns get sql column name.获取数据库列名
  29. var OutsideReportColumns = struct {
  30. OutsideReportID string
  31. Source string
  32. Title string
  33. Abstract string
  34. ClassifyID string
  35. ClassifyName string
  36. Content string
  37. SysUserID string
  38. SysUserName string
  39. EmailMessageUID string
  40. ReportUpdateTime string
  41. ModifyTime string
  42. CreateTime string
  43. ReportCode string
  44. }{
  45. OutsideReportID: "outside_report_id",
  46. Source: "source",
  47. Title: "title",
  48. Abstract: "abstract",
  49. ClassifyID: "classify_id",
  50. ClassifyName: "classify_name",
  51. Content: "content",
  52. SysUserID: "sys_user_id",
  53. SysUserName: "sys_user_name",
  54. EmailMessageUID: "email_message_uid",
  55. ReportUpdateTime: "report_update_time",
  56. ModifyTime: "modify_time",
  57. CreateTime: "create_time",
  58. ReportCode: "report_code",
  59. }
  60. // GetOutsideReportByEmailMessageId
  61. // @Description: 根据邮件id获取报告
  62. // @author: Roc
  63. // @datetime 2024-09-14 17:49:35
  64. // @param emailMessageUid int
  65. // @return item *OutsideReport
  66. // @return err error
  67. func GetOutsideReportByEmailMessageId(emailMessageUid int) (item *OutsideReport, err error) {
  68. err = global.DEFAULT_MYSQL.Where("email_message_uid = ?", emailMessageUid).First(&item).Error
  69. return
  70. }
  71. // AddOutsideReport
  72. // @Description: 新增报告
  73. // @author: Roc
  74. // @datetime 2024-09-14 16:23:32
  75. // @param item *OutsideReport
  76. // @return err error
  77. func AddOutsideReport(item *OutsideReport) (err error) {
  78. err = global.DEFAULT_MYSQL.Create(item).Error
  79. return
  80. }
  81. // CreateOutsideReport
  82. // @Description: 新增报告&附件
  83. // @author: Roc
  84. // @datetime 2024-09-14 16:23:41
  85. // @param item *OutsideReport
  86. // @return err error
  87. func CreateOutsideReport(item *OutsideReport, outsideReportAttachmentList []*OutsideReportAttachment) (err error) {
  88. db := global.DEFAULT_MYSQL.Begin()
  89. defer func() {
  90. if err != nil {
  91. db.Rollback()
  92. } else {
  93. db.Commit()
  94. }
  95. }()
  96. // 添加报告
  97. err = global.DEFAULT_MYSQL.Create(item).Error
  98. if err != nil {
  99. return
  100. }
  101. // 添加报告附件
  102. for _, v := range outsideReportAttachmentList {
  103. v.OutsideReportID = item.OutsideReportID
  104. }
  105. err = global.DEFAULT_MYSQL.CreateInBatches(outsideReportAttachmentList, utils.BatchSize).Error
  106. return
  107. }
  108. // GetMaxOutsideReportByEmailMessageId
  109. // @Description: 获取最大的邮件id
  110. // @return maxEmailMessageUid
  111. // @return err
  112. func GetMaxOutsideReportByEmailMessageId() (maxEmailMessageUid int, err error) {
  113. err = global.DEFAULT_MYSQL.Model(OutsideReport{}).Select("max(email_message_uid)").Scan(&maxEmailMessageUid).Error
  114. return
  115. }
  116. // GetNoSysUserNameOutsideReport
  117. // @Description: 获取没有用户的信息
  118. // @return items
  119. // @return err
  120. func GetNoSysUserNameOutsideReport() (items []*OutsideReport, err error) {
  121. err = global.DEFAULT_MYSQL.Where("sys_user_name = '' AND source = 3 ").Find(&items).Error
  122. return
  123. }
  124. func (m *OutsideReport) Update(cols []string) (err error) {
  125. err = global.DEFAULT_MYSQL.Select(cols).Updates(m).Error
  126. return
  127. }
  128. func GetMailOutsideReport() (items []*OutsideReport, err error) {
  129. err = global.DEFAULT_MYSQL.Where("source = 3").Find(&items).Error
  130. return
  131. }
  132. func GetMailOutsideReportHistory() (items []*OutsideReport, err error) {
  133. err = global.DEFAULT_MYSQL.Where("source = 3 AND (title LIKE '%海外分公司市场信息月报%' OR title LIKE '%区域市场信息月报%') AND email_message_uid = 0 ").Find(&items).Error
  134. return
  135. }
  136. func GetMailOutsideReportHistory2() (items []*OutsideReport, err error) {
  137. err = global.DEFAULT_MYSQL.Where("source = 3 AND classify_id IN (377,378) AND email_message_uid = 0 ").Find(&items).Error
  138. return
  139. }
  140. func GetMailOutsideReportHistory3() (items []*OutsideReport, err error) {
  141. err = global.DEFAULT_MYSQL.Where("source = 3 AND classify_id =0 ").Find(&items).Error
  142. return
  143. }