project.go 41 KB

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