edb_info_notice.go 5.1 KB

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