project.go 35 KB

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