edb_info_notice.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package data
  2. import (
  3. "errors"
  4. "eta_gn/eta_task/models/data_manage"
  5. "eta_gn/eta_task/utils"
  6. "fmt"
  7. "time"
  8. )
  9. // 指标更新通知
  10. func RefreshNotice() (err error) {
  11. defer func() {
  12. if err != nil {
  13. fmt.Println("RefreshNotice Err:" + err.Error())
  14. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshNotice ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  15. }
  16. }()
  17. var condition string
  18. var pars []interface{}
  19. endDate := time.Now().AddDate(0, -6, 0)
  20. condition += ` AND end_date > ? `
  21. pars = append(pars, endDate)
  22. items, err := data_manage.GetEdbInfoByCondition(condition, pars, 1)
  23. if err != nil {
  24. return errors.New("GetEdbInfoByCondition:" + err.Error())
  25. }
  26. //日度
  27. dayDiv := `<div style="margin-bottom: 20px;min-width: 1000px;overflow-x: scroll;">
  28. <div>日度指标,超过3天未更新:</div>`
  29. dayTable := `<table border="1" style="border-collapse: collapse;">
  30. <thead>
  31. <tr>
  32. <td>指标编码</td>
  33. <td>指标名称</td>
  34. <td>指标来源</td>
  35. <td>频度</td>
  36. <td>指标数据最后日期</td>
  37. <td>指标数据更新日期</td>
  38. <td>依赖指标</td>
  39. </tr>
  40. </thead>`
  41. dayTableBody := `<tbody>`
  42. //周度
  43. weekDiv := `<div style="margin-bottom: 20px;min-width: 1000px;overflow-x: scroll;"><div>周度指标,超过7天未更新:</div>`
  44. weekTable := `<table border="1" style="border-collapse: collapse;">
  45. <thead>
  46. <tr>
  47. <td>指标编码</td>
  48. <td>指标名称</td>
  49. <td>指标来源</td>
  50. <td>频度</td>
  51. <td>指标数据最后日期</td>
  52. <td>指标数据更新日期</td>
  53. <td>依赖指标</td>
  54. </tr>
  55. </thead>`
  56. weekTableBody := `<tbody>`
  57. monthDiv := `<div style="margin-bottom: 20px;min-width: 1000px;overflow-x: scroll;"><div>月度指标,超过一个月未更新:</div>`
  58. monthTable := `<table border="1" style="border-collapse: collapse;">
  59. <thead>
  60. <tr>
  61. <td>指标编码</td>
  62. <td>指标名称</td>
  63. <td>指标来源</td>
  64. <td>频度</td>
  65. <td>指标数据最后日期</td>
  66. <td>指标数据更新日期</td>
  67. <td>依赖指标</td>
  68. </tr>
  69. </thead>`
  70. monthTableBody := `<tbody>`
  71. allDiv := `<hr style="color: red">`
  72. allDiv = `<div style="margin-bottom: 20px;min-width: 1000px;overflow-x: scroll;"><div>当前所有指标,按数据日期升序排列:</div>`
  73. allTable := `<table border="1" style="border-collapse: collapse;">
  74. <thead>
  75. <tr>
  76. <td>指标编码</td>
  77. <td>指标名称</td>
  78. <td>指标来源</td>
  79. <td>频度</td>
  80. <td>指标数据最后日期</td>
  81. <td>指标数据更新日期</td>
  82. </tr>
  83. </thead>`
  84. allTableBody := `<tbody>`
  85. dayDate := time.Now().AddDate(0, 0, -3)
  86. weekDate := time.Now().AddDate(0, 0, -7)
  87. //月度
  88. monthDate := time.Now().AddDate(0, -1, 0)
  89. for _, v := range items {
  90. if v.Frequency == "日度" && v.EndDate.Before(dayDate) {
  91. dayTableBody += getTableTr(v, 1)
  92. }
  93. if v.Frequency == "周度" && v.EndDate.Before(weekDate) {
  94. weekTableBody += getTableTr(v, 2)
  95. }
  96. if v.Frequency == "月度" && v.EndDate.Before(monthDate) {
  97. monthTableBody += getTableTr(v, 3)
  98. }
  99. allTableBody += getTableTr(v, 4)
  100. }
  101. dayTable += dayTableBody
  102. dayTable += ` </tbody></table></div>`
  103. noticeSendBody := dayDiv + dayTable
  104. noticeSendBody += `<br/>`
  105. weekTable += weekTableBody
  106. weekTable += ` </tbody></table></div>`
  107. noticeSendBody += weekDiv + weekTable
  108. noticeSendBody += `<br/>`
  109. monthTable += monthTableBody
  110. monthTable += ` </tbody></table></div>`
  111. noticeSendBody += monthDiv + monthTable
  112. noticeSendBody += `<br/>`
  113. allTable += allTableBody
  114. allTable += ` </tbody></table></div>`
  115. noticeSendBody += allDiv + allTable
  116. go utils.SendEmailByHongze("指标更新情况通知", noticeSendBody, utils.RefreshEdbInfoEmailSendToUsers, "", "")
  117. //utils.SendEmailByHongze("指标更新情况通知", noticeSendBody, "317699326@qq.com", "", "")
  118. return
  119. }
  120. func getTableTr(item *data_manage.EdbInfoList, tableType int) string {
  121. if item != nil {
  122. trHtml := ` <tr>
  123. <td>` + item.EdbCode + `</td>
  124. <td>` + item.EdbName + `</td>
  125. <td>` + item.SourceName + `</td>
  126. <td>` + item.Frequency + `</td>
  127. <td>` + item.EndDate.Format(utils.FormatDate) + `</td>
  128. <td>` + item.ModifyTime + `</td>`
  129. if item.Source == utils.DATA_SOURCE_CALCULATE ||
  130. item.Source == utils.DATA_SOURCE_CALCULATE_LJZZY ||
  131. item.Source == utils.DATA_SOURCE_CALCULATE_TBZ ||
  132. item.Source == utils.DATA_SOURCE_CALCULATE_TCZ ||
  133. item.Source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS {
  134. //获取依赖指标信息
  135. if tableType != 4 {
  136. //获取依赖指标
  137. mapList, _ := data_manage.GetEdbInfoCalculateMap(item.EdbInfoId, item.Source)
  138. mapStr := ""
  139. for _, v := range mapList {
  140. mapStr += "<p>指标编码:" + v.FromEdbCode + " 来源:" + v.FromSourceName + " 更新日期:" + v.EndDate + "</p>"
  141. }
  142. trHtml += `<td>` + mapStr + `</td>`
  143. }
  144. } else {
  145. if tableType != 4 {
  146. trHtml += `<td></td>`
  147. }
  148. }
  149. trHtml += `</tr>`
  150. return trHtml
  151. } else {
  152. return ""
  153. }
  154. }