project.go 41 KB

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