Kaynağa Gözat

爬虫挂起状态

maxiaoshan 3 yıl önce
ebeveyn
işleme
8737f43aae

+ 40 - 19
src/front/front.go

@@ -28,24 +28,25 @@ import (
 
 type Front struct {
 	*xweb.Action
-	login        xweb.Mapper `xweb:"/"`
-	logout       xweb.Mapper `xweb:"/center/logout"`               //退出
-	loadIndex    xweb.Mapper `xweb:"/center"`                      //控制中心
-	spidernew    xweb.Mapper `xweb:"/center/spider"`               //爬虫新建
-	reg          xweb.Mapper `xweb:"/center/reg"`                  //爬虫注册
-	assign       xweb.Mapper `xweb:"/center/user/assign"`          //分配爬虫
-	loadSpider   xweb.Mapper `xweb:"/center/spider/edit/(.*)"`     //爬虫加载
-	viewSpider   xweb.Mapper `xweb:"/center/spider/view/(.*)"`     //爬虫查看
-	downSpider   xweb.Mapper `xweb:"/center/spider/download/(.*)"` //爬虫下载
-	upState      xweb.Mapper `xweb:"/center/spider/upstate"`       //爬虫状态更新
-	assort       xweb.Mapper `xweb:"/center/spider/assort"`        //审核人员分类
-	batchShelves xweb.Mapper `xweb:"/center/spider/batchShelves"`  //批量上下架
-	checktime    xweb.Mapper `xweb:"/center/spider/checktime"`     //爬虫核对
-	disables     xweb.Mapper `xweb:"/center/spider/disable"`       //批量作废
-	changeEvent  xweb.Mapper `xweb:"/center/changeEvent"`          //节点更新
-	getJson      xweb.Mapper `xweb:"/center/spider/json"`          //
-	delRedis     xweb.Mapper `xweb:"/center/spider/delRedis"`      //清理Redis
-	updateESP    xweb.Mapper `xweb:"/center/spider/updateesp"`     //修改爬虫的节点/状态/平台
+	login           xweb.Mapper `xweb:"/"`
+	logout          xweb.Mapper `xweb:"/center/logout"`                 //退出
+	loadIndex       xweb.Mapper `xweb:"/center"`                        //控制中心
+	spidernew       xweb.Mapper `xweb:"/center/spider"`                 //爬虫新建
+	reg             xweb.Mapper `xweb:"/center/reg"`                    //爬虫注册
+	assign          xweb.Mapper `xweb:"/center/user/assign"`            //分配爬虫
+	loadSpider      xweb.Mapper `xweb:"/center/spider/edit/(.*)"`       //爬虫加载
+	viewSpider      xweb.Mapper `xweb:"/center/spider/view/(.*)"`       //爬虫查看
+	downSpider      xweb.Mapper `xweb:"/center/spider/download/(.*)"`   //爬虫下载
+	upState         xweb.Mapper `xweb:"/center/spider/upstate"`         //爬虫状态更新
+	assort          xweb.Mapper `xweb:"/center/spider/assort"`          //审核人员分类
+	batchShelves    xweb.Mapper `xweb:"/center/spider/batchShelves"`    //批量上下架
+	checktime       xweb.Mapper `xweb:"/center/spider/checktime"`       //爬虫核对
+	disables        xweb.Mapper `xweb:"/center/spider/disable"`         //批量作废
+	changeEvent     xweb.Mapper `xweb:"/center/changeEvent"`            //节点更新
+	getJson         xweb.Mapper `xweb:"/center/spider/json"`            //
+	delRedis        xweb.Mapper `xweb:"/center/spider/delRedis"`        //清理Redis
+	updateESP       xweb.Mapper `xweb:"/center/spider/updateesp"`       //修改爬虫的节点/状态/平台
+	updatePendState xweb.Mapper `xweb:"/center/spider/updatePendState"` //修改爬虫的节点/状态/平台
 
 	spiderModel xweb.Mapper `xweb:"/center/model"`           //获取补充模型
 	runStep     xweb.Mapper `xweb:"/center/run"`             //方法测试
@@ -555,10 +556,11 @@ func (f *Front) Importfile() {
 						o["platform"] = cells[9].Value
 						weigh, _ := cells[10].Int()
 						estimate, _ := cells[11].Int()
-						qu.Debug(weigh, estimate)
 						o["estimate"] = estimate
 						o["weight"] = weigh
+						//导入默认字段
 						o["spidercompete"] = true
+						o["pendstate"] = 0
 						//table := cells[6].Value
 						//o["table"] = table
 						//o["transfercode"] = qu.IntAll(Transfercode[table])
@@ -839,6 +841,25 @@ func (f *Front) DelRedis() {
 	f.ServeJson(err)
 }
 
+func (f *Front) UpdatePendState() {
+	success := false
+	pendstate, _ := f.GetInteger("pendstate")
+	code := f.GetString("code")
+	stype := f.GetString("stype")
+	qu.Debug(code, stype, pendstate)
+	success = u.MgoE.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"pendstate": pendstate}}, false, false)
+	if success {
+		if stype == "code" { //爬虫挂起时,关闭所有任务
+			u.MgoE.Update("task", map[string]interface{}{"s_code": code, "i_state": map[string]interface{}{"$ne": 6}}, map[string]interface{}{"$set": map[string]interface{}{"i_state": 6}}, false, true)
+		} else if stype == "task" { //任务挂起任务时任务关闭
+			id := f.GetString("id")
+			u.MgoE.UpdateById("task", id, map[string]interface{}{"$set": map[string]interface{}{"i_pendstate": pendstate, "i_state": 6}})
+		}
+	}
+
+	f.ServeJson(map[string]interface{}{"success": success})
+}
+
 func (f *Front) UpdateESP() {
 	val := f.GetString("val")
 	w := f.GetString("w")

+ 7 - 7
src/front/spider.go

@@ -1187,7 +1187,7 @@ func IsHasUpState(auth, state int) bool {
 	return rep
 }
 
-var list_fields = `{"_id":1,"code":1,"createuser":1,"modifyuser":1,"modifytime":1,"l_uploadtime":1,"l_checktime":1,"state":1,"param_common":1,"event":1,"urgency":1,"platform":1}`
+var list_fields = `{"_id":1,"code":1,"createuser":1,"modifyuser":1,"modifytime":1,"l_uploadtime":1,"l_checktime":1,"state":1,"param_common":1,"event":1,"urgency":1,"platform":1,"pendstate":1}`
 
 //脚本管理,结合爬虫运行信息
 func (f *Front) LuaList() {
@@ -1344,12 +1344,12 @@ func (f *Front) Heart() {
 			}
 			ut := qu.Int64All(l["updatetime"])
 			l["updatetime"] = qu.FormatDateByInt64(&ut, qu.Date_Full_Layout)
-			l["isfindlist"] = "否"
-			typeList := qu.IntAll((*d)["type_list"])
-			strList := qu.ObjToString((*d)["str_list"])
-			if typeList == 1 && strings.Contains(strList, "findListHtml") {
-				l["isfindlist"] = "是"
-			}
+			//l["isfindlist"] = "否"
+			//typeList := qu.IntAll((*d)["type_list"])
+			//strList := qu.ObjToString((*d)["str_list"])
+			//if typeList == 1 && strings.Contains(strList, "findListHtml") {
+			//	l["isfindlist"] = "是"
+			//}
 		}
 
 		f.ServeJson(map[string]interface{}{"draw": draw, "data": list, "recordsFiltered": count, "recordsTotal": count})

+ 68 - 70
src/main_test.go

@@ -2,65 +2,63 @@
 package main
 
 import (
+	"github.com/lauyoume/gopinyin"
 	"log"
-	"luaweb/spider"
-	"luaweb/util"
 	mgdb "qfw/util/mongodb"
+	"spider"
 	"testing"
 	"time"
-
-	"github.com/lauyoume/gopinyin"
 )
 
 //模板测试
-func Test_Tmp(t *testing.T) {
-	proficient := ""
-	//通用变量配置
-	common := []interface{}{
-		"upload_test", "中央采购网-上传测试", "测试脚本栏目", true, 1, 10, 30, "bidding", "utf8", 1, 4002,
-		"http://www.ccgp.gov.cn/zycg/zycgdt/index.htm",
-	}
-	//最新时间配置
-	ptime := []interface{}{
-		"yyyyMMddHHmm",
-		"http://www.ccgp.gov.cn/zycg/zycgdt/index.htm",
-		"ul li em:eq(0)",
-	}
-	//	proficient = `function getLastPublishTime()
-	//					local content = download("",{})
-	//					return lastpushtime
-	//				end`
-	log.Println(spider.GetLastPublishTime(common, ptime, proficient, 0))
-	//列表页配置
-	list := []interface{}{
-		"http://www.ccgp.gov.cn/zycg/zycgdt/index#pageno#.htm",
-		"'http://www.ccgp.gov.cn/zycg/zycgdt/index.htm','http://www.ccgp.gov.cn/zycg/zycgdt/index_1.htm'",
-		"ul#main_list_lt_list>li",
-		"a:eq(1):attr(href)",
-		"a:eq(1):attr(title)",
-		"em:eq(0)",
-		"yyyyMMddHHmm",
-	}
-	model := map[string]interface{}{}
-	model["type"] = "other"
-	model["area"] = "HA"
-	model["city"] = "郑州"
-	model["publishdept"] = "郑州市财政厅"
-	//	proficient = `function downloadAndParseListPage(pageno)
-	//				end`
-	log.Println(spider.GetPageList(common, list, model, proficient, 0))
-	content := []interface{}{
-		"div.TRS_Editor",
-		"div.TRS_Editor",
-	}
-	data := map[string]interface{}{}
-	data["title"] = "苏州市召开市级政府采购信用融资工作座谈会"
-	data["href"] = "http://www.zfcg.suzhou.gov.cn/html/content/20160729165741501.shtml"
-	data["publishtime"] = "2016-08-17 12:12:12"
-	//	proficient = `function downloadDetailPage(data)
-	//			end`
-	log.Println(spider.GetContentInfo(common, content, data, proficient, 0))
-}
+//func Test_Tmp(t *testing.T) {
+//	proficient := ""
+//	//通用变量配置
+//	common := []interface{}{
+//		"upload_test", "中央采购网-上传测试", "测试脚本栏目", true, 1, 10, 30, "bidding", "utf8", 1, 4002,
+//		"http://www.ccgp.gov.cn/zycg/zycgdt/index.htm",
+//	}
+//	//最新时间配置
+//	ptime := []interface{}{
+//		"yyyyMMddHHmm",
+//		"http://www.ccgp.gov.cn/zycg/zycgdt/index.htm",
+//		"ul li em:eq(0)",
+//	}
+//	//	proficient = `function getLastPublishTime()
+//	//					local content = download("",{})
+//	//					return lastpushtime
+//	//				end`
+//	log.Println(spider.GetLastPublishTime(common, ptime, proficient, 0, 0))
+//	//列表页配置
+//	list := []interface{}{
+//		"http://www.ccgp.gov.cn/zycg/zycgdt/index#pageno#.htm",
+//		"'http://www.ccgp.gov.cn/zycg/zycgdt/index.htm','http://www.ccgp.gov.cn/zycg/zycgdt/index_1.htm'",
+//		"ul#main_list_lt_list>li",
+//		"a:eq(1):attr(href)",
+//		"a:eq(1):attr(title)",
+//		"em:eq(0)",
+//		"yyyyMMddHHmm",
+//	}
+//	model := map[string]interface{}{}
+//	model["type"] = "other"
+//	model["area"] = "HA"
+//	model["city"] = "郑州"
+//	model["publishdept"] = "郑州市财政厅"
+//	//	proficient = `function downloadAndParseListPage(pageno)
+//	//				end`
+//	log.Println(spider.GetPageList(common, list, model, proficient, 0, "bid", 0))
+//	content := []interface{}{
+//		"div.TRS_Editor",
+//		"div.TRS_Editor",
+//	}
+//	data := map[string]interface{}{}
+//	data["title"] = "苏州市召开市级政府采购信用融资工作座谈会"
+//	data["href"] = "http://www.zfcg.suzhou.gov.cn/html/content/20160729165741501.shtml"
+//	data["publishtime"] = "2016-08-17 12:12:12"
+//	//	proficient = `function downloadDetailPage(data)
+//	//			end`
+//	log.Println(spider.GetContentInfo(common, content, data, proficient, "bid", 0, 0))
+//}
 
 //保存更新爬虫
 func Test_saveSpider(t *testing.T) {
@@ -126,26 +124,26 @@ func Test_saveSpider(t *testing.T) {
 }
 
 //生成lua文件测试
-func Test_createFile(t *testing.T) {
-	mgdb.InitMongodbPool(2, "192.168.3.18:27080", "luaweb")
-	scritp := spider.GetScript("upload_test")
-	if scritp != "" {
-		_, err := spider.CreateFile("upload_test", scritp)
-		log.Println(err)
-	}
-}
+//func Test_createFile(t *testing.T) {
+//	mgdb.InitMongodbPool(2, "192.168.3.18:27080", "luaweb")
+//	scritp := spider.GetScript("upload_test")
+//	if scritp != "" {
+//		_, err := spider.CreateFile("upload_test", scritp)
+//		log.Println(err)
+//	}
+//}
 
 //上传脚本
-func Test_uploadFile(t *testing.T) {
-	util.InitMsgClient(util.Config.Msgserveraddr, util.Config.Msgname)
-	mgdb.InitMongodbPool(2, "192.168.3.18:27080", "luaweb")
-	ret, err := spider.UpLoadScript("upload_test", 7001)
-	if err != nil {
-		log.Println("err", err)
-	} else {
-		log.Println("ret", ret)
-	}
-}
+//func Test_uploadFile(t *testing.T) {
+//	util.InitMsgClient(util.Config.Msgserveraddr, util.Config.Msgname)
+//	mgdb.InitMongodbPool(2, "192.168.3.18:27080", "luaweb")
+//	ret, err := spider.UpLoadScript("upload_test", 7001)
+//	if err != nil {
+//		log.Println("err", err)
+//	} else {
+//		log.Println("ret", ret)
+//	}
+//}
 
 //获取拼音首子母
 func Test_getFirstName(t *testing.T) {

+ 8 - 10
src/web/templates/heart.html

@@ -24,11 +24,10 @@
                   <th>爬虫</th>
                   <th>节点</th>
           		  <th>维护人</th>
-          		  <th>列表页心跳</th>
-                  <th>详情页心跳</th>
-                  <th>采集心跳</th>
-                  <th>采集量心跳</th>
-                  <th>IsFindList</th>
+          		  <th>列表页执行心跳</th>
+                  <th>详情页执行心跳</th>
+                  <th>列表页采集成功心跳</th>
+                  <th>详情页采集成功心跳</th>
                   <th>更新时间</th>
 <!--                  <th class="hidden-xs">操作</th>-->
                 </tr>
@@ -46,7 +45,7 @@
               "url": "/js/dataTables.chinese.lang"
           },
 		"columnDefs": [
-		  { "orderable": false, "targets": [0,1,2,3,4,9] } //设置列不可排序
+		  { "orderable": false, "targets": [0,1,2,3,4] } //设置列不可排序
 		],
     "order": [[5,"asc"]], //默认排序列
 		"processing":true,
@@ -54,8 +53,8 @@
 		"searching": true,
 		"ordering": true,
 		"info": true,
-    "paging": true,
-		"autoWidth": true,
+        "paging": true,
+		"autoWidth": false,
     "iDisplayLength": 50, //每页初始显示5条记录
 
 		"ajax": {
@@ -87,9 +86,8 @@
 		{ "data": "modifyuser"},
         { "data": "list"},
         { "data": "detail"},
-        { "data": "detailexecute"},
         { "data": "findlist"},
-        { "data": "isfindlist"},
+        { "data": "detailexecute",width:"72px"},
         { "data": "updatetime"}
     ],
     "fnServerParams": function (e) {  

+ 178 - 141
src/web/templates/index.html

@@ -142,7 +142,8 @@
           				<th>最后修改时间</th>
           				<th>状态</th>
 						<th>平台</th>
-                  <th class="hidden-xs">操作</th>
+						<th>挂起</th>
+                  		<th class="hidden-xs">操作</th>
                 </tr>
                 </thead>
               </table>
@@ -159,107 +160,132 @@ $(function(){
               "url": "/js/dataTables.chinese.lang"
           },
 		"columnDefs": [
-	    { "orderable": false, "targets": [0,10,11] },
-      //更新节点
-		  {"targets":[6], createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
-  			  {{if gt (session "auth") 2}}
-  			    var aInput;
-  			    $(cell).click(function () {
-  				  $(this).html(createComboxEvent(rowData._id,rowData.state,rowData.code));
-  				  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();
-  				    ttable.cell(cell).data(text);
-  				    cellData = text;
-  			    });
-		    {{end}}
-		  }},
-		  //更新状态
-      {"targets":[9], createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
-		    {{if gt (session "auth") 2}}
-		      var aInput;
-		      $(cell).click(function () {
-			    if(cellData!=4&&cellData!=7&&cellData!=8&&cellData!=9&&cellData!=10){
-			      return
-			    }
-			    $(this).html(createComboxState(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();
-      			if(text=="待完成"){
-      			  text = 0
-      			}else if (text=="已作废"){
-      			  text = 4
-      			}else if (text=="无发布"){
-      			  text = 7
-      			}else if (text=="需登录"){
-      			  text = 8
-      			}else if (text=="无法处理"){
-      			  text = 9
-      			}else if (text=="已删除"){
-      			  text = 10
-      			}else if (text=="已上线"){
-      			  text = 11
-      			}
-			    ttable.cell(cell).data(text);
-			      cellData = text;
-		      });
-		    {{end}}
-		  }},
-      //更新平台
-      	{"targets":[10], createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
-		    {{if gt (session "auth") 2}}
-		      var aInput;
-		      $(cell).click(function () {
-			    $(this).html(createComboxPlatform(rowData.code,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();
-      			if(text=="待完成"){
-      			  text = 0
-      			}else if (text=="已作废"){
-      			  text = 4
-      			}else if (text=="无发布"){
-      			  text = 7
-      			}else if (text=="需登录"){
-      			  text = 8
-      			}else if (text=="无法处理"){
-      			  text = 9
-      			}else if (text=="已删除"){
-      			  text = 10
-      			}else if (text=="已上线"){
-      			  text = 11
-      			}
-			    ttable.cell(cell).data(text);
-			      cellData = text;
-		      });
-		    {{end}}
-		  }}
-	  ],
+			{ "orderable": false, "targets": [0,10] },
+			//更新节点
+			{"targets":[6], createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
+				  {{if gt (session "auth") 2}}
+					var aInput;
+					$(cell).click(function () {
+					  $(this).html(createComboxEvent(rowData._id,rowData.state,rowData.code));
+					  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();
+						ttable.cell(cell).data(text);
+						cellData = text;
+					});
+				{{end}}
+			  }},
+			//更新状态
+			{"targets":[9], createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
+				{{if gt (session "auth") 2}}
+				  var aInput;
+				  $(cell).click(function () {
+					if(cellData!=4&&cellData!=7&&cellData!=8&&cellData!=9&&cellData!=10){
+					  return
+					}
+					$(this).html(createComboxState(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();
+					if(text=="待完成"){
+					  text = 0
+					}else if (text=="已作废"){
+					  text = 4
+					}else if (text=="无发布"){
+					  text = 7
+					}else if (text=="需登录"){
+					  text = 8
+					}else if (text=="无法处理"){
+					  text = 9
+					}else if (text=="已删除"){
+					  text = 10
+					}else if (text=="已上线"){
+					  text = 11
+					}
+					ttable.cell(cell).data(text);
+					  cellData = text;
+				  });
+				{{end}}
+			  }},
+			//更新平台
+			{"targets":[10], createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
+				{{if gt (session "auth") 2}}
+				  var aInput;
+				  $(cell).click(function () {
+					$(this).html(createComboxPlatform(rowData.code,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();
+					if(text=="待完成"){
+					  text = 0
+					}else if (text=="已作废"){
+					  text = 4
+					}else if (text=="无发布"){
+					  text = 7
+					}else if (text=="需登录"){
+					  text = 8
+					}else if (text=="无法处理"){
+					  text = 9
+					}else if (text=="已删除"){
+					  text = 10
+					}else if (text=="已上线"){
+					  text = 11
+					}
+					ttable.cell(cell).data(text);
+					  cellData = text;
+				  });
+				{{end}}
+			  }},
+			//爬虫挂起
+			{"targets":[11], createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
+				var aInput;
+				$(cell).click(function () {
+					$(this).html(createComboxPendState(rowData.code));
+					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();
+					if(text == "否"){
+						text = 0
+					}else if(text == "是"){
+						text = 1
+					}
+					ttable.cell(cell).data(text);
+					cellData = text;
+				});
+			}}
+		],
 		"order": [[1,"desc"]],
 		"processing":true,
 		"serverSide": true,
@@ -338,6 +364,13 @@ $(function(){
 				return val
 			}},
 			{ "data": "platform"},
+			{ "data": "pendstate",render:function(val){
+				if(val == 0){
+					return "否"
+				}else{
+					return "是"
+				}
+			}},
 			{ "data": "param_common","width":"95px",render:function(val,a,row){
 				var div=$("<div><div class=\"btn-group\"></div></div>")
 				var currentuser="{{session "username"}}";
@@ -508,11 +541,11 @@ $(function(){
 			$("#spider td input[type=checkbox]").prop("checked",false);
 		}
 	}
-  function spidercopy(){
-      $("#modal-spidercopy").modal("show");
-  } 
-  //复制爬虫
-  function comfirm_spidercopy(){
+	function spidercopy(){
+		$("#modal-spidercopy").modal("show");
+	}
+    //复制爬虫
+	function comfirm_spidercopy(){
     var code = $("#spidercopy").val();
     if(code != ""){
       $.ajax({
@@ -532,7 +565,30 @@ $(function(){
       alert("爬虫不能为空!")
     }
   }
-{{if gt (session "auth") 1}}	
+  	function createComboxPendState(code){
+	return "<select onchange='changeCodePendState(this.value,\""+code+"\")' class='form-control input-sm'>"+
+			"<option value=1>是</option>"+
+			"<option value=0>否</option>"+
+			"</select>"
+};
+	function changeCodePendState(pendstate,code){
+		$.ajax({
+			url:"/center/spider/updatePendState",
+			type:"post",
+			data:{
+				"pendstate":pendstate,
+				"code":code,
+				"stype":"code"
+			},
+			success:function(r){
+				if(!r || !r.success){
+					showTip("修改失败", 1000, function() {});
+				}
+				ttable.ajax.reload();
+			}
+		})
+	}
+{{if gt (session "auth") 1}}
 	function refuse(me){
 		var $r=window.prompt("确定打回?请输入打回原因")
 		if($r){
@@ -550,26 +606,7 @@ $(function(){
 				}
 			})
 		}
-    } 	
-	
-	//function disable(me){
-	//	showConfirm("确定作废?", function() {
-	//		$.ajax({
-	//			url:$(me).attr("hrefs"),
-	//			type:"post",
-	//			success:function(r){
-	//				if(r){
-	//					//showTip("作废成功", 1000, function() {});
-	//					ttable.ajax.reload(null,false);
-	//				}else{
-	///					showTip("作废失败", 1000, function() {});
-	//				}
-	//			}
-	//		})
-	//	});
-    //}
-   
-    
+    }
 	function assign(){
 		var names=[];
 		$("#spider td input[type=checkbox]").each(function(){
@@ -666,7 +703,7 @@ $(function(){
 	function disables_cancel(){
 		$("#modal-disables").modal("hide");
 	}
-  function spidercopy_cancel(){
+  	function spidercopy_cancel(){
 		$("#modal-spidercopy").modal("hide");
 	}
 	//分配爬虫
@@ -707,16 +744,16 @@ $(function(){
 			return;
 		}	
 	};
-  //修改节点
-  function createComboxEvent(id,state,code){
-    var events={{.T.events}};
-    var spiderEvent="";
+    //修改节点
+    function createComboxEvent(id,state,code){
+    	var events={{.T.events}};
+    	var spiderEvent="";
 		for(k in events){
 			spiderEvent+="<option value='"+events[k]+"'>"+events[k]+"</option>"
 		}
-    return "<select onchange='changeEventOrStateOrPlatform(this.value,\"event\",\""+state+"\",\""+code+"\",\""+id+"\")' class='form-control input-sm'>"+spiderEvent+"</select>"
-  };
-  function createComboxState(id){
+    	return "<select onchange='changeEventOrStateOrPlatform(this.value,\"event\",\""+state+"\",\""+code+"\",\""+id+"\")' class='form-control input-sm'>"+spiderEvent+"</select>"
+    };
+    function createComboxState(id){
     return "<select id='task_state'  onchange='changeEventOrStateOrPlatform(this.value,\"state\",\"\",\"\",\""+id+"\")' class='form-control input-sm'>"+
             "<option value='0' class='text-info text-bold'>待完成</option>"+
       		  "<option disabled value='1'>待审核</option>"+
@@ -732,16 +769,16 @@ $(function(){
             "<option disabled value='10'>已上线</option>"+
           +"</select>"
   };
-  function createComboxPlatform(code,id){
-    return "<select onchange='changeEventOrStateOrPlatform(this.value,\"platform\",\"\",\""+code+"\",\""+id+"\")' class='form-control input-sm'>"+
+    function createComboxPlatform(code,id){
+    	return "<select onchange='changeEventOrStateOrPlatform(this.value,\"platform\",\"\",\""+code+"\",\""+id+"\")' class='form-control input-sm'>"+
     			  "<option value='golua平台'>golua平台</option>"+
     			  "<option value='python'>python</option>"+
     				"<option value='通用爬虫'>通用爬虫</option>"+
     				"<option value='chrome插件'>chrome插件</option>"+
           "</select>"
   };
-  function changeEventOrStateOrPlatform(val,w,s,c,id){
-    $.ajax({
+    function changeEventOrStateOrPlatform(val,w,s,c,id){
+    	$.ajax({
 			url:"/center/spider/updateesp",
 			type:"post",
 			data:{
@@ -751,7 +788,7 @@ $(function(){
 				"s":s,
 				"c":c
 			},
-      success:function(r){
+       success:function(r){
 				if(r=="n"){
           showTip("修改失败", 1000, function() {});
         }

+ 72 - 13
src/web/templates/mytask.html

@@ -16,17 +16,18 @@
 					<table id="mytask" class="table table-bordered table-striped">
 						<thead>
 							<tr>
-								<td>爬虫代码</td>
-								<td>网站名称</td>
-								<td>栏目名称</td>
-								<td>节点</td>
-								<td>任务状态</td>
-                				<td>类型</td>
-								<td>紧急度</td>
-								<td>次数</td>
-								<td>频率次数</td>
-								<td>来源</td>
-								<td>最迟完成时间</td>
+								<th>爬虫代码</th>
+								<th>网站名称</th>
+								<th>栏目名称</th>
+								<th>节点</th>
+								<th>任务状态</th>
+                				<th>类型</th>
+								<th>紧急度</th>
+								<th>次数</th>
+								<th>频率次数</th>
+								<th>来源</th>
+								<th>最迟完成时间</th>
+								<th>挂起</th>
 								<th class="hidden-xs">操作</th>
 							</tr>
 						</thead>
@@ -48,7 +49,35 @@
 				
        		 },
 			"columnDefs": [
-			    { "orderable": false, "targets": [0,1,2,3,4,5,11] }
+			    { "orderable": false, "targets": [0,1,2,3,4,5,12] },
+				//爬虫挂起
+				{"targets":[11], createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
+						var aInput;
+						$(cell).click(function () {
+							if( rowData.i_state == "关闭"||rowData.i_pendstate ==1 ){//任务不能由挂起转为非挂起状态;关闭任务不能挂起操作
+								return
+							}
+							$(this).html(createComboxPendState(rowData.s_code,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();
+							if(text == "否"){
+								text = 0
+							}else if(text == "是"){
+								text = 1
+							}
+							mytask.cell(cell).data(text);
+							cellData = text;
+						});
+					}}
 			],	
       		"order": [[10,"desc"]], //默认排序列
 			"lengthChange":false,
@@ -99,6 +128,13 @@
 				}},
 				{"data": "s_source"},
 				{"data":"l_complete"},
+				{ "data": "i_pendstate",render:function(val){
+					if(val == 0||val == undefined){
+						return "否"
+					}else{
+						return "是"
+					}
+				}},
 				{"data":"_id",render:function(val,a,row){
 					var div=$("<div><div class=\"btn-group\"></div></div>")
 					var buttonWatch=$('<a type="button" class="btn btn-sm btn-default">查看</a>');
@@ -238,7 +274,30 @@
 	function checkclick(urgency){
 		mytask.ajax.reload();
 	}
-	
+	function createComboxPendState(code,id){
+		return "<select onchange='changeCodePendState(this.value,\""+code+"\",\""+id+"\")' class='form-control input-sm'>"+
+				"<option value=1>是</option>"+
+				"<option value=0>否</option>"+
+				"</select>"
+	};
+	function changeCodePendState(pendstate,code,id){
+		$.ajax({
+			url:"/center/spider/updatePendState",
+			type:"post",
+			data:{
+				"pendstate":pendstate,
+				"id":id,
+				"code":code,
+				"stype":"task"
+			},
+			success:function(r){
+				if(!r || !r.success){
+					showTip("修改失败", 1000, function() {});
+				}
+				mytask.ajax.reload();
+			}
+		})
+	}
 	</script>
 </div>
 {{include "bottom.html"}}

+ 78 - 19
src/web/templates/task.html

@@ -64,21 +64,22 @@
 					<table id="task" class="table table-bordered table-striped">
 						<thead>
 							<tr>
-								<td>网址</td>
+								<th>网址</th>
 								<th><input type="checkbox" id="selrow" onclick="selectrow(this)"/></th>
-								<td>编号</td>
-								<td>网站名称</td>
-								<td>栏目名称</td>
-								<td>爬虫代码</td>
-								<td>状态</td>
-               					<td>类型</td>
-								<td>维护人</td>
-								<td>紧急度</td>
-								<td>节点</td>
-								<td>次数</td>
-								<td>频率次数</td>
-                				<td>来源</td>
-								<td>最迟完成时间</td>
+								<th>编号</th>
+								<th>网站名称</th>
+								<th>栏目名称</th>
+								<th>爬虫代码</th>
+								<th>状态</th>
+               					<th>类型</th>
+								<th>维护人</th>
+								<th>紧急度</th>
+								<th>节点</th>
+								<th>次数</th>
+								<th>频率次数</th>
+                				<th>来源</th>
+								<th>最迟完成时间</th>
+								<th>挂起</th>
 								<th class="hidden-xs">操作</th>
 							</tr>
 						</thead>
@@ -114,8 +115,36 @@
        		 },
 			"columnDefs": [
 				{ "targets": 0 ,"bVisible": false}, //隐藏列
-				{ "orderable": false, "targets": [0,1,2,3,4,5,6,7,8,15] } //设置列不可排序
-			],	
+				{ "orderable": false, "targets": [0,1,2,3,4,5,6,7,8,16] }, //设置列不可排序
+				//爬虫挂起
+				{"targets":[15], createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
+					var aInput;
+					$(cell).click(function () {
+						if( rowData.i_state == "关闭"||rowData.i_pendstate ==1 ){//任务不能由挂起转为非挂起状态;关闭任务不能挂起操作
+							return
+						}
+						$(this).html(createComboxPendState(rowData.s_code,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();
+						if(text == "否"){
+							text = 0
+						}else if(text == "是"){
+							text = 1
+						}
+						ttabletask.cell(cell).data(text);
+						cellData = text;
+					});
+				}}
+			],
 			"order": [[14,"desc"]], //默认排序列
 			"lengthChange":false,
 			"serverSide": true,
@@ -193,6 +222,13 @@
 				{"data": "l_complete","width":"8%",render:function(val,a,row){
 							return val;
 						}},
+				{ "data": "i_pendstate",render:function(val){
+					if(val == 0||val == undefined){
+						return "否"
+					}else{
+						return "是"
+					}
+				}},
 				{"data": "_id","width":"91px",render:function(val,a,row){
 					var div=$("<div><div class=\"btn-group\"></div></div>")
 					var buttonWatch=$('<a type="button" target="_blank" class="btn btn-sm btn-default">编辑</a>');
@@ -316,9 +352,9 @@
 				taskEvent+
 			"</select></div>"
 			$("#task_filter").prepend("&nbsp;&nbsp;");
-      $("#task_filter").prepend(selectEvent);
+      		$("#task_filter").prepend(selectEvent);
 
-      var modifyuser="<option value='-1'>全部</option>"
+      		var modifyuser="<option value='-1'>全部</option>"
 			var modifyusers={{.T.modifyusers}}
 			for(k in modifyusers){
 				modifyuser+="<option value='"+modifyusers[k]["_id"]+"'>"+modifyusers[k]["s_name"]+"</option>"
@@ -338,7 +374,30 @@
 			})
    		})
 	})
-	
+  function createComboxPendState(code,id){
+	  return "<select onchange='changeCodePendState(this.value,\""+code+"\",\""+id+"\")' class='form-control input-sm'>"+
+			  "<option value=1>是</option>"+
+			  "<option value=0>否</option>"+
+			  "</select>"
+  };
+  function changeCodePendState(pendstate,code,id){
+	  $.ajax({
+		  url:"/center/spider/updatePendState",
+		  type:"post",
+		  data:{
+			  "pendstate":pendstate,
+			  "id":id,
+			  "code":code,
+			  "stype":"task"
+		  },
+		  success:function(r){
+			  if(!r || !r.success){
+				  showTip("修改失败", 1000, function() {});
+			  }
+			  ttabletask.ajax.reload();
+		  }
+	  })
+  }
 	function checkclick(urgency){
 		ttabletask.ajax.reload();
 	}