project.go 35 KB

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