package data
import (
"errors"
"eta_gn/eta_task/models/data_manage"
"eta_gn/eta_task/utils"
"fmt"
"time"
)
// 指标更新通知
func RefreshNotice() (err error) {
defer func() {
if err != nil {
fmt.Println("RefreshNotice Err:" + err.Error())
go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshNotice ErrMsg:"+err.Error(), utils.EmailSendToUsers)
}
}()
var condition string
var pars []interface{}
endDate := time.Now().AddDate(0, -6, 0)
condition += ` AND end_date > ? `
pars = append(pars, endDate)
items, err := data_manage.GetEdbInfoByCondition(condition, pars, 1)
if err != nil {
return errors.New("GetEdbInfoByCondition:" + err.Error())
}
//日度
dayDiv := `
日度指标,超过3天未更新:
`
dayTable := `
指标编码 |
指标名称 |
指标来源 |
频度 |
指标数据最后日期 |
指标数据更新日期 |
依赖指标 |
`
dayTableBody := ``
//周度
weekDiv := `周度指标,超过7天未更新:
`
weekTable := `
指标编码 |
指标名称 |
指标来源 |
频度 |
指标数据最后日期 |
指标数据更新日期 |
依赖指标 |
`
weekTableBody := ``
monthDiv := `月度指标,超过一个月未更新:
`
monthTable := `
指标编码 |
指标名称 |
指标来源 |
频度 |
指标数据最后日期 |
指标数据更新日期 |
依赖指标 |
`
monthTableBody := ``
allDiv := `
`
allDiv = `当前所有指标,按数据日期升序排列:
`
allTable := `
指标编码 |
指标名称 |
指标来源 |
频度 |
指标数据最后日期 |
指标数据更新日期 |
`
allTableBody := ``
dayDate := time.Now().AddDate(0, 0, -3)
weekDate := time.Now().AddDate(0, 0, -7)
//月度
monthDate := time.Now().AddDate(0, -1, 0)
for _, v := range items {
if v.Frequency == "日度" && v.EndDate.Before(dayDate) {
dayTableBody += getTableTr(v, 1)
}
if v.Frequency == "周度" && v.EndDate.Before(weekDate) {
weekTableBody += getTableTr(v, 2)
}
if v.Frequency == "月度" && v.EndDate.Before(monthDate) {
monthTableBody += getTableTr(v, 3)
}
allTableBody += getTableTr(v, 4)
}
dayTable += dayTableBody
dayTable += `
`
noticeSendBody := dayDiv + dayTable
noticeSendBody += `
`
weekTable += weekTableBody
weekTable += `
`
noticeSendBody += weekDiv + weekTable
noticeSendBody += `
`
monthTable += monthTableBody
monthTable += `
`
noticeSendBody += monthDiv + monthTable
noticeSendBody += `
`
allTable += allTableBody
allTable += `
`
noticeSendBody += allDiv + allTable
go utils.SendEmailByHongze("指标更新情况通知", noticeSendBody, utils.RefreshEdbInfoEmailSendToUsers, "", "")
//utils.SendEmailByHongze("指标更新情况通知", noticeSendBody, "317699326@qq.com", "", "")
return
}
func getTableTr(item *data_manage.EdbInfoList, tableType int) string {
if item != nil {
trHtml := `
` + item.EdbCode + ` |
` + item.EdbName + ` |
` + item.SourceName + ` |
` + item.Frequency + ` |
` + item.EndDate.Format(utils.FormatDate) + ` |
` + item.ModifyTime + ` | `
if item.Source == utils.DATA_SOURCE_CALCULATE ||
item.Source == utils.DATA_SOURCE_CALCULATE_LJZZY ||
item.Source == utils.DATA_SOURCE_CALCULATE_TBZ ||
item.Source == utils.DATA_SOURCE_CALCULATE_TCZ ||
item.Source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS {
//获取依赖指标信息
if tableType != 4 {
//获取依赖指标
mapList, _ := data_manage.GetEdbInfoCalculateMap(item.EdbInfoId, item.Source)
mapStr := ""
for _, v := range mapList {
mapStr += "指标编码:" + v.FromEdbCode + " 来源:" + v.FromSourceName + " 更新日期:" + v.EndDate + "
"
}
trHtml += `` + mapStr + ` | `
}
} else {
if tableType != 4 {
trHtml += ` | `
}
}
trHtml += `
`
return trHtml
} else {
return ""
}
}