project.go 41 KB

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