project.go 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  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. redis.PutCKV("project", thisinfo.Id, set)
  591. push := p.PushListInfo(tmp, thisinfo.Id)
  592. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  593. set["list"] = []bson.M{
  594. push,
  595. }
  596. p.updatePool <- []map[string]interface{}{
  597. {
  598. "_id": pId,
  599. },
  600. {
  601. "$set": set,
  602. },
  603. }
  604. return pId.Hex(), &p1
  605. }
  606. //项目中list的信息
  607. func (p *ProjectTask) PushListInfo(tmp map[string]interface{}, infoid string) bson.M {
  608. res := bson.M{
  609. "infoid": infoid,
  610. }
  611. for _, k := range INFOFIELDS {
  612. if tmp[k] != nil {
  613. res[k] = tmp[k]
  614. }
  615. }
  616. return res
  617. }
  618. //生成存放在内存中的对象
  619. func (p *ProjectTask) NewCachePinfo(id primitive.ObjectID, thisinfo *Info, bidtype, bidstatus string) ProjectCache {
  620. p1 := ProjectCache{
  621. Id: id,
  622. Ids: []string{thisinfo.Id},
  623. ProjectName: thisinfo.ProjectName,
  624. ProjectCode: thisinfo.ProjectCode,
  625. Buyer: thisinfo.Buyer,
  626. Agency: thisinfo.Agency,
  627. Area: thisinfo.Area,
  628. City: thisinfo.City,
  629. District: thisinfo.District,
  630. MPN: []string{},
  631. MPC: []string{},
  632. FirstTime: thisinfo.Publishtime,
  633. LastTime: thisinfo.Publishtime,
  634. Budget: thisinfo.Budget,
  635. Bidamount: thisinfo.Bidamount,
  636. Bidstatus: bidstatus,
  637. Bidtype: bidtype,
  638. }
  639. if thisinfo.LenPTC > 5 {
  640. p1.MPC = append(p1.MPC, thisinfo.PTC)
  641. }
  642. return p1
  643. }
  644. // @Description 更新项目 全量合并
  645. // @update 中间表查询需要更新的项目信息
  646. // @Author J 2022/7/6 14:02
  647. func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info, pInfo *ProjectCache, weight int, comStr string, ex int) {
  648. if p.currentType != "updateInfo" {
  649. if BinarySearch(pInfo.Ids, thisinfo.Id) > -1 {
  650. qu.Debug("repeat", thisinfo.Id, ",pid", pInfo.Id)
  651. return
  652. }
  653. }
  654. pdata := redis.Get("project", pInfo.Id.Hex())
  655. if pdata == nil {
  656. qu.Debug("redis err, not find project ", pInfo.Id.Hex())
  657. return
  658. }
  659. projectMap := pdata.(map[string]interface{})
  660. bys, _ := json.Marshal(projectMap)
  661. var project *Project
  662. err := json.Unmarshal(bys, &project)
  663. if err != nil {
  664. qu.Debug("project Unmarshal err,", err)
  665. return
  666. }
  667. set := map[string]interface{}{}
  668. pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
  669. if len(pInfo.Ids) > 30 {
  670. //异常标记
  671. set["listtag"] = 1
  672. }
  673. //zbtime、lasttime、jgtime
  674. pInfo.LastTime = thisinfo.Publishtime
  675. set["lasttime"] = thisinfo.Publishtime
  676. if thisinfo.TopType == "招标" {
  677. if project.Zbtime <= 0 {
  678. project.Zbtime = thisinfo.Publishtime
  679. set["zbtime"] = tmp["publishtime"]
  680. }
  681. if project.Jgtime > 0 {
  682. project.Jgtime = int64(0)
  683. set["jgtime"] = int64(0)
  684. }
  685. } else if thisinfo.TopType == "结果" {
  686. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  687. if project.Jgtime > 0 {
  688. //jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
  689. //公告状态和项目状态同样都是中标或者成交,
  690. if thisinfo.SubType == "成交" && project.Bidstatus == "中标" {
  691. if p.jgTime < thisinfo.Publishtime {
  692. project.Jgtime = thisinfo.Publishtime
  693. set["jgtime"] = tmp["publishtime"]
  694. }
  695. //公告状态和项目状态同样是流标或者废标
  696. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (project.Bidstatus == "流标" || project.Bidstatus == "废标") {
  697. if p.jgTime < thisinfo.Publishtime {
  698. project.Jgtime = thisinfo.Publishtime
  699. set["jgtime"] = tmp["publishtime"]
  700. }
  701. }
  702. } else {
  703. project.Jgtime = thisinfo.Publishtime
  704. set["jgtime"] = tmp["publishtime"]
  705. }
  706. }
  707. } else if thisinfo.SubType == "合同" {
  708. if project.Bidstatus == "中标" || project.Bidstatus == "成交" || project.Bidstatus == "" {
  709. //中标、成交不更新jgtime
  710. } else {
  711. project.Jgtime = thisinfo.Publishtime
  712. set["jgtime"] = tmp["publishtime"]
  713. }
  714. }
  715. if thisinfo.Bidopentime > project.Bidopentime {
  716. project.Bidopentime = thisinfo.Bidopentime
  717. set["bidopentime"] = project.Bidopentime
  718. }
  719. bt := qu.ObjToString(tmp["toptype"])
  720. bs := qu.ObjToString(tmp["subtype"])
  721. p.mapBidLock.Lock()
  722. if bt == "招标" {
  723. //招标状态,更新projectscope
  724. if tmp["projectscope"] != nil {
  725. set["projectscope"] = qu.ObjToString(tmp["projectscope"])
  726. }
  727. set["bidstatus"] = bt
  728. project.Bidstatus = bt
  729. if bidtype[bs] != "" {
  730. set["bidtype"] = bidtype[bs]
  731. project.Bidtype = bidtype[bs]
  732. } else {
  733. set["bidtype"] = "招标"
  734. project.Bidtype = "招标"
  735. }
  736. } else {
  737. if bidstatus[bs] != "" {
  738. set["bidstatus"] = thisinfo.SubType
  739. project.Bidstatus = thisinfo.SubType
  740. } else if thisinfo.Infoformat == 2 {
  741. set["bidstatus"] = "拟建"
  742. project.Bidstatus = "拟建"
  743. } else if bs == "" && bt == "结果" {
  744. if project.Bidstatus == "招标" {
  745. set["bidstatus"] = ""
  746. project.Bidstatus = ""
  747. }
  748. } else {
  749. set["bidstatus"] = "其它"
  750. project.Bidstatus = "其它"
  751. }
  752. }
  753. p.mapBidLock.Unlock()
  754. //异常标记
  755. if ex > 0 {
  756. set["exception"] = ex
  757. }
  758. //3\4\5--省、市、县
  759. //if thisinfo.Area != "全国" {
  760. // if pInfo.Area == "全国" {
  761. // pInfo.Area = thisinfo.Area
  762. // set["area"] = thisinfo.Area
  763. // } else if pInfo.Area != thisinfo.Area {
  764. // //xt = false
  765. // }
  766. // if pInfo.City == "" && thisinfo.City != "" {
  767. // pInfo.City = thisinfo.City
  768. // set["city"] = thisinfo.City
  769. // } else if pInfo.City != thisinfo.City {
  770. // //xt = false
  771. // }
  772. // if thisinfo.District != "" && pInfo.District == "" {
  773. // pInfo.District = thisinfo.District
  774. // set["district"] = thisinfo.District
  775. // }
  776. //}
  777. //相同城市的公告才会合并到一起(全国列外)
  778. if thisinfo.Area != "全国" {
  779. pInfo.Area = thisinfo.Area
  780. project.Area = thisinfo.Area
  781. set["area"] = thisinfo.Area
  782. if thisinfo.City != "" {
  783. pInfo.City = thisinfo.City
  784. project.City = thisinfo.City
  785. set["city"] = thisinfo.City
  786. }
  787. if thisinfo.District != "" {
  788. pInfo.District = thisinfo.District
  789. project.District = thisinfo.District
  790. set["district"] = thisinfo.District
  791. }
  792. }
  793. //项目名称
  794. //if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  795. if pInfo.ProjectName == "" && thisinfo.ProjectName != "" {
  796. pInfo.ProjectName = thisinfo.ProjectName
  797. project.ProjectName = thisinfo.ProjectName
  798. set["projectname"] = thisinfo.ProjectName
  799. }
  800. //7--项目编号
  801. //if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  802. if pInfo.ProjectCode == "" && thisinfo.ProjectCode != "" {
  803. pInfo.ProjectCode = thisinfo.ProjectCode
  804. project.ProjectCode = thisinfo.ProjectCode
  805. set["projectcode"] = thisinfo.ProjectCode
  806. }
  807. //7--采购单位
  808. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  809. pInfo.Buyer = thisinfo.Buyer
  810. project.Buyer = thisinfo.Buyer
  811. set["buyer"] = thisinfo.Buyer
  812. project.Buyerclass = thisinfo.Buyerclass
  813. set["buyerclass"] = thisinfo.Buyerclass
  814. }
  815. if pInfo.Buyer == "" {
  816. project.Buyerclass = ""
  817. set["buyerclass"] = ""
  818. }
  819. //采购单位联系人
  820. if thisinfo.Buyerperson != "" {
  821. project.Buyerperson = thisinfo.Buyerperson
  822. set["buyerperson"] = thisinfo.Buyerperson
  823. } else {
  824. project.Buyerperson = ""
  825. set["buyerperson"] = ""
  826. }
  827. //采购单位電話
  828. if thisinfo.Buyertel != "" {
  829. project.Buyertel = thisinfo.Buyertel
  830. set["buyertel"] = project.Buyertel
  831. } else {
  832. project.Buyertel = ""
  833. set["buyertel"] = ""
  834. }
  835. if thisinfo.ContractCode != "" {
  836. if project.ContractCode == "" {
  837. set["contractcode"] = thisinfo.ContractCode
  838. } else {
  839. list := strings.Split(project.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. project.Agency = thisinfo.Agency
  851. set["agency"] = thisinfo.Agency
  852. }
  853. if len(thisinfo.Topscopeclass) > 0 {
  854. sort.Strings(project.Topscopeclass)
  855. for _, k := range thisinfo.Topscopeclass {
  856. if BinarySearch(project.Topscopeclass, k) == -1 {
  857. project.Topscopeclass = append(project.Topscopeclass, k)
  858. sort.Strings(project.Topscopeclass)
  859. }
  860. }
  861. set["topscopeclass"] = project.Topscopeclass
  862. }
  863. //项目评审专家
  864. if len(thisinfo.ReviewExperts) > 0 {
  865. set["review_experts"] = thisinfo.ReviewExperts
  866. project.ReviewExperts = thisinfo.ReviewExperts
  867. }
  868. if thisinfo.Purchasing != "" {
  869. if project.Purchasing == "" {
  870. list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
  871. p := strings.Join(qu.ObjArrToStringArr(list), ",")
  872. project.Purchasing = p
  873. set["purchasing"] = p
  874. } else {
  875. list := strings.Split(project.Purchasing, ",")
  876. list = qu.ObjArrToStringArr(Duplicate(list))
  877. for _, k := range list {
  878. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  879. list = append(list, k)
  880. sort.Strings(list)
  881. }
  882. }
  883. set["purchasing"] = strings.Join(list, ",")
  884. }
  885. }
  886. //中标候选人
  887. if len(thisinfo.WinnerOrder) > 0 {
  888. var list = []string{}
  889. for _, v := range thisinfo.WinnerOrder {
  890. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  891. list = append(list, qu.ObjToString(v["entname"]))
  892. }
  893. }
  894. set["winnerorder"] = list
  895. project.Winnerorder = list
  896. }
  897. if len(thisinfo.Subscopeclass) > 0 {
  898. sort.Strings(project.Subscopeclass)
  899. for _, k := range thisinfo.Subscopeclass {
  900. if BinarySearch(project.Subscopeclass, k) == -1 {
  901. project.Subscopeclass = append(project.Subscopeclass, k)
  902. sort.Strings(project.Subscopeclass)
  903. }
  904. }
  905. set["subscopeclass"] = project.Subscopeclass
  906. set["s_subscopeclass"] = strings.Join(project.Subscopeclass, ",")
  907. }
  908. if len(thisinfo.Winners) > 0 {
  909. if len(project.Winners) <= 0 {
  910. set["winner"] = qu.ObjToString(tmp["winner"])
  911. }
  912. winners := strings.Split(project.Winners, ",")
  913. for _, k := range thisinfo.Winners {
  914. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  915. if BinarySearch(winners, k) != -1 {
  916. deleteSlice(winners, k, "")
  917. }
  918. } else {
  919. if BinarySearch(winners, k) == -1 {
  920. winners = append(winners, k)
  921. }
  922. }
  923. }
  924. set["s_winner"] = strings.Join(qu.ObjArrToStringArr(Duplicate(winners)), ",")
  925. }
  926. if len(thisinfo.EntIdList) > 0 {
  927. for _, v := range thisinfo.EntIdList {
  928. if BinarySearch(project.EntIdList, v) == -1 {
  929. project.EntIdList = append(project.EntIdList, v)
  930. }
  931. }
  932. set["entidlist"] = project.EntIdList
  933. }
  934. // first_cooperation
  935. if pInfo.Buyer != "" && len(strings.Split(project.Winners, ",")) > 0 {
  936. FirstCooperation(set, pInfo.Buyer, strings.Split(project.Winners, ","), project.EntIdList)
  937. }
  938. //项目规模
  939. if len(thisinfo.ProjectScale) > 0 {
  940. project.ProjectScale = thisinfo.ProjectScale
  941. set["project_scale"] = thisinfo.ProjectScale
  942. }
  943. //工期时长
  944. if thisinfo.ProjectDuration > 0 {
  945. project.ProjectDuration = thisinfo.ProjectDuration
  946. set["project_duration"] = thisinfo.ProjectDuration
  947. }
  948. // 工期单位
  949. if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
  950. project.ProjectTimeunit = thisinfo.ProjectTimeUnit
  951. set["project_timeunit"] = thisinfo.ProjectTimeUnit
  952. }
  953. //开工日期
  954. if thisinfo.ProjectStartDate > 0 {
  955. if project.ProjectStartDate > 0 {
  956. if project.ProjectStartDate < thisinfo.ProjectStartDate {
  957. project.ProjectStartDate = thisinfo.ProjectStartDate
  958. set["project_startdate"] = thisinfo.ProjectStartDate
  959. }
  960. } else {
  961. project.ProjectStartDate = thisinfo.ProjectStartDate
  962. set["project_startdate"] = thisinfo.ProjectStartDate
  963. }
  964. }
  965. //竣工日期
  966. if thisinfo.ProjectCompleteDate > 0 {
  967. if project.ProjctCompleteDate > 0 {
  968. if project.ProjctCompleteDate < thisinfo.ProjectCompleteDate {
  969. project.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  970. set["project_completedate"] = thisinfo.ProjectCompleteDate
  971. }
  972. } else {
  973. project.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  974. set["project_completedate"] = thisinfo.ProjectCompleteDate
  975. }
  976. }
  977. // 付款方式
  978. if len(thisinfo.Payway) > 0 {
  979. project.Payway = thisinfo.Payway
  980. set["payway"] = thisinfo.Payway
  981. }
  982. // 履约保证金
  983. if tmp["contract_guarantee"] != nil {
  984. project.ContractGuarantee = thisinfo.ContractGuarantee
  985. set["contract_guarantee"] = thisinfo.ContractGuarantee
  986. }
  987. // 投标保证金
  988. if tmp["bid_guarantee"] != nil {
  989. project.BidGuarantee = thisinfo.BidGuarantee
  990. set["bid_guarantee"] = thisinfo.BidGuarantee
  991. }
  992. // 资质条件
  993. if len(thisinfo.Qualifies) > 0 {
  994. var str []string
  995. if len(project.Qualifies) > 0 {
  996. str = append(str, strings.Split(project.Qualifies, ",")...)
  997. }
  998. for _, v := range thisinfo.Qualifies {
  999. if len(qu.ObjToString(v["key"])) > 0 {
  1000. if BinarySearch(str, qu.ObjToString(v["key"])) == -1 {
  1001. str = append(str, qu.ObjToString(v["key"]))
  1002. }
  1003. }
  1004. }
  1005. if len(str) > 0 {
  1006. project.Qualifies = strings.Join(str, ",")
  1007. set["qualifies"] = strings.Join(str, ",")
  1008. }
  1009. }
  1010. if thisinfo.HasPackage { //多包处理
  1011. set["multipackage"] = 1
  1012. pkg := PackageFormat(thisinfo, project)
  1013. project.Package = pkg
  1014. set["package"] = project.Package
  1015. }
  1016. //处理多包后,计算预算金额、中标金额
  1017. CountAmount(project, thisinfo, tmp)
  1018. if project.Budget >= 0 && project.Budgettag != 1 {
  1019. pInfo.Budget = project.Budget
  1020. set["budget"] = project.Budget
  1021. set["budgettag"] = 0
  1022. }
  1023. if project.Bidamount >= 0 && project.Bidamounttag != 1 {
  1024. pInfo.Bidamount = project.Bidamount
  1025. set["bidamount"] = pInfo.Bidamount
  1026. set["bidamounttag"] = 0
  1027. }
  1028. if pInfo.Bidamount > 0 {
  1029. set["sortprice"] = pInfo.Bidamount
  1030. } else {
  1031. if pInfo.Budget > 0 {
  1032. set["sortprice"] = pInfo.Budget
  1033. }
  1034. }
  1035. infofield := InfoField{
  1036. Budget: thisinfo.Budget,
  1037. Bidamount: thisinfo.Bidamount,
  1038. ContractCode: thisinfo.ContractCode,
  1039. ProjectName: thisinfo.ProjectName,
  1040. ProjectCode: thisinfo.ProjectCode,
  1041. Bidstatus: bs,
  1042. }
  1043. copyMap := Copy(project.InfoFiled).(map[string]InfoField)
  1044. copyMap[thisinfo.Id] = infofield
  1045. tmpMap := make(map[string]interface{})
  1046. for k, v := range copyMap {
  1047. tmpMap[k] = StructToMap(v)
  1048. }
  1049. tmpMap[thisinfo.Id] = StructToMap(infofield)
  1050. project.InfoFiled = copyMap
  1051. set["infofield"] = tmpMap
  1052. set["mpn"] = pInfo.MPN
  1053. set["mpc"] = pInfo.MPC
  1054. if p.currentType == "project" {
  1055. set["pici"] = p.pici
  1056. } else {
  1057. set["pici"] = tmp["comeintime"]
  1058. }
  1059. redis.PutCKV("project", project.Id.Hex(), set)
  1060. update := map[string]interface{}{}
  1061. if len(set) > 0 {
  1062. update["$set"] = set
  1063. }
  1064. push := p.PushListInfo(tmp, thisinfo.Id)
  1065. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  1066. push["compareStr"] = comStr
  1067. push["resVal"] = pInfo.resVal
  1068. push["pjVal"] = pInfo.pjVal
  1069. update["$push"] = map[string]interface{}{
  1070. "list": push,
  1071. "ids": thisinfo.Id,
  1072. }
  1073. //clearMap := map[string]interface{}{}
  1074. //ClearData(clearMap, set)
  1075. //if len(clearMap) > 0 {
  1076. // update["$unset"] = clearMap
  1077. //}
  1078. if len(update) > 0 {
  1079. updateInfo := []map[string]interface{}{
  1080. {
  1081. "_id": pInfo.Id,
  1082. },
  1083. update,
  1084. }
  1085. p.updatePool <- updateInfo
  1086. }
  1087. }
  1088. /**
  1089. * 更新项目时,项目状态的处理
  1090. * 返回是否新增项目,异常标记
  1091. * 1、新增项目时,招标信息的状态(toptype)不是招标、拟建、预告 异常:1
  1092. * 异常1是在项目新建的时候才会产生
  1093. * 3、项目合并时,项目状态是”流标“/”废标“,招标信息状态不是”招标“ 异常:2
  1094. * 4、项目合并时,项目状态是”合同“/”其它“,招标信息类型是”结果“ 异常:3
  1095. */
  1096. func (p *ProjectTask) CompareStatus(project *ProjectCache, info *Info) (bool, int) {
  1097. if info.TopType == "拟建" || info.TopType == "预告" || info.TopType == "招标" {
  1098. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  1099. return false, 0
  1100. } else if project.Bidstatus == "废标" || project.Bidstatus == "流标" {
  1101. return false, 0
  1102. } else {
  1103. return true, 0
  1104. }
  1105. } else if info.TopType == "结果" {
  1106. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  1107. return false, 0
  1108. } else if project.Bidstatus == info.SubType {
  1109. //状态一样,根据发布时间判断是否合并
  1110. if (info.Publishtime - project.LastTime) > p.statusTime {
  1111. return true, 0
  1112. } else {
  1113. return false, 0
  1114. }
  1115. } else if project.Bidstatus == "成交" && info.SubType == "中标" {
  1116. return true, 0
  1117. } else if project.Bidstatus == "流标" || project.Bidstatus == "废标" {
  1118. return false, 2
  1119. } else if project.Bidstatus == "合同" || project.Bidstatus == "其它" {
  1120. return false, 3
  1121. } else {
  1122. return false, 0
  1123. }
  1124. } else {
  1125. return false, 0
  1126. }
  1127. }
  1128. /*
  1129. * 对比地区(省、市),存在且不同,不能合并
  1130. * 返回是否新建项目
  1131. */
  1132. func ComparePlace(project *ProjectCache, info *Info) bool {
  1133. if info.Area == "全国" || info.Area == "" {
  1134. return false
  1135. }
  1136. if project.Area == "全国" || project.Area == "" {
  1137. return false
  1138. }
  1139. if info.Area == project.Area {
  1140. if info.City == "" || project.City == "" {
  1141. return false
  1142. } else if info.City == project.City {
  1143. return false
  1144. }
  1145. } else {
  1146. return true
  1147. }
  1148. return true
  1149. }
  1150. func packageEle(map1 map[string]interface{}, id string) map[string]interface{} {
  1151. p2 := map[string]interface{}{}
  1152. for _, k := range PackageEle {
  1153. if map1[k] != nil {
  1154. p2[k] = map1[k]
  1155. }
  1156. infoid := p2["infoid"]
  1157. if infoid == nil {
  1158. p2["infoid"] = id
  1159. }
  1160. }
  1161. return p2
  1162. }
  1163. func PackageFormat(info *Info, project *Project) map[string]interface{} {
  1164. p1 := map[string]interface{}{}
  1165. if project != nil && project.Package != nil && len(project.Package) > 0 {
  1166. packageCopy := Copy(project.Package).(map[string]interface{})
  1167. p1 = packageCopy
  1168. for k, v := range info.Package {
  1169. if v1, ok := v.(map[string]interface{}); ok {
  1170. v2 := map[string]interface{}{}
  1171. v2 = packageEle(v1, info.Id)
  1172. if v2["bidstatus"] == nil {
  1173. v2["bidstatus"] = info.SubType
  1174. }
  1175. addFlag := false
  1176. for k1, v3 := range p1 {
  1177. if v4, ok := v3.([]map[string]interface{}); ok {
  1178. //if qu.ObjToString(v4[0]["origin"]) == qu.ObjToString(v2["origin"]) && qu.ObjToString(v4[0]["name"]) == qu.ObjToString(v2["name"]) {
  1179. if k1 == k {
  1180. v4 = append(v4, v2)
  1181. p1[k1] = v4
  1182. addFlag = true
  1183. break
  1184. }
  1185. }
  1186. }
  1187. if !addFlag {
  1188. p1[k] = []map[string]interface{}{v2}
  1189. }
  1190. }
  1191. }
  1192. } else {
  1193. for k, v := range info.Package {
  1194. v1, _ := v.(map[string]interface{})
  1195. p2 := map[string]interface{}{}
  1196. p2 = packageEle(v1, info.Id)
  1197. if p2["bidstatus"] == nil {
  1198. p2["bidstatus"] = info.SubType
  1199. }
  1200. p1[k] = []map[string]interface{}{p2}
  1201. }
  1202. }
  1203. return p1
  1204. }
  1205. // 计算预算(budget)、中标金额(bidamount)
  1206. func CountAmount(project *Project, info *Info, tmp map[string]interface{}) {
  1207. if info.HasPackage {
  1208. budget := 0.0
  1209. for _, v := range project.Package {
  1210. v1, _ := v.([]map[string]interface{})
  1211. for _, v2 := range v1 {
  1212. if v2["budget"] != nil {
  1213. b1 := qu.Float64All(v2["budget"])
  1214. if b1 > 0 {
  1215. budget = budget + b1
  1216. break
  1217. }
  1218. } else {
  1219. project.Budgettag = 1
  1220. }
  1221. }
  1222. }
  1223. if budget > 0 {
  1224. project.Budget = budget
  1225. project.Budgettag = 0
  1226. } else if budget == 0 && info.Budget > 0 {
  1227. project.Budget = info.Budget
  1228. project.Budgettag = 0
  1229. }
  1230. } else {
  1231. //招标没有多包
  1232. k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1233. if len(k) > 0 {
  1234. //招标是单包
  1235. if len(project.Package) > 0 {
  1236. //项目有多包
  1237. flag := false
  1238. for _, v := range project.Package {
  1239. v1, _ := v.([]map[string]interface{})
  1240. if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1241. flag = true
  1242. }
  1243. }
  1244. if !flag {
  1245. project.Budget = project.Budget + info.Budget
  1246. project.Budgettag = 0
  1247. }
  1248. } else {
  1249. //项目没有多包
  1250. if info.Budget > 0 {
  1251. project.Budget = project.Budget + info.Budget
  1252. project.Budgettag = 0
  1253. } else if info.Budget == 0 && tmp["budget"] != nil {
  1254. project.Budgettag = 0
  1255. }
  1256. }
  1257. } else {
  1258. if info.Budget > 0 && project.Budget < info.Budget {
  1259. project.Budget = info.Budget
  1260. project.Budgettag = 0
  1261. }
  1262. }
  1263. }
  1264. if info.SubType == "中标" || info.SubType == "成交" || info.SubType == "合同" {
  1265. if info.HasPackage {
  1266. bidamount := 0.0
  1267. for _, v := range project.Package {
  1268. v1, _ := v.([]map[string]interface{})
  1269. for _, v2 := range v1 {
  1270. b1 := qu.Float64All(v2["bidamount"])
  1271. if b1 > 0 {
  1272. bidamount = bidamount + b1
  1273. break
  1274. }
  1275. }
  1276. }
  1277. if bidamount > 0 {
  1278. project.Bidamount = bidamount
  1279. project.Bidamounttag = 0
  1280. } else if bidamount == 0 && info.Bidamount > 0 {
  1281. project.Bidamount = info.Bidamount
  1282. project.Bidamounttag = 0
  1283. }
  1284. } else {
  1285. //招标没有多包
  1286. k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1287. if len(k) > 0 {
  1288. //招标是单包
  1289. if len(project.Package) > 0 {
  1290. //项目有多包
  1291. flag := false
  1292. for _, v := range project.Package {
  1293. v1, _ := v.([]map[string]interface{})
  1294. if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1295. flag = true
  1296. }
  1297. }
  1298. if !flag {
  1299. project.Bidamount = project.Bidamount + info.Bidamount
  1300. project.Bidamounttag = 0
  1301. }
  1302. } else {
  1303. //项目没有多包
  1304. if info.Bidamount > 0 {
  1305. project.Bidamount = project.Bidamount + info.Bidamount
  1306. project.Bidamounttag = 0
  1307. } else if info.Bidamount == 0 && tmp["bidamount"] != nil {
  1308. project.Bidamounttag = 0
  1309. } else {
  1310. project.Bidamounttag = 1
  1311. }
  1312. }
  1313. } else {
  1314. if info.SubType == "中标" || info.SubType == "成交" {
  1315. if info.Bidamount > 0 {
  1316. project.Bidamount = info.Bidamount
  1317. project.Bidamounttag = 0
  1318. } else {
  1319. flag := false
  1320. if project.InfoFiled != nil && len(project.InfoFiled) > 0 {
  1321. for _, res := range project.InfoFiled {
  1322. if res.ContractCode != "" && res.ContractCode == info.ContractCode {
  1323. flag = true
  1324. break
  1325. }
  1326. if res.Bidamount == project.Bidamount {
  1327. flag = true
  1328. break
  1329. }
  1330. }
  1331. if !flag {
  1332. project.Bidamount = project.Bidamount + info.Bidamount
  1333. project.Bidamounttag = 0
  1334. } else {
  1335. if info.Budget > 0 && project.Bidamount > info.Bidamount {
  1336. project.Bidamount = info.Bidamount
  1337. project.Bidamounttag = 0
  1338. }
  1339. }
  1340. }
  1341. }
  1342. }
  1343. }
  1344. }
  1345. } else {
  1346. project.Bidamounttag = 1
  1347. }
  1348. }
  1349. //结构体转map
  1350. func StructToMap(filed InfoField) map[string]interface{} {
  1351. //先转json
  1352. result, err := json.Marshal(filed)
  1353. if err != nil {
  1354. return nil
  1355. }
  1356. //json转map
  1357. res := make(map[string]interface{})
  1358. err = json.Unmarshal(result, &res)
  1359. return res
  1360. }
  1361. func ClearData(clearMap, tmp map[string]interface{}) {
  1362. for k, v := range tmp {
  1363. if v == "" {
  1364. clearMap[k] = ""
  1365. }
  1366. }
  1367. }
  1368. func IsCreatePro(info *Info) (bol bool) {
  1369. bol = true
  1370. if info.SubType == "" || info.SubType == "变更" || info.SubType == "验收" || info.SubType == "违规" ||
  1371. info.SubType == "结果变更" || info.SubType == "其它" {
  1372. if info.ProjectName == "" && info.ProjectCode == "" {
  1373. bol = false
  1374. } else if info.ProjectName == "" && info.Buyer == "" {
  1375. bol = false
  1376. } else if info.ProjectCode == "" && info.Buyer == "" {
  1377. bol = false
  1378. }
  1379. }
  1380. return bol
  1381. }
  1382. func (p *ProjectTask) GetBidTypeAndBidStatus(info *Info) (string, string) {
  1383. p.mapBidLock.Lock()
  1384. defer p.mapBidLock.Unlock()
  1385. typeStr := bidtype[info.TopType]
  1386. statusStr := bidstatus[info.SubType]
  1387. if info.Infoformat == 2 || info.SubType == "拟建" {
  1388. statusStr = "拟建"
  1389. typeStr = ""
  1390. } else {
  1391. if bidtype[typeStr] == "" {
  1392. typeStr = "招标"
  1393. }
  1394. if typeStr == "招标" {
  1395. statusStr = typeStr
  1396. } else {
  1397. if statusStr == "" {
  1398. statusStr = "其它"
  1399. }
  1400. }
  1401. }
  1402. return typeStr, statusStr
  1403. }
  1404. func FirstCooperation(set map[string]interface{}, b string, winns, entidlist []string) {
  1405. defer func() {
  1406. // 处理数组越界异常
  1407. if r := recover(); r != nil {
  1408. //qu.Debug("recover...:", r)
  1409. }
  1410. }()
  1411. pid := mongodb.BsonIdToSId(set["_id"])
  1412. var eids []string
  1413. for i, eid := range entidlist {
  1414. if eid != "-" {
  1415. text := b + "," + winns[i]
  1416. ex, _ := redis.Exists(RedisCode, text)
  1417. if !ex {
  1418. redis.PutCKV(RedisCode, text, pid)
  1419. eids = append(eids, eid)
  1420. }
  1421. }
  1422. }
  1423. if len(eids) > 0 {
  1424. set["first_cooperation"] = entidlist
  1425. }
  1426. }