package report import ( "eta/eta_email_analysis/global" "eta/eta_email_analysis/utils" "time" ) // OutsideReport 外部报告 type OutsideReport struct { OutsideReportID int `gorm:"primaryKey;column:outside_report_id" json:"-"` Source uint8 `gorm:"column:source" json:"source"` // 来源,1:ETA系统录入;2:API接口录入;3:邮件监听录入 Title string `gorm:"column:title" json:"title"` // 报告标题 Abstract string `gorm:"column:abstract" json:"abstract"` // 摘要 ClassifyID int `gorm:"column:classify_id" json:"classifyId"` // 所属分类id ClassifyName string `gorm:"column:classify_name" json:"classifyName"` // 所属分类名称(整个分类链条) Content string `gorm:"column:content" json:"content"` // 报告富文本内容 SysUserID int `gorm:"column:sys_user_id" json:"sysUserId"` // 创建人id SysUserName string `gorm:"column:sys_user_name" json:"sysUserName"` // 创建人姓名 EmailMessageUID int `gorm:"column:email_message_uid" json:"emailMessageUid"` // 该邮件在邮箱中的唯一id ReportUpdateTime time.Time `gorm:"column:report_update_time" json:"reportUpdateTime"` // 报告更新时间,如果来源于邮件,那么取邮件的收件时间 ModifyTime time.Time `gorm:"column:modify_time" json:"modifyTime"` // 最近一次修改时间 CreateTime time.Time `gorm:"column:create_time" json:"createTime"` // 创建时间 ReportCode string `gorm:"column:report_code" json:"reportCode"` // 报告唯一编码 } // TableName get sql table name.获取数据库表名 func (m *OutsideReport) TableName() string { return "outside_report" } // OutsideReportColumns get sql column name.获取数据库列名 var OutsideReportColumns = struct { OutsideReportID string Source string Title string Abstract string ClassifyID string ClassifyName string Content string SysUserID string SysUserName string EmailMessageUID string ReportUpdateTime string ModifyTime string CreateTime string ReportCode string }{ OutsideReportID: "outside_report_id", Source: "source", Title: "title", Abstract: "abstract", ClassifyID: "classify_id", ClassifyName: "classify_name", Content: "content", SysUserID: "sys_user_id", SysUserName: "sys_user_name", EmailMessageUID: "email_message_uid", ReportUpdateTime: "report_update_time", ModifyTime: "modify_time", CreateTime: "create_time", ReportCode: "report_code", } // GetOutsideReportByEmailMessageId // @Description: 根据邮件id获取报告 // @author: Roc // @datetime 2024-09-14 17:49:35 // @param emailMessageUid int // @return item *OutsideReport // @return err error func GetOutsideReportByEmailMessageId(emailMessageUid int) (item *OutsideReport, err error) { err = global.DEFAULT_MYSQL.Where("email_message_uid = ?", emailMessageUid).First(&item).Error return } // AddOutsideReport // @Description: 新增报告 // @author: Roc // @datetime 2024-09-14 16:23:32 // @param item *OutsideReport // @return err error func AddOutsideReport(item *OutsideReport) (err error) { err = global.DEFAULT_MYSQL.Create(item).Error return } // CreateOutsideReport // @Description: 新增报告&附件 // @author: Roc // @datetime 2024-09-14 16:23:41 // @param item *OutsideReport // @return err error func CreateOutsideReport(item *OutsideReport, outsideReportAttachmentList []*OutsideReportAttachment) (err error) { db := global.DEFAULT_MYSQL.Begin() defer func() { if err != nil { db.Rollback() } else { db.Commit() } }() // 添加报告 err = global.DEFAULT_MYSQL.Create(item).Error if err != nil { return } // 添加报告附件 for _, v := range outsideReportAttachmentList { v.OutsideReportID = item.OutsideReportID } err = global.DEFAULT_MYSQL.CreateInBatches(outsideReportAttachmentList, utils.BatchSize).Error return } // GetMaxOutsideReportByEmailMessageId // @Description: 获取最大的邮件id // @return maxEmailMessageUid // @return err func GetMaxOutsideReportByEmailMessageId() (maxEmailMessageUid int, err error) { err = global.DEFAULT_MYSQL.Model(OutsideReport{}).Select("max(email_message_uid)").Scan(&maxEmailMessageUid).Error return } // GetNoSysUserNameOutsideReport // @Description: 获取没有用户的信息 // @return items // @return err func GetNoSysUserNameOutsideReport() (items []*OutsideReport, err error) { err = global.DEFAULT_MYSQL.Where("sys_user_name = '' AND source = 3 ").Find(&items).Error return } func (m *OutsideReport) Update(cols []string) (err error) { err = global.DEFAULT_MYSQL.Select(cols).Updates(m).Error return } func GetMailOutsideReport() (items []*OutsideReport, err error) { err = global.DEFAULT_MYSQL.Where("source = 3").Find(&items).Error return } func GetMailOutsideReportHistory() (items []*OutsideReport, err error) { err = global.DEFAULT_MYSQL.Where("source = 3 AND (title LIKE '%海外分公司市场信息月报%' OR title LIKE '%区域市场信息月报%') AND email_message_uid = 0 ").Find(&items).Error return } func GetMailOutsideReportHistory2() (items []*OutsideReport, err error) { err = global.DEFAULT_MYSQL.Where("source = 3 AND classify_id IN (377,378) AND email_message_uid = 0 ").Find(&items).Error return } func GetMailOutsideReportHistory3() (items []*OutsideReport, err error) { err = global.DEFAULT_MYSQL.Where("source = 3 AND classify_id =0 ").Find(&items).Error return }