123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- 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 := `<div style="margin-bottom: 20px;min-width: 1000px;overflow-x: scroll;">
- <div>日度指标,超过3天未更新:</div>`
- dayTable := `<table border="1" style="border-collapse: collapse;">
- <thead>
- <tr>
- <td>指标编码</td>
- <td>指标名称</td>
- <td>指标来源</td>
- <td>频度</td>
- <td>指标数据最后日期</td>
- <td>指标数据更新日期</td>
- <td>依赖指标</td>
- </tr>
- </thead>`
- dayTableBody := `<tbody>`
- //周度
- weekDiv := `<div style="margin-bottom: 20px;min-width: 1000px;overflow-x: scroll;"><div>周度指标,超过7天未更新:</div>`
- weekTable := `<table border="1" style="border-collapse: collapse;">
- <thead>
- <tr>
- <td>指标编码</td>
- <td>指标名称</td>
- <td>指标来源</td>
- <td>频度</td>
- <td>指标数据最后日期</td>
- <td>指标数据更新日期</td>
- <td>依赖指标</td>
- </tr>
- </thead>`
- weekTableBody := `<tbody>`
- monthDiv := `<div style="margin-bottom: 20px;min-width: 1000px;overflow-x: scroll;"><div>月度指标,超过一个月未更新:</div>`
- monthTable := `<table border="1" style="border-collapse: collapse;">
- <thead>
- <tr>
- <td>指标编码</td>
- <td>指标名称</td>
- <td>指标来源</td>
- <td>频度</td>
- <td>指标数据最后日期</td>
- <td>指标数据更新日期</td>
- <td>依赖指标</td>
- </tr>
- </thead>`
- monthTableBody := `<tbody>`
- allDiv := `<hr style="color: red">`
- allDiv = `<div style="margin-bottom: 20px;min-width: 1000px;overflow-x: scroll;"><div>当前所有指标,按数据日期升序排列:</div>`
- allTable := `<table border="1" style="border-collapse: collapse;">
- <thead>
- <tr>
- <td>指标编码</td>
- <td>指标名称</td>
- <td>指标来源</td>
- <td>频度</td>
- <td>指标数据最后日期</td>
- <td>指标数据更新日期</td>
- </tr>
- </thead>`
- allTableBody := `<tbody>`
- 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 += ` </tbody></table></div>`
- noticeSendBody := dayDiv + dayTable
- noticeSendBody += `<br/>`
- weekTable += weekTableBody
- weekTable += ` </tbody></table></div>`
- noticeSendBody += weekDiv + weekTable
- noticeSendBody += `<br/>`
- monthTable += monthTableBody
- monthTable += ` </tbody></table></div>`
- noticeSendBody += monthDiv + monthTable
- noticeSendBody += `<br/>`
- allTable += allTableBody
- allTable += ` </tbody></table></div>`
- 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 := ` <tr>
- <td>` + item.EdbCode + `</td>
- <td>` + item.EdbName + `</td>
- <td>` + item.SourceName + `</td>
- <td>` + item.Frequency + `</td>
- <td>` + item.EndDate.Format(utils.FormatDate) + `</td>
- <td>` + item.ModifyTime + `</td>`
- 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 += "<p>指标编码:" + v.FromEdbCode + " 来源:" + v.FromSourceName + " 更新日期:" + v.EndDate + "</p>"
- }
- trHtml += `<td>` + mapStr + `</td>`
- }
- } else {
- if tableType != 4 {
- trHtml += `<td></td>`
- }
- }
- trHtml += `</tr>`
- return trHtml
- } else {
- return ""
- }
- }
|