wangshan 9 сар өмнө
parent
commit
7bee07cd75

+ 75 - 3
jy_publishing/go.mod

@@ -1,14 +1,12 @@
 module jy_publishing
 
-go 1.16
+go 1.20
 
 require (
 	github.com/Chain-Zhang/pinyin v0.1.3
 	github.com/aliyun/aliyun-oss-go-sdk v2.2.2+incompatible
-	github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
 	github.com/golang/protobuf v1.5.2
 	github.com/nsqio/go-nsq v1.1.0
-	github.com/satori/go.uuid v1.2.0 // indirect
 	github.com/zeromicro/go-zero v1.3.2
 	go.mongodb.org/mongo-driver v1.10.1
 	go.uber.org/zap v1.24.0
@@ -19,3 +17,77 @@ require (
 	jygit.jydev.jianyu360.cn/BP/servicerd v0.0.0-20230621085048-b7e09df0c982
 	jygit.jydev.jianyu360.cn/data_processing/common_utils v0.0.0-20230621011928-cdaea81cabe1
 )
+
+require (
+	github.com/PuerkitoBio/goquery v1.8.0 // indirect
+	github.com/andybalholm/cascadia v1.3.1 // indirect
+	github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
+	github.com/beorn7/perks v1.0.1 // indirect
+	github.com/cespare/xxhash/v2 v2.1.2 // indirect
+	github.com/coreos/go-semver v0.3.0 // indirect
+	github.com/coreos/go-systemd/v22 v22.3.2 // indirect
+	github.com/davecgh/go-spew v1.1.1 // indirect
+	github.com/dchest/captcha v1.0.0 // indirect
+	github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
+	github.com/go-logr/logr v1.2.2 // indirect
+	github.com/go-logr/stdr v1.2.2 // indirect
+	github.com/go-redis/redis/v8 v8.11.4 // indirect
+	github.com/gogo/protobuf v1.3.2 // indirect
+	github.com/golang/mock v1.6.0 // indirect
+	github.com/golang/snappy v0.0.4 // indirect
+	github.com/google/go-cmp v0.5.7 // indirect
+	github.com/google/gofuzz v1.2.0 // indirect
+	github.com/googleapis/gnostic v0.4.1 // indirect
+	github.com/hashicorp/golang-lru v0.5.4 // indirect
+	github.com/josharian/intern v1.0.0 // indirect
+	github.com/json-iterator/go v1.1.12 // indirect
+	github.com/klauspost/compress v1.13.6 // indirect
+	github.com/mailru/easyjson v0.7.7 // indirect
+	github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
+	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
+	github.com/modern-go/reflect2 v1.0.2 // indirect
+	github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
+	github.com/olivere/elastic/v7 v7.0.32 // indirect
+	github.com/openzipkin/zipkin-go v0.4.0 // indirect
+	github.com/pkg/errors v0.9.1 // indirect
+	github.com/prometheus/client_golang v1.11.0 // indirect
+	github.com/prometheus/client_model v0.2.0 // indirect
+	github.com/prometheus/common v0.30.0 // indirect
+	github.com/prometheus/procfs v0.7.3 // indirect
+	github.com/satori/go.uuid v1.2.0 // indirect
+	github.com/spaolacci/murmur3 v1.1.0 // indirect
+	github.com/xdg-go/pbkdf2 v1.0.0 // indirect
+	github.com/xdg-go/scram v1.1.1 // indirect
+	github.com/xdg-go/stringprep v1.0.3 // indirect
+	github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
+	go.etcd.io/etcd/api/v3 v3.5.2 // indirect
+	go.etcd.io/etcd/client/pkg/v3 v3.5.2 // indirect
+	go.etcd.io/etcd/client/v3 v3.5.2 // indirect
+	go.opentelemetry.io/otel v1.5.0 // indirect
+	go.opentelemetry.io/otel/exporters/jaeger v1.3.0 // indirect
+	go.opentelemetry.io/otel/exporters/zipkin v1.3.0 // indirect
+	go.opentelemetry.io/otel/sdk v1.3.0 // indirect
+	go.opentelemetry.io/otel/trace v1.5.0 // indirect
+	go.uber.org/atomic v1.9.0 // indirect
+	go.uber.org/automaxprocs v1.4.0 // indirect
+	go.uber.org/multierr v1.8.0 // indirect
+	golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
+	golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
+	golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
+	golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
+	golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect
+	golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
+	golang.org/x/text v0.3.7 // indirect
+	golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
+	google.golang.org/appengine v1.6.7 // indirect
+	google.golang.org/genproto v0.0.0-20220228195345-15d65a4533f7 // indirect
+	gopkg.in/inf.v0 v0.9.1 // indirect
+	gopkg.in/yaml.v2 v2.4.0 // indirect
+	k8s.io/api v0.20.12 // indirect
+	k8s.io/apimachinery v0.20.12 // indirect
+	k8s.io/client-go v0.20.12 // indirect
+	k8s.io/klog/v2 v2.40.1 // indirect
+	k8s.io/utils v0.0.0-20201110183641-67b214c5f920 // indirect
+	sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
+	sigs.k8s.io/yaml v1.2.0 // indirect
+)

+ 1 - 4
jy_publishing/go.sum

@@ -417,18 +417,15 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
 github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
 github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
-github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
-github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
 github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
-github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
 github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
 github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
 github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=

+ 38 - 71
jy_publishing/main.go

@@ -3,112 +3,79 @@ package main
 import (
 	"encoding/json"
 	"fmt"
-	"github.com/zeromicro/go-zero/core/discov"
-	"github.com/zeromicro/go-zero/zrpc"
 	"jy_publishing/Logger"
 	ms "jy_publishing/megaloscope"
 	nsq "jy_publishing/nsq"
+	"jy_publishing/tool"
 	util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
 	"jygit.jydev.jianyu360.cn/data_processing/common_utils/elastic"
 	"jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
 	"jygit.jydev.jianyu360.cn/data_processing/common_utils/udp"
 	"log"
 	"net"
-	"strings"
 )
 
 var (
-	Sysconfig         map[string]interface{}
-	MgoBid, MgoExt    *mongodb.MongodbSim
-	BidColl           string
-	ExtColl, ExtColl1 string
-	FileTopicResult   string
-	Es                *elastic.Elastic
-	Index, IndexAll   string
-	Itype             string
-	JyRpcClient       zrpc.Client
-	ClientAddr        string
-	MCJy, MCAtts      *nsq.Consumer
-	MProducer         *nsq.Producer
-	Ms                *ms.Megaloscope //敏感词
-	UdpClient         udp.UdpClient   //udp对象
-	InfoCodes         []infoCode
+	Itype        string
+	MCJy, MCAtts *nsq.Consumer
 )
 
-type infoCode struct {
-	Code        string `json:"code"`        //发布信息代码
-	Name        string `json:"name"`        //发布信息类型名称
-	IsPublic    int    `json:"isPublic"`    //是否公开;默认公开:0;不公开:1
-	ExtractType int    `json:"extractType"` //-1:采购信息
-}
-
 func init() {
 	Logger.InitLogger("./log/All.log", "debug")
-	util.ReadConfig(&Sysconfig)
+	util.ReadConfig(&tool.Sysconfig)
 	//信息类型
-	if Sysconfig["infoCode"] != nil {
-		b, err := json.Marshal(Sysconfig["infoCode"])
+	if tool.Sysconfig["infoCode"] != nil {
+		b, err := json.Marshal(tool.Sysconfig["infoCode"])
 		if err == nil {
-			err = json.Unmarshal(b, &InfoCodes)
+			err = json.Unmarshal(b, &tool.InfoCodes)
 		}
 		if err != nil {
 			log.Println("infoCode init err :", err)
 		}
 	}
-	bidding := Sysconfig["bidding"].(map[string]interface{})
-	BidColl = bidding["dbColl"].(string)
-	MgoBid = &mongodb.MongodbSim{
+	bidding := tool.Sysconfig["bidding"].(map[string]interface{})
+	tool.BidColl = bidding["dbColl"].(string)
+	tool.MgoBid = &mongodb.MongodbSim{
 		MongodbAddr: bidding["addr"].(string),
-		Size:        util.IntAllDef(Sysconfig["mgoPoolSize"], 5),
+		Size:        util.IntAllDef(tool.Sysconfig["mgoPoolSize"], 5),
 		DbName:      bidding["dbName"].(string),
 		UserName:    bidding["uname"].(string),
 		Password:    bidding["upwd"].(string),
 	}
-	MgoBid.InitPool()
-	extract := Sysconfig["extract"].(map[string]interface{})
-	ExtColl = extract["dbColl"].(string)
-	ExtColl1 = extract["dbColl1"].(string)
-	MgoExt = &mongodb.MongodbSim{
+	tool.MgoBid.InitPool()
+	extract := tool.Sysconfig["extract"].(map[string]interface{})
+	tool.ExtColl = extract["dbColl"].(string)
+	tool.ExtColl1 = extract["dbColl1"].(string)
+	tool.MgoExt = &mongodb.MongodbSim{
 		MongodbAddr: extract["addr"].(string),
-		Size:        util.IntAllDef(Sysconfig["mgoPoolSize"], 5),
+		Size:        util.IntAllDef(tool.Sysconfig["mgoPoolSize"], 5),
 		DbName:      extract["dbName"].(string),
 	}
-	MgoExt.InitPool()
-	es := Sysconfig["es"].(map[string]interface{})
-	Es = &elastic.Elastic{
+	tool.MgoExt.InitPool()
+	es := tool.Sysconfig["es"].(map[string]interface{})
+	tool.Es = &elastic.Elastic{
 		S_esurl:  util.ObjToString(es["addr"]),
 		I_size:   util.IntAllDef(es["pool"], 10),
 		Username: util.ObjToString(es["user"]),
 		Password: util.ObjToString(es["password"]),
 	}
-	Index = util.ObjToString(es["index"])
-	IndexAll = util.ObjToString(es["index_all"])
+	tool.Index = util.ObjToString(es["index"])
+	tool.IndexAll = util.ObjToString(es["index_all"])
 	Itype = util.ObjToString(es["itype"])
-	Es.InitElasticSize()
+	tool.Es.InitElasticSize()
 
 	//加载敏感词文件
-	Ms = ms.NewMegaloscope("./rules.txt")
-	InitOss()
-	initEtcd()
+	tool.Ms = ms.NewMegaloscope("./rules.txt")
+	tool.InitOss()
+	tool.InitEtcd()
 	initUdp()
 }
 
-func initEtcd() {
-	jyRpc := Sysconfig["jy_rpc"].(map[string]interface{})
-	Logger.Debug("etcd 注册rpc服务, " + util.ObjToString(jyRpc["key"]))
-	JyRpcClient = zrpc.MustNewClient(zrpc.RpcClientConf{
-		Etcd: discov.EtcdConf{
-			Hosts: strings.Split(util.ObjToString(jyRpc["addr"]), ","),
-			Key:   util.ObjToString(jyRpc["key"]),
-		},
-	})
-}
-
 func initUdp() {
-	updport := Sysconfig["udpPort"].(string)
-	UdpClient = udp.UdpClient{Local: updport, BufSize: 1024}
+	updport := tool.Sysconfig["udpPort"].(string)
+	tool.UdpClient = udp.UdpClient{Local: updport, BufSize: 1024}
 	Logger.Info("Udp 监听 port: " + updport)
-	UdpClient.Listen(processUdpMsg)
+	tool.UdpClient.Listen(processUdpMsg)
 }
 
 func main() {
@@ -122,7 +89,7 @@ func main() {
 // @Description 剑鱼消息队列 按照类型处理消息
 // @Author J 2022/4/14 11:42 AM
 func jyNsqMethod() {
-	cof := Sysconfig["nsq_jy"].(map[string]interface{})
+	cof := tool.Sysconfig["nsq_jy"].(map[string]interface{})
 	var err error
 	MCJy, err = nsq.NewConsumer(&nsq.Cconfig{
 		IsJsonEncode: true, //与生产者配置对应,设为true会取第1个字节进行类型判断
@@ -139,7 +106,7 @@ func jyNsqMethod() {
 		select {
 		case obj := <-MCJy.Ch: //从通道读取即可
 			Logger.Info("jy nsq: " + fmt.Sprint(obj))
-			taskInfo(obj)
+			tool.TaskInfo(obj)
 		}
 	}
 }
@@ -148,17 +115,17 @@ func jyNsqMethod() {
 // @Author J 2022/4/14 1:18 PM
 func attsNsqMethod() {
 	var err error
-	cofAtts := Sysconfig["nsq_attachment"].(map[string]interface{})
-	MProducer, err = nsq.NewProducer(util.ObjToString(cofAtts["addr_p"]), util.ObjToString(cofAtts["topic"]), true)
+	cofAtts := tool.Sysconfig["nsq_attachment"].(map[string]interface{})
+	tool.MProducer, err = nsq.NewProducer(util.ObjToString(cofAtts["addr_p"]), util.ObjToString(cofAtts["topic"]), true)
 	if err != nil {
 		Logger.Error(err.Error())
 	}
-	FileTopicResult = util.ObjToString(cofAtts["topic-result"])
+	tool.FileTopicResult = util.ObjToString(cofAtts["topic-result"])
 	MCAtts, err = nsq.NewConsumer(&nsq.Cconfig{
 		IsJsonEncode: true,
 		Addr:         util.ObjToString(cofAtts["addr_c"]),
 		ConnectType:  1, //默认连接nsqd
-		Topic:        FileTopicResult,
+		Topic:        tool.FileTopicResult,
 		Channel:      util.ObjToString(cofAtts["channel"]),
 		Concurrent:   util.IntAllDef(cofAtts["concurrent"], 1), //并发数
 	})
@@ -170,7 +137,7 @@ func attsNsqMethod() {
 		select {
 		case obj := <-MCAtts.Ch:
 			Logger.Info("file extract receive nsq: " + fmt.Sprint(obj))
-			taskAtts(obj.(map[string]interface{}))
+			tool.TaskAtts(obj.(map[string]interface{}))
 		}
 	}
 }
@@ -188,12 +155,12 @@ func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
 			if key == "" {
 				key = "udpok"
 			}
-			go UdpClient.WriteUdp([]byte(key), udp.OP_NOOP, ra)
+			go tool.UdpClient.WriteUdp([]byte(key), udp.OP_NOOP, ra)
 			tasktype, _ := resp["stype"].(string)
 			switch tasktype {
 			case "jyfb_data_over":
 				go func() {
-					JyRpcDataFin(resp["infoid"].(string))
+					tool.JyRpcDataFin(resp["infoid"].(string))
 				}()
 			}
 		}

+ 2 - 1
jy_publishing/service.go

@@ -3,6 +3,7 @@ package main
 import (
 	"fmt"
 	"jy_publishing/Logger"
+	"jy_publishing/tool"
 )
 
 type DataService struct {
@@ -35,6 +36,6 @@ func (d *DataService) DeleteData(req Request, res *Response) error {
 		return fmt.Errorf(" Id error...")
 	}
 	var err error
-	DelMethod(req.Id)
+	tool.DelMethod(req.Id)
 	return err
 }

+ 20 - 0
jy_publishing/tool/etcd.go

@@ -0,0 +1,20 @@
+package tool
+
+import (
+	"github.com/zeromicro/go-zero/core/discov"
+	"github.com/zeromicro/go-zero/zrpc"
+	"jy_publishing/Logger"
+	util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
+	"strings"
+)
+
+func InitEtcd() {
+	jyRpc := Sysconfig["jy_rpc"].(map[string]interface{})
+	Logger.Debug("etcd 注册rpc服务, " + util.ObjToString(jyRpc["key"]))
+	JyRpcClient = zrpc.MustNewClient(zrpc.RpcClientConf{
+		Etcd: discov.EtcdConf{
+			Hosts: strings.Split(util.ObjToString(jyRpc["addr"]), ","),
+			Key:   util.ObjToString(jyRpc["key"]),
+		},
+	})
+}

+ 1 - 1
jy_publishing/ossclient.go → jy_publishing/tool/ossclient.go

@@ -1,5 +1,5 @@
 // ossclient
-package main
+package tool
 
 import (
 	"fmt"

+ 5 - 5
jy_publishing/task.go → jy_publishing/tool/task.go

@@ -1,4 +1,4 @@
-package main
+package tool
 
 import (
 	"context"
@@ -61,7 +61,7 @@ var InfoType = map[int]string{
 // @Description 信息处理(信息发布和附件识别)
 // 1、敏感词处理,2、信息发布,3、信息删除
 // @Author J 2022/4/9 11:47 AM
-func taskInfo(obj interface{}) {
+func TaskInfo(obj interface{}) {
 	info, _ := obj.(map[string]interface{})
 	if util.ObjToString(info["action"]) == "1" {
 		// 敏感词处理
@@ -336,7 +336,7 @@ type AttsResult struct {
 
 // @Description 附件处理完成队列
 // @Author J 2022/4/13 3:29 PM
-func taskAtts(obj map[string]interface{}) {
+func TaskAtts(obj map[string]interface{}) {
 	atts := make(map[string]interface{})
 	atts_text := make(map[string]interface{})
 	for i, r := range obj["result"].([]interface{}) {
@@ -381,7 +381,7 @@ func JyRpcSensitive(req *jypb.SensitiveRequest) {
 	resp, err := jyIntf.SensitiveMethod(context.Background(), req)
 	if err != nil {
 		Logger.Error(err.Error())
-		initEtcd()
+		InitEtcd()
 		resp, err = jyIntf.SensitiveMethod(context.Background(), req)
 		if err != nil {
 			Logger.Error(err.Error())
@@ -439,7 +439,7 @@ func JyRpcDataFin(_id string) {
 	resp, err := jyIntf.StateMethod(context.Background(), req)
 	if err != nil {
 		Logger.Error(err.Error())
-		initEtcd()
+		InitEtcd()
 		resp, err = jyIntf.StateMethod(context.Background(), req)
 		if err != nil {
 			Logger.Error(err.Error())

+ 33 - 0
jy_publishing/tool/tool.go

@@ -0,0 +1,33 @@
+package tool
+
+import (
+	"github.com/zeromicro/go-zero/zrpc"
+	ms "jy_publishing/megaloscope"
+	nsq "jy_publishing/nsq"
+	"jygit.jydev.jianyu360.cn/data_processing/common_utils/elastic"
+	"jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
+	"jygit.jydev.jianyu360.cn/data_processing/common_utils/udp"
+)
+
+var (
+	Sysconfig         map[string]interface{}
+	ExtColl, ExtColl1 string
+	FileTopicResult   string
+	MProducer         *nsq.Producer
+	Ms                *ms.Megaloscope //敏感词
+	ClientAddr        string
+	InfoCodes         []infoCode
+	MgoBid, MgoExt    *mongodb.MongodbSim
+	Es                *elastic.Elastic
+	BidColl           string
+	JyRpcClient       zrpc.Client
+	Index, IndexAll   string
+	UdpClient         udp.UdpClient //udp对象
+)
+
+type infoCode struct {
+	Code        string `json:"code"`        //发布信息代码
+	Name        string `json:"name"`        //发布信息类型名称
+	IsPublic    int    `json:"isPublic"`    //是否公开;默认公开:0;不公开:1
+	ExtractType int    `json:"extractType"` //-1:采购信息
+}