init.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. package main
  2. import (
  3. "fmt"
  4. "go.mongodb.org/mongo-driver/bson/primitive"
  5. "log"
  6. "math"
  7. mu "mfw/util"
  8. "mongodb"
  9. "qfw/util"
  10. "qfw/util/redis"
  11. "reflect"
  12. "regexp"
  13. "sort"
  14. "strings"
  15. "sync"
  16. )
  17. var (
  18. Sysconfig map[string]interface{} //读取配置文件
  19. MongoTool, MgoBidding, MgoSpider *mongodb.MongodbSim //mongodb连接
  20. ExtractColl, ProjectColl, BackupColl, SiteColl string //抽取表、项目表、项目快照表、站点表
  21. ExtractColl1 string
  22. Thread int //配置项线程数
  23. BlackList []interface{}
  24. BlaskListMap map[string]bool
  25. RedisCode string
  26. )
  27. var (
  28. //判断是日期
  29. _datereg = regexp.MustCompile("20[0-2][0-9][年-][0-9]{1,2}[月-][0-9]{1,2}[日-]([0-9]{1,2}时[0-9]{0,2})?")
  30. _numreg1 = regexp.MustCompile("^[0-9-]{1,8}$")
  31. _zimureg1 = regexp.MustCompile("^[a-zA-Z-]{1,7}$")
  32. _nzreg = regexp.MustCompile("^[0-9a-zA-Z-]+$")
  33. _hanreg = regexp.MustCompile(`^[\p{Han}::【】\\[\\]()()--、]+$`)
  34. replaceStr = regexp.MustCompile("(工程|采购|项目|[?!、【】()—()--]|栏标价|中标候选人|招标代理)")
  35. //判断带有分包、等特定词的
  36. pStr = regexp.MustCompile("(勘察|监理|施工|设计|验收|标段|分包|子包|[0-9A-Z]包|[一二三四五六七八九十0-9]批)")
  37. //判断包含数值
  38. nreg1 = regexp.MustCompile("[0-9]{2,}")
  39. //判断包含字母
  40. zreg1 = regexp.MustCompile("[a-zA-Z]{1,}")
  41. //判断包含汉字
  42. hreg1 = regexp.MustCompile(`[\p{Han}]+`)
  43. //判断项目编号是在10以内的纯数字结构
  44. numCheckPc = regexp.MustCompile("^[0-9-]{1,10}$")
  45. //仅初始化使用
  46. compareNoPass = map[string]bool{}
  47. compareAB = map[string]bool{}
  48. compareAB2D = map[string]bool{}
  49. compareABD = map[string]bool{}
  50. compareAB2CD = map[string]bool{}
  51. compareABCD = map[string]bool{}
  52. )
  53. func init() {
  54. util.ReadConfig(&Sysconfig)
  55. MongoTool = &mongodb.MongodbSim{
  56. MongodbAddr: Sysconfig["mongodbServers"].(string),
  57. Size: util.IntAll(Sysconfig["mongodbPoolSize"]),
  58. DbName: Sysconfig["mongodbName"].(string),
  59. }
  60. MongoTool.InitPool()
  61. bidding, _ := Sysconfig["bidding"].(map[string]interface{})
  62. MgoBidding = &mongodb.MongodbSim{
  63. MongodbAddr: bidding["addr"].(string),
  64. Size: util.IntAll(bidding["dbsize"]),
  65. DbName: bidding["dbname"].(string),
  66. UserName: bidding["uname"].(string),
  67. Password: bidding["upwd"].(string),
  68. }
  69. MgoBidding.InitPool()
  70. spider, _ := Sysconfig["spider"].(map[string]interface{})
  71. MgoSpider = &mongodb.MongodbSim{
  72. MongodbAddr: spider["addr"].(string),
  73. Size: util.IntAll(spider["dbsize"]),
  74. DbName: spider["dbname"].(string),
  75. }
  76. MgoSpider.InitPool()
  77. ExtractColl = Sysconfig["extractColl"].(string)
  78. ExtractColl1 = Sysconfig["extractColl1"].(string)
  79. ProjectColl = Sysconfig["projectColl"].(string)
  80. BackupColl = Sysconfig["projectColl"].(string) + "_back"
  81. SiteColl = Sysconfig["siteColl"].(string)
  82. Thread = util.IntAll(Sysconfig["thread"])
  83. //NextNode = Sysconfig["nextNode"].([]interface{})
  84. udpport, _ := Sysconfig["udpport"].(string)
  85. udpclient = mu.UdpClient{Local: udpport, BufSize: 1024}
  86. udpclient.Listen(processUdpMsg)
  87. log.Println("Udp服务监听", udpport)
  88. BlackList = Sysconfig["rp_blacklist"].([]interface{})
  89. BlaskListMap = make(map[string]bool)
  90. for _, v := range BlackList {
  91. BlaskListMap[util.ObjToString(v)] = true
  92. }
  93. redisC := Sysconfig["redis-addr"].(string)
  94. redisCon := Sysconfig["redis"].(map[string]interface{})
  95. RedisCode = util.ObjToString(redisCon["dbname"])
  96. redis_addr := util.ObjToString(redisCon["addr"])
  97. redis_db := util.IntAll(redisCon["db"])
  98. //"qyxy_buyer=172.17.4.189:8379"
  99. redis.InitRedis1(fmt.Sprintf("%s=%s", RedisCode, redis_addr), redis_db) // 采购单位与中标单位初次合作项目
  100. redis.InitRedis1(redisC, 0)
  101. initWinnerRegexp()
  102. initBuyerRegexp()
  103. initAgencyRegexp()
  104. //加载项目数据
  105. //---不能通过
  106. vm := []string{"C", "D"}
  107. for i := 0; i < 2; i++ {
  108. for j := 0; j < 2; j++ {
  109. for k := 0; k < 2; k++ {
  110. key := vm[i] + vm[j] + vm[k]
  111. compareNoPass[key] = true
  112. //fmt.Println(key)
  113. }
  114. }
  115. }
  116. //fmt.Println("-------------------")
  117. //三个元素一致 [AB][AB][AB],分值最高
  118. vm = []string{"A", "B"}
  119. for i := 0; i < 2; i++ {
  120. for j := 0; j < 2; j++ {
  121. for k := 0; k < 2; k++ {
  122. key := vm[i] + vm[j] + vm[k]
  123. compareAB[key] = true
  124. //fmt.Println(key)
  125. }
  126. }
  127. }
  128. //fmt.Println("-------------------", len(compareAB))
  129. //---至少两个一致,其他可能不存在
  130. //[AB][AB][ABD]
  131. //[AB][ABD][AB]
  132. vm = []string{"A", "B"}
  133. vm2 := []string{"A", "B", "D"}
  134. for i := 0; i < 2; i++ {
  135. for j := 0; j < 2; j++ {
  136. for k := 0; k < 3; k++ {
  137. key := vm[i] + vm[j] + vm2[k]
  138. if !compareAB[key] {
  139. compareAB2D[key] = true
  140. //fmt.Println(key)
  141. }
  142. }
  143. }
  144. }
  145. for i := 0; i < 2; i++ {
  146. for j := 0; j < 3; j++ {
  147. for k := 0; k < 2; k++ {
  148. key := vm[i] + vm2[j] + vm[k]
  149. if !compareAB[key] {
  150. compareAB2D[key] = true
  151. //fmt.Println(key)
  152. }
  153. }
  154. }
  155. }
  156. //fmt.Println("-------------------", len(compareAB2D))
  157. //---至少一个一致,其他可能不存在
  158. //[ABD][ABD][ABD] //已经删除DDD
  159. vm = []string{"A", "B", "D"}
  160. for i := 0; i < 3; i++ {
  161. for j := 0; j < 3; j++ {
  162. for k := 0; k < 3; k++ {
  163. key := vm[i] + vm[j] + vm[k]
  164. if !compareAB[key] && !compareAB2D[key] && !compareNoPass[key] {
  165. compareABD[key] = true
  166. //fmt.Println(key)
  167. }
  168. }
  169. }
  170. }
  171. //fmt.Println("-------------------", len(compareABD))
  172. //[AB][ABCD][AB]
  173. //[AB][AB][ABCD]
  174. vm = []string{"A", "B"}
  175. vm2 = []string{"A", "B", "C", "D"}
  176. for i := 0; i < 2; i++ {
  177. for j := 0; j < 4; j++ {
  178. for k := 0; k < 2; k++ {
  179. key := vm[i] + vm2[j] + vm[k]
  180. if !compareAB[key] && !compareAB2D[key] && !compareNoPass[key] && !compareABD[key] {
  181. compareAB2CD[key] = true
  182. //fmt.Println(key)
  183. }
  184. }
  185. }
  186. }
  187. for i := 0; i < 2; i++ {
  188. for j := 0; j < 2; j++ {
  189. for k := 0; k < 4; k++ {
  190. key := vm[i] + vm[j] + vm2[k]
  191. if !compareAB[key] && !compareAB2D[key] && !compareNoPass[key] && !compareABD[key] {
  192. compareAB2CD[key] = true
  193. //fmt.Println(key)
  194. }
  195. }
  196. }
  197. }
  198. //fmt.Println("-------------------", len(compareAB2CD))
  199. //[ABECD][ABECD][ABECD] //已经删除[CD][CD][CD] //这个要重点讨论
  200. vm = []string{"A", "B", "C", "D"}
  201. for i := 0; i < 4; i++ {
  202. for j := 0; j < 4; j++ {
  203. for k := 0; k < 4; k++ {
  204. key := vm[i] + vm[j] + vm[k]
  205. if !compareAB[key] && !compareAB2D[key] && !compareABD[key] && !compareNoPass[key] && !compareAB2CD[key] {
  206. compareABCD[key] = true
  207. //fmt.Println(key)
  208. }
  209. }
  210. }
  211. }
  212. }
  213. func CheckHanAndNum(str string) (b bool) {
  214. return nreg1.MatchString(str) && hreg1.MatchString(str)
  215. }
  216. func CheckZimuAndNum(str string) (b bool) {
  217. return zreg1.MatchString(str) && nreg1.MatchString(str)
  218. }
  219. type KeyMap struct {
  220. Lock sync.Mutex
  221. Map map[string]*Key
  222. }
  223. type ID struct {
  224. Id string
  225. Lock sync.Mutex
  226. P *ProjectCache
  227. }
  228. type Key struct {
  229. Arr []string
  230. Lock sync.Mutex
  231. }
  232. type IdAndLock struct {
  233. Id string
  234. Lock sync.Mutex
  235. }
  236. func NewKeyMap() *KeyMap {
  237. return &KeyMap{
  238. Map: map[string]*Key{},
  239. Lock: sync.Mutex{},
  240. }
  241. }
  242. //招标信息实体类
  243. type Info struct {
  244. Id string `json:"_id"`
  245. Href string `json:"href"` //源地址
  246. Publishtime int64 `json:"publishtime"`
  247. Comeintime int64 `json:"comeintime"`
  248. Title string `json:"title"`
  249. TopType string `json:"toptype"`
  250. SubType string `json:"subtype"`
  251. ProjectName string `json:"projectname"`
  252. ProjectCode string `json:"projectcode"`
  253. ProjectScope string `json:"projectscope"`
  254. ContractCode string `json:"contractcode"`
  255. Buyer string `json:"buyer"`
  256. Buyerperson string `json:"buyerperson"`
  257. Buyertel string `json:"buyertel"`
  258. Agency string `json:"agency"`
  259. Area string `json:"area"`
  260. City string `json:"city"`
  261. District string `json:"district"`
  262. Infoformat int `json:"infoformat"`
  263. ReviewExperts []string `json:"review_experts"`
  264. Purchasing string `json:"purchasing"`
  265. WinnerOrder []map[string]interface{} `json:"winnerorder"`
  266. ProjectScale string `json:"project_scale"`
  267. ProjectDuration int `json:"project_duration"`
  268. ProjectTimeUnit string `json:"project_timeunit"`
  269. ProjectStartDate int64 `json:"project_startdate"`
  270. ProjectCompleteDate int64 `json:"project_completedate"`
  271. Payway string `json:"payway"`
  272. ContractGuarantee bool `json:"contract_guarantee"`
  273. BidGuarantee bool `json:"bid_guarantee"`
  274. Qualifies []map[string]interface{} `json:"qualifies"`
  275. EntIdList []string `json:"entidlist"`
  276. HasPackage bool // `json:"haspackage"`
  277. Package map[string]interface{} `json:"package"`
  278. Topscopeclass []string `json:"topscopeclass"`
  279. Subscopeclass []string `json:"subscopeclass"`
  280. Buyerclass string `json:"buyerclass"`
  281. Bidopentime int64 `json:"bidopentime"`
  282. Budget float64 `json:"budget"`
  283. Bidamount float64 `json:"bidamount"`
  284. Winners []string
  285. dealtype int
  286. PTC string //从标题中抽的项目编号
  287. pnbval int //项目名称、编号、采购单位存在的个数
  288. LenPC int //项目编号长度
  289. LenPN int //项目名称长度
  290. LenPTC int //标题抽的项目编号长度
  291. //以下三个元素做对比,计算包含时候使用
  292. PNBH int //0初始,+包含,-被包含
  293. PCBH int
  294. PTCBH int
  295. }
  296. // 内存 项目信息
  297. type ProjectCache struct {
  298. Id primitive.ObjectID `json:"_id"`
  299. Ids []string `json:"ids,omitempty"`
  300. FirstTime int64 `json:"firsttime,omitempty"` //项目的最早时间
  301. LastTime int64 `json:"lasttime,omitempty"` //项目的最后时间
  302. ProjectName string `json:"projectname,omitempty"` //项目名称
  303. ProjectCode string `json:"projectcode,omitempty"` //项目代码唯一(纯数字的权重低)
  304. Buyer string `json:"buyer,omitempty"` //采购单位唯一
  305. Agency string `json:"agency"` //代理机构
  306. Area string `json:"area"` //地区
  307. City string `json:"city"` //地市
  308. District string `json:"district"` //区县
  309. Bidamount float64 `json:"bidamount,omitempty"` //中标金额
  310. Budget float64 `json:"budget,omitempty"` //预算
  311. Bidstatus string `json:"bidstatus"` //
  312. Bidtype string `json:"bidtype"` //
  313. score int
  314. comStr string
  315. MPN []string `json:"mpn,omitempty"` //合并后多余的项目名称
  316. MPC []string `json:"mpc,omitempty"` //合并后多余的项目编号
  317. resVal, pjVal int
  318. }
  319. // 项目信息
  320. type Project struct {
  321. Id primitive.ObjectID `json:"_id"`
  322. Ids []string `json:"ids,omitempty"`
  323. FirstTime int64 `json:"firsttime,omitempty"` //项目的最早时间
  324. LastTime int64 `json:"lasttime,omitempty"` //项目的最后时间
  325. ProjectName string `json:"projectname,omitempty"` //项目名称
  326. ProjectCode string `json:"projectcode,omitempty"` //项目代码唯一(纯数字的权重低)
  327. Buyer string `json:"buyer,omitempty"` //采购单位唯一
  328. Agency string `json:"agency"` //代理机构
  329. Area string `json:"area"` //地区
  330. City string `json:"city"` //地市
  331. District string `json:"district"` //区县
  332. Bidamount float64 `json:"bidamount,omitempty"` //中标金额
  333. Budget float64 `json:"budget,omitempty"` //预算
  334. score int
  335. comStr string
  336. MPN []string `json:"mpn,omitempty"` //合并后多余的项目名称
  337. MPC []string `json:"mpc,omitempty"` //合并后多余的项目编号
  338. resVal, pjVal int
  339. Topscopeclass []string `json:"topscopeclass,omitempty"`
  340. Subscopeclass []string `json:"subscopeclass,omitempty"` //子行业分类
  341. Winners string `json:"s_winner,omitempty"` //中标人
  342. ContractCode string `json:"contractcode,omitempty"` //合同编号
  343. Buyerperson string `json:"buyerperson"` //采购联系人
  344. Buyertel string `json:"buyertel"` //采购联系人电话
  345. Bidstatus string `json:"bidstatus"` //
  346. Bidtype string `json:"bidtype"` //
  347. ReviewExperts []string `json:"review_experts"` // 项目评审专家
  348. Purchasing string `json:"purchasing"` // 标的物
  349. Package map[string]interface{} `json:"package,omitempty"` //分包的对比对象
  350. Buyerclass string `json:"buyerclass"` //采购单位分类
  351. Bidopentime int64 `json:"bidopentime,omitempty"` //开标时间
  352. Jgtime int64 `json:"jgtime"` //结果中标时间
  353. Zbtime int64 `json:"zbtime"` //招标时间
  354. Winnerorder []string `json:"winnerorder"` //中标候选人
  355. ProjectScale string `json:"project_scale"` //项目规模
  356. ProjectDuration int `json:"project_duration"` //工期时长
  357. ProjectTimeunit string `json:"project_timeunit"` //工期时长单位
  358. ProjectStartDate int64 `json:"project_startdate"` //开工日期
  359. ProjctCompleteDate int64 `json:"projct_completedate"` //竣工日期
  360. Payway string `json:"payway"` //付款方式
  361. ContractGuarantee bool `json:"contract_guarantee"` //履约保证金 是否支持包含
  362. BidGuarantee bool `json:"bid_guarantee"` //投标保证金 是否支持包含
  363. Qualifies string `json:"qualifies"` //资质条件
  364. EntIdList []string `json:"entidlist"` //企业id
  365. //FirstCooperation []string `json:"first_cooperation"` //first_cooperation
  366. InfoFiled map[string]InfoField `json:"infofield"` //逻辑处理需要的info字段
  367. Budgettag int `json:"budgettag"` //预算是否有效标记
  368. Bidamounttag int `json:"bidamounttag"` //中标金额是否有效标记
  369. }
  370. //存储部分招标信息字段,业务逻辑处理需要
  371. type InfoField struct {
  372. Budget float64 `json:"budget"`
  373. Bidamount float64 `json:"bidamount"`
  374. ContractCode string `json:"contractcode"`
  375. ProjectName string `json:"projectname"`
  376. ProjectCode string `json:"projectcode"`
  377. Bidstatus string `json:"bidstatus"`
  378. }
  379. //站点信息
  380. type Site struct {
  381. Id string `json:"_id"`
  382. Site string `json:"site"` //站点名字
  383. Area string `json:"area"` //省
  384. City string `json:"city"` //市
  385. District string `json:"district"` //区、县
  386. Domain string `json:"domain"` //地址
  387. Status int `json:"status"` //
  388. }
  389. //二分字符串查找
  390. func BinarySearch(s []string, k string) int {
  391. sort.Strings(s)
  392. lo, hi := 0, len(s)-1
  393. for lo <= hi {
  394. m := (lo + hi) >> 1
  395. if s[m] < k {
  396. lo = m + 1
  397. } else if s[m] > k {
  398. hi = m - 1
  399. } else {
  400. return m
  401. }
  402. }
  403. return -1
  404. }
  405. func Duplicate(a interface{}) (ret []interface{}) {
  406. va := reflect.ValueOf(a)
  407. for i := 0; i < va.Len(); i++ {
  408. if i > 0 && reflect.DeepEqual(va.Index(i-1).Interface(), va.Index(i).Interface()) {
  409. continue
  410. }
  411. ret = append(ret, va.Index(i).Interface())
  412. }
  413. return ret
  414. }
  415. //计算文本相似度
  416. func CosineSimilar(srcWords1, dstWords1 string) float64 {
  417. srcWords, dstWords := strings.Split(srcWords1, ""), strings.Split(dstWords1, "")
  418. // get all words
  419. allWordsMap := make(map[string]int, 0)
  420. for _, word := range srcWords {
  421. if _, found := allWordsMap[word]; !found {
  422. allWordsMap[word] = 1
  423. } else {
  424. allWordsMap[word] += 1
  425. }
  426. }
  427. for _, word := range dstWords {
  428. if _, found := allWordsMap[word]; !found {
  429. allWordsMap[word] = 1
  430. } else {
  431. allWordsMap[word] += 1
  432. }
  433. }
  434. // stable the sort
  435. allWordsSlice := make([]string, 0)
  436. for word, _ := range allWordsMap {
  437. allWordsSlice = append(allWordsSlice, word)
  438. }
  439. // assemble vector
  440. srcVector := make([]int, len(allWordsSlice))
  441. dstVector := make([]int, len(allWordsSlice))
  442. for _, word := range srcWords {
  443. if index := BinarySearch(allWordsSlice, word); index != -1 {
  444. srcVector[index] += 1
  445. }
  446. }
  447. for _, word := range dstWords {
  448. if index := BinarySearch(allWordsSlice, word); index != -1 {
  449. dstVector[index] += 1
  450. }
  451. }
  452. // calc cos
  453. numerator := float64(0)
  454. srcSq := 0
  455. dstSq := 0
  456. for i, srcCount := range srcVector {
  457. dstCount := dstVector[i]
  458. numerator += float64(srcCount * dstCount)
  459. srcSq += srcCount * srcCount
  460. dstSq += dstCount * dstCount
  461. }
  462. denominator := math.Sqrt(float64(srcSq * dstSq))
  463. v1 := numerator / denominator
  464. // if v1 > 0.6 {
  465. // log.Println(v1, srcWords1, dstWords1)
  466. // }
  467. return v1
  468. }
  469. func initWinnerRegexp() {
  470. winRegMap := Sysconfig["winner"].(map[string]interface{})
  471. //preRegexps := winRegMap["pre_regexp"].([]interface{})
  472. //backRegexps := winRegMap["back_regexp"].([]interface{})
  473. //backRepRegexps := winRegMap["back_rep_regexp"].([]interface{})
  474. backBlack := winRegMap["blacklist"].([]interface{})
  475. //var winPreRegexps []*regexp.Regexp
  476. //for _, v := range preRegexps {
  477. // reg := regexp.MustCompile("^" + v.(string))
  478. // winPreRegexps = append(winPreRegexps, reg)
  479. //}
  480. //PreRegexp["winner"] = winPreRegexps
  481. //var winBackRegexps []*regexp.Regexp
  482. //for _, v := range backRegexps {
  483. // reg := regexp.MustCompile(v.(string))
  484. // winBackRegexps = append(winBackRegexps, reg)
  485. //}
  486. //BackRegexp["winner"] = winBackRegexps
  487. //var winBackRepRegexps []RegexpInfo
  488. //for _, v := range backRepRegexps {
  489. // reps := strings.Split(v.(string), "#")
  490. // if len(reps) > 1 {
  491. // reg := RegexpInfo{
  492. // regs: regexp.MustCompile(reps[0]),
  493. // repstr: reps[1],
  494. // }
  495. // winBackRepRegexps = append(winBackRepRegexps, reg)
  496. // }
  497. //}
  498. //BackRepRegexp["winner"] = winBackRepRegexps
  499. var winBlackRegexps []*regexp.Regexp
  500. for _, v := range backBlack {
  501. reg := regexp.MustCompile(v.(string))
  502. winBlackRegexps = append(winBlackRegexps, reg)
  503. }
  504. BlackRegexp["winner"] = winBlackRegexps
  505. }
  506. func initBuyerRegexp() {
  507. buyRegMap := Sysconfig["buyer"].(map[string]interface{})
  508. //preRegexps := buyRegMap["pre_regexp"].([]interface{})
  509. //backRegexps := buyRegMap["back_regexp"].([]interface{})
  510. //backRepRegexps := buyRegMap["back_rep_regexp"].([]interface{})
  511. backBlack := buyRegMap["blacklist"].([]interface{})
  512. //var winPreRegexps []*regexp.Regexp
  513. //for _, v := range preRegexps {
  514. // reg := regexp.MustCompile("^" + v.(string))
  515. // winPreRegexps = append(winPreRegexps, reg)
  516. //}
  517. //PreRegexp["buyer"] = winPreRegexps
  518. //var winBackRegexps []*regexp.Regexp
  519. //for _, v := range backRegexps {
  520. // reg := regexp.MustCompile(v.(string))
  521. // winBackRegexps = append(winBackRegexps, reg)
  522. //}
  523. //BackRegexp["buyer"] = winBackRegexps
  524. //var winBackRepRegexps []RegexpInfo
  525. //for _, v := range backRepRegexps {
  526. // reps := strings.Split(v.(string), "#")
  527. // if len(reps) > 1 {
  528. // reg := RegexpInfo{
  529. // regs: regexp.MustCompile(reps[0]),
  530. // repstr: reps[1],
  531. // }
  532. // winBackRepRegexps = append(winBackRepRegexps, reg)
  533. // }
  534. //}
  535. //BackRepRegexp["buyer"] = winBackRepRegexps
  536. var winBlackRegexps []*regexp.Regexp
  537. for _, v := range backBlack {
  538. reg := regexp.MustCompile(v.(string))
  539. winBlackRegexps = append(winBlackRegexps, reg)
  540. }
  541. BlackRegexp["buyer"] = winBlackRegexps
  542. }
  543. func initAgencyRegexp() {
  544. buyRegMap := Sysconfig["agency"].(map[string]interface{})
  545. //preRegexps := buyRegMap["pre_regexp"].([]interface{})
  546. //backRegexps := buyRegMap["back_regexp"].([]interface{})
  547. //backRepRegexps := buyRegMap["back_rep_regexp"].([]interface{})
  548. backBlack := buyRegMap["blacklist"].([]interface{})
  549. //var winPreRegexps []*regexp.Regexp
  550. //for _, v := range preRegexps {
  551. // reg := regexp.MustCompile("^" + v.(string))
  552. // winPreRegexps = append(winPreRegexps, reg)
  553. //}
  554. //PreRegexp["agency"] = winPreRegexps
  555. //var winBackRegexps []*regexp.Regexp
  556. //for _, v := range backRegexps {
  557. // reg := regexp.MustCompile(v.(string))
  558. // winBackRegexps = append(winBackRegexps, reg)
  559. //}
  560. //BackRegexp["agency"] = winBackRegexps
  561. //var winBackRepRegexps []RegexpInfo
  562. //for _, v := range backRepRegexps {
  563. // reps := strings.Split(v.(string), "#")
  564. // if len(reps) > 1 {
  565. // reg := RegexpInfo{
  566. // regs: regexp.MustCompile(reps[0]),
  567. // repstr: reps[1],
  568. // }
  569. // winBackRepRegexps = append(winBackRepRegexps, reg)
  570. // }
  571. //}
  572. //BackRepRegexp["agency"] = winBackRepRegexps
  573. var winBlackRegexps []*regexp.Regexp
  574. for _, v := range backBlack {
  575. reg := regexp.MustCompile(v.(string))
  576. winBlackRegexps = append(winBlackRegexps, reg)
  577. }
  578. BlackRegexp["agency"] = winBlackRegexps
  579. }