project.go 41 KB

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