project.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. package main
  2. import (
  3. "app.yhyue.com/moapp/jybase/encrypt"
  4. "customer_project/config"
  5. "github.com/google/uuid"
  6. "go.mongodb.org/mongo-driver/bson"
  7. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  8. "sort"
  9. "strings"
  10. "sync"
  11. "time"
  12. )
  13. var (
  14. wg sync.WaitGroup
  15. )
  16. // 从对应map中获取对比的项目id
  17. func getCompareIds(pn, pc, pb string, entid int64) (bpn, bpc, bpb int, res []*Key, idArr []string, IDArr []*ID) {
  18. // p.ConCurrentLock(n1, n2, n3, n4)
  19. // defer p.ConCurrentUnLock(n1, n2, n3, n4)
  20. wg.Add(1)
  21. //查找到id数组
  22. res = []*Key{}
  23. //是否查找到,并标识位置。-1代表值为空或已经存在。
  24. bpn, bpc, bpb = -1, -1, -1
  25. var mapPn, mapPc, mapPb map[string]*Key
  26. if mapEnt[entid] == nil {
  27. mapPn = make(map[string]*Key, 50000)
  28. mapPc = make(map[string]*Key, 50000)
  29. mapPb = make(map[string]*Key, 50000)
  30. } else {
  31. mapPn = mapEnt[entid].mapPn
  32. mapPc = mapEnt[entid].mapPc
  33. mapPb = mapEnt[entid].mapPb
  34. }
  35. if pn != "" {
  36. ids := mapPn[pn]
  37. if ids == nil {
  38. ids = &Key{Arr: []string{}}
  39. mapPn[pn] = ids
  40. bpn = 0
  41. }
  42. ids.Lock.Lock()
  43. res = append(res, ids)
  44. }
  45. if pc != "" {
  46. ids := mapPc[pc]
  47. if ids == nil {
  48. ids = &Key{Arr: []string{}}
  49. mapPc[pc] = ids
  50. bpc = len(res)
  51. }
  52. ids.Lock.Lock()
  53. res = append(res, ids)
  54. }
  55. if pb != "" {
  56. ids := mapPb[pb]
  57. if ids == nil {
  58. ids = &Key{Arr: []string{}}
  59. mapPb[pb] = ids
  60. bpb = len(res)
  61. }
  62. ids.Lock.Lock()
  63. res = append(res, ids)
  64. }
  65. repeatId := map[string]bool{}
  66. idArr = []string{} //项目id
  67. IDArr = []*ID{} //项目信息
  68. for _, m := range res {
  69. for _, id := range m.Arr {
  70. if !repeatId[id] {
  71. repeatId[id] = true
  72. //_, _ = strconv.ParseInt(id[0:8], 16, 64)
  73. AllIdsMapLock.Lock()
  74. Id := AllIdsMap[id]
  75. AllIdsMapLock.Unlock()
  76. if Id != nil {
  77. Id.Lock.Lock()
  78. idArr = append(idArr, id)
  79. IDArr = append(IDArr, Id)
  80. }
  81. }
  82. }
  83. }
  84. mapEnt[entid] = &EntMap{
  85. mapPb: mapPb,
  86. mapPn: mapPn,
  87. mapPc: mapPc,
  88. }
  89. return
  90. }
  91. func startProjectMerge(info *Info, tmp map[string]interface{}) {
  92. findLock.Lock()
  93. defer findLock.Unlock()
  94. //bpn, bpc, bptc, bpb 是否查找到,并标识位置。-1代表未查找到。
  95. //pids 是项目id数组集合
  96. //IDArr,是单个项目ID对象集合
  97. bpn, bpc, bpb, pids, _, IDArr := getCompareIds(info.ProjectName, info.ProjectCode, info.Buyer, info.EntId) //, info.LenPN, info.LenPC, info.LenPTC, len([]rune(info.Buyer)))
  98. defer wg.Done()
  99. //map--k为pn,ptn,pc,ptc,buyer值 v为Id数组和lock
  100. for _, m := range pids {
  101. defer m.Lock.Unlock()
  102. }
  103. for _, id := range IDArr {
  104. defer id.Lock.Unlock()
  105. }
  106. bFindProject := false
  107. findPid := ""
  108. //获取完id,进行计算
  109. //定义两组
  110. comRes1 := []*Project{} //优先级最高的对比结果数组
  111. comRes2 := []*Project{} //优化级其次
  112. comRes3 := []*Project{}
  113. for _, v := range IDArr {
  114. comStr := ""
  115. compareProject := v.P
  116. compareProject.score = 0
  117. //代理机构完全不相同,直接新建项目
  118. if CheckContain(compareProject.Agency, info.Agency) == 3 {
  119. continue
  120. }
  121. //地区(省、市、区)不同,直接新建项目
  122. if ComparePlace(compareProject, info) {
  123. continue
  124. }
  125. compareStr, score := comparePNC(info, compareProject)
  126. resVal, pjVal := Select(compareStr, info, compareProject)
  127. //---------------------------------------
  128. if resVal > 0 {
  129. compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount, score2 := compareBCTABB(info, compareProject, 0, score)
  130. //项目名称、项目编号、标题项目编号、采购单位、省、市、发布时间、代理机构
  131. comStr = compareStr + compareBuyer + compareCity + compareTime + compareAgency + compareBudget + compareBidmount
  132. compareProject.comStr = comStr
  133. compareProject.pjVal = pjVal
  134. compareProject.resVal = resVal
  135. //log.Println(compareProject.comStr)
  136. eqV := compareResult(resVal, pjVal, score2, comStr, compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount)
  137. if eqV == 1 {
  138. comRes1 = append(comRes1, compareProject)
  139. } else if eqV == 2 {
  140. comRes2 = append(comRes2, compareProject)
  141. } else if eqV == 3 {
  142. comRes3 = append(comRes3, compareProject)
  143. }
  144. }
  145. }
  146. //--------------------------------对比完成-----------------------
  147. //更新数组、更新项目
  148. for kv, resN := range [][]*Project{comRes1, comRes2, comRes3} {
  149. if len(resN) > 0 {
  150. if len(resN) > 1 {
  151. sort.Slice(resN, func(i, j int) bool {
  152. return resN[i].score > resN[j].score
  153. })
  154. }
  155. resArr := []*Project{}
  156. for _, res := range resN {
  157. resArr = append(resArr, res)
  158. }
  159. if len(resArr) > 0 {
  160. bFindProject = true
  161. findPid = resArr[0].ProjectId
  162. UpdateProject(tmp, info, resArr[0], kv+1, resArr[0].comStr)
  163. for k2, bv := range []int{bpn, bpc, bpb} {
  164. if bv > -1 {
  165. pids[bv].Arr = append(pids[bv].Arr, findPid)
  166. if k2 == 0 {
  167. if resArr[0].ProjectName == "" {
  168. resArr[0].ProjectName = info.ProjectName
  169. }
  170. } else if k2 < 3 {
  171. if resArr[0].ProjectCode == "" {
  172. resArr[0].ProjectCode = info.ProjectCode
  173. }
  174. } else {
  175. if resArr[0].Buyer == "" {
  176. resArr[0].Buyer = info.Buyer
  177. }
  178. }
  179. }
  180. }
  181. } else {
  182. bFindProject = false
  183. findPid = ""
  184. }
  185. break
  186. }
  187. }
  188. if !bFindProject {
  189. id, p1 := NewProject(tmp, info)
  190. AllIdsMapLock.Lock()
  191. AllIdsMap[id] = &ID{Id: id, P: p1}
  192. AllIdsMapLock.Unlock()
  193. for _, m := range pids {
  194. m.Arr = append(m.Arr, id)
  195. }
  196. }
  197. }
  198. func compareBCTABB(info *Info, cp *Project, diffTime int64, score int) (compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount string, score2 int) {
  199. compareBuyer = "D"
  200. if len([]rune(info.Buyer)) > 3 && len([]rune(cp.Buyer)) > 3 {
  201. v := CheckContain(info.Buyer, cp.Buyer)
  202. if v == 1 {
  203. compareBuyer = "A"
  204. score += 3
  205. } else {
  206. //v1 := CosineSimilar(info.Buyer, cp.Buyer)
  207. if v == 2 {
  208. compareBuyer = "B"
  209. score += 1
  210. } else {
  211. compareBuyer = "C"
  212. }
  213. }
  214. }
  215. //---------------------------------------
  216. compareCity = ""
  217. if info.Area != "全国" && info.Area != "" && info.Area == cp.Area {
  218. compareCity += "A"
  219. score += 2
  220. } else if info.Area == "全国" || cp.Area == "全国" {
  221. compareCity += "B"
  222. score += 1
  223. } else {
  224. compareCity += "C"
  225. }
  226. if compareCity != "C" {
  227. if info.City != "" && info.City == cp.City {
  228. compareCity += "A"
  229. score += 2
  230. } else {
  231. if info.Area == "全国" || cp.Area == "全国" {
  232. compareCity += "B"
  233. } else if info.City == compareCity {
  234. compareCity += "B"
  235. } else {
  236. compareCity += "C"
  237. }
  238. }
  239. } else {
  240. compareCity += "C"
  241. }
  242. score2 = 0
  243. if compareCity == "AA" {
  244. if info.District != "" && info.District == cp.District {
  245. score2 = 1
  246. }
  247. }
  248. compareTime = "D"
  249. if diffTime < 45*86400 {
  250. compareTime = "A"
  251. score += 2
  252. } else if diffTime < 90*86400 {
  253. compareTime = "B"
  254. score += 1
  255. }
  256. compareAgency = "D"
  257. if info.Agency != "" {
  258. if info.Agency == cp.Agency {
  259. compareAgency = "A"
  260. score += 2
  261. score2 += 1
  262. } else if cp.Agency != "" {
  263. if strings.Contains(info.Agency, cp.Agency) || strings.Contains(cp.Agency, info.Agency) {
  264. compareAgency = "B"
  265. score += 1
  266. score2 += 1
  267. } else {
  268. compareAgency = "C"
  269. }
  270. }
  271. }
  272. compareBudget = "C"
  273. if info.Budget > 0 && (info.Budget == cp.Budget || (cp.Bidamount > 0 && info.Budget > cp.Bidamount && (info.Budget-cp.Bidamount) < (0.15*info.Budget))) {
  274. compareBudget = "A"
  275. score += 1
  276. score2 += 1
  277. }
  278. // else if info.Budget == 0 && cp.Budget == 0 {
  279. // compareBudget = "B"
  280. // }
  281. compareBidmount = "C"
  282. if info.Bidamount > 0 && (info.Bidamount == cp.Bidamount || (cp.Budget > 0 && cp.Budget > info.Bidamount && (cp.Budget-info.Bidamount) < 0.15*cp.Budget)) {
  283. compareBidmount = "A"
  284. score += 1
  285. score2 += 1
  286. }
  287. // else if info.Bidamount == 0 && cp.Bidamount == 0 {
  288. // compareBidmount = "B"
  289. // }
  290. cp.score = score
  291. return
  292. }
  293. func compareResult(resVal, pjVal, score2 int, comStr, compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount string) int {
  294. eqV := 0
  295. switch resVal {
  296. case 3:
  297. if pjVal == 3 && comStr[3:] != "CCCDCCC" {
  298. eqV = 1
  299. } else if compareBuyer < "C" {
  300. if pjVal > 1 {
  301. eqV = 1
  302. } else { //if (compareCity[1:1] != "C" || compareTime != "D") && score2 > 0
  303. eqV = 2
  304. }
  305. } else if compareBuyer == "D" {
  306. if pjVal > 1 && (compareCity[1:1] != "C" || score2 > 0) {
  307. eqV = 2
  308. } else if compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  309. eqV = 3
  310. }
  311. } else {
  312. if pjVal == 3 && (score2 > 0 || compareCity[1:1] != "C") {
  313. eqV = 2
  314. } else if pjVal == 2 && compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  315. eqV = 3
  316. } else if compareCity == "AA" && compareTime == "A" && score2 > 0 {
  317. eqV = 3
  318. }
  319. }
  320. case 2:
  321. if compareBuyer < "C" {
  322. if pjVal > 1 {
  323. eqV = 2
  324. } else if compareCity[1:1] != "C" && compareTime == "A" || score2 > 0 {
  325. eqV = 3
  326. }
  327. } else if compareBuyer == "D" {
  328. if pjVal > 1 && (score2 > 0 || compareCity[1:1] != "C") {
  329. eqV = 2
  330. } else if compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  331. eqV = 3
  332. }
  333. } else {
  334. if pjVal > 1 && compareTime == "A" && (score2 > 0 || compareCity[1:1] != "C") {
  335. eqV = 2
  336. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  337. eqV = 3
  338. }
  339. }
  340. case 1:
  341. if compareBuyer < "C" {
  342. if pjVal > 1 && (score2 > 0 || compareCity[1:1] != "C") {
  343. eqV = 2
  344. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  345. eqV = 3
  346. }
  347. } else if compareBuyer == "D" {
  348. if pjVal > 1 && compareTime == "A" && (score2 > 0 || compareCity[1:1] != "C") {
  349. eqV = 2
  350. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  351. eqV = 3
  352. }
  353. } else {
  354. if pjVal > 1 && compareTime == "A" && score2 > 0 && (compareBudget == "A" || compareBidmount == "A") && compareCity[1:1] != "C" {
  355. eqV = 3
  356. }
  357. }
  358. }
  359. return eqV
  360. }
  361. func ComparePlace(project *Project, info *Info) bool {
  362. if info.Area == "全国" || info.Area == "" {
  363. return false
  364. }
  365. if project.Area == "全国" || project.Area == "" {
  366. return false
  367. }
  368. if info.Area == project.Area {
  369. if info.City == "" || project.City == "" {
  370. return false
  371. } else if info.City == project.City {
  372. return false
  373. }
  374. } else {
  375. return true
  376. }
  377. return true
  378. }
  379. func NewCachePinfo(thisinfo *Info, pid string) Project {
  380. p1 := Project{
  381. ProjectId: pid,
  382. EntId: thisinfo.EntId,
  383. ProjectName: thisinfo.ProjectName,
  384. ProjectCode: thisinfo.ProjectCode,
  385. Buyer: thisinfo.Buyer,
  386. Agency: thisinfo.Agency,
  387. Area: thisinfo.Area,
  388. City: thisinfo.City,
  389. District: thisinfo.District,
  390. FirstTime: thisinfo.Publishtime,
  391. LastTime: thisinfo.Publishtime,
  392. Budget: thisinfo.Budget,
  393. Bidamount: thisinfo.Bidamount,
  394. }
  395. return p1
  396. }
  397. func NewProject(tmp map[string]interface{}, thisinfo *Info) (string, *Project) {
  398. pId := uuid.New().String()
  399. pId = strings.ReplaceAll(pId, "-", "")
  400. set := map[string]interface{}{}
  401. set["ent_id"] = thisinfo.EntId
  402. set["projectId"] = pId
  403. for _, f := range FIELDS {
  404. if tmp[f] != nil && tmp[f] != "" {
  405. set[f] = tmp[f]
  406. }
  407. }
  408. if util.ObjToString(tmp["projectname"]) == "" {
  409. set["projectname"] = thisinfo.ProjectName
  410. }
  411. p1 := NewCachePinfo(thisinfo, pId)
  412. bt := util.ObjToString(tmp["toptype"])
  413. bs := util.ObjToString(tmp["subtype"])
  414. if thisinfo.SubType == "拟建" {
  415. set["bidstatus"] = "拟建"
  416. bt = "拟建"
  417. } else {
  418. if bidtype[bs] != "" {
  419. set["bidtype"] = bidtype[bs]
  420. } else {
  421. set["bidtype"] = "招标"
  422. }
  423. if bt == "招标" {
  424. set["bidstatus"] = bt
  425. } else {
  426. if bidstatus[bs] != "" {
  427. set["bidstatus"] = thisinfo.SubType
  428. bt = thisinfo.SubType
  429. } else if bs == "" {
  430. set["bidstatus"] = ""
  431. bt = ""
  432. } else {
  433. set["bidstatus"] = "其它"
  434. bt = "其它"
  435. }
  436. }
  437. }
  438. if tmp["bidopentime"] != nil {
  439. set["bidopentime"] = tmp["bidopentime"]
  440. }
  441. now := time.Now()
  442. set["createtime"] = util.FormatDate(&now, util.Date_Full_Layout)
  443. set["updatetime"] = util.FormatDate(&now, util.Date_Full_Layout)
  444. set["firsttime"] = thisinfo.Publishtime
  445. set["lasttime"] = thisinfo.Publishtime
  446. if thisinfo.TopType == "招标" {
  447. set["zbtime"] = tmp["publishtime"]
  448. } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
  449. set["jgtime"] = tmp["publishtime"]
  450. }
  451. if util.ObjToString(tmp["tagname"]) != "" {
  452. p1.TagName = util.ObjToString(tmp["tagname"])
  453. set["tagname"] = util.ObjToString(tmp["tagname"])
  454. }
  455. if util.ObjToString(tmp["tagname2"]) != "" {
  456. p1.TagName2 = util.ObjToString(tmp["tagname2"])
  457. set["tagname2"] = util.ObjToString(tmp["tagname2"])
  458. }
  459. if util.ObjToString(tmp["tagname3"]) != "" {
  460. p1.TagName3 = util.ObjToString(tmp["tagname3"])
  461. set["tagname3"] = util.ObjToString(tmp["tagname3"])
  462. }
  463. if tmp["industry"] != nil {
  464. set["industry"] = util.IntAll(tmp["industry"])
  465. }
  466. if tmp["region"] != nil {
  467. set["region"] = util.IntAll(tmp["region"])
  468. }
  469. if tmp["winner_tag"] != nil {
  470. set["winner_tag"] = util.IntAll(tmp["winner_tag"])
  471. }
  472. id := MysqlTool.Insert(config.Conf.DB.Mysql.Pcoll, set)
  473. if id > 0 {
  474. if len(thisinfo.Winners) > 0 {
  475. for _, w := range thisinfo.Winners {
  476. if w == "" {
  477. continue
  478. }
  479. wSave := make(map[string]interface{})
  480. wSave["projectId"] = pId
  481. wSave["msg_id"] = id
  482. wSave["winner_name"] = w
  483. wSave["bidamount"] = tmp["bidamount"]
  484. wSave["winner_person"] = thisinfo.WinnerPerson
  485. wSave["winner_tel"] = thisinfo.WinnerTel
  486. wSave["ent_id"] = thisinfo.EntId
  487. einfo := MysqlEnt.FindOne("dws_f_ent_baseinfo", bson.M{"name": w}, "id,name_id,company_id", "")
  488. if einfo != nil && len(*einfo) > 0 {
  489. wSave["name_id"] = (*einfo)["name_id"]
  490. wSave["company_id"] = (*einfo)["company_id"]
  491. if cid := util.ObjToString((*einfo)["company_id"]); cid != "" {
  492. wSave["encrypt_id"] = encrypt.EncodeArticleId2ByCheck(cid)
  493. }
  494. }
  495. MysqlTool.Insert("customer_data_yys_project_winner", wSave)
  496. }
  497. }
  498. MysqlTool.Update(config.Conf.DB.Mysql.Coll, bson.M{"id": thisinfo.Id}, bson.M{"projectId": pId})
  499. }
  500. return pId, &p1
  501. }
  502. func UpdateProject(tmp map[string]interface{}, thisinfo *Info, pInfo *Project, weight int, comStr string) {
  503. set := map[string]interface{}{}
  504. //相同城市的公告才会合并到一起(全国列外)
  505. if thisinfo.Area != "全国" {
  506. pInfo.Area = thisinfo.Area
  507. set["area"] = thisinfo.Area
  508. if thisinfo.City != "" {
  509. pInfo.City = thisinfo.City
  510. set["city"] = thisinfo.City
  511. }
  512. if thisinfo.District != "" {
  513. pInfo.District = thisinfo.District
  514. set["district"] = thisinfo.District
  515. }
  516. }
  517. //项目名称
  518. if pInfo.ProjectName == "" && thisinfo.ProjectName != "" {
  519. pInfo.ProjectName = thisinfo.ProjectName
  520. set["projectname"] = thisinfo.ProjectName
  521. }
  522. if pInfo.ProjectCode == "" && thisinfo.ProjectCode != "" {
  523. pInfo.ProjectCode = thisinfo.ProjectCode
  524. set["projectcode"] = thisinfo.ProjectCode
  525. }
  526. //7--采购单位
  527. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  528. pInfo.Buyer = thisinfo.Buyer
  529. set["buyer"] = thisinfo.Buyer
  530. pInfo.Buyerclass = thisinfo.Buyerclass
  531. set["buyerclass"] = thisinfo.Buyerclass
  532. }
  533. //采购单位联系人
  534. if thisinfo.Buyerperson != "" {
  535. pInfo.Buyerperson = thisinfo.Buyerperson
  536. set["buyerperson"] = thisinfo.Buyerperson
  537. }
  538. //采购单位電話
  539. if thisinfo.Buyertel != "" {
  540. pInfo.Buyertel = thisinfo.Buyertel
  541. set["buyertel"] = pInfo.Buyertel
  542. }
  543. //8--代理机构
  544. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  545. pInfo.Agency = thisinfo.Agency
  546. set["agency"] = thisinfo.Agency
  547. }
  548. if util.ObjToString(tmp["agencyperson"]) != "" {
  549. set["agencyperson"] = tmp["agencyperson"]
  550. }
  551. if util.ObjToString(tmp["agencytel"]) != "" {
  552. set["agencytel"] = tmp["agencytel"]
  553. }
  554. //if len(thisinfo.Winners) > 0 {
  555. // var winners []string
  556. // if pInfo.Winners == "" {
  557. // for _, k := range thisinfo.Winners {
  558. // if k == "" {
  559. // continue
  560. // }
  561. // if BinarySearch(winners, k) == -1 {
  562. // winners = append(winners, k)
  563. // }
  564. // }
  565. // } else {
  566. // winners = strings.Split(pInfo.Winners, ",")
  567. // for _, k := range thisinfo.Winners {
  568. // if k == "" {
  569. // continue
  570. // }
  571. // if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  572. // if BinarySearch(winners, k) != -1 {
  573. // deleteSlice(winners, k, "")
  574. // }
  575. // } else {
  576. // if BinarySearch(winners, k) == -1 {
  577. // winners = append(winners, k)
  578. // }
  579. // }
  580. // }
  581. // }
  582. // set["s_winner"] = strings.Join(util.ObjArrToStringArr(Duplicate(winners)), ",")
  583. // if util.ObjToString(tmp["winnertel"]) != "" {
  584. // set["winnertel"] = tmp["winnertel"]
  585. // }
  586. // if util.ObjToString(tmp["winnerperson"]) != "" {
  587. // set["winnerperson"] = tmp["winnerperson"]
  588. // }
  589. //}
  590. bt := util.ObjToString(tmp["toptype"])
  591. bs := util.ObjToString(tmp["subtype"])
  592. if bt == "招标" {
  593. //招标状态,更新projectscope
  594. if tmp["projectscope"] != nil {
  595. set["projectscope"] = util.ObjToString(tmp["projectscope"])
  596. }
  597. set["bidstatus"] = bt
  598. pInfo.Bidstatus = bt
  599. if bidtype[bs] != "" {
  600. set["bidtype"] = bidtype[bs]
  601. pInfo.Bidtype = bidtype[bs]
  602. } else {
  603. set["bidtype"] = "招标"
  604. pInfo.Bidtype = "招标"
  605. }
  606. } else {
  607. if bidstatus[bs] != "" {
  608. set["bidstatus"] = thisinfo.SubType
  609. pInfo.Bidstatus = thisinfo.SubType
  610. } else if bs == "" && bt == "结果" {
  611. if pInfo.Bidstatus == "招标" {
  612. set["bidstatus"] = ""
  613. pInfo.Bidstatus = ""
  614. }
  615. } else {
  616. set["bidstatus"] = "其它"
  617. pInfo.Bidstatus = "其它"
  618. }
  619. }
  620. if tmp["bidopentime"] != nil {
  621. set["bidopentime"] = tmp["bidopentime"]
  622. }
  623. set["lasttime"] = thisinfo.Publishtime
  624. if thisinfo.TopType == "招标" {
  625. set["zbtime"] = tmp["publishtime"]
  626. } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
  627. set["jgtime"] = tmp["publishtime"]
  628. }
  629. if util.ObjToString(tmp["tagname"]) != "" && pInfo.TagName != "" {
  630. pInfo.TagName = util.ObjToString(tmp["tagname"])
  631. set["tagname"] = util.ObjToString(tmp["tagname"])
  632. }
  633. if util.ObjToString(tmp["tagname2"]) != "" && pInfo.TagName2 != "" {
  634. pInfo.TagName2 = util.ObjToString(tmp["tagname2"])
  635. set["tagname2"] = util.ObjToString(tmp["tagname2"])
  636. }
  637. if util.ObjToString(tmp["tagname3"]) != "" && pInfo.TagName3 != "" {
  638. pInfo.TagName3 = util.ObjToString(tmp["tagname3"])
  639. set["tagname3"] = util.ObjToString(tmp["tagname3"])
  640. }
  641. if tmp["industry"] != nil {
  642. set["industry"] = thisinfo.Industry
  643. }
  644. if tmp["region"] != nil {
  645. set["region"] = thisinfo.Region
  646. }
  647. if tmp["winning_tag"] != nil {
  648. set["winning_tag"] = thisinfo.WinnerTag
  649. }
  650. if thisinfo.Budget > 0 {
  651. set["budget"] = thisinfo.Budget
  652. pInfo.Budget = thisinfo.Budget
  653. }
  654. if thisinfo.Bidamount > 0 {
  655. set["bidamount"] = thisinfo.Bidamount
  656. pInfo.Bidamount = thisinfo.Bidamount
  657. }
  658. now := time.Now()
  659. set["updatetime"] = util.FormatDate(&now, util.Date_Full_Layout)
  660. b := MysqlTool.Update(config.Conf.DB.Mysql.Pcoll, bson.M{"projectId": pInfo.ProjectId}, set)
  661. if b {
  662. if len(thisinfo.Winners) > 0 {
  663. for _, w := range thisinfo.Winners {
  664. if w == "" {
  665. continue
  666. }
  667. if info := MysqlTool.FindOne("customer_data_yys_project_winner", bson.M{"projectId": pInfo.ProjectId, "winner_name": w}, "", ""); info != nil && len(*info) > 0 {
  668. continue
  669. }
  670. wSave := make(map[string]interface{})
  671. wSave["projectId"] = pInfo.ProjectId
  672. wSave["msg_id"] = pInfo.Id
  673. wSave["winner_name"] = w
  674. wSave["bidamount"] = tmp["bidamount"]
  675. wSave["winner_person"] = thisinfo.WinnerPerson
  676. wSave["winner_tel"] = thisinfo.WinnerTel
  677. wSave["ent_id"] = thisinfo.EntId
  678. einfo := MysqlEnt.FindOne("dws_f_ent_baseinfo", bson.M{"name": w}, "id,name_id,company_id", "")
  679. if einfo != nil && len(*einfo) > 0 {
  680. wSave["name_id"] = (*einfo)["name_id"]
  681. wSave["company_id"] = (*einfo)["company_id"]
  682. if cid := util.ObjToString((*einfo)["company_id"]); cid != "" {
  683. wSave["encrypt_id"] = encrypt.EncodeArticleId2ByCheck(cid)
  684. }
  685. }
  686. MysqlTool.Insert("customer_data_yys_project_winner", wSave)
  687. }
  688. }
  689. MysqlTool.Update(config.Conf.DB.Mysql.Coll, bson.M{"id": thisinfo.Id}, bson.M{"projectId": pInfo.ProjectId})
  690. }
  691. }