project.go 33 KB

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