init.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. package main
  2. import (
  3. "fmt"
  4. "go.mongodb.org/mongo-driver/bson/primitive"
  5. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  6. "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
  7. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  8. "jygit.jydev.jianyu360.cn/data_processing/common_utils/redis"
  9. "jygit.jydev.jianyu360.cn/data_processing/common_utils/udp"
  10. "math"
  11. "os"
  12. "project/config"
  13. "reflect"
  14. "regexp"
  15. "sort"
  16. "strings"
  17. "sync"
  18. )
  19. var (
  20. MgoP, MgoB, MgoS *mongodb.MongodbSim //mongodb连接
  21. BiddingColl, ProjectColl, BackupColl, SiteColl string //抽取表、项目表、项目快照表、站点表
  22. Thread int //配置项线程数
  23. BlackList []interface{}
  24. SkipSiteList []string
  25. BlaskListMap map[string]bool
  26. RedisCode string
  27. )
  28. var (
  29. //判断是日期
  30. _datereg = regexp.MustCompile("20[0-2][0-9][年-][0-9]{1,2}[月-][0-9]{1,2}[日-]([0-9]{1,2}时[0-9]{0,2})?")
  31. _numreg1 = regexp.MustCompile("^[0-9-]{1,8}$")
  32. _zimureg1 = regexp.MustCompile("^[a-zA-Z-]{1,7}$")
  33. _nzreg = regexp.MustCompile("^[0-9a-zA-Z-]+$")
  34. _hanreg = regexp.MustCompile(`^[\p{Han}::【】\\[\\]()()--、]+$`)
  35. replaceStr = regexp.MustCompile("(工程|采购|项目|[?!、【】()—()--]|栏标价|中标候选人|招标代理)")
  36. //判断带有分包、等特定词的
  37. pStr = regexp.MustCompile("(勘察|监理|施工|设计|验收|标段|分包|子包|[0-9A-Z]包|[一二三四五六七八九十0-9]批)")
  38. //判断包含数值
  39. nreg1 = regexp.MustCompile("[0-9]{2,}")
  40. //判断包含字母
  41. zreg1 = regexp.MustCompile("[a-zA-Z]{1,}")
  42. //判断包含汉字
  43. hreg1 = regexp.MustCompile(`[\p{Han}]+`)
  44. //判断项目编号是在10以内的纯数字结构
  45. numCheckPc = regexp.MustCompile("^[0-9-]{1,10}$")
  46. //仅初始化使用
  47. compareNoPass = map[string]bool{}
  48. compareAB = map[string]bool{}
  49. compareAB2D = map[string]bool{}
  50. compareABD = map[string]bool{}
  51. compareAB2CD = map[string]bool{}
  52. compareABCD = map[string]bool{}
  53. )
  54. func init() {
  55. config.Init("./common.toml")
  56. InitLog()
  57. MgoP = &mongodb.MongodbSim{
  58. MongodbAddr: config.Conf.DB.MongoP.Addr,
  59. Size: config.Conf.DB.MongoP.Size,
  60. DbName: config.Conf.DB.MongoP.Dbname,
  61. UserName: config.Conf.DB.MongoP.User,
  62. Password: config.Conf.DB.MongoP.Password,
  63. }
  64. MgoP.InitPool()
  65. MgoB = &mongodb.MongodbSim{
  66. MongodbAddr: config.Conf.DB.MongoB.Addr,
  67. Size: config.Conf.DB.MongoB.Size,
  68. DbName: config.Conf.DB.MongoB.Dbname,
  69. UserName: config.Conf.DB.MongoB.User,
  70. Password: config.Conf.DB.MongoB.Password,
  71. }
  72. MgoB.InitPool()
  73. MgoS = &mongodb.MongodbSim{
  74. MongodbAddr: config.Conf.DB.MongoS.Addr,
  75. Size: config.Conf.DB.MongoS.Size,
  76. DbName: config.Conf.DB.MongoS.Dbname,
  77. UserName: config.Conf.DB.MongoS.User,
  78. Password: config.Conf.DB.MongoS.Password,
  79. }
  80. MgoS.InitPool()
  81. BiddingColl = config.Conf.DB.MongoB.Coll
  82. ProjectColl = config.Conf.DB.MongoP.Coll
  83. BackupColl = config.Conf.DB.MongoP.Coll + "_back"
  84. SiteColl = config.Conf.Serve.SiteColl
  85. Thread = config.Conf.Serve.Thread
  86. udpclient = udp.UdpClient{Local: config.Conf.Serve.Udp, BufSize: 1024}
  87. udpclient.Listen(processUdpMsg)
  88. log.Info("udp init port:" + udpclient.Local)
  89. //"qyxy_buyer=172.17.4.189:8379"
  90. RedisCode = "qyxy_buyer"
  91. redis.InitRedis1(config.Conf.DB.Redis.AddrQb, config.Conf.DB.Redis.DbQb) // 采购单位与中标单位初次合作项目
  92. redis.InitRedis1(config.Conf.DB.Redis.Addr, 0)
  93. cof := make(map[string]interface{})
  94. util.ReadConfig(&cof)
  95. BlackList = cof["rp_blacklist"].([]interface{})
  96. BlaskListMap = make(map[string]bool)
  97. for _, v := range BlackList {
  98. BlaskListMap[util.ObjToString(v)] = true
  99. }
  100. SkipSiteList = util.ObjArrToStringArr(cof["site_list"].([]interface{}))
  101. initWinnerRegexp(cof)
  102. initBuyerRegexp(cof)
  103. initAgencyRegexp(cof)
  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. BidEndTime int64 `json:"bidendtime"`
  283. Budget float64 `json:"budget"`
  284. Bidamount float64 `json:"bidamount"`
  285. Winners []string
  286. dealtype int
  287. PTC string //从标题中抽的项目编号
  288. pnbval int //项目名称、编号、采购单位存在的个数
  289. LenPC int //项目编号长度
  290. LenPN int //项目名称长度
  291. LenPTC int //标题抽的项目编号长度
  292. //以下三个元素做对比,计算包含时候使用
  293. PNBH int //0初始,+包含,-被包含
  294. PCBH int
  295. PTCBH int
  296. }
  297. // 内存 项目信息
  298. type ProjectCache struct {
  299. Id primitive.ObjectID `json:"_id"`
  300. Ids []string `json:"ids,omitempty"`
  301. Size int `json:"size"`
  302. FirstTime int64 `json:"firsttime,omitempty"` //项目的最早时间
  303. LastTime int64 `json:"lasttime,omitempty"` //项目的最后时间
  304. ProjectName string `json:"projectname,omitempty"` //项目名称
  305. ProjectCode string `json:"projectcode,omitempty"` //项目代码唯一(纯数字的权重低)
  306. Buyer string `json:"buyer,omitempty"` //采购单位唯一
  307. Agency string `json:"agency"` //代理机构
  308. Area string `json:"area"` //地区
  309. City string `json:"city"` //地市
  310. District string `json:"district"` //区县
  311. Bidamount float64 `json:"bidamount,omitempty"` //中标金额
  312. Budget float64 `json:"budget,omitempty"` //预算
  313. Bidstatus string `json:"bidstatus"` //
  314. Bidtype string `json:"bidtype"` //
  315. score int
  316. comStr string
  317. MPN []string `json:"mpn,omitempty"` //合并后多余的项目名称
  318. MPC []string `json:"mpc,omitempty"` //合并后多余的项目编号
  319. resVal, pjVal int
  320. }
  321. // 项目信息
  322. type Project struct {
  323. Id primitive.ObjectID `json:"_id"`
  324. Ids []string `json:"ids,omitempty"`
  325. FirstTime int64 `json:"firsttime,omitempty"` //项目的最早时间
  326. LastTime int64 `json:"lasttime,omitempty"` //项目的最后时间
  327. ProjectName string `json:"projectname,omitempty"` //项目名称
  328. ProjectCode string `json:"projectcode,omitempty"` //项目代码唯一(纯数字的权重低)
  329. Buyer string `json:"buyer,omitempty"` //采购单位唯一
  330. Agency string `json:"agency"` //代理机构
  331. Area string `json:"area"` //地区
  332. City string `json:"city"` //地市
  333. District string `json:"district"` //区县
  334. Bidamount float64 `json:"bidamount,omitempty"` //中标金额
  335. Budget float64 `json:"budget,omitempty"` //预算
  336. score int
  337. comStr string
  338. MPN []string `json:"mpn,omitempty"` //合并后多余的项目名称
  339. MPC []string `json:"mpc,omitempty"` //合并后多余的项目编号
  340. resVal, pjVal int
  341. Topscopeclass []string `json:"topscopeclass,omitempty"`
  342. Subscopeclass []string `json:"subscopeclass,omitempty"` //子行业分类
  343. Winners string `json:"s_winner,omitempty"` //中标人
  344. ContractCode string `json:"contractcode,omitempty"` //合同编号
  345. Buyerperson string `json:"buyerperson"` //采购联系人
  346. Buyertel string `json:"buyertel"` //采购联系人电话
  347. Bidstatus string `json:"bidstatus"` //
  348. Bidtype string `json:"bidtype"` //
  349. ReviewExperts string `json:"review_experts"` // 项目评审专家
  350. Purchasing string `json:"purchasing"` // 标的物
  351. Package map[string]interface{} `json:"package,omitempty"` //分包的对比对象
  352. Buyerclass string `json:"buyerclass"` //采购单位分类
  353. BidOpenTime int64 `json:"bidopentime,omitempty"` //开标时间
  354. BidEndTime int64 `json:"bidendtime,omitempty"` //开标时间
  355. Jgtime int64 `json:"jgtime"` //结果中标时间
  356. Zbtime int64 `json:"zbtime"` //招标时间
  357. Winnerorder []string `json:"winnerorder"` //中标候选人
  358. ProjectScale string `json:"project_scale"` //项目规模
  359. ProjectDuration int `json:"project_duration"` //工期时长
  360. ProjectTimeunit string `json:"project_timeunit"` //工期时长单位
  361. ProjectStartDate int64 `json:"project_startdate"` //开工日期
  362. ProjctCompleteDate int64 `json:"projct_completedate"` //竣工日期
  363. Payway string `json:"payway"` //付款方式
  364. ContractGuarantee bool `json:"contract_guarantee"` //履约保证金 是否支持包含
  365. BidGuarantee bool `json:"bid_guarantee"` //投标保证金 是否支持包含
  366. Qualifies string `json:"qualifies"` //资质条件
  367. EntIdList []string `json:"entidlist"` //企业id
  368. //FirstCooperation []string `json:"first_cooperation"` //first_cooperation
  369. //InfoFiled map[string]InfoField `json:"infofield"` //逻辑处理需要的info字段
  370. }
  371. // 存储部分招标信息字段,业务逻辑处理需要
  372. type InfoField struct {
  373. Budget float64 `json:"budget"`
  374. Bidamount float64 `json:"bidamount"`
  375. ContractCode string `json:"contractcode"`
  376. ProjectName string `json:"projectname"`
  377. ProjectCode string `json:"projectcode"`
  378. Bidstatus string `json:"bidstatus"`
  379. }
  380. // 站点信息
  381. type Site struct {
  382. Id string `json:"_id"`
  383. Site string `json:"site"` //站点名字
  384. Area string `json:"area"` //省
  385. City string `json:"city"` //市
  386. District string `json:"district"` //区、县
  387. Domain string `json:"domain"` //地址
  388. Status int `json:"status"` //
  389. }
  390. // 二分字符串查找
  391. func BinarySearch(s []string, k string) int {
  392. sort.Strings(s)
  393. lo, hi := 0, len(s)-1
  394. for lo <= hi {
  395. m := (lo + hi) >> 1
  396. if s[m] < k {
  397. lo = m + 1
  398. } else if s[m] > k {
  399. hi = m - 1
  400. } else {
  401. return m
  402. }
  403. }
  404. return -1
  405. }
  406. func Duplicate(a interface{}) (ret []interface{}) {
  407. va := reflect.ValueOf(a)
  408. for i := 0; i < va.Len(); i++ {
  409. if i > 0 && reflect.DeepEqual(va.Index(i-1).Interface(), va.Index(i).Interface()) {
  410. continue
  411. }
  412. ret = append(ret, va.Index(i).Interface())
  413. }
  414. return ret
  415. }
  416. // 计算文本相似度
  417. func CosineSimilar(srcWords1, dstWords1 string) float64 {
  418. srcWords, dstWords := strings.Split(srcWords1, ""), strings.Split(dstWords1, "")
  419. // get all words
  420. allWordsMap := make(map[string]int, 0)
  421. for _, word := range srcWords {
  422. if _, found := allWordsMap[word]; !found {
  423. allWordsMap[word] = 1
  424. } else {
  425. allWordsMap[word] += 1
  426. }
  427. }
  428. for _, word := range dstWords {
  429. if _, found := allWordsMap[word]; !found {
  430. allWordsMap[word] = 1
  431. } else {
  432. allWordsMap[word] += 1
  433. }
  434. }
  435. // stable the sort
  436. allWordsSlice := make([]string, 0)
  437. for word, _ := range allWordsMap {
  438. allWordsSlice = append(allWordsSlice, word)
  439. }
  440. // assemble vector
  441. srcVector := make([]int, len(allWordsSlice))
  442. dstVector := make([]int, len(allWordsSlice))
  443. for _, word := range srcWords {
  444. if index := BinarySearch(allWordsSlice, word); index != -1 {
  445. srcVector[index] += 1
  446. }
  447. }
  448. for _, word := range dstWords {
  449. if index := BinarySearch(allWordsSlice, word); index != -1 {
  450. dstVector[index] += 1
  451. }
  452. }
  453. // calc cos
  454. numerator := float64(0)
  455. srcSq := 0
  456. dstSq := 0
  457. for i, srcCount := range srcVector {
  458. dstCount := dstVector[i]
  459. numerator += float64(srcCount * dstCount)
  460. srcSq += srcCount * srcCount
  461. dstSq += dstCount * dstCount
  462. }
  463. denominator := math.Sqrt(float64(srcSq * dstSq))
  464. v1 := numerator / denominator
  465. // if v1 > 0.6 {
  466. // log.Println(v1, srcWords1, dstWords1)
  467. // }
  468. return v1
  469. }
  470. func initWinnerRegexp(cof map[string]interface{}) {
  471. winRegMap := cof["winner"].(map[string]interface{})
  472. //preRegexps := winRegMap["pre_regexp"].([]interface{})
  473. //backRegexps := winRegMap["back_regexp"].([]interface{})
  474. //backRepRegexps := winRegMap["back_rep_regexp"].([]interface{})
  475. backBlack := winRegMap["blacklist"].([]interface{})
  476. //var winPreRegexps []*regexp.Regexp
  477. //for _, v := range preRegexps {
  478. // reg := regexp.MustCompile("^" + v.(string))
  479. // winPreRegexps = append(winPreRegexps, reg)
  480. //}
  481. //PreRegexp["winner"] = winPreRegexps
  482. //var winBackRegexps []*regexp.Regexp
  483. //for _, v := range backRegexps {
  484. // reg := regexp.MustCompile(v.(string))
  485. // winBackRegexps = append(winBackRegexps, reg)
  486. //}
  487. //BackRegexp["winner"] = winBackRegexps
  488. //var winBackRepRegexps []RegexpInfo
  489. //for _, v := range backRepRegexps {
  490. // reps := strings.Split(v.(string), "#")
  491. // if len(reps) > 1 {
  492. // reg := RegexpInfo{
  493. // regs: regexp.MustCompile(reps[0]),
  494. // repstr: reps[1],
  495. // }
  496. // winBackRepRegexps = append(winBackRepRegexps, reg)
  497. // }
  498. //}
  499. //BackRepRegexp["winner"] = winBackRepRegexps
  500. var winBlackRegexps []*regexp.Regexp
  501. for _, v := range backBlack {
  502. reg := regexp.MustCompile(v.(string))
  503. winBlackRegexps = append(winBlackRegexps, reg)
  504. }
  505. BlackRegexp["winner"] = winBlackRegexps
  506. }
  507. func initBuyerRegexp(cof map[string]interface{}) {
  508. buyRegMap := cof["buyer"].(map[string]interface{})
  509. //preRegexps := buyRegMap["pre_regexp"].([]interface{})
  510. //backRegexps := buyRegMap["back_regexp"].([]interface{})
  511. //backRepRegexps := buyRegMap["back_rep_regexp"].([]interface{})
  512. backBlack := buyRegMap["blacklist"].([]interface{})
  513. //var winPreRegexps []*regexp.Regexp
  514. //for _, v := range preRegexps {
  515. // reg := regexp.MustCompile("^" + v.(string))
  516. // winPreRegexps = append(winPreRegexps, reg)
  517. //}
  518. //PreRegexp["buyer"] = winPreRegexps
  519. //var winBackRegexps []*regexp.Regexp
  520. //for _, v := range backRegexps {
  521. // reg := regexp.MustCompile(v.(string))
  522. // winBackRegexps = append(winBackRegexps, reg)
  523. //}
  524. //BackRegexp["buyer"] = winBackRegexps
  525. //var winBackRepRegexps []RegexpInfo
  526. //for _, v := range backRepRegexps {
  527. // reps := strings.Split(v.(string), "#")
  528. // if len(reps) > 1 {
  529. // reg := RegexpInfo{
  530. // regs: regexp.MustCompile(reps[0]),
  531. // repstr: reps[1],
  532. // }
  533. // winBackRepRegexps = append(winBackRepRegexps, reg)
  534. // }
  535. //}
  536. //BackRepRegexp["buyer"] = winBackRepRegexps
  537. var winBlackRegexps []*regexp.Regexp
  538. for _, v := range backBlack {
  539. reg := regexp.MustCompile(v.(string))
  540. winBlackRegexps = append(winBlackRegexps, reg)
  541. }
  542. BlackRegexp["buyer"] = winBlackRegexps
  543. }
  544. func initAgencyRegexp(cof map[string]interface{}) {
  545. buyRegMap := cof["agency"].(map[string]interface{})
  546. //preRegexps := buyRegMap["pre_regexp"].([]interface{})
  547. //backRegexps := buyRegMap["back_regexp"].([]interface{})
  548. //backRepRegexps := buyRegMap["back_rep_regexp"].([]interface{})
  549. backBlack := buyRegMap["blacklist"].([]interface{})
  550. //var winPreRegexps []*regexp.Regexp
  551. //for _, v := range preRegexps {
  552. // reg := regexp.MustCompile("^" + v.(string))
  553. // winPreRegexps = append(winPreRegexps, reg)
  554. //}
  555. //PreRegexp["agency"] = winPreRegexps
  556. //var winBackRegexps []*regexp.Regexp
  557. //for _, v := range backRegexps {
  558. // reg := regexp.MustCompile(v.(string))
  559. // winBackRegexps = append(winBackRegexps, reg)
  560. //}
  561. //BackRegexp["agency"] = winBackRegexps
  562. //var winBackRepRegexps []RegexpInfo
  563. //for _, v := range backRepRegexps {
  564. // reps := strings.Split(v.(string), "#")
  565. // if len(reps) > 1 {
  566. // reg := RegexpInfo{
  567. // regs: regexp.MustCompile(reps[0]),
  568. // repstr: reps[1],
  569. // }
  570. // winBackRepRegexps = append(winBackRepRegexps, reg)
  571. // }
  572. //}
  573. //BackRepRegexp["agency"] = winBackRepRegexps
  574. var winBlackRegexps []*regexp.Regexp
  575. for _, v := range backBlack {
  576. reg := regexp.MustCompile(v.(string))
  577. winBlackRegexps = append(winBlackRegexps, reg)
  578. }
  579. BlackRegexp["agency"] = winBlackRegexps
  580. }
  581. func InitLog() {
  582. logcfg := config.Conf.Log
  583. err := log.InitLog(
  584. log.Path(logcfg.LogPath),
  585. log.Level(logcfg.LogLevel),
  586. log.Compress(logcfg.Compress),
  587. log.MaxSize(logcfg.MaxSize),
  588. log.MaxBackups(logcfg.MaxBackups),
  589. log.MaxAge(logcfg.MaxAge),
  590. log.Format(logcfg.Format),
  591. )
  592. if err != nil {
  593. fmt.Printf("InitLog failed: %v\n", err)
  594. os.Exit(1)
  595. }
  596. }