project.go 43 KB

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