project.go 41 KB

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