Explorar el Código

新版任务新建流程

maxiaoshan hace 3 años
padre
commit
f1703fdbe6
Se han modificado 2 ficheros con 348 adiciones y 265 borrados
  1. 1 1
      src/code.go
  2. 347 264
      src/task.go

+ 1 - 1
src/code.go

@@ -276,7 +276,7 @@ func CreateFirstCodeTask() {
 			result["i_num"] = l.Count
 			result["i_min"] = 0
 			result["i_state"] = 0
-			result["s_type"] = "7"
+			result["s_type"] = "10"
 			result["s_urgency"] = "1"
 			result["i_times"] = 0
 			result["s_downloadtime"] = qu.FormatDateByInt64(&stime, qu.Date_Full_Layout) + "/" + qu.FormatDateByInt64(&etime, qu.Date_Full_Layout)

+ 347 - 264
src/task.go

@@ -18,6 +18,7 @@ type Task struct {
 	ErrType     string                            //异常类型:6:运行异常;5:下载异常;4:发布时间异常;3:乱码;2:状态码异常;1:数据量异常
 	ErrInfo     map[string]map[string]interface{} //异常集合
 	Description string                            //描述
+	State       int                               //状态
 }
 
 var (
@@ -36,12 +37,12 @@ var (
 //创建任务
 func CreateTaskProcess() {
 	InitInfo()                  //初始化
-	GetSpiderDownloadRateData() //统计spider_downloadrate前一天采集异常爬虫
-	GetDownloadFailedData()     //1、统计spider_highlistdata前一天下载失败的爬虫数据(统计完成后修改状态state:0)
-	GetRegatherFailedData()     //2、统计regatherdata前一天重采失败的爬虫数据
-	GetDTPErrData()             //3、统计spider_warn异常数据(发布时间异常、乱码)
-	GetStatusCodeErrorData()    //4、统计spider_sitecheck 站点异常爬虫(404)
-	GetDownloadNumErrData()     //5、统计download前一天下载量异常的爬虫数据(每天1点统计下载量,目前统计完成需要1个小时)
+	GetSpiderDownloadRateData() //1、统计spider_downloadrate前一天列表页采集异常爬虫
+	GetStatusCodeErrorData()    //2、统计spider_sitecheck 站点异常爬虫(404)
+	GetDownloadFailedData()     //3、统计spider_highlistdata前一天下载失败的爬虫数据(统计完成后修改状态state:0)
+	GetRegatherFailedData()     //4、统计regatherdata前一天重采失败的爬虫数据
+	GetDTPErrData()             //5、统计spider_warn异常数据(发布时间异常、乱码)
+	GetDownloadNumErrData()     //6、统计download前一天下载量异常的爬虫数据(每天1点统计下载量,目前统计完成需要1个小时)
 	SaveResult()                //保存统计信息
 	CreateLuaTask()             //创建任务
 	SaveUserCreateTaskNum()     //保存每人创建的任务量
@@ -93,12 +94,189 @@ func CloseTask() {
 	logger.Debug("---清理未更新任务完毕---")
 }
 
-//
+//1、统计spider_downloadrate前一天列表页采集异常爬虫
 func GetSpiderDownloadRateData() {
+	defer qu.Catch()
+	logger.Debug("---开始统计spider_downloadrate异常信息---")
+	sess := MgoS.GetMgoConn()
+	defer MgoS.DestoryMongoConn(sess)
+	ch := make(chan bool, 5)
+	wg := &sync.WaitGroup{}
+	lock := &sync.Mutex{}
+	date := qu.FormatDateByInt64(&StartTime, qu.Date_Short_Layout)
+	query := map[string]interface{}{
+		"date": date,
+	}
+	it := sess.DB("spider").C("spider_downloadrate").Find(&query).Iter()
+	n := 0
+	for tmp := make(map[string]interface{}); it.Next(tmp); n++ {
+		ch <- true
+		wg.Add(1)
+		go func(tmp map[string]interface{}) {
+			defer func() {
+				<-ch
+				wg.Done()
+			}()
+			stype := -1
+			//1、统计采集频率异常信息
+			oh_percent := qu.IntAll(tmp["oh_percent"])
+			event := qu.IntAll(tmp["event"])
+			if oh_percent > 0 && event != 7410 {
+				stype = 8
+			}
 
+			//2、统计列表页异常(统计zero占总下载次数的百分比超过80%的)
+			alltimes := qu.IntAll(tmp["alltimes"])
+			zero := qu.IntAll(tmp["zero"])
+			percent := 0 //记录百分比
+			if zero > 0 {
+				tmpPercent := float64(zero) / float64(alltimes)
+				tmpPercent, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", tmpPercent), 64)
+				percent = int(tmpPercent * float64(100))
+				if percent >= 80 { //占比超过80%
+					stype = 7
+				}
+			}
+			if stype != -1 { //出现异常
+				code := qu.ObjToString(tmp["spidercode"])
+				site := qu.ObjToString(tmp["site"])
+				channel := qu.ObjToString(tmp["channel"])
+				t := &Task{
+					Code:    code,
+					Site:    site,
+					Channel: channel,
+					ErrInfo: map[string]map[string]interface{}{},
+					State:   1,
+				}
+				if stype == 8 {
+					t.ErrType = "8"
+					t.ErrInfo = map[string]map[string]interface{}{
+						"8": map[string]interface{}{
+							"num": oh_percent,
+						},
+					}
+					t.Description = "采集频率异常:\n 列表页共采集" + fmt.Sprint(alltimes) + "轮,其中有" + fmt.Sprint(oh_percent) + "轮数据全采\n"
+				} else if stype == 7 {
+					t.ErrType = "7"
+					t.ErrInfo = map[string]map[string]interface{}{
+						"7": map[string]interface{}{
+							"num": percent,
+						},
+					}
+					t.Description = "列表页异常:\n 列表页采集无信息次数占比" + fmt.Sprint(percent) + "%\n"
+				}
+				lock.Lock()
+				TaskMap[code] = t
+				lock.Unlock()
+			}
+		}(tmp)
+		if n%100 == 0 {
+			qu.Debug("current:", n)
+		}
+		tmp = map[string]interface{}{}
+	}
+	wg.Wait()
+	logger.Debug("---统计spider_downloadrate异常信息完成---")
 }
 
-//1、统计三级页下载失败数据(放到ResetDataState后是因为不会影响统计)
+//2、状态码404
+func GetStatusCodeErrorData() {
+	defer qu.Catch()
+	logger.Debug("---开始统计栏目地址404数据---")
+	sess := MgoS.GetMgoConn()
+	defer MgoS.DestoryMongoConn(sess)
+	ch := make(chan bool, 5)
+	wg := &sync.WaitGroup{}
+	lock := &sync.Mutex{}
+	field := map[string]interface{}{
+		"url":     1,
+		"code":    1,
+		"site":    1,
+		"channel": 1,
+	}
+	query := map[string]interface{}{
+		"comeintime": map[string]interface{}{
+			"$gte": StartTime,
+			"$lte": EndTime,
+		},
+		"statuscode": 404,
+	}
+	it := sess.DB("spider").C("spider_sitecheck").Find(&query).Select(&field).Iter()
+	count, _ := sess.DB("spider").C("spider_sitecheck").Find(&query).Count()
+	logger.Debug("共有404地址", count, "条")
+	n := 0
+	for tmp := make(map[string]interface{}); it.Next(tmp); n++ {
+		ch <- true
+		wg.Add(1)
+		go func(tmp map[string]interface{}) {
+			defer func() {
+				<-ch
+				wg.Done()
+			}()
+			code := qu.ObjToString(tmp["code"])
+			one, _ := MgoE.FindOneByField("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"state": 1})
+			state := qu.IntAll((*one)["state"])
+			if state == 4 || state > 6 {
+				return
+			}
+			//判断3天内是否有采集数据,有则不建404任务
+			stime, etime := GetTime(-3), GetTime(0)
+			q := map[string]interface{}{
+				"spidercode": code,
+				"l_np_publishtime": map[string]interface{}{
+					"$gte": stime,
+					"$lte": etime,
+				},
+			}
+			if MgoS.Count("data_bak", q) > 0 { //有采集数据,不认为是404
+				return
+			}
+			href := qu.ObjToString(tmp["url"])
+			site := qu.ObjToString(tmp["site"])
+			channel := qu.ObjToString(tmp["channel"])
+			lock.Lock()
+			if t := TaskMap[code]; t != nil {
+				t.ErrInfo["6"] = map[string]interface{}{ //ErrInfo新增下载异常信息
+					"num":   404,
+					"hrefs": []string{href},
+				}
+				t.Description += "网站监测:404\n" + href + "\n"
+				t.State = 1
+			} else {
+				t := &Task{
+					Code:        code,
+					Site:        site,
+					Channel:     channel,
+					ErrType:     "6",
+					ErrInfo:     map[string]map[string]interface{}{},
+					Description: "网站监测:404\n" + href + "\n",
+					State:       1,
+				}
+				t.ErrInfo = map[string]map[string]interface{}{
+					"6": map[string]interface{}{
+						"num":   404,
+						"hrefs": []string{href},
+					},
+				}
+				TaskMap[code] = t
+			}
+			lock.Unlock()
+		}(tmp)
+		if n%100 == 0 {
+			qu.Debug("current:", n)
+		}
+		tmp = map[string]interface{}{}
+	}
+	wg.Wait()
+	logger.Debug("---统计栏目地址404数据完成---")
+}
+
+//3、统计三级页下载失败数据
+/*
+	先统计下载失败信息再更新下载失败信息状态(ResetDataState)使其可重新下载,这样不影响统计
+	但是任务已经就绪,若下载失败信息重新下载成功,则使任务不太准备
+	若先重置状态再统计,会使任务统计时缺少,无法正常监控
+*/
 func GetDownloadFailedData() {
 	defer qu.Catch()
 	logger.Debug("---开始统计下载失败信息---")
@@ -139,7 +317,7 @@ func GetDownloadFailedData() {
 			channel := qu.ObjToString(tmp["channel"])
 			lock.Lock()
 			if t := TaskMap[code]; t != nil {
-				if info := t.ErrInfo["6"]; info != nil {
+				if info := t.ErrInfo["5"]; info != nil {
 					num := qu.IntAll(info["num"])
 					num++
 					info["num"] = num
@@ -149,8 +327,11 @@ func GetDownloadFailedData() {
 						info["hrefs"] = hrefs
 						t.Description += href + "\n"
 					}
+					if num >= 10 {
+						t.State = 1
+					}
 				} else {
-					t.ErrInfo["6"] = map[string]interface{}{ //ErrInfo新增下载异常信息
+					t.ErrInfo["5"] = map[string]interface{}{ //ErrInfo新增下载异常信息
 						"num":   1,
 						"hrefs": []string{href},
 					}
@@ -161,12 +342,13 @@ func GetDownloadFailedData() {
 					Code:        code,
 					Site:        site,
 					Channel:     channel,
-					ErrType:     "6",
+					ErrType:     "5",
 					ErrInfo:     map[string]map[string]interface{}{},
 					Description: "下载异常:\n" + href + "\n",
+					State:       0,
 				}
 				t.ErrInfo = map[string]map[string]interface{}{
-					"6": map[string]interface{}{
+					"5": map[string]interface{}{
 						"num":   1,
 						"hrefs": []string{href},
 					},
@@ -201,7 +383,7 @@ func GetDownloadFailedData() {
 	logger.Debug("---统计下载失败信息完成---")
 }
 
-//2、统计重采失败数据
+//4、统计重采失败数据
 func GetRegatherFailedData() {
 	defer qu.Catch()
 	logger.Debug("---开始统计重采失败信息---")
@@ -217,8 +399,10 @@ func GetRegatherFailedData() {
 		"channel":    1,
 	}
 	query := map[string]interface{}{
-		"state": 1,
-		"from":  "lua",
+		"state": map[string]interface{}{
+			"$lte": 1,
+		},
+		"from": "lua",
 		"comeintime": map[string]interface{}{
 			"$gte": StartTime,
 			"$lte": EndTime,
@@ -242,7 +426,7 @@ func GetRegatherFailedData() {
 			channel := qu.ObjToString(tmp["channel"])
 			lock.Lock()
 			if t := TaskMap[code]; t != nil {
-				if info := t.ErrInfo["5"]; info != nil {
+				if info := t.ErrInfo["4"]; info != nil {
 					num := qu.IntAll(info["num"])
 					num++
 					info["num"] = num
@@ -252,25 +436,28 @@ func GetRegatherFailedData() {
 						info["hrefs"] = hrefs
 						t.Description += href + "\n"
 					}
+					if num >= 10 {
+						t.State = 1
+					}
 				} else {
-					t.ErrInfo["5"] = map[string]interface{}{ //ErrInfo新增下载异常信息
+					t.ErrInfo["4"] = map[string]interface{}{ //ErrInfo新增下载异常信息
 						"num":   1,
 						"hrefs": []string{href},
 					}
 					t.Description += "运行报错:\n" + href + "\n"
 				}
-
 			} else {
 				t := &Task{
 					Code:        code,
 					Site:        site,
 					Channel:     channel,
-					ErrType:     "5",
+					ErrType:     "4",
 					ErrInfo:     map[string]map[string]interface{}{},
 					Description: "运行报错:\n" + href + "\n",
+					State:       0,
 				}
 				t.ErrInfo = map[string]map[string]interface{}{
-					"5": map[string]interface{}{
+					"4": map[string]interface{}{
 						"num":   1,
 						"hrefs": []string{href},
 					},
@@ -301,7 +488,7 @@ func GetRegatherFailedData() {
 	logger.Debug("---统计重采失败信息完成---")
 }
 
-//3、统计detail、title、publishtime异常数据
+//5、统计detail、title、publishtime异常数据
 func GetDTPErrData() {
 	defer qu.Catch()
 	logger.Debug("---开始统计信息异常数据---")
@@ -337,7 +524,7 @@ func GetDTPErrData() {
 				<-ch
 				wg.Done()
 			}()
-			errnum := "3" //detail、 title异常
+			errnum := "2" //detail、 title异常
 			destmp := "正文标题异常:\n"
 			field := qu.ObjToString(tmp["field"])
 			info := qu.ObjToString(tmp["info"])
@@ -345,7 +532,7 @@ func GetDTPErrData() {
 				if info == "Publishtime Is Too Late" { //发布时间超前的不建任务
 					return
 				}
-				errnum = "4"
+				errnum = "3"
 				destmp = "发布时间异常:\n"
 			}
 			code := qu.ObjToString(tmp["code"])
@@ -365,6 +552,9 @@ func GetDTPErrData() {
 						info["hrefs"] = hrefs
 						t.Description += href + "\n"
 					}
+					if num >= 10 {
+						t.State = 1
+					}
 				} else {
 					t.ErrInfo[errnum] = map[string]interface{}{
 						"num":   1,
@@ -380,6 +570,7 @@ func GetDTPErrData() {
 					ErrType:     errnum,
 					ErrInfo:     map[string]map[string]interface{}{},
 					Description: destmp + href + "\n",
+					State:       0,
 				}
 				t.ErrInfo = map[string]map[string]interface{}{
 					errnum: map[string]interface{}{
@@ -400,75 +591,7 @@ func GetDTPErrData() {
 	logger.Debug("---统计信息异常数据完成---")
 }
 
-//4、状态码404
-func GetStatusCodeErrorData() {
-	defer qu.Catch()
-	logger.Debug("---开始统计栏目地址404数据---")
-	field := map[string]interface{}{
-		"url":     1,
-		"code":    1,
-		"site":    1,
-		"channel": 1,
-	}
-	query := map[string]interface{}{
-		"comeintime": map[string]interface{}{
-			"$gte": StartTime,
-			"$lte": EndTime,
-		},
-		"statuscode": 404,
-	}
-	list, _ := MgoS.Find("spider_sitecheck", query, nil, field, false, -1, -1)
-	logger.Debug("共有404地址", len(*list), "条")
-	for _, tmp := range *list {
-		code := qu.ObjToString(tmp["code"])
-		one, _ := MgoE.FindOneByField("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"state": 1})
-		state := qu.IntAll((*one)["state"])
-		if state == 4 || state > 6 {
-			continue
-		}
-		//判断3天内是否有采集数据,有则不建404任务
-		stime, etime := GetTime(-3), GetTime(0)
-		q := map[string]interface{}{
-			"spidercode": code,
-			"l_np_publishtime": map[string]interface{}{
-				"$gte": stime,
-				"$lte": etime,
-			},
-		}
-		if MgoS.Count("data_bak", q) > 0 { //有采集数据,不认为是404
-			continue
-		}
-		href := qu.ObjToString(tmp["url"])
-		site := qu.ObjToString(tmp["site"])
-		channel := qu.ObjToString(tmp["channel"])
-		if t := TaskMap[code]; t != nil {
-			t.ErrInfo["2"] = map[string]interface{}{ //ErrInfo新增下载异常信息
-				"num":   404,
-				"hrefs": []string{href},
-			}
-			t.Description += "网站监测:404\n" + href + "\n"
-		} else {
-			t := &Task{
-				Code:        code,
-				Site:        site,
-				Channel:     channel,
-				ErrType:     "2",
-				ErrInfo:     map[string]map[string]interface{}{},
-				Description: "网站监测:404\n" + href + "\n",
-			}
-			t.ErrInfo = map[string]map[string]interface{}{
-				"2": map[string]interface{}{
-					"num":   404,
-					"hrefs": []string{href},
-				},
-			}
-			TaskMap[code] = t
-		}
-	}
-	logger.Debug("---统计栏目地址404数据完成---")
-}
-
-//5、统计下载量异常数据
+//6、统计下载量异常数据
 func GetDownloadNumErrData() {
 	defer qu.Catch()
 	logger.Debug("---开始统计下载量异常数据---")
@@ -526,6 +649,7 @@ func GetDownloadNumErrData() {
 					ErrType:     "1",
 					ErrInfo:     map[string]map[string]interface{}{},
 					Description: "下载量异常:\n" + date + ":" + fmt.Sprint(dnum) + "\n",
+					State:       0,
 				}
 				t.ErrInfo = map[string]map[string]interface{}{
 					"1": map[string]interface{}{
@@ -606,7 +730,8 @@ func SaveResult() {
 			result["errinfo"] = t.ErrInfo
 			result["description"] = t.Description
 			result["comeintime"] = time.Now().Unix()
-			result["updatetime"] = time.Now().Unix()
+			result["state"] = t.State
+			//result["updatetime"] = time.Now().Unix()
 			lua, _ := MgoE.FindOne("luaconfig", map[string]interface{}{"code": t.Code})
 			if lua != nil && len(*lua) > 0 {
 				result["modifyid"] = (*lua)["createuserid"]
@@ -619,7 +744,7 @@ func SaveResult() {
 			}
 			if len(savearr) > 500 {
 				tmps := savearr
-				MgoE.SaveBulk("luataskinfo", tmps...)
+				MgoE.SaveBulk("luataskinfo_test", tmps...)
 				savearr = []map[string]interface{}{}
 			}
 			lock.Unlock()
@@ -628,7 +753,7 @@ func SaveResult() {
 	wg.Wait()
 	lock.Lock()
 	if len(savearr) > 0 {
-		MgoE.SaveBulk("luataskinfo", savearr...)
+		MgoE.SaveBulk("luataskinfo_test", savearr...)
 		savearr = []map[string]interface{}{}
 	}
 	lock.Unlock()
@@ -637,21 +762,6 @@ func SaveResult() {
 }
 
 //创建任务
-/*
-1、新任务待确认
-	1.原任务待确认-->更新原待确认任务的紧急度、最迟完成时间、times;如果times>5则更新为待处理任务;追加信息description、addinfoid
-	2.原任务待处理-->description、addinfoid信息更新到原任务
-	3.原任务处理中-->description、addinfoid信息更新到原任务
-	3.原任务待审核-->新建待确认任务
-	3.原任务未通过-->更新信息后改为待处理;爬虫状态改为待完成;追加信息description、addinfoid
-
-2、新任务待处理
-	1.原任务待确认-->关闭原任务;新建待处理任务,追加信息description、addinfoid;
-	2.原任务待处理-->description、addinfoid信息更新到原任务
-	3.原任务处理中-->description、addinfoid信息更新到原任务
-	3.原任务待审核-->新建待确认任务;
-	3.原任务未通过-->更新信息后改为待处理;爬虫状态改为待完成;追加信息description、addinfoid
-*/
 func CreateLuaTask() {
 	defer qu.Catch()
 	logger.Debug("---开始创建任务---")
@@ -661,7 +771,7 @@ func CreateLuaTask() {
 	wg := &sync.WaitGroup{}
 	field := map[string]interface{}{
 		"comeintime": 0,
-		"updatetime": 0,
+		//"updatetime": 0,
 	}
 	query := map[string]interface{}{
 		"comeintime": map[string]interface{}{
@@ -690,10 +800,13 @@ func CreateLuaTask() {
 			modifyid := qu.ObjToString(tmp["modifyid"])
 			modify := qu.ObjToString(tmp["modify"])
 			event := qu.IntAll(tmp["event"])
+			state := qu.IntAll(tmp["state"])
 			//初始化一些任务的变量
-			n_istate := 0     //当前任务的状态(默认待处理)
-			n_imin := 0       //最小下载量
-			n_itimes := 0     //任务出现特别紧急的次数
+			n_imin := 0   //最小下载量
+			n_itimes := 0 //任务出现特别紧急的次数
+			if state == 1 {
+				n_itimes = 1
+			}
 			n_idn := 0        //下载量
 			n_sdt := ""       //下载量对应的日期
 			n_surgency := "1" //紧急程度
@@ -705,20 +818,8 @@ func CreateLuaTask() {
 				n_idn = qu.IntAll(info["num"])
 				n_sdt = qu.ObjToString(info["date"])
 			}
-			switch errtype {
-			case "6", "5": //下载异常、重采异常
-				info := errinfo[errtype].(map[string]interface{})
-				num := qu.IntAll(info["num"])
-				if num > 5 || (len(errinfo) == 2 && dnerr == nil) || len(errinfo) >= 3 {
-					n_istate = 1
-					n_surgency = "4"
-				}
-			case "4", "3", "2": //下载报错、发布时间异常、detail、title异常、404
-				n_istate = 1
+			if errtype == "8" || errtype == "7" || errtype == "6" {
 				n_surgency = "4"
-			case "1": //下载量异常
-				n_istate = 0
-				n_surgency = "1"
 			}
 			query := map[string]interface{}{
 				"s_code": code,
@@ -728,8 +829,7 @@ func CreateLuaTask() {
 			}
 			list, _ := MgoE.Find("task", query, nil, nil, false, -1, -1)
 			if list != nil && len(*list) > 0 { //已有任务
-				task := (*list)[0]  //记录已有任务的集合
-				if len(*list) > 2 { //一个爬虫不能同时存在状态为0,1,2,3,5的超过2个任务
+				if len(*list) > 1 {
 					logger.Error("Code:", code, "任务异常")
 					MgoE.Save("luacreatetaskerr", map[string]interface{}{
 						"code":       code,
@@ -737,151 +837,133 @@ func CreateLuaTask() {
 						"tasknum":    len(*list),
 					})
 					return
-				} else if len(*list) == 2 { //会出现一个爬虫既有待审核的任务也有待确认的任务,此情况只处理待确认的任务即可
-					tmpstate := qu.IntAll(task["i_state"])
-					if n_istate == 0 { //新建任务为待确认
-						if tmpstate == 3 || tmpstate == 5 { //如果task=(*list)[0]取的是待审核或未通过的任务,则将task替换为待确认任务数据集
-							task = map[string]interface{}{}
-							task = (*list)[1]
-						}
-					} else if n_istate == 1 { //新建任务为待处理
-						if tmpstate == 0 { //如果task=(*list)[0]取的是待确认任务,则将task替换为待审核或未通过的任务数据集
-							task = map[string]interface{}{}
-							task = (*list)[1]
-						}
-					}
 				}
-				//已有任务部分变量
-				o_istate := qu.IntAll(task["i_state"]) //已有任务的状态
-				addinfoid := []string{}                //记录追加信息的infoid
-				if addinfoidtmp, ok := task["addinfoid"].([]interface{}); ok {
-					addinfoid = qu.ObjArrToStringArr(addinfoidtmp)
-				}
-				o_stype := qu.ObjToString(task["s_type"]) //已有任务的类型
-				if errtype > o_stype {                    //任务类型替换为权重最高的
-					o_stype = errtype
-				}
-				o_sdescript := qu.ObjToString(task["s_descript"]) //已有任务的描述
-				o_lcomplete := qu.Int64All(task["l_complete"])    //已有任务的最迟完成时间
-				o_surgency := qu.ObjToString(task["s_urgency"])   //已有任务的紧急度
-				o_iurgency, _ := strconv.Atoi(o_surgency)         //已有任务的紧急度int类型
-				o_itimes := qu.IntAll(task["i_times"])            //已有任务出现特别紧急的次数
-				//处理任务流程
-				switch o_istate {
-				case 0: //原任务为待确认
-					// ctask := true //是否创建新任务(只针对原任务为待确认新任务为待处理)
-					// if n_istate == 0 || (n_istate == 1 && len(*list) == 2) {
-					o_iurgency++         //紧急度加一级
-					if o_iurgency >= 4 { //出现特别紧急的状态,记录次数itimes
-						o_itimes++
-						o_iurgency = 4
-					}
-					o_surgency = fmt.Sprint(o_iurgency)
-					o_lcomplete = CompleteTime(o_surgency)                                                                         //更新完成时间
-					o_sdescript += time.Now().Format(qu.Date_Short_Layout) + "追加描述:------------------------------\n" + description //更新描述
-					addinfoid = append(addinfoid, id)                                                                              //记录追加infoid
-					//ctask = false //n_istate==1&&len(*list)==2为true:新任务为待处理,已有任务除了有待确认还有其他类型任务,此时更新已有的待确认任务
-					//}
-					if n_istate == 0 { //新任务为待确认
-						if o_itimes >= 5 && len(*list) == 1 { //特别紧急的次数出现5次,自动创建待处理的任务(排除有待审核任务的可能)
-							o_istate = 1
+				task := (*list)[0]
+				o_istate := qu.IntAll(task["i_state"])              //已有任务的状态
+				o_stype := qu.ObjToString(task["s_type"])           //已有任务的类型
+				o_sdescript := qu.ObjToString(task["s_descript"])   //已有任务的描述
+				o_addinfoid, _ := task["addinfoid"].([]interface{}) //luataskinfo信息
+				o_lcomplete := qu.Int64All(task["l_complete"])      //已有任务的最迟完成时间
+				o_surgency := qu.ObjToString(task["s_urgency"])     //已有任务的紧急度
+				o_iurgency, _ := strconv.Atoi(o_surgency)           //已有任务的紧急度int类型
+				o_itimes := qu.IntAll(task["i_times"])              //已有任务出现的次数
+				//
+				o_addinfoid = append(o_addinfoid, id)                                                                          //追加addinfoid信息
+				o_sdescript += time.Now().Format(qu.Date_Short_Layout) + "追加描述:------------------------------\n" + description //追加描述
+				set := map[string]interface{}{}
+				//MgoE.Update("task", q, s, false, false)
+				if state == 1 { //新任务为待处理
+					if o_istate <= 2 {
+						if errtype > o_stype { //历史任务是待确认、待处理、处理中状态且任务类型等级低于新建任务,任务类型替换为新任务类型
+							o_stype = errtype
 						}
-						q := map[string]interface{}{
-							"_id": task["_id"],
+						o_surgency = n_surgency //更新紧急度
+						o_itimes++
+						set = map[string]interface{}{
+							"addinfoid":  o_addinfoid,
+							"s_descript": o_sdescript,
+							// "i_min":          n_imin,
+							// "i_num":          n_idn,
+							// "s_downloadtime": n_sdt,
+							// "i_state":        state,
+							"l_complete":   CompleteTime(o_surgency),
+							"s_urgency":    o_surgency,
+							"s_type":       o_stype,
+							"i_times":      o_itimes,
+							"l_updatetime": time.Now().Unix(),
 						}
-						s := map[string]interface{}{
-							"$set": map[string]interface{}{
-								"addinfoid":      addinfoid,
-								"i_state":        o_istate,
-								"s_descript":     o_sdescript,
-								"l_complete":     o_lcomplete,
-								"s_urgency":      o_surgency,
-								"i_times":        o_itimes,
-								"s_type":         o_stype,
-								"i_min":          n_imin,
-								"i_num":          n_idn,
-								"s_downloadtime": n_sdt,
-							},
+					} else { //历史任务类型为未通过或待审核,更新信息
+						set = map[string]interface{}{
+							"addinfoid":    o_addinfoid,
+							"s_descript":   o_sdescript,
+							"l_updatetime": time.Now().Unix(),
 						}
-						//更新task
-						MgoE.Update("task", q, s, false, false)
-					} else if n_istate == 1 { //新任务为待处理
-						if len(*list) == 1 { //已有任务只有待确认,新建待处理任务,关闭原任务
-							//新建任务(这里使用o_sdescript而不是description,是为了追加描述信息)
-							SaveTask(code, site, channel, modifyid, modify, o_sdescript, n_surgency, n_sdt, errtype, n_istate, n_imin, n_idn, event, n_itimes, addinfoid)
-							//关闭原任务
-							MgoE.Update("task", map[string]interface{}{"_id": task["_id"]}, map[string]interface{}{"$set": map[string]interface{}{"i_state": 6}}, false, false)
-						} else { //除了待确认有其他状态的任务,更新待确认任务
-							q := map[string]interface{}{
-								"_id": task["_id"],
-							}
-							s := map[string]interface{}{
-								"$set": map[string]interface{}{
-									"addinfoid": addinfoid,
-									//"i_state":    o_istate,
+					}
+				} else { //新任务为待确认
+					if o_istate == 0 { //历史任务为待确认
+						if o_stype == "1" { //历史任务为数量异常待确认
+							if errtype == "1" { //新任务为数量异常待确认,按紧急程度递增,次数递增
+								o_iurgency++         //紧急度加一级
+								if o_iurgency >= 4 { //出现特别紧急的状态,记录次数itimes
+									o_itimes++
+									o_iurgency = 4
+								}
+								o_surgency = fmt.Sprint(o_iurgency)
+								o_lcomplete = CompleteTime(o_surgency)
+								if o_itimes >= 5 { //特别紧急的次数出现5次,自动创建待处理的任务(排除有待审核任务的可能)
+									state = 1
+								}
+								set = map[string]interface{}{
+									"addinfoid":      o_addinfoid,
 									"s_descript":     o_sdescript,
+									"i_min":          n_imin,
+									"i_num":          n_idn,
+									"s_downloadtime": n_sdt,
+									"i_state":        state,
 									"l_complete":     o_lcomplete,
 									"s_urgency":      o_surgency,
+									"s_type":         errtype,
 									"i_times":        o_itimes,
-									"s_type":         o_stype,
+									"l_updatetime":   time.Now().Unix(),
+								}
+							} else { //新任务为其他异常类型待确认,紧急程度:紧急;
+								if o_iurgency < 4 { //数量异常,特别紧急以下
+									o_surgency = "1"
+								} else {
+									o_surgency = "2"
+								}
+								set = map[string]interface{}{
+									"addinfoid":      o_addinfoid,
+									"s_descript":     o_sdescript,
 									"i_min":          n_imin,
 									"i_num":          n_idn,
 									"s_downloadtime": n_sdt,
-								},
+									"i_state":        state,
+									"l_complete":     CompleteTime(o_surgency),
+									"s_urgency":      o_surgency,
+									"s_type":         errtype,
+									"l_updatetime":   time.Now().Unix(),
+								}
+							}
+						} else { //其他任务类型待确认,历史任务紧急程度+1,次数+1,任务类型更新为异常等级高者且连续4天变为待处理
+							if errtype > o_stype {
+								o_stype = errtype
+							}
+							o_iurgency++         //紧急度加一级
+							if o_iurgency >= 4 { //出现特别紧急的状态,记录次数itimes
+								o_itimes++
+								o_iurgency = 4
+								state = 1 //特别紧急,任务变为待处理
+							}
+							o_surgency = fmt.Sprint(o_iurgency)
+							set = map[string]interface{}{
+								"addinfoid":      o_addinfoid,
+								"s_descript":     o_sdescript,
+								"i_min":          n_imin,
+								"i_num":          n_idn,
+								"s_downloadtime": n_sdt,
+								"i_state":        state,
+								"l_complete":     CompleteTime(o_surgency),
+								"s_urgency":      o_surgency,
+								"s_type":         o_stype,
+								"i_times":        o_itimes,
+								"l_updatetime":   time.Now().Unix(),
 							}
-							//更新task
-							MgoE.Update("task", q, s, false, false)
 						}
-					}
-				case 1, 2: //原任务为待处理、处理中
-					//信息更新
-					o_sdescript += time.Now().Format(qu.Date_Short_Layout) + "追加描述:------------------------------\n" + description //更新描述
-					addinfoid = append(addinfoid, id)
-					q := map[string]interface{}{
-						"_id": task["_id"],
-					}
-					s := map[string]interface{}{
-						"$set": map[string]interface{}{
-							"addinfoid":      addinfoid,
-							"s_descript":     o_sdescript,
-							"s_type":         o_stype,
-							"i_min":          n_imin,
-							"i_num":          n_idn,
-							"s_downloadtime": n_sdt,
-						},
-					}
-					//更新task
-					MgoE.Update("task", q, s, false, false)
-				case 3: //原任务为待审核
-					//新建待确认任务
-					n_istate = 0
-					SaveTask(code, site, channel, modifyid, modify, description, n_surgency, n_sdt, errtype, n_istate, n_imin, n_idn, event, n_itimes, []string{id})
-				case 5: //原任务为未通过
-					//信息更新
-					o_sdescript += time.Now().Format(qu.Date_Short_Layout) + "追加描述:------------------------------\n" + description //更新描述
-					addinfoid = append(addinfoid, id)                                                                              //记录追加infoid
-					o_istate = 1
-					q := map[string]interface{}{
-						"_id": task["_id"],
-					}
-					s := map[string]interface{}{
-						"$set": map[string]interface{}{
-							"addinfoid":      addinfoid,
-							"i_state":        o_istate,
+					} else { //历史任务为待处理以上,只追加描述
+						set = map[string]interface{}{
+							"addinfoid":      o_addinfoid,
 							"s_descript":     o_sdescript,
-							"s_type":         o_stype,
 							"i_min":          n_imin,
 							"i_num":          n_idn,
 							"s_downloadtime": n_sdt,
-						},
+							"l_updatetime":   time.Now().Unix(),
+						}
 					}
-					//更新task
-					MgoE.Update("task", q, s, false, false)
-					//更新lua
-					MgoE.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"state": 0}}, false, false)
 				}
-			} else { //没有任务新建
-				SaveTask(code, site, channel, modifyid, modify, description, n_surgency, n_sdt, errtype, n_istate, n_imin, n_idn, event, n_itimes, []string{id})
+				MgoE.Update("task", map[string]interface{}{"_id": task["_id"]}, map[string]interface{}{"$set": set}, false, false)
+			} else {
+				SaveTask(code, site, channel, modifyid, modify, description, n_surgency, n_sdt, errtype, state, n_imin, n_idn, event, n_itimes, []string{id})
 			}
 		}(tmp)
 		if n%100 == 0 {
@@ -896,15 +978,15 @@ func CreateLuaTask() {
 func SaveTask(code, site, channel, modifyid, modify, description, urgency, downloadtime, errtype string, state, min, downloadnum, event, times int, addinfoid []string) {
 	defer qu.Catch()
 	result := map[string]interface{}{}
-	if stateNum := UserTaskNum[modify]; stateNum == nil {
-		tmp := map[string]int{fmt.Sprint(state): 1}
-		UserTaskNum[modify] = tmp
-	} else {
-		stateNum[fmt.Sprint(state)]++
-	}
-	if state == 1 { //待处理任务,紧急程度定为特别紧急
-		urgency = "4"
-	}
+	// if stateNum := UserTaskNum[modify]; stateNum == nil {
+	// 	tmp := map[string]int{fmt.Sprint(state): 1}
+	// 	UserTaskNum[modify] = tmp
+	// } else {
+	// 	stateNum[fmt.Sprint(state)]++
+	// }
+	// if state == 1 { //待处理任务,紧急程度定为特别紧急
+	// 	urgency = "4"
+	// }
 	result["s_code"] = code
 	result["s_site"] = site
 	result["s_channel"] = channel
@@ -918,6 +1000,7 @@ func SaveTask(code, site, channel, modifyid, modify, description, urgency, downl
 	result["i_event"] = event
 	result["s_downloadtime"] = downloadtime //下载量对应的日期
 	result["l_comeintime"] = time.Now().Unix()
+	result["l_updatetime"] = time.Now().Unix()
 	result["l_complete"] = CompleteTime(urgency)
 	//result["s_date"] = time.Now().Format(qu.Date_Short_Layout) //任务创建字符串日期
 	result["i_times"] = times       //为了方便编辑器对次数的排序,记录当前的次数