소스 검색

新增节点转移列表

maxiaoshan 2 년 전
부모
커밋
452d9176be
5개의 변경된 파일371개의 추가작업 그리고 570개의 파일을 삭제
  1. 114 216
      src/front/luamove.go
  2. 7 0
      src/front/spider.go
  3. 0 204
      src/web/templates/luamovecode.html
  4. 250 0
      src/web/templates/luamovelist.html
  5. 0 150
      src/web/templates/luamovesite.html

+ 114 - 216
src/front/luamove.go

@@ -18,22 +18,12 @@ import (
 
 type LuaMove struct {
 	*xweb.Action
-	luaMoveManager    xweb.Mapper `xweb:"/center/luamove"`                 //站点列表
-	luaMoveSite       xweb.Mapper `xweb:"/center/luamove/site/(.*)"`       //
-	luaMoveCodeInfo   xweb.Mapper `xweb:"/center/luamove/codeinfo"`        //爬虫列表
-	luaMoveBySite     xweb.Mapper `xweb:"/center/luamove/luamovebysite"`   //按站点迁移、关闭
-	luaMoveByCode     xweb.Mapper `xweb:"/center/luamove/luamovebycode"`   //按爬虫迁移、关闭
-	updateEventBySite xweb.Mapper `xweb:"/center/spider/updateventbysite"` //更新某站点下爬虫的节点
+	luaMove       xweb.Mapper `xweb:"/center/luamove"`               //站点列表
+	luaMoveByCode xweb.Mapper `xweb:"/center/luamove/luamovebycode"` //
 }
 
-type OtherBase struct {
-	IsFlow               int    //爬虫所采集数据是否参与数据流程标识
-	SpiderType           string //爬虫类型:increment增量;history历史
-	SpiderHistoryMaxPage int    //采集历史数据时的采集最大页
-	SpiderMoveEvent      string //爬虫采集完历史后要转移到的节点 comm:队列模式、bid:高性能模式、7700
-}
-
-func (lm *LuaMove) LuaMoveManager() {
+func (lm *LuaMove) LuaMove() {
+	defer qu.Catch()
 	auth := qu.IntAll(lm.GetSession("auth"))
 	if auth == role_admin {
 		if lm.Method() == "GET" {
@@ -43,228 +33,149 @@ func (lm *LuaMove) LuaMoveManager() {
 			}
 			sort.Strings(events)
 			lm.T["events"] = events
-			lm.Render("luamovesite.html")
+			lm.Render("luamovelist.html")
 		} else {
-			query := map[string]interface{}{"lm_ismove": true}
-			//lualist := *mgdb.Find("luaconfig", query, nil, nil, false, -1, -1)
-			lualist, _ := u.MgoEB.Find("luaconfig", query, nil, nil, false, -1, -1)
-			data := []map[string]interface{}{}
-			siteMap := map[string][]map[string]interface{}{}
+			state, _ := lm.GetInteger("state")
+			fromevent, _ := lm.GetInteger("fromevent")
+			toevent, _ := lm.GetInteger("toevent")
+			ismove, _ := lm.GetInteger("ismove")
+			start, _ := lm.GetInteger("start")
+			limit, _ := lm.GetInteger("length")
+			draw, _ := lm.GetInteger("draw")
+			searchStr := lm.GetString("search[value]")
+			search := strings.TrimSpace(searchStr)
+			query := map[string]interface{}{}
+			if state != -1 { //是否已处理筛选
+				query["state"] = state
+			}
+			if fromevent != -1 { //历史节点筛选
+				query["fromevent"] = fromevent
+			}
+			if toevent != -1 { //目标节点筛选
+				query["toevent"] = toevent
+			}
+			if ismove != -1 { //是否转移筛选
+				query["ismove"] = ismove == 1
 
-			for _, l := range *lualist {
-				pc := l["param_common"].([]interface{})
-				site := qu.ObjToString(pc[1])
-				href := ""
-				if len(pc) >= 12 {
-					href = qu.ObjToString(pc[11])
-				}
-				lm_movevent := l["lm_movevent"]
-				event := l["event"]
-				if tmp := siteMap[site]; tmp == nil {
-					data = append(data, map[string]interface{}{"site": site, "lm_movevent": lm_movevent, "event": event})
-					siteMap[site] = []map[string]interface{}{
-						map[string]interface{}{
-							"code":        l["code"],
-							"channel":     pc[2],
-							"event":       event,
-							"lm_movevent": lm_movevent,
-							"href":        href,
-							"lm_download": l["lm_download"],
-							"state":       l["state"],
-						},
-					}
-				} else {
-					tmp = append(tmp, map[string]interface{}{
-						"code":        l["code"],
-						"channel":     pc[2],
-						"event":       event,
-						"lm_movevent": lm_movevent,
-						"href":        href,
-						"lm_download": l["lm_download"],
-						"state":       l["state"],
-					})
-					siteMap[site] = tmp
+			}
+			if search != "" {
+				query["$or"] = []interface{}{
+					map[string]interface{}{"code": map[string]interface{}{"$regex": search}},
+					map[string]interface{}{"site": map[string]interface{}{"$regex": search}},
 				}
 			}
-			lm.SetSession("sitemap", siteMap)
-			lm.ServeJson(map[string]interface{}{"data": data})
+			year, month, _ := time.Now().Date()
+			//本月1日时间戳
+			firstOfMonth := time.Date(year, month, 1, 0, 0, 0, 0, time.Local).Unix()
+			query["comeintime"] = map[string]interface{}{ //本月的信息
+				"$gte": firstOfMonth,
+			}
+			sort := `{"%s":%d}`
+			orderIndex := lm.GetString("order[0][column]")
+			orderName := lm.GetString(fmt.Sprintf("columns[%s][data]", orderIndex))
+			orderType := 1
+			if lm.GetString("order[0][dir]") != "asc" {
+				orderType = -1
+			}
+			sort = fmt.Sprintf(sort, orderName, orderType)
+			count := u.MgoEB.Count("luamovevent", query)
+			qu.Debug("query:", query, sort, count)
+			data, _ := u.MgoEB.Find("luamovevent", query, sort, nil, false, start, limit)
+			lm.ServeJson(map[string]interface{}{
+				"draw":            draw,
+				"data":            data,
+				"recordsFiltered": count,
+				"recordsTotal":    count,
+			})
 		}
 	} else {
 		lm.Write("您没有权限")
 	}
 }
 
-func (lm *LuaMove) LuaMoveSite(site string) {
-	defer qu.Catch()
-	if lm.Method() == "GET" {
-		events := []string{}
-		for k, _ := range util.Config.Uploadevents {
-			events = append(events, k)
-		}
-		sort.Strings(events)
-		lm.T["events"] = events
-		lm.T["site"] = site
-		lm.Render("luamovecode.html", &lm.T)
-	}
-}
-
-func (lm *LuaMove) LuaMoveCodeInfo() {
-	site := lm.GetString("site")
-	sitemap := lm.GetSession("sitemap").(map[string][]map[string]interface{})
-	lm.ServeJson(map[string]interface{}{"data": sitemap[site]})
-}
-
-func (lm *LuaMove) LuaMoveBySite() {
-	defer qu.Catch()
-	site := lm.GetString("site")
-	stype := lm.GetString("stype")
-	//movevent, _ := lm.GetInteger("movevent")
-	sitemap := lm.GetSession("sitemap").(map[string][]map[string]interface{})
-	codesinfo := sitemap[site]
-	codes := []string{}
-	for _, info := range codesinfo {
-		code := qu.ObjToString(info["code"])
-		codes = append(codes, code)
-	}
-	ok := false
-	if stype == "move" { //迁移
-		ok = SpiderMoveLua(codes)
-	} else if stype == "close" { //关闭
-		ok, _ = lm.SpiderCloseMoveLua(site, codes, "site")
-	}
-	lm.ServeJson(map[string]interface{}{"ok": ok})
-}
-
 func (lm *LuaMove) LuaMoveByCode() {
 	defer qu.Catch()
-	site := lm.GetString("site")
-	code := lm.GetString("code")
 	stype := lm.GetString("stype")
-	//movevent, _ := lm.GetInteger("movevent")
+	code := lm.GetString("code")
+	movevent := lm.GetString("movevent")
+	events := strings.Split(movevent, ",")
 	codes := strings.Split(code, ",")
 	ok := false
-	flush := false
 	if stype == "move" { //迁移
-		ok = SpiderMoveLua(codes)
-	} else if stype == "close" { //关闭
-		ok, flush = lm.SpiderCloseMoveLua(site, codes, "code")
-	}
-	qu.Debug(ok)
-	lm.ServeJson(map[string]interface{}{"ok": ok, "flush": flush})
-}
-
-func (lm *LuaMove) UpdateEventBySite() {
-	defer qu.Catch()
-	site := lm.GetString("site")
-	movevent, _ := lm.GetInteger("movevent")
-	sitemap := lm.GetSession("sitemap").(map[string][]map[string]interface{})
-	codes := []string{}
-	for _, info := range sitemap[site] {
-		code := qu.ObjToString(info["code"])
-		codes = append(codes, code)
-		info["lm_movevent"] = movevent
-	}
-	lm.SetSession("sitemap", sitemap)
-	query := map[string]interface{}{
-		"code": map[string]interface{}{
-			"$in": codes,
-		},
-	}
-	set := map[string]interface{}{
-		"$set": map[string]interface{}{
-			"lm_movevent": movevent,
-		},
+		if len(codes) != len(events) {
+			qu.Debug("爬虫个数和节点个数不匹配:", codes, events)
+		} else {
+			ok = SpiderMoveLua(codes, events) //节点转移
+		}
+	} else if stype == "close" { //关闭,更新数据状态
+		arr := [][]map[string]interface{}{}
+		for _, code := range codes {
+			arr = append(arr, []map[string]interface{}{
+				map[string]interface{}{"code": code},
+				map[string]interface{}{
+					"$set": map[string]interface{}{
+						"state": 1,
+					},
+				},
+			})
+		}
+		ok = u.MgoEB.UpdateBulk("luamovevent", arr...)
+		arr = [][]map[string]interface{}{}
 	}
-	//mgdb.Update("luaconfig", query, set, false, true)
-	u.MgoEB.Update("luaconfig", query, set, false, true)
+	lm.ServeJson(map[string]interface{}{"ok": ok})
 }
 
 //爬虫迁移
-func SpiderMoveLua(codes []string) bool {
+func SpiderMoveLua(codes []string, events []string) bool {
 	defer qu.Catch()
-	for _, code := range codes {
-		//lua := *mgdb.FindOne("luaconfig", map[string]interface{}{"code": code})
+	msg := []string{}
+	for index, code := range codes {
+		resultEvent := events[index]
+		qu.Debug("爬虫节点转移:", code, resultEvent)
 		lua, _ := u.MgoEB.FindOne("luaconfig", map[string]interface{}{"code": code})
-		movevent := qu.IntAll((*lua)["lm_movevent"])
-		event := qu.IntAll((*lua)["event"])
-		state := qu.IntAll((*lua)["state"])
-		upresult := true
-		var err interface{}
-		if state < 7 || state == 4 { //无发布、需登录、转python、已删除状态无需下架
-			//下架
-			upresult, err = spider.UpdateSpiderByCodeState(code, "6", event) //脚本下架
-		}
-		if upresult && err == nil { //下架成功,更新节点
-			//更新节点
-			query := map[string]interface{}{
-				"code": code,
-			}
-			set := map[string]interface{}{
-				"$set": map[string]interface{}{
-					"event": movevent,
-				},
-			}
-			//mgdb.Update("luaconfig", query, set, false, false)
-			u.MgoEB.Update("luaconfig", query, set, false, false)
-			//上架
-			if state == 5 { //只有是已上架状态的爬虫上架
-				upresult, err = spider.UpdateSpiderByCodeState(code, "5", movevent) //脚本上架
-				if !upresult || err != nil {
-					SendMail("爬虫定期节点迁移" + code + "上架失败")
-					qu.Debug("定期节点迁移", code, "上架失败")
-					return false
+		if len(*lua) > 0 {
+			state := qu.IntAll((*lua)["state"])
+			//event := qu.IntAll((*lua)["event"])
+			if state == 5 { //查询该爬虫是否是已上架状态,是则更新节点后上架,否则只更新
+				upresult := true
+				var err interface{}
+				//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) //脚本上架
+					if !upresult || err != nil {
+						qu.Debug("爬虫节点转移", code, "上架失败")
+						msg = append(msg, "爬虫节点转移"+code+"上架失败")
+					}
+				} else {
+					qu.Debug("爬虫节点转移", code, "下架失败")
+					msg = append(msg, "爬虫节点转移"+code+"下架失败")
 				}
 			}
+			u.MgoEB.Update("luamovevent", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"state": 1}}, false, false)
 		} else {
-			SendMail("爬虫定期节点迁移" + code + "下架失败")
-			qu.Debug("定期节点迁移", code, "下架失败")
-			return false
+			msg = append(msg, "爬虫节点转移未找到爬虫"+code)
 		}
 	}
+	if len(msg) > 0 {
+		SendMail(strings.Join(msg, ";"))
+	}
 	return true
 }
 
-//更新爬虫是否要迁移的状态
-func (lm *LuaMove) SpiderCloseMoveLua(site string, codes []string, by string) (bool, bool) {
+func SendMail(text string) {
 	defer qu.Catch()
-	flush := false
-	query := map[string]interface{}{
-		"code": map[string]interface{}{
-			"$in": codes,
-		},
-	}
-	set := map[string]interface{}{
-		"$set": map[string]interface{}{
-			"lm_ismove": false,
-		},
-	}
-	sitemap := lm.GetSession("sitemap").(map[string][]map[string]interface{})
-	//清除session
-	if by == "code" {
-		tmpArr := []map[string]interface{}{}
-		infoArr := sitemap[site]
-		for _, info := range infoArr {
-			flag := false
-			for _, code := range codes {
-				if qu.ObjToString(info["code"]) == code {
-					flag = true
-					break
-				}
-			}
-			if !flag {
-				tmpArr = append(tmpArr, info)
-			}
-		}
-		if len(tmpArr) == 0 {
-			delete(sitemap, site)
-			flush = true
-		} else {
-			sitemap[site] = tmpArr
+	for i := 1; i <= 3; i++ {
+		res, err := http.Get(fmt.Sprintf("%s?to=%s&title=%s&body=%s", util.Config.JkMail["api"], util.Config.JkMail["to"], "lua-timeluamove-err", text))
+		if err == nil {
+			res.Body.Close()
+			read, err := ioutil.ReadAll(res.Body)
+			qu.Debug("邮件发送:", string(read), err)
+			break
 		}
-		lm.SetSession("sitemap", sitemap)
 	}
-	//return mgdb.Update("luaconfig", query, set, false, true), flush
-	return u.MgoEB.Update("luaconfig", query, set, false, true), flush
 }
 
 //
@@ -367,16 +278,3 @@ func GetEvent(code string, lua map[string]interface{}) int {
 	}
 	return result
 }
-
-func SendMail(text string) {
-	defer qu.Catch()
-	for i := 1; i <= 3; i++ {
-		res, err := http.Get(fmt.Sprintf("%s?to=%s&title=%s&body=%s", util.Config.JkMail["api"], util.Config.JkMail["to"], "lua-timeluamove-err", text))
-		if err == nil {
-			res.Body.Close()
-			read, err := ioutil.ReadAll(res.Body)
-			qu.Debug("邮件发送:", string(read), err)
-			break
-		}
-	}
-}

+ 7 - 0
src/front/spider.go

@@ -72,6 +72,13 @@ type StepRe3 struct {
 	Expert  string
 }
 
+type OtherBase struct {
+	IsFlow               int    //爬虫所采集数据是否参与数据流程标识
+	SpiderType           string //爬虫类型:increment增量;history历史
+	SpiderHistoryMaxPage int    //采集历史数据时的采集最大页
+	SpiderMoveEvent      string //爬虫采集完历史后要转移到的节点 comm:队列模式、bid:高性能模式、7700
+}
+
 //加载某个爬虫
 func (f *Front) LoadSpider(codeTaskIdReState string) error {
 	tmpStr := strings.Split(codeTaskIdReState, "__")

+ 0 - 204
src/web/templates/luamovecode.html

@@ -1,204 +0,0 @@
-{{include "head.html"}}
-<div class="content-wrapper">
-		<section class="content-header">
-		   <h1>
-		     迁移列表
-		     <small>
-				  <button class="btn btn-primary btn-sm" onclick='batchCodeMove("")'>批量迁移</button>
-				  <button class="btn btn-primary btn-sm" onclick="batchCodeClose()">批量关闭</button>
-			   </small>
-		   </h1>
-		   <ol class="breadcrumb">
-		     <li><a href="#"><i class="fa fa-dashboard"></i> 爬虫</a></li>
-		     <li class="active">列表</li>
-		   </ol>
-		 </section>
-		<section class="content">
-			<div class="box">
-				<div class="box-body">
-					<table id="luamovecode" 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>
-                <th>下载量</th>
-                <th>爬虫状态</th>
-								<th class="hidden-xs">操作</th>
-							</tr>
-						</thead>
-						<tbody>
-							
-						</tbody>
-					</table>
-				</div>
-			</div>
-		</section>
-<script>
-	$(function(){
-		luamovecodetable = $('#luamovecode').DataTable({
-			"language": {
-        "url": "/js/dataTables.chinese.lang"
-      },
-			"ajax": {
-      	"url": "/center/luamove/codeinfo",
-     		"type": "POST",
-        "data": {"site":{{.T.site}}}
-      },
-			"columnDefs": [
-				//{ "targets": 0 ,"bVisible": false}, //隐藏列
-			  { "orderable": false, "targets": [0,1,2,3,4,6,7] }, //设置列不可排序
-      ],	
-			"order": [[5,"asc"]], //默认排序列
-			"lengthChange":false,
-			"serverSide": false,
-			"searching": false,
-			"ordering": true,
-			"info": true,
-			"autoWidth": true,
-      "paging": false,
-			"columns": [
-				{"data": "code",render:function(val,a,row){
-					return "<input type='checkbox' code='"+row.code+"' movevent='"+row.lm_movevent+"'/>"
-				}},
-	      {"data": "code"},
-				{"data": "channel",render:function(val,a,row){
-					var href ="javascript:void(0)" ;
-					if(row["href"] != ""){
-						href = row["href"];
-					}
-					var vals="<a href='"+href+"' title='"+val+"' target='_blank'>"+val+"</a>"
-					return vals
-				}},
-				 {"data": "event"},
-         {"data": "lm_movevent"},
-         {"data": "lm_download"},
-        { "data": "state","width":"70px",render:function(val,a,row){
-				if(val==0){
-					val="<span class='text-info text-bold'>待完成</span>"
-				}else if(val==1){
-					val="<span class='text-primary text-bold'>待审核</span>"
-				}else if(val==2){
-					val="<span class='text-danger text-bold'>未通过</span>"
-				}else if(val==3){
-					val="<span class='text-success text-bold'>已通过</span>"
-				}else if(val==4){
-					val="<span class='text-danger text-bold'>已作废</span>"
-				}else if(val==5){
-					val="<span class='text-success text-bold'>已上架</span>"
-				}else if(val==6){
-					val="<span class='text-danger text-bold'>已下架</span>"
-				}else if(val==7){
-					val="<span class='text-danger text-bold'>无发布</span>"
-				}else if(val==8){
-					val="<span class='text-danger text-bold'>需登录</span>"
-				}else if(val==9){
-					val="<span class='text-danger text-bold'>转python</span>"
-				}else if(val==10){
-					val="<span class='text-danger text-bold'>已删除</span>"
-				}
-				return val
-			}},
-        {"data": "_id",render:function(val,a,row){
-					var div=$("<div><div class=\"btn-group\"></div></div>")
-					var buttonMove=$('<a type="button" target="_blank" class="btn btn-sm btn-default">迁移</a>');
-					var buttonClose=$('<a type="button" class="btn btn-sm btn-default">关闭</a>');
-				  buttonMove.attr("onclick","codeLuaMove('"+row.code+"','move','"+row.lm_movevent+"')");
-					buttonClose.attr("onclick","codeLuaMove('"+row.code+"','close','"+row.lm_movevent+"')");
-					div.find(".btn-group").append(buttonMove);
-					div.find(".btn-group").append(buttonClose);
-					
-					return div.html();
-				}}
-			]
-	  });
-		common.setActive("index_pcqy");
-	})
-  
-  //批量迁移
-	function batchCodeMove(){
-		var codes=[];
-    var movevent="";
-		$("#luamovecode_wrapper td input[type=checkbox]").each(function(){
-			if($(this).prop("checked")){
-				codes.push($(this).attr("code"));
-        var tmp = $(this).attr("movevent")
-        if(movevent != "" && movevent != tmp){
-          showTip("目标节点不一致", 1000);
-          return
-        }else if(movevent == ""){
-          movevent = tmp
-        }
-			}
-		});
-		if(codes.length >0){
-			showConfirm("确定批量迁移?", function() {
-        codeLuaMove(codes.join(","),"move",movevent)
-			})
-		}else{
-			showTip("没有选择项", 1000);
-		}
-	}
-	//批量关闭
-	function batchCodeClose(){
-		var codes=[];
-		$("#luamovecode_wrapper td input[type=checkbox]").each(function(){
-			if($(this).prop("checked")){
-				codes.push($(this).attr("code"));
-			}
-		});
-		if(codes.length >0){
-			showConfirm("确定批量关闭?", function() {
-        codeLuaMove(codes.join(","),"close","")
-			})
-		}else{
-			showTip("没有选择项", 1000);
-		}
-	}
-	
-  function codeLuaMove(code,stype,movevent){
-    var text = "迁移";
-    if(stype=="close"){
-      text = "关闭"
-    }
-    $.ajax({
-      url:"/center/luamove/luamovebycode",
-      type:"post",
-      data:{"code":code,"stype":stype,"movevent":movevent,"site":{{.T.site}}},
-      success:function(r){
-        console.log(r)
-        if(r){
-          if(r.flush){//跳到site列表
-            $('#com-alert').on('hidden.bs.modal', function () {
-						  window.location.href = "/center/luamove";
-					  })
-          }else if(r.ok){
-            showTip(text+"成功", 1000);
-            $("#selrow").prop('checked',false);
-            $('#com-alert').on('hidden.bs.modal', function () {
-						  luamovecodetable.ajax.reload();
-					  })
-          }else{
-            showTip(text+"失败", 1000);
-          }
-        }else{
-          showTip(text+"失败", 1000);
-        }
-      }
-    })
-  }
-  
-  function selectrow(me){
-		var sel=$(me);
-		var isSelected=sel.prop('checked');
-		if(isSelected){
-			$("#luamovecode td input[type=checkbox]").prop("checked",true);
-		}else{
-			$("#luamovecode td input[type=checkbox]").prop("checked",false);
-		}
-	}
- </script>
-</div>
-{{include "bottom.html"}}

+ 250 - 0
src/web/templates/luamovelist.html

@@ -0,0 +1,250 @@
+{{include "head.html"}}
+<div class="content-wrapper">
+		<section class="content-header">
+		   <h1>
+		     迁移列表
+		     <small>
+				  <button class="btn btn-primary btn-sm" onclick='batchCodeMove("")'>批量迁移</button>
+				  <button class="btn btn-primary btn-sm" onclick="batchCodeClose()">批量关闭</button>
+			   </small>
+		   </h1>
+		   <ol class="breadcrumb">
+		     <li><a href="#"><i class="fa fa-dashboard"></i> 爬虫</a></li>
+		     <li class="active">列表</li>
+		   </ol>
+		 </section>
+		<section class="content">
+			<div class="box">
+				<div class="box-body">
+					<table id="luamovecode" 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>
+								<th>历史节点</th>
+								<th>目标节点</th>
+								<th>下载量(comeintime)</th>
+								<th>下载量(publishtime)</th>
+								<th>迁移状态</th>
+								<th class="hidden-xs">操作</th>
+							</tr>
+						</thead>
+						<tbody>
+							
+						</tbody>
+					</table>
+				</div>
+			</div>
+		</section>
+<script>
+	$(function(){
+		luamovecodetable = $('#luamovecode').DataTable({
+			"language": {
+        		"url": "/js/dataTables.chinese.lang"
+      		},
+			"ajax": {
+      			"url": "/center/luamove",
+     			"type": "POST"
+      		},
+			"columnDefs": [
+				//{ "targets": 0 ,"bVisible": false}, //隐藏列
+			  { "orderable": false, "targets": [0,1,2,3,4,5,6,8,9] }, //设置列不可排序
+      		],
+			"order": [[7,"asc"]], //默认排序列
+			"lengthChange":false,
+			"serverSide": true,
+			"searching": true,
+			"ordering": true,
+			"info": true,
+			"autoWidth": true,
+			"columns": [
+				{"data": "code",render:function(val,a,row){
+					return "<input type='checkbox' ismove='"+row.ismove+"' state='"+row.state+"' code='"+row.code+"' movevent='"+row.toevent+"'/>"
+				}},
+	      		{"data": "site",width:"200px"},
+				{"data": "channel"},
+				{"data": "code"},
+				{"data": "ismove",width:"30px",render:function (val){
+					if(val){
+						return "是"
+					}else{
+						return "否"
+					}
+				}},
+				{"data": "fromevent",width:"30px"},
+				{"data": "toevent",width:"30px"},
+				{"data": "datanum"},
+				{"data": "ptimedatanum"},
+				{"data": "state",render:function (val){
+					if(val == 0){
+						return "未处理"
+					}else{
+						return "已处理"
+					}
+				}},
+        		{"data": "_id",width:"70px",render:function(val,a,row){
+					if(row.state == 1){
+						return ""
+					}
+					var div=$("<div><div class=\"btn-group\"></div></div>")
+					var buttonMove=$('<a type="button" target="_blank" class="btn btn-sm btn-success">迁移</a>');
+					var buttonClose=$('<a type="button" class="btn btn-sm btn-danger">关闭</a>');
+				  	buttonMove.attr("onclick","codeLuaMove('"+row.code+"','move','"+row.toevent+"')");
+					buttonClose.attr("onclick","codeLuaMove('"+row.code+"','close','')");
+					div.find(".btn-group").append(buttonMove);
+					div.find(".btn-group").append(buttonClose);
+					return div.html();
+				}}
+			],
+			"fnServerParams": function (e) {
+				var state = $("#state").val();
+				var fromevent = $("#fromevent").val();
+				var toevent = $("#toevent").val();
+				var ismove = $("#ismove").val();
+				//是否处理
+				if(state){
+					e.state = state;
+				}else{
+					e.state="-1";
+				}
+				//历史节点
+				if(fromevent){
+					e.fromevent = fromevent;
+				}else{
+					e.fromevent="-1";
+				}
+				//目标节点
+				if(toevent){
+					e.toevent = toevent;
+				}else{
+					e.toevent="-1";
+				}
+				//是否转移
+				if(ismove){
+					e.ismove = ismove;
+				}else{
+					e.ismove="-1";
+				}
+			}
+		});
+		common.setActive("index_pcqy");
+		luamovecodetable.on('init.dt', function () {
+			//是否处理
+			var opt_state="<option value='-1'>全部</option>"+
+					"<option value='1'>是</option>"+
+					"<option value='0'>否</option>";
+			var select_state="<div class='form-group'><label for='name'>是否处理:</label>"+
+					"<select id='state' onchange='checkclick(this.value)' class='form-control input-sm'>"+
+					opt_state+
+					"</select></div>"
+			$("#luamovecode_filter").prepend("&nbsp;&nbsp;");
+			$("#luamovecode_filter").prepend(select_state);
+			//节点
+			var event="<option value='-1'>全部</option>"
+			var events={{.T.events}}
+			for(k in events){
+				event+="<option value='"+events[k]+"'>"+events[k]+"</option>"
+			}
+			//目标节点
+			var select_fromevent="<div class='form-group'><label for='name'>目标节点:</label>"+
+					"<select id='toevent' onchange='checkclick(this.value)' class='form-control input-sm'>"+
+					event+
+					"</select></div>"
+			$("#luamovecode_filter").prepend("&nbsp;&nbsp;");
+			$("#luamovecode_filter").prepend(select_fromevent);
+			//历史节点
+			var select_toevent="<div class='form-group'><label for='name'>历史节点:</label>"+
+					"<select id='fromevent' onchange='checkclick(this.value)' class='form-control input-sm'>"+
+					event+
+					"</select></div>"
+			$("#luamovecode_filter").prepend("&nbsp;&nbsp;");
+			$("#luamovecode_filter").prepend(select_toevent);
+			//节点是否转移
+			var opt_move="<option value='-1'>全部</option>"+
+					"<option value='1'>是</option>"+
+					"<option value='0'>否</option>";
+			var select_move="<div class='form-group'><label for='name'>是否转移:</label>"+
+					"<select id='ismove' onchange='checkclick(this.value)' class='form-control input-sm'>"+
+					opt_move+
+					"</select></div>"
+			$("#luamovecode_filter").prepend("&nbsp;&nbsp;");
+			$("#luamovecode_filter").prepend(select_move);
+
+			//修改样式
+			$("#luamovecode_wrapper .col-sm-6").css({width:"100%"});
+		});
+	})
+	function checkclick(){
+		luamovecodetable.ajax.reload();
+	}
+  	//批量迁移
+	function batchCodeMove(){
+		var codes=[];
+    	var movevent=[];
+		$("#luamovecode_wrapper td input[type=checkbox]").each(function(){
+			if($(this).prop("checked") && $(this).attr("state") != "1" && $(this).attr("ismove") == "true"){
+				codes.push($(this).attr("code"));
+				movevent.push($(this).attr("movevent"));
+			}
+		});
+		if(codes.length >0){
+			showConfirm("确定批量迁移?", function() {
+        		codeLuaMove(codes.join(","),"move",movevent.join(","))
+			})
+		}else{
+			showTip("没有选择项", 1000);
+		}
+	}
+	//批量关闭
+	function batchCodeClose(){
+		var codes=[];
+		$("#luamovecode_wrapper td input[type=checkbox]").each(function(){
+			if($(this).prop("checked") && $(this).attr("state") != "1"){
+				codes.push($(this).attr("code"));
+			}
+		});
+		if(codes.length >0){
+			showConfirm("确定批量关闭?", function() {
+        	codeLuaMove(codes.join(","),"close","")
+			})
+		}else{
+			showTip("没有选择项", 1000);
+		}
+	}
+	
+  function codeLuaMove(code,stype,movevent){
+	var text = "迁移";
+	if(stype=="close"){
+	  text = "关闭"
+	}
+	$.ajax({
+	  url:"/center/luamove/luamovebycode",
+	  type:"post",
+	  data:{"code":code,"stype":stype,"movevent":movevent},
+	  success:function(r){
+		if(r&&r.ok){
+			$("#selrow").prop('checked',false);
+			luamovecodetable.ajax.reload();
+			showTip(text+"成功", 1000);
+		}else{
+		  showTip(text+"失败", 1000);
+		}
+	  }
+	})
+  }
+  
+  function selectrow(me){
+		var sel=$(me);
+		var isSelected=sel.prop('checked');
+		if(isSelected){
+			$("#luamovecode td input[type=checkbox]").prop("checked",true);
+		}else{
+			$("#luamovecode td input[type=checkbox]").prop("checked",false);
+		}
+	}
+ </script>
+</div>
+{{include "bottom.html"}}

+ 0 - 150
src/web/templates/luamovesite.html

@@ -1,150 +0,0 @@
-{{include "head.html"}}
-<div class="content-wrapper">
-		<section class="content-header">
-		   <h1>
-		     迁移站点列表
-		   </h1>
-      <ol class="breadcrumb">
-		     <li><a href="#"><i class="fa fa-dashboard"></i> 站点</a></li>
-		     <li class="active">列表</li>
-		   </ol>
-		 </section>
-		<section class="content">
-			<div class="box">
-				<div class="box-body">
-					<table id="luamovesite" class="table table-bordered table-striped">
-						<thead>
-							<tr>
-								<th>网站名称</th>
-                <th>节点</th>
-                <th>目标节点</th>
-								<th class="hidden-xs">操作</th>
-							</tr>
-						</thead>
-						<tbody>
-							
-						</tbody>
-					</table>
-				</div>
-			</div>
-		</section>
-<script>
-	$(function(){
-    //sitemap = {};
-		luamovesitetable = $('#luamovesite').DataTable({
-			"language": {
-        "url": "/js/dataTables.chinese.lang"
-      },
-			"ajax": {
-      	"url": "/center/luamove",
-     		"type": "POST",
-      },
-			"columnDefs": [
-        {"targets":[2], createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
-          {{if gt (session "auth") 2}}
-          var aInput;
-          $(cell).click(function () {
-            $(this).html(createComboxEvent(rowData.site));
-            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();
-            luamovesitetable.cell(cell).data(text);
-            cellData = text;
-          });
-          {{end}}
-        }}
-			],	
-			"lengthChange":false,
-			"serverSide": false,
-			"searching": false,
-			"ordering": false,
-			"info": true,
-			"autoWidth": true,
-      "paging": false,
-			"columns": [
-        {"data": "site"},
-				{"data": "event"},
-        {"data": "lm_movevent"},
-        {"data": "_id",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>');
-					var buttonMove=$('<a type="button" target="_blank" class="btn btn-sm btn-default">迁移</a>');
-					var buttonClose=$('<a type="button" class="btn btn-sm btn-default">关闭</a>');
-					buttonWatch.attr("href","/center/luamove/site/"+row.site);
-          buttonMove.attr("onclick","siteLuaMove('"+row.site+"','move','"+row.lm_movevent+"')");
-					buttonClose.attr("onclick","siteLuaMove('"+row.site+"','close','"+row.lm_movevent+"')");
-					div.find(".btn-group").append(buttonWatch);
-					div.find(".btn-group").append(buttonMove);
-          div.find(".btn-group").append(buttonClose);
-					return div.html();
-				}}
-			]
-      //"fnDrawCallback":function(s){
-      //  sitemap = s.json["sitemap"]
-      //}
-	  });
-		common.setActive("index_pcqy");
-	})
-  //按站点迁移、关闭
-  function siteLuaMove(site,stype,movevent){
-    var text = "迁移";
-    if(stype=="close"){
-      text = "关闭"
-    }
-    $.ajax({
-      url:"/center/luamove/luamovebysite",
-      type:"post",
-      data:{"site":site,"stype":stype,"movevent":movevent},
-      success:function(r){
-        if(r&&r.ok){
-          showTip(text+"成功", 1000);
-          $('#com-alert').on('hidden.bs.modal', function () {
-						luamovesitetable.ajax.reload();
-					})
-        }else{
-          showTip(text+"失败", 1000);
-        }
-      }
-    })
-  }
-  
-  function selectrow(me){
-		var sel=$(me);
-		var isSelected=sel.prop('checked');
-		if(isSelected){
-			$("#luamovesite td input[type=checkbox]").prop("checked",true);
-		}else{
-			$("#luamovesite td input[type=checkbox]").prop("checked",false);
-		}
-	}
-  //切换节点
-	function createComboxEvent(site){
-    var events={{.T.events}};
-    var spiderEvent="";
-		for(k in events){
-			spiderEvent+="<option value='"+events[k]+"'>"+events[k]+"</option>"
-		}
-    return "<select onchange='changeEventOrState(this.value,\""+site+"\",)' class='form-control input-sm'>"+spiderEvent+"</select>"
-  };
-  //修改目标节点
-  function changeEventOrState(movevent,site){
-    $.ajax({
-			url:"/center/spider/updateventbysite",
-			type:"post",
-			data:{
-				"movevent":movevent,
-        "site":site
-			}
-		})
-  };
-</script>
-</div>
-{{include "bottom.html"}}