|
@@ -22,6 +22,7 @@ import (
|
|
|
|
|
|
// 同步用户锁,防止重复同步,不管是全量还是增量,都是同一时间只能一个同步
|
|
|
var lockListenEmail sync.Mutex
|
|
|
+
|
|
|
// 邮件改名规则
|
|
|
var ruleList []report.MailRule
|
|
|
|
|
@@ -66,12 +67,26 @@ func ListenMail() {
|
|
|
emailMessageUID := global.CONFIG.Email.StartReadIndex
|
|
|
if emailMessageUID <= 0 {
|
|
|
emailMessageUID, err = report.GetMaxOutsideReportByEmailMessageId()
|
|
|
- // 已经存在了,那么就返回
|
|
|
+ // 查找失败了,那么就记录
|
|
|
if err != nil {
|
|
|
global.FILE_LOG.Errorf("获取已入库的最大邮件id失败:%s", err.Error())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ {
|
|
|
+ idList, err := report.GetAllOutsideReportByEmailMessageId()
|
|
|
+ // 已经存在了,那么就返回
|
|
|
+ if err != nil {
|
|
|
+ global.FILE_LOG.Errorf("获取已入库的所有邮件id失败:%s", err.Error())
|
|
|
+ } else {
|
|
|
+ idMap := make(map[int]bool)
|
|
|
+ for _, v := range idList {
|
|
|
+ idMap[v] = true
|
|
|
+ }
|
|
|
+ mail.IsHandleMessageIdMap = idMap
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
mailAddress := fmt.Sprintf("%s:%d", global.CONFIG.Email.Host, global.CONFIG.Email.Port)
|
|
|
mail.ListenMail(mailAddress, global.CONFIG.Email.Folder, global.CONFIG.Email.UserName, global.CONFIG.Email.Password, global.CONFIG.Email.ReadBatchSize, emailMessageUID, mailMessageChan, mailMessageDoneChan)
|
|
|
|
|
@@ -134,7 +149,7 @@ func handleMailMessage(emailMessage mail.MailMessage) (err error) {
|
|
|
global.FILE_LOG.Errorf("更新收件时间失败:%s", err.Error())
|
|
|
return
|
|
|
}
|
|
|
- global.FILE_LOG.Debugf( "更新收件时间,名称:%s, 原时间:%s, 新收件时间: %s", outReport.Title, outReport.ReportUpdateTime, emailMessage.Date)
|
|
|
+ global.FILE_LOG.Debugf("更新收件时间,名称:%s, 原时间:%s, 新收件时间: %s", outReport.Title, outReport.ReportUpdateTime, emailMessage.Date)
|
|
|
}
|
|
|
global.FILE_LOG.Debugf("已存在,就不处理了,报告标题:%s;;邮件下标:%d", outReport.Title, emailMessage.Uid)
|
|
|
return
|
|
@@ -195,30 +210,33 @@ func handleMailMessage(emailMessage mail.MailMessage) (err error) {
|
|
|
classifyName = classify.ClassifyName
|
|
|
|
|
|
// 特殊规则
|
|
|
- if strings.Contains(title, "海外分公司市场信息月报") || strings.Contains(title, "区域市场信息月报"){
|
|
|
- if emailMessage.From == "report.pcanalyst00@petrochina-usa.com" {
|
|
|
- sysUserName = "PCI"
|
|
|
- break
|
|
|
- } else {
|
|
|
- v.Author = emailMessage.From
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if strings.Contains(v.Author, "@") {
|
|
|
- sysUser, tmpErr := eta.GetSysUserByEmail(v.Author)
|
|
|
- if tmpErr != nil && !utils.IsErrNoRow(tmpErr) {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
- if sysUser.AdminId > 0 {
|
|
|
- sysUserId = sysUser.AdminId
|
|
|
- sysUserName = sysUser.RealName
|
|
|
+ //if strings.Contains(title, "海外分公司市场信息月报") || strings.Contains(title, "区域市场信息月报") {
|
|
|
+ // if emailMessage.From == "report.pcanalyst00@petrochina-usa.com" {
|
|
|
+ // sysUserName = "PCI"
|
|
|
+ // break
|
|
|
+ // } else {
|
|
|
+ // v.Author = emailMessage.From
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ if v.Author != `` {
|
|
|
+ if strings.Contains(v.Author, "@") {
|
|
|
+ sysUser, tmpErr := eta.GetSysUserByEmail(v.Author)
|
|
|
+ if tmpErr != nil && !utils.IsErrNoRow(tmpErr) {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if sysUser.AdminId > 0 {
|
|
|
+ sysUserId = sysUser.AdminId
|
|
|
+ sysUserName = sysUser.RealName
|
|
|
+ } else {
|
|
|
+ sysUserName = v.Author
|
|
|
+ }
|
|
|
} else {
|
|
|
sysUserName = v.Author
|
|
|
}
|
|
|
- } else {
|
|
|
- sysUserName = v.Author
|
|
|
}
|
|
|
+
|
|
|
break
|
|
|
}
|
|
|
}
|