project.go 40 KB

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