project.go 41 KB

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