project.go 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251
  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. set["pici"] = p.pici
  478. set["ids"] = []string{thisinfo.Id}
  479. if thisinfo.TopType == "招标" {
  480. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
  481. set["zbtime"] = tmp["publishtime"]
  482. p1.Zbtime = qu.Int64All(tmp["publishtime"])
  483. }
  484. } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
  485. set["jgtime"] = tmp["publishtime"]
  486. p1.Jgtime = thisinfo.Publishtime
  487. }
  488. if len(thisinfo.Subscopeclass) > 0 {
  489. set["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
  490. }
  491. if tmp["budget"] != nil && tmp["budget"] != "" {
  492. set["budget"] = thisinfo.Budget
  493. p1.Budgettag = 0
  494. set["budgettag"] = 0
  495. } else {
  496. p1.Budgettag = 1
  497. set["budgettag"] = 1
  498. }
  499. if tmp["bidamount"] != nil && tmp["bidamount"] != "" {
  500. set["bidamount"] = thisinfo.Bidamount
  501. p1.Bidamounttag = 0
  502. set["bidamounttag"] = 0
  503. } else {
  504. p1.Bidamounttag = 1
  505. set["bidamounttag"] = 1
  506. }
  507. if p1.Bidamount > 0 {
  508. set["sortprice"] = p1.Bidamount
  509. }else if p1.Budget > 0 {
  510. set["sortprice"] = p1.Budget
  511. }
  512. if len(thisinfo.Winners) > 0 {
  513. set["s_winner"] = strings.Join(thisinfo.Winners, ",")
  514. p1.Winners = thisinfo.Winners
  515. }
  516. if thisinfo.HasPackage {
  517. set["multipackage"] = 1
  518. set["package"] = pkg
  519. } else {
  520. set["multipackage"] = 0
  521. }
  522. if thisinfo.Buyer == "" {
  523. set["buyerclass"] = ""
  524. }
  525. p1.InfoFiled = make(map[string]InfoField)
  526. infofiled := InfoField{
  527. Budget: thisinfo.Budget,
  528. Bidamount: thisinfo.Bidamount,
  529. ContractCode: thisinfo.ContractCode,
  530. ProjectName: thisinfo.ProjectName,
  531. ProjectCode: thisinfo.ProjectCode,
  532. Bidstatus: bs,
  533. }
  534. p1.InfoFiled[thisinfo.Id] = infofiled
  535. res := StructToMap(infofiled)
  536. set["infofield"] = map[string]interface{}{
  537. thisinfo.Id: res,
  538. }
  539. push := p.PushListInfo(tmp, thisinfo.Id)
  540. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  541. set["list"] = []bson.M{
  542. push,
  543. }
  544. //p.savePool <- set
  545. p.updatePool <- []map[string]interface{}{
  546. {
  547. "_id": pId,
  548. },
  549. {
  550. "$set": set,
  551. },
  552. }
  553. //log.Println(set)
  554. return pId.Hex(), &p1
  555. }
  556. //招标信息字段
  557. var INFOFIELDS = []string{
  558. "projectname",
  559. "projectcode",
  560. "projectscope",
  561. "contractcode",
  562. "title",
  563. "href",
  564. "publishtime",
  565. "comeintime",
  566. "bidopentime",
  567. "toptype",
  568. "subtype",
  569. "buyer",
  570. "buyerclass",
  571. "agency",
  572. "winner",
  573. "budget",
  574. "bidamount",
  575. "topscopeclass",
  576. "subscopclass",
  577. "infoformat",
  578. "buyerperson",
  579. "buyertel",
  580. "area",
  581. "city",
  582. "district",
  583. "spidercode",
  584. "site",
  585. }
  586. //项目中list的信息
  587. func (p *ProjectTask) PushListInfo(tmp map[string]interface{}, infoid string) bson.M {
  588. res := bson.M{
  589. "infoid": infoid,
  590. }
  591. for _, k := range INFOFIELDS {
  592. if tmp[k] != nil {
  593. res[k] = tmp[k]
  594. }
  595. }
  596. return res
  597. }
  598. //生成存放在内存中的对象
  599. func (p *ProjectTask) NewCachePinfo(id primitive.ObjectID, thisinfo *Info, bidtype, bidstatus string, pkg map[string]interface{}) ProjectInfo {
  600. p1 := ProjectInfo{
  601. Id: id,
  602. Ids: []string{thisinfo.Id},
  603. ProjectName: thisinfo.ProjectName,
  604. ProjectCode: thisinfo.ProjectCode,
  605. ContractCode: thisinfo.ContractCode,
  606. Buyer: thisinfo.Buyer,
  607. Buyerclass: thisinfo.Buyerclass,
  608. Buyerperson: thisinfo.Buyerperson,
  609. Buyertel: thisinfo.Buyertel,
  610. Topscopeclass: thisinfo.Topscopeclass,
  611. Subscopeclass: thisinfo.Subscopeclass,
  612. Agency: thisinfo.Agency,
  613. Area: thisinfo.Area,
  614. City: thisinfo.City,
  615. District: thisinfo.District,
  616. MPN: []string{},
  617. MPC: []string{},
  618. FirstTime: thisinfo.Publishtime,
  619. LastTime: thisinfo.Publishtime,
  620. Budget: thisinfo.Budget,
  621. Package: pkg,
  622. Bidamount: thisinfo.Bidamount,
  623. Bidstatus: bidstatus,
  624. Bidtype: bidtype,
  625. Winners: thisinfo.Winners,
  626. }
  627. if thisinfo.LenPTC > 5 {
  628. p1.MPC = append(p1.MPC, thisinfo.PTC)
  629. }
  630. return p1
  631. }
  632. //更新项目
  633. func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info, pInfo *ProjectInfo, weight int, comStr string, ex int) {
  634. if p.currentType != "ql" && p.currentType != "updateInfo" {
  635. if BinarySearch(pInfo.Ids, thisinfo.Id) > -1 {
  636. log.Println("repeat", thisinfo.Id)
  637. return
  638. }
  639. }
  640. set := map[string]interface{}{}
  641. pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
  642. if len(pInfo.Ids) > 30 {
  643. //异常标记
  644. set["listtag"] = 1
  645. }
  646. //zbtime、lasttime、jgtime
  647. pInfo.LastTime = thisinfo.Publishtime
  648. set["lasttime"] = thisinfo.Publishtime
  649. if thisinfo.TopType == "招标" {
  650. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" && pInfo.Zbtime <= 0 {
  651. set["zbtime"] = tmp["publishtime"]
  652. }
  653. if pInfo.Jgtime > 0 {
  654. pInfo.Jgtime = int64(0)
  655. set["jgtime"] = int64(0)
  656. }
  657. } else if thisinfo.TopType == "结果" {
  658. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  659. if pInfo.Jgtime > 0 {
  660. jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
  661. //公告状态和项目状态同样都是中标或者成交,
  662. if (thisinfo.SubType == "中标" || thisinfo.SubType == "成交") && (pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交") {
  663. if jg1 > p.jgTime {
  664. set["jgtime"] = tmp["publishtime"]
  665. pInfo.Jgtime = thisinfo.Publishtime
  666. }
  667. //公告状态和项目状态同样是流标或者废标
  668. }else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (pInfo.Bidstatus == "流标" || pInfo.Bidstatus == "废标") {
  669. if jg1 > p.jgTime {
  670. set["jgtime"] = tmp["publishtime"]
  671. pInfo.Jgtime = thisinfo.Publishtime
  672. }
  673. }
  674. }else {
  675. set["jgtime"] = tmp["publishtime"]
  676. pInfo.Jgtime = thisinfo.Publishtime
  677. }
  678. }
  679. } else if thisinfo.SubType == "合同" {
  680. if pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交" {
  681. //中标、成交不更新jgtime
  682. return
  683. }
  684. set["jgtime"] = tmp["publishtime"]
  685. pInfo.Jgtime = thisinfo.Publishtime
  686. }
  687. if thisinfo.Bidopentime > pInfo.Bidopentime {
  688. pInfo.Bidopentime = thisinfo.Bidopentime
  689. set["bidopentime"] = pInfo.Bidopentime
  690. }
  691. bt := qu.ObjToString(tmp["toptype"])
  692. bs := qu.ObjToString(tmp["subtype"])
  693. p.mapBidLock.Lock()
  694. if bidtype[bs] != "" {
  695. set["bidtype"] = bidtype[bs]
  696. }
  697. if bt == "招标" {
  698. //招标状态,更新projectscope
  699. if tmp["projectscope"] != nil {
  700. set["projectscope"] = qu.ObjToString(tmp["projectscope"])
  701. }
  702. set["bidstatus"] = bt
  703. pInfo.Bidstatus = bt
  704. } else {
  705. if bidstatus[bs] != "" {
  706. set["bidstatus"] = thisinfo.SubType
  707. pInfo.Bidstatus = thisinfo.SubType
  708. } else if thisinfo.Infoformat == 2 {
  709. set["bidstatus"] = "拟建"
  710. pInfo.Bidstatus = "拟建"
  711. } else if bs == "" {
  712. set["bidstatus"] = ""
  713. pInfo.Bidstatus = ""
  714. } else {
  715. set["bidstatus"] = "其它"
  716. pInfo.Bidstatus = "其它"
  717. }
  718. }
  719. p.mapBidLock.Unlock()
  720. //异常标记
  721. if ex > 0 {
  722. set["exception"] = ex
  723. }
  724. //3\4\5--省、市、县
  725. if thisinfo.Area != "全国" {
  726. if pInfo.Area == "全国" {
  727. pInfo.Area = thisinfo.Area
  728. set["area"] = thisinfo.Area
  729. } else if pInfo.Area != thisinfo.Area {
  730. //xt = false
  731. }
  732. if pInfo.City == "" && thisinfo.City != "" {
  733. pInfo.City = thisinfo.City
  734. set["city"] = thisinfo.City
  735. } else if pInfo.City != thisinfo.City {
  736. //xt = false
  737. }
  738. if thisinfo.District != "" && pInfo.District == "" {
  739. pInfo.District = thisinfo.District
  740. set["district"] = thisinfo.District
  741. }
  742. }
  743. //6--项目名称
  744. if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  745. pInfo.ProjectName = thisinfo.ProjectName
  746. set["projectname"] = thisinfo.ProjectName
  747. }
  748. //7--项目编号
  749. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  750. pInfo.ProjectCode = thisinfo.ProjectCode
  751. set["projectcode"] = thisinfo.ProjectCode
  752. }
  753. //7--采购单位
  754. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  755. pInfo.Buyer = thisinfo.Buyer
  756. set["buyer"] = thisinfo.Buyer
  757. pInfo.Buyerclass = thisinfo.Buyerclass
  758. set["buyerclass"] = thisinfo.Buyerclass
  759. }
  760. if pInfo.Buyer == "" {
  761. set["buyerclass"] = ""
  762. }
  763. if thisinfo.ContractCode != "" {
  764. set["contractcode"] = pInfo.ContractCode + "," + thisinfo.ContractCode
  765. }
  766. //8--代理机构
  767. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  768. pInfo.Agency = thisinfo.Agency
  769. set["agency"] = thisinfo.Agency
  770. }
  771. //9--采购单位联系人
  772. if thisinfo.Buyerperson != "" && strings.Index(pInfo.Buyerperson, thisinfo.Buyerperson) < 0 {
  773. pInfo.Buyerperson = thisinfo.Buyerperson
  774. set["buyerperson"] = pInfo.Buyerperson
  775. }
  776. //10--采购单位電話
  777. if thisinfo.Buyertel != "" && strings.Index(pInfo.Buyertel, thisinfo.Buyertel) < 0 {
  778. pInfo.Buyertel = thisinfo.Buyertel
  779. set["buyertel"] = pInfo.Buyertel
  780. }
  781. if len(thisinfo.Topscopeclass) > 0 {
  782. sort.Strings(pInfo.Topscopeclass)
  783. for _, k := range thisinfo.Topscopeclass {
  784. if BinarySearch(pInfo.Topscopeclass, k) == -1 {
  785. pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
  786. sort.Strings(pInfo.Topscopeclass)
  787. }
  788. }
  789. set["topscopeclass"] = pInfo.Topscopeclass
  790. }
  791. if len(thisinfo.Subscopeclass) > 0 {
  792. sort.Strings(pInfo.Subscopeclass)
  793. for _, k := range thisinfo.Subscopeclass {
  794. if BinarySearch(pInfo.Subscopeclass, k) == -1 {
  795. pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
  796. sort.Strings(pInfo.Subscopeclass)
  797. }
  798. }
  799. set["subscopeclass"] = pInfo.Subscopeclass
  800. set["s_subscopeclass"] = strings.Join(pInfo.Subscopeclass, ",")
  801. }
  802. if len(thisinfo.Winners) > 0 {
  803. if len(pInfo.Winners) <= 0 {
  804. set["winner"] = qu.ObjToString(tmp["winner"])
  805. }
  806. sort.Strings(pInfo.Winners)
  807. for _, k := range thisinfo.Winners {
  808. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  809. if BinarySearch(pInfo.Winners, k) != -1 {
  810. deleteSlice(pInfo.Winners, k, "")
  811. sort.Strings(pInfo.Winners)
  812. }
  813. }else {
  814. if BinarySearch(pInfo.Winners, k) == -1 {
  815. pInfo.Winners = append(pInfo.Winners, k)
  816. sort.Strings(pInfo.Winners)
  817. }
  818. }
  819. }
  820. set["s_winner"] = strings.Join(pInfo.Winners, ",")
  821. }
  822. if thisinfo.HasPackage { //多包处理
  823. set["multipackage"] = 1
  824. pkg := PackageFormat(thisinfo, pInfo)
  825. pInfo.Package = pkg
  826. set["package"] = pInfo.Package
  827. }
  828. //处理多包后,计算预算金额、中标金额
  829. CountAmount(pInfo, thisinfo, tmp)
  830. if pInfo.Budget >= 0 && pInfo.Budgettag != 1 {
  831. set["budget"] = pInfo.Budget
  832. set["budgettag"] = 0
  833. } else {
  834. set["budgettag"] = 1
  835. }
  836. if pInfo.Bidamount >= 0 && pInfo.Bidamounttag != 1 {
  837. set["bidamount"] = pInfo.Bidamount
  838. set["bidamounttag"] = 0
  839. } else {
  840. set["bidamounttag"] = 1
  841. }
  842. if pInfo.Bidamount > 0 {
  843. set["sortprice"] = pInfo.Bidamount
  844. }else if pInfo.Budget > 0 {
  845. set["sortprice"] = pInfo.Budget
  846. }
  847. infofiled := InfoField{
  848. Budget: thisinfo.Budget,
  849. Bidamount: thisinfo.Bidamount,
  850. ContractCode: thisinfo.ContractCode,
  851. ProjectName: thisinfo.ProjectName,
  852. ProjectCode: thisinfo.ProjectCode,
  853. Bidstatus: bs,
  854. }
  855. copyMap := Copy(pInfo.InfoFiled).(map[string]InfoField)
  856. copyMap[thisinfo.Id] = infofiled
  857. tmpMap := make(map[string]interface{})
  858. for k, v := range copyMap {
  859. tmpMap[k] = StructToMap(v)
  860. }
  861. tmpMap[thisinfo.Id] = StructToMap(infofiled)
  862. pInfo.InfoFiled = copyMap
  863. set["infofield"] = tmpMap
  864. set["mpn"] = pInfo.MPN
  865. set["mpc"] = pInfo.MPC
  866. set["pici"] = p.pici
  867. update := map[string]interface{}{}
  868. if len(set) > 0 {
  869. update["$set"] = set
  870. }
  871. //保留原数据吧
  872. push := p.PushListInfo(tmp, thisinfo.Id)
  873. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  874. push["compareStr"] = comStr
  875. push["resVal"] = pInfo.resVal
  876. push["pjVal"] = pInfo.pjVal
  877. update["$push"] = map[string]interface{}{
  878. "list": push,
  879. "ids": thisinfo.Id,
  880. }
  881. if len(update) > 0 {
  882. updateInfo := []map[string]interface{}{
  883. {
  884. "_id": pInfo.Id,
  885. },
  886. update,
  887. }
  888. p.updatePool <- updateInfo
  889. }
  890. }
  891. /**
  892. * 更新项目时,项目状态的处理
  893. * 返回是否新增项目,异常标记
  894. * 1、新增项目时,招标信息的状态(toptype)不是招标、拟建、预告 异常:1
  895. * 异常1是在项目新建的时候才会产生
  896. * 3、项目合并时,项目状态是”流标“/”废标“,招标信息状态不是”招标“ 异常:2
  897. * 4、项目合并时,项目状态是”合同“/”其它“,招标信息类型是”结果“ 异常:3
  898. */
  899. func (p *ProjectTask) CompareStatus(project *ProjectInfo, info *Info) (bool, int) {
  900. if info.TopType == "拟建" || info.TopType == "预告" || info.TopType == "招标" {
  901. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  902. return false, 0
  903. } else if project.Bidstatus == "废标" || project.Bidstatus == "流标" {
  904. return false, 0
  905. } else {
  906. return true, 0
  907. }
  908. } else if info.TopType == "结果" {
  909. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  910. return false, 0
  911. } else if project.Bidstatus == info.SubType {
  912. //状态一样,根据发布时间判断是否合并
  913. if (info.Publishtime - project.LastTime) > p.statusTime {
  914. return true, 0
  915. } else {
  916. return false, 0
  917. }
  918. } else if project.Bidstatus == "成交" && info.SubType == "中标" {
  919. return true, 0
  920. } else if project.Bidstatus == "流标" || project.Bidstatus == "废标" {
  921. return false, 2
  922. } else if project.Bidstatus == "合同" || project.Bidstatus == "其它" {
  923. return false, 3
  924. } else {
  925. return false, 0
  926. }
  927. } else {
  928. return false, 0
  929. }
  930. }
  931. /*
  932. * 对比地区(省、市、区),存在且不同,不能合并
  933. * 返回是否新建项目
  934. */
  935. func ComparePlace(project *ProjectInfo, info *Info) bool {
  936. if info.Area == "全国" || info.Area == "" {
  937. return false
  938. }
  939. if project.Area == "全国" || project.Area == "" {
  940. return false
  941. }
  942. if info.Area == project.Area {
  943. if info.City == "" || project.City == "" {
  944. return false
  945. } else if info.City == project.City {
  946. if project.District == "" || info.District == "" || info.District == project.District {
  947. return false
  948. } else {
  949. return true
  950. }
  951. } else {
  952. return true
  953. }
  954. } else {
  955. return true
  956. }
  957. }
  958. var PackageEle = []string{
  959. "origin",
  960. "name",
  961. //"text",
  962. "budget",
  963. "winner",
  964. "bidamount",
  965. "bidamounttype",
  966. "currency",
  967. "bidstatus",
  968. }
  969. func packageEle(map1 map[string]interface{}, id string) map[string]interface{} {
  970. p2 := map[string]interface{}{}
  971. for _, k := range PackageEle {
  972. if map1[k] != nil {
  973. p2[k] = map1[k]
  974. }
  975. infoid := p2["infoid"]
  976. if infoid == nil {
  977. p2["infoid"] = id
  978. }
  979. }
  980. return p2
  981. }
  982. func PackageFormat(info *Info, project *ProjectInfo) map[string]interface{} {
  983. p1 := map[string]interface{}{}
  984. if project != nil && project.Package != nil && len(project.Package) > 0 {
  985. packageCopy := Copy(project.Package).(map[string]interface{})
  986. p1 = packageCopy
  987. for k, v := range info.Package {
  988. if v1, ok := v.(map[string]interface{}); ok {
  989. v2 := map[string]interface{}{}
  990. v2 = packageEle(v1, info.Id)
  991. if v2["bidstatus"] == nil {
  992. v2["bidstatus"] = info.SubType
  993. }
  994. addFlag := false
  995. for k1, v3 := range p1 {
  996. if v4, ok := v3.([]map[string]interface{}); ok {
  997. //if qu.ObjToString(v4[0]["origin"]) == qu.ObjToString(v2["origin"]) && qu.ObjToString(v4[0]["name"]) == qu.ObjToString(v2["name"]) {
  998. if k1 == k {
  999. v4 = append(v4, v2)
  1000. p1[k1] = v4
  1001. addFlag = true
  1002. break
  1003. }
  1004. }
  1005. }
  1006. if !addFlag {
  1007. p1[k] = []map[string]interface{}{v2}
  1008. }
  1009. }
  1010. }
  1011. } else {
  1012. for k, v := range info.Package {
  1013. v1, _ := v.(map[string]interface{})
  1014. p2 := map[string]interface{}{}
  1015. p2 = packageEle(v1, info.Id)
  1016. if p2["bidstatus"] == nil {
  1017. p2["bidstatus"] = info.SubType
  1018. }
  1019. p1[k] = []map[string]interface{}{p2}
  1020. }
  1021. }
  1022. return p1
  1023. }
  1024. //计算预算(budget)、中标金额(bidamount)
  1025. func CountAmount(project *ProjectInfo, info *Info, tmp map[string]interface{}) {
  1026. if info.HasPackage {
  1027. budget := 0.0
  1028. for _, v := range project.Package {
  1029. v1, _ := v.([]map[string]interface{})
  1030. for _, v2 := range v1 {
  1031. if v2["budget"] != nil {
  1032. b1 := qu.Float64All(v2["budget"])
  1033. if b1 > 0 {
  1034. budget = budget + b1
  1035. break
  1036. }
  1037. } else {
  1038. project.Budgettag = 1
  1039. }
  1040. }
  1041. }
  1042. if budget > 0 {
  1043. project.Budget = budget
  1044. project.Budgettag = 0
  1045. } else if budget == 0 && info.Budget > 0 {
  1046. project.Budget = info.Budget
  1047. project.Budgettag = 0
  1048. }
  1049. } else {
  1050. //招标没有多包
  1051. k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1052. if len(k) > 0 {
  1053. //招标是单包
  1054. if len(project.Package) > 0 {
  1055. //项目有多包
  1056. flag := false
  1057. for _, v := range project.Package {
  1058. v1, _ := v.([]map[string]interface{})
  1059. if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1060. flag = true
  1061. }
  1062. }
  1063. if !flag {
  1064. project.Budget = project.Budget + info.Budget
  1065. project.Budgettag = 0
  1066. }
  1067. } else {
  1068. //项目没有多包
  1069. if info.Budget > 0 {
  1070. project.Budget = project.Budget + info.Budget
  1071. project.Budgettag = 0
  1072. } else if info.Budget == 0 && tmp["budget"] != nil {
  1073. project.Budgettag = 0
  1074. } else {
  1075. project.Budgettag = 1
  1076. }
  1077. }
  1078. } else {
  1079. if project.Budget < info.Budget {
  1080. project.Budget = info.Budget
  1081. project.Budgettag = 0
  1082. }
  1083. if tmp["budget"] == nil {
  1084. project.Budgettag = 1
  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. if tmp["bidamount"] == nil {
  1168. project.Budgettag = 1
  1169. }
  1170. }
  1171. }
  1172. } else {
  1173. project.Bidamounttag = 1
  1174. }
  1175. }
  1176. //结构体转map
  1177. func StructToMap(filed InfoField) map[string]interface{} {
  1178. //先转json
  1179. result, err := json.Marshal(filed)
  1180. if err != nil {
  1181. return nil
  1182. }
  1183. //json转map
  1184. res := make(map[string]interface{})
  1185. err = json.Unmarshal(result, &res)
  1186. return res
  1187. }