project.go 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. package main
  2. import (
  3. "encoding/json"
  4. "log"
  5. "math"
  6. qu "qfw/util"
  7. "sort"
  8. "strings"
  9. "time"
  10. "go.mongodb.org/mongo-driver/bson"
  11. "go.mongodb.org/mongo-driver/bson/primitive"
  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. if !IsCreatePro(info) {
  211. return
  212. }
  213. id, p1 := p.NewProject(tmp, info)
  214. p.AllIdsMapLock.Lock()
  215. p.AllIdsMap[id] = &ID{Id: id, P: p1}
  216. p.AllIdsMapLock.Unlock()
  217. for _, m := range pids {
  218. m.Arr = append(m.Arr, id)
  219. }
  220. }
  221. }
  222. func (p *ProjectTask) compareBCTABB(info *Info, cp *ProjectInfo, diffTime int64, score int) (compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount string, score2 int) {
  223. compareBuyer = "D"
  224. if len([]rune(info.Buyer)) > 3 && len([]rune(cp.Buyer)) > 3 {
  225. v := CheckContain(info.Buyer, cp.Buyer)
  226. if v == 1 {
  227. compareBuyer = "A"
  228. score += 3
  229. } else {
  230. //v1 := CosineSimilar(info.Buyer, cp.Buyer)
  231. if v == 2 {
  232. compareBuyer = "B"
  233. score += 1
  234. } else {
  235. compareBuyer = "C"
  236. }
  237. }
  238. }
  239. //---------------------------------------
  240. compareCity = ""
  241. if info.Area != "全国" && info.Area != "" && info.Area == cp.Area {
  242. compareCity += "A"
  243. score += 2
  244. } else if info.Area == "全国" || cp.Area == "全国" {
  245. compareCity += "B"
  246. score += 1
  247. } else {
  248. compareCity += "C"
  249. }
  250. if compareCity != "C" {
  251. if info.City != "" && info.City == cp.City {
  252. compareCity += "A"
  253. score += 2
  254. } else {
  255. if info.Area == "全国" || cp.Area == "全国" {
  256. compareCity += "B"
  257. } else if info.City == compareCity {
  258. compareCity += "B"
  259. } else {
  260. compareCity += "C"
  261. }
  262. }
  263. } else {
  264. compareCity += "C"
  265. }
  266. score2 = 0
  267. if compareCity == "AA" {
  268. if info.District != "" && info.District == cp.District {
  269. score2 = 1
  270. }
  271. }
  272. compareTime = "D"
  273. if diffTime < 45*86400 {
  274. compareTime = "A"
  275. score += 2
  276. } else if diffTime < 90*86400 {
  277. compareTime = "B"
  278. score += 1
  279. }
  280. compareAgency = "D"
  281. if info.Agency != "" {
  282. if info.Agency == cp.Agency {
  283. compareAgency = "A"
  284. score += 2
  285. score2 += 1
  286. } else if cp.Agency != "" {
  287. if strings.Contains(info.Agency, cp.Agency) || strings.Contains(cp.Agency, info.Agency) {
  288. compareAgency = "B"
  289. score += 1
  290. score2 += 1
  291. } else {
  292. compareAgency = "C"
  293. }
  294. }
  295. }
  296. compareBudget = "C"
  297. if info.Budget > 0 && (info.Budget == cp.Budget || (cp.Bidamount > 0 && info.Budget > cp.Bidamount && (info.Budget-cp.Bidamount) < (0.15*info.Budget))) {
  298. compareBudget = "A"
  299. score += 1
  300. score2 += 1
  301. }
  302. // else if info.Budget == 0 && cp.Budget == 0 {
  303. // compareBudget = "B"
  304. // }
  305. compareBidmount = "C"
  306. if info.Bidamount > 0 && (info.Bidamount == cp.Bidamount || (cp.Budget > 0 && cp.Budget > info.Bidamount && (cp.Budget-info.Bidamount) < 0.15*cp.Budget)) {
  307. compareBidmount = "A"
  308. score += 1
  309. score2 += 1
  310. }
  311. // else if info.Bidamount == 0 && cp.Bidamount == 0 {
  312. // compareBidmount = "B"
  313. // }
  314. cp.score = score
  315. return
  316. }
  317. func compareResult(resVal, pjVal, score2 int, comStr, compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount string) int {
  318. eqV := 0
  319. switch resVal {
  320. case 3:
  321. if pjVal == 3 && comStr[3:] != "CCCDCCC" {
  322. eqV = 1
  323. } else if compareBuyer < "C" {
  324. if pjVal > 1 {
  325. eqV = 1
  326. } else { //if (compareCity[1:1] != "C" || compareTime != "D") && score2 > 0
  327. eqV = 2
  328. }
  329. } else if compareBuyer == "D" {
  330. if pjVal > 1 && (compareCity[1:1] != "C" || score2 > 0) {
  331. eqV = 2
  332. } else if compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  333. eqV = 3
  334. }
  335. } else {
  336. if pjVal == 3 && (score2 > 0 || compareCity[1:1] != "C") {
  337. eqV = 2
  338. } else if pjVal == 2 && compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  339. eqV = 3
  340. } else if compareCity == "AA" && compareTime == "A" && score2 > 0 {
  341. eqV = 3
  342. }
  343. }
  344. case 2:
  345. if compareBuyer < "C" {
  346. if pjVal > 1 {
  347. eqV = 2
  348. } else if compareCity[1:1] != "C" && compareTime == "A" || score2 > 0 {
  349. eqV = 3
  350. }
  351. } else if compareBuyer == "D" {
  352. if pjVal > 1 && (score2 > 0 || compareCity[1:1] != "C") {
  353. eqV = 2
  354. } else if compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  355. eqV = 3
  356. }
  357. } else {
  358. if pjVal > 1 && compareTime == "A" && (score2 > 0 || compareCity[1:1] != "C") {
  359. eqV = 2
  360. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  361. eqV = 3
  362. }
  363. }
  364. case 1:
  365. if compareBuyer < "C" {
  366. if pjVal > 1 && (score2 > 0 || compareCity[1:1] != "C") {
  367. eqV = 2
  368. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  369. eqV = 3
  370. }
  371. } else if compareBuyer == "D" {
  372. if pjVal > 1 && compareTime == "A" && (score2 > 0 || compareCity[1:1] != "C") {
  373. eqV = 2
  374. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  375. eqV = 3
  376. }
  377. } else {
  378. if pjVal > 1 && compareTime == "A" && score2 > 0 && (compareBudget == "A" || compareBidmount == "A") && compareCity[1:1] != "C" {
  379. eqV = 3
  380. }
  381. }
  382. }
  383. return eqV
  384. }
  385. //项目中的字段
  386. var FIELDS = []string{
  387. "area",
  388. "city",
  389. "district",
  390. "projectname",
  391. "projectcode",
  392. "buyer",
  393. "buyerclass",
  394. "buyerperson",
  395. "buyertel",
  396. "winner",
  397. "agency",
  398. "topscopeclass",
  399. "subscopeclass",
  400. "package",
  401. }
  402. //招标时间zbtime、中标时间jgtime、项目状态bidstatus、招标类型bidtype、最后发布时间lasttime、首次发布时间firsttime
  403. func (p *ProjectTask) NewProject(tmp map[string]interface{}, thisinfo *Info) (string, *ProjectInfo) {
  404. pId := primitive.NewObjectID() //NewObjectId()
  405. set := map[string]interface{}{}
  406. set["_id"] = pId
  407. for _, f := range FIELDS {
  408. if tmp[f] != nil && tmp[f] != "" {
  409. set[f] = tmp[f]
  410. }
  411. }
  412. bidopentime := qu.Int64All(tmp["bidopentime"])
  413. if bidopentime > 0 {
  414. set["bidopentime"] = bidopentime
  415. }
  416. //异常标记
  417. if thisinfo.TopType != "招标" && thisinfo.TopType != "拟建" && thisinfo.TopType != "预告" {
  418. set["exception"] = 1
  419. }
  420. //projecthref保存
  421. if jsonData, ok := tmp["jsondata"].(map[string]interface{}); ok {
  422. if jsonData != nil && qu.ObjToString(jsonData["projecthref"]) != "" {
  423. set["projecthref"] = jsonData["projecthref"]
  424. }
  425. }
  426. //合同编号
  427. if thisinfo.ContractCode != "" {
  428. set["contractcode"] = thisinfo.ContractCode
  429. }
  430. bt := qu.ObjToString(tmp["toptype"])
  431. bs := qu.ObjToString(tmp["subtype"])
  432. p.mapBidLock.Lock()
  433. if thisinfo.Infoformat == 2 || thisinfo.SubType == "拟建" {
  434. set["bidstatus"] = "拟建"
  435. bt = "拟建"
  436. } else {
  437. if bidtype[bs] != "" {
  438. set["bidtype"] = bidtype[bs]
  439. } else {
  440. set["bidtype"] = "招标"
  441. }
  442. if bt == "招标" {
  443. set["projectscope"] = qu.ObjToString(tmp["projectscope"])
  444. set["bidstatus"] = bt
  445. } else {
  446. if bidstatus[bs] != "" {
  447. set["bidstatus"] = thisinfo.SubType
  448. bt = thisinfo.SubType
  449. } else if bs == "" {
  450. set["bidstatus"] = ""
  451. bt = ""
  452. } else {
  453. set["bidstatus"] = "其它"
  454. bt = "其它"
  455. }
  456. }
  457. }
  458. p.mapBidLock.Unlock()
  459. pkg := PackageFormat(thisinfo, nil)
  460. p1 := p.NewCachePinfo(pId, thisinfo, bs, bt, pkg)
  461. now := time.Now().Unix()
  462. set["createtime"] = now
  463. set["sourceinfoid"] = thisinfo.Id
  464. set["sourceinfourl"] = tmp["href"]
  465. set["firsttime"] = tmp["publishtime"]
  466. set["lasttime"] = tmp["publishtime"]
  467. //增量用系统时间,全量(历史)入库时间
  468. if p.currentType == "project" {
  469. set["pici"] = p.pici
  470. } else {
  471. set["pici"] = tmp["comeintime"]
  472. }
  473. set["ids"] = []string{thisinfo.Id}
  474. if thisinfo.TopType == "招标" {
  475. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
  476. set["zbtime"] = tmp["publishtime"]
  477. p1.Zbtime = qu.Int64All(tmp["publishtime"])
  478. }
  479. } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
  480. set["jgtime"] = tmp["publishtime"]
  481. p1.Jgtime = thisinfo.Publishtime
  482. }
  483. if len(thisinfo.Subscopeclass) > 0 {
  484. set["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
  485. }
  486. if len(thisinfo.Winners) > 0 {
  487. set["s_winner"] = strings.Join(thisinfo.Winners, ",")
  488. p1.Winners = thisinfo.Winners
  489. }
  490. if thisinfo.HasPackage {
  491. set["multipackage"] = 1
  492. set["package"] = pkg
  493. } else {
  494. set["multipackage"] = 0
  495. }
  496. //项目评审专家
  497. if len(thisinfo.ReviewExperts) > 0 {
  498. set["review_experts"] = thisinfo.ReviewExperts
  499. p1.ReviewExperts = thisinfo.ReviewExperts
  500. }
  501. //标的物
  502. if thisinfo.Purchasing != "" {
  503. set["purchasing"] = thisinfo.Purchasing
  504. p1.Purchasing = thisinfo.Purchasing
  505. }
  506. //中标候选人
  507. if len(thisinfo.WinnerOrder) > 0 {
  508. var list = []string{}
  509. for _, v := range thisinfo.WinnerOrder {
  510. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  511. list = append(list, qu.ObjToString(v["entname"]))
  512. }
  513. }
  514. set["winnerorder"] = list
  515. p1.Winnerorder = list
  516. }
  517. p1.InfoFiled = make(map[string]InfoField)
  518. infofield := InfoField{
  519. Budget: thisinfo.Budget,
  520. Bidamount: thisinfo.Bidamount,
  521. ContractCode: thisinfo.ContractCode,
  522. ProjectName: thisinfo.ProjectName,
  523. ProjectCode: thisinfo.ProjectCode,
  524. Bidstatus: bs,
  525. }
  526. p1.InfoFiled[thisinfo.Id] = infofield
  527. res := StructToMap(infofield)
  528. set["infofield"] = map[string]interface{}{
  529. thisinfo.Id: res,
  530. }
  531. if tmp["budget"] != nil && tmp["budget"] != "" {
  532. set["budget"] = thisinfo.Budget
  533. p1.Budgettag = 0
  534. set["budgettag"] = 0
  535. } else {
  536. p1.Budgettag = 1
  537. set["budgettag"] = 1
  538. }
  539. if tmp["bidamount"] != nil && tmp["bidamount"] != "" {
  540. set["bidamount"] = thisinfo.Bidamount
  541. p1.Bidamounttag = 0
  542. set["bidamounttag"] = 0
  543. } else {
  544. p1.Bidamounttag = 1
  545. set["bidamounttag"] = 1
  546. }
  547. if p1.Bidamount > 0 {
  548. set["sortprice"] = p1.Bidamount
  549. } else if p1.Budget > 0 {
  550. set["sortprice"] = p1.Budget
  551. }
  552. push := p.PushListInfo(tmp, thisinfo.Id)
  553. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  554. set["list"] = []bson.M{
  555. push,
  556. }
  557. //p.savePool <- set
  558. p.updatePool <- []map[string]interface{}{
  559. {
  560. "_id": pId,
  561. },
  562. {
  563. "$set": set,
  564. },
  565. }
  566. //log.Println(set)
  567. return pId.Hex(), &p1
  568. }
  569. //招标信息字段
  570. var INFOFIELDS = []string{
  571. "projectname",
  572. "projectcode",
  573. "projectscope",
  574. "contractcode",
  575. "title",
  576. "href",
  577. "publishtime",
  578. "comeintime",
  579. "bidopentime",
  580. "toptype",
  581. "subtype",
  582. "buyer",
  583. "buyerclass",
  584. "agency",
  585. "winner",
  586. "budget",
  587. "bidamount",
  588. "topscopeclass",
  589. "subscopclass",
  590. "infoformat",
  591. "buyerperson",
  592. "buyertel",
  593. "area",
  594. "city",
  595. "district",
  596. "spidercode",
  597. "site",
  598. "review_experts",
  599. "purchasing",
  600. }
  601. //项目中list的信息
  602. func (p *ProjectTask) PushListInfo(tmp map[string]interface{}, infoid string) bson.M {
  603. res := bson.M{
  604. "infoid": infoid,
  605. }
  606. for _, k := range INFOFIELDS {
  607. if tmp[k] != nil {
  608. res[k] = tmp[k]
  609. }
  610. }
  611. return res
  612. }
  613. //生成存放在内存中的对象
  614. func (p *ProjectTask) NewCachePinfo(id primitive.ObjectID, thisinfo *Info, bidtype, bidstatus string, pkg map[string]interface{}) ProjectInfo {
  615. p1 := ProjectInfo{
  616. Id: id,
  617. Ids: []string{thisinfo.Id},
  618. ProjectName: thisinfo.ProjectName,
  619. ProjectCode: thisinfo.ProjectCode,
  620. ContractCode: thisinfo.ContractCode,
  621. Buyer: thisinfo.Buyer,
  622. Buyerclass: thisinfo.Buyerclass,
  623. Buyerperson: thisinfo.Buyerperson,
  624. Buyertel: thisinfo.Buyertel,
  625. Topscopeclass: thisinfo.Topscopeclass,
  626. Subscopeclass: thisinfo.Subscopeclass,
  627. Agency: thisinfo.Agency,
  628. Area: thisinfo.Area,
  629. City: thisinfo.City,
  630. District: thisinfo.District,
  631. MPN: []string{},
  632. MPC: []string{},
  633. FirstTime: thisinfo.Publishtime,
  634. LastTime: thisinfo.Publishtime,
  635. Budget: thisinfo.Budget,
  636. Package: pkg,
  637. Bidamount: thisinfo.Bidamount,
  638. Bidstatus: bidstatus,
  639. Bidtype: bidtype,
  640. Winners: thisinfo.Winners,
  641. ReviewExperts: thisinfo.ReviewExperts,
  642. Purchasing: thisinfo.Purchasing,
  643. }
  644. if thisinfo.LenPTC > 5 {
  645. p1.MPC = append(p1.MPC, thisinfo.PTC)
  646. }
  647. return p1
  648. }
  649. //更新项目
  650. func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info, pInfo *ProjectInfo, weight int, comStr string, ex int) {
  651. if p.currentType != "updateInfo" {
  652. if BinarySearch(pInfo.Ids, thisinfo.Id) > -1 {
  653. log.Println("repeat", thisinfo.Id, ",pid", pInfo.Id)
  654. return
  655. }
  656. }
  657. set := map[string]interface{}{}
  658. pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
  659. if len(pInfo.Ids) > 30 {
  660. //异常标记
  661. set["listtag"] = 1
  662. }
  663. //zbtime、lasttime、jgtime
  664. pInfo.LastTime = thisinfo.Publishtime
  665. set["lasttime"] = thisinfo.Publishtime
  666. if thisinfo.TopType == "招标" {
  667. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" && pInfo.Zbtime <= 0 {
  668. set["zbtime"] = tmp["publishtime"]
  669. }
  670. if pInfo.Jgtime > 0 {
  671. pInfo.Jgtime = int64(0)
  672. set["jgtime"] = int64(0)
  673. }
  674. } else if thisinfo.TopType == "结果" {
  675. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  676. if pInfo.Jgtime > 0 {
  677. jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
  678. //公告状态和项目状态同样都是中标或者成交,
  679. if (thisinfo.SubType == "中标" || thisinfo.SubType == "成交") && (pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交") {
  680. if jg1 > p.jgTime {
  681. set["jgtime"] = tmp["publishtime"]
  682. pInfo.Jgtime = thisinfo.Publishtime
  683. }
  684. //公告状态和项目状态同样是流标或者废标
  685. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (pInfo.Bidstatus == "流标" || pInfo.Bidstatus == "废标") {
  686. if jg1 > p.jgTime {
  687. set["jgtime"] = tmp["publishtime"]
  688. pInfo.Jgtime = thisinfo.Publishtime
  689. }
  690. }
  691. } else {
  692. set["jgtime"] = tmp["publishtime"]
  693. pInfo.Jgtime = thisinfo.Publishtime
  694. }
  695. }
  696. } else if thisinfo.SubType == "合同" {
  697. if pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交" || pInfo.Bidstatus == "" {
  698. //中标、成交不更新jgtime
  699. } else {
  700. set["jgtime"] = tmp["publishtime"]
  701. pInfo.Jgtime = thisinfo.Publishtime
  702. }
  703. }
  704. if thisinfo.Bidopentime > pInfo.Bidopentime {
  705. pInfo.Bidopentime = thisinfo.Bidopentime
  706. set["bidopentime"] = pInfo.Bidopentime
  707. }
  708. bt := qu.ObjToString(tmp["toptype"])
  709. bs := qu.ObjToString(tmp["subtype"])
  710. p.mapBidLock.Lock()
  711. if bt == "招标" {
  712. //招标状态,更新projectscope
  713. if tmp["projectscope"] != nil {
  714. set["projectscope"] = qu.ObjToString(tmp["projectscope"])
  715. }
  716. set["bidstatus"] = bt
  717. pInfo.Bidstatus = bt
  718. if bidtype[bs] != "" {
  719. set["bidtype"] = bidtype[bs]
  720. pInfo.Bidtype = bidtype[bs]
  721. } else {
  722. set["bidtype"] = "招标"
  723. pInfo.Bidtype = "招标"
  724. }
  725. } else {
  726. if bidstatus[bs] != "" {
  727. set["bidstatus"] = thisinfo.SubType
  728. pInfo.Bidstatus = thisinfo.SubType
  729. } else if thisinfo.Infoformat == 2 {
  730. set["bidstatus"] = "拟建"
  731. pInfo.Bidstatus = "拟建"
  732. } else if bs == "" && bt == "结果" {
  733. if pInfo.Bidstatus == "招标" {
  734. set["bidstatus"] = ""
  735. pInfo.Bidstatus = ""
  736. }
  737. } else {
  738. set["bidstatus"] = "其它"
  739. pInfo.Bidstatus = "其它"
  740. }
  741. }
  742. p.mapBidLock.Unlock()
  743. //异常标记
  744. if ex > 0 {
  745. set["exception"] = ex
  746. }
  747. //3\4\5--省、市、县
  748. //if thisinfo.Area != "全国" {
  749. // if pInfo.Area == "全国" {
  750. // pInfo.Area = thisinfo.Area
  751. // set["area"] = thisinfo.Area
  752. // } else if pInfo.Area != thisinfo.Area {
  753. // //xt = false
  754. // }
  755. // if pInfo.City == "" && thisinfo.City != "" {
  756. // pInfo.City = thisinfo.City
  757. // set["city"] = thisinfo.City
  758. // } else if pInfo.City != thisinfo.City {
  759. // //xt = false
  760. // }
  761. // if thisinfo.District != "" && pInfo.District == "" {
  762. // pInfo.District = thisinfo.District
  763. // set["district"] = thisinfo.District
  764. // }
  765. //}
  766. //相同城市的公告才会合并到一起(全国列外)
  767. if thisinfo.Area != "全国" {
  768. pInfo.Area = thisinfo.Area
  769. set["area"] = thisinfo.Area
  770. pInfo.City = thisinfo.City
  771. set["city"] = thisinfo.City
  772. if thisinfo.District != "" {
  773. pInfo.District = thisinfo.District
  774. set["district"] = thisinfo.District
  775. }
  776. }
  777. //6--项目名称
  778. if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  779. pInfo.ProjectName = thisinfo.ProjectName
  780. set["projectname"] = thisinfo.ProjectName
  781. }
  782. //7--项目编号
  783. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  784. pInfo.ProjectCode = thisinfo.ProjectCode
  785. set["projectcode"] = thisinfo.ProjectCode
  786. }
  787. //7--采购单位
  788. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  789. pInfo.Buyer = thisinfo.Buyer
  790. set["buyer"] = thisinfo.Buyer
  791. pInfo.Buyerclass = thisinfo.Buyerclass
  792. set["buyerclass"] = thisinfo.Buyerclass
  793. }
  794. if pInfo.Buyer == "" {
  795. set["buyerclass"] = ""
  796. }
  797. //采购单位联系人
  798. if thisinfo.Buyerperson != "" {
  799. pInfo.Buyerperson = thisinfo.Buyerperson
  800. set["buyerperson"] = pInfo.Buyerperson
  801. } else {
  802. pInfo.Buyerperson = ""
  803. set["buyerperson"] = ""
  804. }
  805. //采购单位電話
  806. if thisinfo.Buyertel != "" {
  807. pInfo.Buyertel = thisinfo.Buyertel
  808. set["buyertel"] = pInfo.Buyertel
  809. } else {
  810. pInfo.Buyertel = ""
  811. set["buyertel"] = ""
  812. }
  813. if thisinfo.ContractCode != "" {
  814. set["contractcode"] = pInfo.ContractCode + "," + thisinfo.ContractCode
  815. }
  816. //8--代理机构
  817. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  818. pInfo.Agency = thisinfo.Agency
  819. set["agency"] = thisinfo.Agency
  820. }
  821. if len(thisinfo.Topscopeclass) > 0 {
  822. sort.Strings(pInfo.Topscopeclass)
  823. for _, k := range thisinfo.Topscopeclass {
  824. if BinarySearch(pInfo.Topscopeclass, k) == -1 {
  825. pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
  826. sort.Strings(pInfo.Topscopeclass)
  827. }
  828. }
  829. set["topscopeclass"] = pInfo.Topscopeclass
  830. }
  831. //项目评审专家
  832. if len(thisinfo.ReviewExperts) > 0 {
  833. set["review_experts"] = thisinfo.ReviewExperts
  834. pInfo.ReviewExperts = thisinfo.ReviewExperts
  835. }
  836. if thisinfo.Purchasing != "" {
  837. if pInfo.Purchasing == "" {
  838. pInfo.Purchasing = thisinfo.Purchasing
  839. set["purchasing"] = thisinfo.Purchasing
  840. } else {
  841. list := strings.Split(pInfo.Purchasing, ",")
  842. for _, k := range list {
  843. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  844. list = append(list, k)
  845. sort.Strings(list)
  846. }
  847. }
  848. set["purchasing"] = strings.Join(list, ",")
  849. }
  850. }
  851. //中标候选人
  852. if len(thisinfo.WinnerOrder) > 0 {
  853. var list = []string{}
  854. for _, v := range thisinfo.WinnerOrder {
  855. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  856. list = append(list, qu.ObjToString(v["entname"]))
  857. }
  858. }
  859. set["winnerorder"] = list
  860. pInfo.Winnerorder = list
  861. }
  862. if len(thisinfo.Subscopeclass) > 0 {
  863. sort.Strings(pInfo.Subscopeclass)
  864. for _, k := range thisinfo.Subscopeclass {
  865. if BinarySearch(pInfo.Subscopeclass, k) == -1 {
  866. pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
  867. sort.Strings(pInfo.Subscopeclass)
  868. }
  869. }
  870. set["subscopeclass"] = pInfo.Subscopeclass
  871. set["s_subscopeclass"] = strings.Join(pInfo.Subscopeclass, ",")
  872. }
  873. if len(thisinfo.Winners) > 0 {
  874. if len(pInfo.Winners) <= 0 {
  875. set["winner"] = qu.ObjToString(tmp["winner"])
  876. }
  877. sort.Strings(pInfo.Winners)
  878. for _, k := range thisinfo.Winners {
  879. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  880. if BinarySearch(pInfo.Winners, k) != -1 {
  881. deleteSlice(pInfo.Winners, k, "")
  882. sort.Strings(pInfo.Winners)
  883. }
  884. } else {
  885. if BinarySearch(pInfo.Winners, k) == -1 {
  886. pInfo.Winners = append(pInfo.Winners, k)
  887. sort.Strings(pInfo.Winners)
  888. }
  889. }
  890. }
  891. set["s_winner"] = strings.Join(pInfo.Winners, ",")
  892. }
  893. if thisinfo.HasPackage { //多包处理
  894. set["multipackage"] = 1
  895. pkg := PackageFormat(thisinfo, pInfo)
  896. pInfo.Package = pkg
  897. set["package"] = pInfo.Package
  898. }
  899. //处理多包后,计算预算金额、中标金额
  900. CountAmount(pInfo, thisinfo, tmp)
  901. if pInfo.Budget >= 0 && pInfo.Budgettag != 1 {
  902. set["budget"] = pInfo.Budget
  903. set["budgettag"] = 0
  904. }
  905. if pInfo.Bidamount >= 0 && pInfo.Bidamounttag != 1 {
  906. set["bidamount"] = pInfo.Bidamount
  907. set["bidamounttag"] = 0
  908. }
  909. if pInfo.Bidamount >= pInfo.Budget {
  910. set["sortprice"] = pInfo.Bidamount
  911. } else if pInfo.Budget >= pInfo.Bidamount {
  912. set["sortprice"] = pInfo.Budget
  913. }
  914. infofield := InfoField{
  915. Budget: thisinfo.Budget,
  916. Bidamount: thisinfo.Bidamount,
  917. ContractCode: thisinfo.ContractCode,
  918. ProjectName: thisinfo.ProjectName,
  919. ProjectCode: thisinfo.ProjectCode,
  920. Bidstatus: bs,
  921. }
  922. copyMap := Copy(pInfo.InfoFiled).(map[string]InfoField)
  923. copyMap[thisinfo.Id] = infofield
  924. tmpMap := make(map[string]interface{})
  925. for k, v := range copyMap {
  926. tmpMap[k] = StructToMap(v)
  927. }
  928. tmpMap[thisinfo.Id] = StructToMap(infofield)
  929. pInfo.InfoFiled = copyMap
  930. set["infofield"] = tmpMap
  931. set["mpn"] = pInfo.MPN
  932. set["mpc"] = pInfo.MPC
  933. if p.currentType == "project" {
  934. set["pici"] = p.pici
  935. } else {
  936. set["pici"] = tmp["comeintime"]
  937. }
  938. update := map[string]interface{}{}
  939. if len(set) > 0 {
  940. update["$set"] = set
  941. }
  942. push := p.PushListInfo(tmp, thisinfo.Id)
  943. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  944. push["compareStr"] = comStr
  945. push["resVal"] = pInfo.resVal
  946. push["pjVal"] = pInfo.pjVal
  947. update["$push"] = map[string]interface{}{
  948. "list": push,
  949. "ids": thisinfo.Id,
  950. }
  951. //clearMap := map[string]interface{}{}
  952. //ClearData(clearMap, set)
  953. //if len(clearMap) > 0 {
  954. // update["$unset"] = clearMap
  955. //}
  956. if len(update) > 0 {
  957. updateInfo := []map[string]interface{}{
  958. {
  959. "_id": pInfo.Id,
  960. },
  961. update,
  962. }
  963. p.updatePool <- updateInfo
  964. }
  965. }
  966. /**
  967. * 更新项目时,项目状态的处理
  968. * 返回是否新增项目,异常标记
  969. * 1、新增项目时,招标信息的状态(toptype)不是招标、拟建、预告 异常:1
  970. * 异常1是在项目新建的时候才会产生
  971. * 3、项目合并时,项目状态是”流标“/”废标“,招标信息状态不是”招标“ 异常:2
  972. * 4、项目合并时,项目状态是”合同“/”其它“,招标信息类型是”结果“ 异常:3
  973. */
  974. func (p *ProjectTask) CompareStatus(project *ProjectInfo, info *Info) (bool, int) {
  975. if info.TopType == "拟建" || info.TopType == "预告" || info.TopType == "招标" {
  976. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  977. return false, 0
  978. } else if project.Bidstatus == "废标" || project.Bidstatus == "流标" {
  979. return false, 0
  980. } else {
  981. return true, 0
  982. }
  983. } else if info.TopType == "结果" {
  984. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  985. return false, 0
  986. } else if project.Bidstatus == info.SubType {
  987. //状态一样,根据发布时间判断是否合并
  988. if (info.Publishtime - project.LastTime) > p.statusTime {
  989. return true, 0
  990. } else {
  991. return false, 0
  992. }
  993. } else if project.Bidstatus == "成交" && info.SubType == "中标" {
  994. return true, 0
  995. } else if project.Bidstatus == "流标" || project.Bidstatus == "废标" {
  996. return false, 2
  997. } else if project.Bidstatus == "合同" || project.Bidstatus == "其它" {
  998. return false, 3
  999. } else {
  1000. return false, 0
  1001. }
  1002. } else {
  1003. return false, 0
  1004. }
  1005. }
  1006. /*
  1007. * 对比地区(省、市),存在且不同,不能合并
  1008. * 返回是否新建项目
  1009. */
  1010. func ComparePlace(project *ProjectInfo, info *Info) bool {
  1011. if info.Area == "全国" || info.Area == "" {
  1012. return false
  1013. }
  1014. if project.Area == "全国" || project.Area == "" {
  1015. return false
  1016. }
  1017. if info.Area == project.Area {
  1018. if info.City == "" || project.City == "" {
  1019. return false
  1020. } else if info.City == project.City {
  1021. return false
  1022. }
  1023. } else {
  1024. return true
  1025. }
  1026. return true
  1027. }
  1028. var PackageEle = []string{
  1029. "origin",
  1030. "name",
  1031. //"text",
  1032. "budget",
  1033. "winner",
  1034. "bidamount",
  1035. "bidamounttype",
  1036. "currency",
  1037. "bidstatus",
  1038. }
  1039. func packageEle(map1 map[string]interface{}, id string) map[string]interface{} {
  1040. p2 := map[string]interface{}{}
  1041. for _, k := range PackageEle {
  1042. if map1[k] != nil {
  1043. p2[k] = map1[k]
  1044. }
  1045. infoid := p2["infoid"]
  1046. if infoid == nil {
  1047. p2["infoid"] = id
  1048. }
  1049. }
  1050. return p2
  1051. }
  1052. func PackageFormat(info *Info, project *ProjectInfo) map[string]interface{} {
  1053. p1 := map[string]interface{}{}
  1054. if project != nil && project.Package != nil && len(project.Package) > 0 {
  1055. packageCopy := Copy(project.Package).(map[string]interface{})
  1056. p1 = packageCopy
  1057. for k, v := range info.Package {
  1058. if v1, ok := v.(map[string]interface{}); ok {
  1059. v2 := map[string]interface{}{}
  1060. v2 = packageEle(v1, info.Id)
  1061. if v2["bidstatus"] == nil {
  1062. v2["bidstatus"] = info.SubType
  1063. }
  1064. addFlag := false
  1065. for k1, v3 := range p1 {
  1066. if v4, ok := v3.([]map[string]interface{}); ok {
  1067. //if qu.ObjToString(v4[0]["origin"]) == qu.ObjToString(v2["origin"]) && qu.ObjToString(v4[0]["name"]) == qu.ObjToString(v2["name"]) {
  1068. if k1 == k {
  1069. v4 = append(v4, v2)
  1070. p1[k1] = v4
  1071. addFlag = true
  1072. break
  1073. }
  1074. }
  1075. }
  1076. if !addFlag {
  1077. p1[k] = []map[string]interface{}{v2}
  1078. }
  1079. }
  1080. }
  1081. } else {
  1082. for k, v := range info.Package {
  1083. v1, _ := v.(map[string]interface{})
  1084. p2 := map[string]interface{}{}
  1085. p2 = packageEle(v1, info.Id)
  1086. if p2["bidstatus"] == nil {
  1087. p2["bidstatus"] = info.SubType
  1088. }
  1089. p1[k] = []map[string]interface{}{p2}
  1090. }
  1091. }
  1092. return p1
  1093. }
  1094. // 计算预算(budget)、中标金额(bidamount)
  1095. func CountAmount(project *ProjectInfo, info *Info, tmp map[string]interface{}) {
  1096. if info.HasPackage {
  1097. budget := 0.0
  1098. for _, v := range project.Package {
  1099. v1, _ := v.([]map[string]interface{})
  1100. for _, v2 := range v1 {
  1101. if v2["budget"] != nil {
  1102. b1 := qu.Float64All(v2["budget"])
  1103. if b1 > 0 {
  1104. budget = budget + b1
  1105. break
  1106. }
  1107. } else {
  1108. project.Budgettag = 1
  1109. }
  1110. }
  1111. }
  1112. if budget > 0 {
  1113. project.Budget = budget
  1114. project.Budgettag = 0
  1115. } else if budget == 0 && info.Budget > 0 {
  1116. project.Budget = info.Budget
  1117. project.Budgettag = 0
  1118. }
  1119. } else {
  1120. //招标没有多包
  1121. k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1122. if len(k) > 0 {
  1123. //招标是单包
  1124. if len(project.Package) > 0 {
  1125. //项目有多包
  1126. flag := false
  1127. for _, v := range project.Package {
  1128. v1, _ := v.([]map[string]interface{})
  1129. if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1130. flag = true
  1131. }
  1132. }
  1133. if !flag {
  1134. project.Budget = project.Budget + info.Budget
  1135. project.Budgettag = 0
  1136. }
  1137. } else {
  1138. //项目没有多包
  1139. if info.Budget > 0 {
  1140. project.Budget = project.Budget + info.Budget
  1141. project.Budgettag = 0
  1142. } else if info.Budget == 0 && tmp["budget"] != nil {
  1143. project.Budgettag = 0
  1144. }
  1145. }
  1146. } else {
  1147. if info.Budget > 0 && project.Budget < info.Budget {
  1148. project.Budget = info.Budget
  1149. project.Budgettag = 0
  1150. }
  1151. }
  1152. }
  1153. if info.SubType == "中标" || info.SubType == "成交" || info.SubType == "合同" {
  1154. if info.HasPackage {
  1155. bidamount := 0.0
  1156. for _, v := range project.Package {
  1157. v1, _ := v.([]map[string]interface{})
  1158. for _, v2 := range v1 {
  1159. b1 := qu.Float64All(v2["bidamount"])
  1160. if b1 > 0 {
  1161. bidamount = bidamount + b1
  1162. break
  1163. }
  1164. }
  1165. }
  1166. if bidamount > 0 {
  1167. project.Bidamount = bidamount
  1168. project.Bidamounttag = 0
  1169. } else if bidamount == 0 && info.Bidamount > 0 {
  1170. project.Bidamount = info.Bidamount
  1171. project.Bidamounttag = 0
  1172. }
  1173. } else {
  1174. //招标没有多包
  1175. k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1176. if len(k) > 0 {
  1177. //招标是单包
  1178. if len(project.Package) > 0 {
  1179. //项目有多包
  1180. flag := false
  1181. for _, v := range project.Package {
  1182. v1, _ := v.([]map[string]interface{})
  1183. if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1184. flag = true
  1185. }
  1186. }
  1187. if !flag {
  1188. project.Bidamount = project.Bidamount + info.Bidamount
  1189. project.Bidamounttag = 0
  1190. }
  1191. } else {
  1192. //项目没有多包
  1193. if info.Bidamount > 0 {
  1194. project.Bidamount = project.Bidamount + info.Bidamount
  1195. project.Bidamounttag = 0
  1196. } else if info.Bidamount == 0 && tmp["bidamount"] != nil {
  1197. project.Bidamounttag = 0
  1198. } else {
  1199. project.Bidamounttag = 1
  1200. }
  1201. }
  1202. } else {
  1203. if info.SubType == "中标" || info.SubType == "成交" {
  1204. if info.Bidamount > 0 {
  1205. project.Bidamount = info.Bidamount
  1206. project.Bidamounttag = 0
  1207. } else {
  1208. flag := false
  1209. if project.InfoFiled != nil && len(project.InfoFiled) > 0 {
  1210. for _, res := range project.InfoFiled {
  1211. if res.ContractCode != "" && res.ContractCode == info.ContractCode {
  1212. flag = true
  1213. break
  1214. }
  1215. if res.Bidamount == project.Bidamount {
  1216. flag = true
  1217. break
  1218. }
  1219. }
  1220. if !flag {
  1221. project.Bidamount = project.Bidamount + info.Bidamount
  1222. project.Bidamounttag = 0
  1223. } else {
  1224. if info.Budget > 0 && project.Bidamount > info.Bidamount {
  1225. project.Bidamount = info.Bidamount
  1226. project.Bidamounttag = 0
  1227. }
  1228. }
  1229. }
  1230. }
  1231. }
  1232. }
  1233. }
  1234. } else {
  1235. project.Bidamounttag = 1
  1236. }
  1237. }
  1238. //结构体转map
  1239. func StructToMap(filed InfoField) map[string]interface{} {
  1240. //先转json
  1241. result, err := json.Marshal(filed)
  1242. if err != nil {
  1243. return nil
  1244. }
  1245. //json转map
  1246. res := make(map[string]interface{})
  1247. err = json.Unmarshal(result, &res)
  1248. return res
  1249. }
  1250. func ClearData(clearMap, tmp map[string]interface{}) {
  1251. for k, v := range tmp {
  1252. if v == "" {
  1253. clearMap[k] = ""
  1254. }
  1255. }
  1256. }
  1257. func IsCreatePro(info *Info) (bol bool) {
  1258. bol = true
  1259. if info.SubType == "" || info.SubType == "变更" || info.SubType == "验收" || info.SubType == "违规" ||
  1260. info.SubType == "结果变更" || info.SubType == "其它" {
  1261. if info.ProjectName == "" && info.ProjectCode == "" {
  1262. bol = false
  1263. }else if info.ProjectName == "" && info.Buyer == "" {
  1264. bol = false
  1265. }else if info.ProjectCode == "" && info.Buyer == "" {
  1266. bol = false
  1267. }
  1268. }
  1269. return bol
  1270. }
  1271. var bidtype = map[string]string{
  1272. "招标": "招标",
  1273. "邀标": "邀标",
  1274. "询价": "询价",
  1275. "单一": "单一",
  1276. "竞价": "竞价",
  1277. "竞谈": "竞谈",
  1278. }
  1279. var bidstatus = map[string]string{
  1280. "预告": "预告",
  1281. "中标": "中标",
  1282. "成交": "成交",
  1283. "废标": "废标",
  1284. "流标": "流标",
  1285. "合同": "合同",
  1286. }
  1287. func GetBidTypeAndBidStatus(info *Info) (string, string) {
  1288. typeStr := bidtype[info.TopType]
  1289. statusStr := bidstatus[info.SubType]
  1290. if info.Infoformat == 2 || info.SubType == "拟建" {
  1291. statusStr = "拟建"
  1292. typeStr = ""
  1293. } else {
  1294. if bidtype[typeStr] == "" {
  1295. typeStr = "招标"
  1296. }
  1297. if typeStr == "招标" {
  1298. statusStr = typeStr
  1299. } else {
  1300. if statusStr == "" {
  1301. statusStr = "其它"
  1302. }
  1303. }
  1304. }
  1305. return typeStr, statusStr
  1306. }