owner.go 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. package service
  2. import (
  3. elastic "app.yhyue.com/moapp/jybase/es"
  4. "context"
  5. "encoding/json"
  6. "fmt"
  7. "sort"
  8. "strings"
  9. "time"
  10. "app.yhyue.com/moapp/jybase/encrypt"
  11. "app.yhyue.com/moapp/jybase/common"
  12. . "bp.jydev.jianyu360.cn/CRM/application/api/common"
  13. "bp.jydev.jianyu360.cn/CRM/application/entity"
  14. "github.com/gogf/gf/v2/util/gconv"
  15. "github.com/shopspring/decimal"
  16. "github.com/zeromicro/go-zero/core/logx"
  17. )
  18. const (
  19. EntINDEX = "ent_info"
  20. EntTYPE = "ent_info"
  21. )
  22. type OwnerService struct {
  23. PartyA string
  24. Supplier string
  25. Heterotophy string
  26. Intermediary string
  27. Agency string
  28. SearchEntName string
  29. SourceType string
  30. ProcessingStatus string
  31. Area string
  32. PositionId int64
  33. PageIndex int64
  34. PageSize int64
  35. BuyerId string
  36. BuyerName string
  37. WinnerId string
  38. WinnerName string
  39. CooperateType string
  40. EntAccountId int64
  41. ProjectType string
  42. }
  43. type BuyerProject struct {
  44. BuyerId string
  45. BuyerName string
  46. Project ProjectEntity
  47. IsMonitor bool
  48. IsCreateCustomer bool
  49. IsIgnore bool
  50. Area string
  51. Zbtime int64
  52. }
  53. type ProjectEntity struct {
  54. Number int64
  55. zbtime int64
  56. EstimatedAmount int64
  57. Connections []map[string]interface{}
  58. }
  59. type Recommend struct {
  60. BuyerId string `ch:"buyer_id"`
  61. Buyer string `ch:"buyer"`
  62. }
  63. type Project struct {
  64. BuyerId string `ch:"buyer_id"`
  65. Area string `ch:"area"`
  66. GroupCount uint64 `ch:"group_count"`
  67. Zbtime int64 `ch:"zbtime"`
  68. Money decimal.Decimal `ch:"money"`
  69. }
  70. func (t *OwnerService) OwnerlList() map[string]interface{} {
  71. //先查询采购单位列表
  72. startTime := time.Now().Unix()
  73. dataMap := &map[string]map[string]interface{}{}
  74. projectMap := &map[string]map[string]interface{}{}
  75. if t.PartyA != "" || t.Supplier != "" || t.Heterotophy != "" || t.Intermediary != "" || t.Agency != "" {
  76. dataMap = BuyerList(t.PartyA, t.Supplier, t.Heterotophy, t.Intermediary, t.Agency, t.PositionId)
  77. if len(*dataMap) == 0 {
  78. return map[string]interface{}{
  79. "connectionsNumber": 0,
  80. "highSuccessNumber": 0,
  81. "monitorNumber": 0,
  82. "list": []BuyerProject{},
  83. }
  84. }
  85. //处理状态初始化
  86. ProcessingStatusInit(t.PositionId, dataMap, t.ProcessingStatus)
  87. //监控状态处理
  88. MonitorStatusInit(t.PositionId, dataMap, t.SourceType)
  89. //项目数量查询
  90. buyerArr := []string{}
  91. for _, value := range *dataMap {
  92. buyerArr = append(buyerArr, fmt.Sprintf(`"%s"`, gconv.String(value["buyerName"])))
  93. }
  94. //项目数量处理
  95. projectMap, _, dataMap = ProjectHandle(buyerArr, t.EntAccountId, t.SearchEntName, t.Area, t.ProjectType, dataMap)
  96. } else if t.SearchEntName != "" {
  97. //1 只看转介绍成功率高2只看已监控的
  98. //先查找采购单位数据
  99. projectMap, dataMap, _ = ProjectHandle([]string{}, t.EntAccountId, t.SearchEntName, t.Area, t.ProjectType, dataMap)
  100. a7 := time.Now().Unix()
  101. fmt.Println("es用时", a7-startTime)
  102. ProcessingStatusInit(t.PositionId, dataMap, t.ProcessingStatus)
  103. a8 := time.Now().Unix()
  104. fmt.Println("状态用时", a8-a7)
  105. //监控状态处理
  106. MonitorStatusInit(t.PositionId, dataMap, t.SourceType)
  107. a9 := time.Now().Unix()
  108. fmt.Println("监控用时", a9-a8)
  109. }
  110. endTime := time.Now().Unix()
  111. fmt.Println("用时时间:", endTime-startTime)
  112. if len(*dataMap) == 0 {
  113. return map[string]interface{}{}
  114. }
  115. //采购单位和项目合并
  116. a1 := time.Now().Unix()
  117. returnData, connectionsNumber, highSuccessNumber, monitorNumber := BuyerProjectMerge(dataMap, projectMap, t.SourceType)
  118. a2 := time.Now().Unix()
  119. fmt.Println("组合数据", a2-a1)
  120. //数组排序
  121. //分页数据处理
  122. if t.PageSize == 0 {
  123. t.PageSize = 10
  124. }
  125. if t.PageIndex == 0 {
  126. t.PageIndex = 1
  127. }
  128. startIndex := (t.PageIndex - 1) * t.PageSize
  129. endIndex := t.PageIndex * t.PageSize
  130. sort.Slice(returnData, func(i, j int) bool {
  131. return returnData[i].Zbtime < returnData[j].Zbtime
  132. })
  133. if startIndex < gconv.Int64(len(returnData)) {
  134. if endIndex > gconv.Int64(len(returnData)) {
  135. endIndex = gconv.Int64(len(returnData))
  136. }
  137. returnData = returnData[startIndex:endIndex]
  138. } else {
  139. return map[string]interface{}{}
  140. }
  141. buyerIdArr := []string{}
  142. for _, value := range returnData {
  143. if value.BuyerId != "" {
  144. buyerIdArr = append(buyerIdArr, fmt.Sprintf("'%s'", value.BuyerId))
  145. }
  146. }
  147. //可介绍业主人脉处理
  148. a3 := time.Now().Unix()
  149. routeList := ConnectionsHandle(buyerIdArr, t.PositionId, false)
  150. a4 := time.Now().Unix()
  151. fmt.Println("组合数1111据", a4-a3)
  152. for _, v := range routeList {
  153. buyerId := gconv.String(v["a_id"])
  154. for i, v1 := range returnData {
  155. aBuyerId := v1.BuyerId
  156. if buyerId == aBuyerId {
  157. //组装数据
  158. returnData[i].Project.Connections = append(returnData[i].Project.Connections, v)
  159. }
  160. }
  161. }
  162. //返回数据组装
  163. return map[string]interface{}{
  164. "connectionsNumber": connectionsNumber,
  165. "highSuccessNumber": highSuccessNumber,
  166. "monitorNumber": monitorNumber,
  167. "list": returnData,
  168. }
  169. }
  170. // 可介绍业主人脉列表
  171. func ConnectionsHandle(buyerArr []string, positionId int64, isAll bool) []map[string]interface{} {
  172. returnData := []map[string]interface{}{}
  173. a1 := time.Now().Unix()
  174. //中间人
  175. returnData = FindMiddleman(buyerArr, positionId, returnData)
  176. a2 := time.Now().Unix()
  177. fmt.Println("中间人", a2-a1)
  178. if isAll && len(returnData) > 0 {
  179. return returnData
  180. }
  181. //采购单位 投资关系 管辖关系
  182. //采购单位
  183. a3 := time.Now().Unix()
  184. returnData = Findfirstparty(buyerArr, returnData)
  185. a4 := time.Now().Unix()
  186. fmt.Println("采购单位", a4-a3)
  187. if isAll && len(returnData) > 0 {
  188. return returnData
  189. }
  190. a5 := time.Now().Unix()
  191. returnData = Findwinner(buyerArr, returnData)
  192. a6 := time.Now().Unix()
  193. logx.Info("供应商", a6-a5)
  194. return returnData
  195. }
  196. // 供应商处理
  197. func Findwinner(buyerArr []string, returnData []map[string]interface{}) []map[string]interface{} {
  198. if len(buyerArr) == 0 {
  199. return returnData
  200. }
  201. //供应商 采购单位 供应商 招标代理机构 采购单位 招标代理机构 需要计算合作次数
  202. winnerSql := fmt.Sprintf(`select
  203. DISTINCT
  204. zbtime,
  205. project_id,
  206. project_name,
  207. buyer_id,
  208. buyer,
  209. agency_id,
  210. agency,
  211. winner_id,
  212. winner
  213. from
  214. transaction_info
  215. where
  216. buyer_id in (%s)`, strings.Join(buyerArr, ","))
  217. winnerArr := SupplierFindConnectionsHandle(winnerSql)
  218. if winnerArr != nil && len(winnerArr) > 0 {
  219. //企业联系人处理
  220. entIdArr := []string{}
  221. for _, v := range winnerArr {
  222. if v.WinnerId != "" {
  223. entIdArr = append(entIdArr, fmt.Sprintf("'%s'", v.WinnerId))
  224. }
  225. if v.Agency_id != "" {
  226. entIdArr = append(entIdArr, fmt.Sprintf("'%s'", v.Agency_id))
  227. }
  228. }
  229. personMap := map[string]string{}
  230. entNameMap := map[string]string{}
  231. if len(entIdArr) > 0 {
  232. personSql := fmt.Sprintf(`select id,name as personName from ent_contact where id in (%s) ORDER by name`, strings.Join(entIdArr, ","))
  233. personArr := PersonFindConnectionsHandle(personSql)
  234. //联系人处理
  235. for _, v := range personArr {
  236. personMap[v.Id] = v.PersonName
  237. }
  238. entSql := fmt.Sprintf(`select id ,company_name as personName from ent_info where id in (%s) ORDER by company_name`, strings.Join(entIdArr, ","))
  239. entNameArr := PersonFindConnectionsHandle(entSql)
  240. for _, v := range entNameArr {
  241. entNameMap[v.Id] = v.PersonName
  242. }
  243. }
  244. winnerMap := map[string]map[string]interface{}{}
  245. agencyMap := map[string]map[string]interface{}{}
  246. agencyIdMap := map[string]bool{}
  247. for _, m := range winnerArr {
  248. buyerId := m.Buyer_id
  249. winner := m.Winner
  250. buyer := m.Buyer
  251. winnerId := m.WinnerId
  252. agency := m.Agency
  253. agencyId := m.Agency_id
  254. projectId := encrypt.EncodeArticleId2ByCheck(m.Project_id)
  255. projectName := m.Project_name
  256. zbtime := m.Zbtime
  257. key := fmt.Sprintf("%s_%s", buyerId, winnerId)
  258. if winnerId != "" {
  259. if _, ok := winnerMap[key]; ok {
  260. data := winnerMap[key]
  261. data["count"] = gconv.Int64(data["data"]) + 1
  262. dataList := gconv.Maps(data["list"])
  263. dataList = append(dataList, map[string]interface{}{
  264. "zbtime": zbtime,
  265. "projectId": projectId,
  266. "projectName": projectName,
  267. })
  268. data["list"] = dataList
  269. winnerMap[key] = data
  270. } else {
  271. winnerMap[key] = map[string]interface{}{
  272. "b_id": winnerId,
  273. "b_name": winner,
  274. "a_name": buyer,
  275. "a_id": buyerId,
  276. "sourceType": "supplier",
  277. "personName": gconv.String(personMap[winnerId]),
  278. "count": 1,
  279. "list": []map[string]interface{}{
  280. {
  281. "zbtime": zbtime,
  282. "entName": winner,
  283. "projectId": projectId,
  284. "projectName": projectName,
  285. },
  286. },
  287. }
  288. }
  289. }
  290. if agencyId != "" && buyerId != "" && projectId != "" {
  291. key = fmt.Sprintf("%s_%s_%s", buyerId, agencyId, projectId)
  292. key1 := fmt.Sprintf("%s_%s_%s", buyerId, agencyId, projectId)
  293. if _, ok := agencyIdMap[key]; ok {
  294. data := agencyMap[key]
  295. data["count"] = gconv.Int64(data["data"]) + 1
  296. dataList := gconv.Maps(data["list"])
  297. dataList = append(dataList, map[string]interface{}{
  298. "zbtime": zbtime,
  299. "projectId": projectId,
  300. "projectName": projectName,
  301. })
  302. data["list"] = dataList
  303. agencyMap[key] = data
  304. } else {
  305. agencyIdMap[key] = true
  306. agencyMap[key1] = map[string]interface{}{
  307. "b_id": agencyId,
  308. "b_name": agency,
  309. "a_name": buyer,
  310. "a_id": buyerId,
  311. "sourceType": "agency",
  312. "count": 1,
  313. "personName": gconv.String(personMap[agencyId]),
  314. "list": []map[string]interface{}{
  315. {
  316. "zbtime": zbtime,
  317. "projectId": projectId,
  318. "projectName": projectName,
  319. },
  320. },
  321. }
  322. }
  323. }
  324. }
  325. for _, m := range winnerMap {
  326. returnData = append(returnData, map[string]interface{}{
  327. "b_id": gconv.String(m["b_id"]),
  328. "b_name": gconv.String(m["b_name"]),
  329. "a_name": gconv.String(m["a_name"]),
  330. "a_id": gconv.String(m["a_id"]),
  331. "sourceType": gconv.String(m["sourceType"]),
  332. "relationship": gconv.String(m["relationship"]),
  333. "count": gconv.Int64(m["count"]),
  334. "list": m["list"],
  335. })
  336. }
  337. for _, m := range agencyMap {
  338. returnData = append(returnData, map[string]interface{}{
  339. "b_id": gconv.String(m["b_id"]),
  340. "b_name": gconv.String(m["b_name"]),
  341. "a_name": gconv.String(m["a_name"]),
  342. "a_id": gconv.String(m["a_id"]),
  343. "sourceType": gconv.String(m["sourceType"]),
  344. "relationship": gconv.String(m["relationship"]),
  345. "count": gconv.Int64(m["count"]),
  346. "list": m["list"],
  347. })
  348. }
  349. }
  350. return returnData
  351. }
  352. // 中间人查询
  353. func FindMiddleman(buyerArr []string, positionId int64, returnData []map[string]interface{}) []map[string]interface{} {
  354. if len(buyerArr) == 0 {
  355. return returnData
  356. }
  357. //中间人 作为可介绍业主 企业名称
  358. companyArr := CrmMysql.SelectBySql(
  359. fmt.Sprintf("select DISTINCT b.company_id,b.company_name,a.relate_id,a.relate_name,b.contact_person from connection_introduce a INNER JOIN connection b on a.position_id=%d and a.connection_id=b.id and a.relate_Id in (%s) and a.itype =1 and b.itype=4 and b.status=1 ", positionId, strings.Join(buyerArr, ",")))
  360. for _, v := range *companyArr {
  361. companyId := gconv.String(v["company_id"])
  362. companyName := gconv.String(v["company_name"])
  363. relateName := gconv.String(v["relate_name"])
  364. relateId := gconv.String(v["relate_id"])
  365. //key := fmt.Sprintf("%s_%s", relateId, companyId)
  366. returnData = append(returnData, map[string]interface{}{
  367. "b_id": companyId,
  368. "b_name": companyName,
  369. "a_name": relateName,
  370. "a_id": relateId,
  371. "sourceType": "middleman",
  372. "relationship": "业主的关系人",
  373. "personName": gconv.String(v["contact_person"]),
  374. })
  375. }
  376. return returnData
  377. }
  378. // 企业之间关系查询
  379. func Findfirstparty(buyerArr []string, returnData []map[string]interface{}) []map[string]interface{} {
  380. if len(buyerArr) == 0 {
  381. return returnData
  382. }
  383. buyerSql := fmt.Sprintf(`select DISTINCT
  384. a.a_id as a_id,
  385. a.b_id as b_id,
  386. a.a_name as a_name,
  387. a.b_name as b_name,
  388. 111 as status,
  389. a.code as code
  390. from
  391. ent_map_code a
  392. where
  393. a.a_id in (%s)
  394. and a.code in('0101', '0201')
  395. UNION ALL
  396. select
  397. a.b_id as a_id,
  398. a.a_id as b_id,
  399. a.b_name as a_name,
  400. a.a_name as b_name,
  401. 222 as status,
  402. a.code as code
  403. from
  404. ent_map_code a
  405. where
  406. a.b_id in (%s)
  407. and a.code in('0101', '0201')`,
  408. strings.Join(buyerArr, ","),
  409. strings.Join(buyerArr, ","))
  410. relationshipArr := BuyerFindConnectionsHandle(buyerSql)
  411. if relationshipArr != nil && len(relationshipArr) > 0 {
  412. entIdArr := []string{}
  413. for _, v := range relationshipArr {
  414. if v.Bid != "" {
  415. entIdArr = append(entIdArr, fmt.Sprintf("'%s'", v.Bid))
  416. }
  417. }
  418. personMap := map[string]string{}
  419. if len(entIdArr) > 0 {
  420. personSql := fmt.Sprintf(`select id,name from ent_contact where id in (%s) ORDER by name`, strings.Join(entIdArr, ","))
  421. personArr := PersonFindConnectionsHandle(personSql)
  422. //联系人处理
  423. for _, v := range personArr {
  424. personMap[v.Id] = v.PersonName
  425. }
  426. }
  427. for _, v := range relationshipArr {
  428. code := v.Code
  429. status := v.Status
  430. if gconv.String(status) == "111" {
  431. //key := fmt.Sprintf("%s_%s", a_id, b_id)
  432. switch code {
  433. case "0101": //管辖关系
  434. returnData = append(returnData, map[string]interface{}{
  435. "b_id": v.Bid,
  436. "b_name": v.Bname,
  437. "a_name": v.Aname,
  438. "a_id": v.Aid,
  439. "sourceType": "firstparty",
  440. "relationship": "业主的下级机构",
  441. "personName": gconv.String(personMap[v.Bid]),
  442. })
  443. case "0201": //投资关系
  444. returnData = append(returnData, map[string]interface{}{
  445. "b_id": v.Bid,
  446. "b_name": v.Bname,
  447. "a_name": v.Aname,
  448. "a_id": v.Aid,
  449. "sourceType": "firstparty",
  450. "relationship": "业主的股东",
  451. "personName": gconv.String(personMap[v.Bid]),
  452. })
  453. }
  454. }
  455. if gconv.String(status) == "222" {
  456. //key := fmt.Sprintf("%s_%s", b_id, a_id)
  457. if code == "0101" {
  458. //"0101":管辖关系
  459. returnData = append(returnData, map[string]interface{}{
  460. "b_id": v.Bid,
  461. "b_name": v.Bname,
  462. "a_name": v.Aname,
  463. "a_id": v.Aid,
  464. "sourceType": "firstparty",
  465. "relationship": "业主的上级机构",
  466. "personName": gconv.String(personMap[v.Aid]),
  467. })
  468. }
  469. }
  470. }
  471. }
  472. return returnData
  473. }
  474. // 采购单位和项目合并
  475. func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}, sourceType string) ([]BuyerProject, int64, int64, int64) {
  476. returnData := []BuyerProject{}
  477. connectionsNumber := int64(0)
  478. highSuccessNumber := int64(0)
  479. monitorNumber := int64(0)
  480. for buyerId, buyerMap := range *dataMap {
  481. buyerName := gconv.String(buyerMap["buyerName"])
  482. count := int64(0)
  483. if _, ok := (*projectMap)[buyerName]; ok {
  484. projectMap := (*projectMap)[buyerName]
  485. if isMonitor := gconv.Bool(buyerMap["isMonitor"]); isMonitor {
  486. monitorNumber++
  487. }
  488. count = gconv.Int64(projectMap["count"])
  489. money := gconv.Int64(projectMap["money"])
  490. zbtime := gconv.Int64(projectMap["zbtime"])
  491. if count >= 2 {
  492. highSuccessNumber++
  493. }
  494. if sourceType == "1" {
  495. if count < 2 {
  496. continue
  497. }
  498. }
  499. returnData = append(returnData, BuyerProject{
  500. BuyerId: buyerId,
  501. BuyerName: buyerName,
  502. Project: ProjectEntity{
  503. Number: count,
  504. EstimatedAmount: money,
  505. Connections: []map[string]interface{}{},
  506. },
  507. Area: gconv.String(projectMap["area"]),
  508. Zbtime: zbtime,
  509. IsIgnore: gconv.Bool(buyerMap["isIgnore"]),
  510. IsMonitor: gconv.Bool(buyerMap["isMonitor"]),
  511. IsCreateCustomer: gconv.Bool(buyerMap["isCreateCustomer"]),
  512. })
  513. } else {
  514. if sourceType == "1" {
  515. if count < 2 {
  516. continue
  517. }
  518. }
  519. returnData = append(returnData, BuyerProject{
  520. BuyerId: buyerId,
  521. BuyerName: buyerName,
  522. Project: ProjectEntity{
  523. Number: 0,
  524. EstimatedAmount: 0,
  525. Connections: []map[string]interface{}{},
  526. },
  527. Area: "",
  528. Zbtime: 0,
  529. IsIgnore: gconv.Bool(buyerMap["isIgnore"]),
  530. IsMonitor: gconv.Bool(buyerMap["isMonitor"]),
  531. IsCreateCustomer: gconv.Bool(buyerMap["isCreateCustomer"]),
  532. })
  533. }
  534. connectionsNumber++
  535. }
  536. return returnData, connectionsNumber, highSuccessNumber, monitorNumber
  537. }
  538. // 已监控数据处理
  539. func MonitorStatusInit(positionId int64, dataMap *map[string]map[string]interface{}, sourceType string) {
  540. monitorMap := map[string]bool{}
  541. query := map[string]interface{}{
  542. "userId": gconv.String(positionId),
  543. }
  544. clist, ok := Mgo.Find("follow_customer", query, ``, `{"name":1}`, false, -1, -1)
  545. if ok && clist != nil && len(*clist) > 0 {
  546. for _, v := range *clist {
  547. monitorMap[gconv.String(v["name"])] = true
  548. }
  549. }
  550. //采购单位和自己监控的对比
  551. newMap := &map[string]map[string]interface{}{}
  552. for k, v := range *dataMap {
  553. buyerName := gconv.String(v["buyerName"])
  554. if _, ok1 := monitorMap[gconv.String(buyerName)]; ok1 {
  555. v["isMonitor"] = true
  556. (*newMap)[k] = v
  557. } else {
  558. if sourceType != "2" {
  559. v["isMonitor"] = false
  560. (*newMap)[k] = v
  561. }
  562. }
  563. }
  564. if sourceType == "2" {
  565. *dataMap = *newMap
  566. return
  567. }
  568. if newMap != nil {
  569. *dataMap = *newMap
  570. }
  571. }
  572. func FindStatus(positionId int64) (map[string]bool, map[string]bool, map[string]bool) {
  573. //未处理
  574. untreatedMap := map[string]bool{}
  575. //已忽略
  576. ignoredMap := map[string]bool{}
  577. //已创建
  578. createdMap := map[string]bool{}
  579. processingArr := CrmMysql.Find(entity.CONNECTION_STATUS, map[string]interface{}{
  580. "itype": 1,
  581. "position_id": positionId,
  582. }, "relate_id,is_handle,is_ignore,is_create", "", -1, -1)
  583. if processingArr != nil && len(*processingArr) > 0 {
  584. for _, v := range *processingArr {
  585. entId := gconv.String(v["relate_id"])
  586. handle := gconv.Int64(v["is_handle"])
  587. ignore := gconv.Int64(v["is_ignore"])
  588. create := gconv.Int64(v["is_create"])
  589. if handle == 1 {
  590. untreatedMap[entId] = true
  591. }
  592. if ignore == 1 {
  593. ignoredMap[entId] = true
  594. }
  595. if create == 1 {
  596. createdMap[entId] = true
  597. }
  598. }
  599. }
  600. return untreatedMap, ignoredMap, createdMap
  601. }
  602. // 处理状态初始化
  603. func ProcessingStatusInit(positionId int64, dataMap *map[string]map[string]interface{}, processingStatus string) {
  604. //收录数据处理
  605. untreatedMap, ignoredMap, createdMap := FindStatus(positionId)
  606. newMap := &map[string]map[string]interface{}{}
  607. //所有采购单位和处理状态对比
  608. for buyerId, value := range *dataMap {
  609. for _, v := range strings.Split(processingStatus, ",") {
  610. switch v {
  611. case "1":
  612. if _, ok := untreatedMap[buyerId]; !ok {
  613. (*newMap)[buyerId] = value
  614. }
  615. case "2":
  616. if _, ok := ignoredMap[buyerId]; ok {
  617. value["isIgnore"] = true
  618. (*newMap)[buyerId] = value
  619. }
  620. case "3":
  621. if _, ok := createdMap[buyerId]; ok {
  622. value["isCreateCustomer"] = true
  623. (*newMap)[buyerId] = value
  624. }
  625. case "全部", "":
  626. if _, ok := ignoredMap[buyerId]; ok {
  627. value["isIgnore"] = true
  628. }
  629. if _, ok := createdMap[buyerId]; ok {
  630. value["isCreateCustomer"] = true
  631. }
  632. (*newMap)[buyerId] = value
  633. }
  634. }
  635. }
  636. if newMap != nil {
  637. *dataMap = *newMap
  638. }
  639. }
  640. // 采购单位查询
  641. func BuyerList(partyA, supplier, heterotophy, intermediary, agency string, positionId int64) *map[string]map[string]interface{} {
  642. dataMap := &map[string]map[string]interface{}{}
  643. //甲方
  644. if partyA != "" {
  645. intermediaryArr := []string{}
  646. for _, v := range strings.Split(partyA, ",") {
  647. if v != "" {
  648. intermediaryArr = append(intermediaryArr, fmt.Sprintf("'%s'", v))
  649. }
  650. }
  651. if len(partyA) > 0 {
  652. partyASql := fmt.Sprintf(`select id as buyer_id,company_name as buyer from ent_info where id in (%s)`, strings.Join(intermediaryArr, ","))
  653. FindHandle(partyASql, dataMap)
  654. }
  655. }
  656. //供应商 //同甲异业
  657. findInSetArr := []string{}
  658. if supplier != "" {
  659. for _, v := range strings.Split(supplier, ",") {
  660. if v != "" {
  661. findInSetArr = append(findInSetArr, fmt.Sprintf("'%s'", v))
  662. }
  663. }
  664. }
  665. if heterotophy != "" {
  666. for _, v := range strings.Split(heterotophy, ",") {
  667. if v != "" {
  668. findInSetArr = append(findInSetArr, fmt.Sprintf("'%s'", v))
  669. }
  670. }
  671. }
  672. if len(findInSetArr) > 0 {
  673. sqlStr := fmt.Sprintf(`SELECT buyer_id,buyer FROM transaction_info where hasAny(winner_id,[%s]) `, strings.Join(findInSetArr, ","))
  674. FindHandle(sqlStr, dataMap)
  675. }
  676. //中间人
  677. if intermediary != "" {
  678. wh, args := common.WhArgs(strings.Split(intermediary, ","))
  679. args = append(args, positionId)
  680. intermediaryArr := CrmMysql.SelectBySql(`select b.relate_id as relate_id,b.relate_name as relate_name from crm.connection a inner join crm.connection_introduce b on ( a.id in (`+wh+`) and a.position_id=? and a.id=b.connection_id and b.itype=1)`, args...)
  681. if intermediaryArr != nil && len(*intermediaryArr) > 0 {
  682. for _, m := range *intermediaryArr {
  683. buyerId := gconv.String(m["relate_id"])
  684. buyerName := gconv.String(m["relate_name"])
  685. (*dataMap)[buyerId] = map[string]interface{}{
  686. "buyerName": buyerName,
  687. }
  688. }
  689. }
  690. }
  691. //招标代理
  692. if agency != "" {
  693. agencyArr := []string{}
  694. for _, s := range strings.Split(agency, ",") {
  695. agencyArr = append(agencyArr, fmt.Sprintf("'%s'", s))
  696. }
  697. sqlStr := fmt.Sprintf(`SELECT buyer_id,buyer FROM transaction_info where agency_id in (%s) `, strings.Join(agencyArr, ","))
  698. FindHandle(sqlStr, dataMap)
  699. }
  700. return dataMap
  701. }
  702. // 项目数量查询
  703. func ProjectHandle(buyerArr []string, entAccountId int64, entName, area, projectType string, dataMap *map[string]map[string]interface{}) (*map[string]map[string]interface{}, *map[string]map[string]interface{}, *map[string]map[string]interface{}) {
  704. projectMap := &map[string]map[string]interface{}{}
  705. returnMap := &map[string]map[string]interface{}{}
  706. sql := ""
  707. sqlStr := ""
  708. propertyFormStr := ""
  709. if projectType == "1" {
  710. propertyForm := ""
  711. m1 := CrmMysql.FindOne("config_tenant", map[string]interface{}{"account_id": entAccountId}, "probusfor", "")
  712. if m1 != nil && len(*m1) > 0 {
  713. propertyForm = common.ObjToString((*m1)["probusfor"])
  714. if propertyForm != "" {
  715. propertyFormStr = fmt.Sprintf(`,{"match":{"property_form":"%s"}}`, propertyForm)
  716. }
  717. }
  718. }
  719. if entName != "" {
  720. sql = `{"query":{"bool":{"must":[{"multi_match":{"query":"%s","type":"phrase","fields":["buyer.mbuyer"]}}%s%s]}},"aggs":{"buyer_count":{"terms":{"field":"buyer","size":500,"order":{"zbtime_count":"desc"}},"aggs":{"area_count":{"terms":{"field":"area"}},"buyer_id":{"terms":{"field":"buyer_id"}},"money_count":{"sum":{"field":"project_money"}},"zbtime_count":{"max":{"field":"zbtime"}}}}},"size":0}`
  721. sqlStr = fmt.Sprintf(sql, entName, common.If(area != "", fmt.Sprintf(`,{"term":{"area":"%s"}}`, area), ""), common.If(projectType == "1", propertyFormStr, ""))
  722. } else {
  723. sql = `{"query":{"bool":{"must":[{"terms":{"buyer":[%s]}}%s%s]}},"aggs":{"buyer_count":{"terms":{"field":"buyer","size":500,"order":{"zbtime_count":"desc"}},"aggs":{"area_count":{"terms":{"field":"area"}},"buyer_id":{"terms":{"field":"buyer_id"}},"money_count":{"sum":{"field":"project_money"}},"zbtime_count":{"max":{"field":"zbtime"}}}}},"size":0}`
  724. sqlStr = fmt.Sprintf(sql, strings.Join(buyerArr, ","), common.If(area != "", fmt.Sprintf(`,{"term":{"area":"%s"}}`, area), ""), common.If(projectType == "1", propertyFormStr, ""))
  725. }
  726. startTime := time.Now().Unix()
  727. data, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, sqlStr)
  728. endTime := time.Now().Unix()
  729. fmt.Println("es用时时间:", endTime-startTime)
  730. if len(data) == 0 {
  731. return projectMap, returnMap, dataMap
  732. }
  733. for _, object := range data {
  734. buyerArr := BuyerAggStruct{}
  735. bs, ok := object.MarshalJSON()
  736. if ok != nil {
  737. logx.Error("解析项目数据失败", object)
  738. continue
  739. }
  740. err := json.Unmarshal(bs, &buyerArr)
  741. if err != nil {
  742. logx.Error(err)
  743. }
  744. for _, v := range buyerArr.Buckets {
  745. buyerName := v.Key
  746. area := ""
  747. buyerId := ""
  748. for _, areaEntity := range v.Area_count.Buckets {
  749. area = Deduplication(area, areaEntity.Key)
  750. }
  751. for _, buyerIdEntity := range v.Buyer_id.Buckets {
  752. if buyerIdEntity.Key != "" {
  753. buyerId = buyerIdEntity.Key
  754. }
  755. }
  756. (*projectMap)[buyerName] = map[string]interface{}{
  757. "area": area,
  758. "zbtime": v.Zbtime_count.Value,
  759. "money": common.RetainDecimal(common.Float64All(v.Money_count.Value)/10000, 2),
  760. "count": v.Doc_count,
  761. "buyerId": buyerId,
  762. }
  763. (*returnMap)[buyerId] = map[string]interface{}{
  764. "buyerName": buyerName,
  765. }
  766. }
  767. }
  768. if projectType == "1" || area != "" {
  769. if entName == "" {
  770. for buyerId, v := range *dataMap {
  771. buyerName := gconv.String(v["buyerName"])
  772. if _, ok := (*projectMap)[buyerName]; !ok {
  773. delete(*dataMap, buyerId)
  774. }
  775. }
  776. } else {
  777. for buyerId, v := range *returnMap {
  778. buyerName := gconv.String(v["buyerName"])
  779. if _, ok := (*projectMap)[buyerName]; !ok {
  780. delete(*returnMap, buyerId)
  781. }
  782. }
  783. }
  784. }
  785. return projectMap, returnMap, dataMap
  786. }
  787. type BuyerAggStruct struct {
  788. Buckets []struct {
  789. Key string `json:"key,omitempty"`
  790. Doc_count int64 `json:"doc_count,omitempty"`
  791. Zbtime_count struct {
  792. Value interface{} `json:"value,omitempty"`
  793. } `json:"zbtime_count,omitempty"`
  794. Money_count struct {
  795. Value interface{} `json:"value,omitempty"`
  796. } `json:"money_count,omitempty"`
  797. Area_count struct {
  798. Buckets []struct {
  799. Key string `json:"key,omitempty"`
  800. Doc_count int64 `json:"doc_count,omitempty"`
  801. }
  802. } `json:"area_count"`
  803. Buyer_id struct {
  804. Buckets []struct {
  805. Key string `json:"key,omitempty"`
  806. Doc_count int64 `json:"doc_count,omitempty"`
  807. }
  808. } `json:"buyer_id"`
  809. }
  810. }
  811. // 采购单位查询sql
  812. func FindHandle(sqlStr string, dataMap *map[string]map[string]interface{}) {
  813. rows, err := ClickhouseConn.Query(context.Background(), sqlStr)
  814. if err != nil {
  815. logx.Error("查询失败", sqlStr, err)
  816. }
  817. for rows.Next() {
  818. data := Recommend{}
  819. rows.ScanStruct(&data)
  820. if data.BuyerId != "" {
  821. (*dataMap)[data.BuyerId] = map[string]interface{}{
  822. "buyerName": data.Buyer,
  823. }
  824. }
  825. }
  826. return
  827. }
  828. type ConnectionsEntity struct {
  829. Aid string `ch:"a_id"`
  830. Bid string `ch:"b_id"`
  831. Aname string `ch:"a_name"`
  832. Bname string `ch:"b_name"`
  833. Status uint8 `ch:"status"`
  834. Code string `ch:"code"`
  835. Cperson string `ch:"c_person"`
  836. }
  837. type PersonEntity struct {
  838. Id string `ch:"id"`
  839. PersonName string `ch:"personName"`
  840. }
  841. type SupplierConnectionsEntity struct {
  842. Zbtime int64 `ch:"zbtime"`
  843. Project_id string `ch:"project_id"`
  844. Project_name string `ch:"project_name"`
  845. Buyer_id string `ch:"buyer_id"`
  846. Buyer string `ch:"buyer"`
  847. Agency_id string `ch:"agency_id"`
  848. Agency string `ch:"agency"`
  849. WinnerId []string `ch:"winner_id"`
  850. Winner []string `ch:"winner"`
  851. }
  852. type SupplierConnectionsEntitys struct {
  853. Zbtime int64
  854. Project_id string
  855. Project_name string
  856. Buyer_id string
  857. Buyer string
  858. Agency_id string
  859. Agency string
  860. WinnerId string
  861. Winner string
  862. }
  863. type TimeConnectionsEntity struct {
  864. Zbtime int64 `ch:"zbtime"`
  865. Project_id string `ch:"project_id"`
  866. Project_name string `ch:"project_name"`
  867. }
  868. // 采购单位人脉信息查询sql
  869. func BuyerFindConnectionsHandle(sqlStr string) []ConnectionsEntity {
  870. returnData := []ConnectionsEntity{}
  871. rows, err := ClickhouseConn.Query(context.Background(), sqlStr)
  872. if err != nil {
  873. logx.Error("查询失败", sqlStr, err)
  874. }
  875. for rows.Next() {
  876. data := ConnectionsEntity{}
  877. err := rows.ScanStruct(&data)
  878. logx.Info(err)
  879. returnData = append(returnData, data)
  880. }
  881. return returnData
  882. }
  883. func PersonFindConnectionsHandle(sqlStr string) []PersonEntity {
  884. returnData := []PersonEntity{}
  885. rows, err := ClickhouseConn.Query(context.Background(), sqlStr)
  886. if err != nil {
  887. logx.Error("查询失败", sqlStr, err)
  888. }
  889. for rows.Next() {
  890. data := PersonEntity{}
  891. rows.ScanStruct(&data)
  892. returnData = append(returnData, data)
  893. }
  894. return returnData
  895. }
  896. // 供应商
  897. func SupplierFindConnectionsHandle(sqlStr string) []SupplierConnectionsEntitys {
  898. returnData := []SupplierConnectionsEntitys{}
  899. rows, err := ClickhouseConn.Query(context.Background(), sqlStr)
  900. if err != nil {
  901. logx.Error("查询失败", sqlStr, err)
  902. }
  903. for rows.Next() {
  904. data := SupplierConnectionsEntity{}
  905. err = rows.ScanStruct(&data)
  906. if err != nil {
  907. logx.Error(err)
  908. }
  909. if len(data.Winner) == 0 {
  910. returnData = append(returnData, SupplierConnectionsEntitys{
  911. Zbtime: data.Zbtime,
  912. Project_id: data.Project_id,
  913. Project_name: data.Project_name,
  914. Buyer_id: data.Buyer_id,
  915. Buyer: data.Buyer,
  916. Agency_id: data.Agency_id,
  917. Agency: data.Agency,
  918. WinnerId: "",
  919. Winner: "",
  920. })
  921. } else {
  922. for k, v := range data.WinnerId {
  923. fmt.Println(k, len(data.Winner))
  924. if k+1 > len(data.Winner) {
  925. continue
  926. }
  927. returnData = append(returnData, SupplierConnectionsEntitys{
  928. Zbtime: data.Zbtime,
  929. Project_id: data.Project_id,
  930. Project_name: data.Project_name,
  931. Buyer_id: data.Buyer_id,
  932. Buyer: data.Buyer,
  933. Agency_id: data.Agency_id,
  934. Agency: data.Agency,
  935. WinnerId: gconv.String(v),
  936. Winner: gconv.String(data.Winner[k]),
  937. })
  938. }
  939. }
  940. }
  941. return returnData
  942. }
  943. // 合作时间查询
  944. func TimeFindConnectionsHandle(sqlStr string) []TimeConnectionsEntity {
  945. returnData := []TimeConnectionsEntity{}
  946. rows, err := ClickhouseConn.Query(context.Background(), sqlStr)
  947. if err != nil {
  948. logx.Error("查询失败", sqlStr, err)
  949. }
  950. for rows.Next() {
  951. data := TimeConnectionsEntity{}
  952. rows.ScanStruct(&data)
  953. returnData = append(returnData, data)
  954. }
  955. return returnData
  956. }
  957. // 去重处理
  958. func Deduplication(a, b string) string {
  959. newArr := []string{}
  960. if b == "全国" {
  961. return a
  962. }
  963. if a != "" {
  964. newArr = append(newArr, a)
  965. }
  966. if b != "" {
  967. newArr = append(newArr, b)
  968. }
  969. return strings.Join(newArr, ",")
  970. }
  971. // 路径列表
  972. func (t *OwnerService) OwnerRoute() []map[string]interface{} {
  973. if t.BuyerId == "" {
  974. return []map[string]interface{}{}
  975. }
  976. routeList := ConnectionsHandle([]string{
  977. fmt.Sprintf("'%s'", t.BuyerId),
  978. }, t.PositionId, false)
  979. for i, routeMap := range routeList {
  980. sourceType := gconv.String(routeMap["sourceType"])
  981. if sourceType == "agency" || sourceType == "supplier" {
  982. data := routeList[i]
  983. data["cooperateCount"] = len(gconv.Maps(data["list"]))
  984. delete(data, "list")
  985. routeList[i] = data
  986. }
  987. }
  988. return routeList
  989. }
  990. // 合作列表
  991. func (t *OwnerService) OwnerCooperate() []map[string]interface{} {
  992. returData := []map[string]interface{}{}
  993. dataArr := []TimeConnectionsEntity{}
  994. if t.CooperateType == "supplier" {
  995. //供应商
  996. supplierSql := fmt.Sprintf(`SELECT
  997. zbtime,
  998. project_id,
  999. project_name
  1000. FROM
  1001. transaction_info
  1002. ARRAY
  1003. JOIN winner_id as winnerId
  1004. where buyer_id= '%s' and winnerId='%s'`, t.BuyerId, t.WinnerId)
  1005. dataArr = TimeFindConnectionsHandle(supplierSql)
  1006. } else if t.CooperateType == "agency" {
  1007. //代理机构
  1008. agentSql := fmt.Sprintf(`select zbtime,project_id,project_name from transaction_info where buyer_id ='%s' and agency_id ='%s' order by zbtime,winner_id `, t.BuyerId, t.WinnerId)
  1009. dataArr = TimeFindConnectionsHandle(agentSql)
  1010. }
  1011. if dataArr != nil && len(dataArr) > 0 {
  1012. for _, m := range dataArr {
  1013. zbtime := m.Zbtime
  1014. returData = append(returData, map[string]interface{}{
  1015. "zbtime": common.If(zbtime == 0, "", time.Unix(zbtime, 10).Format("2006.01.02")),
  1016. "entName": t.WinnerName,
  1017. "projectId": encrypt.EncodeArticleId2ByCheck(m.Project_id),
  1018. "projectName": m.Project_name,
  1019. })
  1020. }
  1021. }
  1022. return returData
  1023. }
  1024. func (t *OwnerService) CandidateChannel() []*ResultData {
  1025. returnData := []*ResultData{}
  1026. dataMap := &map[string]map[string]interface{}{}
  1027. if t.PartyA != "" || t.Supplier != "" || t.Heterotophy != "" || t.Intermediary != "" || t.Agency != "" {
  1028. dataMap = BuyerList(t.PartyA, t.Supplier, t.Heterotophy, t.Intermediary, t.Agency, t.PositionId)
  1029. }
  1030. if len(*dataMap) > 0 && dataMap != nil {
  1031. propertyForm := ""
  1032. m1 := CrmMysql.FindOne("config_tenant", map[string]interface{}{"account_id": t.EntAccountId}, "probusfor", "")
  1033. if m1 != nil && len(*m1) > 0 {
  1034. propertyForm = common.ObjToString((*m1)["probusfor"])
  1035. }
  1036. for buyerId := range *dataMap {
  1037. r1, r2 := GetData(propertyForm, buyerId)
  1038. if r1 != nil && len(r1) > 0 {
  1039. for _, m := range r1 {
  1040. near, zbtime := LastTimeCoop(buyerId, common.ObjToString(m["name"]), "adiffb")
  1041. tmp := ResultData{
  1042. SourceType: "adiffb",
  1043. EntName: common.ObjToString(m["name"]),
  1044. ProjectNum: common.IntAll(m["coop_size"]),
  1045. TotalAmount: common.Float64All(m["coop_amount"]),
  1046. RecentTime: zbtime,
  1047. NearlyYears: near,
  1048. }
  1049. returnData = append(returnData, &tmp)
  1050. }
  1051. }
  1052. if r2 != nil && len(r2) > 0 {
  1053. for _, m := range r2 {
  1054. near, zbtime := LastTimeCoop(buyerId, common.ObjToString(m["name"]), "agency")
  1055. tmp := ResultData{
  1056. SourceType: "agency",
  1057. EntName: common.ObjToString(m["name"]),
  1058. ProjectNum: common.IntAll(m["coop_size"]),
  1059. TotalAmount: common.Float64All(m["coop_amount"]),
  1060. RecentTime: zbtime,
  1061. NearlyYears: near,
  1062. BuyerId: common.ObjToString(m["nameId"]),
  1063. }
  1064. returnData = append(returnData, &tmp)
  1065. }
  1066. }
  1067. // 中间人可介绍业主
  1068. var r3 []map[string]interface{}
  1069. r3 = FindMiddleman([]string{fmt.Sprintf("'%s'", buyerId)}, t.PositionId, r3)
  1070. if r3 != nil && len(r3) > 0 {
  1071. for _, m := range r3 {
  1072. tmp := ResultData{
  1073. SourceType: "middleman",
  1074. EntName: common.ObjToString(m["b_name"]),
  1075. EntPerson: common.ObjToString(m["personName"]),
  1076. Relationship: "业主的关系人",
  1077. BuyerId: common.ObjToString(m["b_id"]),
  1078. }
  1079. returnData = append(returnData, &tmp)
  1080. }
  1081. }
  1082. // 关联单位
  1083. var r4 []map[string]interface{}
  1084. r4 = Findfirstparty([]string{fmt.Sprintf("'%s'", buyerId)}, r4)
  1085. if r4 != nil && len(r4) > 0 {
  1086. for _, m := range r3 {
  1087. tmp := ResultData{
  1088. SourceType: "sup_sub",
  1089. EntName: common.ObjToString(m["b_name"]),
  1090. EntPerson: common.ObjToString(m["personName"]),
  1091. Relationship: common.ObjToString(m["relationship"]),
  1092. BuyerId: common.ObjToString(m["b_id"]),
  1093. }
  1094. returnData = append(returnData, &tmp)
  1095. }
  1096. }
  1097. }
  1098. }
  1099. //状态处理
  1100. if len(returnData) > 0 {
  1101. monitorMap := map[string]bool{}
  1102. query := map[string]interface{}{
  1103. "userId": gconv.String(t.PositionId),
  1104. }
  1105. clist, ok := Mgo.Find("follow_customer", query, ``, `{"name":1}`, false, -1, -1)
  1106. if ok && clist != nil && len(*clist) > 0 {
  1107. for _, v := range *clist {
  1108. monitorMap[gconv.String(v["name"])] = true
  1109. }
  1110. }
  1111. _, ignoredMap, createdMap := FindStatus(t.PositionId)
  1112. for k, value := range returnData {
  1113. buyerId := value.BuyerId
  1114. if _, ok := ignoredMap[buyerId]; ok {
  1115. value.IsIgnore = true
  1116. }
  1117. if _, ok := createdMap[buyerId]; ok {
  1118. value.IsCreateCustomer = true
  1119. }
  1120. if _, ok := monitorMap[buyerId]; ok {
  1121. value.IsMonitor = true
  1122. }
  1123. returnData[k] = value
  1124. }
  1125. }
  1126. return returnData
  1127. }