project.go 41 KB

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