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