project.go 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  1. package main
  2. import (
  3. "encoding/json"
  4. "log"
  5. "math"
  6. "mongodb"
  7. qu "qfw/util"
  8. "sort"
  9. "strings"
  10. "time"
  11. "go.mongodb.org/mongo-driver/bson"
  12. "go.mongodb.org/mongo-driver/bson/primitive"
  13. )
  14. /**
  15. 项目合并,对比,计算,合并,生成项目
  16. **/
  17. //从对应map中获取对比的项目id
  18. func (p *ProjectTask) getCompareIds(pn, pc, ptc, pb string) (bpn, bpc, bptc, bpb int, res []*Key, idArr []string, IDArr []*ID) {
  19. // p.ConCurrentLock(n1, n2, n3, n4)
  20. // defer p.ConCurrentUnLock(n1, n2, n3, n4)
  21. p.wg.Add(1)
  22. //查找到id数组
  23. res = []*Key{}
  24. //是否查找到,并标识位置。-1代表值为空或已经存在。
  25. bpn, bpc, bptc, bpb = -1, -1, -1, -1
  26. if pn != "" {
  27. ids := p.mapPn[pn]
  28. if ids == nil {
  29. ids = &Key{Arr: []string{}}
  30. p.mapPn[pn] = ids
  31. bpn = 0
  32. }
  33. ids.Lock.Lock()
  34. res = append(res, ids)
  35. }
  36. if pc != "" {
  37. ids := p.mapPc[pc]
  38. if ids == nil {
  39. ids = &Key{Arr: []string{}}
  40. p.mapPc[pc] = ids
  41. bpc = len(res)
  42. }
  43. ids.Lock.Lock()
  44. res = append(res, ids)
  45. }
  46. if ptc != "" {
  47. ids := p.mapPc[ptc]
  48. if ids == nil {
  49. ids = &Key{Arr: []string{}}
  50. p.mapPc[ptc] = ids
  51. bptc = len(res)
  52. }
  53. ids.Lock.Lock()
  54. res = append(res, ids)
  55. }
  56. if pb != "" {
  57. ids := p.mapPb[pb]
  58. if ids == nil {
  59. ids = &Key{Arr: []string{}}
  60. p.mapPb[pb] = ids
  61. bpb = len(res)
  62. }
  63. ids.Lock.Lock()
  64. res = append(res, ids)
  65. }
  66. repeatId := map[string]bool{}
  67. idArr = []string{} //项目id
  68. IDArr = []*ID{} //项目信息
  69. for _, m := range res {
  70. for _, id := range m.Arr {
  71. if !repeatId[id] {
  72. repeatId[id] = true
  73. //_, _ = strconv.ParseInt(id[0:8], 16, 64)
  74. p.AllIdsMapLock.Lock()
  75. Id := p.AllIdsMap[id]
  76. p.AllIdsMapLock.Unlock()
  77. if Id != nil {
  78. Id.Lock.Lock()
  79. idArr = append(idArr, id)
  80. IDArr = append(IDArr, Id)
  81. }
  82. }
  83. }
  84. }
  85. return
  86. }
  87. func (p *ProjectTask) startProjectMerge(info *Info, tmp map[string]interface{}) {
  88. p.findLock.Lock()
  89. defer p.findLock.Unlock()
  90. // 3.18 isfow=0数据不参与项目合并
  91. code := strings.ReplaceAll(qu.ObjToString(tmp["spidercode"]), " ", "")
  92. p.mapSpiderLock.Lock()
  93. isflow := p.mapSpider[code]
  94. qu.Debug(code, isflow)
  95. p.mapSpiderLock.Unlock()
  96. if isflow == 0 {
  97. p.NewProject(tmp, info)
  98. qu.Debug("直接新建项目,", "project id")
  99. return
  100. }
  101. //只有或没有采购单位的无法合并
  102. //bpn, bpc, bptc, bpb 是否查找到,并标识位置。-1代表未查找到。
  103. //pids 是项目id数组集合
  104. //IDArr,是单个项目ID对象集合
  105. 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)))
  106. defer p.wg.Done()
  107. //map--k为pn,ptn,pc,ptc,buyer值 v为Id数组和lock
  108. for _, m := range pids {
  109. defer m.Lock.Unlock()
  110. }
  111. for _, id := range IDArr {
  112. defer id.Lock.Unlock()
  113. }
  114. bFindProject := false
  115. findPid := ""
  116. //获取完id,进行计算
  117. //定义两组
  118. comRes1 := []*ProjectInfo{} //优先级最高的对比结果数组
  119. comRes2 := []*ProjectInfo{} //优化级其次
  120. comRes3 := []*ProjectInfo{}
  121. for _, v := range IDArr {
  122. comStr := ""
  123. compareProject := v.P
  124. compareProject.score = 0
  125. //问题出地LastTime!!!!!
  126. diffTime := int64(math.Abs(float64(info.Publishtime - compareProject.LastTime)))
  127. if diffTime <= p.validTime {
  128. //代理机构完全不相同,直接新建项目
  129. if CheckContain(compareProject.Agency, info.Agency) == 3 {
  130. continue
  131. }
  132. //地区(省、市、区)不同,直接新建项目
  133. if ComparePlace(compareProject, info) {
  134. continue
  135. }
  136. info.PNBH = 0
  137. info.PCBH = 0
  138. info.PTCBH = 0
  139. compareStr, score := comparePNC(info, compareProject)
  140. resVal, pjVal := Select(compareStr, info, compareProject)
  141. //---------------------------------------
  142. //log.Println(resVal, pjVal, compareProject)
  143. if resVal > 0 {
  144. compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount, score2 := p.compareBCTABB(info, compareProject, diffTime, score)
  145. //项目名称、项目编号、标题项目编号、采购单位、省、市、发布时间、代理机构
  146. comStr = compareStr + compareBuyer + compareCity + compareTime + compareAgency + compareBudget + compareBidmount
  147. compareProject.comStr = comStr
  148. compareProject.pjVal = pjVal
  149. compareProject.resVal = resVal
  150. //log.Println(compareProject.comStr)
  151. eqV := compareResult(resVal, pjVal, score2, comStr, compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount)
  152. if eqV == 1 {
  153. comRes1 = append(comRes1, compareProject)
  154. } else if eqV == 2 {
  155. comRes2 = append(comRes2, compareProject)
  156. } else if eqV == 3 {
  157. comRes3 = append(comRes3, compareProject)
  158. }
  159. }
  160. }
  161. }
  162. //--------------------------------对比完成-----------------------
  163. //更新数组、更新项目
  164. for kv, resN := range [][]*ProjectInfo{comRes1, comRes2, comRes3} {
  165. if len(resN) > 0 {
  166. if len(resN) > 1 {
  167. sort.Slice(resN, func(i, j int) bool {
  168. return resN[i].score > resN[j].score
  169. })
  170. }
  171. ex := 0
  172. resArr := []*ProjectInfo{}
  173. for i, res := range resN {
  174. choose, e := p.CompareStatus(resN[i], info)
  175. if !choose {
  176. ex = e
  177. resArr = append(resArr, res)
  178. }
  179. }
  180. if len(resArr) > 0 {
  181. bFindProject = true
  182. findPid = resArr[0].Id.Hex()
  183. p.UpdateProject(tmp, info, resArr[0], kv+1, resArr[0].comStr, ex)
  184. for k2, bv := range []int{bpn, bpc, bptc, bpb} {
  185. if bv > -1 {
  186. pids[bv].Arr = append(pids[bv].Arr, findPid)
  187. if k2 == 0 {
  188. if resArr[0].ProjectName == "" {
  189. resArr[0].ProjectName = info.ProjectName
  190. } else {
  191. if resArr[0].MPN == nil {
  192. resArr[0].MPN = []string{info.ProjectName}
  193. } else {
  194. resArr[0].MPN = append(resArr[0].MPN, info.ProjectName)
  195. }
  196. }
  197. } else if k2 < 3 {
  198. if resArr[0].ProjectCode == "" {
  199. resArr[0].ProjectCode = qu.If(k2 == 1, info.ProjectCode, info.PTC).(string)
  200. } else {
  201. if resArr[0].MPC == nil {
  202. resArr[0].MPC = []string{qu.If(k2 == 1, info.ProjectCode, info.PTC).(string)}
  203. } else {
  204. resArr[0].MPC = append(resArr[0].MPC, qu.If(k2 == 1, info.ProjectCode, info.PTC).(string))
  205. }
  206. }
  207. } else {
  208. if resArr[0].Buyer == "" {
  209. resArr[0].Buyer = info.Buyer
  210. }
  211. }
  212. }
  213. }
  214. } else {
  215. bFindProject = false
  216. findPid = ""
  217. }
  218. break
  219. }
  220. }
  221. if !bFindProject {
  222. //if !IsCreatePro(info) {
  223. // qu.Debug("舍弃数据---", info.Id)
  224. // return
  225. //}
  226. qu.Debug("直接新建项目----")
  227. id, p1 := p.NewProject(tmp, info)
  228. p.AllIdsMapLock.Lock()
  229. p.AllIdsMap[id] = &ID{Id: id, P: p1}
  230. p.AllIdsMapLock.Unlock()
  231. for _, m := range pids {
  232. m.Arr = append(m.Arr, id)
  233. }
  234. }
  235. }
  236. func (p *ProjectTask) compareBCTABB(info *Info, cp *ProjectInfo, diffTime int64, score int) (compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount string, score2 int) {
  237. compareBuyer = "D"
  238. if len([]rune(info.Buyer)) > 3 && len([]rune(cp.Buyer)) > 3 {
  239. v := CheckContain(info.Buyer, cp.Buyer)
  240. if v == 1 {
  241. compareBuyer = "A"
  242. score += 3
  243. } else {
  244. //v1 := CosineSimilar(info.Buyer, cp.Buyer)
  245. if v == 2 {
  246. compareBuyer = "B"
  247. score += 1
  248. } else {
  249. compareBuyer = "C"
  250. }
  251. }
  252. }
  253. //---------------------------------------
  254. compareCity = ""
  255. if info.Area != "全国" && info.Area != "" && info.Area == cp.Area {
  256. compareCity += "A"
  257. score += 2
  258. } else if info.Area == "全国" || cp.Area == "全国" {
  259. compareCity += "B"
  260. score += 1
  261. } else {
  262. compareCity += "C"
  263. }
  264. if compareCity != "C" {
  265. if info.City != "" && info.City == cp.City {
  266. compareCity += "A"
  267. score += 2
  268. } else {
  269. if info.Area == "全国" || cp.Area == "全国" {
  270. compareCity += "B"
  271. } else if info.City == compareCity {
  272. compareCity += "B"
  273. } else {
  274. compareCity += "C"
  275. }
  276. }
  277. } else {
  278. compareCity += "C"
  279. }
  280. score2 = 0
  281. if compareCity == "AA" {
  282. if info.District != "" && info.District == cp.District {
  283. score2 = 1
  284. }
  285. }
  286. compareTime = "D"
  287. if diffTime < 45*86400 {
  288. compareTime = "A"
  289. score += 2
  290. } else if diffTime < 90*86400 {
  291. compareTime = "B"
  292. score += 1
  293. }
  294. compareAgency = "D"
  295. if info.Agency != "" {
  296. if info.Agency == cp.Agency {
  297. compareAgency = "A"
  298. score += 2
  299. score2 += 1
  300. } else if cp.Agency != "" {
  301. if strings.Contains(info.Agency, cp.Agency) || strings.Contains(cp.Agency, info.Agency) {
  302. compareAgency = "B"
  303. score += 1
  304. score2 += 1
  305. } else {
  306. compareAgency = "C"
  307. }
  308. }
  309. }
  310. compareBudget = "C"
  311. if info.Budget > 0 && (info.Budget == cp.Budget || (cp.Bidamount > 0 && info.Budget > cp.Bidamount && (info.Budget-cp.Bidamount) < (0.15*info.Budget))) {
  312. compareBudget = "A"
  313. score += 1
  314. score2 += 1
  315. }
  316. // else if info.Budget == 0 && cp.Budget == 0 {
  317. // compareBudget = "B"
  318. // }
  319. compareBidmount = "C"
  320. if info.Bidamount > 0 && (info.Bidamount == cp.Bidamount || (cp.Budget > 0 && cp.Budget > info.Bidamount && (cp.Budget-info.Bidamount) < 0.15*cp.Budget)) {
  321. compareBidmount = "A"
  322. score += 1
  323. score2 += 1
  324. }
  325. // else if info.Bidamount == 0 && cp.Bidamount == 0 {
  326. // compareBidmount = "B"
  327. // }
  328. cp.score = score
  329. return
  330. }
  331. func compareResult(resVal, pjVal, score2 int, comStr, compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount string) int {
  332. eqV := 0
  333. switch resVal {
  334. case 3:
  335. if pjVal == 3 && comStr[3:] != "CCCDCCC" {
  336. eqV = 1
  337. } else if compareBuyer < "C" {
  338. if pjVal > 1 {
  339. eqV = 1
  340. } else { //if (compareCity[1:1] != "C" || compareTime != "D") && score2 > 0
  341. eqV = 2
  342. }
  343. } else if compareBuyer == "D" {
  344. if pjVal > 1 && (compareCity[1:1] != "C" || score2 > 0) {
  345. eqV = 2
  346. } else if compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  347. eqV = 3
  348. }
  349. } else {
  350. if pjVal == 3 && (score2 > 0 || compareCity[1:1] != "C") {
  351. eqV = 2
  352. } else if pjVal == 2 && compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  353. eqV = 3
  354. } else if compareCity == "AA" && compareTime == "A" && score2 > 0 {
  355. eqV = 3
  356. }
  357. }
  358. case 2:
  359. if compareBuyer < "C" {
  360. if pjVal > 1 {
  361. eqV = 2
  362. } else if compareCity[1:1] != "C" && compareTime == "A" || score2 > 0 {
  363. eqV = 3
  364. }
  365. } else if compareBuyer == "D" {
  366. if pjVal > 1 && (score2 > 0 || compareCity[1:1] != "C") {
  367. eqV = 2
  368. } else if compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  369. eqV = 3
  370. }
  371. } else {
  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. }
  378. case 1:
  379. if compareBuyer < "C" {
  380. if pjVal > 1 && (score2 > 0 || compareCity[1:1] != "C") {
  381. eqV = 2
  382. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  383. eqV = 3
  384. }
  385. } else if compareBuyer == "D" {
  386. if pjVal > 1 && compareTime == "A" && (score2 > 0 || compareCity[1:1] != "C") {
  387. eqV = 2
  388. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  389. eqV = 3
  390. }
  391. } else {
  392. if pjVal > 1 && compareTime == "A" && score2 > 0 && (compareBudget == "A" || compareBidmount == "A") && compareCity[1:1] != "C" {
  393. eqV = 3
  394. }
  395. }
  396. }
  397. return eqV
  398. }
  399. //招标时间zbtime、中标时间jgtime、项目状态bidstatus、招标类型bidtype、最后发布时间lasttime、首次发布时间firsttime
  400. func (p *ProjectTask) NewProject(tmp map[string]interface{}, thisinfo *Info) (string, *ProjectInfo) {
  401. //pId := primitive.NewObjectID() //NewObjectId()
  402. pId := mongodb.StringTOBsonId(thisinfo.Id)
  403. set := map[string]interface{}{}
  404. set["_id"] = pId
  405. for _, f := range FIELDS {
  406. if tmp[f] != nil && tmp[f] != "" {
  407. set[f] = tmp[f]
  408. }
  409. }
  410. bidopentime := qu.Int64All(tmp["bidopentime"])
  411. if bidopentime > 0 {
  412. set["bidopentime"] = bidopentime
  413. }
  414. //异常标记
  415. if thisinfo.TopType != "招标" && thisinfo.TopType != "拟建" && thisinfo.TopType != "预告" {
  416. set["exception"] = 1
  417. }
  418. //projecthref保存
  419. if jsonData, ok := tmp["jsondata"].(map[string]interface{}); ok {
  420. if jsonData != nil && qu.ObjToString(jsonData["projecthref"]) != "" {
  421. set["projecthref"] = jsonData["projecthref"]
  422. }
  423. }
  424. //合同编号
  425. if thisinfo.ContractCode != "" {
  426. set["contractcode"] = thisinfo.ContractCode
  427. }
  428. bt := qu.ObjToString(tmp["toptype"])
  429. bs := qu.ObjToString(tmp["subtype"])
  430. p.mapBidLock.Lock()
  431. if thisinfo.Infoformat == 2 || thisinfo.SubType == "拟建" {
  432. set["bidstatus"] = "拟建"
  433. bt = "拟建"
  434. } else {
  435. if bidtype[bs] != "" {
  436. set["bidtype"] = bidtype[bs]
  437. } else {
  438. set["bidtype"] = "招标"
  439. }
  440. if bt == "招标" {
  441. set["projectscope"] = qu.ObjToString(tmp["projectscope"])
  442. set["bidstatus"] = bt
  443. } else {
  444. if bidstatus[bs] != "" {
  445. set["bidstatus"] = thisinfo.SubType
  446. bt = thisinfo.SubType
  447. } else if bs == "" {
  448. set["bidstatus"] = ""
  449. bt = ""
  450. } else {
  451. set["bidstatus"] = "其它"
  452. bt = "其它"
  453. }
  454. }
  455. }
  456. p.mapBidLock.Unlock()
  457. pkg := PackageFormat(thisinfo, nil)
  458. p1 := p.NewCachePinfo(pId, thisinfo, bs, bt, pkg)
  459. now := time.Now().Unix()
  460. set["createtime"] = now
  461. set["sourceinfoid"] = thisinfo.Id
  462. set["sourceinfourl"] = tmp["href"]
  463. set["firsttime"] = tmp["publishtime"]
  464. set["lasttime"] = tmp["publishtime"]
  465. //增量用系统时间,全量(历史)入库时间
  466. if p.currentType == "project" {
  467. set["pici"] = p.pici
  468. } else {
  469. set["pici"] = tmp["comeintime"]
  470. }
  471. set["ids"] = []string{thisinfo.Id}
  472. if thisinfo.TopType == "招标" {
  473. //if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
  474. set["zbtime"] = tmp["publishtime"]
  475. p1.Zbtime = qu.Int64All(tmp["publishtime"])
  476. //}
  477. } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
  478. set["jgtime"] = tmp["publishtime"]
  479. p1.Jgtime = thisinfo.Publishtime
  480. }
  481. if len(thisinfo.Subscopeclass) > 0 {
  482. set["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
  483. }
  484. if len(thisinfo.Winners) > 0 {
  485. set["s_winner"] = strings.Join(thisinfo.Winners, ",")
  486. p1.Winners = thisinfo.Winners
  487. }
  488. if thisinfo.HasPackage {
  489. set["multipackage"] = 1
  490. set["package"] = pkg
  491. } else {
  492. set["multipackage"] = 0
  493. }
  494. //项目评审专家
  495. if len(thisinfo.ReviewExperts) > 0 {
  496. set["review_experts"] = thisinfo.ReviewExperts
  497. p1.ReviewExperts = thisinfo.ReviewExperts
  498. }
  499. //标的物
  500. if thisinfo.Purchasing != "" {
  501. list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
  502. p := strings.Join(qu.ObjArrToStringArr(list), ",")
  503. set["purchasing"] = p
  504. p1.Purchasing = p
  505. }
  506. //中标候选人
  507. if len(thisinfo.WinnerOrder) > 0 {
  508. var list = []string{}
  509. for _, v := range thisinfo.WinnerOrder {
  510. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  511. list = append(list, qu.ObjToString(v["entname"]))
  512. }
  513. }
  514. set["winnerorder"] = list
  515. p1.Winnerorder = list
  516. }
  517. //项目规模
  518. if len(thisinfo.ProjectScale) > 0 {
  519. p1.ProjectScale = thisinfo.ProjectScale
  520. set["project_scale"] = thisinfo.ProjectScale
  521. }
  522. //工期时长
  523. if thisinfo.ProjectDuration > 0 {
  524. p1.ProjectDuration = thisinfo.ProjectDuration
  525. set["project_duration"] = thisinfo.ProjectDuration
  526. }
  527. // 工期单位
  528. if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
  529. p1.ProjectTimeunit = thisinfo.ProjectTimeUnit
  530. set["project_timeunit"] = thisinfo.ProjectTimeUnit
  531. }
  532. //开工日期
  533. if thisinfo.ProjectStartDate > 0 {
  534. p1.ProjectStartDate = thisinfo.ProjectStartDate
  535. set["project_startdate"] = thisinfo.ProjectStartDate
  536. }
  537. //竣工日期
  538. if thisinfo.ProjectCompleteDate > 0 {
  539. p1.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  540. set["project_completedate"] = thisinfo.ProjectCompleteDate
  541. }
  542. //付款方式
  543. if len(thisinfo.Payway) > 0 {
  544. p1.Payway = thisinfo.Payway
  545. set["payway"] = thisinfo.Payway
  546. }
  547. // 履约保证金
  548. if tmp["contract_guarantee"] != nil {
  549. p1.ContractGuarantee = thisinfo.ContractGuarantee
  550. set["contract_guarantee"] = thisinfo.ContractGuarantee
  551. }
  552. // 投标保证金
  553. if tmp["bid_guarantee"] != nil {
  554. p1.BidGuarantee = thisinfo.BidGuarantee
  555. set["bid_guarantee"] = thisinfo.BidGuarantee
  556. }
  557. // 资质条件
  558. if len(thisinfo.Qualifies) > 0 {
  559. var str []string
  560. for _, v := range thisinfo.Qualifies {
  561. if len(qu.ObjToString(v["key"])) > 0 {
  562. if BinarySearch(str, qu.ObjToString(v["key"])) == -1 {
  563. str = append(str, qu.ObjToString(v["key"]))
  564. }
  565. }
  566. }
  567. if len(str) > 0 {
  568. p1.Qualifies = strings.Join(str, ",")
  569. set["qualifies"] = strings.Join(str, ",")
  570. }
  571. }
  572. if len(p1.EntIdList) > 0 {
  573. set["entidlist"] = p1.EntIdList
  574. }
  575. p1.InfoFiled = make(map[string]InfoField)
  576. infofield := InfoField{
  577. Budget: thisinfo.Budget,
  578. Bidamount: thisinfo.Bidamount,
  579. ContractCode: thisinfo.ContractCode,
  580. ProjectName: thisinfo.ProjectName,
  581. ProjectCode: thisinfo.ProjectCode,
  582. Bidstatus: bs,
  583. }
  584. p1.InfoFiled[thisinfo.Id] = infofield
  585. res := StructToMap(infofield)
  586. set["infofield"] = map[string]interface{}{
  587. thisinfo.Id: res,
  588. }
  589. if tmp["budget"] != nil && tmp["budget"] != "" {
  590. set["budget"] = thisinfo.Budget
  591. p1.Budgettag = 0
  592. set["budgettag"] = 0
  593. } else {
  594. p1.Budgettag = 1
  595. set["budgettag"] = 1
  596. }
  597. if tmp["bidamount"] != nil && tmp["bidamount"] != "" {
  598. set["bidamount"] = thisinfo.Bidamount
  599. p1.Bidamounttag = 0
  600. set["bidamounttag"] = 0
  601. } else {
  602. p1.Bidamounttag = 1
  603. set["bidamounttag"] = 1
  604. }
  605. if p1.Bidamount > 0 {
  606. set["sortprice"] = p1.Bidamount
  607. } else if p1.Budget > 0 {
  608. set["sortprice"] = p1.Budget
  609. }
  610. push := p.PushListInfo(tmp, thisinfo.Id)
  611. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  612. set["list"] = []bson.M{
  613. push,
  614. }
  615. //p.savePool <- set
  616. p.updatePool <- []map[string]interface{}{
  617. {
  618. "_id": pId,
  619. },
  620. {
  621. "$set": set,
  622. },
  623. }
  624. return pId.Hex(), &p1
  625. }
  626. //项目中list的信息
  627. func (p *ProjectTask) PushListInfo(tmp map[string]interface{}, infoid string) bson.M {
  628. res := bson.M{
  629. "infoid": infoid,
  630. }
  631. for _, k := range INFOFIELDS {
  632. if tmp[k] != nil {
  633. res[k] = tmp[k]
  634. }
  635. }
  636. return res
  637. }
  638. //生成存放在内存中的对象
  639. func (p *ProjectTask) NewCachePinfo(id primitive.ObjectID, thisinfo *Info, bidtype, bidstatus string, pkg map[string]interface{}) ProjectInfo {
  640. p1 := ProjectInfo{
  641. Id: id,
  642. Ids: []string{thisinfo.Id},
  643. ProjectName: thisinfo.ProjectName,
  644. ProjectCode: thisinfo.ProjectCode,
  645. ContractCode: thisinfo.ContractCode,
  646. Buyer: thisinfo.Buyer,
  647. Buyerclass: thisinfo.Buyerclass,
  648. Buyerperson: thisinfo.Buyerperson,
  649. Buyertel: thisinfo.Buyertel,
  650. Topscopeclass: thisinfo.Topscopeclass,
  651. Subscopeclass: thisinfo.Subscopeclass,
  652. Agency: thisinfo.Agency,
  653. Area: thisinfo.Area,
  654. City: thisinfo.City,
  655. District: thisinfo.District,
  656. MPN: []string{},
  657. MPC: []string{},
  658. FirstTime: thisinfo.Publishtime,
  659. LastTime: thisinfo.Publishtime,
  660. Budget: thisinfo.Budget,
  661. Package: pkg,
  662. Bidamount: thisinfo.Bidamount,
  663. Bidstatus: bidstatus,
  664. Bidtype: bidtype,
  665. Winners: thisinfo.Winners,
  666. EntIdList: thisinfo.EntIdList,
  667. }
  668. if thisinfo.LenPTC > 5 {
  669. p1.MPC = append(p1.MPC, thisinfo.PTC)
  670. }
  671. return p1
  672. }
  673. //更新项目 全量合并
  674. func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info, pInfo *ProjectInfo, weight int, comStr string, ex int) {
  675. if p.currentType != "updateInfo" {
  676. if BinarySearch(pInfo.Ids, thisinfo.Id) > -1 {
  677. log.Println("repeat", thisinfo.Id, ",pid", pInfo.Id)
  678. return
  679. }
  680. }
  681. set := map[string]interface{}{}
  682. pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
  683. if len(pInfo.Ids) > 30 {
  684. //异常标记
  685. set["listtag"] = 1
  686. }
  687. //zbtime、lasttime、jgtime
  688. pInfo.LastTime = thisinfo.Publishtime
  689. set["lasttime"] = thisinfo.Publishtime
  690. if thisinfo.TopType == "招标" {
  691. if pInfo.Zbtime <= 0 {
  692. set["zbtime"] = tmp["publishtime"]
  693. }
  694. if pInfo.Jgtime > 0 {
  695. pInfo.Jgtime = int64(0)
  696. set["jgtime"] = int64(0)
  697. }
  698. } else if thisinfo.TopType == "结果" {
  699. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  700. if pInfo.Jgtime > 0 {
  701. //jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
  702. //公告状态和项目状态同样都是中标或者成交,
  703. if thisinfo.SubType == "成交" && pInfo.Bidstatus == "中标" {
  704. if p.jgTime < thisinfo.Publishtime {
  705. set["jgtime"] = tmp["publishtime"]
  706. pInfo.Jgtime = thisinfo.Publishtime
  707. }
  708. //公告状态和项目状态同样是流标或者废标
  709. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (pInfo.Bidstatus == "流标" || pInfo.Bidstatus == "废标") {
  710. if p.jgTime < thisinfo.Publishtime {
  711. set["jgtime"] = tmp["publishtime"]
  712. pInfo.Jgtime = thisinfo.Publishtime
  713. }
  714. }
  715. } else {
  716. set["jgtime"] = tmp["publishtime"]
  717. pInfo.Jgtime = thisinfo.Publishtime
  718. }
  719. }
  720. } else if thisinfo.SubType == "合同" {
  721. if pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交" || pInfo.Bidstatus == "" {
  722. //中标、成交不更新jgtime
  723. } else {
  724. set["jgtime"] = tmp["publishtime"]
  725. pInfo.Jgtime = thisinfo.Publishtime
  726. }
  727. }
  728. if thisinfo.Bidopentime > pInfo.Bidopentime {
  729. pInfo.Bidopentime = thisinfo.Bidopentime
  730. set["bidopentime"] = pInfo.Bidopentime
  731. }
  732. bt := qu.ObjToString(tmp["toptype"])
  733. bs := qu.ObjToString(tmp["subtype"])
  734. p.mapBidLock.Lock()
  735. if bt == "招标" {
  736. //招标状态,更新projectscope
  737. if tmp["projectscope"] != nil {
  738. set["projectscope"] = qu.ObjToString(tmp["projectscope"])
  739. }
  740. set["bidstatus"] = bt
  741. pInfo.Bidstatus = bt
  742. if bidtype[bs] != "" {
  743. set["bidtype"] = bidtype[bs]
  744. pInfo.Bidtype = bidtype[bs]
  745. } else {
  746. set["bidtype"] = "招标"
  747. pInfo.Bidtype = "招标"
  748. }
  749. } else {
  750. if bidstatus[bs] != "" {
  751. set["bidstatus"] = thisinfo.SubType
  752. pInfo.Bidstatus = thisinfo.SubType
  753. } else if thisinfo.Infoformat == 2 {
  754. set["bidstatus"] = "拟建"
  755. pInfo.Bidstatus = "拟建"
  756. } else if bs == "" && bt == "结果" {
  757. if pInfo.Bidstatus == "招标" {
  758. set["bidstatus"] = ""
  759. pInfo.Bidstatus = ""
  760. }
  761. } else {
  762. set["bidstatus"] = "其它"
  763. pInfo.Bidstatus = "其它"
  764. }
  765. }
  766. p.mapBidLock.Unlock()
  767. //异常标记
  768. if ex > 0 {
  769. set["exception"] = ex
  770. }
  771. //3\4\5--省、市、县
  772. //if thisinfo.Area != "全国" {
  773. // if pInfo.Area == "全国" {
  774. // pInfo.Area = thisinfo.Area
  775. // set["area"] = thisinfo.Area
  776. // } else if pInfo.Area != thisinfo.Area {
  777. // //xt = false
  778. // }
  779. // if pInfo.City == "" && thisinfo.City != "" {
  780. // pInfo.City = thisinfo.City
  781. // set["city"] = thisinfo.City
  782. // } else if pInfo.City != thisinfo.City {
  783. // //xt = false
  784. // }
  785. // if thisinfo.District != "" && pInfo.District == "" {
  786. // pInfo.District = thisinfo.District
  787. // set["district"] = thisinfo.District
  788. // }
  789. //}
  790. //相同城市的公告才会合并到一起(全国列外)
  791. if thisinfo.Area != "全国" {
  792. pInfo.Area = thisinfo.Area
  793. set["area"] = thisinfo.Area
  794. pInfo.City = thisinfo.City
  795. set["city"] = thisinfo.City
  796. if thisinfo.District != "" {
  797. pInfo.District = thisinfo.District
  798. set["district"] = thisinfo.District
  799. }
  800. }
  801. //6--项目名称
  802. if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  803. pInfo.ProjectName = thisinfo.ProjectName
  804. set["projectname"] = thisinfo.ProjectName
  805. }
  806. //7--项目编号
  807. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  808. pInfo.ProjectCode = thisinfo.ProjectCode
  809. set["projectcode"] = thisinfo.ProjectCode
  810. }
  811. //7--采购单位
  812. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  813. pInfo.Buyer = thisinfo.Buyer
  814. set["buyer"] = thisinfo.Buyer
  815. pInfo.Buyerclass = thisinfo.Buyerclass
  816. set["buyerclass"] = thisinfo.Buyerclass
  817. }
  818. if pInfo.Buyer == "" {
  819. set["buyerclass"] = ""
  820. }
  821. //采购单位联系人
  822. if thisinfo.Buyerperson != "" {
  823. pInfo.Buyerperson = thisinfo.Buyerperson
  824. set["buyerperson"] = pInfo.Buyerperson
  825. } else {
  826. pInfo.Buyerperson = ""
  827. set["buyerperson"] = ""
  828. }
  829. //采购单位電話
  830. if thisinfo.Buyertel != "" {
  831. pInfo.Buyertel = thisinfo.Buyertel
  832. set["buyertel"] = pInfo.Buyertel
  833. } else {
  834. pInfo.Buyertel = ""
  835. set["buyertel"] = ""
  836. }
  837. if thisinfo.ContractCode != "" {
  838. if pInfo.ContractCode == "" {
  839. set["contractcode"] = thisinfo.ContractCode
  840. } else {
  841. list := strings.Split(pInfo.ContractCode, ",")
  842. if BinarySearch(list, thisinfo.ContractCode) == -1 {
  843. list = append(list, thisinfo.ContractCode)
  844. sort.Strings(list)
  845. }
  846. set["contractcode"] = strings.Join(list, ",")
  847. }
  848. }
  849. //8--代理机构
  850. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  851. pInfo.Agency = thisinfo.Agency
  852. set["agency"] = thisinfo.Agency
  853. }
  854. if len(thisinfo.Topscopeclass) > 0 {
  855. sort.Strings(pInfo.Topscopeclass)
  856. for _, k := range thisinfo.Topscopeclass {
  857. if BinarySearch(pInfo.Topscopeclass, k) == -1 {
  858. pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
  859. sort.Strings(pInfo.Topscopeclass)
  860. }
  861. }
  862. set["topscopeclass"] = pInfo.Topscopeclass
  863. }
  864. //项目评审专家
  865. if len(thisinfo.ReviewExperts) > 0 {
  866. set["review_experts"] = thisinfo.ReviewExperts
  867. pInfo.ReviewExperts = thisinfo.ReviewExperts
  868. }
  869. if thisinfo.Purchasing != "" {
  870. if pInfo.Purchasing == "" {
  871. list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
  872. p := strings.Join(qu.ObjArrToStringArr(list), ",")
  873. pInfo.Purchasing = p
  874. set["purchasing"] = p
  875. } else {
  876. list := strings.Split(pInfo.Purchasing, ",")
  877. list = qu.ObjArrToStringArr(Duplicate(list))
  878. for _, k := range list {
  879. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  880. list = append(list, k)
  881. sort.Strings(list)
  882. }
  883. }
  884. set["purchasing"] = strings.Join(list, ",")
  885. }
  886. }
  887. //中标候选人
  888. if len(thisinfo.WinnerOrder) > 0 {
  889. var list = []string{}
  890. for _, v := range thisinfo.WinnerOrder {
  891. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  892. list = append(list, qu.ObjToString(v["entname"]))
  893. }
  894. }
  895. set["winnerorder"] = list
  896. pInfo.Winnerorder = list
  897. }
  898. if len(thisinfo.Subscopeclass) > 0 {
  899. sort.Strings(pInfo.Subscopeclass)
  900. for _, k := range thisinfo.Subscopeclass {
  901. if BinarySearch(pInfo.Subscopeclass, k) == -1 {
  902. pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
  903. sort.Strings(pInfo.Subscopeclass)
  904. }
  905. }
  906. set["subscopeclass"] = pInfo.Subscopeclass
  907. set["s_subscopeclass"] = strings.Join(pInfo.Subscopeclass, ",")
  908. }
  909. if len(thisinfo.Winners) > 0 {
  910. if len(pInfo.Winners) <= 0 {
  911. set["winner"] = qu.ObjToString(tmp["winner"])
  912. }
  913. sort.Strings(pInfo.Winners)
  914. for _, k := range thisinfo.Winners {
  915. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  916. if BinarySearch(pInfo.Winners, k) != -1 {
  917. deleteSlice(pInfo.Winners, k, "")
  918. sort.Strings(pInfo.Winners)
  919. }
  920. } else {
  921. if BinarySearch(pInfo.Winners, k) == -1 {
  922. pInfo.Winners = append(pInfo.Winners, k)
  923. sort.Strings(pInfo.Winners)
  924. }
  925. }
  926. }
  927. set["s_winner"] = strings.Join(pInfo.Winners, ",")
  928. }
  929. if len(thisinfo.EntIdList) > 0 {
  930. for _, v := range thisinfo.EntIdList {
  931. if BinarySearch(pInfo.EntIdList, v) == -1 {
  932. pInfo.EntIdList = append(pInfo.EntIdList, v)
  933. }
  934. }
  935. set["entidlist"] = pInfo.EntIdList
  936. }
  937. //项目规模
  938. if len(thisinfo.ProjectScale) > 0 {
  939. pInfo.ProjectScale = thisinfo.ProjectScale
  940. set["project_scale"] = thisinfo.ProjectScale
  941. }
  942. //工期时长
  943. if thisinfo.ProjectDuration > 0 {
  944. pInfo.ProjectDuration = thisinfo.ProjectDuration
  945. set["project_duration"] = thisinfo.ProjectDuration
  946. }
  947. // 工期单位
  948. if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
  949. pInfo.ProjectTimeunit = thisinfo.ProjectTimeUnit
  950. set["project_timeunit"] = thisinfo.ProjectTimeUnit
  951. }
  952. //开工日期
  953. if thisinfo.ProjectStartDate > 0 {
  954. if pInfo.ProjectStartDate > 0 {
  955. if pInfo.ProjectStartDate < thisinfo.ProjectStartDate {
  956. pInfo.ProjectStartDate = thisinfo.ProjectStartDate
  957. set["project_startdate"] = thisinfo.ProjectStartDate
  958. }
  959. } else {
  960. pInfo.ProjectStartDate = thisinfo.ProjectStartDate
  961. set["project_startdate"] = thisinfo.ProjectStartDate
  962. }
  963. }
  964. //竣工日期
  965. if thisinfo.ProjectCompleteDate > 0 {
  966. if pInfo.ProjctCompleteDate > 0 {
  967. if pInfo.ProjctCompleteDate < thisinfo.ProjectCompleteDate {
  968. pInfo.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  969. set["project_completedate"] = thisinfo.ProjectCompleteDate
  970. }
  971. } else {
  972. pInfo.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  973. set["project_completedate"] = thisinfo.ProjectCompleteDate
  974. }
  975. }
  976. // 付款方式
  977. if len(thisinfo.Payway) > 0 {
  978. pInfo.Payway = thisinfo.Payway
  979. set["payway"] = thisinfo.Payway
  980. }
  981. // 履约保证金
  982. if tmp["contract_guarantee"] != nil {
  983. pInfo.ContractGuarantee = thisinfo.ContractGuarantee
  984. set["contract_guarantee"] = thisinfo.ContractGuarantee
  985. }
  986. // 投标保证金
  987. if tmp["bid_guarantee"] != nil {
  988. pInfo.BidGuarantee = thisinfo.BidGuarantee
  989. set["bid_guarantee"] = thisinfo.BidGuarantee
  990. }
  991. // 资质条件
  992. if len(thisinfo.Qualifies) > 0 {
  993. var str []string
  994. if len(pInfo.Qualifies) > 0 {
  995. str = append(str, strings.Split(pInfo.Qualifies, ",")...)
  996. }
  997. for _, v := range thisinfo.Qualifies {
  998. if len(qu.ObjToString(v["key"])) > 0 {
  999. if BinarySearch(str, qu.ObjToString(v["key"])) == -1 {
  1000. str = append(str, qu.ObjToString(v["key"]))
  1001. }
  1002. }
  1003. }
  1004. if len(str) > 0 {
  1005. pInfo.Qualifies = strings.Join(str, ",")
  1006. set["qualifies"] = strings.Join(str, ",")
  1007. }
  1008. }
  1009. if thisinfo.HasPackage { //多包处理
  1010. set["multipackage"] = 1
  1011. pkg := PackageFormat(thisinfo, pInfo)
  1012. pInfo.Package = pkg
  1013. set["package"] = pInfo.Package
  1014. }
  1015. //处理多包后,计算预算金额、中标金额
  1016. CountAmount(pInfo, thisinfo, tmp)
  1017. if pInfo.Budget >= 0 && pInfo.Budgettag != 1 {
  1018. set["budget"] = pInfo.Budget
  1019. set["budgettag"] = 0
  1020. }
  1021. if pInfo.Bidamount >= 0 && pInfo.Bidamounttag != 1 {
  1022. set["bidamount"] = pInfo.Bidamount
  1023. set["bidamounttag"] = 0
  1024. }
  1025. if pInfo.Bidamount >= pInfo.Budget {
  1026. set["sortprice"] = pInfo.Bidamount
  1027. } else if pInfo.Budget >= pInfo.Bidamount {
  1028. set["sortprice"] = pInfo.Budget
  1029. }
  1030. infofield := InfoField{
  1031. Budget: thisinfo.Budget,
  1032. Bidamount: thisinfo.Bidamount,
  1033. ContractCode: thisinfo.ContractCode,
  1034. ProjectName: thisinfo.ProjectName,
  1035. ProjectCode: thisinfo.ProjectCode,
  1036. Bidstatus: bs,
  1037. }
  1038. copyMap := Copy(pInfo.InfoFiled).(map[string]InfoField)
  1039. copyMap[thisinfo.Id] = infofield
  1040. tmpMap := make(map[string]interface{})
  1041. for k, v := range copyMap {
  1042. tmpMap[k] = StructToMap(v)
  1043. }
  1044. tmpMap[thisinfo.Id] = StructToMap(infofield)
  1045. pInfo.InfoFiled = copyMap
  1046. set["infofield"] = tmpMap
  1047. set["mpn"] = pInfo.MPN
  1048. set["mpc"] = pInfo.MPC
  1049. if p.currentType == "project" {
  1050. set["pici"] = p.pici
  1051. } else {
  1052. set["pici"] = tmp["comeintime"]
  1053. }
  1054. update := map[string]interface{}{}
  1055. if len(set) > 0 {
  1056. update["$set"] = set
  1057. }
  1058. push := p.PushListInfo(tmp, thisinfo.Id)
  1059. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  1060. push["compareStr"] = comStr
  1061. push["resVal"] = pInfo.resVal
  1062. push["pjVal"] = pInfo.pjVal
  1063. update["$push"] = map[string]interface{}{
  1064. "list": push,
  1065. "ids": thisinfo.Id,
  1066. }
  1067. //clearMap := map[string]interface{}{}
  1068. //ClearData(clearMap, set)
  1069. //if len(clearMap) > 0 {
  1070. // update["$unset"] = clearMap
  1071. //}
  1072. if len(update) > 0 {
  1073. updateInfo := []map[string]interface{}{
  1074. {
  1075. "_id": pInfo.Id,
  1076. },
  1077. update,
  1078. }
  1079. p.updatePool <- updateInfo
  1080. }
  1081. }
  1082. /**
  1083. * 更新项目时,项目状态的处理
  1084. * 返回是否新增项目,异常标记
  1085. * 1、新增项目时,招标信息的状态(toptype)不是招标、拟建、预告 异常:1
  1086. * 异常1是在项目新建的时候才会产生
  1087. * 3、项目合并时,项目状态是”流标“/”废标“,招标信息状态不是”招标“ 异常:2
  1088. * 4、项目合并时,项目状态是”合同“/”其它“,招标信息类型是”结果“ 异常:3
  1089. */
  1090. func (p *ProjectTask) CompareStatus(project *ProjectInfo, info *Info) (bool, int) {
  1091. if info.TopType == "拟建" || info.TopType == "预告" || info.TopType == "招标" {
  1092. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  1093. return false, 0
  1094. } else if project.Bidstatus == "废标" || project.Bidstatus == "流标" {
  1095. return false, 0
  1096. } else {
  1097. return true, 0
  1098. }
  1099. } else if info.TopType == "结果" {
  1100. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  1101. return false, 0
  1102. } else if project.Bidstatus == info.SubType {
  1103. //状态一样,根据发布时间判断是否合并
  1104. if (info.Publishtime - project.LastTime) > p.statusTime {
  1105. return true, 0
  1106. } else {
  1107. return false, 0
  1108. }
  1109. } else if project.Bidstatus == "成交" && info.SubType == "中标" {
  1110. return true, 0
  1111. } else if project.Bidstatus == "流标" || project.Bidstatus == "废标" {
  1112. return false, 2
  1113. } else if project.Bidstatus == "合同" || project.Bidstatus == "其它" {
  1114. return false, 3
  1115. } else {
  1116. return false, 0
  1117. }
  1118. } else {
  1119. return false, 0
  1120. }
  1121. }
  1122. /*
  1123. * 对比地区(省、市),存在且不同,不能合并
  1124. * 返回是否新建项目
  1125. */
  1126. func ComparePlace(project *ProjectInfo, info *Info) bool {
  1127. if info.Area == "全国" || info.Area == "" {
  1128. return false
  1129. }
  1130. if project.Area == "全国" || project.Area == "" {
  1131. return false
  1132. }
  1133. if info.Area == project.Area {
  1134. if info.City == "" || project.City == "" {
  1135. return false
  1136. } else if info.City == project.City {
  1137. return false
  1138. }
  1139. } else {
  1140. return true
  1141. }
  1142. return true
  1143. }
  1144. func packageEle(map1 map[string]interface{}, id string) map[string]interface{} {
  1145. p2 := map[string]interface{}{}
  1146. for _, k := range PackageEle {
  1147. if map1[k] != nil {
  1148. p2[k] = map1[k]
  1149. }
  1150. infoid := p2["infoid"]
  1151. if infoid == nil {
  1152. p2["infoid"] = id
  1153. }
  1154. }
  1155. return p2
  1156. }
  1157. func PackageFormat(info *Info, project *ProjectInfo) map[string]interface{} {
  1158. p1 := map[string]interface{}{}
  1159. if project != nil && project.Package != nil && len(project.Package) > 0 {
  1160. packageCopy := Copy(project.Package).(map[string]interface{})
  1161. p1 = packageCopy
  1162. for k, v := range info.Package {
  1163. if v1, ok := v.(map[string]interface{}); ok {
  1164. v2 := map[string]interface{}{}
  1165. v2 = packageEle(v1, info.Id)
  1166. if v2["bidstatus"] == nil {
  1167. v2["bidstatus"] = info.SubType
  1168. }
  1169. addFlag := false
  1170. for k1, v3 := range p1 {
  1171. if v4, ok := v3.([]map[string]interface{}); ok {
  1172. //if qu.ObjToString(v4[0]["origin"]) == qu.ObjToString(v2["origin"]) && qu.ObjToString(v4[0]["name"]) == qu.ObjToString(v2["name"]) {
  1173. if k1 == k {
  1174. v4 = append(v4, v2)
  1175. p1[k1] = v4
  1176. addFlag = true
  1177. break
  1178. }
  1179. }
  1180. }
  1181. if !addFlag {
  1182. p1[k] = []map[string]interface{}{v2}
  1183. }
  1184. }
  1185. }
  1186. } else {
  1187. for k, v := range info.Package {
  1188. v1, _ := v.(map[string]interface{})
  1189. p2 := map[string]interface{}{}
  1190. p2 = packageEle(v1, info.Id)
  1191. if p2["bidstatus"] == nil {
  1192. p2["bidstatus"] = info.SubType
  1193. }
  1194. p1[k] = []map[string]interface{}{p2}
  1195. }
  1196. }
  1197. return p1
  1198. }
  1199. // 计算预算(budget)、中标金额(bidamount)
  1200. func CountAmount(project *ProjectInfo, info *Info, tmp map[string]interface{}) {
  1201. if info.HasPackage {
  1202. budget := 0.0
  1203. for _, v := range project.Package {
  1204. v1, _ := v.([]map[string]interface{})
  1205. for _, v2 := range v1 {
  1206. if v2["budget"] != nil {
  1207. b1 := qu.Float64All(v2["budget"])
  1208. if b1 > 0 {
  1209. budget = budget + b1
  1210. break
  1211. }
  1212. } else {
  1213. project.Budgettag = 1
  1214. }
  1215. }
  1216. }
  1217. if budget > 0 {
  1218. project.Budget = budget
  1219. project.Budgettag = 0
  1220. } else if budget == 0 && info.Budget > 0 {
  1221. project.Budget = info.Budget
  1222. project.Budgettag = 0
  1223. }
  1224. } else {
  1225. //招标没有多包
  1226. k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1227. if len(k) > 0 {
  1228. //招标是单包
  1229. if len(project.Package) > 0 {
  1230. //项目有多包
  1231. flag := false
  1232. for _, v := range project.Package {
  1233. v1, _ := v.([]map[string]interface{})
  1234. if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1235. flag = true
  1236. }
  1237. }
  1238. if !flag {
  1239. project.Budget = project.Budget + info.Budget
  1240. project.Budgettag = 0
  1241. }
  1242. } else {
  1243. //项目没有多包
  1244. if info.Budget > 0 {
  1245. project.Budget = project.Budget + info.Budget
  1246. project.Budgettag = 0
  1247. } else if info.Budget == 0 && tmp["budget"] != nil {
  1248. project.Budgettag = 0
  1249. }
  1250. }
  1251. } else {
  1252. if info.Budget > 0 && project.Budget < info.Budget {
  1253. project.Budget = info.Budget
  1254. project.Budgettag = 0
  1255. }
  1256. }
  1257. }
  1258. if info.SubType == "中标" || info.SubType == "成交" || info.SubType == "合同" {
  1259. if info.HasPackage {
  1260. bidamount := 0.0
  1261. for _, v := range project.Package {
  1262. v1, _ := v.([]map[string]interface{})
  1263. for _, v2 := range v1 {
  1264. b1 := qu.Float64All(v2["bidamount"])
  1265. if b1 > 0 {
  1266. bidamount = bidamount + b1
  1267. break
  1268. }
  1269. }
  1270. }
  1271. if bidamount > 0 {
  1272. project.Bidamount = bidamount
  1273. project.Bidamounttag = 0
  1274. } else if bidamount == 0 && info.Bidamount > 0 {
  1275. project.Bidamount = info.Bidamount
  1276. project.Bidamounttag = 0
  1277. }
  1278. } else {
  1279. //招标没有多包
  1280. k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1281. if len(k) > 0 {
  1282. //招标是单包
  1283. if len(project.Package) > 0 {
  1284. //项目有多包
  1285. flag := false
  1286. for _, v := range project.Package {
  1287. v1, _ := v.([]map[string]interface{})
  1288. if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1289. flag = true
  1290. }
  1291. }
  1292. if !flag {
  1293. project.Bidamount = project.Bidamount + info.Bidamount
  1294. project.Bidamounttag = 0
  1295. }
  1296. } else {
  1297. //项目没有多包
  1298. if info.Bidamount > 0 {
  1299. project.Bidamount = project.Bidamount + info.Bidamount
  1300. project.Bidamounttag = 0
  1301. } else if info.Bidamount == 0 && tmp["bidamount"] != nil {
  1302. project.Bidamounttag = 0
  1303. } else {
  1304. project.Bidamounttag = 1
  1305. }
  1306. }
  1307. } else {
  1308. if info.SubType == "中标" || info.SubType == "成交" {
  1309. if info.Bidamount > 0 {
  1310. project.Bidamount = info.Bidamount
  1311. project.Bidamounttag = 0
  1312. } else {
  1313. flag := false
  1314. if project.InfoFiled != nil && len(project.InfoFiled) > 0 {
  1315. for _, res := range project.InfoFiled {
  1316. if res.ContractCode != "" && res.ContractCode == info.ContractCode {
  1317. flag = true
  1318. break
  1319. }
  1320. if res.Bidamount == project.Bidamount {
  1321. flag = true
  1322. break
  1323. }
  1324. }
  1325. if !flag {
  1326. project.Bidamount = project.Bidamount + info.Bidamount
  1327. project.Bidamounttag = 0
  1328. } else {
  1329. if info.Budget > 0 && project.Bidamount > info.Bidamount {
  1330. project.Bidamount = info.Bidamount
  1331. project.Bidamounttag = 0
  1332. }
  1333. }
  1334. }
  1335. }
  1336. }
  1337. }
  1338. }
  1339. } else {
  1340. project.Bidamounttag = 1
  1341. }
  1342. }
  1343. //结构体转map
  1344. func StructToMap(filed InfoField) map[string]interface{} {
  1345. //先转json
  1346. result, err := json.Marshal(filed)
  1347. if err != nil {
  1348. return nil
  1349. }
  1350. //json转map
  1351. res := make(map[string]interface{})
  1352. err = json.Unmarshal(result, &res)
  1353. return res
  1354. }
  1355. func ClearData(clearMap, tmp map[string]interface{}) {
  1356. for k, v := range tmp {
  1357. if v == "" {
  1358. clearMap[k] = ""
  1359. }
  1360. }
  1361. }
  1362. func IsCreatePro(info *Info) (bol bool) {
  1363. bol = true
  1364. if info.SubType == "" || info.SubType == "变更" || info.SubType == "验收" || info.SubType == "违规" ||
  1365. info.SubType == "结果变更" || info.SubType == "其它" {
  1366. if info.ProjectName == "" && info.ProjectCode == "" {
  1367. bol = false
  1368. } else if info.ProjectName == "" && info.Buyer == "" {
  1369. bol = false
  1370. } else if info.ProjectCode == "" && info.Buyer == "" {
  1371. bol = false
  1372. }
  1373. }
  1374. return bol
  1375. }
  1376. func (p *ProjectTask) GetBidTypeAndBidStatus(info *Info) (string, string) {
  1377. p.mapBidLock.Lock()
  1378. defer p.mapBidLock.Unlock()
  1379. typeStr := bidtype[info.TopType]
  1380. statusStr := bidstatus[info.SubType]
  1381. if info.Infoformat == 2 || info.SubType == "拟建" {
  1382. statusStr = "拟建"
  1383. typeStr = ""
  1384. } else {
  1385. if bidtype[typeStr] == "" {
  1386. typeStr = "招标"
  1387. }
  1388. if typeStr == "招标" {
  1389. statusStr = typeStr
  1390. } else {
  1391. if statusStr == "" {
  1392. statusStr = "其它"
  1393. }
  1394. }
  1395. }
  1396. return typeStr, statusStr
  1397. }