init.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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. FirstTime int64 `json:"firsttime,omitempty"` //项目的最早时间
  302. LastTime int64 `json:"lasttime,omitempty"` //项目的最后时间
  303. ProjectName string `json:"projectname,omitempty"` //项目名称
  304. ProjectCode string `json:"projectcode,omitempty"` //项目代码唯一(纯数字的权重低)
  305. Buyer string `json:"buyer,omitempty"` //采购单位唯一
  306. Agency string `json:"agency"` //代理机构
  307. Area string `json:"area"` //地区
  308. City string `json:"city"` //地市
  309. District string `json:"district"` //区县
  310. Bidamount float64 `json:"bidamount,omitempty"` //中标金额
  311. Budget float64 `json:"budget,omitempty"` //预算
  312. Bidstatus string `json:"bidstatus"` //
  313. Bidtype string `json:"bidtype"` //
  314. score int
  315. comStr string
  316. MPN []string `json:"mpn,omitempty"` //合并后多余的项目名称
  317. MPC []string `json:"mpc,omitempty"` //合并后多余的项目编号
  318. resVal, pjVal int
  319. }
  320. // 项目信息
  321. type Project struct {
  322. Id primitive.ObjectID `json:"_id"`
  323. Ids []string `json:"ids,omitempty"`
  324. FirstTime int64 `json:"firsttime,omitempty"` //项目的最早时间
  325. LastTime int64 `json:"lasttime,omitempty"` //项目的最后时间
  326. ProjectName string `json:"projectname,omitempty"` //项目名称
  327. ProjectCode string `json:"projectcode,omitempty"` //项目代码唯一(纯数字的权重低)
  328. Buyer string `json:"buyer,omitempty"` //采购单位唯一
  329. Agency string `json:"agency"` //代理机构
  330. Area string `json:"area"` //地区
  331. City string `json:"city"` //地市
  332. District string `json:"district"` //区县
  333. Bidamount float64 `json:"bidamount,omitempty"` //中标金额
  334. Budget float64 `json:"budget,omitempty"` //预算
  335. score int
  336. comStr string
  337. MPN []string `json:"mpn,omitempty"` //合并后多余的项目名称
  338. MPC []string `json:"mpc,omitempty"` //合并后多余的项目编号
  339. resVal, pjVal int
  340. Topscopeclass []string `json:"topscopeclass,omitempty"`
  341. Subscopeclass []string `json:"subscopeclass,omitempty"` //子行业分类
  342. Winners string `json:"s_winner,omitempty"` //中标人
  343. ContractCode string `json:"contractcode,omitempty"` //合同编号
  344. Buyerperson string `json:"buyerperson"` //采购联系人
  345. Buyertel string `json:"buyertel"` //采购联系人电话
  346. Bidstatus string `json:"bidstatus"` //
  347. Bidtype string `json:"bidtype"` //
  348. ReviewExperts []string `json:"review_experts"` // 项目评审专家
  349. Purchasing string `json:"purchasing"` // 标的物
  350. Package map[string]interface{} `json:"package,omitempty"` //分包的对比对象
  351. Buyerclass string `json:"buyerclass"` //采购单位分类
  352. BidOpenTime int64 `json:"bidopentime,omitempty"` //开标时间
  353. BidEndTime int64 `json:"bidendtime,omitempty"` //开标时间
  354. Jgtime int64 `json:"jgtime"` //结果中标时间
  355. Zbtime int64 `json:"zbtime"` //招标时间
  356. Winnerorder []string `json:"winnerorder"` //中标候选人
  357. ProjectScale string `json:"project_scale"` //项目规模
  358. ProjectDuration int `json:"project_duration"` //工期时长
  359. ProjectTimeunit string `json:"project_timeunit"` //工期时长单位
  360. ProjectStartDate int64 `json:"project_startdate"` //开工日期
  361. ProjctCompleteDate int64 `json:"projct_completedate"` //竣工日期
  362. Payway string `json:"payway"` //付款方式
  363. ContractGuarantee bool `json:"contract_guarantee"` //履约保证金 是否支持包含
  364. BidGuarantee bool `json:"bid_guarantee"` //投标保证金 是否支持包含
  365. Qualifies string `json:"qualifies"` //资质条件
  366. EntIdList []string `json:"entidlist"` //企业id
  367. //FirstCooperation []string `json:"first_cooperation"` //first_cooperation
  368. InfoFiled map[string]InfoField `json:"infofield"` //逻辑处理需要的info字段
  369. Budgettag int `json:"budgettag"` //预算是否有效标记
  370. Bidamounttag int `json:"bidamounttag"` //中标金额是否有效标记
  371. }
  372. //存储部分招标信息字段,业务逻辑处理需要
  373. type InfoField struct {
  374. Budget float64 `json:"budget"`
  375. Bidamount float64 `json:"bidamount"`
  376. ContractCode string `json:"contractcode"`
  377. ProjectName string `json:"projectname"`
  378. ProjectCode string `json:"projectcode"`
  379. Bidstatus string `json:"bidstatus"`
  380. }
  381. //站点信息
  382. type Site struct {
  383. Id string `json:"_id"`
  384. Site string `json:"site"` //站点名字
  385. Area string `json:"area"` //省
  386. City string `json:"city"` //市
  387. District string `json:"district"` //区、县
  388. Domain string `json:"domain"` //地址
  389. Status int `json:"status"` //
  390. }
  391. //二分字符串查找
  392. func BinarySearch(s []string, k string) int {
  393. sort.Strings(s)
  394. lo, hi := 0, len(s)-1
  395. for lo <= hi {
  396. m := (lo + hi) >> 1
  397. if s[m] < k {
  398. lo = m + 1
  399. } else if s[m] > k {
  400. hi = m - 1
  401. } else {
  402. return m
  403. }
  404. }
  405. return -1
  406. }
  407. func Duplicate(a interface{}) (ret []interface{}) {
  408. va := reflect.ValueOf(a)
  409. for i := 0; i < va.Len(); i++ {
  410. if i > 0 && reflect.DeepEqual(va.Index(i-1).Interface(), va.Index(i).Interface()) {
  411. continue
  412. }
  413. ret = append(ret, va.Index(i).Interface())
  414. }
  415. return ret
  416. }
  417. //计算文本相似度
  418. func CosineSimilar(srcWords1, dstWords1 string) float64 {
  419. srcWords, dstWords := strings.Split(srcWords1, ""), strings.Split(dstWords1, "")
  420. // get all words
  421. allWordsMap := make(map[string]int, 0)
  422. for _, word := range srcWords {
  423. if _, found := allWordsMap[word]; !found {
  424. allWordsMap[word] = 1
  425. } else {
  426. allWordsMap[word] += 1
  427. }
  428. }
  429. for _, word := range dstWords {
  430. if _, found := allWordsMap[word]; !found {
  431. allWordsMap[word] = 1
  432. } else {
  433. allWordsMap[word] += 1
  434. }
  435. }
  436. // stable the sort
  437. allWordsSlice := make([]string, 0)
  438. for word, _ := range allWordsMap {
  439. allWordsSlice = append(allWordsSlice, word)
  440. }
  441. // assemble vector
  442. srcVector := make([]int, len(allWordsSlice))
  443. dstVector := make([]int, len(allWordsSlice))
  444. for _, word := range srcWords {
  445. if index := BinarySearch(allWordsSlice, word); index != -1 {
  446. srcVector[index] += 1
  447. }
  448. }
  449. for _, word := range dstWords {
  450. if index := BinarySearch(allWordsSlice, word); index != -1 {
  451. dstVector[index] += 1
  452. }
  453. }
  454. // calc cos
  455. numerator := float64(0)
  456. srcSq := 0
  457. dstSq := 0
  458. for i, srcCount := range srcVector {
  459. dstCount := dstVector[i]
  460. numerator += float64(srcCount * dstCount)
  461. srcSq += srcCount * srcCount
  462. dstSq += dstCount * dstCount
  463. }
  464. denominator := math.Sqrt(float64(srcSq * dstSq))
  465. v1 := numerator / denominator
  466. // if v1 > 0.6 {
  467. // log.Println(v1, srcWords1, dstWords1)
  468. // }
  469. return v1
  470. }
  471. func initWinnerRegexp(cof map[string]interface{}) {
  472. winRegMap := cof["winner"].(map[string]interface{})
  473. //preRegexps := winRegMap["pre_regexp"].([]interface{})
  474. //backRegexps := winRegMap["back_regexp"].([]interface{})
  475. //backRepRegexps := winRegMap["back_rep_regexp"].([]interface{})
  476. backBlack := winRegMap["blacklist"].([]interface{})
  477. //var winPreRegexps []*regexp.Regexp
  478. //for _, v := range preRegexps {
  479. // reg := regexp.MustCompile("^" + v.(string))
  480. // winPreRegexps = append(winPreRegexps, reg)
  481. //}
  482. //PreRegexp["winner"] = winPreRegexps
  483. //var winBackRegexps []*regexp.Regexp
  484. //for _, v := range backRegexps {
  485. // reg := regexp.MustCompile(v.(string))
  486. // winBackRegexps = append(winBackRegexps, reg)
  487. //}
  488. //BackRegexp["winner"] = winBackRegexps
  489. //var winBackRepRegexps []RegexpInfo
  490. //for _, v := range backRepRegexps {
  491. // reps := strings.Split(v.(string), "#")
  492. // if len(reps) > 1 {
  493. // reg := RegexpInfo{
  494. // regs: regexp.MustCompile(reps[0]),
  495. // repstr: reps[1],
  496. // }
  497. // winBackRepRegexps = append(winBackRepRegexps, reg)
  498. // }
  499. //}
  500. //BackRepRegexp["winner"] = winBackRepRegexps
  501. var winBlackRegexps []*regexp.Regexp
  502. for _, v := range backBlack {
  503. reg := regexp.MustCompile(v.(string))
  504. winBlackRegexps = append(winBlackRegexps, reg)
  505. }
  506. BlackRegexp["winner"] = winBlackRegexps
  507. }
  508. func initBuyerRegexp(cof map[string]interface{}) {
  509. buyRegMap := cof["buyer"].(map[string]interface{})
  510. //preRegexps := buyRegMap["pre_regexp"].([]interface{})
  511. //backRegexps := buyRegMap["back_regexp"].([]interface{})
  512. //backRepRegexps := buyRegMap["back_rep_regexp"].([]interface{})
  513. backBlack := buyRegMap["blacklist"].([]interface{})
  514. //var winPreRegexps []*regexp.Regexp
  515. //for _, v := range preRegexps {
  516. // reg := regexp.MustCompile("^" + v.(string))
  517. // winPreRegexps = append(winPreRegexps, reg)
  518. //}
  519. //PreRegexp["buyer"] = winPreRegexps
  520. //var winBackRegexps []*regexp.Regexp
  521. //for _, v := range backRegexps {
  522. // reg := regexp.MustCompile(v.(string))
  523. // winBackRegexps = append(winBackRegexps, reg)
  524. //}
  525. //BackRegexp["buyer"] = winBackRegexps
  526. //var winBackRepRegexps []RegexpInfo
  527. //for _, v := range backRepRegexps {
  528. // reps := strings.Split(v.(string), "#")
  529. // if len(reps) > 1 {
  530. // reg := RegexpInfo{
  531. // regs: regexp.MustCompile(reps[0]),
  532. // repstr: reps[1],
  533. // }
  534. // winBackRepRegexps = append(winBackRepRegexps, reg)
  535. // }
  536. //}
  537. //BackRepRegexp["buyer"] = winBackRepRegexps
  538. var winBlackRegexps []*regexp.Regexp
  539. for _, v := range backBlack {
  540. reg := regexp.MustCompile(v.(string))
  541. winBlackRegexps = append(winBlackRegexps, reg)
  542. }
  543. BlackRegexp["buyer"] = winBlackRegexps
  544. }
  545. func initAgencyRegexp(cof map[string]interface{}) {
  546. buyRegMap := cof["agency"].(map[string]interface{})
  547. //preRegexps := buyRegMap["pre_regexp"].([]interface{})
  548. //backRegexps := buyRegMap["back_regexp"].([]interface{})
  549. //backRepRegexps := buyRegMap["back_rep_regexp"].([]interface{})
  550. backBlack := buyRegMap["blacklist"].([]interface{})
  551. //var winPreRegexps []*regexp.Regexp
  552. //for _, v := range preRegexps {
  553. // reg := regexp.MustCompile("^" + v.(string))
  554. // winPreRegexps = append(winPreRegexps, reg)
  555. //}
  556. //PreRegexp["agency"] = winPreRegexps
  557. //var winBackRegexps []*regexp.Regexp
  558. //for _, v := range backRegexps {
  559. // reg := regexp.MustCompile(v.(string))
  560. // winBackRegexps = append(winBackRegexps, reg)
  561. //}
  562. //BackRegexp["agency"] = winBackRegexps
  563. //var winBackRepRegexps []RegexpInfo
  564. //for _, v := range backRepRegexps {
  565. // reps := strings.Split(v.(string), "#")
  566. // if len(reps) > 1 {
  567. // reg := RegexpInfo{
  568. // regs: regexp.MustCompile(reps[0]),
  569. // repstr: reps[1],
  570. // }
  571. // winBackRepRegexps = append(winBackRepRegexps, reg)
  572. // }
  573. //}
  574. //BackRepRegexp["agency"] = winBackRepRegexps
  575. var winBlackRegexps []*regexp.Regexp
  576. for _, v := range backBlack {
  577. reg := regexp.MustCompile(v.(string))
  578. winBlackRegexps = append(winBlackRegexps, reg)
  579. }
  580. BlackRegexp["agency"] = winBlackRegexps
  581. }
  582. func InitLog() {
  583. logcfg := config.Conf.Log
  584. err := log.InitLog(
  585. log.Path(logcfg.LogPath),
  586. log.Level(logcfg.LogLevel),
  587. log.Compress(logcfg.Compress),
  588. log.MaxSize(logcfg.MaxSize),
  589. log.MaxBackups(logcfg.MaxBackups),
  590. log.MaxAge(logcfg.MaxAge),
  591. log.Format(logcfg.Format),
  592. )
  593. if err != nil {
  594. fmt.Printf("InitLog failed: %v\n", err)
  595. os.Exit(1)
  596. }
  597. }