zhangjinkun 7 жил өмнө
parent
commit
d0551e71d9

+ 45 - 0
src/jy/admin/rule.go

@@ -24,6 +24,8 @@ const (
 	EFL = "EFL" //抽取前置脚本
 	EBE = "EBE" //抽取后置正则
 	EBL = "EBL" //抽取后置脚本
+	ECE = "ECE" //抽取逻辑正则
+	ECL = "ECL" //抽取逻辑脚本
 )
 
 func init() {
@@ -72,6 +74,15 @@ func init() {
 	})
 	Admin.POST("/logicback/data", RuleLogicBackData)
 	Admin.POST("/logicback/save", RuleLogicBackSave)
+	Admin.POST("/logicback/del", RuleLogicBackDel)
+	Admin.GET("/logicore", func(c *gin.Context) {
+		version := c.Query("version")
+		sid := c.Query("sid")
+		c.HTML(200, "rule_logicore.html", gin.H{"version": version, "sid": sid})
+	})
+	Admin.POST("/logicore/data", RuleLogicCoreData)
+	Admin.POST("/logicore/save", RuleLogicCoreSave)
+	Admin.POST("/logicore/del", RuleLogicCoreDel)
 
 	//ruletag
 	Admin.GET("/ruletag", func(c *gin.Context) {
@@ -287,6 +298,40 @@ func RuleLogicBackDel(c *gin.Context) {
 	b := Mgo.Del("rule_logicback", `{"_id":"`+_id+`"}`)
 	c.JSON(200, gin.H{"rep": b})
 }
+func RuleLogicCoreData(c *gin.Context) {
+	sid, _ := c.GetPostForm("sid")
+	data, _ := Mgo.Find("rule_logicore", `{"sid":"`+sid+`"}`, `{"_id":-1}`, nil, false, -1, -1)
+	c.JSON(200, gin.H{"data": data, "sid": sid})
+}
+func RuleLogicCoreSave(c *gin.Context) {
+	data := GetPostForm(c)
+	_id, _ := c.GetPostForm("_id")
+	b := false
+	if _id == "" {
+		data["l_createtime"] = time.Now().Unix()
+		data["s_username"] = sessions.Default(c).Get("username")
+		s_type := data["s_type"]
+		code := ""
+		if s_type == "0" { //抽取逻辑正则
+			code = util.GetSyncIndex(ECE)
+		} else { //抽取逻辑脚本
+			code = util.GetSyncIndex(ECL)
+		}
+		data["s_code"] = code
+		b = Mgo.Save("rule_logicore", data) != ""
+	} else {
+		data["l_lasttime"] = time.Now().Unix()
+		b = Mgo.Update("rule_logicore", `{"_id":"`+_id+`"}`, map[string]interface{}{
+			"$set": data,
+		}, true, false)
+	}
+	c.JSON(200, gin.H{"rep": b})
+}
+func RuleLogicCoreDel(c *gin.Context) {
+	_id, _ := c.GetPostForm("_id")
+	b := Mgo.Del("rule_logicore", `{"_id":"`+_id+`"}`)
+	c.JSON(200, gin.H{"rep": b})
+}
 
 //标签库列表
 func RuleTagData(c *gin.Context) {

+ 1 - 1
src/web/templates/admin/rule_logiclist.html

@@ -82,7 +82,7 @@ $(function () {
 				tmp = '<div class="btn-group">'+
 					'<a class="btn btn-sm btn-primary" href="/admin/logicpre?version='+{{.version}}+'&sid='+row._id+'">前置规则</a>'+
 					//'<a class="btn btn-sm btn-success opr" opr="editlua">抽取规则</a>'+
-					'<a class="btn btn-sm btn-success" href="/admin/logic?version='+{{.version}}+'&sid='+row._id+'">抽取规则</a>'+
+					'<a class="btn btn-sm btn-success" href="/admin/logicore?version='+{{.version}}+'&sid='+row._id+'">抽取规则</a>'+
 					'<a class="btn btn-sm btn-info" href="/admin/logicback?version='+{{.version}}+'&sid='+row._id+'">后置规则</a>'+
 					'</div>';
 				return  tmp

+ 198 - 0
src/web/templates/admin/rule_logicore.html

@@ -0,0 +1,198 @@
+{{template "inc"}}
+<!-- Main Header -->
+{{template "header"}}
+<!-- Left side column. 权限菜单 -->
+{{template "memu"}}
+
+<!-- Content Wrapper. Contains page content -->
+<div class="content-wrapper">
+	<section class="content-header">
+		<h1>
+			<small><a class="btn btn-primary opr" opr="new">新增正则</a></small>
+			<small><a class="btn btn-primary opr" opr="newlua">新增脚本</a></small>
+		</h1>
+		<ol class="breadcrumb">
+		  <li><a href="/admin/version"><i class="fa fa-dashboard"></i>版本管理</a></li>
+		  <li><a href="/admin/rulelogic?version={{.version}}">抽取逻辑</a></li>
+		  <li class="active"><a href="/admin/logicore?version={{.version}}&sid={{.sid}}">抽取规则</a></li>
+		</ol>
+    </section>
+  <!-- Main content -->
+  <section class="content">
+      <div class="row">
+	      <div class="col-xs-12">
+	        <div class="box">
+		        <div class="box-body">
+		            <table id="dataTable" class="table table-bordered table-hover">
+		              <thead>
+		              <tr>
+						<th>代码</th>
+		                <th>名称</th>
+						<th>创建人</th>
+						<th>描述</th>
+						<th>类型</th>
+						<th>操作</th>
+		              </tr>
+		              </thead>
+		            </table>
+		        </div>
+	          <!-- /.box-body -->
+	        </div>
+        <!-- /.box -->
+		</div>
+	</div>
+  </section>
+</div>
+{{template "luares"}}
+{{template "dialog"}}
+{{template "footer"}}
+
+<script>
+menuActive("version")
+$(function () {
+	ttable=$('#dataTable').DataTable({
+		"paging"      : false,
+		"lengthChange": false,
+		"searching"   : true,
+		"ordering"    : false,
+		"info"        : true,
+		"autoWidth"   : false,
+		"ajax": {
+			"url": "/admin/logicore/data",
+			"type": "post",
+			"data":{"sid":{{ .sid}} }
+		 },
+		"language": {
+            "url": "/res/dist/js/dataTables.chinese.lang"
+        },
+		"columns": [
+			{ "data": "s_code"},
+            { "data": "s_name"},
+			{ "data": "s_username"},
+			{ "data": "s_descript"},
+			{ "data": "s_type",render:function(val,a,row){
+				if(val=="0"){
+					return "正则"
+				}else{
+					return "lua脚本"
+				}
+			}},
+			{ "data": "_id",render:function(val,a,row,pos){
+				tmp=""
+				if(row.s_type=="0"){
+					tmp = '<div>'+
+						'<a class="btn btn-sm btn-primary opr" opr="edit" row="'+pos.row+'" >编辑</a> '+
+						'<a class="btn btn-sm btn-warning" onclick="del(\''+val+'\')">删除</a> '+
+						'</div>';
+				}else{
+					tmp = '<div>'+
+						'<a class="btn btn-sm btn-primary opr" opr="editlua" row="'+pos.row+'" >编辑</a> '+
+						'<a class="btn btn-sm btn-warning" onclick="del(\''+val+'\')">删除</a> '+
+						'</div>';
+				}
+				return tmp
+			}}
+       	]
+	});
+	ttable.on('init.dt', function () {
+		$(".opr").click(function(){
+			var n=$(this).attr("opr")
+			var htmlObj={},obj,tag=[]
+			var _tit="" 
+			switch(n){
+			case "edit":			
+				obj=ttable.row($(this).closest("tr")).data();
+			case "editlua":			
+				obj=ttable.row($(this).closest("tr")).data();
+			case "newlua":
+			case "new":
+				comtag=[{label:"名称",s_label:"s_name",placeholder:"",must:true},{label:"描述",s_label:"s_descript",type:"tpl_text"}]
+				regtag=[{label:"正则",s_label:"s_rule",type:"tpl_text",must:true}]
+				luatag=[{label:"脚本",s_label:"s_luascript",type:"tpl_text",must:true}]
+				hiddentag=[{s_label:"_id",type:"tpl_hidden"},{s_label:"sid",type:"tpl_hidden"},{s_label:"s_type",type:"tpl_hidden"},{s_label:"s_version",type:"tpl_hidden"}]
+				islua=false
+				tag = com.pushArry(tag,comtag)
+				if(n=="edit"){
+					_tit="编辑-"+obj.s_name
+					tag = com.pushArry(tag,regtag)
+					tag = com.pushArry(tag,hiddentag)
+				}else if(n=="editlua"){
+					_tit="编辑-"+obj.s_name
+					islua=true
+					tag = com.pushArry(tag,luatag)
+					tag = com.pushArry(tag,hiddentag)
+				}else{
+					_tit="新增规则"
+					if(n=="newlua"){
+						_tit="新增脚本"
+						obj={"sid":"{{.sid}}","s_type":"1","s_version":"{{.version}}"}
+						tag = com.pushArry(tag,luatag)
+						tag = com.pushArry(tag,hiddentag)
+						islua=true
+					}else{
+						obj={"sid":"{{.sid}}","s_type":"0","s_version":"{{.version}}"}
+						tag = com.pushArry(tag,regtag)
+						tag = com.pushArry(tag,hiddentag)
+					}
+				}
+				htmlObj={
+					title:_tit,
+					tag:tag,
+					lua:islua,
+					bts:[
+						{label:"保存",class:"btn-primary",
+							fun:function(){
+								var obj={}
+								var bcon=true
+								$("#_con").find("input[id!=s_show],textarea").each(function(i,el){
+									var val=$(el).val();
+									if(el.id=="s_luascript"){
+										val=editor_1.getValue()
+										obj[el.id]=val
+									}else{
+										obj[el.id]=$(el).val()
+									}
+									if(el.id!="_id"&&$(el).attr("must")&&!val){
+										bcon=false
+										return false
+									}
+								})
+								if (bcon){								
+									$.post("/admin/logicore/save",obj,function(data){
+										if(data&&data.rep){
+											window.location.href="/admin/logicore?version={{.version}}&sid={{.sid}}"								
+										}else{
+											showTip(data.msg,1000)
+										}
+									},'json')
+								}else{
+									alert("红色标签的表单不能为空!")
+								}
+							}
+						}
+					]
+				}
+			OpenDialog(htmlObj,obj)
+			break;
+			}
+		});
+	})
+})
+
+function del(_id){
+	showConfirm("确定删除?", function() {
+		$.ajax({
+			url:"/admin/logicore/del",
+			type:"post",
+			data:{"_id":_id},
+			success:function(r){
+				if(r.rep){				
+					ttable.ajax.reload();
+				}else{
+					showTip("删除失败", 1000);
+				}
+			}
+		})
+	});
+}
+</script>