project.go 42 KB

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