project.go 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  1. package main
  2. import (
  3. "go.mongodb.org/mongo-driver/bson"
  4. "go.mongodb.org/mongo-driver/bson/primitive"
  5. "go.uber.org/zap"
  6. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  7. "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
  8. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  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 BinarySearch(pInfo.Ids, thisinfo.Id) > -1 {
  698. log.Info("repeat", zap.String("info", thisinfo.Id), zap.Any("pid", pInfo.Id))
  699. return
  700. }
  701. set := map[string]interface{}{}
  702. pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
  703. //zbtime、lasttime、jgtime
  704. pInfo.LastTime = thisinfo.Publishtime
  705. set["lasttime"] = thisinfo.Publishtime
  706. if thisinfo.TopType == "招标" {
  707. if pInfo.Zbtime <= 0 {
  708. pInfo.Zbtime = thisinfo.Publishtime
  709. set["zbtime"] = tmp["publishtime"]
  710. }
  711. if pInfo.Jgtime > 0 {
  712. pInfo.Jgtime = int64(0)
  713. set["jgtime"] = int64(0)
  714. }
  715. } else if thisinfo.TopType == "结果" {
  716. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  717. if pInfo.Jgtime > 0 {
  718. //jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
  719. //公告状态和项目状态同样都是中标或者成交,
  720. if thisinfo.SubType == "成交" && pInfo.Bidstatus == "中标" {
  721. if jgTime < thisinfo.Publishtime {
  722. pInfo.Jgtime = thisinfo.Publishtime
  723. set["jgtime"] = tmp["publishtime"]
  724. }
  725. //公告状态和项目状态同样是流标或者废标
  726. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (pInfo.Bidstatus == "流标" || pInfo.Bidstatus == "废标") {
  727. if jgTime < thisinfo.Publishtime {
  728. pInfo.Jgtime = thisinfo.Publishtime
  729. set["jgtime"] = tmp["publishtime"]
  730. }
  731. }
  732. } else {
  733. pInfo.Jgtime = thisinfo.Publishtime
  734. set["jgtime"] = tmp["publishtime"]
  735. }
  736. }
  737. } else if thisinfo.SubType == "合同" {
  738. if pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交" || pInfo.Bidstatus == "" {
  739. //中标、成交不更新jgtime
  740. } else {
  741. pInfo.Jgtime = thisinfo.Publishtime
  742. set["jgtime"] = tmp["publishtime"]
  743. }
  744. }
  745. if thisinfo.Bidopentime > pInfo.Bidopentime {
  746. pInfo.Bidopentime = thisinfo.Bidopentime
  747. set["bidopentime"] = pInfo.Bidopentime
  748. }
  749. bt := util.ObjToString(tmp["toptype"])
  750. bs := util.ObjToString(tmp["subtype"])
  751. mapBidLock.Lock()
  752. if bt == "招标" {
  753. //招标状态,更新projectscope
  754. if tmp["projectscope"] != nil {
  755. set["projectscope"] = util.ObjToString(tmp["projectscope"])
  756. }
  757. set["bidstatus"] = bt
  758. pInfo.Bidstatus = bt
  759. if bidtype[bs] != "" {
  760. set["bidtype"] = bidtype[bs]
  761. pInfo.Bidtype = bidtype[bs]
  762. } else {
  763. set["bidtype"] = "招标"
  764. pInfo.Bidtype = "招标"
  765. }
  766. } else {
  767. if bidstatus[bs] != "" {
  768. set["bidstatus"] = thisinfo.SubType
  769. pInfo.Bidstatus = thisinfo.SubType
  770. } else if thisinfo.Infoformat == 2 {
  771. set["bidstatus"] = "拟建"
  772. pInfo.Bidstatus = "拟建"
  773. } else if bs == "" && bt == "结果" {
  774. if pInfo.Bidstatus == "招标" {
  775. set["bidstatus"] = ""
  776. pInfo.Bidstatus = ""
  777. }
  778. } else {
  779. set["bidstatus"] = "其它"
  780. pInfo.Bidstatus = "其它"
  781. }
  782. }
  783. mapBidLock.Unlock()
  784. //相同城市的公告才会合并到一起(全国列外)
  785. if thisinfo.Area != "全国" {
  786. pInfo.Area = thisinfo.Area
  787. set["area"] = thisinfo.Area
  788. if thisinfo.City != "" {
  789. pInfo.City = thisinfo.City
  790. set["city"] = thisinfo.City
  791. }
  792. if thisinfo.District != "" {
  793. pInfo.District = thisinfo.District
  794. set["district"] = thisinfo.District
  795. }
  796. }
  797. //项目名称
  798. //if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  799. if pInfo.ProjectName == "" && thisinfo.ProjectName != "" {
  800. pInfo.ProjectName = thisinfo.ProjectName
  801. set["projectname"] = thisinfo.ProjectName
  802. }
  803. //7--项目编号
  804. //if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  805. if pInfo.ProjectCode == "" && thisinfo.ProjectCode != "" {
  806. pInfo.ProjectCode = thisinfo.ProjectCode
  807. set["projectcode"] = thisinfo.ProjectCode
  808. }
  809. //7--采购单位
  810. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  811. pInfo.Buyer = thisinfo.Buyer
  812. set["buyer"] = thisinfo.Buyer
  813. pInfo.Buyerclass = thisinfo.Buyerclass
  814. set["buyerclass"] = thisinfo.Buyerclass
  815. }
  816. if pInfo.Buyer == "" {
  817. pInfo.Buyerclass = ""
  818. set["buyerclass"] = ""
  819. }
  820. //采购单位联系人
  821. if thisinfo.Buyerperson != "" {
  822. pInfo.Buyerperson = thisinfo.Buyerperson
  823. set["buyerperson"] = thisinfo.Buyerperson
  824. } else {
  825. pInfo.Buyerperson = ""
  826. set["buyerperson"] = ""
  827. }
  828. //采购单位電話
  829. if thisinfo.Buyertel != "" {
  830. pInfo.Buyertel = thisinfo.Buyertel
  831. set["buyertel"] = pInfo.Buyertel
  832. } else {
  833. pInfo.Buyertel = ""
  834. set["buyertel"] = ""
  835. }
  836. if thisinfo.ContractCode != "" {
  837. if pInfo.ContractCode == "" {
  838. set["contractcode"] = thisinfo.ContractCode
  839. } else {
  840. list := strings.Split(pInfo.ContractCode, ",")
  841. if BinarySearch(list, thisinfo.ContractCode) == -1 {
  842. list = append(list, thisinfo.ContractCode)
  843. sort.Strings(list)
  844. }
  845. set["contractcode"] = strings.Join(list, ",")
  846. }
  847. }
  848. //8--代理机构
  849. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  850. pInfo.Agency = thisinfo.Agency
  851. set["agency"] = thisinfo.Agency
  852. }
  853. if len(thisinfo.Topscopeclass) > 0 {
  854. sort.Strings(pInfo.Topscopeclass)
  855. for _, k := range thisinfo.Topscopeclass {
  856. if BinarySearch(pInfo.Topscopeclass, k) == -1 {
  857. pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
  858. sort.Strings(pInfo.Topscopeclass)
  859. }
  860. }
  861. set["topscopeclass"] = pInfo.Topscopeclass
  862. }
  863. if thisinfo.Purchasing != "" {
  864. if pInfo.Purchasing == "" {
  865. list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
  866. p := strings.Join(util.ObjArrToStringArr(list), ",")
  867. pInfo.Purchasing = p
  868. set["purchasing"] = p
  869. } else {
  870. list := strings.Split(pInfo.Purchasing, ",")
  871. list = util.ObjArrToStringArr(Duplicate(list))
  872. for _, k := range list {
  873. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  874. list = append(list, k)
  875. sort.Strings(list)
  876. }
  877. }
  878. set["purchasing"] = strings.Join(list, ",")
  879. }
  880. }
  881. // 标的物
  882. if tmp["purchasinglist"] != nil && len(util.ObjArrToMapArr(tmp["purchasinglist"].([]interface{}))) > 0 {
  883. if thisinfo.TopType == "招标" || thisinfo.TopType == "预告" {
  884. set["zb_plist"] = tmp["purchasinglist"]
  885. } else {
  886. set["jg_plist"] = tmp["purchasinglist"]
  887. }
  888. }
  889. set["sourceinfoid"] = thisinfo.Id
  890. //中标候选人
  891. if len(thisinfo.WinnerOrder) > 0 {
  892. var list = []string{}
  893. for _, v := range thisinfo.WinnerOrder {
  894. if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
  895. list = append(list, util.ObjToString(v["entname"]))
  896. }
  897. }
  898. set["winnerorder"] = list
  899. pInfo.Winnerorder = list
  900. }
  901. if len(thisinfo.Subscopeclass) > 0 {
  902. sort.Strings(pInfo.Subscopeclass)
  903. for _, k := range thisinfo.Subscopeclass {
  904. if BinarySearch(pInfo.Subscopeclass, k) == -1 {
  905. pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
  906. sort.Strings(pInfo.Subscopeclass)
  907. }
  908. }
  909. set["subscopeclass"] = pInfo.Subscopeclass
  910. set["s_subscopeclass"] = strings.Join(pInfo.Subscopeclass, ",")
  911. }
  912. if len(thisinfo.Winners) > 0 {
  913. var winners []string
  914. if pInfo.Winners == "" {
  915. set["winner"] = util.ObjToString(tmp["winner"])
  916. for _, k := range thisinfo.Winners {
  917. if k == "" {
  918. continue
  919. }
  920. if BinarySearch(winners, k) == -1 {
  921. winners = append(winners, k)
  922. }
  923. }
  924. } else {
  925. winners = strings.Split(pInfo.Winners, ",")
  926. for _, k := range thisinfo.Winners {
  927. if k == "" {
  928. continue
  929. }
  930. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  931. if BinarySearch(winners, k) != -1 {
  932. deleteSlice(winners, k, "")
  933. }
  934. } else {
  935. if BinarySearch(winners, k) == -1 {
  936. winners = append(winners, k)
  937. }
  938. }
  939. }
  940. }
  941. set["s_winner"] = strings.Join(util.ObjArrToStringArr(Duplicate(winners)), ",")
  942. if util.ObjToString(tmp["winnertel"]) != "" {
  943. set["winnertel"] = tmp["winnertel"]
  944. }
  945. if util.ObjToString(tmp["winnerperson"]) != "" {
  946. set["winnerperson"] = tmp["winnerperson"]
  947. }
  948. }
  949. if thisinfo.HasPackage { //多包处理
  950. set["multipackage"] = 1
  951. pkg := PackageFormat(thisinfo, pInfo)
  952. pInfo.Package = pkg
  953. set["package"] = pInfo.Package
  954. }
  955. //处理多包后,计算预算金额、中标金额
  956. CountAmount(pInfo, thisinfo, tmp)
  957. if pInfo.Budget >= 0 && pInfo.Budgettag != 1 {
  958. pInfo.Budget = pInfo.Budget
  959. set["budget"] = pInfo.Budget
  960. set["budgettag"] = 0
  961. }
  962. if pInfo.Bidamount >= 0 && pInfo.Bidamounttag != 1 {
  963. pInfo.Bidamount = pInfo.Bidamount
  964. set["bidamount"] = pInfo.Bidamount
  965. set["bidamounttag"] = 0
  966. }
  967. if pInfo.Bidamount > 0 {
  968. set["sortprice"] = pInfo.Bidamount
  969. } else {
  970. if pInfo.Budget > 0 {
  971. set["sortprice"] = pInfo.Budget
  972. }
  973. }
  974. infofield := InfoField{
  975. Budget: thisinfo.Budget,
  976. Bidamount: thisinfo.Bidamount,
  977. ContractCode: thisinfo.ContractCode,
  978. ProjectName: thisinfo.ProjectName,
  979. ProjectCode: thisinfo.ProjectCode,
  980. Bidstatus: bs,
  981. }
  982. copyMap := Copy(pInfo.InfoFiled).(map[string]InfoField)
  983. copyMap[thisinfo.Id] = infofield
  984. tmpMap := make(map[string]interface{})
  985. for k, v := range copyMap {
  986. tmpMap[k] = StructToMap(v)
  987. }
  988. tmpMap[thisinfo.Id] = StructToMap(infofield)
  989. pInfo.InfoFiled = copyMap
  990. set["infofield"] = tmpMap
  991. if currentType == "project" {
  992. set["pici"] = pici
  993. } else {
  994. set["pici"] = tmp["comeintime"]
  995. }
  996. update := map[string]interface{}{}
  997. if len(set) > 0 {
  998. update["$set"] = set
  999. }
  1000. push := PushListInfo(tmp, thisinfo.Id)
  1001. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  1002. push["compareStr"] = comStr
  1003. push["resVal"] = pInfo.resVal
  1004. push["pjVal"] = pInfo.pjVal
  1005. update["$push"] = map[string]interface{}{
  1006. "list": push,
  1007. "ids": thisinfo.Id,
  1008. }
  1009. if len(update) > 0 {
  1010. updateInfo := []map[string]interface{}{
  1011. {
  1012. "_id": pInfo.Id,
  1013. },
  1014. update,
  1015. }
  1016. updatePool <- updateInfo
  1017. }
  1018. }
  1019. // 计算预算(budget)、中标金额(bidamount)
  1020. func CountAmount(project *Project, info *Info, tmp map[string]interface{}) {
  1021. if info.HasPackage {
  1022. budget := 0.0
  1023. for _, v := range project.Package {
  1024. v1, _ := v.([]map[string]interface{})
  1025. for _, v2 := range v1 {
  1026. if v2["budget"] != nil {
  1027. b1 := util.Float64All(v2["budget"])
  1028. if b1 > 0 {
  1029. budget = budget + b1
  1030. break
  1031. }
  1032. } else {
  1033. project.Budgettag = 1
  1034. }
  1035. }
  1036. }
  1037. if budget > 0 {
  1038. project.Budget = budget
  1039. project.Budgettag = 0
  1040. } else if budget == 0 && info.Budget > 0 {
  1041. project.Budget = info.Budget
  1042. project.Budgettag = 0
  1043. }
  1044. } else {
  1045. //招标没有多包
  1046. k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1047. if len(k) > 0 {
  1048. //招标是单包
  1049. if len(project.Package) > 0 {
  1050. //项目有多包
  1051. flag := false
  1052. for _, v := range project.Package {
  1053. v1, _ := v.([]map[string]interface{})
  1054. if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1055. flag = true
  1056. }
  1057. }
  1058. if !flag {
  1059. project.Budget = project.Budget + info.Budget
  1060. project.Budgettag = 0
  1061. }
  1062. } else {
  1063. //项目没有多包
  1064. if info.Budget > 0 {
  1065. project.Budget = project.Budget + info.Budget
  1066. project.Budgettag = 0
  1067. } else if info.Budget == 0 && tmp["budget"] != nil {
  1068. project.Budgettag = 0
  1069. }
  1070. }
  1071. } else {
  1072. if info.Budget > 0 && project.Budget < info.Budget {
  1073. project.Budget = info.Budget
  1074. project.Budgettag = 0
  1075. }
  1076. }
  1077. }
  1078. if info.SubType == "中标" || info.SubType == "成交" || info.SubType == "合同" {
  1079. if info.HasPackage {
  1080. bidamount := 0.0
  1081. for _, v := range project.Package {
  1082. v1, _ := v.([]map[string]interface{})
  1083. for _, v2 := range v1 {
  1084. b1 := util.Float64All(v2["bidamount"])
  1085. if b1 > 0 {
  1086. bidamount = bidamount + b1
  1087. break
  1088. }
  1089. }
  1090. }
  1091. if bidamount > 0 {
  1092. project.Bidamount = bidamount
  1093. project.Bidamounttag = 0
  1094. } else if bidamount == 0 && info.Bidamount > 0 {
  1095. project.Bidamount = info.Bidamount
  1096. project.Bidamounttag = 0
  1097. }
  1098. } else {
  1099. //招标没有多包
  1100. k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1101. if len(k) > 0 {
  1102. //招标是单包
  1103. if len(project.Package) > 0 {
  1104. //项目有多包
  1105. flag := false
  1106. for _, v := range project.Package {
  1107. v1, _ := v.([]map[string]interface{})
  1108. if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1109. flag = true
  1110. }
  1111. }
  1112. if !flag {
  1113. project.Bidamount = project.Bidamount + info.Bidamount
  1114. project.Bidamounttag = 0
  1115. }
  1116. } else {
  1117. //项目没有多包
  1118. if info.Bidamount > 0 {
  1119. project.Bidamount = project.Bidamount + info.Bidamount
  1120. project.Bidamounttag = 0
  1121. } else if info.Bidamount == 0 && tmp["bidamount"] != nil {
  1122. project.Bidamounttag = 0
  1123. } else {
  1124. project.Bidamounttag = 1
  1125. }
  1126. }
  1127. } else {
  1128. if info.SubType == "中标" || info.SubType == "成交" {
  1129. if info.Bidamount > 0 {
  1130. project.Bidamount = info.Bidamount
  1131. project.Bidamounttag = 0
  1132. } else {
  1133. flag := false
  1134. if project.InfoFiled != nil && len(project.InfoFiled) > 0 {
  1135. for _, res := range project.InfoFiled {
  1136. if res.ContractCode != "" && res.ContractCode == info.ContractCode {
  1137. flag = true
  1138. break
  1139. }
  1140. if res.Bidamount == project.Bidamount {
  1141. flag = true
  1142. break
  1143. }
  1144. }
  1145. if !flag {
  1146. project.Bidamount = project.Bidamount + info.Bidamount
  1147. project.Bidamounttag = 0
  1148. } else {
  1149. if info.Budget > 0 && project.Bidamount > info.Bidamount {
  1150. project.Bidamount = info.Bidamount
  1151. project.Bidamounttag = 0
  1152. }
  1153. }
  1154. }
  1155. }
  1156. }
  1157. }
  1158. }
  1159. } else {
  1160. project.Bidamounttag = 1
  1161. }
  1162. }