project.go 42 KB

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