init.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. package main
  2. import (
  3. "customer_project/config"
  4. "fmt"
  5. "jygit.jydev.jianyu360.cn/data_processing/common_utils/elastic"
  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/mysqldb"
  9. "os"
  10. "sync"
  11. )
  12. var (
  13. MongoTool *mongodb.MongodbSim
  14. MysqlTool, MysqlEnt *mysqldb.Mysql
  15. Es *elastic.Elastic
  16. findLock sync.Mutex
  17. //mapPb, mapPn, mapPc map[string]*Key
  18. mapEnt map[int64]*EntMap
  19. AllIdsMapLock sync.Mutex
  20. AllIdsMap map[string]*ID
  21. //仅初始化使用
  22. compareNoPass = map[string]bool{}
  23. compareAB = map[string]bool{}
  24. compareAB2D = map[string]bool{}
  25. compareABD = map[string]bool{}
  26. compareAB2CD = map[string]bool{}
  27. compareABCD = map[string]bool{}
  28. )
  29. type EntMap struct {
  30. mapPb map[string]*Key
  31. mapPn map[string]*Key
  32. mapPc map[string]*Key
  33. }
  34. type ID struct {
  35. Id string
  36. Lock sync.Mutex
  37. P *Project
  38. }
  39. type Key struct {
  40. Arr []string
  41. Lock sync.Mutex
  42. }
  43. func init() {
  44. wg = sync.WaitGroup{}
  45. AllIdsMap = make(map[string]*ID, 5000000)
  46. //mapPb = make(map[string]*Key, 1500000)
  47. //mapPn = make(map[string]*Key, 5000000)
  48. //mapPc = make(map[string]*Key, 5000000)
  49. mapEnt = make(map[int64]*EntMap, 5000)
  50. //加载项目数据
  51. //---不能通过
  52. vm := []string{"C", "D"}
  53. for i := 0; i < 2; i++ {
  54. for j := 0; j < 2; j++ {
  55. for k := 0; k < 2; k++ {
  56. key := vm[i] + vm[j] + vm[k]
  57. compareNoPass[key] = true
  58. //fmt.Println(key)
  59. }
  60. }
  61. }
  62. //fmt.Println("-------------------")
  63. //三个元素一致 [AB][AB][AB],分值最高
  64. vm = []string{"A", "B"}
  65. for i := 0; i < 2; i++ {
  66. for j := 0; j < 2; j++ {
  67. for k := 0; k < 2; k++ {
  68. key := vm[i] + vm[j] + vm[k]
  69. compareAB[key] = true
  70. //fmt.Println(key)
  71. }
  72. }
  73. }
  74. //fmt.Println("-------------------", len(compareAB))
  75. //---至少两个一致,其他可能不存在
  76. //[AB][AB][ABD]
  77. //[AB][ABD][AB]
  78. vm = []string{"A", "B"}
  79. vm2 := []string{"A", "B", "D"}
  80. for i := 0; i < 2; i++ {
  81. for j := 0; j < 2; j++ {
  82. for k := 0; k < 3; k++ {
  83. key := vm[i] + vm[j] + vm2[k]
  84. if !compareAB[key] {
  85. compareAB2D[key] = true
  86. //fmt.Println(key)
  87. }
  88. }
  89. }
  90. }
  91. for i := 0; i < 2; i++ {
  92. for j := 0; j < 3; j++ {
  93. for k := 0; k < 2; k++ {
  94. key := vm[i] + vm2[j] + vm[k]
  95. if !compareAB[key] {
  96. compareAB2D[key] = true
  97. //fmt.Println(key)
  98. }
  99. }
  100. }
  101. }
  102. //fmt.Println("-------------------", len(compareAB2D))
  103. //---至少一个一致,其他可能不存在
  104. //[ABD][ABD][ABD] //已经删除DDD
  105. vm = []string{"A", "B", "D"}
  106. for i := 0; i < 3; i++ {
  107. for j := 0; j < 3; j++ {
  108. for k := 0; k < 3; k++ {
  109. key := vm[i] + vm[j] + vm[k]
  110. if !compareAB[key] && !compareAB2D[key] && !compareNoPass[key] {
  111. compareABD[key] = true
  112. //fmt.Println(key)
  113. }
  114. }
  115. }
  116. }
  117. //fmt.Println("-------------------", len(compareABD))
  118. //[AB][ABCD][AB]
  119. //[AB][AB][ABCD]
  120. vm = []string{"A", "B"}
  121. vm2 = []string{"A", "B", "C", "D"}
  122. for i := 0; i < 2; i++ {
  123. for j := 0; j < 4; j++ {
  124. for k := 0; k < 2; k++ {
  125. key := vm[i] + vm2[j] + vm[k]
  126. if !compareAB[key] && !compareAB2D[key] && !compareNoPass[key] && !compareABD[key] {
  127. compareAB2CD[key] = true
  128. //fmt.Println(key)
  129. }
  130. }
  131. }
  132. }
  133. for i := 0; i < 2; i++ {
  134. for j := 0; j < 2; j++ {
  135. for k := 0; k < 4; k++ {
  136. key := vm[i] + vm[j] + vm2[k]
  137. if !compareAB[key] && !compareAB2D[key] && !compareNoPass[key] && !compareABD[key] {
  138. compareAB2CD[key] = true
  139. //fmt.Println(key)
  140. }
  141. }
  142. }
  143. }
  144. //fmt.Println("-------------------", len(compareAB2CD))
  145. //[ABECD][ABECD][ABECD] //已经删除[CD][CD][CD] //这个要重点讨论
  146. vm = []string{"A", "B", "C", "D"}
  147. for i := 0; i < 4; i++ {
  148. for j := 0; j < 4; j++ {
  149. for k := 0; k < 4; k++ {
  150. key := vm[i] + vm[j] + vm[k]
  151. if !compareAB[key] && !compareAB2D[key] && !compareABD[key] && !compareNoPass[key] && !compareAB2CD[key] {
  152. compareABCD[key] = true
  153. //fmt.Println(key)
  154. }
  155. }
  156. }
  157. }
  158. }
  159. func InitMysql() {
  160. dbcfg := config.Conf.DB.Mysql
  161. MysqlTool = &mysqldb.Mysql{
  162. Address: dbcfg.Addr,
  163. DBName: dbcfg.Dbname,
  164. UserName: dbcfg.User,
  165. PassWord: dbcfg.Password,
  166. }
  167. MysqlTool.Init()
  168. MysqlEnt = &mysqldb.Mysql{
  169. Address: config.Conf.DB.Ent.Addr,
  170. DBName: config.Conf.DB.Ent.Dbname,
  171. UserName: config.Conf.DB.Ent.User,
  172. PassWord: config.Conf.DB.Ent.Password,
  173. }
  174. MysqlEnt.Init()
  175. }
  176. func InitLog() {
  177. logcfg := config.Conf.Log
  178. err := log.InitLog(
  179. log.Path(logcfg.LogPath),
  180. log.Level(logcfg.LogLevel),
  181. log.Compress(logcfg.Compress),
  182. log.MaxSize(logcfg.MaxSize),
  183. log.MaxBackups(logcfg.MaxBackups),
  184. log.MaxAge(logcfg.MaxAge),
  185. log.Format(logcfg.Format),
  186. )
  187. if err != nil {
  188. fmt.Printf("InitLog failed: %v\n", err)
  189. os.Exit(1)
  190. }
  191. }
  192. type Project struct {
  193. Id int64 `json:"msg_id"`
  194. EntId int64 `json:"ent_id"`
  195. ProjectId string `json:"projectId"`
  196. FirstTime string `json:"firsttime,omitempty"` //项目的最早时间
  197. LastTime string `json:"lasttime,omitempty"` //项目的最后时间
  198. ProjectName string `json:"projectname,omitempty"` //项目名称
  199. ProjectCode string `json:"projectcode,omitempty"` //项目代码
  200. Buyer string `json:"buyer,omitempty"` //采购单位
  201. Agency string `json:"agency"` //代理机构
  202. //Winners string `json:"s_winner,omitempty"` //中标人
  203. Area string `json:"area"` //地区
  204. City string `json:"city"` //地市
  205. District string `json:"district"` //区县
  206. Bidamount float64 `json:"bidamount,omitempty"` //中标金额
  207. Budget float64 `json:"budget,omitempty"` //预算
  208. Bidtype string `json:"bidtype"`
  209. Bidstatus string `json:"bidstatus"`
  210. score int
  211. comStr string
  212. resVal, pjVal int
  213. Topscopeclass []string `json:"topscopeclass,omitempty"`
  214. Subscopeclass []string `json:"subscopeclass,omitempty"` //子行业分类
  215. Buyerperson string `json:"buyerperson"` //采购联系人
  216. Buyertel string `json:"buyertel"` //采购联系人电话
  217. AgencyPerson string `json:"agencyperson"`
  218. AgencyTel string `json:"agencytel"`
  219. //WinnerPerson string `json:"winnerperson"`
  220. //WinnerTel string `json:"winnertel"`
  221. Buyerclass string `json:"buyerclass"` //采购单位分类
  222. Bidopentime int64 `json:"bidopentime,omitempty"` //开标时间
  223. Jgtime int64 `json:"jgtime"` //结果中标时间
  224. Zbtime int64 `json:"zbtime"` //招标时间
  225. Industry string `json:"industry"`
  226. Region string `json:"region"`
  227. WinnerTag string `json:"winner_tag"`
  228. TagName string `json:"tagname"` //招标单位一级标签
  229. TagName2 string `json:"tagname2"` //招标单位二级行业
  230. TagName3 string `json:"tagname3"` //中标单位行业归类
  231. }
  232. type Info struct {
  233. Id int64 `json:"id"`
  234. EntId int64 `json:"eid"`
  235. RuleName string `json:"rulename"`
  236. TagName string `json:"tagname"`
  237. TagName2 string `json:"tagname2"`
  238. TagName3 string `json:"tagname3"`
  239. Href string `json:"href"` //源地址
  240. JybxHref string `json:"jybxhref"`
  241. Publishtime string `json:"publishtime"`
  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. Buyer string `json:"buyer"`
  248. Buyerperson string `json:"buyerperson"`
  249. Buyertel string `json:"buyertel"`
  250. WinnerTel string `json:"winnertel"`
  251. WinnerPerson string `json:"winnerperson"`
  252. Agency string `json:"agency"`
  253. AgencyPerson string `json:"agencyperson"`
  254. AgencyTel string `json:"agencytel"`
  255. Area string `json:"area"`
  256. City string `json:"city"`
  257. District string `json:"district"`
  258. Buyerclass string `json:"buyerclass"`
  259. Budget float64 `json:"budget"`
  260. Bidamount float64 `json:"bidamount"`
  261. Region string `json:"region"`
  262. Industry string `json:"industry"`
  263. WinnerTag string `json:"winner_tag"`
  264. Winners []string
  265. pnbval int //项目名称、编号、采购单位存在的个数
  266. LenPC int //项目编号长度
  267. LenPN int //项目名称长度
  268. LenPTC int //标题抽的项目编号长度
  269. }