init.go 23 KB

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