project.go 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math"
  6. "sort"
  7. "strings"
  8. "time"
  9. "go.mongodb.org/mongo-driver/bson"
  10. "go.mongodb.org/mongo-driver/bson/primitive"
  11. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  12. "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
  13. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  14. "jygit.jydev.jianyu360.cn/data_processing/common_utils/redis"
  15. )
  16. /**
  17. 项目合并,对比,计算,合并,生成项目
  18. **/
  19. // 从对应map中获取对比的项目id
  20. func (p *ProjectTask) getCompareIds(pn, pc, ptc, pb string) (bpn, bpc, bptc, bpb int, res []*Key, idArr []string, IDArr []*ID) {
  21. // p.ConCurrentLock(n1, n2, n3, n4)
  22. // defer p.ConCurrentUnLock(n1, n2, n3, n4)
  23. p.wg.Add(1)
  24. //查找到id数组
  25. res = []*Key{}
  26. //是否查找到,并标识位置。-1代表值为空或已经存在。
  27. bpn, bpc, bptc, bpb = -1, -1, -1, -1
  28. if pn != "" {
  29. ids := p.mapPn[pn]
  30. if ids == nil {
  31. ids = &Key{Arr: []string{}}
  32. p.mapPn[pn] = ids
  33. bpn = 0
  34. }
  35. ids.Lock.Lock()
  36. res = append(res, ids)
  37. }
  38. if pc != "" {
  39. ids := p.mapPc[pc]
  40. if ids == nil {
  41. ids = &Key{Arr: []string{}}
  42. p.mapPc[pc] = ids
  43. bpc = len(res)
  44. }
  45. ids.Lock.Lock()
  46. res = append(res, ids)
  47. }
  48. if ptc != "" {
  49. ids := p.mapPc[ptc]
  50. if ids == nil {
  51. ids = &Key{Arr: []string{}}
  52. p.mapPc[ptc] = ids
  53. bptc = len(res)
  54. }
  55. ids.Lock.Lock()
  56. res = append(res, ids)
  57. }
  58. if pb != "" {
  59. ids := p.mapPb[pb]
  60. if ids == nil {
  61. ids = &Key{Arr: []string{}}
  62. p.mapPb[pb] = ids
  63. bpb = len(res)
  64. }
  65. ids.Lock.Lock()
  66. res = append(res, ids)
  67. }
  68. repeatId := map[string]bool{}
  69. idArr = []string{} //项目id
  70. IDArr = []*ID{} //项目信息
  71. for _, m := range res {
  72. for _, id := range m.Arr {
  73. if !repeatId[id] {
  74. repeatId[id] = true
  75. //_, _ = strconv.ParseInt(id[0:8], 16, 64)
  76. p.AllIdsMapLock.Lock()
  77. Id := p.AllIdsMap[id]
  78. p.AllIdsMapLock.Unlock()
  79. if Id != nil {
  80. Id.Lock.Lock()
  81. idArr = append(idArr, id)
  82. IDArr = append(IDArr, Id)
  83. }
  84. }
  85. }
  86. }
  87. return
  88. }
  89. func (p *ProjectTask) startProjectMerge(info *Info, tmp map[string]interface{}) {
  90. p.findLock.Lock()
  91. defer p.findLock.Unlock()
  92. // 3.18 isfow=0数据不参与项目合并 (1表示正常数据招标流程)
  93. code := strings.ReplaceAll(util.ObjToString(tmp["spidercode"]), " ", "")
  94. p.mapSpiderLock.Lock()
  95. defer p.mapSpiderLock.Unlock()
  96. if v, ok := p.mapSpider[code]; ok && (v == 0) {
  97. //qu.Debug("isflow=0 新建项目" + code)
  98. p.NewProject(tmp, info)
  99. return
  100. }
  101. //只有或没有采购单位的无法合并
  102. //bpn, bpc, bptc, bpb 是否查找到,并标识位置。-1代表未查找到。
  103. //pids 是项目id数组集合
  104. //IDArr,是单个项目ID对象集合
  105. bpn, bpc, bptc, bpb, pids, _, IDArr := p.getCompareIds(info.ProjectName, info.ProjectCode, info.PTC, info.Buyer) //, info.LenPN, info.LenPC, info.LenPTC, len([]rune(info.Buyer)))
  106. defer p.wg.Done()
  107. //map--k为pn,ptn,pc,ptc,buyer值 v为Id数组和lock
  108. for _, m := range pids {
  109. defer m.Lock.Unlock()
  110. }
  111. for _, id := range IDArr {
  112. defer id.Lock.Unlock()
  113. }
  114. bFindProject := false
  115. findPid := ""
  116. //获取完id,进行计算
  117. //定义两组
  118. comRes1 := []*ProjectCache{} //优先级最高的对比结果数组
  119. comRes2 := []*ProjectCache{} //优化级其次
  120. comRes3 := []*ProjectCache{}
  121. for _, v := range IDArr {
  122. comStr := ""
  123. compareProject := v.P
  124. compareProject.score = 0
  125. //问题出地LastTime!!!!!
  126. diffTime := int64(math.Abs(float64(info.Publishtime - compareProject.LastTime)))
  127. if diffTime <= p.validTime {
  128. //代理机构完全不相同,直接新建项目...................
  129. if CheckContain(compareProject.Agency, info.Agency) == 3 {
  130. continue
  131. }
  132. //地区(省、市、区)不同,直接新建项目
  133. if ComparePlace(compareProject, info) {
  134. continue
  135. }
  136. info.PNBH = 0
  137. info.PCBH = 0
  138. info.PTCBH = 0
  139. compareStr, score := comparePNC(info, compareProject)
  140. resVal, pjVal := Select(compareStr, info, compareProject)
  141. //---------------------------------------
  142. if resVal > 0 {
  143. compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount, score2 := p.compareBCTABB(info, compareProject, diffTime, score)
  144. //项目名称、项目编号、标题项目编号、采购单位、省、市、发布时间、代理机构
  145. comStr = compareStr + compareBuyer + compareCity + compareTime + compareAgency + compareBudget + compareBidmount
  146. compareProject.comStr = comStr
  147. compareProject.pjVal = pjVal
  148. compareProject.resVal = resVal
  149. // fmt.Println(compareProject.comStr)
  150. eqV := compareResult(resVal, pjVal, score2, comStr, compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount)
  151. if eqV == 1 {
  152. comRes1 = append(comRes1, compareProject)
  153. } else if eqV == 2 {
  154. comRes2 = append(comRes2, compareProject)
  155. } else if eqV == 3 {
  156. comRes3 = append(comRes3, compareProject)
  157. }
  158. }
  159. }
  160. }
  161. //--------------------------------对比完成-----------------------
  162. //更新数组、更新项目
  163. for kv, resN := range [][]*ProjectCache{comRes1, comRes2, comRes3} {
  164. if len(resN) > 0 {
  165. if len(resN) > 1 {
  166. sort.Slice(resN, func(i, j int) bool {
  167. return resN[i].score > resN[j].score
  168. })
  169. }
  170. ex := 0
  171. resArr := []*ProjectCache{}
  172. for _, res := range resN {
  173. //choose, e := p.CompareStatus(resN[i], info)
  174. //if !choose {
  175. // ex = e
  176. resArr = append(resArr, res)
  177. //}
  178. }
  179. if len(resArr) > 0 {
  180. bFindProject = true
  181. findPid = resArr[0].Id.Hex()
  182. p.UpdateProject(tmp, info, resArr[0], kv+1, resArr[0].comStr, ex)
  183. for k2, bv := range []int{bpn, bpc, bptc, bpb} {
  184. if bv > -1 {
  185. pids[bv].Arr = append(pids[bv].Arr, findPid)
  186. if k2 == 0 {
  187. if resArr[0].ProjectName == "" {
  188. resArr[0].ProjectName = info.ProjectName
  189. } else {
  190. if resArr[0].MPN == nil {
  191. resArr[0].MPN = []string{info.ProjectName}
  192. } else {
  193. resArr[0].MPN = append(resArr[0].MPN, info.ProjectName)
  194. }
  195. }
  196. } else if k2 < 3 {
  197. if resArr[0].ProjectCode == "" {
  198. resArr[0].ProjectCode = util.If(k2 == 1, info.ProjectCode, info.PTC).(string)
  199. } else {
  200. if resArr[0].MPC == nil {
  201. resArr[0].MPC = []string{util.If(k2 == 1, info.ProjectCode, info.PTC).(string)}
  202. } else {
  203. resArr[0].MPC = append(resArr[0].MPC, util.If(k2 == 1, info.ProjectCode, info.PTC).(string))
  204. }
  205. }
  206. } else {
  207. if resArr[0].Buyer == "" {
  208. resArr[0].Buyer = info.Buyer
  209. }
  210. }
  211. }
  212. }
  213. } else {
  214. bFindProject = false
  215. findPid = ""
  216. }
  217. break
  218. }
  219. }
  220. if !bFindProject {
  221. //if !IsCreatePro(info) {
  222. // qu.Debug("舍弃数据---", info.Id)
  223. // return
  224. //}
  225. id, p1 := p.NewProject(tmp, info)
  226. p.AllIdsMapLock.Lock()
  227. p.AllIdsMap[id] = &ID{Id: id, P: p1}
  228. p.AllIdsMapLock.Unlock()
  229. for _, m := range pids {
  230. m.Arr = append(m.Arr, id)
  231. }
  232. }
  233. }
  234. func (p *ProjectTask) compareBCTABB(info *Info, cp *ProjectCache, diffTime int64, score int) (compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount string, score2 int) {
  235. compareBuyer = "D"
  236. if len([]rune(info.Buyer)) > 3 && len([]rune(cp.Buyer)) > 3 {
  237. v := CheckContain(info.Buyer, cp.Buyer)
  238. if v == 1 {
  239. compareBuyer = "A"
  240. score += 3
  241. } else {
  242. //v1 := CosineSimilar(info.Buyer, cp.Buyer)
  243. if v == 2 {
  244. compareBuyer = "B"
  245. score += 1
  246. } else {
  247. compareBuyer = "C"
  248. }
  249. }
  250. }
  251. //---------------------------------------
  252. compareCity = ""
  253. if info.Area != "全国" && info.Area != "" && info.Area == cp.Area {
  254. compareCity += "A"
  255. score += 2
  256. } else if info.Area == "全国" || cp.Area == "全国" {
  257. compareCity += "B"
  258. score += 1
  259. } else {
  260. compareCity += "C"
  261. }
  262. if compareCity != "C" {
  263. if info.City != "" && info.City == cp.City {
  264. compareCity += "A"
  265. score += 2
  266. } else {
  267. if info.Area == "全国" || cp.Area == "全国" {
  268. compareCity += "B"
  269. } else if info.City == compareCity {
  270. compareCity += "B"
  271. } else {
  272. compareCity += "C"
  273. }
  274. }
  275. } else {
  276. compareCity += "C"
  277. }
  278. score2 = 0
  279. if compareCity == "AA" {
  280. score2 = 1
  281. //if info.District != "" && info.District == cp.District {
  282. // score2 = 1
  283. //}
  284. }
  285. compareTime = "D"
  286. if diffTime < 45*86400 {
  287. compareTime = "A"
  288. score += 2
  289. } else if diffTime < 90*86400 {
  290. compareTime = "B"
  291. score += 1
  292. }
  293. compareAgency = "D"
  294. if info.Agency != "" {
  295. if info.Agency == cp.Agency {
  296. compareAgency = "A"
  297. score += 2
  298. score2 += 1
  299. } else if cp.Agency != "" {
  300. if strings.Contains(info.Agency, cp.Agency) || strings.Contains(cp.Agency, info.Agency) {
  301. compareAgency = "B"
  302. score += 1
  303. score2 += 1
  304. } else {
  305. compareAgency = "C"
  306. }
  307. }
  308. }
  309. compareBudget = "C"
  310. if info.Budget > 0 && (info.Budget == cp.Budget || (cp.Bidamount > 0 && info.Budget > cp.Bidamount && (info.Budget-cp.Bidamount) < (0.15*info.Budget))) {
  311. compareBudget = "A"
  312. score += 1
  313. score2 += 1
  314. }
  315. // else if info.Budget == 0 && cp.Budget == 0 {
  316. // compareBudget = "B"
  317. // }
  318. compareBidmount = "C"
  319. if info.Bidamount > 0 && (info.Bidamount == cp.Bidamount || (cp.Budget > 0 && cp.Budget > info.Bidamount && (cp.Budget-info.Bidamount) < 0.15*cp.Budget)) {
  320. compareBidmount = "A"
  321. score += 1
  322. score2 += 1
  323. }
  324. // else if info.Bidamount == 0 && cp.Bidamount == 0 {
  325. // compareBidmount = "B"
  326. // }
  327. cp.score = score
  328. return
  329. }
  330. func compareResult(resVal, pjVal, score2 int, comStr, compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount string) int {
  331. eqV := 0
  332. switch resVal {
  333. case 3:
  334. if pjVal == 3 && comStr[3:] != "CCCDCCC" {
  335. eqV = 1
  336. } else if compareBuyer < "C" {
  337. if pjVal > 1 {
  338. eqV = 1
  339. } else { //if (compareCity[1:1] != "C" || compareTime != "D") && score2 > 0
  340. eqV = 2
  341. }
  342. } else if compareBuyer == "D" {
  343. if pjVal > 1 && (compareCity[1:1] != "C" || score2 > 0) {
  344. eqV = 2
  345. } else if compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  346. eqV = 3
  347. }
  348. } else {
  349. if pjVal == 3 && (score2 > 0 || compareCity[1:1] != "C") {
  350. eqV = 2
  351. } else if pjVal == 2 && compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  352. eqV = 3
  353. } else if compareCity == "AA" && compareTime == "A" && score2 > 0 {
  354. eqV = 3
  355. }
  356. }
  357. case 2:
  358. if compareBuyer < "C" {
  359. if pjVal > 1 {
  360. eqV = 2
  361. } else if compareCity[1:1] != "C" && compareTime == "A" || score2 > 0 {
  362. eqV = 3
  363. }
  364. } else if compareBuyer == "D" {
  365. if pjVal > 1 && (score2 > 0 || compareCity[1:1] != "C") {
  366. eqV = 2
  367. } else if compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  368. eqV = 3
  369. }
  370. } else {
  371. if pjVal > 1 && compareTime == "A" && (score2 > 0 || compareCity[1:1] != "C") {
  372. eqV = 2
  373. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  374. eqV = 3
  375. }
  376. }
  377. case 1:
  378. if compareBuyer < "C" {
  379. if pjVal > 1 && (score2 > 0 || compareCity[1:1] != "C") {
  380. eqV = 2
  381. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  382. eqV = 3
  383. }
  384. } else if compareBuyer == "D" {
  385. if pjVal > 1 && compareTime == "A" && (score2 > 0 || compareCity[1:1] != "C") {
  386. eqV = 2
  387. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  388. eqV = 3
  389. }
  390. } else {
  391. if pjVal > 1 && compareTime == "A" && score2 > 0 && (compareBudget == "A" || compareBidmount == "A") && compareCity[1:1] != "C" {
  392. eqV = 3
  393. }
  394. }
  395. }
  396. return eqV
  397. }
  398. func (p *ProjectTask) NewProject(tmp map[string]interface{}, thisinfo *Info) (string, *ProjectCache) {
  399. //pId := primitive.NewObjectID() //NewObjectId()
  400. pId := mongodb.StringTOBsonId(thisinfo.Id)
  401. set := map[string]interface{}{}
  402. set["_id"] = pId
  403. for _, f := range FIELDS {
  404. if tmp[f] != nil && tmp[f] != "" {
  405. set[f] = tmp[f]
  406. }
  407. }
  408. bidopentime := util.Int64All(tmp["bidopentime"])
  409. if bidopentime > 0 {
  410. set["bidopentime"] = bidopentime
  411. }
  412. bidendtime := util.Int64All(tmp["bidendtime"])
  413. if bidendtime > 0 {
  414. set["bidendtime"] = bidendtime
  415. }
  416. //异常标记
  417. if thisinfo.TopType != "招标" && thisinfo.TopType != "拟建" && thisinfo.TopType != "预告" {
  418. set["exception"] = 1
  419. }
  420. //projecthref保存
  421. if jsonData, ok := tmp["jsondata"].(map[string]interface{}); ok {
  422. if jsonData != nil && util.ObjToString(jsonData["projecthref"]) != "" {
  423. set["projecthref"] = jsonData["projecthref"]
  424. }
  425. }
  426. //合同编号
  427. if thisinfo.ContractCode != "" {
  428. set["contractcode"] = thisinfo.ContractCode
  429. }
  430. bt := util.ObjToString(tmp["toptype"])
  431. bs := util.ObjToString(tmp["subtype"])
  432. p.mapBidLock.Lock()
  433. if thisinfo.Infoformat == 2 || thisinfo.SubType == "拟建" {
  434. set["bidstatus"] = "拟建"
  435. bt = "拟建"
  436. } else {
  437. if bidtype[bs] != "" {
  438. set["bidtype"] = bidtype[bs]
  439. } else {
  440. set["bidtype"] = "招标"
  441. }
  442. if bt == "招标" {
  443. set["projectscope"] = util.ObjToString(tmp["projectscope"])
  444. set["bidstatus"] = bt
  445. } else {
  446. if bidstatus[bs] != "" {
  447. set["bidstatus"] = thisinfo.SubType
  448. bt = thisinfo.SubType
  449. } else if bs == "" {
  450. set["bidstatus"] = ""
  451. bt = ""
  452. } else {
  453. set["bidstatus"] = "其它"
  454. bt = "其它"
  455. }
  456. }
  457. }
  458. p.mapBidLock.Unlock()
  459. pkg := PackageFormat(thisinfo, nil)
  460. p1 := p.NewCachePinfo(pId, thisinfo, bs, bt)
  461. now := time.Now().Unix()
  462. set["createtime"] = now
  463. set["sourceinfoid"] = thisinfo.Id
  464. set["sourceinfourl"] = tmp["href"]
  465. set["firsttime"] = tmp["publishtime"]
  466. set["lasttime"] = tmp["publishtime"]
  467. //增量用系统时间,全量(历史)入库时间
  468. if p.currentType == "pl" {
  469. set["pici"] = tmp["comeintime"]
  470. } else {
  471. set["pici"] = p.pici
  472. }
  473. set["ids"] = []string{thisinfo.Id}
  474. if thisinfo.TopType == "招标" {
  475. //if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
  476. set["zbtime"] = tmp["publishtime"]
  477. //}
  478. } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
  479. set["jgtime"] = tmp["publishtime"]
  480. set["jgtime_first"] = tmp["publishtime"]
  481. }
  482. if len(thisinfo.Subscopeclass) > 0 {
  483. set["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
  484. }
  485. if len(thisinfo.Winners) > 0 {
  486. set["s_winner"] = strings.Join(thisinfo.Winners, ",")
  487. }
  488. if thisinfo.HasPackage {
  489. set["multipackage"] = 1
  490. set["package"] = pkg
  491. } else {
  492. set["multipackage"] = 0
  493. }
  494. //项目评审专家
  495. if thisinfo.ReviewExperts != "" {
  496. set["review_experts"] = thisinfo.ReviewExperts
  497. }
  498. //标的物
  499. if thisinfo.Purchasing != "" {
  500. list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
  501. p := strings.Join(util.ObjArrToStringArr(list), ",")
  502. set["purchasing"] = p
  503. }
  504. //中标候选人
  505. if len(thisinfo.WinnerOrder) > 0 {
  506. var list = []string{}
  507. for _, v := range thisinfo.WinnerOrder {
  508. if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
  509. list = append(list, util.ObjToString(v["entname"]))
  510. }
  511. }
  512. set["winnerorder"] = list
  513. }
  514. //项目规模
  515. if len(thisinfo.ProjectScale) > 0 {
  516. set["project_scale"] = thisinfo.ProjectScale
  517. }
  518. //工期时长
  519. if thisinfo.ProjectDuration > 0 {
  520. set["project_duration"] = thisinfo.ProjectDuration
  521. }
  522. // 工期单位
  523. if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
  524. set["project_timeunit"] = thisinfo.ProjectTimeUnit
  525. }
  526. //开工日期
  527. if thisinfo.ProjectStartDate > 0 {
  528. set["project_startdate"] = thisinfo.ProjectStartDate
  529. }
  530. //竣工日期
  531. if thisinfo.ProjectCompleteDate > 0 {
  532. set["project_completedate"] = thisinfo.ProjectCompleteDate
  533. }
  534. //付款方式
  535. if len(thisinfo.Payway) > 0 {
  536. set["payway"] = thisinfo.Payway
  537. }
  538. // 履约保证金
  539. if tmp["contract_guarantee"] != nil {
  540. set["contract_guarantee"] = thisinfo.ContractGuarantee
  541. }
  542. // 投标保证金
  543. if tmp["bid_guarantee"] != nil {
  544. set["bid_guarantee"] = thisinfo.BidGuarantee
  545. }
  546. // 资质条件
  547. if len(thisinfo.Qualifies) > 0 {
  548. var str []string
  549. for _, v := range thisinfo.Qualifies {
  550. if len(util.ObjToString(v["key"])) > 0 {
  551. if BinarySearch(str, util.ObjToString(v["key"])) == -1 {
  552. str = append(str, util.ObjToString(v["key"]))
  553. }
  554. }
  555. }
  556. if len(str) > 0 {
  557. set["qualifies"] = strings.Join(str, ",")
  558. }
  559. }
  560. if len(thisinfo.EntIdList) > 0 {
  561. set["entidlist"] = thisinfo.EntIdList
  562. }
  563. // first_cooperation
  564. if p1.Buyer != "" && len(thisinfo.Winners) > 0 {
  565. FirstCooperation(set, p1.Buyer, thisinfo.Winners, thisinfo.EntIdList)
  566. }
  567. //infofield := InfoField{
  568. // Budget: thisinfo.Budget,
  569. // Bidamount: thisinfo.Bidamount,
  570. // ContractCode: thisinfo.ContractCode,
  571. // ProjectName: thisinfo.ProjectName,
  572. // ProjectCode: thisinfo.ProjectCode,
  573. // Bidstatus: bs,
  574. //}
  575. //res := StructToMap(infofield)
  576. //set["infofield"] = map[string]interface{}{
  577. // thisinfo.Id: res,
  578. //}
  579. //if tmp["budget"] != nil && tmp["budget"] != "" {
  580. // set["budget"] = thisinfo.Budget
  581. // set["budgettag"] = 0
  582. //} else {
  583. // set["budgettag"] = 1
  584. //}
  585. //if tmp["bidamount"] != nil && tmp["bidamount"] != "" {
  586. // set["bidamount"] = thisinfo.Bidamount
  587. // set["bidamounttag"] = 0
  588. //} else {
  589. // set["bidamounttag"] = 1
  590. //}
  591. if thisinfo.Budget > 0 {
  592. set["budget"] = thisinfo.Budget
  593. }
  594. if thisinfo.Bidamount > 0 {
  595. set["bidamount"] = thisinfo.Bidamount
  596. }
  597. if p1.Bidamount > 0 {
  598. set["sortprice"] = p1.Bidamount
  599. } else {
  600. if p1.Budget > 0 {
  601. set["sortprice"] = p1.Budget
  602. }
  603. }
  604. if tmp["bid_field"] != nil {
  605. set["bid_field"] = tmp["bid_field"]
  606. }
  607. redis.PutCKV(RedisProject, fmt.Sprintf(P_KEY, thisinfo.Id), set)
  608. set["size"] = 1
  609. push := p.PushListInfo(tmp, thisinfo.Id)
  610. if len(thisinfo.Winners) > 0 {
  611. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  612. }
  613. set["list"] = []bson.M{
  614. push,
  615. }
  616. p.updatePool <- []map[string]interface{}{
  617. {
  618. "_id": pId,
  619. },
  620. {
  621. "$set": set,
  622. },
  623. }
  624. return pId.Hex(), &p1
  625. }
  626. // 项目中list的信息
  627. func (p *ProjectTask) PushListInfo(tmp map[string]interface{}, infoid string) bson.M {
  628. res := bson.M{
  629. "infoid": infoid,
  630. }
  631. for _, k := range INFOFIELDS {
  632. if tmp[k] != nil {
  633. res[k] = tmp[k]
  634. }
  635. }
  636. return res
  637. }
  638. // 生成存放在内存中的对象
  639. func (p *ProjectTask) NewCachePinfo(id primitive.ObjectID, thisinfo *Info, bidtype, bidstatus string) ProjectCache {
  640. p1 := ProjectCache{
  641. Id: id,
  642. Ids: []string{thisinfo.Id},
  643. ProjectName: thisinfo.ProjectName,
  644. ProjectCode: thisinfo.ProjectCode,
  645. Buyer: thisinfo.Buyer,
  646. Agency: thisinfo.Agency,
  647. Area: thisinfo.Area,
  648. City: thisinfo.City,
  649. District: thisinfo.District,
  650. MPN: []string{},
  651. MPC: []string{},
  652. FirstTime: thisinfo.Publishtime,
  653. LastTime: thisinfo.Publishtime,
  654. Budget: thisinfo.Budget,
  655. Bidamount: thisinfo.Bidamount,
  656. Bidstatus: bidstatus,
  657. Bidtype: bidtype,
  658. Size: 1,
  659. }
  660. if thisinfo.LenPTC > 5 {
  661. p1.MPC = append(p1.MPC, thisinfo.PTC)
  662. }
  663. return p1
  664. }
  665. // @Description 更新项目 全量合并
  666. // @update 中间表查询需要更新的项目信息
  667. // @Author J 2022/7/6 14:02
  668. func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info, pInfo *ProjectCache, weight int, comStr string, ex int) {
  669. if p.currentType != "updateInfo" {
  670. if BinarySearch(pInfo.Ids, thisinfo.Id) > -1 {
  671. log.Info("repeat" + thisinfo.Id + ",pid" + pInfo.Id.Hex())
  672. return
  673. }
  674. }
  675. pdata := redis.Get(RedisProject, fmt.Sprintf(P_KEY, pInfo.Id.Hex()))
  676. if pdata == nil {
  677. log.Info("redis err, not find project " + pInfo.Id.Hex())
  678. return
  679. }
  680. projectMap := pdata.(map[string]interface{})
  681. bys, _ := json.Marshal(projectMap)
  682. var project *Project
  683. err := json.Unmarshal(bys, &project)
  684. if err != nil {
  685. log.Info("project Unmarshal err," + err.Error() + ",pid: " + pInfo.Id.Hex())
  686. return
  687. }
  688. set := map[string]interface{}{}
  689. pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
  690. if len(pInfo.Ids) > 30 {
  691. //异常标记
  692. set["listtag"] = 1
  693. }
  694. //zbtime、lasttime、jgtime
  695. pInfo.LastTime = thisinfo.Publishtime
  696. set["lasttime"] = thisinfo.Publishtime
  697. if thisinfo.TopType == "招标" {
  698. if project.Zbtime <= 0 {
  699. project.Zbtime = thisinfo.Publishtime
  700. set["zbtime"] = tmp["publishtime"]
  701. }
  702. if project.Jgtime > 0 {
  703. project.Jgtime = int64(0)
  704. set["jgtime"] = int64(0)
  705. }
  706. } else if thisinfo.TopType == "结果" {
  707. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  708. if project.Jgtime > 0 {
  709. //jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
  710. //公告状态和项目状态同样都是中标或者成交,
  711. if thisinfo.SubType == "成交" && project.Bidstatus == "中标" {
  712. if p.jgTime < thisinfo.Publishtime {
  713. project.Jgtime = thisinfo.Publishtime
  714. set["jgtime"] = tmp["publishtime"]
  715. }
  716. //公告状态和项目状态同样是流标或者废标
  717. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (project.Bidstatus == "流标" || project.Bidstatus == "废标") {
  718. if p.jgTime < thisinfo.Publishtime {
  719. project.Jgtime = thisinfo.Publishtime
  720. set["jgtime"] = tmp["publishtime"]
  721. }
  722. }
  723. } else {
  724. project.Jgtime = thisinfo.Publishtime
  725. set["jgtime"] = tmp["publishtime"]
  726. project.JgtimeFirst = thisinfo.Publishtime
  727. set["jgtime_first"] = tmp["publishtime"]
  728. }
  729. }
  730. if thisinfo.SubType == "结果变更" {
  731. //project是项目 thisinfo是标讯 p是内存
  732. if thisinfo.Publishtime > 0 {
  733. //结果时间(jgtime)保存最早的结果时间,有结果更新的公告时再更新
  734. if project.JgtimeFirst < thisinfo.Publishtime {
  735. set["jgtime_first"] = tmp["publishtime"]
  736. project.JgtimeFirst = thisinfo.Publishtime
  737. }
  738. } else {
  739. set["jgtime_first"] = tmp["publishtime"]
  740. project.JgtimeFirst = thisinfo.Publishtime
  741. }
  742. }
  743. } else if thisinfo.SubType == "合同" {
  744. if project.Bidstatus == "中标" || project.Bidstatus == "成交" || project.Bidstatus == "" {
  745. //中标、成交不更新jgtime
  746. } else {
  747. project.Jgtime = thisinfo.Publishtime
  748. set["jgtime"] = tmp["publishtime"]
  749. }
  750. }
  751. if thisinfo.BidOpenTime > project.BidOpenTime {
  752. project.BidOpenTime = thisinfo.BidOpenTime
  753. set["bidopentime"] = project.BidOpenTime
  754. }
  755. if thisinfo.BidEndTime > 0 {
  756. project.BidEndTime = thisinfo.BidEndTime
  757. set["bidendtime"] = project.BidEndTime
  758. }
  759. bt := util.ObjToString(tmp["toptype"])
  760. bs := util.ObjToString(tmp["subtype"])
  761. p.mapBidLock.Lock()
  762. if bt == "招标" {
  763. //招标状态,更新projectscope
  764. if tmp["projectscope"] != nil {
  765. set["projectscope"] = util.ObjToString(tmp["projectscope"])
  766. }
  767. set["bidstatus"] = bt
  768. project.Bidstatus = bt
  769. if bidtype[bs] != "" {
  770. set["bidtype"] = bidtype[bs]
  771. project.Bidtype = bidtype[bs]
  772. } else {
  773. set["bidtype"] = "招标"
  774. project.Bidtype = "招标"
  775. }
  776. } else {
  777. if bidstatus[bs] != "" {
  778. set["bidstatus"] = thisinfo.SubType
  779. project.Bidstatus = thisinfo.SubType
  780. } else if thisinfo.Infoformat == 2 {
  781. set["bidstatus"] = "拟建"
  782. project.Bidstatus = "拟建"
  783. } else if bs == "" && bt == "结果" {
  784. if project.Bidstatus == "招标" {
  785. set["bidstatus"] = ""
  786. project.Bidstatus = ""
  787. }
  788. } else {
  789. set["bidstatus"] = "其它"
  790. project.Bidstatus = "其它"
  791. }
  792. }
  793. p.mapBidLock.Unlock()
  794. //异常标记
  795. if ex > 0 {
  796. set["exception"] = ex
  797. }
  798. //3\4\5--省、市、县
  799. //if thisinfo.Area != "全国" {
  800. // if pInfo.Area == "全国" {
  801. // pInfo.Area = thisinfo.Area
  802. // set["area"] = thisinfo.Area
  803. // } else if pInfo.Area != thisinfo.Area {
  804. // //xt = false
  805. // }
  806. // if pInfo.City == "" && thisinfo.City != "" {
  807. // pInfo.City = thisinfo.City
  808. // set["city"] = thisinfo.City
  809. // } else if pInfo.City != thisinfo.City {
  810. // //xt = false
  811. // }
  812. // if thisinfo.District != "" && pInfo.District == "" {
  813. // pInfo.District = thisinfo.District
  814. // set["district"] = thisinfo.District
  815. // }
  816. //}
  817. //相同城市的公告才会合并到一起(全国列外)
  818. if thisinfo.Area != "全国" {
  819. pInfo.Area = thisinfo.Area
  820. project.Area = thisinfo.Area
  821. set["area"] = thisinfo.Area
  822. if thisinfo.City != "" {
  823. pInfo.City = thisinfo.City
  824. project.City = thisinfo.City
  825. set["city"] = thisinfo.City
  826. }
  827. if thisinfo.District != "" {
  828. pInfo.District = thisinfo.District
  829. project.District = thisinfo.District
  830. set["district"] = thisinfo.District
  831. }
  832. }
  833. //项目名称
  834. //if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  835. if pInfo.ProjectName == "" && thisinfo.ProjectName != "" {
  836. pInfo.ProjectName = thisinfo.ProjectName
  837. project.ProjectName = thisinfo.ProjectName
  838. set["projectname"] = thisinfo.ProjectName
  839. }
  840. //7--项目编号
  841. //if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  842. if pInfo.ProjectCode == "" && thisinfo.ProjectCode != "" {
  843. pInfo.ProjectCode = thisinfo.ProjectCode
  844. project.ProjectCode = thisinfo.ProjectCode
  845. set["projectcode"] = thisinfo.ProjectCode
  846. }
  847. //7--采购单位
  848. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  849. pInfo.Buyer = thisinfo.Buyer
  850. project.Buyer = thisinfo.Buyer
  851. set["buyer"] = thisinfo.Buyer
  852. project.Buyerclass = thisinfo.Buyerclass
  853. set["buyerclass"] = thisinfo.Buyerclass
  854. }
  855. if pInfo.Buyer == "" {
  856. project.Buyerclass = ""
  857. set["buyerclass"] = ""
  858. }
  859. //采购单位联系人
  860. if thisinfo.Buyerperson != "" {
  861. project.Buyerperson = thisinfo.Buyerperson
  862. set["buyerperson"] = thisinfo.Buyerperson
  863. } else {
  864. project.Buyerperson = ""
  865. set["buyerperson"] = ""
  866. }
  867. //采购单位電話
  868. if thisinfo.Buyertel != "" {
  869. project.Buyertel = thisinfo.Buyertel
  870. set["buyertel"] = project.Buyertel
  871. } else {
  872. project.Buyertel = ""
  873. set["buyertel"] = ""
  874. }
  875. if thisinfo.ContractCode != "" {
  876. if project.ContractCode == "" {
  877. set["contractcode"] = thisinfo.ContractCode
  878. } else {
  879. list := strings.Split(project.ContractCode, ",")
  880. if BinarySearch(list, thisinfo.ContractCode) == -1 {
  881. list = append(list, thisinfo.ContractCode)
  882. sort.Strings(list)
  883. }
  884. set["contractcode"] = strings.Join(list, ",")
  885. }
  886. }
  887. //8--代理机构
  888. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  889. pInfo.Agency = thisinfo.Agency
  890. project.Agency = thisinfo.Agency
  891. set["agency"] = thisinfo.Agency
  892. }
  893. if len(thisinfo.Topscopeclass) > 0 {
  894. sort.Strings(project.Topscopeclass)
  895. for _, k := range thisinfo.Topscopeclass {
  896. if BinarySearch(project.Topscopeclass, k) == -1 {
  897. project.Topscopeclass = append(project.Topscopeclass, k)
  898. sort.Strings(project.Topscopeclass)
  899. }
  900. }
  901. set["topscopeclass"] = project.Topscopeclass
  902. }
  903. //项目评审专家
  904. if thisinfo.ReviewExperts != "" {
  905. set["review_experts"] = thisinfo.ReviewExperts
  906. project.ReviewExperts = thisinfo.ReviewExperts
  907. }
  908. if thisinfo.Purchasing != "" {
  909. if project.Purchasing == "" {
  910. list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
  911. p := strings.Join(util.ObjArrToStringArr(list), ",")
  912. project.Purchasing = p
  913. set["purchasing"] = p
  914. } else {
  915. list := strings.Split(project.Purchasing, ",")
  916. list = util.ObjArrToStringArr(Duplicate(list))
  917. for _, k := range list {
  918. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  919. list = append(list, k)
  920. sort.Strings(list)
  921. }
  922. }
  923. set["purchasing"] = strings.Join(list, ",")
  924. }
  925. }
  926. //中标候选人
  927. if len(thisinfo.WinnerOrder) > 0 {
  928. var list = []string{}
  929. for _, v := range thisinfo.WinnerOrder {
  930. if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
  931. list = append(list, util.ObjToString(v["entname"]))
  932. }
  933. }
  934. set["winnerorder"] = list
  935. project.Winnerorder = list
  936. }
  937. if len(thisinfo.Subscopeclass) > 0 {
  938. sort.Strings(project.Subscopeclass)
  939. for _, k := range thisinfo.Subscopeclass {
  940. if BinarySearch(project.Subscopeclass, k) == -1 {
  941. project.Subscopeclass = append(project.Subscopeclass, k)
  942. sort.Strings(project.Subscopeclass)
  943. }
  944. }
  945. set["subscopeclass"] = project.Subscopeclass
  946. set["s_subscopeclass"] = strings.Join(project.Subscopeclass, ",")
  947. }
  948. if len(thisinfo.Winners) > 0 {
  949. var winners []string
  950. if project.Winners == "" {
  951. set["winner"] = util.ObjToString(tmp["winner"])
  952. for _, k := range thisinfo.Winners {
  953. if k == "" {
  954. continue
  955. }
  956. if BinarySearch(winners, k) == -1 {
  957. winners = append(winners, k)
  958. }
  959. }
  960. } else {
  961. winners = strings.Split(project.Winners, ",")
  962. for _, k := range thisinfo.Winners {
  963. if k == "" {
  964. continue
  965. }
  966. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  967. if BinarySearch(winners, k) != -1 {
  968. deleteSlice(winners, k, "")
  969. }
  970. } else {
  971. if BinarySearch(winners, k) == -1 {
  972. winners = append(winners, k)
  973. }
  974. }
  975. }
  976. }
  977. if len(winners) > 0 {
  978. set["s_winner"] = strings.Join(util.ObjArrToStringArr(Duplicate(winners)), ",")
  979. }
  980. }
  981. if len(thisinfo.EntIdList) > 0 {
  982. for _, v := range thisinfo.EntIdList {
  983. if BinarySearch(project.EntIdList, v) == -1 {
  984. project.EntIdList = append(project.EntIdList, v)
  985. }
  986. }
  987. set["entidlist"] = project.EntIdList
  988. }
  989. //first_cooperation
  990. if pInfo.Buyer != "" && len(strings.Split(project.Winners, ",")) > 0 {
  991. FirstCooperation(set, pInfo.Buyer, strings.Split(project.Winners, ","), project.EntIdList)
  992. }
  993. //项目规模
  994. if len(thisinfo.ProjectScale) > 0 {
  995. project.ProjectScale = thisinfo.ProjectScale
  996. set["project_scale"] = thisinfo.ProjectScale
  997. }
  998. //工期时长
  999. if thisinfo.ProjectDuration > 0 {
  1000. project.ProjectDuration = thisinfo.ProjectDuration
  1001. set["project_duration"] = thisinfo.ProjectDuration
  1002. }
  1003. // 工期单位
  1004. if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
  1005. project.ProjectTimeunit = thisinfo.ProjectTimeUnit
  1006. set["project_timeunit"] = thisinfo.ProjectTimeUnit
  1007. }
  1008. //开工日期
  1009. if thisinfo.ProjectStartDate > 0 {
  1010. if project.ProjectStartDate > 0 {
  1011. if project.ProjectStartDate < thisinfo.ProjectStartDate {
  1012. project.ProjectStartDate = thisinfo.ProjectStartDate
  1013. set["project_startdate"] = thisinfo.ProjectStartDate
  1014. }
  1015. } else {
  1016. project.ProjectStartDate = thisinfo.ProjectStartDate
  1017. set["project_startdate"] = thisinfo.ProjectStartDate
  1018. }
  1019. }
  1020. //竣工日期
  1021. if thisinfo.ProjectCompleteDate > 0 {
  1022. if project.ProjctCompleteDate > 0 {
  1023. if project.ProjctCompleteDate < thisinfo.ProjectCompleteDate {
  1024. project.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  1025. set["project_completedate"] = thisinfo.ProjectCompleteDate
  1026. }
  1027. } else {
  1028. project.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  1029. set["project_completedate"] = thisinfo.ProjectCompleteDate
  1030. }
  1031. }
  1032. // 付款方式
  1033. if len(thisinfo.Payway) > 0 {
  1034. project.Payway = thisinfo.Payway
  1035. set["payway"] = thisinfo.Payway
  1036. }
  1037. // 履约保证金
  1038. if tmp["contract_guarantee"] != nil {
  1039. project.ContractGuarantee = thisinfo.ContractGuarantee
  1040. set["contract_guarantee"] = thisinfo.ContractGuarantee
  1041. }
  1042. // 投标保证金
  1043. if tmp["bid_guarantee"] != nil {
  1044. project.BidGuarantee = thisinfo.BidGuarantee
  1045. set["bid_guarantee"] = thisinfo.BidGuarantee
  1046. }
  1047. // 资质条件
  1048. if len(thisinfo.Qualifies) > 0 {
  1049. var str []string
  1050. if len(project.Qualifies) > 0 {
  1051. str = append(str, strings.Split(project.Qualifies, ",")...)
  1052. }
  1053. for _, v := range thisinfo.Qualifies {
  1054. if len(util.ObjToString(v["key"])) > 0 {
  1055. if BinarySearch(str, util.ObjToString(v["key"])) == -1 {
  1056. str = append(str, util.ObjToString(v["key"]))
  1057. }
  1058. }
  1059. }
  1060. if len(str) > 0 {
  1061. project.Qualifies = strings.Join(str, ",")
  1062. set["qualifies"] = strings.Join(str, ",")
  1063. }
  1064. }
  1065. if thisinfo.HasPackage { //多包处理
  1066. set["multipackage"] = 1
  1067. pkg := PackageFormat(thisinfo, project)
  1068. project.Package = pkg
  1069. set["package"] = project.Package
  1070. }
  1071. //处理多包后,计算预算金额、中标金额
  1072. //CountAmount(project, thisinfo, tmp)
  1073. //if project.Budget >= 0 && project.Budgettag != 1 {
  1074. // pInfo.Budget = project.Budget
  1075. // set["budget"] = project.Budget
  1076. // set["budgettag"] = 0
  1077. //}
  1078. //if project.Bidamount >= 0 && project.Bidamounttag != 1 {
  1079. // pInfo.Bidamount = project.Bidamount
  1080. // set["bidamount"] = pInfo.Bidamount
  1081. // set["bidamounttag"] = 0
  1082. //}
  1083. if thisinfo.Budget > 0 {
  1084. pInfo.Budget = thisinfo.Budget
  1085. project.Budget = thisinfo.Budget
  1086. set["budget"] = thisinfo.Budget
  1087. }
  1088. if thisinfo.Bidamount > 0 {
  1089. pInfo.Bidamount = thisinfo.Bidamount
  1090. project.Bidamount = thisinfo.Bidamount
  1091. set["bidamount"] = thisinfo.Bidamount
  1092. }
  1093. if pInfo.Bidamount > 0 {
  1094. set["sortprice"] = pInfo.Bidamount
  1095. } else {
  1096. if pInfo.Budget > 0 {
  1097. set["sortprice"] = pInfo.Budget
  1098. }
  1099. }
  1100. if tmp["bid_field"] != nil {
  1101. set["bid_field"] = tmp["bid_field"]
  1102. }
  1103. //infofield := InfoField{
  1104. // Budget: thisinfo.Budget,
  1105. // Bidamount: thisinfo.Bidamount,
  1106. // ContractCode: thisinfo.ContractCode,
  1107. // ProjectName: thisinfo.ProjectName,
  1108. // ProjectCode: thisinfo.ProjectCode,
  1109. // Bidstatus: bs,
  1110. //}
  1111. //copyMap := util.DeepCopy(project.InfoFiled).(map[string]InfoField)
  1112. //copyMap[thisinfo.Id] = infofield
  1113. //tmpMap := make(map[string]interface{})
  1114. //for k, v := range copyMap {
  1115. // tmpMap[k] = StructToMap(v)
  1116. //}
  1117. //tmpMap[thisinfo.Id] = StructToMap(infofield)
  1118. //project.InfoFiled = copyMap
  1119. //set["infofield"] = tmpMap
  1120. set["mpn"] = pInfo.MPN
  1121. set["mpc"] = pInfo.MPC
  1122. pInfo.Size = pInfo.Size + 1
  1123. set["size"] = pInfo.Size
  1124. if p.currentType == "project" || p.currentType == "project_history" {
  1125. set["pici"] = p.pici
  1126. } else {
  1127. set["pici"] = tmp["comeintime"]
  1128. }
  1129. redis.PutCKV(RedisProject, fmt.Sprintf(P_KEY, project.Id.Hex()), set)
  1130. update := map[string]interface{}{}
  1131. if len(set) > 0 {
  1132. update["$set"] = set
  1133. }
  1134. push := p.PushListInfo(tmp, thisinfo.Id)
  1135. if len(thisinfo.Winners) > 0 {
  1136. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  1137. }
  1138. push["compareStr"] = comStr
  1139. push["resVal"] = pInfo.resVal
  1140. push["pjVal"] = pInfo.pjVal
  1141. update["$push"] = map[string]interface{}{
  1142. "list": push,
  1143. "ids": thisinfo.Id,
  1144. }
  1145. //clearMap := map[string]interface{}{}
  1146. //ClearData(clearMap, set)
  1147. //if len(clearMap) > 0 {
  1148. // update["$unset"] = clearMap
  1149. //}
  1150. if len(update) > 0 {
  1151. updateInfo := []map[string]interface{}{
  1152. {
  1153. "_id": pInfo.Id,
  1154. },
  1155. update,
  1156. }
  1157. p.updatePool <- updateInfo
  1158. }
  1159. }
  1160. /**
  1161. * 更新项目时,项目状态的处理
  1162. * 返回是否新增项目,异常标记
  1163. * 1、新增项目时,招标信息的状态(toptype)不是招标、拟建、预告 异常:1
  1164. * 异常1是在项目新建的时候才会产生
  1165. * 3、项目合并时,项目状态是”流标“/”废标“,招标信息状态不是”招标“ 异常:2
  1166. * 4、项目合并时,项目状态是”合同“/”其它“,招标信息类型是”结果“ 异常:3
  1167. */
  1168. func (p *ProjectTask) CompareStatus(project *ProjectCache, info *Info) (bool, int) {
  1169. if info.TopType == "拟建" || info.TopType == "预告" || info.TopType == "招标" {
  1170. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  1171. return false, 0
  1172. } else if project.Bidstatus == "废标" || project.Bidstatus == "流标" {
  1173. return false, 0
  1174. } else {
  1175. return true, 0
  1176. }
  1177. } else if info.TopType == "结果" {
  1178. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  1179. return false, 0
  1180. } else if project.Bidstatus == info.SubType {
  1181. //状态一样,根据发布时间判断是否合并
  1182. if (info.Publishtime - project.LastTime) > p.statusTime {
  1183. return true, 0
  1184. } else {
  1185. return false, 0
  1186. }
  1187. } else if project.Bidstatus == "成交" && info.SubType == "中标" {
  1188. return true, 0
  1189. } else if project.Bidstatus == "流标" || project.Bidstatus == "废标" {
  1190. return false, 2
  1191. } else if project.Bidstatus == "合同" || project.Bidstatus == "其它" {
  1192. return false, 3
  1193. } else {
  1194. return false, 0
  1195. }
  1196. } else {
  1197. return false, 0
  1198. }
  1199. }
  1200. /*
  1201. * 对比地区(省、市),存在且不同,不能合并
  1202. * 返回是否新建项目
  1203. */
  1204. func ComparePlace(project *ProjectCache, info *Info) bool {
  1205. if info.Area == "全国" || info.Area == "" {
  1206. return false
  1207. }
  1208. if project.Area == "全国" || project.Area == "" {
  1209. return false
  1210. }
  1211. if info.Area == project.Area {
  1212. if info.City == "" || project.City == "" {
  1213. return false
  1214. } else if info.City == project.City {
  1215. return false
  1216. }
  1217. } else {
  1218. return true
  1219. }
  1220. return true
  1221. }
  1222. func packageEle(map1 map[string]interface{}, id string) map[string]interface{} {
  1223. p2 := map[string]interface{}{}
  1224. for _, k := range PackageEle {
  1225. if map1[k] != nil {
  1226. p2[k] = map1[k]
  1227. }
  1228. infoid := p2["infoid"]
  1229. if infoid == nil {
  1230. p2["infoid"] = id
  1231. }
  1232. }
  1233. return p2
  1234. }
  1235. func PackageFormat(info *Info, project *Project) map[string]interface{} {
  1236. p1 := map[string]interface{}{}
  1237. if project != nil && project.Package != nil && len(project.Package) > 0 {
  1238. packageCopy := util.DeepCopy(project.Package).(map[string]interface{})
  1239. p1 = packageCopy
  1240. for k, v := range info.Package {
  1241. if v1, ok := v.(map[string]interface{}); ok {
  1242. v2 := map[string]interface{}{}
  1243. v2 = packageEle(v1, info.Id)
  1244. if v2["bidstatus"] == nil {
  1245. v2["bidstatus"] = info.SubType
  1246. }
  1247. addFlag := false
  1248. for k1, v3 := range p1 {
  1249. if v4, ok := v3.([]map[string]interface{}); ok {
  1250. //if qu.ObjToString(v4[0]["origin"]) == qu.ObjToString(v2["origin"]) && qu.ObjToString(v4[0]["name"]) == qu.ObjToString(v2["name"]) {
  1251. if k1 == k {
  1252. v4 = append(v4, v2)
  1253. p1[k1] = v4
  1254. addFlag = true
  1255. break
  1256. }
  1257. }
  1258. }
  1259. if !addFlag {
  1260. p1[k] = []map[string]interface{}{v2}
  1261. }
  1262. }
  1263. }
  1264. } else {
  1265. for k, v := range info.Package {
  1266. v1, _ := v.(map[string]interface{})
  1267. p2 := map[string]interface{}{}
  1268. p2 = packageEle(v1, info.Id)
  1269. if p2["bidstatus"] == nil {
  1270. p2["bidstatus"] = info.SubType
  1271. }
  1272. p1[k] = []map[string]interface{}{p2}
  1273. }
  1274. }
  1275. return p1
  1276. }
  1277. // 计算预算(budget)、中标金额(bidamount)
  1278. //func CountAmount(project *Project, info *Info, tmp map[string]interface{}) {
  1279. // if info.HasPackage {
  1280. // budget := 0.0
  1281. // for _, v := range project.Package {
  1282. // v1, _ := v.([]map[string]interface{})
  1283. // for _, v2 := range v1 {
  1284. // if v2["budget"] != nil {
  1285. // b1 := util.Float64All(v2["budget"])
  1286. // if b1 > 0 {
  1287. // budget = budget + b1
  1288. // break
  1289. // }
  1290. // } else {
  1291. // project.Budgettag = 1
  1292. // }
  1293. // }
  1294. // }
  1295. // if budget > 0 {
  1296. // project.Budget = budget
  1297. // project.Budgettag = 0
  1298. // } else if budget == 0 && info.Budget > 0 {
  1299. // project.Budget = info.Budget
  1300. // project.Budgettag = 0
  1301. // }
  1302. // } else {
  1303. // //招标没有多包
  1304. // k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1305. // if len(k) > 0 {
  1306. // //招标是单包
  1307. // if len(project.Package) > 0 {
  1308. // //项目有多包
  1309. // flag := false
  1310. // for _, v := range project.Package {
  1311. // v1, _ := v.([]map[string]interface{})
  1312. // if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1313. // flag = true
  1314. // }
  1315. // }
  1316. // if !flag {
  1317. // project.Budget = project.Budget + info.Budget
  1318. // project.Budgettag = 0
  1319. // }
  1320. // } else {
  1321. // //项目没有多包
  1322. // if info.Budget > 0 {
  1323. // project.Budget = project.Budget + info.Budget
  1324. // project.Budgettag = 0
  1325. // } else if info.Budget == 0 && tmp["budget"] != nil {
  1326. // project.Budgettag = 0
  1327. // }
  1328. // }
  1329. // } else {
  1330. // if info.Budget > 0 && project.Budget < info.Budget {
  1331. // project.Budget = info.Budget
  1332. // project.Budgettag = 0
  1333. // }
  1334. // }
  1335. // }
  1336. // if info.SubType == "中标" || info.SubType == "成交" || info.SubType == "合同" {
  1337. // if info.HasPackage {
  1338. // bidamount := 0.0
  1339. // for _, v := range project.Package {
  1340. // v1, _ := v.([]map[string]interface{})
  1341. // for _, v2 := range v1 {
  1342. // b1 := util.Float64All(v2["bidamount"])
  1343. // if b1 > 0 {
  1344. // bidamount = bidamount + b1
  1345. // break
  1346. // }
  1347. // }
  1348. // }
  1349. // if bidamount > 0 {
  1350. // project.Bidamount = bidamount
  1351. // project.Bidamounttag = 0
  1352. // } else if bidamount == 0 && info.Bidamount > 0 {
  1353. // project.Bidamount = info.Bidamount
  1354. // project.Bidamounttag = 0
  1355. // }
  1356. // } else {
  1357. // //招标没有多包
  1358. // k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1359. // if len(k) > 0 {
  1360. // //招标是单包
  1361. // if len(project.Package) > 0 {
  1362. // //项目有多包
  1363. // flag := false
  1364. // for _, v := range project.Package {
  1365. // v1, _ := v.([]map[string]interface{})
  1366. // if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1367. // flag = true
  1368. // }
  1369. // }
  1370. // if !flag {
  1371. // project.Bidamount = project.Bidamount + info.Bidamount
  1372. // project.Bidamounttag = 0
  1373. // }
  1374. // } else {
  1375. // //项目没有多包
  1376. // if info.Bidamount > 0 {
  1377. // project.Bidamount = project.Bidamount + info.Bidamount
  1378. // project.Bidamounttag = 0
  1379. // } else if info.Bidamount == 0 && tmp["bidamount"] != nil {
  1380. // project.Bidamounttag = 0
  1381. // } else {
  1382. // project.Bidamounttag = 1
  1383. // }
  1384. // }
  1385. // } else {
  1386. // if info.SubType == "中标" || info.SubType == "成交" {
  1387. // if info.Bidamount > 0 {
  1388. // project.Bidamount = info.Bidamount
  1389. // project.Bidamounttag = 0
  1390. // } else {
  1391. // flag := false
  1392. // if project.InfoFiled != nil && len(project.InfoFiled) > 0 {
  1393. // for _, res := range project.InfoFiled {
  1394. // if res.ContractCode != "" && res.ContractCode == info.ContractCode {
  1395. // flag = true
  1396. // break
  1397. // }
  1398. // if res.Bidamount == project.Bidamount {
  1399. // flag = true
  1400. // break
  1401. // }
  1402. // }
  1403. // if !flag {
  1404. // project.Bidamount = project.Bidamount + info.Bidamount
  1405. // project.Bidamounttag = 0
  1406. // } else {
  1407. // if info.Budget > 0 && project.Bidamount > info.Bidamount {
  1408. // project.Bidamount = info.Bidamount
  1409. // project.Bidamounttag = 0
  1410. // }
  1411. // }
  1412. // }
  1413. // }
  1414. // }
  1415. // }
  1416. // }
  1417. // } else {
  1418. // project.Bidamounttag = 1
  1419. // }
  1420. //
  1421. //}
  1422. // 结构体转map
  1423. //func StructToMap(filed InfoField) map[string]interface{} {
  1424. // //先转json
  1425. // result, err := json.Marshal(filed)
  1426. // if err != nil {
  1427. // return nil
  1428. // }
  1429. // //json转map
  1430. // res := make(map[string]interface{})
  1431. // err = json.Unmarshal(result, &res)
  1432. // return res
  1433. //}
  1434. func ClearData(clearMap, tmp map[string]interface{}) {
  1435. for k, v := range tmp {
  1436. if v == "" {
  1437. clearMap[k] = ""
  1438. }
  1439. }
  1440. }
  1441. func IsCreatePro(info *Info) (bol bool) {
  1442. bol = true
  1443. if info.SubType == "" || info.SubType == "变更" || info.SubType == "验收" || info.SubType == "违规" ||
  1444. info.SubType == "结果变更" || info.SubType == "其它" {
  1445. if info.ProjectName == "" && info.ProjectCode == "" {
  1446. bol = false
  1447. } else if info.ProjectName == "" && info.Buyer == "" {
  1448. bol = false
  1449. } else if info.ProjectCode == "" && info.Buyer == "" {
  1450. bol = false
  1451. }
  1452. }
  1453. return bol
  1454. }
  1455. func (p *ProjectTask) GetBidTypeAndBidStatus(info *Info) (string, string) {
  1456. p.mapBidLock.Lock()
  1457. defer p.mapBidLock.Unlock()
  1458. typeStr := bidtype[info.TopType]
  1459. statusStr := bidstatus[info.SubType]
  1460. if info.Infoformat == 2 || info.SubType == "拟建" {
  1461. statusStr = "拟建"
  1462. typeStr = ""
  1463. } else {
  1464. if bidtype[typeStr] == "" {
  1465. typeStr = "招标"
  1466. }
  1467. if typeStr == "招标" {
  1468. statusStr = typeStr
  1469. } else {
  1470. if statusStr == "" {
  1471. statusStr = "其它"
  1472. }
  1473. }
  1474. }
  1475. return typeStr, statusStr
  1476. }
  1477. func FirstCooperation(set map[string]interface{}, b string, winns, entidlist []string) {
  1478. defer func() {
  1479. // 处理数组越界异常
  1480. if r := recover(); r != nil {
  1481. //qu.Debug("recover...:", r)
  1482. }
  1483. }()
  1484. pid := mongodb.BsonIdToSId(set["_id"])
  1485. var eids []string
  1486. for i, eid := range entidlist {
  1487. if eid != "-" {
  1488. text := b + "," + winns[i]
  1489. ex, _ := redis.Exists(RedisBuyer, text)
  1490. if !ex {
  1491. redis.PutCKV(RedisBuyer, text, pid)
  1492. eids = append(eids, eid)
  1493. }
  1494. }
  1495. }
  1496. if len(eids) > 0 {
  1497. set["first_cooperation"] = entidlist
  1498. }
  1499. }