project.go 40 KB

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