init.go 24 KB

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