Przeglądaj źródła

新增lua周报统计

maxiaoshan 2 lat temu
rodzic
commit
894a799b5a
2 zmienionych plików z 64 dodań i 0 usunięć
  1. 2 0
      src/main.go
  2. 62 0
      src/timetask/report.go

+ 2 - 0
src/main.go

@@ -56,6 +56,8 @@ func main() {
 	c.AddFunc(util.StartTaskCron, luatask.StartTask)           //开始任务
 	//爬虫相关周报统计
 	c.AddFunc(util.SpiderWeeklyReportCron, timetask.SpiderWeeklyReport)
+	//lua小组周报
+	c.AddFunc("0 30 17 ? * FRI", timetask.SpiderWeeklyReportForLua)
 	//c.AddFunc(CodeSummaryCron, SummaryCode)    //上架爬虫信息汇总
 	ch := make(chan bool, 1)
 	<-ch

+ 62 - 0
src/timetask/report.go

@@ -4,6 +4,7 @@ import (
 	"bytes"
 	"fmt"
 	"github.com/tealeg/xlsx"
+	"net/http"
 	qu "qfw/util"
 	gm "qfw/util/mail"
 	"strconv"
@@ -583,3 +584,64 @@ func ConvertDataType(ratio float64) float64 {
 	ratio, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", ratio*100), 64)
 	return ratio
 }
+
+var LuaWeeklyReport = `
+	本周总结:
+		完成爬虫总量:<font color=\"warning\">%d个</font>;
+		开发新爬虫量:<font color=\"warning\">%d个</font>;
+		维护历史爬虫量:<font color=\"warning\">%d个</font>;
+		待完成爬虫总量:<font color=\"warning\">%d个</font>;
+		待核实任务总量:<font color=\"warning\">%d个</font>;
+`
+
+func SpiderWeeklyReportForLua() {
+	defer qu.Catch()
+	//维护爬虫总量
+	q := map[string]interface{}{
+		"comeintime": map[string]interface{}{
+			"$gte": util.GetTime(-4),
+			"$lte": time.Now().Unix(),
+		},
+		"types": "审核",
+	}
+	qu.Debug(q)
+	allCount := util.MgoEB.Count("lua_logs_auditor", q)
+	//开发新爬虫数量
+	q["event"] = 7000
+	newCount := util.MgoEB.Count("lua_logs_auditor_new", q)
+	//待完成爬虫数量=待开发新爬虫+待维护历史任务
+	q1 := map[string]interface{}{
+		"event":    7000,
+		"platform": "golua平台",
+		"state": map[string]interface{}{
+			"$lte": 2, //待完成、待审核、未通过
+		},
+	}
+	needNewCount := util.MgoEB.Count("luaconfig", q1)
+	q2 := map[string]interface{}{
+		"i_state": map[string]interface{}{
+			"$in": []int{2, 3, 5}, //处理中、待审核、未通过
+		},
+	}
+	needHistoryCount := util.MgoEB.Count("task", q2)
+	//待确认爬虫数量(异常)=待分发的任务(待确认+待处理)
+	q = map[string]interface{}{
+		"i_state": map[string]interface{}{
+			"$lte": 1, //任务状态:待确认、待处理
+		},
+	}
+	taskCount := util.MgoEB.Count("task", q)
+	text := fmt.Sprintf(LuaWeeklyReport, allCount, newCount, allCount-newCount, needNewCount+needHistoryCount, taskCount)
+	msg := fmt.Sprintf(MarkdownModel, text)
+	qu.Debug("msg", msg)
+	resp, err := http.Post(
+		"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=d61e5bf5-bd85-4749-996a-f2ff6b7c4177",
+		"application/json",
+		bytes.NewBuffer([]byte(msg)),
+	)
+	if err != nil {
+		fmt.Println("request error:", err)
+		return
+	}
+	defer resp.Body.Close()
+}