init.go 22 KB

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