project.go 35 KB

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