owner.go 35 KB

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