project.go 41 KB

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