|
@@ -6,7 +6,6 @@ import (
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
|
cu "jygit.jydev.jianyu360.cn/data_capture/myself_util/commonutil"
|
|
|
iu "jygit.jydev.jianyu360.cn/data_capture/myself_util/initutil"
|
|
|
- su "jygit.jydev.jianyu360.cn/data_capture/myself_util/spiderutil"
|
|
|
"log"
|
|
|
"net/http"
|
|
|
"time"
|
|
@@ -39,47 +38,33 @@ func main() {
|
|
|
func SubscribeNats() {
|
|
|
//先消费,带压缩
|
|
|
Jnats.SubZip(Subscribe, func(msg *nats.Msg) {
|
|
|
- data := &MsgInfo{}
|
|
|
- err := bson.Unmarshal(msg.Data, &data)
|
|
|
- if err != nil {
|
|
|
- log.Println("解析数据失败:", err)
|
|
|
- data.Err = err.Error()
|
|
|
- //SaveData()//保存异常数据
|
|
|
- } else {
|
|
|
- //处理数据
|
|
|
- data.Stime = time.Now().Unix()
|
|
|
- data.CurrSetp = Subscribe
|
|
|
- DealFile(data.Data)
|
|
|
- data.Etime = time.Now().Unix()
|
|
|
- }
|
|
|
- //消息回写
|
|
|
- bs, _ := bson.Marshal(data)
|
|
|
- err = msg.Respond(bs)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("回执失败:", data.Id)
|
|
|
- //SaveData()//保存异常数据
|
|
|
- }
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-func DealFile(tmp map[string]interface{}) {
|
|
|
- site := cu.ObjToString(tmp["site"]) //解析附件站点
|
|
|
- if limitRatio := OssSite[site]; limitRatio > 0 { //配置站点解析附件,根据准确率情况替换正文
|
|
|
- replace, filetext := AnalysisFile(true, limitRatio, tmp)
|
|
|
- if replace { //替换正文
|
|
|
- tmp["detail"] = filetext
|
|
|
- }
|
|
|
- } else { //其它网站附件信息,detail无效,只有一个附件且不是ocr识别的,替换正文
|
|
|
- //判断detail是否有效
|
|
|
- detail := cu.ObjToString(tmp["detail"])
|
|
|
- detail = su.FilterDetail(detail) //只保留文本内容
|
|
|
- if len([]rune(detail)) <= 5 || (len([]rune(detail)) <= 50 && SpecialTextReg.MatchString(detail)) {
|
|
|
- replace, filetext := AnalysisFile(false, 0, tmp)
|
|
|
- if replace { //替换正文
|
|
|
- tmp["detail"] = filetext
|
|
|
+ NatsThreads <- true
|
|
|
+ go func(msg *nats.Msg) {
|
|
|
+ defer func() {
|
|
|
+ <-NatsThreads
|
|
|
+ }()
|
|
|
+ data := &MsgInfo{}
|
|
|
+ err := bson.Unmarshal(msg.Data, &data)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("解析数据失败:", err)
|
|
|
+ data.Err = err.Error()
|
|
|
+ //SaveData()//保存异常数据
|
|
|
+ } else {
|
|
|
+ //处理数据
|
|
|
+ data.Stime = time.Now().Unix()
|
|
|
+ data.CurrSetp = Subscribe
|
|
|
+ DealFile(data.Data)
|
|
|
+ data.Etime = time.Now().Unix()
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
+ //消息回写
|
|
|
+ bs, _ := bson.Marshal(data)
|
|
|
+ err = msg.Respond(bs)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("回执失败:", data.Id, data.Data["_id"])
|
|
|
+ //SaveData()//保存异常数据
|
|
|
+ }
|
|
|
+ }(msg)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/*func SendMail(bodyTextAll string) {
|