owner.go 35 KB

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