Răsfoiți Sursa

-任务管理-udp

apple 5 ani în urmă
părinte
comite
941d88933f

+ 4 - 1
src/config.json

@@ -3,6 +3,8 @@
   "mgodb": "192.168.3.207:27092",
   "dbsize": 5,
   "dbname": "datatag",
+  "jydbname": "extract_kf",
+  "jycollname": "zk_xiufu_test01",
   "mgodben": "192.168.3.207:27092",
   "dbnameen": "enterprise",
   "mongoenc": "winner_enterprise",
@@ -16,5 +18,6 @@
   "jkmail": {
     "to": "wangjianghan@topnet.net.cn",
     "api": "http://10.171.112.160:19281/_send/_mail"
-  }
+  },
+  "udpport": ":11116"
 }

+ 2 - 0
src/main.go

@@ -12,6 +12,8 @@ import (
 	"github.com/go-xweb/xweb"
 )
 
+
+
 func init() {
 	qu.ReadConfig(&util.Sysconfig) //初始化配置
 	util.InitMgoPool()             //初始化连接

+ 110 - 2
src/service/repair_rule.go

@@ -2,17 +2,125 @@ package service
 
 import (
 	"github.com/go-xweb/xweb"
+	"gopkg.in/mgo.v2/bson"
+	"log"
 	qu "qfw/util"
+	"reflect"
+	. "util"
 )
 
 type RepairRule struct {
 	*xweb.Action
-	taskList     xweb.Mapper `xweb:"/service/jianyu/repair"`         //标签列表
+	repairList     xweb.Mapper `xweb:"/service/jianyu/repair"`
+	searchID       xweb.Mapper `xweb:"/service/jianyu/searchID"`
+	searchHref     xweb.Mapper `xweb:"/service/jianyu/searchHref"`
+	repairEdit     xweb.Mapper `xweb:"/service/jianyu/edit"`
+	repairDelete   xweb.Mapper `xweb:"/service/jianyu/delete"`
+	repairSave     xweb.Mapper `xweb:"/service/jianyu/save"`
+
 }
 
 
-func (jy *RepairRule) TaskList() {
+func (jy *RepairRule) RepairList() {
 	defer qu.Catch()
 	jy.Render("repair/jianyu_repair.html")
 
+
+}
+
+//编辑
+func (jy *RepairRule) RepairEdit() {
+	defer qu.Catch()
+	id := jy.GetString("id")
+	data, _ := JYMgo.FindById(JyCollName,id,"")
+	//log.Println(data)
+	tmp_id := qu.BsonIdToSId((*data)["_id"])
+	delete(*data, "_id")
+	jy.T["data"] = *data
+	jy.T["id"] = tmp_id
+	jy.Render("repair/jianyu_edit.html", &jy.T)
+}
+
+//删除
+func (jy *RepairRule) RepairDelete() {
+	defer qu.Catch()
+	//测试-待定
+	jy.ServeJson(map[string]interface{}{
+		"rep": true,
+	})
+	//_id := jy.GetString("_id")
+	//set := bson.M{"_id":qu.StringTOBsonId(_id)}
+	//b :=Mgo.Del("JyCollName",set)
+	//jy.ServeJson(map[string]interface{}{
+	//	"rep": b,
+	//})
 }
+
+
+//修改-mongo -es
+func (jy *RepairRule) RepairSave() {
+	if jy.Method() == "POST" {
+
+		data := GetPostForm(jy.Request)
+		//log.Println(data)
+		//log.Println(data["id"])
+		uploadData := qu.ObjToMap(data["data"])
+		log.Println(reflect.TypeOf(uploadData))
+		log.Println(uploadData)
+		//log.Println(data)
+		//id := data["id"].(string)
+		//delete(data, "id")
+
+		//id, rep := saveTaskMongo(id,data)
+		//task.ServeJson(map[string]interface{}{
+		//	"rep":       rep,
+		//})
+	}
+}
+
+
+//查询
+func (jy *RepairRule) SearchID() {
+	defer qu.Catch()
+	if jy.Method() == "POST" {
+		id := jy.GetString("_id")
+		id = "5eca4d52511b120337790327"//临时测试
+		if !bson.IsObjectIdHex(id){
+			jy.ServeJson(map[string]interface{}{
+				"rep":false,
+				"msg":"id格式不正确",
+			})
+		}else {
+			data, rep := JYMgo.Find(JyCollName, bson.M{"_id": qu.StringTOBsonId(id)}, nil, nil, false, -1, -1)
+			if !rep ||len(*data)<=0 {
+				jy.ServeJson(map[string]interface{}{
+					"rep": false,
+					"msg":"未查询到数据",
+				})
+			}else {
+				jy.ServeJson(map[string]interface{}{
+					"rep":				rep,
+					"data":            data,
+				})
+			}
+		}
+	}
+}
+
+func (jy *RepairRule) SearchHref() {
+	defer qu.Catch()
+	if jy.Method() == "POST" {
+		href := jy.GetString("href")
+		data, rep := JYMgo.Find(JyCollName, bson.M{"href": href}, nil, nil, false, -1, -1)
+		if !rep ||len(*data)<=0 {
+			jy.ServeJson(map[string]interface{}{
+				"rep":				false,
+			})
+		}else {
+			jy.ServeJson(map[string]interface{}{
+				"rep":				rep,
+				"data":            data,
+			})
+		}
+	}
+}

+ 142 - 22
src/service/task_rule.go

@@ -1,13 +1,17 @@
 package service
 
 import (
+	"encoding/json"
 	"github.com/go-xweb/xweb"
 	"gopkg.in/mgo.v2/bson"
 	"log"
+	"net"
+	"qfw/common/src/qfw/util"
 	qu "qfw/util"
 	"strings"
 	"time"
 	. "util"
+	mu "mfw/util"
 )
 
 type TaskRule struct {
@@ -19,6 +23,52 @@ type TaskRule struct {
 	taskDelete   xweb.Mapper `xweb:"/service/task/delete"`       //任务保存
 	taskStart    xweb.Mapper `xweb:"/service/task/start"`    //任务保存
 	taskEnd	 	 xweb.Mapper `xweb:"/service/task/end"`      //任务保存
+}
+var (
+	udpclient    	mu.UdpClient             //udp对象
+	taskConfig		map[string]interface{} //配置文件
+	isTaskOK		bool
+	timeout = 3
+)
+func init() {
+	qu.ReadConfig(&taskConfig) //初始化配置
+	updport := taskConfig["udpport"].(string)
+	udpclient = mu.UdpClient{Local: updport, BufSize: 1024}
+	log.Println("Udp服务监听", updport)
+	udpclient.Listen(processUdpMsg)
+}
+
+func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
+	switch act {
+	case mu.OP_TYPE_DATA:
+		var rep map[string]interface{}
+		err := json.Unmarshal(data, &rep)
+		if err != nil { //测试接收
+
+			go udpclient.WriteUdp([]byte{}, mu.OP_NOOP, ra) //回应上一个节点
+		} else {
+			by, _ := json.Marshal(map[string]interface{}{
+				"taskid":  rep["taskid"],
+				"stype":   rep["stype"],
+			})
+			go udpclient.WriteUdp(by, mu.OP_NOOP, ra) //回应上一个节点
+
+		}
+	case mu.OP_NOOP: //下个节点回应
+		log.Println("接收回应:",string(data))
+		var rep map[string]interface{}
+		err := json.Unmarshal(data, &rep)
+		if err != nil {//空数据
+			//
+		}else {//正确
+			if qu.ObjToString(rep["stype"])=="startTask" {
+				updateMgoIsuse("1",qu.ObjToString(rep["taskid"]))
+			}else if rep["stype"]=="stopTask"{
+				updateMgoIsuse("0",qu.ObjToString(rep["taskid"]))
+			}else {
+
+			}
+		}}
 
 }
 
@@ -61,7 +111,7 @@ func (task *TaskRule) TaskCreate() {
 func (task *TaskRule) TaskEdit() {
 	defer qu.Catch()
 	log.Println("编辑")
-	id := task.GetString("id")         //标签列表编辑
+	id := task.GetString("id")
 	query := bson.M{}
 	query["_id"] = qu.StringTOBsonId(id)
 	data, _ := Mgo.FindOneByField("taskinfo", query, `{}`)
@@ -112,40 +162,110 @@ func (task *TaskRule) TaskDelete() {
 
 //开始任务
 func (task *TaskRule) TaskStart() {
-	log.Println("启动")
 	defer qu.Catch()
-	id := task.GetString("_id")
-	set := bson.M{
-		"$set": bson.M{
-			"s_isuse": "1",
-		},
-	}
-	b := Mgo.UpdateById("taskinfo", id, set)
-	task.ServeJson(map[string]interface{}{
-		"rep": b,
+	data := GetPostForm(task.Request)
+	id := qu.ObjToString(data["id"])
+	//发送udp 开启
+	by, _ := json.Marshal(map[string]interface{}{
+		"taskid": id,
+		"stype": "startTask",
 	})
+	addr := &net.UDPAddr{
+		IP:   net.ParseIP(data["addr"].(string)),
+		Port: util.IntAll(data["port"]),
+	}
+
+	err :=udpclient.WriteUdp(by, mu.OP_TYPE_DATA, addr)
+	if err!=nil {
+		task.ServeJson(map[string]interface{}{
+			"rep": false,
+			"msg":"任务开始失败-udp",
+		})
+	}
+
+	n:=0
+	for {
+		if !isTaskOK && n < timeout {
+			time.Sleep(1 * time.Second)
+			n++
+		} else {
+			break
+		}
+	}
+	log.Println("循环结束",isTaskOK,n,"处理开启post回调")
+	if isTaskOK {
+		isTaskOK = false
+		task.ServeJson(map[string]interface{}{
+			"rep": true,
+			"msg":"任务开始成功",
+		})
+	}else {
+		isTaskOK = false
+		task.ServeJson(map[string]interface{}{
+			"rep": false,
+			"msg":"任务开始失败-超时",
+		})
+	}
 }
 
 //关闭任务
 func (task *TaskRule) TaskEnd() {
-	log.Println("关闭")
 	defer qu.Catch()
-	id := task.GetString("_id")
+	data := GetPostForm(task.Request)
+	id := qu.ObjToString(data["id"])
+	//发送udp 关闭
+	by, _ := json.Marshal(map[string]interface{}{
+		"taskid":  id,
+		"stype": "stopTask",
+	})
+	addr := &net.UDPAddr{
+		IP:   net.ParseIP(data["addr"].(string)),
+		Port: util.IntAll(data["port"]),
+	}
+	err :=udpclient.WriteUdp(by, mu.OP_TYPE_DATA, addr)
+	if err!=nil {
+		task.ServeJson(map[string]interface{}{
+			"rep": false,
+			"msg":"任务开始失败-udp",
+		})
+	}
+
+	n:=0
+	for {
+		if !isTaskOK && n < timeout {
+			time.Sleep(1 * time.Second)
+			n++
+		} else {
+			break
+		}
+	}
+	log.Println("循环结束",isTaskOK,n,"处理关闭post回调")
+	if isTaskOK {
+		isTaskOK = false
+		task.ServeJson(map[string]interface{}{
+			"rep": true,
+			"msg":"任务开始成功",
+		})
+	}else {
+		isTaskOK = false
+		task.ServeJson(map[string]interface{}{
+			"rep": false,
+			"msg":"任务开始失败-超时",
+		})
+	}
+}
+
+func updateMgoIsuse(isu string,id string)  {
 	set := bson.M{
 		"$set": bson.M{
-			"s_isuse": "0",
+			"s_isuse": isu,
 		},
 	}
-	b := Mgo.UpdateById("taskinfo", id, set)
-	task.ServeJson(map[string]interface{}{
-		"rep": b,
-	})
+	log.Println(id)
+	Mgo.UpdateById("taskinfo", id, set)
+	isTaskOK = true
 }
 
-
-
-
-
 //******方法
 func saveTaskMongo(id string, rdata map[string]interface{}) (rid string, rep bool) {
 	defer qu.Catch()

+ 19 - 0
src/util/config.go

@@ -9,11 +9,13 @@ import (
 var (
 	Sysconfig       map[string]interface{} //配置文件
 	Mgo             *mongodb.MongodbSim
+	JYMgo			*mongodb.MongodbSim
 	MgoEn           *mongodb.MongodbSim
 	EsIndex, EsType string
 	MgoEnC          string
 	Subday          float64
 	PreviewHref     string //数据预览地址
+	JyCollName		string
 )
 
 var (
@@ -38,6 +40,9 @@ func InitMgoPool() {
 	}
 	Mgo.InitPool()
 }
+
+
+
 func initMgoEn() {
 	MgoEn = &mongodb.MongodbSim{
 		MongodbAddr: qu.ObjToString(Sysconfig["mgodben"]),
@@ -48,6 +53,17 @@ func initMgoEn() {
 	MgoEn.InitPool()
 }
 
+func initJYMgo()  {
+	JYMgo = &mongodb.MongodbSim{
+		MongodbAddr: qu.ObjToString(Sysconfig["mgodben"]),
+		Size:        qu.IntAll(Sysconfig["dbsize"]),
+		DbName:      qu.ObjToString(Sysconfig["jydbname"]),
+	}
+	JyCollName = qu.ObjToString(Sysconfig["jycollname"])
+	JYMgo.InitPool()
+
+}
+
 func InitOther() {
 	initCitys()
 	initInfoType()
@@ -58,10 +74,13 @@ func InitOther() {
 	initTaskType()
 	initEs()
 	initMgoEn()
+	initJYMgo()
 	Subday = qu.Float64All(Sysconfig["subday"])
 	PreviewHref = qu.ObjToString(Sysconfig["preview_href"])
 }
 
+
+
 func initCitys() {
 	//map初始化
 	if ProvinceCitys == nil {

+ 99 - 0
src/web/templates/repair/jianyu_edit.html

@@ -0,0 +1,99 @@
+{{include "com/inc.html"}}
+<!-- Main Header -->
+{{include "com/header.html"}}
+<!-- Left side column. 权限菜单 -->
+{{include "com/menu.html"}}
+{{include "com/modal.html"}}
+
+<style>
+    /* 方法1:设置textarea合适的宽高 */
+    #jsonTextarea {
+        float: left;
+        margin-right: 20px;
+        width: 40%;
+        height: 70vh;
+        outline: none;
+        padding: 5px;
+    }
+
+    /* 方法2:自定义高亮样式 */
+    #jsonPre {
+        float: left;
+        width: 40%;
+        height: 70vh;
+        outline: 1px solid #ccc;
+        padding: 5px;
+        overflow: scroll;
+    }
+</style>
+
+{{/*<script src="/time/js/angular.min.js"></script>*/}}
+{{/*<script src="/time/js/wui-date.js"></script>*/}}
+<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><a href="/service/jianyu/repair">维护中心</a></li>
+            <li><a href="#">修复数据</a></li>
+        </ol>
+    </section>
+    <!-- Main content -->
+    <section class="content">
+        <div class="nav-tabs-custom">
+            <ul class="nav nav-tabs edit-step">
+                </br>
+                <button class="btn btn-primary btn-sm" style="float: right;margin-top: 7px;margin-right: 10px" onclick="saveRepair()"><i class="fa fa-fw fa-file-text fa-lg"></i>更新数据</button>
+                </br></br></br>
+            </ul>
+            <form class="form-horizontal">
+                <div class="box-body">
+                    <textarea id="jsonTextarea"></textarea>
+                </div>
+            </form>
+        </div>
+    </section>
+</div>
+
+{{include "com/dialog.html"}}
+{{include "com/footer.html"}}
+<script>
+    menuActive("/service/jianyu/repair");
+    var edit_data = {{.T.data}};
+    var cur_id = {{.T.id}};
+    // alert(JSON.stringify(cur_id))
+    function parse(str) {
+        return JSON.stringify(str, null, "\t")
+    }
+    $('#jsonTextarea').val(parse(edit_data));
+
+    function saveRepair() {
+        var curData = document.getElementById('jsonTextarea').value;
+        var data = JSON.parse(curData)
+        alert(JSON.stringify(data))
+
+        for (var k in data) {
+            // alert(k)
+            // alert(data[k])
+        }
+        $.ajax({
+            url: "/service/jianyu/save",
+            type: 'POST',
+            data: {"id":cur_id,"data":edit_data},
+            success: function (task) {
+                if (task.rep) {
+                    window.location.href="/service/jianyu/repair"
+                } else {
+                    showTip("更新失败",1000);
+                }
+            }
+        })
+
+    }
+
+
+
+
+
+
+</script>

+ 196 - 10
src/web/templates/repair/jianyu_repair.html

@@ -1,10 +1,196 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <title>Title</title>
-</head>
-<body>
-
-</body>
-</html>
+{{include "com/inc.html"}}
+<!-- Main Header -->
+{{include "com/header.html"}}
+<!-- Left side column. 权限菜单 -->
+{{include "com/menu.html"}}
+{{include "com/modal.html"}}
+
+<style>
+    .j-input__inner {
+        box-sizing: border-box;
+        display: inline-block;
+        padding: 0px 45px 0px 15px;
+        width: 300px;
+        height: 40px;
+        color: #1D1D1D;
+
+        background-color: #fff;
+        background-image: none;
+        line-height: 40px;
+        font-size: inherit;
+        -webkit-appearance: none;
+        outline: none;
+        border: 1px solid #dcdfe6;
+        border-radius: 4px;
+        transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
+    }
+    .j-input__inner:hover {
+        border-color: #c0c4cc;
+    }
+    .j-input__inner:focus {
+        border-color: #409eff;
+    }
+    .search-icon {
+        position:relative;
+        width: 30px;
+        height: 30px;
+        top: 0px;
+        right: 40px;
+    }
+</style>
+
+<div class="content-wrapper" id="showbtn">
+    <section class="content-header">
+        <ol class="breadcrumb">
+            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
+            <li><a href="/service/jianyu/repair"> 维护中心</a></li>
+        </ol>
+
+        <br/>
+    </section>
+    <!-- Main content -->
+    <section class="content">
+        <div class="row">
+            <div class="col-xs-12">
+                <div class="box">
+                    <div class="box-body">
+                        <div class="tab-content">
+                            <input class="j-input__inner" type="text" placeholder="请输入查询的id" id="idSea">
+                            <img src="" class="search-icon" onclick="idSearch()" />
+                            <input class="j-input__inner" type="text" placeholder="请输入查询的href" id="hrefSea">
+                            <img src="" class="search-icon" onclick="hrefSearch()" />
+                        </div>
+
+                        <table id="dataTable" class="table table-bordered table-hover">
+                            <thead>
+                            <tr>
+                                <th>编号</th>
+                                <th>标题</th>
+                                <th>正文</th>
+                                <th>发布时间</th>
+                                <th>操作</th>
+                            </tr>
+                            </thead>
+                        </table>
+                    </div>
+                    <!-- /.box-body -->
+                </div>
+                <!-- /.box -->
+            </div>
+        </div>
+    </section>
+</div>
+
+{{include "com/dialog.html"}}
+{{include "com/footer.html"}}
+<script>
+    menuActive("/jianyu/repair");
+    $(document).ready(function () {
+        ttable = $('#dataTable').DataTable({
+            "paging": false,
+            "lengthChange": false,
+            "searching": false,
+            "ordering": false,
+            "info": true,
+            "autoWidth": false,
+            "serverSide": false,
+            "language": {
+                "url": "/dist/js/dataTables.chinese.lang"
+            },
+            "fnDrawCallback": function () {
+                $("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) {
+                    var redirectpage = 0
+                    if ($("#changePage").val() && $("#changePage").val() > 0) {
+                        var redirectpage = $("#changePage").val() - 1;
+                    }
+                    ttable.page(redirectpage).draw(false);
+                });
+                this.api().column(0).nodes().each(function(cell, i) {
+                    cell.innerHTML = i + 1;
+                });
+            },
+            "columns": [
+                {"data": null,width:"8%"},
+                {"data": "title"},
+                {"data": "href",width:"20%"},
+                {"data": "publishtime",width:"20%", render: function (val) {
+                        var dt = new Date()
+                        dt.setTime(parseInt(val) * 1000);
+                        return dt.format("yyyy-MM-dd hh-mm-ss")
+                    }},
+                {"data": "_id", width:"15%",render: function (val, a, row, pos) {
+                        tmp = '<div>' +
+                            '<a class="btn btn-sm btn-primary" href="/service/jianyu/edit?id='+val+'">编辑</a>'+
+                            '&nbsp'+'&nbsp'+
+                            '<a class="btn btn-sm btn-danger" onclick="del_repair(\''+val+'\')">删除</a>'+
+                            '</div>';
+                        return tmp
+                    }}
+            ]
+        });
+    });
+
+
+    function idSearch() {
+        var search_name = $('#idSea').val()
+        $.ajax({
+            url:"/service/jianyu/searchID",
+            type:"post",
+            data:{"_id": search_name},
+            success:function(r){
+                if (r.rep) {
+                    $('#dataTable').dataTable().fnClearTable();
+                    $('#dataTable').dataTable().fnAddData(r.data);
+                }else {
+                    showTip(r.msg)
+                }
+            }
+        })
+    }
+    function hrefSearch() {
+        var search_name = $('#hrefSea').val()
+        $.ajax({
+            url:"/service/jianyu/searchHref",
+            type:"post",
+            data:{"href": search_name},
+            success:function(r){
+                if (r.rep) {
+                    $('#dataTable').dataTable().fnClearTable();
+                    $('#dataTable').dataTable().fnAddData(r.data);
+                }else {
+                    showTip("请输入正确的href")
+                }
+            }
+        })
+    }
+
+
+
+
+
+
+
+    function del_repair(del_id){
+        showConfirm("确定删除?", function() {
+            $.ajax({
+                url:"/service/jianyu/delete",
+                type:"post",
+                data:{"_id": del_id},
+                success:function(r){
+                    if(r.rep){
+                        $('#dataTable').dataTable().fnClearTable();
+                    }else{
+                        alert("删除失败");
+                    }
+                }
+            })
+        });
+    }
+
+
+
+
+
+
+</script>

+ 22 - 3
src/web/templates/task/task_create.html

@@ -52,6 +52,20 @@
                         </div>
 
                     </div>
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label"><span style="color:red;">* </span>udp地址</label>
+                        <div class="col-sm-3">
+                            <input type="text" class="form-control" id="udpaddr" placeholder="请输入地址" required>
+                        </div>
+
+                        <label class="col-sm-2 control-label"><span style="color:red;">* </span>udp端口</label>
+                        <div class="col-sm-3">
+                            <input type="text" class="form-control" id="udport" placeholder="请输入端口" required>
+                        </div>
+                    </div>
+
+
                     <div class="form-group">
                         <label class="col-sm-2 control-label"><span style="color:red;">* </span>起始id</label>
                         <div class="col-sm-3">
@@ -88,9 +102,9 @@
                     </div>
 
                     <div class="form-group">
-                        <label class="col-sm-2 control-label"><span style="color:red;">* </span>from数据库</label>
+                        <label class="col-sm-2 control-label"><span style="color:red;">* </span>from数据库/index</label>
                         <div class="col-sm-3">
-                            <input type="text" class="form-control" id="fromdbname" placeholder="请输入数据库名"
+                            <input type="text" class="form-control" id="fromdbname" placeholder="请输入数据库名/index"
                                    value="">
                         </div>
                         <label class="col-sm-2 control-label"><span style="color:red;">* </span>from表</label>
@@ -153,6 +167,8 @@
     var codeType = {{.T.taskType}};
     var dict = {
         "id":"",
+        "s_udpaddr":"",
+        "s_udport":"",
         "s_taskname": "",
         "s_isuse": "0",
         "s_tasktype": "",
@@ -189,7 +205,8 @@
         if (data["s_taskname"]==""||data["s_tasktype"]==""||data["s_startid"]==""||
             data["s_fromdburl"]==""||data["s_fromdbname"]==""|| data["s_fromdbcoll"]==""||
             data["s_fromtype"]==""|| data["s_todburl"]==""||data["s_todbname"]==""||
-            data["s_todbcoll"]==""|| data["s_totype"]=="") {
+            data["s_todbcoll"]==""|| data["s_totype"]==""|| data["s_udpaddr"]=="" ||
+            data["s_udport"]=="") {
             return true
         }
         return false
@@ -203,6 +220,8 @@
         dict["s_todburl"] = $('#todburl').val();
         dict["s_todbname"] = $('#todbname').val();
         dict["s_todbcoll"] = $("#todbcoll").val();
+        dict["s_udpaddr"] = $('#udpaddr').val();
+        dict["s_udport"] = $("#udport").val();
 
 
         if (checkDict(dict)) {

+ 24 - 4
src/web/templates/task/task_edit.html

@@ -52,6 +52,20 @@
                         </div>
 
                     </div>
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label"><span style="color:red;">* </span>udp地址</label>
+                        <div class="col-sm-3">
+                            <input type="text" class="form-control" id="udpaddr" placeholder="请输入地址" required>
+                        </div>
+
+                        <label class="col-sm-2 control-label"><span style="color:red;">* </span>udp端口</label>
+                        <div class="col-sm-3">
+                            <input type="text" class="form-control" id="udport" placeholder="请输入端口" required>
+                        </div>
+                    </div>
+
+
                     <div class="form-group">
                         <label class="col-sm-2 control-label"><span style="color:red;">* </span>起始id</label>
                         <div class="col-sm-3">
@@ -88,9 +102,9 @@
                     </div>
 
                     <div class="form-group">
-                        <label class="col-sm-2 control-label"><span style="color:red;">* </span>from数据库</label>
+                        <label class="col-sm-2 control-label"><span style="color:red;">* </span>from数据库/index</label>
                         <div class="col-sm-3">
-                            <input type="text" class="form-control" id="fromdbname" placeholder="请输入数据库名"
+                            <input type="text" class="form-control" id="fromdbname" placeholder="请输入数据库名/index"
                                    value="">
                         </div>
                         <label class="col-sm-2 control-label"><span style="color:red;">* </span>from表</label>
@@ -170,6 +184,8 @@
         "s_createuser": edit_data["s_createuser"],
         "i_updatetime": edit_data["i_updatetime"],
         "s_updateuser": edit_data["s_updateuser"],
+        "s_udport": edit_data["s_udport"],
+        "s_udpaddr": edit_data["s_udpaddr"],
     };
 
     $(document).ready(function () {
@@ -205,13 +221,16 @@
         $("#todbname").val(dict["s_todbname"])
         $("#todbcoll").val(dict["s_todbcoll"])
         $("#totype").val(dict["s_totype"])
+        $("#udpaddr").val(dict["s_udpaddr"])
+        $("#udport").val(dict["s_udport"])
 
     });
     function checkDict(data)  {
         if (data["s_taskname"]==""||data["s_tasktype"]==""||data["s_startid"]==""||
             data["s_fromdburl"]==""||data["s_fromdbname"]==""|| data["s_fromdbcoll"]==""||
             data["s_fromtype"]==""|| data["s_todburl"]==""||data["s_todbname"]==""||
-            data["s_todbcoll"]==""|| data["s_totype"]=="") {
+            data["s_todbcoll"]==""|| data["s_totype"]==""|| data["s_udpaddr"]=="" ||
+            data["s_udport"]=="") {
             return true
         }
         return false
@@ -225,7 +244,8 @@
         dict["s_todburl"] = $('#todburl').val();
         dict["s_todbname"] = $('#todbname').val();
         dict["s_todbcoll"] = $("#todbcoll").val();
-
+        dict["s_udpaddr"] = $('#udpaddr').val();
+        dict["s_udport"] = $("#udport").val();
 
         if (checkDict(dict)) {
             let msg = "请完善所有信息"

+ 25 - 22
src/web/templates/task/task_list.html

@@ -4,6 +4,9 @@
 <!-- Left side column. 权限菜单 -->
 {{include "com/menu.html"}}
 {{include "com/modal.html"}}
+
+
+
 <div class="content-wrapper" id="showbtn">
     <section class="content-header">
         <h1>
@@ -88,7 +91,7 @@
                         tmp = '<div>' +
                             '<a class="btn btn-sm btn-primary" href="/service/task/edit?id='+val+'">编辑</a>'+
                             '&nbsp'+'&nbsp'+
-                            '<a class="btn btn-sm btn-danger" onclick="del_task(\''+val+'\')">删除</a>'+
+                            '<a class="btn btn-sm btn-danger"  onclick="del_task(\''+val+'\')">删除</a>'+
                             '</div>';
                         return tmp
                     }},
@@ -97,15 +100,15 @@
                         if (row.s_isuse=="0") {
                             //未启动
                             tmp = '<div>' +
-                                '<a class="btn btn-sm btn-primary" onclick="start_task(\''+val+'\')">启动</a>'+
+                                '<a class="btn btn-sm btn-primary" onclick="start_task(\''+val+'\',\''+row.s_udpaddr+'\',\''+row.s_udport+'\')">启动</a>'+
                                 '&nbsp'+'&nbsp'+
-                                '<a class="btn btn-sm btn-info" disabled="true" onclick="end_task(\''+val+'\')">关闭</a>'+                                '</div>';
+                                '<a class="btn btn-sm btn-info" disabled="true" href="javascript:return false;">关闭</a>'+                                '</div>';
                                 '<div>';
                         } else {
                             tmp = '<div>'+
-                                '<a class="btn btn-sm btn-primary" disabled="true" onclick="start_task(\''+val+'\')">已启动</a>'+
+                                '<a class="btn btn-sm btn-primary" disabled="true" href="javascript:return false;">已启动</a>'+
                                 '&nbsp'+'&nbsp'+
-                                '<a class="btn btn-sm btn-info" onclick="end_task(\''+val+'\')">关闭</a>'+
+                                '<a class="btn btn-sm btn-info" onclick="end_task(\''+val+'\',\''+row.s_udpaddr+'\',\''+row.s_udport+'\')">关闭</a>'+
                                 '</div>';
                         }
 
@@ -116,34 +119,36 @@
         });
     });
 
-    function del_task(del_id){
-        showConfirm("确定删除?", function() {
+
+    function start_task(id,addr,port){
+        showConfirm("确定开启任务?", function() {
             $.ajax({
-                url:"/service/task/delete",
+                url:"/service/task/start",
                 type:"post",
-                data:{"_id": del_id},
+                data:{"id": id,"addr": addr,"port": port},
                 success:function(r){
                     if(r.rep){
                         ttable.ajax.reload();
                     }else{
-                        alert("删除失败");
+                        alert(r.msg);
                     }
                 }
             })
         });
     }
 
-    function start_task(task_id){
-        showConfirm("确定开启任务?", function() {
+
+    function end_task(id,addr,port){
+        showConfirm("确定关闭任务?", function() {
             $.ajax({
-                url:"/service/task/start",
+                url:"/service/task/end",
                 type:"post",
-                data:{"_id": task_id},
+                data:{"id": id,"addr": addr,"port": port},
                 success:function(r){
                     if(r.rep){
                         ttable.ajax.reload();
                     }else{
-                        alert("开启任务失败");
+                        alert(r.msg);
                     }
                 }
             })
@@ -151,17 +156,17 @@
     }
 
 
-    function end_task(task_id){
-        showConfirm("确定关闭任务?", function() {
+    function del_task(del_id){
+        showConfirm("确定删除?", function() {
             $.ajax({
-                url:"/service/task/end",
+                url:"/service/task/delete",
                 type:"post",
-                data:{"_id": task_id},
+                data:{"_id": del_id},
                 success:function(r){
                     if(r.rep){
                         ttable.ajax.reload();
                     }else{
-                        alert("开启任务失败");
+                        alert("删除失败");
                     }
                 }
             })
@@ -169,6 +174,4 @@
     }
 
 
-
-
 </script>