project.go 35 KB

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