project.go 41 KB

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