Browse Source

功能修改

maxiaoshan 2 years ago
parent
commit
f698f097a9
4 changed files with 57 additions and 24 deletions
  1. 6 2
      src/front/spider.go
  2. 45 17
      src/task/task.go
  3. 2 1
      src/taskManager/taskManager.go
  4. 4 4
      src/web/templates/newtasklist.html

+ 6 - 2
src/front/spider.go

@@ -429,7 +429,7 @@ func (f *Front) SaveStep() {
 			param["iscopycontent"] = f.StepRe3.Checked
 			//
 			param["listisfilter"] = ListFilterReg.MatchString(f.Step2.Expert) //列表页校验是否含“--关键词过滤”
-			matchLua, msg := LuaTextCheck(f.Step2.Expert, f.Step3.Expert, f.Step2.Types, infoformat, model)
+			matchLua, msg := LuaTextCheck(f.Base.SpiderCode, f.Step2.Expert, f.Step3.Expert, f.Step2.Types, infoformat, model)
 			if !matchLua {
 				issave := spider.SaveSpider(code, param) //保存脚本
 				if issave {
@@ -541,7 +541,7 @@ func LuaSaveLog(code, user string, data *map[string]interface{}, stype int) {
 }
 
 //爬虫保存时,检查列表页和三级页代码中是否含lua原生方法
-func LuaTextCheck(list, detail string, type_list, infoformat int, model map[string]interface{}) (b bool, msg string) {
+func LuaTextCheck(code, list, detail string, type_list, infoformat int, model map[string]interface{}) (b bool, msg string) {
 	defer qu.Catch()
 	if LuaReg.MatchString(list) || LuaReg.MatchString(detail) {
 		msg = "代码中含有lua原生方法;"
@@ -593,6 +593,10 @@ func LuaTextCheck(list, detail string, type_list, infoformat int, model map[stri
 		if infoformat == 2 && !strings.Contains(detail, "projectname") {
 			msg += "拟建/审批数据缺少projectname字段;"
 		}
+		//校验爬虫代码的一致性
+		if !strings.Contains(list, code) {
+			msg += `模板item["spidercode"]值错误`
+		}
 	}
 	b = msg != ""
 	return

+ 45 - 17
src/task/task.go

@@ -6,17 +6,18 @@ import (
 	"mongodb"
 	qu "qfw/util"
 	"sort"
-	util "spiderutil"
+	sp "spiderutil"
 	"strconv"
 	"strings"
 	"time"
-	u "util"
+	"util"
 )
 
 type Task struct {
 	*xweb.Action
-	taskList xweb.Mapper `xweb:"/center/newtask/tasklist"`  //任务管理
-	taskEdit xweb.Mapper `xweb:"/center/newtask/edit/(.*)"` //编辑任务
+	taskList    xweb.Mapper `xweb:"/center/newtask/tasklist"`  //任务管理
+	taskEdit    xweb.Mapper `xweb:"/center/newtask/edit/(.*)"` //编辑任务
+	taskTagCode xweb.Mapper `xweb:"/center/newtask/tagcode"`   //标记爬虫
 }
 
 func (t *Task) TaskList() {
@@ -32,16 +33,16 @@ func (t *Task) TaskList() {
 	draw, _ := t.GetInteger("draw")
 	start, _ := t.GetInteger("start")
 	limit, _ := t.GetInteger("length")
-	if auth == u.Role_Admin {
+	if auth == util.Role_Admin {
 		if t.Method() == "GET" {
 			events := []string{}
-			for k, _ := range util.Config.Uploadevents {
+			for k, _ := range sp.Config.Uploadevents {
 				events = append(events, k)
 			}
 			sort.Strings(events)
 			t.T["events"] = events
 			t.T["modifyusers"] = getModifyUsers()
-			t.Render("newtask.html", &t.T)
+			t.Render("newtasklist.html", &t.T)
 		} else {
 			query := queryCriteria(userid, platform, taskState, event, stype)
 			if search != "" {
@@ -67,15 +68,15 @@ func (t *Task) TaskList() {
 				sort = `{` + sortb + `,"l_complete":1}`
 			}
 			qu.Debug("query:", query, sort)
-			task, _ := u.MgoEB.Find("newtask", query, sort, nil, false, start, limit)
-			count := u.MgoEB.Count("newtask", query)
+			task, _ := util.MgoEB.Find("newtask", query, sort, nil, false, start, limit)
+			count := util.MgoEB.Count("newtask", query)
 			page := start / 10
 			if len(*task) > 0 {
 				for k, v := range *task {
 					v["num"] = k + 1 + page*10
-					v["encode"] = util.Se.Encode2Hex(fmt.Sprint(v["s_code"]))
+					v["encode"] = sp.Se.Encode2Hex(fmt.Sprint(v["s_code"]))
 					//根据code查询luaconfig
-					lua, _ := u.MgoEB.FindOneByField("luaconfig", map[string]interface{}{"code": qu.ObjToString(v["s_code"])}, `{"href":1}`)
+					lua, _ := util.MgoEB.FindOneByField("luaconfig", map[string]interface{}{"code": qu.ObjToString(v["s_code"])}, `{"href":1}`)
 					if len(*lua) > 0 {
 						v["href"] = (*lua)["href"]
 					} else {
@@ -100,7 +101,7 @@ func (t *Task) TaskEdit(ids string) error {
 		query := map[string]interface{}{
 			"_id": mongodb.StringTOBsonId(id),
 		}
-		task, _ := u.MgoEB.FindOne("newtask", query)
+		task, _ := util.MgoEB.FindOne("newtask", query)
 		if task != nil && len(*task) > 0 {
 			(*task)["l_comeintime"] = time.Unix((*task)["l_comeintime"].(int64), 0).Format("2006-01-02 15:04:05")
 			(*task)["l_complete"] = time.Unix((*task)["l_complete"].(int64), 0).Format("2006-01-02 15:04:05")
@@ -121,7 +122,7 @@ func (t *Task) TaskEdit(ids string) error {
 					}
 				}
 			}
-			t.T["encode"] = util.Se.Encode2Hex(fmt.Sprint((*task)["s_code"]))
+			t.T["encode"] = sp.Se.Encode2Hex(fmt.Sprint((*task)["s_code"]))
 			t.T["id"] = id
 			t.T["task"] = *task
 			t.T["param"] = param
@@ -131,11 +132,11 @@ func (t *Task) TaskEdit(ids string) error {
 				t.T["xgTime"] = qu.ObjToString(t.GetSession(id))
 			}
 			t.DelSession(id)
-			if auth == u.Role_Admin {
+			if auth == util.Role_Admin {
 				return t.Render("taskedit.html", &t.T)
-			} else if auth == u.Role_Dev {
+			} else if auth == util.Role_Dev {
 				return t.Render("mytaskedit.html", &t.T)
-			} else if auth == u.Role_Examine {
+			} else if auth == util.Role_Examine {
 				return t.Render("auditedit.html", &t.T)
 			}
 		}
@@ -143,12 +144,39 @@ func (t *Task) TaskEdit(ids string) error {
 	return nil
 }
 
+func (t *Task) TaskTagCode() {
+	defer qu.Catch()
+	taskId := t.GetString("id")
+	code := t.GetString("code")
+	stype := t.GetString("stype")
+	qu.Debug(taskId, code, stype)
+	//关闭任务
+	update := map[string]interface{}{
+		"$set": map[string]interface{}{
+			"i_state":     6,
+			"l_checktime": time.Now().Unix(),
+		},
+	}
+	util.MgoEB.UpdateById("newtask", taskId, update)
+	//标记爬虫
+	/*
+		tags:{任务类型:标记时间}
+	*/
+	update = map[string]interface{}{
+		"$set": map[string]interface{}{
+			"codetags." + stype: time.Now().Unix(),
+		},
+	}
+	util.MgoEB.Update("luaconfig", map[string]interface{}{"code": code}, update, false, false)
+	t.Write("y")
+}
+
 func getModifyUsers() []map[string]interface{} {
 	query := map[string]interface{}{
 		"i_auth":   1,
 		"i_delete": 0,
 	}
-	user, _ := u.MgoEB.Find("user", query, nil, nil, false, -1, -1)
+	user, _ := util.MgoEB.Find("user", query, nil, nil, false, -1, -1)
 	return *user
 }
 

+ 2 - 1
src/taskManager/taskManager.go

@@ -1143,7 +1143,8 @@ func (t *TaskM) SearchDataInfo() {
 		if coll == "spider_warn" {
 			info := (*data)["data"].(map[string]interface{})
 			publishtime := qu.Int64All(info["publishtime"])
-			text = "publishtime:" + fmt.Sprint(publishtime) + "\ntitle:" + qu.ObjToString((*data)["title"]) + ";\ndetail:" + qu.ObjToString(info["detail"])
+			publishtime_str := qu.FormatDateByInt64(&publishtime, qu.Date_Full_Layout)
+			text = "publishtime:" + publishtime_str + "\ntitle:" + qu.ObjToString((*data)["title"]) + ";\ndetail:" + qu.ObjToString(info["detail"])
 		} else {
 			text = "publishtime:" + fmt.Sprint((*data)["publishtime"]) + "\ntitle:" + qu.ObjToString((*data)["title"]) + "; "
 		}

+ 4 - 4
src/web/templates/newtask.html → src/web/templates/newtasklist.html

@@ -198,7 +198,7 @@
 					//var buttonDel=$('<a type="button" class="btn btn-sm btn-default">删除</a>');
 					buttonWatch.attr("href","/center/newtask/edit/"+row['_id']+"__0");
 					buttonClose.attr("onclick","closeTask('"+row['s_code']+"','"+row['i_state']+"','"+row['_id']+"')");
-					buttonTag.attr("onclick","tagTask('"+row['s_code']+"','"+row['i_state']+"','"+row['_id']+"','"+row['s_type']+"')");
+					buttonTag.attr("onclick","tagCode('"+row['s_code']+"','"+row['i_state']+"','"+row['_id']+"','"+row['s_type']+"')");
 					div.find(".btn-group").append(buttonWatch);
 				    div.find(".btn-group").append(buttonClose);
 					if(row['i_state'] == "0"){
@@ -425,13 +425,13 @@
 	}
 
 	//标记任务
-	function tagTask(code,state,id,stype){
-	  if(state != "待确认" && state != "待处理" && state != "处理中"){
+	function tagCode(code,state,id,stype){
+	  if(state != 0){
 		  alert("该任务不能被标记!")
 		  return
 	  }
 	  showConfirm("确定标记任务?",function(){
-		  $.post("/center/spider/tagcode",{"id":id,"code":code,"stype":stype},function(r){
+		  $.post("/center/newtask/tagcode",{"id":id,"code":code,"stype":stype},function(r){
 			  if(r == "y"){
 				  showTip("标记成功", 1000);
 				  $('#com-alert').on('hidden.bs.modal', function () {