project.go 33 KB

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