init.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. package main
  2. import (
  3. "fmt"
  4. "go.mongodb.org/mongo-driver/bson/primitive"
  5. "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
  6. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  7. "medical_project/config"
  8. "os"
  9. "regexp"
  10. "sync"
  11. )
  12. var (
  13. MongoBid, MongoPro *mongodb.MongodbSim //mongodb连接
  14. wg sync.WaitGroup
  15. findLock sync.Mutex
  16. //采购单位、项目名称、项目编号
  17. mapPb, mapPn, mapPc map[string]*Key
  18. AllIdsMapLock sync.Mutex
  19. AllIdsMap map[string]*ID
  20. //bidtype、bidstatus 锁
  21. mapBidLock sync.Mutex
  22. updatePool chan []map[string]interface{}
  23. updateSp chan bool
  24. saveSize int
  25. currentType string
  26. currentTime int64
  27. pici int64
  28. validTime int64
  29. statusTime int64
  30. jgTime int64
  31. compareNoPass = map[string]bool{}
  32. compareAB = map[string]bool{}
  33. compareAB2D = map[string]bool{}
  34. compareABD = map[string]bool{}
  35. compareAB2CD = map[string]bool{}
  36. compareABCD = map[string]bool{}
  37. _datereg = regexp.MustCompile("20[0-2][0-9][年-][0-9]{1,2}[月-][0-9]{1,2}[日-]([0-9]{1,2}时[0-9]{0,2})?")
  38. replaceStr = regexp.MustCompile("(工程|采购|项目|[?!、【】()—()--]|栏标价|中标候选人|招标代理)")
  39. //纯数字或纯字母
  40. StrOrNum2 = regexp.MustCompile("^[0-9_-]+$|^[a-zA-Z_-]+$")
  41. //含分包词,招标未识别分包 合并到一个项目
  42. KeyPackage = regexp.MustCompile("[0-9a-zA-Z一二三四五六七八九十ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ]+.{0,2}(包|段)|(包|段)[0-9a-zA-Z一二三四五六七八九十ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ]+.{0,2}")
  43. titleGetPc = regexp.MustCompile("^([-0-9a-zA-Z第号采招政询电审竞#]{8,}[-0-9a-zA-Z#]+)")
  44. titleGetPc1 = regexp.MustCompile("[\\[【((](.{0,6}(编号|编码|项号|包号|代码|标段?号)[::为])?([-0-9a-zA-Z第号采招政询电审竞#]{5,}([\\[\\]()()][-0-9a-zA-Z第号采招审竞#]+[\\[\\]()()][-0-9a-zA-Z第号采招审竞#]+)?)[\\]】))]")
  45. titleGetPc2 = regexp.MustCompile("([-0-9a-zA-Z第号采政招询电审竞#]{8,}[-0-9a-zA-Z#]+)(.{0,5}公告)?$")
  46. numCheckPc = regexp.MustCompile("^[0-9-]{1,10}$")
  47. StrOrNum = regexp.MustCompile("^[0-9_-]{1,4}$|^[a-zA-Z_-]{1,4}$")
  48. _zimureg1 = regexp.MustCompile("^[a-zA-Z-]{1,7}$")
  49. )
  50. func init() {
  51. config.Init("./common.toml")
  52. InitLog()
  53. InitMgo()
  54. updatePool = make(chan []map[string]interface{}, 5000)
  55. updateSp = make(chan bool, 1)
  56. saveSize = 200
  57. wg = sync.WaitGroup{}
  58. mapPn = make(map[string]*Key, 5000000)
  59. AllIdsMap = make(map[string]*ID, 5000000)
  60. mapPb = make(map[string]*Key, 1500000)
  61. mapPn = make(map[string]*Key, 5000000)
  62. mapPc = make(map[string]*Key, 5000000)
  63. validTime = int64(config.Conf.Server.ValidTime * 86400)
  64. statusTime = int64(config.Conf.Server.StatusDays * 86400)
  65. jgTime = int64(7 * 86400)
  66. //加载项目数据
  67. //---不能通过
  68. vm := []string{"C", "D"}
  69. //三个元素一致 [AB][AB][AB],分值最高
  70. vm = []string{"A", "B"}
  71. for i := 0; i < 2; i++ {
  72. for j := 0; j < 2; j++ {
  73. for k := 0; k < 2; k++ {
  74. key := vm[i] + vm[j] + vm[k]
  75. compareAB[key] = true
  76. }
  77. }
  78. }
  79. }
  80. func InitLog() {
  81. logcfg := config.Conf.Log
  82. err := log.InitLog(
  83. log.Path(logcfg.LogPath),
  84. log.Level(logcfg.LogLevel),
  85. log.Compress(logcfg.Compress),
  86. log.MaxSize(logcfg.MaxSize),
  87. log.MaxBackups(logcfg.MaxBackups),
  88. log.MaxAge(logcfg.MaxAge),
  89. log.Format(logcfg.Format),
  90. )
  91. if err != nil {
  92. fmt.Printf("InitLog failed: %v\n", err)
  93. os.Exit(1)
  94. }
  95. }
  96. func InitMgo() {
  97. MongoBid = &mongodb.MongodbSim{
  98. MongodbAddr: config.Conf.DB.MongoB.Addr,
  99. DbName: config.Conf.DB.MongoB.Dbname,
  100. Size: config.Conf.DB.MongoB.Size,
  101. UserName: config.Conf.DB.MongoB.User,
  102. Password: config.Conf.DB.MongoB.Password,
  103. }
  104. MongoBid.InitPool()
  105. MongoPro = &mongodb.MongodbSim{
  106. MongodbAddr: config.Conf.DB.MongoP.Addr,
  107. DbName: config.Conf.DB.MongoP.Dbname,
  108. Size: config.Conf.DB.MongoP.Size,
  109. UserName: config.Conf.DB.MongoP.User,
  110. Password: config.Conf.DB.MongoP.Password,
  111. }
  112. MongoPro.InitPool()
  113. }
  114. //招标信息实体类
  115. type Info struct {
  116. Id string `json:"_id"`
  117. Href string `json:"href"` //源地址
  118. Publishtime int64 `json:"publishtime"`
  119. Comeintime int64 `json:"comeintime"`
  120. Title string `json:"title"`
  121. TopType string `json:"toptype"`
  122. SubType string `json:"subtype"`
  123. ProjectName string `json:"projectname"`
  124. ProjectCode string `json:"projectcode"`
  125. ProjectScope string `json:"projectscope"`
  126. ContractCode string `json:"contractcode"`
  127. Buyer string `json:"buyer"`
  128. Buyerperson string `json:"buyerperson"`
  129. Buyertel string `json:"buyertel"`
  130. Agency string `json:"agency"`
  131. Area string `json:"area"`
  132. City string `json:"city"`
  133. District string `json:"district"`
  134. Infoformat int `json:"infoformat"`
  135. ReviewExperts []string `json:"review_experts"`
  136. Purchasing string `json:"purchasing"`
  137. WinnerOrder []map[string]interface{} `json:"winnerorder"`
  138. ProjectScale string `json:"project_scale"`
  139. ProjectDuration int `json:"project_duration"`
  140. ProjectTimeUnit string `json:"project_timeunit"`
  141. ProjectStartDate int64 `json:"project_startdate"`
  142. ProjectCompleteDate int64 `json:"project_completedate"`
  143. Payway string `json:"payway"`
  144. ContractGuarantee bool `json:"contract_guarantee"`
  145. BidGuarantee bool `json:"bid_guarantee"`
  146. Qualifies []map[string]interface{} `json:"qualifies"`
  147. EntIdList []string `json:"entidlist"`
  148. HasPackage bool // `json:"haspackage"`
  149. Package map[string]interface{} `json:"package"`
  150. Topscopeclass []string `json:"topscopeclass"`
  151. Subscopeclass []string `json:"subscopeclass"`
  152. Buyerclass string `json:"buyerclass"`
  153. Bidopentime int64 `json:"bidopentime"`
  154. Budget float64 `json:"budget"`
  155. Bidamount float64 `json:"bidamount"`
  156. Winners []string
  157. dealtype int
  158. PTC string //从标题中抽的项目编号
  159. pnbval int //项目名称、编号、采购单位存在的个数
  160. LenPC int //项目编号长度
  161. LenPN int //项目名称长度
  162. LenPTC int //标题抽的项目编号长度
  163. //以下三个元素做对比,计算包含时候使用
  164. PNBH int //0初始,+包含,-被包含
  165. PCBH int
  166. PTCBH int
  167. }
  168. // 内存 项目信息
  169. type Project struct {
  170. Id primitive.ObjectID `json:"_id"`
  171. Ids []string `json:"ids,omitempty"`
  172. FirstTime int64 `json:"firsttime,omitempty"` //项目的最早时间
  173. LastTime int64 `json:"lasttime,omitempty"` //项目的最后时间
  174. ProjectName string `json:"projectname,omitempty"` //项目名称
  175. ProjectCode string `json:"projectcode,omitempty"` //项目代码唯一(纯数字的权重低)
  176. Buyer string `json:"buyer,omitempty"` //采购单位唯一
  177. Agency string `json:"agency"` //代理机构
  178. Area string `json:"area"` //地区
  179. City string `json:"city"` //地市
  180. District string `json:"district"` //区县
  181. Bidamount float64 `json:"bidamount,omitempty"` //中标金额
  182. Budget float64 `json:"budget,omitempty"` //预算
  183. score int
  184. comStr string
  185. MPN []string `json:"mpn,omitempty"` //合并后多余的项目名称
  186. MPC []string `json:"mpc,omitempty"` //合并后多余的项目编号
  187. resVal, pjVal int
  188. Topscopeclass []string `json:"topscopeclass,omitempty"`
  189. Subscopeclass []string `json:"subscopeclass,omitempty"` //子行业分类
  190. Winners string `json:"s_winner,omitempty"` //中标人
  191. ContractCode string `json:"contractcode,omitempty"` //合同编号
  192. Buyerperson string `json:"buyerperson"` //采购联系人
  193. Buyertel string `json:"buyertel"` //采购联系人电话
  194. Bidstatus string `json:"bidstatus"` //
  195. Bidtype string `json:"bidtype"` //
  196. ReviewExperts []string `json:"review_experts"` // 项目评审专家
  197. Purchasing string `json:"purchasing"` // 标的物
  198. Package map[string]interface{} `json:"package,omitempty"` //分包的对比对象
  199. Buyerclass string `json:"buyerclass"` //采购单位分类
  200. Bidopentime int64 `json:"bidopentime,omitempty"` //开标时间
  201. Jgtime int64 `json:"jgtime"` //结果中标时间
  202. Zbtime int64 `json:"zbtime"` //招标时间
  203. Winnerorder []string `json:"winnerorder"` //中标候选人
  204. ProjectScale string `json:"project_scale"` //项目规模
  205. ProjectDuration int `json:"project_duration"` //工期时长
  206. ProjectTimeunit string `json:"project_timeunit"` //工期时长单位
  207. ProjectStartDate int64 `json:"project_startdate"` //开工日期
  208. ProjctCompleteDate int64 `json:"projct_completedate"` //竣工日期
  209. Payway string `json:"payway"` //付款方式
  210. ContractGuarantee bool `json:"contract_guarantee"` //履约保证金 是否支持包含
  211. BidGuarantee bool `json:"bid_guarantee"` //投标保证金 是否支持包含
  212. Qualifies string `json:"qualifies"` //资质条件
  213. EntIdList []string `json:"entidlist"` //企业id
  214. //FirstCooperation []string `json:"first_cooperation"` //first_cooperation
  215. InfoFiled map[string]InfoField `json:"infofield"` //逻辑处理需要的info字段
  216. Budgettag int `json:"budgettag"` //预算是否有效标记
  217. Bidamounttag int `json:"bidamounttag"` //中标金额是否有效标记
  218. }
  219. //存储部分招标信息字段,业务逻辑处理需要
  220. type InfoField struct {
  221. Budget float64 `json:"budget"`
  222. Bidamount float64 `json:"bidamount"`
  223. ContractCode string `json:"contractcode"`
  224. ProjectName string `json:"projectname"`
  225. ProjectCode string `json:"projectcode"`
  226. Bidstatus string `json:"bidstatus"`
  227. }
  228. type ID struct {
  229. Id string
  230. Lock sync.Mutex
  231. P *Project
  232. }
  233. type Key struct {
  234. Arr []string
  235. Lock sync.Mutex
  236. }