project.go 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516
  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. if len(p1.EntIdList) > 0 {
  574. set["entidlist"] = p1.EntIdList
  575. }
  576. p1.InfoFiled = make(map[string]InfoField)
  577. infofield := InfoField{
  578. Budget: thisinfo.Budget,
  579. Bidamount: thisinfo.Bidamount,
  580. ContractCode: thisinfo.ContractCode,
  581. ProjectName: thisinfo.ProjectName,
  582. ProjectCode: thisinfo.ProjectCode,
  583. Bidstatus: bs,
  584. }
  585. p1.InfoFiled[thisinfo.Id] = infofield
  586. res := StructToMap(infofield)
  587. set["infofield"] = map[string]interface{}{
  588. thisinfo.Id: res,
  589. }
  590. if tmp["budget"] != nil && tmp["budget"] != "" {
  591. set["budget"] = thisinfo.Budget
  592. p1.Budgettag = 0
  593. set["budgettag"] = 0
  594. } else {
  595. p1.Budgettag = 1
  596. set["budgettag"] = 1
  597. }
  598. if tmp["bidamount"] != nil && tmp["bidamount"] != "" {
  599. set["bidamount"] = thisinfo.Bidamount
  600. p1.Bidamounttag = 0
  601. set["bidamounttag"] = 0
  602. } else {
  603. p1.Bidamounttag = 1
  604. set["bidamounttag"] = 1
  605. }
  606. if p1.Bidamount > 0 {
  607. set["sortprice"] = p1.Bidamount
  608. } else if p1.Budget > 0 {
  609. set["sortprice"] = p1.Budget
  610. }
  611. push := p.PushListInfo(tmp, thisinfo.Id)
  612. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  613. set["list"] = []bson.M{
  614. push,
  615. }
  616. //p.savePool <- set
  617. p.updatePool <- []map[string]interface{}{
  618. {
  619. "_id": pId,
  620. },
  621. {
  622. "$set": set,
  623. },
  624. }
  625. //log.Println(set)
  626. return pId.Hex(), &p1
  627. }
  628. //招标信息字段
  629. var INFOFIELDS = []string{
  630. "projectname",
  631. "projectcode",
  632. "projectscope",
  633. "contractcode",
  634. "title",
  635. "href",
  636. "publishtime",
  637. "comeintime",
  638. "bidopentime",
  639. "toptype",
  640. "subtype",
  641. "buyer",
  642. "buyerclass",
  643. "agency",
  644. "winner",
  645. "budget",
  646. "bidamount",
  647. "topscopeclass",
  648. "subscopclass",
  649. "infoformat",
  650. "buyerperson",
  651. "buyertel",
  652. "area",
  653. "city",
  654. "district",
  655. "spidercode",
  656. "site",
  657. "review_experts",
  658. "purchasing",
  659. "project_scale",
  660. "project_duration",
  661. "project_timeunit",
  662. "project_startdate",
  663. "project_completedate",
  664. "payway",
  665. "contract_guarantee",
  666. "bid_guarantee",
  667. "qualifies",
  668. "entidlist",
  669. }
  670. //项目中list的信息
  671. func (p *ProjectTask) PushListInfo(tmp map[string]interface{}, infoid string) bson.M {
  672. res := bson.M{
  673. "infoid": infoid,
  674. }
  675. for _, k := range INFOFIELDS {
  676. if tmp[k] != nil {
  677. res[k] = tmp[k]
  678. }
  679. }
  680. return res
  681. }
  682. //生成存放在内存中的对象
  683. func (p *ProjectTask) NewCachePinfo(id primitive.ObjectID, thisinfo *Info, bidtype, bidstatus string, pkg map[string]interface{}) ProjectInfo {
  684. p1 := ProjectInfo{
  685. Id: id,
  686. Ids: []string{thisinfo.Id},
  687. ProjectName: thisinfo.ProjectName,
  688. ProjectCode: thisinfo.ProjectCode,
  689. ContractCode: thisinfo.ContractCode,
  690. Buyer: thisinfo.Buyer,
  691. Buyerclass: thisinfo.Buyerclass,
  692. Buyerperson: thisinfo.Buyerperson,
  693. Buyertel: thisinfo.Buyertel,
  694. Topscopeclass: thisinfo.Topscopeclass,
  695. Subscopeclass: thisinfo.Subscopeclass,
  696. Agency: thisinfo.Agency,
  697. Area: thisinfo.Area,
  698. City: thisinfo.City,
  699. District: thisinfo.District,
  700. MPN: []string{},
  701. MPC: []string{},
  702. FirstTime: thisinfo.Publishtime,
  703. LastTime: thisinfo.Publishtime,
  704. Budget: thisinfo.Budget,
  705. Package: pkg,
  706. Bidamount: thisinfo.Bidamount,
  707. Bidstatus: bidstatus,
  708. Bidtype: bidtype,
  709. Winners: thisinfo.Winners,
  710. EntIdList: thisinfo.EntIdList,
  711. }
  712. if thisinfo.LenPTC > 5 {
  713. p1.MPC = append(p1.MPC, thisinfo.PTC)
  714. }
  715. return p1
  716. }
  717. //更新项目
  718. func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info, pInfo *ProjectInfo, weight int, comStr string, ex int) {
  719. if p.currentType != "updateInfo" {
  720. if BinarySearch(pInfo.Ids, thisinfo.Id) > -1 {
  721. log.Println("repeat", thisinfo.Id, ",pid", pInfo.Id)
  722. return
  723. }
  724. }
  725. set := map[string]interface{}{}
  726. pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
  727. if len(pInfo.Ids) > 30 {
  728. //异常标记
  729. set["listtag"] = 1
  730. }
  731. //zbtime、lasttime、jgtime
  732. pInfo.LastTime = thisinfo.Publishtime
  733. set["lasttime"] = thisinfo.Publishtime
  734. if thisinfo.TopType == "招标" {
  735. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" && pInfo.Zbtime <= 0 {
  736. set["zbtime"] = tmp["publishtime"]
  737. }
  738. if pInfo.Jgtime > 0 {
  739. pInfo.Jgtime = int64(0)
  740. set["jgtime"] = int64(0)
  741. }
  742. } else if thisinfo.TopType == "结果" {
  743. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  744. if pInfo.Jgtime > 0 {
  745. jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
  746. //公告状态和项目状态同样都是中标或者成交,
  747. if (thisinfo.SubType == "中标" || thisinfo.SubType == "成交") && (pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交") {
  748. if jg1 > p.jgTime {
  749. set["jgtime"] = tmp["publishtime"]
  750. pInfo.Jgtime = thisinfo.Publishtime
  751. }
  752. //公告状态和项目状态同样是流标或者废标
  753. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (pInfo.Bidstatus == "流标" || pInfo.Bidstatus == "废标") {
  754. if jg1 > p.jgTime {
  755. set["jgtime"] = tmp["publishtime"]
  756. pInfo.Jgtime = thisinfo.Publishtime
  757. }
  758. }
  759. } else {
  760. set["jgtime"] = tmp["publishtime"]
  761. pInfo.Jgtime = thisinfo.Publishtime
  762. }
  763. }
  764. } else if thisinfo.SubType == "合同" {
  765. if pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交" || pInfo.Bidstatus == "" {
  766. //中标、成交不更新jgtime
  767. } else {
  768. set["jgtime"] = tmp["publishtime"]
  769. pInfo.Jgtime = thisinfo.Publishtime
  770. }
  771. }
  772. if thisinfo.Bidopentime > pInfo.Bidopentime {
  773. pInfo.Bidopentime = thisinfo.Bidopentime
  774. set["bidopentime"] = pInfo.Bidopentime
  775. }
  776. bt := qu.ObjToString(tmp["toptype"])
  777. bs := qu.ObjToString(tmp["subtype"])
  778. p.mapBidLock.Lock()
  779. if bt == "招标" {
  780. //招标状态,更新projectscope
  781. if tmp["projectscope"] != nil {
  782. set["projectscope"] = qu.ObjToString(tmp["projectscope"])
  783. }
  784. set["bidstatus"] = bt
  785. pInfo.Bidstatus = bt
  786. if bidtype[bs] != "" {
  787. set["bidtype"] = bidtype[bs]
  788. pInfo.Bidtype = bidtype[bs]
  789. } else {
  790. set["bidtype"] = "招标"
  791. pInfo.Bidtype = "招标"
  792. }
  793. } else {
  794. if bidstatus[bs] != "" {
  795. set["bidstatus"] = thisinfo.SubType
  796. pInfo.Bidstatus = thisinfo.SubType
  797. } else if thisinfo.Infoformat == 2 {
  798. set["bidstatus"] = "拟建"
  799. pInfo.Bidstatus = "拟建"
  800. } else if bs == "" && bt == "结果" {
  801. if pInfo.Bidstatus == "招标" {
  802. set["bidstatus"] = ""
  803. pInfo.Bidstatus = ""
  804. }
  805. } else {
  806. set["bidstatus"] = "其它"
  807. pInfo.Bidstatus = "其它"
  808. }
  809. }
  810. p.mapBidLock.Unlock()
  811. //异常标记
  812. if ex > 0 {
  813. set["exception"] = ex
  814. }
  815. //3\4\5--省、市、县
  816. //if thisinfo.Area != "全国" {
  817. // if pInfo.Area == "全国" {
  818. // pInfo.Area = thisinfo.Area
  819. // set["area"] = thisinfo.Area
  820. // } else if pInfo.Area != thisinfo.Area {
  821. // //xt = false
  822. // }
  823. // if pInfo.City == "" && thisinfo.City != "" {
  824. // pInfo.City = thisinfo.City
  825. // set["city"] = thisinfo.City
  826. // } else if pInfo.City != thisinfo.City {
  827. // //xt = false
  828. // }
  829. // if thisinfo.District != "" && pInfo.District == "" {
  830. // pInfo.District = thisinfo.District
  831. // set["district"] = thisinfo.District
  832. // }
  833. //}
  834. //相同城市的公告才会合并到一起(全国列外)
  835. if thisinfo.Area != "全国" {
  836. pInfo.Area = thisinfo.Area
  837. set["area"] = thisinfo.Area
  838. pInfo.City = thisinfo.City
  839. set["city"] = thisinfo.City
  840. if thisinfo.District != "" {
  841. pInfo.District = thisinfo.District
  842. set["district"] = thisinfo.District
  843. }
  844. }
  845. //6--项目名称
  846. if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  847. pInfo.ProjectName = thisinfo.ProjectName
  848. set["projectname"] = thisinfo.ProjectName
  849. }
  850. //7--项目编号
  851. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  852. pInfo.ProjectCode = thisinfo.ProjectCode
  853. set["projectcode"] = thisinfo.ProjectCode
  854. }
  855. //7--采购单位
  856. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  857. pInfo.Buyer = thisinfo.Buyer
  858. set["buyer"] = thisinfo.Buyer
  859. pInfo.Buyerclass = thisinfo.Buyerclass
  860. set["buyerclass"] = thisinfo.Buyerclass
  861. }
  862. if pInfo.Buyer == "" {
  863. set["buyerclass"] = ""
  864. }
  865. //采购单位联系人
  866. if thisinfo.Buyerperson != "" {
  867. pInfo.Buyerperson = thisinfo.Buyerperson
  868. set["buyerperson"] = pInfo.Buyerperson
  869. } else {
  870. pInfo.Buyerperson = ""
  871. set["buyerperson"] = ""
  872. }
  873. //采购单位電話
  874. if thisinfo.Buyertel != "" {
  875. pInfo.Buyertel = thisinfo.Buyertel
  876. set["buyertel"] = pInfo.Buyertel
  877. } else {
  878. pInfo.Buyertel = ""
  879. set["buyertel"] = ""
  880. }
  881. if thisinfo.ContractCode != "" {
  882. set["contractcode"] = pInfo.ContractCode + "," + thisinfo.ContractCode
  883. }
  884. //8--代理机构
  885. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  886. pInfo.Agency = thisinfo.Agency
  887. set["agency"] = thisinfo.Agency
  888. }
  889. if len(thisinfo.Topscopeclass) > 0 {
  890. sort.Strings(pInfo.Topscopeclass)
  891. for _, k := range thisinfo.Topscopeclass {
  892. if BinarySearch(pInfo.Topscopeclass, k) == -1 {
  893. pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
  894. sort.Strings(pInfo.Topscopeclass)
  895. }
  896. }
  897. set["topscopeclass"] = pInfo.Topscopeclass
  898. }
  899. //项目评审专家
  900. if len(thisinfo.ReviewExperts) > 0 {
  901. set["review_experts"] = thisinfo.ReviewExperts
  902. pInfo.ReviewExperts = thisinfo.ReviewExperts
  903. }
  904. if thisinfo.Purchasing != "" {
  905. if pInfo.Purchasing == "" {
  906. pInfo.Purchasing = thisinfo.Purchasing
  907. set["purchasing"] = thisinfo.Purchasing
  908. } else {
  909. list := strings.Split(pInfo.Purchasing, ",")
  910. for _, k := range list {
  911. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  912. list = append(list, k)
  913. sort.Strings(list)
  914. }
  915. }
  916. set["purchasing"] = strings.Join(list, ",")
  917. }
  918. }
  919. //中标候选人
  920. if len(thisinfo.WinnerOrder) > 0 {
  921. var list = []string{}
  922. for _, v := range thisinfo.WinnerOrder {
  923. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  924. list = append(list, qu.ObjToString(v["entname"]))
  925. }
  926. }
  927. set["winnerorder"] = list
  928. pInfo.Winnerorder = list
  929. }
  930. if len(thisinfo.Subscopeclass) > 0 {
  931. sort.Strings(pInfo.Subscopeclass)
  932. for _, k := range thisinfo.Subscopeclass {
  933. if BinarySearch(pInfo.Subscopeclass, k) == -1 {
  934. pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
  935. sort.Strings(pInfo.Subscopeclass)
  936. }
  937. }
  938. set["subscopeclass"] = pInfo.Subscopeclass
  939. set["s_subscopeclass"] = strings.Join(pInfo.Subscopeclass, ",")
  940. }
  941. if len(thisinfo.Winners) > 0 {
  942. if len(pInfo.Winners) <= 0 {
  943. set["winner"] = qu.ObjToString(tmp["winner"])
  944. }
  945. sort.Strings(pInfo.Winners)
  946. for _, k := range thisinfo.Winners {
  947. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  948. if BinarySearch(pInfo.Winners, k) != -1 {
  949. deleteSlice(pInfo.Winners, k, "")
  950. sort.Strings(pInfo.Winners)
  951. }
  952. } else {
  953. if BinarySearch(pInfo.Winners, k) == -1 {
  954. pInfo.Winners = append(pInfo.Winners, k)
  955. sort.Strings(pInfo.Winners)
  956. }
  957. }
  958. }
  959. set["s_winner"] = strings.Join(pInfo.Winners, ",")
  960. }
  961. //项目规模
  962. if len(thisinfo.ProjectScale) > 0 {
  963. pInfo.ProjectScale = thisinfo.ProjectScale
  964. set["project_scale"] = thisinfo.ProjectScale
  965. }
  966. //工期时长
  967. if thisinfo.ProjectDuration > 0 {
  968. pInfo.ProjectDuration = thisinfo.ProjectDuration
  969. set["project_duration"] = thisinfo.ProjectDuration
  970. }
  971. // 工期单位
  972. if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
  973. pInfo.ProjectTimeunit = thisinfo.ProjectTimeUnit
  974. set["project_timeunit"] = thisinfo.ProjectTimeUnit
  975. }
  976. //开工日期
  977. if thisinfo.ProjectStartDate > 0 {
  978. if pInfo.ProjectStartDate > 0 {
  979. if pInfo.ProjectStartDate < thisinfo.ProjectStartDate {
  980. pInfo.ProjectStartDate = thisinfo.ProjectStartDate
  981. set["project_startdate"] = thisinfo.ProjectStartDate
  982. }
  983. }else {
  984. pInfo.ProjectStartDate = thisinfo.ProjectStartDate
  985. set["project_startdate"] = thisinfo.ProjectStartDate
  986. }
  987. }
  988. //竣工日期
  989. if thisinfo.ProjectCompleteDate > 0 {
  990. if pInfo.ProjctCompleteDate > 0 {
  991. if pInfo.ProjctCompleteDate < thisinfo.ProjectCompleteDate {
  992. pInfo.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  993. set["project_completedate"] = thisinfo.ProjectCompleteDate
  994. }
  995. }else {
  996. pInfo.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  997. set["project_completedate"] = thisinfo.ProjectCompleteDate
  998. }
  999. }
  1000. // 付款方式
  1001. if len(thisinfo.Payway) > 0 {
  1002. pInfo.Payway = thisinfo.Payway
  1003. set["payway"] = thisinfo.Payway
  1004. }
  1005. // 履约保证金
  1006. if tmp["contract_guarantee"] != nil {
  1007. pInfo.ContractGuarantee = thisinfo.ContractGuarantee
  1008. set["contract_guarantee"] = thisinfo.ContractGuarantee
  1009. }
  1010. // 投标保证金
  1011. if tmp["bid_guarantee"] != nil {
  1012. pInfo.BidGuarantee = thisinfo.BidGuarantee
  1013. set["bid_guarantee"] = thisinfo.BidGuarantee
  1014. }
  1015. // 资质条件
  1016. if len(thisinfo.Qualifies) > 0 {
  1017. var str []string
  1018. if len(pInfo.Qualifies) > 0 {
  1019. str = append(str, strings.Split(pInfo.Qualifies, ",")...)
  1020. }
  1021. for _, v := range thisinfo.Qualifies{
  1022. if len(qu.ObjToString(v["key"])) > 0 {
  1023. if BinarySearch(str, qu.ObjToString(v["key"])) == -1 {
  1024. str = append(str, qu.ObjToString(v["key"]))
  1025. }
  1026. }
  1027. }
  1028. if len(str) > 0 {
  1029. pInfo.Qualifies = strings.Join(str, ",")
  1030. set["qualifies"] = strings.Join(str, ",")
  1031. }
  1032. }
  1033. if len(thisinfo.EntIdList) > 0 {
  1034. for _, v := range thisinfo.EntIdList{
  1035. if BinarySearch(pInfo.EntIdList, v) == -1 {
  1036. pInfo.EntIdList = append(pInfo.EntIdList, v)
  1037. }
  1038. }
  1039. set["entidlist"] = pInfo.EntIdList
  1040. }
  1041. if thisinfo.HasPackage { //多包处理
  1042. set["multipackage"] = 1
  1043. pkg := PackageFormat(thisinfo, pInfo)
  1044. pInfo.Package = pkg
  1045. set["package"] = pInfo.Package
  1046. }
  1047. //处理多包后,计算预算金额、中标金额
  1048. CountAmount(pInfo, thisinfo, tmp)
  1049. if pInfo.Budget >= 0 && pInfo.Budgettag != 1 {
  1050. set["budget"] = pInfo.Budget
  1051. set["budgettag"] = 0
  1052. }
  1053. if pInfo.Bidamount >= 0 && pInfo.Bidamounttag != 1 {
  1054. set["bidamount"] = pInfo.Bidamount
  1055. set["bidamounttag"] = 0
  1056. }
  1057. if pInfo.Bidamount >= pInfo.Budget {
  1058. set["sortprice"] = pInfo.Bidamount
  1059. } else if pInfo.Budget >= pInfo.Bidamount {
  1060. set["sortprice"] = pInfo.Budget
  1061. }
  1062. infofield := InfoField{
  1063. Budget: thisinfo.Budget,
  1064. Bidamount: thisinfo.Bidamount,
  1065. ContractCode: thisinfo.ContractCode,
  1066. ProjectName: thisinfo.ProjectName,
  1067. ProjectCode: thisinfo.ProjectCode,
  1068. Bidstatus: bs,
  1069. }
  1070. copyMap := Copy(pInfo.InfoFiled).(map[string]InfoField)
  1071. copyMap[thisinfo.Id] = infofield
  1072. tmpMap := make(map[string]interface{})
  1073. for k, v := range copyMap {
  1074. tmpMap[k] = StructToMap(v)
  1075. }
  1076. tmpMap[thisinfo.Id] = StructToMap(infofield)
  1077. pInfo.InfoFiled = copyMap
  1078. set["infofield"] = tmpMap
  1079. set["mpn"] = pInfo.MPN
  1080. set["mpc"] = pInfo.MPC
  1081. if p.currentType == "project" {
  1082. set["pici"] = p.pici
  1083. } else {
  1084. set["pici"] = tmp["comeintime"]
  1085. }
  1086. update := map[string]interface{}{}
  1087. if len(set) > 0 {
  1088. update["$set"] = set
  1089. }
  1090. push := p.PushListInfo(tmp, thisinfo.Id)
  1091. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  1092. push["compareStr"] = comStr
  1093. push["resVal"] = pInfo.resVal
  1094. push["pjVal"] = pInfo.pjVal
  1095. update["$push"] = map[string]interface{}{
  1096. "list": push,
  1097. "ids": thisinfo.Id,
  1098. }
  1099. //clearMap := map[string]interface{}{}
  1100. //ClearData(clearMap, set)
  1101. //if len(clearMap) > 0 {
  1102. // update["$unset"] = clearMap
  1103. //}
  1104. if len(update) > 0 {
  1105. updateInfo := []map[string]interface{}{
  1106. {
  1107. "_id": pInfo.Id,
  1108. },
  1109. update,
  1110. }
  1111. p.updatePool <- updateInfo
  1112. }
  1113. }
  1114. /**
  1115. * 更新项目时,项目状态的处理
  1116. * 返回是否新增项目,异常标记
  1117. * 1、新增项目时,招标信息的状态(toptype)不是招标、拟建、预告 异常:1
  1118. * 异常1是在项目新建的时候才会产生
  1119. * 3、项目合并时,项目状态是”流标“/”废标“,招标信息状态不是”招标“ 异常:2
  1120. * 4、项目合并时,项目状态是”合同“/”其它“,招标信息类型是”结果“ 异常:3
  1121. */
  1122. func (p *ProjectTask) CompareStatus(project *ProjectInfo, info *Info) (bool, int) {
  1123. if info.TopType == "拟建" || info.TopType == "预告" || info.TopType == "招标" {
  1124. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  1125. return false, 0
  1126. } else if project.Bidstatus == "废标" || project.Bidstatus == "流标" {
  1127. return false, 0
  1128. } else {
  1129. return true, 0
  1130. }
  1131. } else if info.TopType == "结果" {
  1132. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  1133. return false, 0
  1134. } else if project.Bidstatus == info.SubType {
  1135. //状态一样,根据发布时间判断是否合并
  1136. if (info.Publishtime - project.LastTime) > p.statusTime {
  1137. return true, 0
  1138. } else {
  1139. return false, 0
  1140. }
  1141. } else if project.Bidstatus == "成交" && info.SubType == "中标" {
  1142. return true, 0
  1143. } else if project.Bidstatus == "流标" || project.Bidstatus == "废标" {
  1144. return false, 2
  1145. } else if project.Bidstatus == "合同" || project.Bidstatus == "其它" {
  1146. return false, 3
  1147. } else {
  1148. return false, 0
  1149. }
  1150. } else {
  1151. return false, 0
  1152. }
  1153. }
  1154. /*
  1155. * 对比地区(省、市),存在且不同,不能合并
  1156. * 返回是否新建项目
  1157. */
  1158. func ComparePlace(project *ProjectInfo, info *Info) bool {
  1159. if info.Area == "全国" || info.Area == "" {
  1160. return false
  1161. }
  1162. if project.Area == "全国" || project.Area == "" {
  1163. return false
  1164. }
  1165. if info.Area == project.Area {
  1166. if info.City == "" || project.City == "" {
  1167. return false
  1168. } else if info.City == project.City {
  1169. return false
  1170. }
  1171. } else {
  1172. return true
  1173. }
  1174. return true
  1175. }
  1176. var PackageEle = []string{
  1177. "origin",
  1178. "name",
  1179. //"text",
  1180. "budget",
  1181. "winner",
  1182. "bidamount",
  1183. "bidamounttype",
  1184. "currency",
  1185. "bidstatus",
  1186. }
  1187. func packageEle(map1 map[string]interface{}, id string) map[string]interface{} {
  1188. p2 := map[string]interface{}{}
  1189. for _, k := range PackageEle {
  1190. if map1[k] != nil {
  1191. p2[k] = map1[k]
  1192. }
  1193. infoid := p2["infoid"]
  1194. if infoid == nil {
  1195. p2["infoid"] = id
  1196. }
  1197. }
  1198. return p2
  1199. }
  1200. func PackageFormat(info *Info, project *ProjectInfo) map[string]interface{} {
  1201. p1 := map[string]interface{}{}
  1202. if project != nil && project.Package != nil && len(project.Package) > 0 {
  1203. packageCopy := Copy(project.Package).(map[string]interface{})
  1204. p1 = packageCopy
  1205. for k, v := range info.Package {
  1206. if v1, ok := v.(map[string]interface{}); ok {
  1207. v2 := map[string]interface{}{}
  1208. v2 = packageEle(v1, info.Id)
  1209. if v2["bidstatus"] == nil {
  1210. v2["bidstatus"] = info.SubType
  1211. }
  1212. addFlag := false
  1213. for k1, v3 := range p1 {
  1214. if v4, ok := v3.([]map[string]interface{}); ok {
  1215. //if qu.ObjToString(v4[0]["origin"]) == qu.ObjToString(v2["origin"]) && qu.ObjToString(v4[0]["name"]) == qu.ObjToString(v2["name"]) {
  1216. if k1 == k {
  1217. v4 = append(v4, v2)
  1218. p1[k1] = v4
  1219. addFlag = true
  1220. break
  1221. }
  1222. }
  1223. }
  1224. if !addFlag {
  1225. p1[k] = []map[string]interface{}{v2}
  1226. }
  1227. }
  1228. }
  1229. } else {
  1230. for k, v := range info.Package {
  1231. v1, _ := v.(map[string]interface{})
  1232. p2 := map[string]interface{}{}
  1233. p2 = packageEle(v1, info.Id)
  1234. if p2["bidstatus"] == nil {
  1235. p2["bidstatus"] = info.SubType
  1236. }
  1237. p1[k] = []map[string]interface{}{p2}
  1238. }
  1239. }
  1240. return p1
  1241. }
  1242. // 计算预算(budget)、中标金额(bidamount)
  1243. func CountAmount(project *ProjectInfo, info *Info, tmp map[string]interface{}) {
  1244. if info.HasPackage {
  1245. budget := 0.0
  1246. for _, v := range project.Package {
  1247. v1, _ := v.([]map[string]interface{})
  1248. for _, v2 := range v1 {
  1249. if v2["budget"] != nil {
  1250. b1 := qu.Float64All(v2["budget"])
  1251. if b1 > 0 {
  1252. budget = budget + b1
  1253. break
  1254. }
  1255. } else {
  1256. project.Budgettag = 1
  1257. }
  1258. }
  1259. }
  1260. if budget > 0 {
  1261. project.Budget = budget
  1262. project.Budgettag = 0
  1263. } else if budget == 0 && info.Budget > 0 {
  1264. project.Budget = info.Budget
  1265. project.Budgettag = 0
  1266. }
  1267. } else {
  1268. //招标没有多包
  1269. k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1270. if len(k) > 0 {
  1271. //招标是单包
  1272. if len(project.Package) > 0 {
  1273. //项目有多包
  1274. flag := false
  1275. for _, v := range project.Package {
  1276. v1, _ := v.([]map[string]interface{})
  1277. if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1278. flag = true
  1279. }
  1280. }
  1281. if !flag {
  1282. project.Budget = project.Budget + info.Budget
  1283. project.Budgettag = 0
  1284. }
  1285. } else {
  1286. //项目没有多包
  1287. if info.Budget > 0 {
  1288. project.Budget = project.Budget + info.Budget
  1289. project.Budgettag = 0
  1290. } else if info.Budget == 0 && tmp["budget"] != nil {
  1291. project.Budgettag = 0
  1292. }
  1293. }
  1294. } else {
  1295. if info.Budget > 0 && project.Budget < info.Budget {
  1296. project.Budget = info.Budget
  1297. project.Budgettag = 0
  1298. }
  1299. }
  1300. }
  1301. if info.SubType == "中标" || info.SubType == "成交" || info.SubType == "合同" {
  1302. if info.HasPackage {
  1303. bidamount := 0.0
  1304. for _, v := range project.Package {
  1305. v1, _ := v.([]map[string]interface{})
  1306. for _, v2 := range v1 {
  1307. b1 := qu.Float64All(v2["bidamount"])
  1308. if b1 > 0 {
  1309. bidamount = bidamount + b1
  1310. break
  1311. }
  1312. }
  1313. }
  1314. if bidamount > 0 {
  1315. project.Bidamount = bidamount
  1316. project.Bidamounttag = 0
  1317. } else if bidamount == 0 && info.Bidamount > 0 {
  1318. project.Bidamount = info.Bidamount
  1319. project.Bidamounttag = 0
  1320. }
  1321. } else {
  1322. //招标没有多包
  1323. k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1324. if len(k) > 0 {
  1325. //招标是单包
  1326. if len(project.Package) > 0 {
  1327. //项目有多包
  1328. flag := false
  1329. for _, v := range project.Package {
  1330. v1, _ := v.([]map[string]interface{})
  1331. if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1332. flag = true
  1333. }
  1334. }
  1335. if !flag {
  1336. project.Bidamount = project.Bidamount + info.Bidamount
  1337. project.Bidamounttag = 0
  1338. }
  1339. } else {
  1340. //项目没有多包
  1341. if info.Bidamount > 0 {
  1342. project.Bidamount = project.Bidamount + info.Bidamount
  1343. project.Bidamounttag = 0
  1344. } else if info.Bidamount == 0 && tmp["bidamount"] != nil {
  1345. project.Bidamounttag = 0
  1346. } else {
  1347. project.Bidamounttag = 1
  1348. }
  1349. }
  1350. } else {
  1351. if info.SubType == "中标" || info.SubType == "成交" {
  1352. if info.Bidamount > 0 {
  1353. project.Bidamount = info.Bidamount
  1354. project.Bidamounttag = 0
  1355. } else {
  1356. flag := false
  1357. if project.InfoFiled != nil && len(project.InfoFiled) > 0 {
  1358. for _, res := range project.InfoFiled {
  1359. if res.ContractCode != "" && res.ContractCode == info.ContractCode {
  1360. flag = true
  1361. break
  1362. }
  1363. if res.Bidamount == project.Bidamount {
  1364. flag = true
  1365. break
  1366. }
  1367. }
  1368. if !flag {
  1369. project.Bidamount = project.Bidamount + info.Bidamount
  1370. project.Bidamounttag = 0
  1371. } else {
  1372. if info.Budget > 0 && project.Bidamount > info.Bidamount {
  1373. project.Bidamount = info.Bidamount
  1374. project.Bidamounttag = 0
  1375. }
  1376. }
  1377. }
  1378. }
  1379. }
  1380. }
  1381. }
  1382. } else {
  1383. project.Bidamounttag = 1
  1384. }
  1385. }
  1386. //结构体转map
  1387. func StructToMap(filed InfoField) map[string]interface{} {
  1388. //先转json
  1389. result, err := json.Marshal(filed)
  1390. if err != nil {
  1391. return nil
  1392. }
  1393. //json转map
  1394. res := make(map[string]interface{})
  1395. err = json.Unmarshal(result, &res)
  1396. return res
  1397. }
  1398. func ClearData(clearMap, tmp map[string]interface{}) {
  1399. for k, v := range tmp {
  1400. if v == "" {
  1401. clearMap[k] = ""
  1402. }
  1403. }
  1404. }
  1405. func IsCreatePro(info *Info) (bol bool) {
  1406. bol = true
  1407. if info.SubType == "" || info.SubType == "变更" || info.SubType == "验收" || info.SubType == "违规" ||
  1408. info.SubType == "结果变更" || info.SubType == "其它" {
  1409. if info.ProjectName == "" && info.ProjectCode == "" {
  1410. bol = false
  1411. }else if info.ProjectName == "" && info.Buyer == "" {
  1412. bol = false
  1413. }else if info.ProjectCode == "" && info.Buyer == "" {
  1414. bol = false
  1415. }
  1416. }
  1417. return bol
  1418. }
  1419. var bidtype = map[string]string{
  1420. "招标": "招标",
  1421. "邀标": "邀标",
  1422. "询价": "询价",
  1423. "单一": "单一",
  1424. "竞价": "竞价",
  1425. "竞谈": "竞谈",
  1426. }
  1427. var bidstatus = map[string]string{
  1428. "预告": "预告",
  1429. "中标": "中标",
  1430. "成交": "成交",
  1431. "废标": "废标",
  1432. "流标": "流标",
  1433. "合同": "合同",
  1434. }
  1435. func GetBidTypeAndBidStatus(info *Info) (string, string) {
  1436. typeStr := bidtype[info.TopType]
  1437. statusStr := bidstatus[info.SubType]
  1438. if info.Infoformat == 2 || info.SubType == "拟建" {
  1439. statusStr = "拟建"
  1440. typeStr = ""
  1441. } else {
  1442. if bidtype[typeStr] == "" {
  1443. typeStr = "招标"
  1444. }
  1445. if typeStr == "招标" {
  1446. statusStr = typeStr
  1447. } else {
  1448. if statusStr == "" {
  1449. statusStr = "其它"
  1450. }
  1451. }
  1452. }
  1453. return typeStr, statusStr
  1454. }