project.go 41 KB

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