project.go 33 KB

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