zhangjinkun 6 年之前
父节点
当前提交
ccd887f00a
共有 3 个文件被更改,包括 84 次插入79 次删除
  1. 82 13
      src/jy/admin/rulecheck.go
  2. 2 1
      src/jy/extract/extract.go
  3. 0 65
      src/jy/extract/extractcheck.go

+ 82 - 13
src/jy/admin/rulecheck.go

@@ -6,6 +6,8 @@ import (
 	. "jy/mongodbutil"
 	ju "jy/util"
 	qu "qfw/util"
+	"regexp"
+	"strings"
 
 	"github.com/gin-gonic/gin"
 )
@@ -15,20 +17,20 @@ func init() {
 	Admin.POST("/check/prerule", func(c *gin.Context) {
 		rule, _ := c.GetPostForm("s_rule")
 		con, _ := c.GetPostForm("s_testcon")
-		str := extract.PreRulesCheckReg(con, rule)
+		str := checkPreReg(con, rule)
 		c.JSON(200, gin.H{"rep": str})
 	})
 	Admin.POST("/check/extrule", func(c *gin.Context) {
 		rule, _ := c.GetPostForm("s_rule")
 		con, _ := c.GetPostForm("s_testcon")
 		field, _ := c.GetPostForm("s_field")
-		tmp := extract.ExtRulesCheckReg(field, con, rule)
+		tmp := checkCoreReg(field, con, rule)
 		c.JSON(200, gin.H{"rep": tmp})
 	})
 	Admin.POST("/check/backrule", func(c *gin.Context) {
 		rule, _ := c.GetPostForm("s_rule")
 		con, _ := c.GetPostForm("s_testcon")
-		str := extract.BackRulesCheckReg(con, rule)
+		str := checkBackReg(con, rule)
 		c.JSON(200, gin.H{"rep": str})
 	})
 
@@ -63,7 +65,7 @@ func init() {
 		version, _ := c.GetPostForm("s_version")
 		code, _ := c.GetPostForm("s_code")
 		name, _ := c.GetPostForm("s_name")
-		extinfo := checkBackScript(code, name, version, infoid, luascript)
+		extinfo := checkBackScript("rule_back", code, name, version, infoid, luascript, true)
 		c.JSON(200, gin.H{"rep": extinfo})
 	})
 	//抽取前置验证
@@ -131,7 +133,7 @@ func init() {
 		name, _ := c.GetPostForm("s_name")
 		vid, _ := c.GetPostForm("vid")
 		version, _ := Mgo.FindById("version", vid, `{"version":1}`)
-		extinfo := checkBackScript(code, name, qu.ObjToString((*version)["version"]), infoid, luascript)
+		extinfo := checkBackScript("rule_logicback", code, name, qu.ObjToString((*version)["version"]), infoid, luascript, true)
 		c.JSON(200, gin.H{"rep": extinfo})
 	})
 }
@@ -145,7 +147,64 @@ func getCheckInfos() *[]map[string]interface{} {
 	return infos
 }
 
-//前置过滤验证
+//正则前置过滤检查
+func checkPreReg(content, ruleText string) string {
+	tmp := strings.Split(ruleText, "__")
+	if len(tmp) == 2 {
+		reg := regexp.MustCompile(tmp[0])
+		return reg.ReplaceAllString(content, tmp[1])
+	} else {
+		reg := regexp.MustCompile(tmp[0])
+		return reg.ReplaceAllString(content, "")
+	}
+}
+
+//正则后置过滤检查
+func checkBackReg(content, ruleText string) string {
+	tmp := strings.Split(ruleText, "__")
+	if len(tmp) == 2 {
+		reg := regexp.MustCompile(tmp[0])
+		return reg.ReplaceAllString(content, tmp[1])
+	} else {
+		reg := regexp.MustCompile(tmp[0])
+		return reg.ReplaceAllString(content, "")
+	}
+}
+
+//正则抽取检查
+func checkCoreReg(field, content, ruleText string) map[string]string {
+	rep := map[string]string{}
+	tmp := strings.Split(ruleText, "__")
+	if len(tmp) == 2 {
+		epos := strings.Split(tmp[1], ",")
+		posm := map[string]int{}
+		for _, v := range epos {
+			ks := strings.Split(v, ":")
+			if len(ks) == 2 { //(.*)招标公告(.*)__2:projectname,4:area
+				posm[ks[1]] = qu.IntAll(ks[0])
+			} else {
+				posm[field] = qu.IntAll(ks[0])
+			}
+		}
+		reg := regexp.MustCompile(tmp[0])
+		apos := reg.FindAllStringSubmatchIndex(content, -1)
+		if len(apos) > 0 {
+			pos := apos[0]
+			for k, p := range posm {
+				if len(pos) > p {
+					if pos[p] == -1 || pos[p+1] == -1 {
+						continue
+					}
+					val := content[pos[p]:pos[p+1]]
+					rep[k] = val
+				}
+			}
+		}
+	}
+	return rep
+}
+
+//lua脚本前置过滤验证
 func checkPreScript(code, name, infoid, script string) map[string]interface{} {
 	doc, _ := Mgo.FindById("bidding", infoid, extract.Fields)
 	j := extract.PreInfo(*doc)
@@ -156,8 +215,8 @@ func checkPreScript(code, name, infoid, script string) map[string]interface{} {
 	return rep
 }
 
-//通用后置过滤验证
-func checkBackScript(code, name, version, infoid, script string) map[string]interface{} {
+//lua脚本通用后置过滤验证
+func checkBackScript(table, code, name, version, infoid, script string, alone bool) interface{} {
 	defer qu.Catch()
 	vsion, _ := Mgo.FindOne("version", `{"version":"`+version+`"}`)
 	e := &extract.ExtractTask{}
@@ -194,11 +253,23 @@ func checkBackScript(code, name, version, infoid, script string) map[string]inte
 	lua := ju.LuaScript{Code: code, Name: name, Result: result, Script: script}
 	lua.Block = j.Block
 	extinfo := lua.RunScript("back")
-	return extinfo
+	if !alone {
+		return extinfo
+	} else {
+		if table == "rule_back" {
+			return extinfo
+		} else {
+			ru, _ := Mgo.FindOne("rule_logicback", `{"s_code":"`+code+`"}`)
+			pid := (*ru)["pid"].(string)
+			tmp, _ := Mgo.FindById("versioninfo", pid, `{"s_field":1}`)
+			s_field := (*tmp)["s_field"].(string)
+			return extinfo[s_field]
+		}
+	}
 }
 
-//抽取验证
-func checkCoreScript(code, name, infoid, script string) map[string]interface{} {
+//lua脚本抽取验证
+func checkCoreScript(code, name, infoid, script string) interface{} {
 	doc, _ := Mgo.FindById("bidding", infoid, extract.Fields)
 	j := extract.PreInfo(*doc)
 	delete(*j.Data, "contenthtml")
@@ -207,5 +278,3 @@ func checkCoreScript(code, name, infoid, script string) map[string]interface{} {
 	rep := lua.RunScript("core")
 	return rep
 }
-
-//抽取过滤验证

+ 2 - 1
src/jy/extract/extract.go

@@ -107,7 +107,8 @@ func RunExtractTask(ext *ExtractTask) {
 	}
 	query := bson.M{"_id": bson.M{"$gte": bson.ObjectIdHex(ext.TaskInfo.LastExtId)}}
 	list, _ := ext.TaskInfo.DB.Find(ext.TaskInfo.FromColl, query, nil, Fields, false, -1, -1)
-	for _, v := range *list {
+	for k, v := range *list {
+		log.Println(k, v["_id"])
 		if !ext.IsRun {
 			break
 		}

+ 0 - 65
src/jy/extract/extractcheck.go

@@ -1,65 +0,0 @@
-// extractcheck
-package extract
-
-import (
-	qu "qfw/util"
-	"regexp"
-	"strings"
-)
-
-//前置过滤检查
-func PreRulesCheckReg(content, ruleText string) string {
-	tmp := strings.Split(ruleText, "__")
-	if len(tmp) == 2 {
-		reg := regexp.MustCompile(tmp[0])
-		return reg.ReplaceAllString(content, tmp[1])
-	} else {
-		reg := regexp.MustCompile(tmp[0])
-		return reg.ReplaceAllString(content, "")
-	}
-}
-
-//后置过滤检查
-func BackRulesCheckReg(content, ruleText string) string {
-	tmp := strings.Split(ruleText, "__")
-	if len(tmp) == 2 {
-		reg := regexp.MustCompile(tmp[0])
-		return reg.ReplaceAllString(content, tmp[1])
-	} else {
-		reg := regexp.MustCompile(tmp[0])
-		return reg.ReplaceAllString(content, "")
-	}
-}
-
-//抽取检查
-func ExtRulesCheckReg(field, content, ruleText string) map[string]string {
-	rep := map[string]string{}
-	tmp := strings.Split(ruleText, "__")
-	if len(tmp) == 2 {
-		epos := strings.Split(tmp[1], ",")
-		posm := map[string]int{}
-		for _, v := range epos {
-			ks := strings.Split(v, ":")
-			if len(ks) == 2 { //(.*)招标公告(.*)__2:projectname,4:area
-				posm[ks[1]] = qu.IntAll(ks[0])
-			} else {
-				posm[field] = qu.IntAll(ks[0])
-			}
-		}
-		reg := regexp.MustCompile(tmp[0])
-		apos := reg.FindAllStringSubmatchIndex(content, -1)
-		if len(apos) > 0 {
-			pos := apos[0]
-			for k, p := range posm {
-				if len(pos) > p {
-					if pos[p] == -1 || pos[p+1] == -1 {
-						continue
-					}
-					val := content[pos[p]:pos[p+1]]
-					rep[k] = val
-				}
-			}
-		}
-	}
-	return rep
-}