maxiaoshan 2 年之前
父節點
當前提交
5f79346f44
共有 6 個文件被更改,包括 110 次插入14 次删除
  1. 2 0
      src/front/front.go
  2. 24 6
      src/front/luamove.go
  3. 2 0
      src/front/spider.go
  4. 1 1
      src/web/templates/head.html
  5. 80 6
      src/web/templates/luamovelist.html
  6. 1 1
      src/web/templates/spiderbase.html

+ 2 - 0
src/front/front.go

@@ -987,6 +987,8 @@ func (f *Front) UpdateESP() {
 				if historyevent := (*one)["historyevent"]; historyevent != nil {
 					b, err = spider.UpdateSpiderByCodeState(code, "6", qu.IntAll(historyevent))
 				}
+				//关闭任务
+				u.MgoEB.Update("task", map[string]interface{}{"s_code": code, "i_state": map[string]interface{}{"$in": []int{0, 1, 2, 3, 5}}}, map[string]interface{}{"$set": map[string]interface{}{"i_state": 6}}, false, true)
 				if b && err == nil {
 					set["state"] = 0 //更新状态
 					set["luauser"] = map[string]interface{}{

+ 24 - 6
src/front/luamove.go

@@ -20,6 +20,8 @@ type LuaMove struct {
 	*xweb.Action
 	luaMove       xweb.Mapper `xweb:"/center/luamove"`               //站点列表
 	luaMoveByCode xweb.Mapper `xweb:"/center/luamove/luamovebycode"` //
+	closeAll      xweb.Mapper `xweb:"/center/luamove/closeall"`      //关闭所有爬虫
+	updateToEvent xweb.Mapper `xweb:"/center/luamove/updatetoevent"` //更新目标节点
 }
 
 func (lm *LuaMove) LuaMove() {
@@ -114,7 +116,8 @@ func (lm *LuaMove) LuaMoveByCode() {
 				map[string]interface{}{"code": code},
 				map[string]interface{}{
 					"$set": map[string]interface{}{
-						"state": 1,
+						"state":      1,
+						"updatetime": time.Now().Unix(),
 					},
 				},
 			})
@@ -125,6 +128,21 @@ func (lm *LuaMove) LuaMoveByCode() {
 	lm.ServeJson(map[string]interface{}{"ok": ok})
 }
 
+func (lm *LuaMove) CloseAll() {
+	defer qu.Catch()
+	ok := u.MgoEB.Update("luamovevent", map[string]interface{}{"state": 0}, map[string]interface{}{"$set": map[string]interface{}{"state": 1, "updatetime": time.Now().Unix()}}, false, true)
+	lm.ServeJson(map[string]interface{}{"ok": ok})
+}
+
+func (lm *LuaMove) UpdateToEvent() {
+	defer qu.Catch()
+	id := lm.GetString("id")
+	event, _ := lm.GetInteger("event")
+	qu.Debug(id, event)
+	ok := u.MgoEB.UpdateById("luamovevent", id, map[string]interface{}{"$set": map[string]interface{}{"toevent": event, "updatetime": time.Now().Unix()}})
+	lm.ServeJson(map[string]interface{}{"ok": ok})
+}
+
 //爬虫迁移
 func SpiderMoveLua(codes []string, events []string) bool {
 	defer qu.Catch()
@@ -135,16 +153,16 @@ func SpiderMoveLua(codes []string, events []string) bool {
 		lua, _ := u.MgoEB.FindOne("luaconfig", map[string]interface{}{"code": code})
 		if len(*lua) > 0 {
 			state := qu.IntAll((*lua)["state"])
-			//event := qu.IntAll((*lua)["event"])
+			event := qu.IntAll((*lua)["event"])
 			if state == 5 { //查询该爬虫是否是已上架状态,是则更新节点后上架,否则只更新
 				upresult := true
 				var err interface{}
-				//upresult, err = spider.UpdateSpiderByCodeState(code, "6", event) //脚本下架
-				if upresult && err == nil { //下架成功,更新节点
+				upresult, err = spider.UpdateSpiderByCodeState(code, "6", event) //脚本下架
+				if upresult && err == nil {                                      //下架成功,更新节点
 					re := qu.IntAll(resultEvent)
 					u.MgoEB.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"event": re, "historyevent": re}}, false, false)
 					//上架
-					//upresult, err = spider.UpdateSpiderByCodeState(code, "5",re) //脚本上架
+					upresult, err = spider.UpdateSpiderByCodeState(code, "5", re) //脚本上架
 					if !upresult || err != nil {
 						qu.Debug("爬虫节点转移", code, "上架失败")
 						msg = append(msg, "爬虫节点转移"+code+"上架失败")
@@ -154,7 +172,7 @@ func SpiderMoveLua(codes []string, events []string) bool {
 					msg = append(msg, "爬虫节点转移"+code+"下架失败")
 				}
 			}
-			u.MgoEB.Update("luamovevent", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"state": 1}}, false, false)
+			u.MgoEB.Update("luamovevent", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"state": 1, "updatetime": time.Now().Unix()}}, false, false)
 		} else {
 			msg = append(msg, "爬虫节点转移未找到爬虫"+code)
 		}

+ 2 - 0
src/front/spider.go

@@ -1144,6 +1144,8 @@ func UpStateAndUpSpider(code, id, reason, username string, state int) (bool, err
 						"spideruser": (*one)["createuser"],
 						"modifytime": (*one)["modifytime"],
 						"event":      (*one)["event"],
+						"site":       (*one)["site"],
+						"channel":    (*one)["channel"],
 					}
 					//新爬虫审核记录表
 					if state == Sp_state_3 {

+ 1 - 1
src/web/templates/head.html

@@ -587,7 +587,6 @@
 			<li data="index_rwgl"><a href="/center/managerTask"><i class="glyphicon glyphicon glyphicon-tasks"></i> <span>任务管理</span></a></li>
 			<li data="index_fbgl"><a href="/center/lualist.html"><i class="glyphicon glyphicon-credit-card"></i> <span>运行监控中心</span></a></li>
 		    <li data="index_pcdr"><a href="/center/importdata"><i class="glyphicon glyphicon-import"></i> <span>爬虫导入</span></a></li>
-		    <li data="index_site"><a href="/center/site/sitelist"><i class="glyphicon glyphicon-home"></i> <span>站点列表</span></a></li>
 		    <li data="index_pcqy"><a href="/center/luamove"><i class="glyphicon glyphicon-move"></i> <span>爬虫迁移管理</span></a></li>
 		{{else if eq (session "auth") 2}}
 			<li data="index"><a href="/center"><i class="glyphicon glyphicon-eye-open"></i> <span>爬虫审核</span></a></li>
@@ -602,6 +601,7 @@
     	<li data="index_errdata"><a href="/center/errorData"><i class="glyphicon glyphicon-exclamation-sign"></i> <span>错误信息管理</span></a></li>
 <!--		<li data="index_wtgl"><a href="/center/managerQues"><i class="glyphicon glyphicon-question-sign"></i> <span>问题管理</span></a></li>-->
 		{{end}}
+		<li data="index_site"><a href="/center/site/sitelist"><i class="glyphicon glyphicon-home"></i> <span>站点列表</span></a></li>
 		<li ><a href="/center/logout" target="_self"><i class="fa fa-sign-out"></i> <span>退出</span></a></li>
 		<li style="color:#fff;padding:35px 20px;" class="hide">
 			<div class="form-group">

+ 80 - 6
src/web/templates/luamovelist.html

@@ -6,7 +6,8 @@
 		     <small>
 				  <button class="btn btn-primary btn-sm" onclick='batchCodeMove("")'>批量迁移</button>
 				  <button class="btn btn-primary btn-sm" onclick="batchCodeClose()">批量关闭</button>
-			   </small>
+				 <button class="btn btn-primary btn-sm" onclick="CloseAll()">一键关闭</button>
+			 </small>
 		   </h1>
 		   <ol class="breadcrumb">
 		     <li><a href="#"><i class="fa fa-dashboard"></i> 爬虫</a></li>
@@ -26,6 +27,8 @@
 								<th>是否转移</th>
 								<th>历史节点</th>
 								<th>目标节点</th>
+								<th>最大页</th>
+								<th>间隔(分)</th>
 								<th>下载量(comeintime)</th>
 								<th>下载量(publishtime)</th>
 								<th>迁移状态</th>
@@ -51,9 +54,32 @@
       		},
 			"columnDefs": [
 				//{ "targets": 0 ,"bVisible": false}, //隐藏列
-			  { "orderable": false, "targets": [0,1,2,3,4,5,6,8,9] }, //设置列不可排序
-      		],
-			"order": [[7,"asc"]], //默认排序列
+			  { "orderable": false, "targets": [0,1,2,3,4,5,6,7,8,11,12] }, //设置列不可排序
+				//更新节点
+			  {"targets":[6], createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
+				{{if gt (session "auth") 2}}
+				var aInput;
+				$(cell).click(function () {
+					$(this).html(createComboxEvent(rowData._id));
+					var aInput = $(this).find(":input");
+					aInput.focus().val(cellData);
+				});
+				$(cell).on("click", ":input", function (e) {
+					e.stopPropagation();
+				});
+				$(cell).on("change", ":input", function () {
+					$(this).blur();
+				});
+				$(cell).on("blur", ":input", function () {
+					var text = $(this).find("option:selected").text();
+					luamovecodetable.cell(cell).data(text);
+					cellData = text;
+				});
+				{{end}}
+			}},
+
+			],
+			"order": [[9,"asc"]], //默认排序列
 			"lengthChange":false,
 			"serverSide": true,
 			"searching": true,
@@ -65,7 +91,9 @@
 					return "<input type='checkbox' ismove='"+row.ismove+"' state='"+row.state+"' code='"+row.code+"' movevent='"+row.toevent+"'/>"
 				}},
 	      		{"data": "site",width:"200px"},
-				{"data": "channel"},
+				{"data": "channel",render:function (val,a,row){
+					return "<a href='"+row.href+"' title='"+val+"' target='_blank'>"+val+"</a>"
+				}},
 				{"data": "code"},
 				{"data": "ismove",width:"30px",render:function (val){
 					if(val){
@@ -76,6 +104,8 @@
 				}},
 				{"data": "fromevent",width:"30px"},
 				{"data": "toevent",width:"30px"},
+				{"data": "maxpage"},
+				{"data": "cycletime"},
 				{"data": "datanum"},
 				{"data": "ptimedatanum"},
 				{"data": "state",render:function (val){
@@ -235,7 +265,24 @@
 	  }
 	})
   }
-  
+
+  function CloseAll() {
+	  showConfirm("确定关闭所有爬虫?", function() {
+		  $.ajax({
+			  url: "/center/luamove/closeall",
+			  type: "post",
+			  success:function(r){
+				  if(r&&r.ok){
+					  showTip("更新成功", 1000);
+					  luamovecodetable.ajax.reload();
+				  }else{
+					  showTip("更新失败", 2000);
+				  }
+			  }
+		  })
+	  })
+  }
+
   function selectrow(me){
 		var sel=$(me);
 		var isSelected=sel.prop('checked');
@@ -245,6 +292,33 @@
 			$("#luamovecode td input[type=checkbox]").prop("checked",false);
 		}
 	}
+
+	//修改节点
+	function createComboxEvent(id){
+		var events={{.T.events}};
+		var spiderEvent="";
+		for(k in events){
+			spiderEvent+="<option value='"+events[k]+"'>"+events[k]+"</option>"
+		}
+		return "<select onchange='updateesp(this.value,\""+id+"\")' class='form-control input-sm'>"+spiderEvent+"</select>"
+	};
+	function updateesp(event,id){
+		console.log(event,id);
+		$.ajax({
+			url:"/center/luamove/updatetoevent",
+			type:"post",
+			data:{
+				"event":event,
+				"id":id
+			},
+			success:function(r){
+				if(!r){
+					showTip("修改失败", 1000, function() {});
+				}
+				luamovecodetable.ajax.reload();
+			}
+		})
+	}
  </script>
 </div>
 {{include "bottom.html"}}

+ 1 - 1
src/web/templates/spiderbase.html

@@ -184,7 +184,7 @@
 							增量节点
 						</label>
 						<div class="col-sm-7">
-							<select name="OtherBase.SpiderMoveEvent" id="spidermovevent" class="form-control">
+							<select name="OtherBase.SpiderMoveEvent" disabled id="spidermovevent" class="form-control">
 <!--								<option value="bid" disabled style="color:#DADADA">-->
 <!--									高性能模式-->
 <!--								</option>-->