project.go 36 KB

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