project.go 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533
  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. //公告状态和项目状态同样都是中标或者成交,
  758. if (thisinfo.SubType == "中标" || thisinfo.SubType == "成交") && (pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交") {
  759. if jg1 > p.jgTime {
  760. set["jgtime"] = tmp["publishtime"]
  761. pInfo.Jgtime = thisinfo.Publishtime
  762. }
  763. //公告状态和项目状态同样是流标或者废标
  764. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (pInfo.Bidstatus == "流标" || pInfo.Bidstatus == "废标") {
  765. if jg1 > p.jgTime {
  766. set["jgtime"] = tmp["publishtime"]
  767. pInfo.Jgtime = thisinfo.Publishtime
  768. }
  769. }
  770. } else {
  771. set["jgtime"] = tmp["publishtime"]
  772. pInfo.Jgtime = thisinfo.Publishtime
  773. }
  774. }
  775. } else if thisinfo.SubType == "合同" {
  776. if pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交" || pInfo.Bidstatus == "" {
  777. //中标、成交不更新jgtime
  778. } else {
  779. set["jgtime"] = tmp["publishtime"]
  780. pInfo.Jgtime = thisinfo.Publishtime
  781. }
  782. }
  783. if thisinfo.Bidopentime > pInfo.Bidopentime {
  784. pInfo.Bidopentime = thisinfo.Bidopentime
  785. set["bidopentime"] = pInfo.Bidopentime
  786. }
  787. bt := qu.ObjToString(tmp["toptype"])
  788. bs := qu.ObjToString(tmp["subtype"])
  789. p.mapBidLock.Lock()
  790. if bt == "招标" {
  791. //招标状态,更新projectscope
  792. if tmp["projectscope"] != nil {
  793. set["projectscope"] = qu.ObjToString(tmp["projectscope"])
  794. }
  795. set["bidstatus"] = bt
  796. pInfo.Bidstatus = bt
  797. if bidtype[bs] != "" {
  798. set["bidtype"] = bidtype[bs]
  799. pInfo.Bidtype = bidtype[bs]
  800. } else {
  801. set["bidtype"] = "招标"
  802. pInfo.Bidtype = "招标"
  803. }
  804. } else {
  805. if bidstatus[bs] != "" {
  806. set["bidstatus"] = thisinfo.SubType
  807. pInfo.Bidstatus = thisinfo.SubType
  808. } else if thisinfo.Infoformat == 2 {
  809. set["bidstatus"] = "拟建"
  810. pInfo.Bidstatus = "拟建"
  811. } else if bs == "" && bt == "结果" {
  812. if pInfo.Bidstatus == "招标" {
  813. set["bidstatus"] = ""
  814. pInfo.Bidstatus = ""
  815. }
  816. } else {
  817. set["bidstatus"] = "其它"
  818. pInfo.Bidstatus = "其它"
  819. }
  820. }
  821. p.mapBidLock.Unlock()
  822. //异常标记
  823. if ex > 0 {
  824. set["exception"] = ex
  825. }
  826. //3\4\5--省、市、县
  827. //if thisinfo.Area != "全国" {
  828. // if pInfo.Area == "全国" {
  829. // pInfo.Area = thisinfo.Area
  830. // set["area"] = thisinfo.Area
  831. // } else if pInfo.Area != thisinfo.Area {
  832. // //xt = false
  833. // }
  834. // if pInfo.City == "" && thisinfo.City != "" {
  835. // pInfo.City = thisinfo.City
  836. // set["city"] = thisinfo.City
  837. // } else if pInfo.City != thisinfo.City {
  838. // //xt = false
  839. // }
  840. // if thisinfo.District != "" && pInfo.District == "" {
  841. // pInfo.District = thisinfo.District
  842. // set["district"] = thisinfo.District
  843. // }
  844. //}
  845. //相同城市的公告才会合并到一起(全国列外)
  846. if thisinfo.Area != "全国" {
  847. pInfo.Area = thisinfo.Area
  848. set["area"] = thisinfo.Area
  849. pInfo.City = thisinfo.City
  850. set["city"] = thisinfo.City
  851. if thisinfo.District != "" {
  852. pInfo.District = thisinfo.District
  853. set["district"] = thisinfo.District
  854. }
  855. }
  856. //6--项目名称
  857. if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  858. pInfo.ProjectName = thisinfo.ProjectName
  859. set["projectname"] = thisinfo.ProjectName
  860. }
  861. //7--项目编号
  862. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  863. pInfo.ProjectCode = thisinfo.ProjectCode
  864. set["projectcode"] = thisinfo.ProjectCode
  865. }
  866. //7--采购单位
  867. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  868. pInfo.Buyer = thisinfo.Buyer
  869. set["buyer"] = thisinfo.Buyer
  870. pInfo.Buyerclass = thisinfo.Buyerclass
  871. set["buyerclass"] = thisinfo.Buyerclass
  872. }
  873. if pInfo.Buyer == "" {
  874. set["buyerclass"] = ""
  875. }
  876. //采购单位联系人
  877. if thisinfo.Buyerperson != "" {
  878. pInfo.Buyerperson = thisinfo.Buyerperson
  879. set["buyerperson"] = pInfo.Buyerperson
  880. } else {
  881. pInfo.Buyerperson = ""
  882. set["buyerperson"] = ""
  883. }
  884. //采购单位電話
  885. if thisinfo.Buyertel != "" {
  886. pInfo.Buyertel = thisinfo.Buyertel
  887. set["buyertel"] = pInfo.Buyertel
  888. } else {
  889. pInfo.Buyertel = ""
  890. set["buyertel"] = ""
  891. }
  892. if thisinfo.ContractCode != "" {
  893. set["contractcode"] = pInfo.ContractCode + "," + thisinfo.ContractCode
  894. }
  895. //8--代理机构
  896. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  897. pInfo.Agency = thisinfo.Agency
  898. set["agency"] = thisinfo.Agency
  899. }
  900. if len(thisinfo.Topscopeclass) > 0 {
  901. sort.Strings(pInfo.Topscopeclass)
  902. for _, k := range thisinfo.Topscopeclass {
  903. if BinarySearch(pInfo.Topscopeclass, k) == -1 {
  904. pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
  905. sort.Strings(pInfo.Topscopeclass)
  906. }
  907. }
  908. set["topscopeclass"] = pInfo.Topscopeclass
  909. }
  910. //项目评审专家
  911. if len(thisinfo.ReviewExperts) > 0 {
  912. set["review_experts"] = thisinfo.ReviewExperts
  913. pInfo.ReviewExperts = thisinfo.ReviewExperts
  914. }
  915. if thisinfo.Purchasing != "" {
  916. if pInfo.Purchasing == "" {
  917. list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
  918. p := strings.Join(qu.ObjArrToStringArr(list), ",")
  919. pInfo.Purchasing = p
  920. set["purchasing"] = p
  921. } else {
  922. list := strings.Split(pInfo.Purchasing, ",")
  923. list = qu.ObjArrToStringArr(Duplicate(list))
  924. for _, k := range list {
  925. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  926. list = append(list, k)
  927. sort.Strings(list)
  928. }
  929. }
  930. set["purchasing"] = strings.Join(list, ",")
  931. }
  932. }
  933. //中标候选人
  934. if len(thisinfo.WinnerOrder) > 0 {
  935. var list = []string{}
  936. for _, v := range thisinfo.WinnerOrder {
  937. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  938. list = append(list, qu.ObjToString(v["entname"]))
  939. }
  940. }
  941. set["winnerorder"] = list
  942. pInfo.Winnerorder = list
  943. }
  944. if len(thisinfo.Subscopeclass) > 0 {
  945. sort.Strings(pInfo.Subscopeclass)
  946. for _, k := range thisinfo.Subscopeclass {
  947. if BinarySearch(pInfo.Subscopeclass, k) == -1 {
  948. pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
  949. sort.Strings(pInfo.Subscopeclass)
  950. }
  951. }
  952. set["subscopeclass"] = pInfo.Subscopeclass
  953. set["s_subscopeclass"] = strings.Join(pInfo.Subscopeclass, ",")
  954. }
  955. if len(thisinfo.Winners) > 0 {
  956. if len(pInfo.Winners) <= 0 {
  957. set["winner"] = qu.ObjToString(tmp["winner"])
  958. }
  959. sort.Strings(pInfo.Winners)
  960. for _, k := range thisinfo.Winners {
  961. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  962. if BinarySearch(pInfo.Winners, k) != -1 {
  963. deleteSlice(pInfo.Winners, k, "")
  964. sort.Strings(pInfo.Winners)
  965. }
  966. } else {
  967. if BinarySearch(pInfo.Winners, k) == -1 {
  968. pInfo.Winners = append(pInfo.Winners, k)
  969. sort.Strings(pInfo.Winners)
  970. }
  971. }
  972. }
  973. set["s_winner"] = strings.Join(pInfo.Winners, ",")
  974. }
  975. //项目规模
  976. if len(thisinfo.ProjectScale) > 0 {
  977. pInfo.ProjectScale = thisinfo.ProjectScale
  978. set["project_scale"] = thisinfo.ProjectScale
  979. }
  980. //工期时长
  981. if thisinfo.ProjectDuration > 0 {
  982. pInfo.ProjectDuration = thisinfo.ProjectDuration
  983. set["project_duration"] = thisinfo.ProjectDuration
  984. }
  985. // 工期单位
  986. if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
  987. pInfo.ProjectTimeunit = thisinfo.ProjectTimeUnit
  988. set["project_timeunit"] = thisinfo.ProjectTimeUnit
  989. }
  990. //开工日期
  991. if thisinfo.ProjectStartDate > 0 {
  992. if pInfo.ProjectStartDate > 0 {
  993. if pInfo.ProjectStartDate < thisinfo.ProjectStartDate {
  994. pInfo.ProjectStartDate = thisinfo.ProjectStartDate
  995. set["project_startdate"] = thisinfo.ProjectStartDate
  996. }
  997. }else {
  998. pInfo.ProjectStartDate = thisinfo.ProjectStartDate
  999. set["project_startdate"] = thisinfo.ProjectStartDate
  1000. }
  1001. }
  1002. //竣工日期
  1003. if thisinfo.ProjectCompleteDate > 0 {
  1004. if pInfo.ProjctCompleteDate > 0 {
  1005. if pInfo.ProjctCompleteDate < thisinfo.ProjectCompleteDate {
  1006. pInfo.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  1007. set["project_completedate"] = thisinfo.ProjectCompleteDate
  1008. }
  1009. }else {
  1010. pInfo.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  1011. set["project_completedate"] = thisinfo.ProjectCompleteDate
  1012. }
  1013. }
  1014. // 付款方式
  1015. if len(thisinfo.Payway) > 0 {
  1016. pInfo.Payway = thisinfo.Payway
  1017. set["payway"] = thisinfo.Payway
  1018. }
  1019. // 履约保证金
  1020. if tmp["contract_guarantee"] != nil {
  1021. pInfo.ContractGuarantee = thisinfo.ContractGuarantee
  1022. set["contract_guarantee"] = thisinfo.ContractGuarantee
  1023. }
  1024. // 投标保证金
  1025. if tmp["bid_guarantee"] != nil {
  1026. pInfo.BidGuarantee = thisinfo.BidGuarantee
  1027. set["bid_guarantee"] = thisinfo.BidGuarantee
  1028. }
  1029. // 资质条件
  1030. if len(thisinfo.Qualifies) > 0 {
  1031. var str []string
  1032. if len(pInfo.Qualifies) > 0 {
  1033. str = append(str, strings.Split(pInfo.Qualifies, ",")...)
  1034. }
  1035. for _, v := range thisinfo.Qualifies{
  1036. if len(qu.ObjToString(v["key"])) > 0 {
  1037. if BinarySearch(str, qu.ObjToString(v["key"])) == -1 {
  1038. str = append(str, qu.ObjToString(v["key"]))
  1039. }
  1040. }
  1041. }
  1042. if len(str) > 0 {
  1043. pInfo.Qualifies = strings.Join(str, ",")
  1044. set["qualifies"] = strings.Join(str, ",")
  1045. }
  1046. }
  1047. if len(thisinfo.EntIdList) > 0 {
  1048. for _, v := range thisinfo.EntIdList{
  1049. if BinarySearch(pInfo.EntIdList, v) == -1 {
  1050. pInfo.EntIdList = append(pInfo.EntIdList, v)
  1051. }
  1052. }
  1053. set["entidlist"] = pInfo.EntIdList
  1054. }
  1055. if thisinfo.HasPackage { //多包处理
  1056. set["multipackage"] = 1
  1057. pkg := PackageFormat(thisinfo, pInfo)
  1058. pInfo.Package = pkg
  1059. set["package"] = pInfo.Package
  1060. }
  1061. //处理多包后,计算预算金额、中标金额
  1062. CountAmount(pInfo, thisinfo, tmp)
  1063. if pInfo.Budget >= 0 && pInfo.Budgettag != 1 {
  1064. set["budget"] = pInfo.Budget
  1065. set["budgettag"] = 0
  1066. }
  1067. if pInfo.Bidamount >= 0 && pInfo.Bidamounttag != 1 {
  1068. set["bidamount"] = pInfo.Bidamount
  1069. set["bidamounttag"] = 0
  1070. }
  1071. if pInfo.Bidamount >= pInfo.Budget {
  1072. set["sortprice"] = pInfo.Bidamount
  1073. } else if pInfo.Budget >= pInfo.Bidamount {
  1074. set["sortprice"] = pInfo.Budget
  1075. }
  1076. infofield := InfoField{
  1077. Budget: thisinfo.Budget,
  1078. Bidamount: thisinfo.Bidamount,
  1079. ContractCode: thisinfo.ContractCode,
  1080. ProjectName: thisinfo.ProjectName,
  1081. ProjectCode: thisinfo.ProjectCode,
  1082. Bidstatus: bs,
  1083. }
  1084. copyMap := Copy(pInfo.InfoFiled).(map[string]InfoField)
  1085. copyMap[thisinfo.Id] = infofield
  1086. tmpMap := make(map[string]interface{})
  1087. for k, v := range copyMap {
  1088. tmpMap[k] = StructToMap(v)
  1089. }
  1090. tmpMap[thisinfo.Id] = StructToMap(infofield)
  1091. pInfo.InfoFiled = copyMap
  1092. set["infofield"] = tmpMap
  1093. set["mpn"] = pInfo.MPN
  1094. set["mpc"] = pInfo.MPC
  1095. if p.currentType == "project" {
  1096. set["pici"] = p.pici
  1097. } else {
  1098. set["pici"] = tmp["comeintime"]
  1099. }
  1100. update := map[string]interface{}{}
  1101. if len(set) > 0 {
  1102. update["$set"] = set
  1103. }
  1104. push := p.PushListInfo(tmp, thisinfo.Id)
  1105. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  1106. push["compareStr"] = comStr
  1107. push["resVal"] = pInfo.resVal
  1108. push["pjVal"] = pInfo.pjVal
  1109. update["$push"] = map[string]interface{}{
  1110. "list": push,
  1111. "ids": thisinfo.Id,
  1112. }
  1113. //clearMap := map[string]interface{}{}
  1114. //ClearData(clearMap, set)
  1115. //if len(clearMap) > 0 {
  1116. // update["$unset"] = clearMap
  1117. //}
  1118. if len(update) > 0 {
  1119. updateInfo := []map[string]interface{}{
  1120. {
  1121. "_id": pInfo.Id,
  1122. },
  1123. update,
  1124. }
  1125. p.updatePool <- updateInfo
  1126. }
  1127. }
  1128. /**
  1129. * 更新项目时,项目状态的处理
  1130. * 返回是否新增项目,异常标记
  1131. * 1、新增项目时,招标信息的状态(toptype)不是招标、拟建、预告 异常:1
  1132. * 异常1是在项目新建的时候才会产生
  1133. * 3、项目合并时,项目状态是”流标“/”废标“,招标信息状态不是”招标“ 异常:2
  1134. * 4、项目合并时,项目状态是”合同“/”其它“,招标信息类型是”结果“ 异常:3
  1135. */
  1136. func (p *ProjectTask) CompareStatus(project *ProjectInfo, info *Info) (bool, int) {
  1137. if info.TopType == "拟建" || info.TopType == "预告" || info.TopType == "招标" {
  1138. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  1139. return false, 0
  1140. } else if project.Bidstatus == "废标" || project.Bidstatus == "流标" {
  1141. return false, 0
  1142. } else {
  1143. return true, 0
  1144. }
  1145. } else if info.TopType == "结果" {
  1146. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  1147. return false, 0
  1148. } else if project.Bidstatus == info.SubType {
  1149. //状态一样,根据发布时间判断是否合并
  1150. if (info.Publishtime - project.LastTime) > p.statusTime {
  1151. return true, 0
  1152. } else {
  1153. return false, 0
  1154. }
  1155. } else if project.Bidstatus == "成交" && info.SubType == "中标" {
  1156. return true, 0
  1157. } else if project.Bidstatus == "流标" || project.Bidstatus == "废标" {
  1158. return false, 2
  1159. } else if project.Bidstatus == "合同" || project.Bidstatus == "其它" {
  1160. return false, 3
  1161. } else {
  1162. return false, 0
  1163. }
  1164. } else {
  1165. return false, 0
  1166. }
  1167. }
  1168. /*
  1169. * 对比地区(省、市),存在且不同,不能合并
  1170. * 返回是否新建项目
  1171. */
  1172. func ComparePlace(project *ProjectInfo, info *Info) bool {
  1173. if info.Area == "全国" || info.Area == "" {
  1174. return false
  1175. }
  1176. if project.Area == "全国" || project.Area == "" {
  1177. return false
  1178. }
  1179. if info.Area == project.Area {
  1180. if info.City == "" || project.City == "" {
  1181. return false
  1182. } else if info.City == project.City {
  1183. return false
  1184. }
  1185. } else {
  1186. return true
  1187. }
  1188. return true
  1189. }
  1190. var PackageEle = []string{
  1191. "origin",
  1192. "name",
  1193. //"text",
  1194. "budget",
  1195. "winner",
  1196. "bidamount",
  1197. "bidamounttype",
  1198. "currency",
  1199. "bidstatus",
  1200. }
  1201. func packageEle(map1 map[string]interface{}, id string) map[string]interface{} {
  1202. p2 := map[string]interface{}{}
  1203. for _, k := range PackageEle {
  1204. if map1[k] != nil {
  1205. p2[k] = map1[k]
  1206. }
  1207. infoid := p2["infoid"]
  1208. if infoid == nil {
  1209. p2["infoid"] = id
  1210. }
  1211. }
  1212. return p2
  1213. }
  1214. func PackageFormat(info *Info, project *ProjectInfo) map[string]interface{} {
  1215. p1 := map[string]interface{}{}
  1216. if project != nil && project.Package != nil && len(project.Package) > 0 {
  1217. packageCopy := Copy(project.Package).(map[string]interface{})
  1218. p1 = packageCopy
  1219. for k, v := range info.Package {
  1220. if v1, ok := v.(map[string]interface{}); ok {
  1221. v2 := map[string]interface{}{}
  1222. v2 = packageEle(v1, info.Id)
  1223. if v2["bidstatus"] == nil {
  1224. v2["bidstatus"] = info.SubType
  1225. }
  1226. addFlag := false
  1227. for k1, v3 := range p1 {
  1228. if v4, ok := v3.([]map[string]interface{}); ok {
  1229. //if qu.ObjToString(v4[0]["origin"]) == qu.ObjToString(v2["origin"]) && qu.ObjToString(v4[0]["name"]) == qu.ObjToString(v2["name"]) {
  1230. if k1 == k {
  1231. v4 = append(v4, v2)
  1232. p1[k1] = v4
  1233. addFlag = true
  1234. break
  1235. }
  1236. }
  1237. }
  1238. if !addFlag {
  1239. p1[k] = []map[string]interface{}{v2}
  1240. }
  1241. }
  1242. }
  1243. } else {
  1244. for k, v := range info.Package {
  1245. v1, _ := v.(map[string]interface{})
  1246. p2 := map[string]interface{}{}
  1247. p2 = packageEle(v1, info.Id)
  1248. if p2["bidstatus"] == nil {
  1249. p2["bidstatus"] = info.SubType
  1250. }
  1251. p1[k] = []map[string]interface{}{p2}
  1252. }
  1253. }
  1254. return p1
  1255. }
  1256. // 计算预算(budget)、中标金额(bidamount)
  1257. func CountAmount(project *ProjectInfo, info *Info, tmp map[string]interface{}) {
  1258. if info.HasPackage {
  1259. budget := 0.0
  1260. for _, v := range project.Package {
  1261. v1, _ := v.([]map[string]interface{})
  1262. for _, v2 := range v1 {
  1263. if v2["budget"] != nil {
  1264. b1 := qu.Float64All(v2["budget"])
  1265. if b1 > 0 {
  1266. budget = budget + b1
  1267. break
  1268. }
  1269. } else {
  1270. project.Budgettag = 1
  1271. }
  1272. }
  1273. }
  1274. if budget > 0 {
  1275. project.Budget = budget
  1276. project.Budgettag = 0
  1277. } else if budget == 0 && info.Budget > 0 {
  1278. project.Budget = info.Budget
  1279. project.Budgettag = 0
  1280. }
  1281. } else {
  1282. //招标没有多包
  1283. k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1284. if len(k) > 0 {
  1285. //招标是单包
  1286. if len(project.Package) > 0 {
  1287. //项目有多包
  1288. flag := false
  1289. for _, v := range project.Package {
  1290. v1, _ := v.([]map[string]interface{})
  1291. if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1292. flag = true
  1293. }
  1294. }
  1295. if !flag {
  1296. project.Budget = project.Budget + info.Budget
  1297. project.Budgettag = 0
  1298. }
  1299. } else {
  1300. //项目没有多包
  1301. if info.Budget > 0 {
  1302. project.Budget = project.Budget + info.Budget
  1303. project.Budgettag = 0
  1304. } else if info.Budget == 0 && tmp["budget"] != nil {
  1305. project.Budgettag = 0
  1306. }
  1307. }
  1308. } else {
  1309. if info.Budget > 0 && project.Budget < info.Budget {
  1310. project.Budget = info.Budget
  1311. project.Budgettag = 0
  1312. }
  1313. }
  1314. }
  1315. if info.SubType == "中标" || info.SubType == "成交" || info.SubType == "合同" {
  1316. if info.HasPackage {
  1317. bidamount := 0.0
  1318. for _, v := range project.Package {
  1319. v1, _ := v.([]map[string]interface{})
  1320. for _, v2 := range v1 {
  1321. b1 := qu.Float64All(v2["bidamount"])
  1322. if b1 > 0 {
  1323. bidamount = bidamount + b1
  1324. break
  1325. }
  1326. }
  1327. }
  1328. if bidamount > 0 {
  1329. project.Bidamount = bidamount
  1330. project.Bidamounttag = 0
  1331. } else if bidamount == 0 && info.Bidamount > 0 {
  1332. project.Bidamount = info.Bidamount
  1333. project.Bidamounttag = 0
  1334. }
  1335. } else {
  1336. //招标没有多包
  1337. k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1338. if len(k) > 0 {
  1339. //招标是单包
  1340. if len(project.Package) > 0 {
  1341. //项目有多包
  1342. flag := false
  1343. for _, v := range project.Package {
  1344. v1, _ := v.([]map[string]interface{})
  1345. if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1346. flag = true
  1347. }
  1348. }
  1349. if !flag {
  1350. project.Bidamount = project.Bidamount + info.Bidamount
  1351. project.Bidamounttag = 0
  1352. }
  1353. } else {
  1354. //项目没有多包
  1355. if info.Bidamount > 0 {
  1356. project.Bidamount = project.Bidamount + info.Bidamount
  1357. project.Bidamounttag = 0
  1358. } else if info.Bidamount == 0 && tmp["bidamount"] != nil {
  1359. project.Bidamounttag = 0
  1360. } else {
  1361. project.Bidamounttag = 1
  1362. }
  1363. }
  1364. } else {
  1365. if info.SubType == "中标" || info.SubType == "成交" {
  1366. if info.Bidamount > 0 {
  1367. project.Bidamount = info.Bidamount
  1368. project.Bidamounttag = 0
  1369. } else {
  1370. flag := false
  1371. if project.InfoFiled != nil && len(project.InfoFiled) > 0 {
  1372. for _, res := range project.InfoFiled {
  1373. if res.ContractCode != "" && res.ContractCode == info.ContractCode {
  1374. flag = true
  1375. break
  1376. }
  1377. if res.Bidamount == project.Bidamount {
  1378. flag = true
  1379. break
  1380. }
  1381. }
  1382. if !flag {
  1383. project.Bidamount = project.Bidamount + info.Bidamount
  1384. project.Bidamounttag = 0
  1385. } else {
  1386. if info.Budget > 0 && project.Bidamount > info.Bidamount {
  1387. project.Bidamount = info.Bidamount
  1388. project.Bidamounttag = 0
  1389. }
  1390. }
  1391. }
  1392. }
  1393. }
  1394. }
  1395. }
  1396. } else {
  1397. project.Bidamounttag = 1
  1398. }
  1399. }
  1400. //结构体转map
  1401. func StructToMap(filed InfoField) map[string]interface{} {
  1402. //先转json
  1403. result, err := json.Marshal(filed)
  1404. if err != nil {
  1405. return nil
  1406. }
  1407. //json转map
  1408. res := make(map[string]interface{})
  1409. err = json.Unmarshal(result, &res)
  1410. return res
  1411. }
  1412. func ClearData(clearMap, tmp map[string]interface{}) {
  1413. for k, v := range tmp {
  1414. if v == "" {
  1415. clearMap[k] = ""
  1416. }
  1417. }
  1418. }
  1419. func IsCreatePro(info *Info) (bol bool) {
  1420. bol = true
  1421. if info.SubType == "" || info.SubType == "变更" || info.SubType == "验收" || info.SubType == "违规" ||
  1422. info.SubType == "结果变更" || info.SubType == "其它" {
  1423. if info.ProjectName == "" && info.ProjectCode == "" {
  1424. bol = false
  1425. }else if info.ProjectName == "" && info.Buyer == "" {
  1426. bol = false
  1427. }else if info.ProjectCode == "" && info.Buyer == "" {
  1428. bol = false
  1429. }
  1430. }
  1431. return bol
  1432. }
  1433. var bidtype = map[string]string{
  1434. "招标": "招标",
  1435. "邀标": "邀标",
  1436. "询价": "询价",
  1437. "单一": "单一",
  1438. "竞价": "竞价",
  1439. "竞谈": "竞谈",
  1440. }
  1441. var bidstatus = map[string]string{
  1442. "预告": "预告",
  1443. "中标": "中标",
  1444. "成交": "成交",
  1445. "废标": "废标",
  1446. "流标": "流标",
  1447. "合同": "合同",
  1448. }
  1449. func (p *ProjectTask) GetBidTypeAndBidStatus(info *Info) (string, string) {
  1450. p.mapBidLock.Lock()
  1451. defer p.mapBidLock.Unlock()
  1452. typeStr := bidtype[info.TopType]
  1453. statusStr := bidstatus[info.SubType]
  1454. if info.Infoformat == 2 || info.SubType == "拟建" {
  1455. statusStr = "拟建"
  1456. typeStr = ""
  1457. } else {
  1458. if bidtype[typeStr] == "" {
  1459. typeStr = "招标"
  1460. }
  1461. if typeStr == "招标" {
  1462. statusStr = typeStr
  1463. } else {
  1464. if statusStr == "" {
  1465. statusStr = "其它"
  1466. }
  1467. }
  1468. }
  1469. return typeStr, statusStr
  1470. }