maxiaoshan vor 4 Jahren
Ursprung
Commit
0ecc23ec42
6 geänderte Dateien mit 407 neuen und 71 gelöschten Zeilen
  1. 21 19
      src/front/front.go
  2. 38 14
      src/front/site.go
  3. 184 0
      src/timetask/timetask.go
  4. 53 2
      src/util/util.go
  5. 51 9
      src/web/templates/index.html
  6. 60 27
      src/web/templates/sitelist.html

+ 21 - 19
src/front/front.go

@@ -27,24 +27,24 @@ 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
-	updateEventOrState xweb.Mapper `xweb:"/center/spider/updateeventorstate"` //修改爬虫的节点和状态
+	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"`     //修改爬虫的节点和状态
 
 	spiderModel xweb.Mapper `xweb:"/center/model"`           //获取补充模型
 	runStep     xweb.Mapper `xweb:"/center/run"`             //方法测试
@@ -895,7 +895,7 @@ func (f *Front) DelRedis() {
 	f.ServeJson(err)
 }
 
-func (f *Front) UpdateEventOrState() {
+func (f *Front) UpdateESP() {
 	val := f.GetString("val")
 	w := f.GetString("w")
 	id := f.GetString("id")
@@ -908,6 +908,8 @@ func (f *Front) UpdateEventOrState() {
 	}
 	if w == "state" { //修改状态为待完成
 		set["state"] = 0
+	} else if w == "platform" {
+		set["platform"] = val
 	} else { //修改节点
 		event, _ := strconv.Atoi(val)
 		set["event"] = event

+ 38 - 14
src/front/site.go

@@ -18,15 +18,15 @@ import (
 
 type Site struct {
 	*xweb.Action
-	loadIndex     xweb.Mapper `xweb:"/center/site/sitelist"`      //控制中心
+	siteList      xweb.Mapper `xweb:"/center/site/sitelist"`      //控制中心
 	saveSite      xweb.Mapper `xweb:"/center/site/savesite"`      //新增站点
 	importFile    xweb.Mapper `xweb:"/center/site/importfile"`    //导入站点
 	deleteSite    xweb.Mapper `xweb:"/center/site/delete"`        //删除站点
-	getLuas       xweb.Mapper `xweb:"/center/site/getluas/(.*)"`  //删除站点
-	getLuasBySite xweb.Mapper `xweb:"/center/site/getluasbysite"` //删除站点
+	getLuas       xweb.Mapper `xweb:"/center/site/getluas/(.*)"`  //
+	getLuasBySite xweb.Mapper `xweb:"/center/site/getluasbysite"` //
 }
 
-func (s *Site) LoadIndex() {
+func (s *Site) SiteList() {
 	if s.Method() == "POST" {
 		platform := s.GetString("platform")
 		event := s.GetString("event")
@@ -68,7 +68,8 @@ func (s *Site) LoadIndex() {
 		sort = fmt.Sprintf(sort, orderName, orderType)
 		sites, _ := util.MgoE.Find(sp.Config.SiteColl, query, sort, ``, false, start, limit)
 		count := util.MgoE.Count(sp.Config.SiteColl, query)
-		for _, s := range *sites {
+		for k, s := range *sites {
+			s["num"] = k + 1 + start
 			remarktime := qu.Int64All(s["remarktime"])
 			s["remarktime"] = qu.FormatDateByInt64(&remarktime, qu.Date_Full_Layout)
 		}
@@ -79,6 +80,11 @@ func (s *Site) LoadIndex() {
 			events = append(events, k)
 		}
 		sort.Strings(events)
+		//向web页面传递模板方法
+		// funcMap := template.FuncMap{"test": func(events []string) string { return strings.Join(events, ",") }}
+		// s.App.FuncMaps = funcMap
+		//向页面传递cookie
+		//s.SetCookie(&http.Cookie{Name: "testcookie", Value: "testcookie1"})
 		s.T["events"] = events
 		s.T["sitetypes"] = sp.Config.SiteType
 		s.T["areas"] = util.Area
@@ -106,10 +112,15 @@ func (s *Site) SaveSite() {
 	sitetype := s.GetString("sitetype")
 	psite := s.GetString("psite")
 	ssite := s.GetString("ssite")
-	tmpdomain, status, event, platform, remarktime := util.GetLuasInfoBySite(site)
+	tmpdomain, status, event, platform, tmparea, tmpcity, tmpdistrict, remarktime := util.GetLuasInfoBySite(site)
 	if domain == "" {
 		domain = tmpdomain
 	}
+	if area == "" {
+		area = tmparea
+		city = tmpcity
+		district = tmpdistrict
+	}
 	update := map[string]interface{}{
 		"site":         site,
 		"another_name": othername,
@@ -173,10 +184,15 @@ func (s *Site) ImportFile() {
 				site_type := r.Cells[7].Value
 				p_site := r.Cells[8].Value
 				s_site := r.Cells[9].Value
-				tmpdomain, status, event, platform, remarktime := util.GetLuasInfoBySite(site)
+				tmpdomain, status, event, platform, tmparea, tmpcity, tmpdistrict, remarktime := util.GetLuasInfoBySite(site)
 				if domain == "" {
 					domain = tmpdomain
 				}
+				if area == "" {
+					area = tmparea
+					city = tmpcity
+					district = tmpdistrict
+				}
 				save := map[string]interface{}{
 					"site":          site,
 					"another_name":  another_name,
@@ -206,18 +222,26 @@ func (s *Site) ImportFile() {
 
 func (s *Site) DeleteSite() {
 	defer qu.Catch()
-	id := s.GetString("id")
-	set := map[string]interface{}{
-		"$set": map[string]interface{}{
-			"delete":     true,
-			"deletetime": time.Now().Unix(),
-		},
+	ids := s.GetString("id")
+	arr := [][]map[string]interface{}{}
+	for _, id := range strings.Split(ids, ",") {
+		update := []map[string]interface{}{
+			map[string]interface{}{"_id": mgo.StringTOBsonId(id)},
+			map[string]interface{}{
+				"$set": map[string]interface{}{
+					"delete":     true,
+					"deletetime": time.Now().Unix(),
+				},
+			},
+		}
+		arr = append(arr, update)
 	}
-	if util.MgoE.UpdateById(sp.Config.SiteColl, id, set) {
+	if util.MgoE.UpdateBulk(sp.Config.SiteColl, arr...) {
 		s.ServeJson(map[string]interface{}{"d": true})
 	} else {
 		s.ServeJson(map[string]interface{}{"d": false})
 	}
+	return
 }
 
 func (s *Site) GetLuas(site string) {

+ 184 - 0
src/timetask/timetask.go

@@ -0,0 +1,184 @@
+package timetask
+
+import (
+	"fmt"
+	"io/ioutil"
+	"log"
+	"net/http"
+	"net/smtp"
+	qu "qfw/util"
+	mgdb "qfw/util/mongodb"
+	sp "spiderutil"
+	"strconv"
+	"strings"
+	"time"
+	"util"
+
+	"github.com/cron"
+
+	"gopkg.in/mgo.v2/bson"
+	. "gopkg.in/mgo.v2/bson"
+)
+
+var Mail map[string]interface{}
+
+func TimeTask() {
+	defer qu.Catch()
+	c := cron.New()
+	c.Start()
+	c.AddFunc("0 20 9 ? * MON-FRI", CheckCreateTask)
+	c.AddFunc("0 0 */1 ? * *", CheckLuaMove)
+	c.AddFunc("0 30 23 * * *", UpdateSiteInfo) //定时更新站点信息
+	c.Start()
+}
+
+//监测爬虫由历史转增量时未成功的
+func CheckLuaMove() {
+	defer qu.Catch()
+	qu.Debug("开始检测爬虫节点移动...")
+	query := map[string]interface{}{
+		"comeintime": map[string]interface{}{
+			"$gte": time.Now().Add(-(time.Hour * 1)).Unix(),
+			"$lte": time.Now().Unix(),
+		},
+		"ok": false,
+	}
+	qu.Debug("query:", query)
+	list := *mgdb.Find("luamovelog", query, nil, nil, false, -1, -1)
+	text := ""
+	if len(list) > 0 {
+		for _, l := range list {
+			stype := qu.ObjToString(l["type"])
+			code := qu.ObjToString(l["code"])
+			text += code + ":" + stype + ";"
+		}
+	}
+	if text != "" {
+		for i := 1; i <= 3; i++ {
+			res, err := http.Get(fmt.Sprintf("%s?to=%s&title=%s&body=%s", sp.Config.JkMail["api"], sp.Config.JkMail["to"], "lua-move-fail", text))
+			if err == nil {
+				res.Body.Close()
+				read, err := ioutil.ReadAll(res.Body)
+				qu.Debug("邮件发送:", string(read), err)
+				break
+			}
+		}
+	}
+}
+
+//检测创建任务失败的爬虫
+func CheckCreateTask() {
+	defer qu.Catch()
+	qu.Debug("开始检测任务创建...")
+	query := map[string]interface{}{
+		"comeintime": map[string]interface{}{
+			"$gte": GetTime(0),
+		},
+	}
+	codes := []string{}
+	list := *mgdb.Find("luacreatetaskerr", query, nil, nil, false, -1, -1)
+	if len(list) > 0 {
+		for _, l := range list {
+			code := qu.ObjToString(l["code"])
+			codes = append(codes, code)
+		}
+	}
+	if len(codes) > 0 {
+		for i := 1; i <= 3; i++ {
+			res, err := http.Get(fmt.Sprintf("%s?to=%s&title=%s&body=%s", sp.Config.JkMail["api"], sp.Config.JkMail["to"], "lua-createtask-err", "爬虫:"+strings.Join(codes, ";")))
+			if err == nil {
+				res.Body.Close()
+				read, err := ioutil.ReadAll(res.Body)
+				qu.Debug("邮件发送:", string(read), err)
+				break
+			}
+		}
+	}
+}
+
+func SendToMail() {
+	mailInfo := *(qu.ObjToMap(Mail["smtp"]))
+	host := mailInfo["host"].(string)
+	from := mailInfo["from"].(string)
+	pwd := mailInfo["password"].(string)
+	subject := mailInfo["subject"].(string)
+
+	hour := time.Now().Hour()
+	if hour == 8 {
+		//定时查询数据库 查询需要发邮件的人和相关信息
+		timeStr := time.Now().Format("2006-01-02")
+		the_time, _ := time.ParseInLocation("2006-01-02", timeStr, time.Local)
+		time_zero := the_time.Unix()         //当日凌晨的时间戳
+		time_twentyFour := time_zero + 86399 //当日24时的时间戳
+		//聚合查询数据
+		//mgdb.InitMongodbPool(5, "192.168.3.207:27080", "editor")
+		sess := mgdb.GetMgoConn()
+		defer mgdb.DestoryMongoConn(sess)
+		var res []M
+		sess.DB("editor").C("task").Pipe([]M{M{"$match": M{"l_complete": M{"$gte": time_zero, "$lte": time_twentyFour}, "i_state": M{"$gte": 1, "$lte": 2}}},
+			M{"$group": M{"_id": "$s_modifyid", "count": M{"$sum": 1}}}}).All(&res)
+		//遍历数据进行发邮件
+		for _, v := range res {
+			_id, ok := v["_id"].(string)
+			if ok {
+				query := bson.M{
+					"_id": bson.ObjectIdHex(_id),
+				}
+				user := *mgdb.FindOne("user", query)
+				if user["s_email"] == nil {
+					continue
+				}
+				num := strconv.Itoa(v["count"].(int))
+				body := `<html><body><h3>你有` + num + `条任务需要今天完成</h3></body></html>`
+				hp := strings.Split(host, ":")
+				auth := smtp.PlainAuth("", from, pwd, hp[0])
+				content_type := "Content-Type: text/html; charset=UTF-8"
+				msg := []byte("To: " + user["s_email"].(string) + "\r\nFrom: " + from + "\r\nSubject: " + subject + "\r\n" + content_type + "\r\n\r\n" + body)
+				send_to := strings.Split(user["s_email"].(string), ";")
+				err := smtp.SendMail(host, auth, from, send_to, msg)
+				if err == nil {
+					log.Println(user["s_email"].(string), "  sendMail   success")
+				} else {
+					log.Println(user["s_email"].(string), "  sendMail   fail")
+				}
+			}
+		}
+		time.Sleep(1 * time.Hour)
+	}
+	//time.AfterFunc(30*time.Minute, func() { SendToMail(to, num) })
+	time.AfterFunc(30*time.Minute, SendToMail)
+}
+
+//获取第day天凌晨的时间戳
+func GetTime(day int) int64 {
+	defer qu.Catch()
+	nowTime := time.Now().AddDate(0, 0, day)
+	timeStr := qu.FormatDate(&nowTime, qu.Date_Short_Layout)
+	t, _ := time.ParseInLocation(qu.Date_Short_Layout, timeStr, time.Local)
+	return t.Unix()
+}
+
+func UpdateSiteInfo() {
+	defer qu.Catch()
+	qu.Debug("定时更新站点信息开始...")
+	sites, _ := util.MgoE.Find(sp.Config.SiteColl, ``, ``, `{"site":1}`, false, -1, -1)
+	for _, s := range *sites {
+		site := qu.ObjToString(s["site"])
+		domain, status, event, platform, area, city, district, _ := util.GetLuasInfoBySite(site)
+		set := map[string]interface{}{
+			"$set": map[string]interface{}{
+				"platform":      platform,
+				"event":         event,
+				"spider_status": status,
+				"domain":        domain,
+				"area":          area,
+				"city":          city,
+				"district":      district,
+				"updatetime":    time.Now().Unix(),
+			},
+		}
+		util.MgoE.UpdateById(sp.Config.SiteColl, s["_id"], set)
+	}
+	qu.Debug("定时更新站点信息完成...")
+
+}

+ 53 - 2
src/util/util.go

@@ -198,13 +198,16 @@ func SpiderPassCheckListAndDetail(list []map[string]interface{}, data map[string
 	return strings.Join(msg, ",")
 }
 
-func GetLuasInfoBySite(site string) (domain, status, event, platform string, remarktime int64) {
+func GetLuasInfoBySite(site string) (domain, status, event, platform, area, city, district string, remarktime int64) {
 	shelveUp := 0
 	eventMap, platformMap := map[int]interface{}{}, map[string]interface{}{}
 	eventArr, platformArr := []string{}, []string{}
+	areaMap := map[string]int{}
+	areaCityMap := map[string]map[string]int{}
+	cityDistrictMap := map[string]map[string]int{}
 	domainMap := map[string]int{}
 	remarktime = time.Now().Unix()
-	luas, _ := MgoE.Find("luaconfig", `{"param_common.1":"`+site+`"}`, ``, `{"event":1,"state":1,"platform":1,"param_common":1,"comeintime":1}`, false, -1, -1)
+	luas, _ := MgoE.Find("luaconfig", `{"param_common.1":"`+site+`"}`, ``, `{"model":1,"event":1,"state":1,"platform":1,"param_common":1,"comeintime":1}`, false, -1, -1)
 	for _, l := range *luas {
 		//remarktime
 		if comeintime := qu.Int64All(l["comeintime"]); comeintime != int64(0) && comeintime < remarktime {
@@ -229,6 +232,30 @@ func GetLuasInfoBySite(site string) (domain, status, event, platform string, rem
 		}
 		eventMap[event] = true
 		platformMap[platform] = true
+		//area、city、district
+		if model, ok := l["model"].(map[string]interface{}); ok && model != nil {
+			a := qu.ObjToString(model["area"])
+			c := qu.ObjToString(model["city"])
+			d := qu.ObjToString(model["district"])
+			if a != "" {
+				areaMap[a] = areaMap[a] + 1
+				if c != "" {
+					if cityNum := areaCityMap[a]; cityNum != nil {
+						cityNum[c] = cityNum[c] + 1
+					} else {
+						areaCityMap[a] = map[string]int{c: 1}
+					}
+					if d != "" {
+						if distrctNum := cityDistrictMap[c]; distrctNum != nil {
+							distrctNum[d] = distrctNum[d] + 1
+						} else {
+							cityDistrictMap[c] = map[string]int{d: 1}
+						}
+					}
+				}
+
+			}
+		}
 	}
 	//
 	for e, _ := range eventMap {
@@ -248,5 +275,29 @@ func GetLuasInfoBySite(site string) (domain, status, event, platform string, rem
 		}
 	}
 	status = fmt.Sprintf("%d%s%d", shelveUp, "/", len(*luas))
+	//
+	an, cn, dn := 0, 0, 0
+	for at, num := range areaMap {
+		if num > an {
+			area = at
+			an = num
+		}
+	}
+	if area != "" {
+		for ct, num := range areaCityMap[area] {
+			if num > cn {
+				city = ct
+				cn = num
+			}
+		}
+	}
+	if city != "" {
+		for dt, num := range cityDistrictMap[city] {
+			if num > dn {
+				district = dt
+				dn = num
+			}
+		}
+	}
 	return
 }

+ 51 - 9
src/web/templates/index.html

@@ -102,12 +102,12 @@
           				<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>
@@ -126,7 +126,7 @@ $(function(){
           },
 		"columnDefs": [
 		    { "orderable": false, "targets": [0,10,11] },
-			{"targets":[6], createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
+			  {"targets":[6], createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
           {{if gt (session "auth") 2}}
           var aInput;
           $(cell).click(function () {
@@ -147,7 +147,7 @@ $(function(){
           });
           {{end}}
         }},
-        	{"targets":[9], createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
+        {"targets":[9], createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
           {{if gt (session "auth") 2}}
           var aInput;
           $(cell).click(function () {
@@ -183,6 +183,40 @@ $(function(){
             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._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
+            }
+            ttable.cell(cell).data(text);
+            cellData = text;
+          });
+          {{end}}
         }}
 		],
 		"order": [[1,"desc"]],
@@ -330,7 +364,7 @@ $(function(){
 				e.urgency="-1"
 			}
 		    //状态
-		    if(state){
+		  if(state){
 				e.state=state
 			}else{
 				e.state="-1"
@@ -611,10 +645,10 @@ $(function(){
 		for(k in events){
 			spiderEvent+="<option value='"+events[k]+"'>"+events[k]+"</option>"
 		}
-    return "<select onchange='changeEventOrState(this.value,\"event\",\""+state+"\",\""+code+"\",\""+id+"\")' class='form-control input-sm'>"+spiderEvent+"</select>"
+    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='changeEventOrState(this.value,\"state\",\"\",\"\",\""+id+"\")' class='form-control input-sm'>"+
+    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>"+
       			"<option disabled value='2'>未通过</option>"+
@@ -628,9 +662,17 @@ $(function(){
       			"<option disabled value='10'>已删除</option>"+
           +"</select>"
   };
-  function changeEventOrState(val,w,s,c,id){
+  function createComboxPlatform(id){
+    return "<select onchange='changeEventOrStateOrPlatform(this.value,\"platform\",\"\",\"\",\""+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({
-			url:"/center/spider/updateeventorstate",
+			url:"/center/spider/updateesp",
 			type:"post",
 			data:{
 				"val":val,

+ 60 - 27
src/web/templates/sitelist.html

@@ -178,6 +178,7 @@
 <!--			<a class="btn btn-default btn-sm" href="/center/spider">新建爬虫</a>-->
          <a class="btn btn-default btn-sm" id="import" onclick="importSite()">导入</a>
          <a class="btn btn-default btn-sm" id="add" onclick="addSite()">新增</a>
+         <a class="btn btn-default btn-sm" onclick="del()">删除</a>
 <!--			{{end}}-->
          <iframe srcdoc="<form id='uploadform' method='post' enctype='multipart/form-data' action='/center/site/importf
 				ile'><input type='file' name='xlsx' /></form>" height=0 scrolling=no class="hide"  id="fileframe">
@@ -196,6 +197,8 @@
               <table id="sitelist" class="table table-bordered table-striped">
                 <thead>
                 <tr>
+                    <th><input type="checkbox" id="selrow" onclick="selectrow(this)"/></th>
+          				  <th>编号</th>
                     <th>站点</th>
                     <th>别名</th>
                     <th>域名</th>
@@ -206,7 +209,7 @@
                     <th>类型</th>
                     <th>父站</th>
                     <th>子站</th>
-                    <th>网站状态</th>
+                    <th>状态</th>
                     <th>节点</th>
                     <th>时间</th>
                     <th>平台</th>
@@ -228,7 +231,7 @@ $(function(){
         $("#sitetype").append("<option value='"+sitetypes[i]+"'>"+sitetypes[i]+"</option>")
         $("#edit-sitetype").append("<option value='"+sitetypes[i]+"'>"+sitetypes[i]+"</option>")
     }
-	ttable=$('#sitelist').DataTable({
+	  ttable=$('#sitelist').DataTable({
 		"language": {
               "url": "/js/dataTables.chinese.lang"
           },
@@ -248,30 +251,38 @@ $(function(){
 			"type": "POST"
 		 },
 		"columns": [
+      { "data": "_id",render:function(val,a,row){
+				return "<input type='checkbox' value='"+val+"'/>"
+			}},
+      { "data": "_id",render:function(val,a,row){
+				return row.num
+			}},
 			{ "data": "site"},
-            { "data": "another_name"},
-            { "data": "domain"},
-            { "data": "area"},
-            { "data": "city"},
-            { "data": "district"},
-            { "data": "industry"},
-            { "data": "site_type"},
-            { "data": "p_site"},
-            { "data": "s_site"},
-            { "data": "spider_status",width:"28px",render:function (val,a,row) {
-                  return  "<a href='/center/site/getluas/"+row.site+"' style='color: #333 !important;' target='_blank'>"+val+"</a>"
-                  //return  '<a onclick="goToCenter(\''+row.site+'\')" style="color: #333 !important;" target="_blank">'+val+'</a>'
-                }},
-            { "data": "event",render:function (val,a,row){
-                   var tmpval =val
-                   if(val.length >9){
-                       val = val.substring(0,9)+"..."
-                   }
-                   return "<span title='"+tmpval+"'>"+val+"</span>"
-                }},
-            { "data": "remarktime",width:"50px"},
-            { "data": "platform"},
-            { "data": "_id",render:function (val,a,row){
+      { "data": "another_name"},
+      { "data": "domain",render:function(val,a,row){
+          return "<a href='http://"+val+"' target='_blank' style='color: #333'>"+val+"</a>"
+      }},
+      { "data": "area"},
+      { "data": "city"},
+      { "data": "district"},
+      { "data": "industry"},
+      { "data": "site_type"},
+      { "data": "p_site"},
+      { "data": "s_site"},
+      { "data": "spider_status",width:"28px",render:function (val,a,row) {
+            return  "<a href='/center/site/getluas/"+row.site+"' style='color: #333 !important;' target='_blank'>"+val+"</a>"
+            //return  '<a onclick="goToCenter(\''+row.site+'\')" style="color: #333 !important;" target="_blank">'+val+'</a>'
+          }},
+      { "data": "event",render:function (val,a,row){
+             var tmpval =val
+             if(val.length >9){
+                 val = val.substring(0,9)+"..."
+             }
+             return "<span title='"+tmpval+"'>"+val+"</span>"
+          }},
+      { "data": "remarktime",width:"50px"},
+      { "data": "platform"},
+      { "data": "_id",render:function (val,a,row){
                 var div=$("<div><div class=\"btn-group\"></div></div>")
                 var buttonEdit=$('<a type="button" target="_blank" class="btn btn-sm btn-default">编辑</a>');
                 var buttonDelete=$('<a type="button" class="btn btn-sm btn-default">删除</a>');
@@ -281,7 +292,7 @@ $(function(){
                 div.find(".btn-group").append(buttonDelete);
                 return div.html();
             }}
-        ],
+    ],
 		"fnDrawCallback": function(table) {
 		 	$("ul.pagination").prepend("&nbsp;&nbsp;&nbsp;转到第 <input type='text' id='changePage'   style='width:20px;'> 页    <a type='text' href='javascript:void(0);' id='dataTable-btn' style='text-align:center'>GO</a>");
 		 	$('#dataTable-btn').click(function(e) {    
@@ -426,13 +437,26 @@ function siteEdit(rowjson){
                 $(this).attr("selected",true);
             }
         })
-
     }
     $("#psite").val(row.p_site);
     $("#ssite").val(row.s_site);
     $("#saveSiteId").attr("saveid",row._id);
     $("#editsite").modal("show");
 }
+function del(){
+  var ids=[];
+  $("#sitelist td input[type=checkbox]").each(function(){
+		if($(this).prop("checked")){
+			ids.push($(this).val());
+		}
+	});
+  console.log(ids)
+  if(ids.length>0){
+    siteDelete(ids.join(","));
+    $("#selrow").prop('checked',false);
+  }
+}
+
 //删除站点
 function siteDelete(id){
     showConfirm("确定删除?", function() {
@@ -522,6 +546,15 @@ function checkclick(me){
 function cancelAdd(){
     $("#addsite").modal("hide");
 }
+function selectrow(me){
+		var sel=$(me);
+		var isSelected=sel.prop('checked');
+		if(isSelected){
+			$("#sitelist td input[type=checkbox]").prop("checked",true);
+		}else{
+			$("#sitelist td input[type=checkbox]").prop("checked",false);
+		}
+	}
 </script>
 </div>
 {{include "bottom.html"}}