project.go 45 KB

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