Sfoglia il codice sorgente

更新日报格式

wcc 1 anno fa
parent
commit
5720762cb7
1 ha cambiato i file con 30 aggiunte e 9 eliminazioni
  1. 30 9
      escheck/main.go

+ 30 - 9
escheck/main.go

@@ -12,7 +12,6 @@ import (
 	"jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
 	"log"
 	"net/http"
-	"strconv"
 	"strings"
 	"time"
 )
@@ -153,7 +152,7 @@ func (t *T) task() {
 			t.SendMail(report)
 		}
 	case "report":
-		report = fmt.Sprintf("统计报告%s,【统计结果】,es库数量:%d", t.Name, count)
+		//report = fmt.Sprintf("统计报告%s,【统计结果】,es库数量:%d", t.Name, count)
 		if len(t.Mgo) > 5 {
 			fs := strings.Split(t.Mgo, "|")
 			fmgo := mongodb.NewMgoWithUser(fs[0], fs[3], fs[1], fs[2], 1)
@@ -312,13 +311,31 @@ func (t *T) task() {
 			if noFileCount > 0 {
 				no_file_avgltime = no_file_totaltime / int64(noFileCount)
 			}
-			report += `,mgo统计:` + fmt.Sprint(count3) + `,差值:` + fmt.Sprint(count3-count) + `,mgo总入库量:` + fmt.Sprint(count2) +
-				`<br>竟品统计结果_es统计:` + strconv.Itoa(count1) + `,mgo统计:` + fmt.Sprint(count5) + `,差值:` + fmt.Sprint(count5-count1) + `,mgo总入库量` + fmt.Sprint(count4) +
-				`<br>元博网_es统计:` + strconv.Itoa(countComptet1) + `,mgo统计:` + fmt.Sprint(competeReal1) + `,差值:` + fmt.Sprint(competeReal1-countComptet1) + `,mgo总入库量` + fmt.Sprint(competCount1) +
-				`<br>中国招标与采购网_es统计` + strconv.Itoa(countComptet2) + `,mgo统计:` + fmt.Sprint(competeReal2) + `,差值:` + fmt.Sprint(competeReal2-countComptet2) + `,mgo总入库量` + fmt.Sprint(competCount2) +
-				`<br>北京隆道网络科技有限公司_es统计` + strconv.Itoa(countComptet3) + `,mgo统计:` + fmt.Sprint(competeReal3) + `,差值:` + fmt.Sprint(competeReal3-countComptet3) + `,mgo总入库量` + fmt.Sprint(competCount3) +
-				`<br>友云采_es统计` + strconv.Itoa(countComptet4) + `,mgo统计:` + fmt.Sprint(competeReal4) + `,差值:` + fmt.Sprint(competeReal4-countComptet4) + `,mgo总入库量` + fmt.Sprint(competCount4) +
-				`<br>新集群统计结果_es数量:` + strconv.Itoa(countNew) + `,mgo统计:` + fmt.Sprint(count3) + `,差值:` + fmt.Sprint(count3-countNew)
+			//report += `,mgo统计:` + fmt.Sprint(count3) + `,差值:` + fmt.Sprint(count3-count) + `,mgo总入库量:` + fmt.Sprint(count2) +
+			//	`<br>竟品统计结果_es统计:` + strconv.Itoa(count1) + `,mgo统计:` + fmt.Sprint(count5) + `,差值:` + fmt.Sprint(count5-count1) + `,mgo总入库量` + fmt.Sprint(count4) +
+			//	`<br>元博网_es统计:` + strconv.Itoa(countComptet1) + `,mgo统计:` + fmt.Sprint(competeReal1) + `,差值:` + fmt.Sprint(competeReal1-countComptet1) + `,mgo总入库量` + fmt.Sprint(competCount1) +
+			//	`<br>中国招标与采购网_es统计` + strconv.Itoa(countComptet2) + `,mgo统计:` + fmt.Sprint(competeReal2) + `,差值:` + fmt.Sprint(competeReal2-countComptet2) + `,mgo总入库量` + fmt.Sprint(competCount2) +
+			//	`<br>北京隆道网络科技有限公司_es统计` + strconv.Itoa(countComptet3) + `,mgo统计:` + fmt.Sprint(competeReal3) + `,差值:` + fmt.Sprint(competeReal3-countComptet3) + `,mgo总入库量` + fmt.Sprint(competCount3) +
+			//	`<br>友云采_es统计` + strconv.Itoa(countComptet4) + `,mgo统计:` + fmt.Sprint(competeReal4) + `,差值:` + fmt.Sprint(competeReal4-countComptet4) + `,mgo总入库量` + fmt.Sprint(competCount4) +
+			//	`<br>新集群统计结果_es数量:` + strconv.Itoa(countNew) + `,mgo统计:` + fmt.Sprint(count3) + `,差值:` + fmt.Sprint(count3-countNew)
+
+			//
+			var reportBuilder strings.Builder
+			// 开始表格
+			reportBuilder.WriteString("<table>")
+			reportBuilder.WriteString("<tr><th>统计项</th><th>es统计</th><th>mgo统计</th><th>差值</th><th>mgo总入库量</th></tr>")
+
+			addTableRow(&reportBuilder, "阿里云es集群", count, count3, count3-count, count2)
+			addTableRow(&reportBuilder, "竟品统计结果", count1, count5, count5-count1, count4)
+			addTableRow(&reportBuilder, "元博网", countComptet1, competeReal1, competeReal1-countComptet1, competCount1)
+			addTableRow(&reportBuilder, "中国招标与采购网", countComptet2, competeReal2, competeReal2-countComptet2, competCount2)
+			addTableRow(&reportBuilder, "北京隆道网络科技有限公司", countComptet3, competeReal3, competeReal3-countComptet3, competCount3)
+			addTableRow(&reportBuilder, "友云采", countComptet4, competeReal4, competeReal4-countComptet4, competCount4)
+			addTableRow(&reportBuilder, "华为云es集群", countNew, count3, count3-countNew, 0)
+			// 结束表格
+			reportBuilder.WriteString("</table>")
+			// 获取最终的报告字符串
+			report = reportBuilder.String()
 
 			//存入数据库
 			yesterday := now.AddDate(0, 0, -1)
@@ -373,3 +390,7 @@ func (t *T) SendMail(report string) {
 		fmt.Println("SendMail res ", res)
 	}
 }
+
+func addTableRow(builder *strings.Builder, itemName string, esCount, mgoCount, diff, mgoTotal int) {
+	builder.WriteString(fmt.Sprintf(`<tr><th>%s</th><th>%d</th><th>%d</th><th>%d</th><th>%d</th></tr>`, itemName, esCount, mgoCount, diff, mgoTotal))
+}