project.go 35 KB

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