project.go 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  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. infofiled := 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] = infofiled
  540. res := StructToMap(infofiled)
  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 != "ql" && 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 == "成交" {
  686. //中标、成交不更新jgtime
  687. return
  688. }
  689. set["jgtime"] = tmp["publishtime"]
  690. pInfo.Jgtime = thisinfo.Publishtime
  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 == "" {
  717. set["bidstatus"] = ""
  718. pInfo.Bidstatus = ""
  719. } else {
  720. set["bidstatus"] = "其它"
  721. pInfo.Bidstatus = "其它"
  722. }
  723. }
  724. p.mapBidLock.Unlock()
  725. //异常标记
  726. if ex > 0 {
  727. set["exception"] = ex
  728. }
  729. //3\4\5--省、市、县
  730. if thisinfo.Area != "全国" {
  731. if pInfo.Area == "全国" {
  732. pInfo.Area = thisinfo.Area
  733. set["area"] = thisinfo.Area
  734. } else if pInfo.Area != thisinfo.Area {
  735. //xt = false
  736. }
  737. if pInfo.City == "" && thisinfo.City != "" {
  738. pInfo.City = thisinfo.City
  739. set["city"] = thisinfo.City
  740. } else if pInfo.City != thisinfo.City {
  741. //xt = false
  742. }
  743. if thisinfo.District != "" && pInfo.District == "" {
  744. pInfo.District = thisinfo.District
  745. set["district"] = thisinfo.District
  746. }
  747. }
  748. //6--项目名称
  749. if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  750. pInfo.ProjectName = thisinfo.ProjectName
  751. set["projectname"] = thisinfo.ProjectName
  752. }
  753. //7--项目编号
  754. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  755. pInfo.ProjectCode = thisinfo.ProjectCode
  756. set["projectcode"] = thisinfo.ProjectCode
  757. }
  758. //7--采购单位
  759. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  760. pInfo.Buyer = thisinfo.Buyer
  761. set["buyer"] = thisinfo.Buyer
  762. pInfo.Buyerclass = thisinfo.Buyerclass
  763. set["buyerclass"] = thisinfo.Buyerclass
  764. }
  765. if pInfo.Buyer == "" {
  766. set["buyerclass"] = ""
  767. }
  768. if thisinfo.ContractCode != "" {
  769. set["contractcode"] = pInfo.ContractCode + "," + thisinfo.ContractCode
  770. }
  771. //8--代理机构
  772. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  773. pInfo.Agency = thisinfo.Agency
  774. set["agency"] = thisinfo.Agency
  775. }
  776. //9--采购单位联系人
  777. if thisinfo.Buyerperson != "" && strings.Index(pInfo.Buyerperson, thisinfo.Buyerperson) < 0 {
  778. pInfo.Buyerperson = thisinfo.Buyerperson
  779. set["buyerperson"] = pInfo.Buyerperson
  780. }
  781. //10--采购单位電話
  782. if thisinfo.Buyertel != "" && strings.Index(pInfo.Buyertel, thisinfo.Buyertel) < 0 {
  783. pInfo.Buyertel = thisinfo.Buyertel
  784. set["buyertel"] = pInfo.Buyertel
  785. }
  786. if len(thisinfo.Topscopeclass) > 0 {
  787. sort.Strings(pInfo.Topscopeclass)
  788. for _, k := range thisinfo.Topscopeclass {
  789. if BinarySearch(pInfo.Topscopeclass, k) == -1 {
  790. pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
  791. sort.Strings(pInfo.Topscopeclass)
  792. }
  793. }
  794. set["topscopeclass"] = pInfo.Topscopeclass
  795. }
  796. if len(thisinfo.Subscopeclass) > 0 {
  797. sort.Strings(pInfo.Subscopeclass)
  798. for _, k := range thisinfo.Subscopeclass {
  799. if BinarySearch(pInfo.Subscopeclass, k) == -1 {
  800. pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
  801. sort.Strings(pInfo.Subscopeclass)
  802. }
  803. }
  804. set["subscopeclass"] = pInfo.Subscopeclass
  805. set["s_subscopeclass"] = strings.Join(pInfo.Subscopeclass, ",")
  806. }
  807. if len(thisinfo.Winners) > 0 {
  808. if len(pInfo.Winners) <= 0 {
  809. set["winner"] = qu.ObjToString(tmp["winner"])
  810. }
  811. sort.Strings(pInfo.Winners)
  812. for _, k := range thisinfo.Winners {
  813. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  814. if BinarySearch(pInfo.Winners, k) != -1 {
  815. deleteSlice(pInfo.Winners, k, "")
  816. sort.Strings(pInfo.Winners)
  817. }
  818. }else {
  819. if BinarySearch(pInfo.Winners, k) == -1 {
  820. pInfo.Winners = append(pInfo.Winners, k)
  821. sort.Strings(pInfo.Winners)
  822. }
  823. }
  824. }
  825. set["s_winner"] = strings.Join(pInfo.Winners, ",")
  826. }
  827. if thisinfo.HasPackage { //多包处理
  828. set["multipackage"] = 1
  829. pkg := PackageFormat(thisinfo, pInfo)
  830. pInfo.Package = pkg
  831. set["package"] = pInfo.Package
  832. }
  833. //处理多包后,计算预算金额、中标金额
  834. CountAmount(pInfo, thisinfo, tmp)
  835. if pInfo.Budget >= 0 && pInfo.Budgettag != 1 {
  836. set["budget"] = pInfo.Budget
  837. set["budgettag"] = 0
  838. }
  839. if pInfo.Bidamount >= 0 && pInfo.Bidamounttag != 1 {
  840. set["bidamount"] = pInfo.Bidamount
  841. set["bidamounttag"] = 0
  842. }
  843. if pInfo.Bidamount >= pInfo.Budget {
  844. set["sortprice"] = pInfo.Bidamount
  845. }else if pInfo.Budget >= pInfo.Bidamount {
  846. set["sortprice"] = pInfo.Budget
  847. }
  848. infofiled := InfoField{
  849. Budget: thisinfo.Budget,
  850. Bidamount: thisinfo.Bidamount,
  851. ContractCode: thisinfo.ContractCode,
  852. ProjectName: thisinfo.ProjectName,
  853. ProjectCode: thisinfo.ProjectCode,
  854. Bidstatus: bs,
  855. }
  856. copyMap := Copy(pInfo.InfoFiled).(map[string]InfoField)
  857. copyMap[thisinfo.Id] = infofiled
  858. tmpMap := make(map[string]interface{})
  859. for k, v := range copyMap {
  860. tmpMap[k] = StructToMap(v)
  861. }
  862. tmpMap[thisinfo.Id] = StructToMap(infofiled)
  863. pInfo.InfoFiled = copyMap
  864. set["infofield"] = tmpMap
  865. set["mpn"] = pInfo.MPN
  866. set["mpc"] = pInfo.MPC
  867. if p.currentType == "project" {
  868. set["pici"] = p.pici
  869. }else {
  870. set["pici"] = tmp["comeintime"]
  871. }
  872. update := map[string]interface{}{}
  873. if len(set) > 0 {
  874. update["$set"] = set
  875. }
  876. //保留原数据吧
  877. push := p.PushListInfo(tmp, thisinfo.Id)
  878. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  879. push["compareStr"] = comStr
  880. push["resVal"] = pInfo.resVal
  881. push["pjVal"] = pInfo.pjVal
  882. update["$push"] = map[string]interface{}{
  883. "list": push,
  884. "ids": thisinfo.Id,
  885. }
  886. if len(update) > 0 {
  887. updateInfo := []map[string]interface{}{
  888. {
  889. "_id": pInfo.Id,
  890. },
  891. update,
  892. }
  893. p.updatePool <- updateInfo
  894. }
  895. }
  896. /**
  897. * 更新项目时,项目状态的处理
  898. * 返回是否新增项目,异常标记
  899. * 1、新增项目时,招标信息的状态(toptype)不是招标、拟建、预告 异常:1
  900. * 异常1是在项目新建的时候才会产生
  901. * 3、项目合并时,项目状态是”流标“/”废标“,招标信息状态不是”招标“ 异常:2
  902. * 4、项目合并时,项目状态是”合同“/”其它“,招标信息类型是”结果“ 异常:3
  903. */
  904. func (p *ProjectTask) CompareStatus(project *ProjectInfo, info *Info) (bool, int) {
  905. if info.TopType == "拟建" || info.TopType == "预告" || info.TopType == "招标" {
  906. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  907. return false, 0
  908. } else if project.Bidstatus == "废标" || project.Bidstatus == "流标" {
  909. return false, 0
  910. } else {
  911. return true, 0
  912. }
  913. } else if info.TopType == "结果" {
  914. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  915. return false, 0
  916. } else if project.Bidstatus == info.SubType {
  917. //状态一样,根据发布时间判断是否合并
  918. if (info.Publishtime - project.LastTime) > p.statusTime {
  919. return true, 0
  920. } else {
  921. return false, 0
  922. }
  923. } else if project.Bidstatus == "成交" && info.SubType == "中标" {
  924. return true, 0
  925. } else if project.Bidstatus == "流标" || project.Bidstatus == "废标" {
  926. return false, 2
  927. } else if project.Bidstatus == "合同" || project.Bidstatus == "其它" {
  928. return false, 3
  929. } else {
  930. return false, 0
  931. }
  932. } else {
  933. return false, 0
  934. }
  935. }
  936. /*
  937. * 对比地区(省、市、区),存在且不同,不能合并
  938. * 返回是否新建项目
  939. */
  940. func ComparePlace(project *ProjectInfo, info *Info) bool {
  941. if info.Area == "全国" || info.Area == "" {
  942. return false
  943. }
  944. if project.Area == "全国" || project.Area == "" {
  945. return false
  946. }
  947. if info.Area == project.Area {
  948. if info.City == "" || project.City == "" {
  949. return false
  950. } else if info.City == project.City {
  951. if project.District == "" || info.District == "" || info.District == project.District {
  952. return false
  953. } else {
  954. return true
  955. }
  956. } else {
  957. return true
  958. }
  959. } else {
  960. return true
  961. }
  962. }
  963. var PackageEle = []string{
  964. "origin",
  965. "name",
  966. //"text",
  967. "budget",
  968. "winner",
  969. "bidamount",
  970. "bidamounttype",
  971. "currency",
  972. "bidstatus",
  973. }
  974. func packageEle(map1 map[string]interface{}, id string) map[string]interface{} {
  975. p2 := map[string]interface{}{}
  976. for _, k := range PackageEle {
  977. if map1[k] != nil {
  978. p2[k] = map1[k]
  979. }
  980. infoid := p2["infoid"]
  981. if infoid == nil {
  982. p2["infoid"] = id
  983. }
  984. }
  985. return p2
  986. }
  987. func PackageFormat(info *Info, project *ProjectInfo) map[string]interface{} {
  988. p1 := map[string]interface{}{}
  989. if project != nil && project.Package != nil && len(project.Package) > 0 {
  990. packageCopy := Copy(project.Package).(map[string]interface{})
  991. p1 = packageCopy
  992. for k, v := range info.Package {
  993. if v1, ok := v.(map[string]interface{}); ok {
  994. v2 := map[string]interface{}{}
  995. v2 = packageEle(v1, info.Id)
  996. if v2["bidstatus"] == nil {
  997. v2["bidstatus"] = info.SubType
  998. }
  999. addFlag := false
  1000. for k1, v3 := range p1 {
  1001. if v4, ok := v3.([]map[string]interface{}); ok {
  1002. //if qu.ObjToString(v4[0]["origin"]) == qu.ObjToString(v2["origin"]) && qu.ObjToString(v4[0]["name"]) == qu.ObjToString(v2["name"]) {
  1003. if k1 == k {
  1004. v4 = append(v4, v2)
  1005. p1[k1] = v4
  1006. addFlag = true
  1007. break
  1008. }
  1009. }
  1010. }
  1011. if !addFlag {
  1012. p1[k] = []map[string]interface{}{v2}
  1013. }
  1014. }
  1015. }
  1016. } else {
  1017. for k, v := range info.Package {
  1018. v1, _ := v.(map[string]interface{})
  1019. p2 := map[string]interface{}{}
  1020. p2 = packageEle(v1, info.Id)
  1021. if p2["bidstatus"] == nil {
  1022. p2["bidstatus"] = info.SubType
  1023. }
  1024. p1[k] = []map[string]interface{}{p2}
  1025. }
  1026. }
  1027. return p1
  1028. }
  1029. //计算预算(budget)、中标金额(bidamount)
  1030. func CountAmount(project *ProjectInfo, info *Info, tmp map[string]interface{}) {
  1031. if info.HasPackage {
  1032. budget := 0.0
  1033. for _, v := range project.Package {
  1034. v1, _ := v.([]map[string]interface{})
  1035. for _, v2 := range v1 {
  1036. if v2["budget"] != nil {
  1037. b1 := qu.Float64All(v2["budget"])
  1038. if b1 > 0 {
  1039. budget = budget + b1
  1040. break
  1041. }
  1042. } else {
  1043. project.Budgettag = 1
  1044. }
  1045. }
  1046. }
  1047. if budget > 0 {
  1048. project.Budget = budget
  1049. project.Budgettag = 0
  1050. } else if budget == 0 && info.Budget > 0 {
  1051. project.Budget = info.Budget
  1052. project.Budgettag = 0
  1053. }
  1054. } else {
  1055. //招标没有多包
  1056. k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1057. if len(k) > 0 {
  1058. //招标是单包
  1059. if len(project.Package) > 0 {
  1060. //项目有多包
  1061. flag := false
  1062. for _, v := range project.Package {
  1063. v1, _ := v.([]map[string]interface{})
  1064. if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1065. flag = true
  1066. }
  1067. }
  1068. if !flag {
  1069. project.Budget = project.Budget + info.Budget
  1070. project.Budgettag = 0
  1071. }
  1072. } else {
  1073. //项目没有多包
  1074. if info.Budget > 0 {
  1075. project.Budget = project.Budget + info.Budget
  1076. project.Budgettag = 0
  1077. } else if info.Budget == 0 && tmp["budget"] != nil {
  1078. project.Budgettag = 0
  1079. }
  1080. }
  1081. } else {
  1082. if project.Budget < info.Budget {
  1083. project.Budget = info.Budget
  1084. project.Budgettag = 0
  1085. }
  1086. }
  1087. }
  1088. if info.SubType == "中标" || info.SubType == "成交" || info.SubType == "合同" {
  1089. if info.HasPackage {
  1090. bidamount := 0.0
  1091. for _, v := range project.Package {
  1092. v1, _ := v.([]map[string]interface{})
  1093. for _, v2 := range v1 {
  1094. b1 := qu.Float64All(v2["bidamount"])
  1095. if b1 > 0 {
  1096. bidamount = bidamount + b1
  1097. break
  1098. }
  1099. }
  1100. }
  1101. if bidamount > 0 {
  1102. project.Bidamount = bidamount
  1103. project.Bidamounttag = 0
  1104. } else if bidamount == 0 && info.Bidamount > 0 {
  1105. project.Bidamount = info.Bidamount
  1106. project.Bidamounttag = 0
  1107. }
  1108. } else {
  1109. //招标没有多包
  1110. k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1111. if len(k) > 0 {
  1112. //招标是单包
  1113. if len(project.Package) > 0 {
  1114. //项目有多包
  1115. flag := false
  1116. for _, v := range project.Package {
  1117. v1, _ := v.([]map[string]interface{})
  1118. if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1119. flag = true
  1120. }
  1121. }
  1122. if !flag {
  1123. project.Bidamount = project.Bidamount + info.Bidamount
  1124. project.Bidamounttag = 0
  1125. }
  1126. } else {
  1127. //项目没有多包
  1128. if info.Bidamount > 0 {
  1129. project.Bidamount = project.Bidamount + info.Bidamount
  1130. project.Bidamounttag = 0
  1131. } else if info.Bidamount == 0 && tmp["bidamount"] != nil {
  1132. project.Bidamounttag = 0
  1133. } else {
  1134. project.Bidamounttag = 1
  1135. }
  1136. }
  1137. } else {
  1138. if info.SubType == "中标" || info.SubType == "成交" {
  1139. if project.Bidamount < info.Bidamount {
  1140. project.Bidamount = info.Bidamount
  1141. project.Bidamounttag = 0
  1142. } else {
  1143. flag := false
  1144. if project.InfoFiled != nil && len(project.InfoFiled) > 0 {
  1145. for _, res := range project.InfoFiled {
  1146. if res.ContractCode != "" && res.ContractCode == info.ContractCode {
  1147. flag = true
  1148. break
  1149. }
  1150. if res.Bidamount == project.Bidamount {
  1151. flag = true
  1152. break
  1153. }
  1154. }
  1155. if !flag {
  1156. project.Bidamount = project.Bidamount + info.Bidamount
  1157. project.Bidamounttag = 0
  1158. } else {
  1159. if project.Bidamount < info.Bidamount {
  1160. project.Bidamount = info.Bidamount
  1161. project.Bidamounttag = 0
  1162. }
  1163. }
  1164. }
  1165. }
  1166. }
  1167. }
  1168. }
  1169. } else {
  1170. project.Bidamounttag = 1
  1171. }
  1172. }
  1173. //结构体转map
  1174. func StructToMap(filed InfoField) map[string]interface{} {
  1175. //先转json
  1176. result, err := json.Marshal(filed)
  1177. if err != nil {
  1178. return nil
  1179. }
  1180. //json转map
  1181. res := make(map[string]interface{})
  1182. err = json.Unmarshal(result, &res)
  1183. return res
  1184. }