|
@@ -2,6 +2,7 @@
|
|
|
package admin
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"jy/extract"
|
|
|
. "jy/mongodbutil"
|
|
|
ju "jy/util"
|
|
@@ -149,58 +150,74 @@ func getCheckInfos() *[]map[string]interface{} {
|
|
|
|
|
|
//正则前置过滤检查
|
|
|
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, "")
|
|
|
- }
|
|
|
+ tmpstr := ""
|
|
|
+ qu.Try(func() {
|
|
|
+ tmp := strings.Split(ruleText, "__")
|
|
|
+ if len(tmp) == 2 {
|
|
|
+ reg := regexp.MustCompile(tmp[0])
|
|
|
+ tmpstr = reg.ReplaceAllString(content, tmp[1])
|
|
|
+ } else {
|
|
|
+ reg := regexp.MustCompile(tmp[0])
|
|
|
+ tmpstr = reg.ReplaceAllString(content, "")
|
|
|
+ }
|
|
|
+ }, func(err interface{}) {
|
|
|
+ tmpstr = fmt.Sprint(err)
|
|
|
+ })
|
|
|
+ return tmpstr
|
|
|
}
|
|
|
|
|
|
//正则后置过滤检查
|
|
|
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, "")
|
|
|
- }
|
|
|
+ tmpstr := ""
|
|
|
+ qu.Try(func() {
|
|
|
+ tmp := strings.Split(ruleText, "__")
|
|
|
+ if len(tmp) == 2 {
|
|
|
+ reg := regexp.MustCompile(tmp[0])
|
|
|
+ tmpstr = reg.ReplaceAllString(content, tmp[1])
|
|
|
+ } else {
|
|
|
+ reg := regexp.MustCompile(tmp[0])
|
|
|
+ tmpstr = reg.ReplaceAllString(content, "")
|
|
|
+ }
|
|
|
+ }, func(err interface{}) {
|
|
|
+ tmpstr = fmt.Sprint(err)
|
|
|
+ })
|
|
|
+ return tmpstr
|
|
|
}
|
|
|
|
|
|
//正则抽取检查
|
|
|
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])
|
|
|
+ qu.Try(func() {
|
|
|
+ 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
|
|
|
+ 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
|
|
|
}
|
|
|
- val := content[pos[p]:pos[p+1]]
|
|
|
- rep[k] = val
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ }, func(err interface{}) {
|
|
|
+ rep["err"] = fmt.Sprint(err)
|
|
|
+ })
|
|
|
return rep
|
|
|
}
|
|
|
|