|
@@ -6,11 +6,9 @@ import (
|
|
|
"github.com/garyburd/redigo/redis"
|
|
|
hisRedis "github.com/go-redis/redis"
|
|
|
"gopkg.in/mgo.v2/bson"
|
|
|
- es "gopkg.in/olivere/elastic.v1"
|
|
|
"log"
|
|
|
mu "mfw/util"
|
|
|
"net"
|
|
|
- "qfw/common/src/qfw/util/elastic"
|
|
|
"qfw/util"
|
|
|
"qfw/util/mongodb"
|
|
|
"regexp"
|
|
@@ -27,13 +25,11 @@ var (
|
|
|
HisRedisPool *hisRedis.Client
|
|
|
Addrs = make(map[string]interface{}, 0) //省市县
|
|
|
udpclient mu.UdpClient //udp对象
|
|
|
- ElasticClientIndex, ElasticClientType string
|
|
|
+ Reg_person = regexp.MustCompile("[\u4e00-\u9fa5]+")
|
|
|
Reg_xing = regexp.MustCompile(`\*{1,}`)
|
|
|
- Reg_person = regexp.MustCompile("[\u4E00-\u9FA5\\s]+")
|
|
|
Reg_tel = regexp.MustCompile(`^[0-9\-\s]*$`)
|
|
|
- EsConn *es.Client
|
|
|
Updport int
|
|
|
- CPool chan bool
|
|
|
+ CPoolWinner, CPoolBuery, CPoolAgency chan bool
|
|
|
//his_redis db
|
|
|
redis_winner_db, redis_buyer_db, redis_agency_db int
|
|
|
//异常表正则匹配处理
|
|
@@ -53,7 +49,9 @@ func init() {
|
|
|
if err != nil {
|
|
|
log.Fatalln(err)
|
|
|
}
|
|
|
- CPool = make(chan bool, cpnum)
|
|
|
+ CPoolWinner = make(chan bool, cpnum)
|
|
|
+ CPoolBuery = make(chan bool, cpnum)
|
|
|
+ CPoolAgency = make(chan bool, cpnum)
|
|
|
Fields = []string{"_id", "contact", "partners", "business_scope", "company_address",
|
|
|
"capital", "establish_date", "legal_person", "company_type",
|
|
|
"district", "city", "province", "area_code", "credit_no",
|
|
@@ -68,11 +66,6 @@ func init() {
|
|
|
"address", "district", "city", "province", "area_code", "credit_no", "agency_name",
|
|
|
"history_name", "wechat_accounts", "website", "report_websites"}
|
|
|
|
|
|
- //es.NewClient(es.SetURL(addrs...), es.SetMaxRetries(2), es.SetSniff(false))
|
|
|
- //es init
|
|
|
- elastic.InitElasticSize(Config["elasticsearch"], 50)
|
|
|
- EsConn = elastic.GetEsConn()
|
|
|
- defer elastic.DestoryEsConn(EsConn)
|
|
|
initRdis()
|
|
|
initMongo()
|
|
|
initReg()
|
|
@@ -87,8 +80,8 @@ func main() {
|
|
|
log.Println("Udp服务监听", updport)
|
|
|
log.Println("发送端口port:", Updport)
|
|
|
go TimedTaskWinner() //定时任务
|
|
|
- go TimedTaskBuyer() //定时任务
|
|
|
- go TimedTaskAgency() //定时任务
|
|
|
+ //go TimedTaskBuyer() //定时任务
|
|
|
+ //go TimedTaskAgency() //定时任务
|
|
|
c := make(chan int, 1)
|
|
|
<-c
|
|
|
|
|
@@ -113,13 +106,22 @@ func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
|
|
|
}
|
|
|
//data_info:save//存量 data_info:add //增量
|
|
|
//阻塞
|
|
|
- CPool <- true
|
|
|
+ CPoolWinner <- true
|
|
|
go func(mapinfo *map[string]interface{}) {
|
|
|
- defer func() { <-CPool }()
|
|
|
- go TaskWinner(mapinfo)
|
|
|
- go TaskBuyer(mapinfo)
|
|
|
- go TaskAgency(mapinfo)
|
|
|
+ defer func() { <-CPoolWinner }()
|
|
|
+ TaskWinner(mapinfo)
|
|
|
}(tmp)
|
|
|
+ CPoolBuery <- true
|
|
|
+ go func(mapinfo *map[string]interface{}) {
|
|
|
+ defer func() { <-CPoolBuery }()
|
|
|
+ TaskBuyer(mapinfo)
|
|
|
+ }(tmp)
|
|
|
+ CPoolAgency <- true
|
|
|
+ go func(mapinfo *map[string]interface{}) {
|
|
|
+ defer func() { <-CPoolAgency }()
|
|
|
+ TaskAgency(mapinfo)
|
|
|
+ }(tmp)
|
|
|
+
|
|
|
}
|
|
|
case mu.OP_NOOP: //下个节点回应
|
|
|
log.Println("发送成功", string(data))
|
|
@@ -170,14 +172,12 @@ func initMongo() {
|
|
|
SourceClient.MongodbAddr = Config["mgoinit"]
|
|
|
SourceClient.Size = pool_size
|
|
|
SourceClient.DbName = Config["mgodb_bidding"]
|
|
|
- //mongodbSim.DbName = "qfw"
|
|
|
SourceClient.InitPool()
|
|
|
|
|
|
FClient = new(mongodb.MongodbSim)
|
|
|
FClient.MongodbAddr = Config["mgourl"]
|
|
|
FClient.Size = pool_size
|
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
|
- //mongodbSim.DbName = "qfw"
|
|
|
FClient.InitPool()
|
|
|
FClientmgoConn := FClient.GetMgoConn()
|
|
|
defer FClient.DestoryMongoConn(FClientmgoConn)
|
|
@@ -211,7 +211,15 @@ func initReg() {
|
|
|
if !ok || !ok2 || !ok3 || s_field == "" || s_rule == "" || s_type == "" {
|
|
|
continue
|
|
|
}
|
|
|
- regtmp := regexp.MustCompile(s_rule)
|
|
|
+ var pattern string
|
|
|
+ if strings.Contains(s_rule, "\\u") {
|
|
|
+ s_rule = strings.Replace(s_rule, "\\", "\\\\", -1)
|
|
|
+ s_rule = strings.Replace(s_rule, "\\\\u", "\\u", -1)
|
|
|
+ pattern, _ = strconv.Unquote(`"` + s_rule + `"`)
|
|
|
+ } else {
|
|
|
+ pattern = s_rule
|
|
|
+ }
|
|
|
+ regtmp := regexp.MustCompile(pattern)
|
|
|
if s_field == "winner" {
|
|
|
if s_type == "ok" {
|
|
|
WinnerRegOk = append(WinnerRegOk, *regtmp)
|