|
@@ -5,6 +5,7 @@ import (
|
|
"html/template"
|
|
"html/template"
|
|
. "jy/admin"
|
|
. "jy/admin"
|
|
. "jy/mongodbutil"
|
|
. "jy/mongodbutil"
|
|
|
|
+ ju "jy/util"
|
|
qu "qfw/util"
|
|
qu "qfw/util"
|
|
"regexp"
|
|
"regexp"
|
|
"strings"
|
|
"strings"
|
|
@@ -16,10 +17,20 @@ import (
|
|
|
|
|
|
func init() {
|
|
func init() {
|
|
//列表、编辑
|
|
//列表、编辑
|
|
- Admin.GET("/audit/rulemanager", func(c *gin.Context) {
|
|
|
|
- c.HTML(200, "audit_rulemanager.html", nil)
|
|
|
|
|
|
+ //识别字段
|
|
|
|
+ Admin.GET("/audit/recogfield", func(c *gin.Context) {
|
|
|
|
+ c.HTML(200, "audit_recogfield.html", nil)
|
|
})
|
|
})
|
|
- Admin.POST("/rulemanager/getclass", GetClass) //获取识别字段
|
|
|
|
|
|
+ Admin.POST("/rulemanager/getrecogfield", GetRecogField) //新增识别字段
|
|
|
|
+ Admin.POST("/rulemanager/saverecogfield", SaveRecogField) //保存
|
|
|
|
+ Admin.POST("/rulemanager/delrecogfield", DelRecogField) //删除
|
|
|
|
+ //class
|
|
|
|
+ Admin.GET("/rulemanager/getclasslist", func(c *gin.Context) {
|
|
|
|
+ fname := c.Query("fname")
|
|
|
|
+ fid := c.Query("id")
|
|
|
|
+ c.HTML(200, "audit_classlist.html", gin.H{"fname": fname, "fid": fid})
|
|
|
|
+ })
|
|
|
|
+ Admin.POST("/rulemanager/getclass", GetClass) //获取分类
|
|
Admin.POST("/rulemanager/saveclass", SaveClass) //保存
|
|
Admin.POST("/rulemanager/saveclass", SaveClass) //保存
|
|
Admin.POST("/rulemanager/getauditfield", GetAuditField) //获取要审核的字段
|
|
Admin.POST("/rulemanager/getauditfield", GetAuditField) //获取要审核的字段
|
|
Admin.POST("/rulemanager/delclass", DelClass) //删除
|
|
Admin.POST("/rulemanager/delclass", DelClass) //删除
|
|
@@ -28,6 +39,7 @@ func init() {
|
|
Admin.GET("/rulemanager/getrulelist", func(c *gin.Context) {
|
|
Admin.GET("/rulemanager/getrulelist", func(c *gin.Context) {
|
|
cid := c.Query("id")
|
|
cid := c.Query("id")
|
|
cname := c.Query("cname")
|
|
cname := c.Query("cname")
|
|
|
|
+ fid := c.Query("fid")
|
|
class, _ := Mgo.FindById("rc_class", cid, `{"_id":1,"s_name":1,"s_pid":1}`)
|
|
class, _ := Mgo.FindById("rc_class", cid, `{"_id":1,"s_name":1,"s_pid":1}`)
|
|
//级联查询,往上查
|
|
//级联查询,往上查
|
|
if class != nil && *class != nil {
|
|
if class != nil && *class != nil {
|
|
@@ -52,7 +64,7 @@ func init() {
|
|
}
|
|
}
|
|
data["rule"] = rule
|
|
data["rule"] = rule
|
|
data["class"] = class
|
|
data["class"] = class
|
|
- c.HTML(200, "audit_rulelist.html", gin.H{"cid": cid, "cname": cname, "data": data})
|
|
|
|
|
|
+ c.HTML(200, "audit_rulelist.html", gin.H{"cid": cid, "cname": cname, "data": data, "fid": fid})
|
|
})
|
|
})
|
|
Admin.POST("/rulemanager/getrule", GetRule) //获取规则
|
|
Admin.POST("/rulemanager/getrule", GetRule) //获取规则
|
|
Admin.POST("/rulemanager/saverule", SaveRule) //保存规则
|
|
Admin.POST("/rulemanager/saverule", SaveRule) //保存规则
|
|
@@ -62,8 +74,56 @@ func init() {
|
|
Admin.POST("/rulemanager/runruletest", RunRuleTest) //规则测试
|
|
Admin.POST("/rulemanager/runruletest", RunRuleTest) //规则测试
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+func GetRecogField(c *gin.Context) {
|
|
|
|
+ data, _ := Mgo.Find("rc_field", `{"delete":false}`, `{"i_order":1}`, nil, false, -1, -1)
|
|
|
|
+ for _, d := range *data {
|
|
|
|
+ timeStr := time.Unix(d["l_lasttime"].(int64), 0).Format(Date_Short_Layout)
|
|
|
|
+ d["l_lasttime"] = timeStr
|
|
|
|
+ }
|
|
|
|
+ c.JSON(200, gin.H{"data": data})
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func SaveRecogField(c *gin.Context) {
|
|
|
|
+ data := GetPostForm(c)
|
|
|
|
+ _id, _ := c.GetPostForm("_id")
|
|
|
|
+ session := sessions.Default(c)
|
|
|
|
+ if _id != "" {
|
|
|
|
+ Mgo.UpdateById("rc_field", _id, map[string]interface{}{"$set": data})
|
|
|
|
+ c.JSON(200, gin.H{"rep": true})
|
|
|
|
+ } else {
|
|
|
|
+ //s_class, _ := c.GetPostForm("s_class")
|
|
|
|
+ s_recogfield, _ := c.GetPostForm("s_recogfield")
|
|
|
|
+ d, _ := Mgo.FindOne("rc_field", `{"s_recogfield":"`+s_recogfield+`"}`)
|
|
|
|
+ if len(*d) > 0 {
|
|
|
|
+ c.JSON(200, gin.H{"msg": "已存在!"})
|
|
|
|
+ } else {
|
|
|
|
+ data["l_lasttime"] = time.Now().Unix()
|
|
|
|
+ data["l_date"] = time.Now().Unix()
|
|
|
|
+ data["s_user"] = session.Get("username")
|
|
|
|
+ data["delete"] = false
|
|
|
|
+ Mgo.Save("rc_field", data)
|
|
|
|
+ c.JSON(200, gin.H{"rep": true})
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func DelRecogField(c *gin.Context) {
|
|
|
|
+ //删除识别字段,对应的删除识别字段下的分类和规则
|
|
|
|
+ _id, _ := c.GetPostForm("_id")
|
|
|
|
+ b := Mgo.Update("rc_field", `{"_id":"`+_id+`"}`, map[string]interface{}{
|
|
|
|
+ "$set": map[string]interface{}{"delete": true},
|
|
|
|
+ }, false, false)
|
|
|
|
+ go DelClassAndRule(_id)
|
|
|
|
+ if b {
|
|
|
|
+ c.JSON(200, gin.H{"rep": true})
|
|
|
|
+ } else {
|
|
|
|
+ c.JSON(200, gin.H{"rep": false})
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
func GetClass(c *gin.Context) {
|
|
func GetClass(c *gin.Context) {
|
|
- data, _ := Mgo.Find("rc_class", nil, `{"i_order":1}`, nil, false, -1, -1)
|
|
|
|
|
|
+ s_fid, _ := c.GetPostForm("fid")
|
|
|
|
+ data, _ := Mgo.Find("rc_class", `{"s_fid":"`+s_fid+`","delete":false}`, `{"i_order":1}`, nil, false, -1, -1)
|
|
for _, d := range *data {
|
|
for _, d := range *data {
|
|
timeStr := time.Unix(d["l_lasttime"].(int64), 0).Format(Date_Short_Layout)
|
|
timeStr := time.Unix(d["l_lasttime"].(int64), 0).Format(Date_Short_Layout)
|
|
d["l_lasttime"] = timeStr
|
|
d["l_lasttime"] = timeStr
|
|
@@ -79,15 +139,17 @@ func SaveClass(c *gin.Context) {
|
|
Mgo.UpdateById("rc_class", _id, map[string]interface{}{"$set": data})
|
|
Mgo.UpdateById("rc_class", _id, map[string]interface{}{"$set": data})
|
|
c.JSON(200, gin.H{"rep": true})
|
|
c.JSON(200, gin.H{"rep": true})
|
|
} else {
|
|
} else {
|
|
|
|
+ s_name, _ := c.GetPostForm("s_name")
|
|
s_recogfield, _ := c.GetPostForm("s_recogfield")
|
|
s_recogfield, _ := c.GetPostForm("s_recogfield")
|
|
- d, _ := Mgo.FindOne("rc_class", `{"s_recogfield":"`+s_recogfield+`"}`)
|
|
|
|
- if len(*d) > 0 {
|
|
|
|
- c.JSON(200, gin.H{"msg": "已存在!"})
|
|
|
|
|
|
+ class, _ := Mgo.FindOne("rc_class", `{"s_name":"`+s_name+`","s_recogfield":"`+s_recogfield+`"}`)
|
|
|
|
+ if len(*class) > 0 {
|
|
|
|
+ c.JSON(200, gin.H{"rep": false})
|
|
} else {
|
|
} else {
|
|
data["l_lasttime"] = time.Now().Unix()
|
|
data["l_lasttime"] = time.Now().Unix()
|
|
data["l_date"] = time.Now().Unix()
|
|
data["l_date"] = time.Now().Unix()
|
|
data["s_user"] = session.Get("username")
|
|
data["s_user"] = session.Get("username")
|
|
data["i_order"] = GetOrder("class")
|
|
data["i_order"] = GetOrder("class")
|
|
|
|
+ data["delete"] = false
|
|
Mgo.Save("rc_class", data)
|
|
Mgo.Save("rc_class", data)
|
|
c.JSON(200, gin.H{"rep": true})
|
|
c.JSON(200, gin.H{"rep": true})
|
|
}
|
|
}
|
|
@@ -116,7 +178,10 @@ func GetAuditField(c *gin.Context) {
|
|
|
|
|
|
func DelClass(c *gin.Context) {
|
|
func DelClass(c *gin.Context) {
|
|
_id, _ := c.GetPostForm("_id")
|
|
_id, _ := c.GetPostForm("_id")
|
|
- b := Mgo.Del("rc_class", `{"_id":"`+_id+`"}`)
|
|
|
|
|
|
+ b := Mgo.Update("rc_class", `{"_id":"`+_id+`"}`, map[string]interface{}{
|
|
|
|
+ "$set": map[string]interface{}{"delete": true},
|
|
|
|
+ }, false, false)
|
|
|
|
+ go DelRuleByClass(_id)
|
|
if b {
|
|
if b {
|
|
c.JSON(200, gin.H{"rep": true})
|
|
c.JSON(200, gin.H{"rep": true})
|
|
} else {
|
|
} else {
|
|
@@ -126,6 +191,7 @@ func DelClass(c *gin.Context) {
|
|
|
|
|
|
func GetCList(c *gin.Context) {
|
|
func GetCList(c *gin.Context) {
|
|
nid := c.Query("nid")
|
|
nid := c.Query("nid")
|
|
|
|
+ fname := c.Query("fname")
|
|
query := make(map[string]interface{})
|
|
query := make(map[string]interface{})
|
|
if nid != "" {
|
|
if nid != "" {
|
|
query = map[string]interface{}{
|
|
query = map[string]interface{}{
|
|
@@ -134,7 +200,15 @@ func GetCList(c *gin.Context) {
|
|
},
|
|
},
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if fname != "" {
|
|
|
|
+ query = map[string]interface{}{
|
|
|
|
+ "s_recogfield": map[string]interface{}{
|
|
|
|
+ "$ne": fname,
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+ }
|
|
class, _ := Mgo.Find("rc_class", query, nil, `{"s_name":1}`, false, 0, 200)
|
|
class, _ := Mgo.Find("rc_class", query, nil, `{"s_name":1}`, false, 0, 200)
|
|
|
|
+ fmt.Println("class==========", class)
|
|
c.JSON(200, gin.H{"data": class})
|
|
c.JSON(200, gin.H{"data": class})
|
|
}
|
|
}
|
|
|
|
|
|
@@ -151,7 +225,7 @@ func GetOrder(sel string) int {
|
|
|
|
|
|
func GetRule(c *gin.Context) {
|
|
func GetRule(c *gin.Context) {
|
|
cid, _ := c.GetPostForm("cid")
|
|
cid, _ := c.GetPostForm("cid")
|
|
- data, _ := Mgo.Find("rc_rule", `{"s_classid":"`+cid+`"}`, `{"i_order":1}`, nil, false, -1, -1)
|
|
|
|
|
|
+ data, _ := Mgo.Find("rc_rule", `{"s_classid":"`+cid+`","delete":false}`, `{"i_order":1}`, nil, false, -1, -1)
|
|
for _, d := range *data {
|
|
for _, d := range *data {
|
|
timeStr := time.Unix(d["l_lasttime"].(int64), 0).Format(Date_Short_Layout)
|
|
timeStr := time.Unix(d["l_lasttime"].(int64), 0).Format(Date_Short_Layout)
|
|
d["l_lasttime"] = timeStr
|
|
d["l_lasttime"] = timeStr
|
|
@@ -196,8 +270,8 @@ func SaveRule(c *gin.Context) {
|
|
data["l_lasttime"] = time.Now().Unix()
|
|
data["l_lasttime"] = time.Now().Unix()
|
|
data["l_date"] = time.Now().Unix()
|
|
data["l_date"] = time.Now().Unix()
|
|
data["s_user"] = session.Get("username")
|
|
data["s_user"] = session.Get("username")
|
|
- data["i_status"] = 0
|
|
|
|
data["i_order"] = GetOrder("rule")
|
|
data["i_order"] = GetOrder("rule")
|
|
|
|
+ data["delete"] = false
|
|
Mgo.Save("rc_rule", data)
|
|
Mgo.Save("rc_rule", data)
|
|
c.JSON(200, gin.H{"rep": true})
|
|
c.JSON(200, gin.H{"rep": true})
|
|
}
|
|
}
|
|
@@ -236,7 +310,9 @@ func GetRList(c *gin.Context) {
|
|
|
|
|
|
func DelRule(c *gin.Context) {
|
|
func DelRule(c *gin.Context) {
|
|
_id, _ := c.GetPostForm("_id")
|
|
_id, _ := c.GetPostForm("_id")
|
|
- b := Mgo.Del("rc_rule", `{"_id":"`+_id+`"}`)
|
|
|
|
|
|
+ b := Mgo.Update("rc_rule", `{"_id":"`+_id+`"}`, map[string]interface{}{
|
|
|
|
+ "$set": map[string]interface{}{"delete": true},
|
|
|
|
+ }, false, false)
|
|
if b {
|
|
if b {
|
|
c.JSON(200, gin.H{"rep": true})
|
|
c.JSON(200, gin.H{"rep": true})
|
|
} else {
|
|
} else {
|
|
@@ -282,9 +358,9 @@ func RunRuleTest(c *gin.Context) {
|
|
rule, _ := Mgo.FindById("rc_rule", _id, `{"s_rule":1,"s_rule_prerule":1}`)
|
|
rule, _ := Mgo.FindById("rc_rule", _id, `{"s_rule":1,"s_rule_prerule":1}`)
|
|
s_rule := qu.ObjArrToStringArr((*rule)["s_rule"].([]interface{}))
|
|
s_rule := qu.ObjArrToStringArr((*rule)["s_rule"].([]interface{}))
|
|
fmt.Println(s_con)
|
|
fmt.Println(s_con)
|
|
- s_con = PreFilter(s_con, qu.ObjToString((*rule)["s_rule_prerule"])) //对文本先进行前置过滤
|
|
|
|
|
|
+ s_con = ju.PreFilter(s_con, qu.ObjToString((*rule)["s_rule_prerule"])) //对文本先进行前置过滤
|
|
fmt.Println(s_con)
|
|
fmt.Println(s_con)
|
|
- text, rules, pos, b := ClassificationText(s_con, AnalyRules(s_rule))
|
|
|
|
|
|
+ text, rules, pos, b := ju.ClassificationText(s_con, ju.AnalyRules(s_rule))
|
|
data["b"] = b
|
|
data["b"] = b
|
|
data["pos"] = pos + 1
|
|
data["pos"] = pos + 1
|
|
data["rules"] = func() template.HTML {
|
|
data["rules"] = func() template.HTML {
|
|
@@ -322,3 +398,22 @@ func GetParent(s_pid, coll string, pm *map[string]interface{}) {
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func DelClassAndRule(fid string) {
|
|
|
|
+ class, _ := Mgo.Find("rc_class", `{"s_fid":"`+fid+`"}`, nil, `{"_id":1}`, false, -1, -1)
|
|
|
|
+ for _, c := range *class {
|
|
|
|
+ Mgo.UpdateById("rc_class", c["_id"], map[string]interface{}{ //删除class
|
|
|
|
+ "$set": map[string]interface{}{"delete": true},
|
|
|
|
+ })
|
|
|
|
+ classid := qu.BsonIdToSId(c["_id"])
|
|
|
|
+ Mgo.Update("rc_rule", `{"s_classid":"`+classid+`"}`, map[string]interface{}{ //删除class
|
|
|
|
+ "$set": map[string]interface{}{"delete": true},
|
|
|
|
+ }, false, true)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func DelRuleByClass(classid string) {
|
|
|
|
+ Mgo.Update("rc_rule", `{"s_classid":"`+classid+`"}`, map[string]interface{}{ //删除class
|
|
|
|
+ "$set": map[string]interface{}{"delete": true},
|
|
|
|
+ }, false, true)
|
|
|
|
+}
|