init.go 22 KB

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